iyerr3 commented on a change in pull request #352: Feature/kd tree knn
URL: https://github.com/apache/madlib/pull/352#discussion_r255751797
 
 

 ##########
 File path: src/ports/postgres/modules/knn/knn.py_in
 ##########
 @@ -282,38 +615,50 @@ def knn(schema_madlib, point_source, point_column_name, 
point_id,
                              "knn_temp.{dist_inverse} DESC) AS 
k_nearest_neighbours ").format(**locals())
         else:
             knn_neighbors = ''
-        plpy.execute("""
-            CREATE TEMP TABLE {interim_table} AS
-                SELECT * FROM (
-                    SELECT row_number() over
-                            (partition by {test_id_temp} order by {dist}) AS 
{r},
-                            {test_id_temp},
-                            {train_id},
-                            CASE WHEN {dist} = 0.0 THEN {max_weight_zero_dist}
-                                 ELSE 1.0 / {dist}
-                            END AS {dist_inverse}
-                            {comma_label_out_alias}
-                    FROM (
-                        SELECT {test}.{test_id} AS {test_id_temp},
-                            {train}.{point_id} as {train_id},
-                            {fn_dist}(
-                                {p_col_name},
-                                {t_col_name})
-                            AS {dist}
-                            {label_out}
-                            FROM
-                            (
-                            SELECT {point_id} , {point_column_name} as 
{p_col_name} {label_name} from {point_source}
-                            ) {train},
-                            (
-                            SELECT {test_id} ,{test_column_name} as 
{t_col_name} from {test_source}
-                            ) {test}
-                        ) {x_temp_table}
-                    ) {y_temp_table}
-            WHERE {y_temp_table}.{r} <= {k}
-            """.format(max_weight_zero_dist=MAX_WEIGHT_ZERO_DIST, **locals()))
-
-        sql = """
+
+        if 'kd_tree' in algorithm:
+            kd_output_table = unique_string(desp='kd_tree')
+            kd_tree(schema_madlib, point_source, kd_output_table,
+                    point_column_name, depth, r_id, dim)
+            knn_tree(schema_madlib, kd_output_table, point_source,
+                     point_column_name, point_id, label_column_name,
+                     test_source, test_column_name, test_id, interim_table,
+                     k, output_neighbors, fn_dist, weighted_avg, leaf_nodes,
+                     r_id, dim, label_out, comma_label_out_alias,
+                     label_name, train, train_id, dist_inverse, test_id_temp)
+        else:
+            plpy.execute("""
 
 Review comment:
   IMO, it would be cleaner to put this query in a `knn_brute_force` function 
and call that here. 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to