parquet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b...@apache.org
Subject [03/50] [abbrv] parquet-mr git commit: PARQUET-432: Complete a todo for method ColumnDescriptor.compareTo()
Date Thu, 19 Jan 2017 01:27:14 GMT
PARQUET-432: Complete a todo for method ColumnDescriptor.compareTo()

The ticket proposes to consider the case *path.length < o.path.length* in, for method ColumnDescriptor.compareTo().

Author: proflin <proflin.me@gmail.com>

Closes #314 from proflin/PARQUET-432 and squashes the following commits:

80ba94b [proflin] Addresses PR comments
6ccd00f [proflin] Revert Updates
a4d2a4a [proflin] PARQUET-432: Complete a todo in method ColumnDescriptor.compareTo()
694b76b [proflin] Updates


Project: http://git-wip-us.apache.org/repos/asf/parquet-mr/repo
Commit: http://git-wip-us.apache.org/repos/asf/parquet-mr/commit/21e8f1d9
Tree: http://git-wip-us.apache.org/repos/asf/parquet-mr/tree/21e8f1d9
Diff: http://git-wip-us.apache.org/repos/asf/parquet-mr/diff/21e8f1d9

Branch: refs/heads/parquet-1.8.x
Commit: 21e8f1d93363a012d885a08c81317866294c7ac3
Parents: ee17c85
Author: proflin <proflin.me@gmail.com>
Authored: Fri Jan 29 11:38:34 2016 -0800
Committer: Ryan Blue <blue@apache.org>
Committed: Fri Jan 6 12:02:42 2017 -0800

----------------------------------------------------------------------
 .../apache/parquet/column/ColumnDescriptor.java |  6 +--
 .../parquet/column/TestColumnDescriptor.java    | 52 ++++++++++++++++++++
 2 files changed, 55 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/parquet-mr/blob/21e8f1d9/parquet-column/src/main/java/org/apache/parquet/column/ColumnDescriptor.java
----------------------------------------------------------------------
diff --git a/parquet-column/src/main/java/org/apache/parquet/column/ColumnDescriptor.java
b/parquet-column/src/main/java/org/apache/parquet/column/ColumnDescriptor.java
index 8244913..61f13a2 100644
--- a/parquet-column/src/main/java/org/apache/parquet/column/ColumnDescriptor.java
+++ b/parquet-column/src/main/java/org/apache/parquet/column/ColumnDescriptor.java
@@ -117,14 +117,14 @@ public class ColumnDescriptor implements Comparable<ColumnDescriptor>
{
 
   @Override
   public int compareTo(ColumnDescriptor o) {
-    // TODO(julien): this will fail if o.path.length < this.path.length
-    for (int i = 0; i < path.length; i++) {
+    int length = path.length < o.path.length ? path.length : o.path.length;
+    for (int i = 0; i < length; i++) {
       int compareTo = path[i].compareTo(o.path[i]);
       if (compareTo != 0) {
         return compareTo;
       }
     }
-    return 0;
+    return path.length - o.path.length;
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/parquet-mr/blob/21e8f1d9/parquet-column/src/test/java/org/apache/parquet/column/TestColumnDescriptor.java
----------------------------------------------------------------------
diff --git a/parquet-column/src/test/java/org/apache/parquet/column/TestColumnDescriptor.java
b/parquet-column/src/test/java/org/apache/parquet/column/TestColumnDescriptor.java
new file mode 100644
index 0000000..33d9cea
--- /dev/null
+++ b/parquet-column/src/test/java/org/apache/parquet/column/TestColumnDescriptor.java
@@ -0,0 +1,52 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.parquet.column;
+
+import org.apache.parquet.schema.PrimitiveType;
+import org.junit.Test;
+
+import static junit.framework.Assert.assertEquals;
+
+public class TestColumnDescriptor {
+
+  private ColumnDescriptor column(String... path) {
+    return new ColumnDescriptor(path, PrimitiveType.PrimitiveTypeName.INT32, 0, 0);
+  }
+
+  @Test
+  public void testComparesTo() throws Exception {
+    assertEquals(column("a").compareTo(column("a")), 0);
+    assertEquals(column("a", "b").compareTo(column("a", "b")), 0);
+
+    assertEquals(column("a").compareTo(column("b")), -1);
+    assertEquals(column("b").compareTo(column("a")), 1);
+    assertEquals(column("a", "a").compareTo(column("a", "b")), -1);
+    assertEquals(column("b", "a").compareTo(column("a", "a")), 1);
+
+    assertEquals(column("a").compareTo(column("a", "b")), -1);
+    assertEquals(column("b").compareTo(column("a", "b")), 1);
+
+    assertEquals(column("a", "b").compareTo(column("a")), 1);
+    assertEquals(column("a", "b").compareTo(column("b")), -1);
+
+    assertEquals(column("").compareTo(column("")), 0);
+    assertEquals(column("").compareTo(column("a")), -1);
+    assertEquals(column("a").compareTo(column("")), 1);
+  }
+}


Mime
View raw message