tajo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jihoon...@apache.org
Subject [4/5] tajo git commit: TAJO-1257: ORDER BY with NULL FIRST misses some data. (Keuntae Park)
Date Tue, 20 Jan 2015 13:04:22 GMT
TAJO-1257: ORDER BY with NULL FIRST misses some data. (Keuntae Park)

Closes #307


Project: http://git-wip-us.apache.org/repos/asf/tajo/repo
Commit: http://git-wip-us.apache.org/repos/asf/tajo/commit/4d1006d5
Tree: http://git-wip-us.apache.org/repos/asf/tajo/tree/4d1006d5
Diff: http://git-wip-us.apache.org/repos/asf/tajo/diff/4d1006d5

Branch: refs/heads/index_support
Commit: 4d1006d56b7761500e16afe7be7826422850555a
Parents: 6f07cef
Author: Keuntae Park <sirpkt@apache.org>
Authored: Tue Jan 20 15:47:53 2015 +0900
Committer: Keuntae Park <sirpkt@apache.org>
Committed: Tue Jan 20 15:47:53 2015 +0900

----------------------------------------------------------------------
 CHANGES                                         |  2 ++
 .../org/apache/tajo/engine/utils/TupleUtil.java | 18 ++++++++-----
 .../apache/tajo/engine/query/TestSortQuery.java | 28 ++++++++++++++++++++
 3 files changed, 42 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tajo/blob/4d1006d5/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index 8acd4e5..eec490b 100644
--- a/CHANGES
+++ b/CHANGES
@@ -169,6 +169,8 @@ Release 0.10.0 - unreleased
 
   BUG FIXES
 
+    TAJO-1257: ORDER BY with NULL FIRST misses some data. (Keuntae Park)
+
     TAJO-1225: Fix wrong schema name in JDBC driver. (jaehwa)
 
     TAJO-1304: Can not found TextFile in catalog. (jinho)

http://git-wip-us.apache.org/repos/asf/tajo/blob/4d1006d5/tajo-core/src/main/java/org/apache/tajo/engine/utils/TupleUtil.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/utils/TupleUtil.java b/tajo-core/src/main/java/org/apache/tajo/engine/utils/TupleUtil.java
index 3bb1b5b..027da50 100644
--- a/tajo-core/src/main/java/org/apache/tajo/engine/utils/TupleUtil.java
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/utils/TupleUtil.java
@@ -97,13 +97,19 @@ public class TupleUtil {
         continue;
       }
       if (columnStat.hasNullValue()) {
-        int rangeIndex = sortSpecs[i].isAscending() ? ranges.length - 1 : 0;
-        VTuple rangeTuple = sortSpecs[i].isAscending() ? (VTuple) ranges[rangeIndex].getEnd()
: (VTuple) ranges[rangeIndex].getStart();
-        if (LOG.isDebugEnabled()) {
-          LOG.debug("Set null into range: " + col.getQualifiedName() + ", previous tuple
is " + rangeTuple);
+        if (sortSpecs[i].isNullFirst()) {
+          int rangeIndex = 0;
+          VTuple rangeTuple = (VTuple) ranges[rangeIndex].getStart();
+          rangeTuple.put(i, NullDatum.get());
+        } else {
+          int rangeIndex = sortSpecs[i].isAscending() ? ranges.length - 1 : 0;
+          VTuple rangeTuple = sortSpecs[i].isAscending() ? (VTuple) ranges[rangeIndex].getEnd()
: (VTuple) ranges[rangeIndex].getStart();
+          if (LOG.isDebugEnabled()) {
+            LOG.debug("Set null into range: " + col.getQualifiedName() + ", previous tuple
is " + rangeTuple);
+          }
+          rangeTuple.put(i, NullDatum.get());
+          LOG.info("Set null into range: " + col.getQualifiedName() + ", current tuple is
" + rangeTuple);
         }
-        rangeTuple.put(i, NullDatum.get());
-        LOG.info("Set null into range: " + col.getQualifiedName() + ", current tuple is "
+ rangeTuple);
       }
       i++;
     }

http://git-wip-us.apache.org/repos/asf/tajo/blob/4d1006d5/tajo-core/src/test/java/org/apache/tajo/engine/query/TestSortQuery.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/java/org/apache/tajo/engine/query/TestSortQuery.java b/tajo-core/src/test/java/org/apache/tajo/engine/query/TestSortQuery.java
index 21a2cc0..9c911f9 100644
--- a/tajo-core/src/test/java/org/apache/tajo/engine/query/TestSortQuery.java
+++ b/tajo-core/src/test/java/org/apache/tajo/engine/query/TestSortQuery.java
@@ -237,6 +237,34 @@ public class TestSortQuery extends QueryTestCaseBase {
   }
 
   @Test
+  public final void testSortOnNullColumn3() throws Exception {
+    KeyValueSet tableOptions = new KeyValueSet();
+    tableOptions.set(StorageConstants.TEXT_DELIMITER, StorageConstants.DEFAULT_FIELD_DELIMITER);
+    tableOptions.set(StorageConstants.TEXT_NULL, "\\\\N");
+
+    Schema schema = new Schema();
+    schema.addColumn("id", Type.INT4);
+    schema.addColumn("name", Type.TEXT);
+    String[] data = new String[]{ "1|111", "2|\\N", "3|333" };
+    TajoTestingCluster.createTable("table11", schema, tableOptions, data, 1);
+
+    try {
+      ResultSet res = executeString("select * from table11 order by name null first");
+      String ascExpected = "id,name\n" +
+          "-------------------------------\n" +
+          "2,null\n" +
+          "1,111\n" +
+          "3,333\n";
+
+      assertEquals(ascExpected, resultSetToString(res));
+      res.close();
+
+    } finally {
+      executeString("DROP TABLE table11 PURGE");
+    }
+  }
+
+  @Test
   public final void testSortOnUnicodeTextAsc() throws Exception {
     try {
       testingCluster.setAllTajoDaemonConfValue(ConfVars.$TEST_MIN_TASK_NUM.varname, "2");


Mime
View raw message