You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by na...@apache.org on 2013/11/26 02:52:06 UTC

svn commit: r1545505 - in /hive/trunk: ql/src/test/org/apache/hadoop/hive/ql/io/ serde/src/java/org/apache/hadoop/hive/serde2/columnar/ serde/src/test/org/apache/hadoop/hive/serde2/columnar/

Author: navis
Date: Tue Nov 26 01:52:05 2013
New Revision: 1545505

URL: http://svn.apache.org/r1545505
Log:
HIVE-5839 : BytesRefArrayWritable compareTo violates contract (Xuefu Zhang via Navis)

Added:
    hive/trunk/serde/src/test/org/apache/hadoop/hive/serde2/columnar/TestBytesRefArrayWritable.java
Modified:
    hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/io/TestRCFile.java
    hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/columnar/BytesRefArrayWritable.java

Modified: hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/io/TestRCFile.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/io/TestRCFile.java?rev=1545505&r1=1545504&r2=1545505&view=diff
==============================================================================
--- hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/io/TestRCFile.java (original)
+++ hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/io/TestRCFile.java Tue Nov 26 01:52:05 2013
@@ -135,9 +135,11 @@ public class TestRCFile {
       patialS.set(2, new BytesRefWritable("789".getBytes("UTF-8")));
       patialS.set(3, new BytesRefWritable("1000".getBytes("UTF-8")));
       patialS.set(4, new BytesRefWritable("NULL".getBytes("UTF-8")));
-      patialS.set(5, new BytesRefWritable("NULL".getBytes("UTF-8")));
+      // LazyString has no so-called NULL sequence. The value is empty string if not.
+      patialS.set(5, new BytesRefWritable("".getBytes("UTF-8")));
       patialS.set(6, new BytesRefWritable("NULL".getBytes("UTF-8")));
-      patialS.set(7, new BytesRefWritable("NULL".getBytes("UTF-8")));
+      // LazyString has no so-called NULL sequence. The value is empty string if not.
+      patialS.set(7, new BytesRefWritable("".getBytes("UTF-8")));
 
     } catch (UnsupportedEncodingException e) {
       throw new RuntimeException(e);

Modified: hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/columnar/BytesRefArrayWritable.java
URL: http://svn.apache.org/viewvc/hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/columnar/BytesRefArrayWritable.java?rev=1545505&r1=1545504&r2=1545505&view=diff
==============================================================================
--- hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/columnar/BytesRefArrayWritable.java (original)
+++ hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/columnar/BytesRefArrayWritable.java Tue Nov 26 01:52:05 2013
@@ -139,38 +139,15 @@ public class BytesRefArrayWritable imple
       return sizeDiff;
     }
     for (int i = 0; i < valid; i++) {
-      if (other.contains(bytesRefWritables[i])) {
-        continue;
-      } else {
-        return 1;
+      int res = bytesRefWritables[i].compareTo(other.bytesRefWritables[i]);
+      if (res != 0) {
+        return res;
       }
     }
     return 0;
   }
 
   /**
-   * Returns <tt>true</tt> if this instance contains one or more the specified
-   * BytesRefWritable.
-   *
-   * @param bytesRefWritable
-   *          BytesRefWritable element to be tested
-   * @return <tt>true</tt> if contains the specified element
-   * @throws IllegalArgumentException
-   *           if the specified element is null
-   */
-  public boolean contains(BytesRefWritable bytesRefWritable) {
-    if (bytesRefWritable == null) {
-      throw new IllegalArgumentException("Argument can not be null.");
-    }
-    for (int i = 0; i < valid; i++) {
-      if (bytesRefWritables[i].equals(bytesRefWritable)) {
-        return true;
-      }
-    }
-    return false;
-  }
-
-  /**
    * {@inheritDoc}
    */
   @Override

Added: hive/trunk/serde/src/test/org/apache/hadoop/hive/serde2/columnar/TestBytesRefArrayWritable.java
URL: http://svn.apache.org/viewvc/hive/trunk/serde/src/test/org/apache/hadoop/hive/serde2/columnar/TestBytesRefArrayWritable.java?rev=1545505&view=auto
==============================================================================
--- hive/trunk/serde/src/test/org/apache/hadoop/hive/serde2/columnar/TestBytesRefArrayWritable.java (added)
+++ hive/trunk/serde/src/test/org/apache/hadoop/hive/serde2/columnar/TestBytesRefArrayWritable.java Tue Nov 26 01:52:05 2013
@@ -0,0 +1,50 @@
+/**
+ * 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.hadoop.hive.serde2.columnar;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class TestBytesRefArrayWritable {
+  private final BytesRefArrayWritable left = new BytesRefArrayWritable(4);
+  private final BytesRefArrayWritable right = new BytesRefArrayWritable(4);
+
+  @Before
+  public void setup() throws Exception {
+    left.set(0, new BytesRefWritable("123".getBytes("UTF-8")));
+    left.set(1, new BytesRefWritable("456".getBytes("UTF-8")));
+    left.set(2, new BytesRefWritable("789".getBytes("UTF-8")));
+    left.set(3, new BytesRefWritable("1000".getBytes("UTF-8")));
+
+    right.set(0, new BytesRefWritable("123".getBytes("UTF-8")));
+    right.set(1, new BytesRefWritable("456".getBytes("UTF-8")));
+    right.set(2, new BytesRefWritable("289".getBytes("UTF-8")));
+    right.set(3, new BytesRefWritable("1000".getBytes("UTF-8")));
+  }
+
+  @Test // HIVE-5839
+  public void testCompareTo() {
+    int a = left.compareTo(right);
+    int b = right.compareTo(left);
+    Assert.assertEquals("a.compareTo(b) should be equal to -b.compareTo(a)", a, -b );
+    Assert.assertEquals("An object must be equal to itself", 0, left.compareTo(left));
+  }
+
+}