Github user jingyimei commented on a diff in the pull request:
https://github.com/apache/madlib/pull/191#discussion_r146700914
--- Diff: src/ports/postgres/modules/knn/knn.py_in ---
@@ -160,20 +164,23 @@ def knn(schema_madlib, point_source,
point_column_name, point_id, label_column_n
) {x_temp_table}
) {y_temp_table}
WHERE {y_temp_table}.r <= {k_val}
- """.format(**locals()))
- plpy.execute(
- """
+ """.format(**locals())
+ plpy.execute(sql1)
+
+ sql2 = """
CREATE TABLE {output_table} AS
SELECT {test_id_temp} AS id, {test_column_name} ,
CASE WHEN {output_neighbors}
- THEN array_agg(knn_temp.train_id)
+ THEN array_agg(knn_temp.train_id
+ ORDER BY knn_temp.dist ASC)
--- End diff --
Can be in one line
---