khannaekta commented on a change in pull request #401: DL: fix
default_buffer_size calculation
URL: https://github.com/apache/madlib/pull/401#discussion_r289137967
##########
File path: src/ports/postgres/modules/internal/db_utils.py_in
##########
@@ -93,3 +92,28 @@ def is_col_1d_array(source_table, col_name):
""".format(col_name, source_table)
result = plpy.execute(query)
return result[0]["n_y"]
+
+#
------------------------------------------------------------------------------
+# This function runs postgres array_ndims function to get
+# the dimension of an array. For example if it is a 3
+# dimension array it will be an array with 3 elements
+# like [32,32,3].
+def get_ndims(source_table, col_name):
+ array_ndims = plpy.execute("SELECT array_ndims({0}) AS ndims FROM {1}".
+ format(col_name, source_table))[0]['ndims']
+
+ return array_ndims
+
+# This function is to calculate the total `length` of a
+# multi dimentional array. For example, if an array is
+# with 3 dimentions and ndims=[32,32,3], this function
+# will return the product of them, which is 32*32*3
+def get_product_of_dimensions(source_table, col_name):
+ ndims = get_ndims(source_table, col_name)
+ dimension_product = 1
+ for i in range(1, ndims + 1):
+ array_upper_query = "SELECT array_upper({0}, {1}) AS dimension from
{2}".format(col_name, i, source_table)
Review comment:
We can also call `get_col_dimension(col_name, source_table, i)` which calls
the same query internally.
But, will leave it upto you whichever way you prefer.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services