drill-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From par...@apache.org
Subject drill git commit: DRILL-1555: fix a problem in ArraySegment cloning logic
Date Sat, 17 Jan 2015 00:31:01 GMT
Repository: drill
Updated Branches:
  refs/heads/master bd4d669d1 -> 289348f95


DRILL-1555: fix a problem in ArraySegment cloning logic


Project: http://git-wip-us.apache.org/repos/asf/drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/drill/commit/289348f9
Tree: http://git-wip-us.apache.org/repos/asf/drill/tree/289348f9
Diff: http://git-wip-us.apache.org/repos/asf/drill/diff/289348f9

Branch: refs/heads/master
Commit: 289348f955af620403c4a95b01c065918e3e1510
Parents: bd4d669
Author: Hanifi Gunes <hgunes@maprtech.com>
Authored: Thu Jan 15 15:40:35 2015 -0800
Committer: Parth Chandra <pchandra@maprtech.com>
Committed: Fri Jan 16 16:30:28 2015 -0800

----------------------------------------------------------------------
 .../drill/common/expression/PathSegment.java    |  4 +-
 .../common/expression/PathSegmentTests.java     | 45 ++++++++++++++++++++
 2 files changed, 47 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/drill/blob/289348f9/common/src/main/java/org/apache/drill/common/expression/PathSegment.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/drill/common/expression/PathSegment.java b/common/src/main/java/org/apache/drill/common/expression/PathSegment.java
index 24dd945..744a07f 100644
--- a/common/src/main/java/org/apache/drill/common/expression/PathSegment.java
+++ b/common/src/main/java/org/apache/drill/common/expression/PathSegment.java
@@ -99,7 +99,7 @@ public abstract class PathSegment{
 
     @Override
     public PathSegment clone() {
-      PathSegment seg = new ArraySegment(index);
+      PathSegment seg = index < 0 ? new ArraySegment(null) : new ArraySegment(index);
       if (child != null) {
         seg.setChild(child.clone());
       }
@@ -108,7 +108,7 @@ public abstract class PathSegment{
 
     @Override
     public ArraySegment cloneWithNewChild(PathSegment newChild) {
-      ArraySegment seg = new ArraySegment(index);
+      ArraySegment seg = index < 0 ? new ArraySegment(null) : new ArraySegment(index);
       if (child != null) {
         seg.setChild(child.cloneWithNewChild(newChild));
       } else {

http://git-wip-us.apache.org/repos/asf/drill/blob/289348f9/common/src/test/java/org/apache/drill/common/expression/PathSegmentTests.java
----------------------------------------------------------------------
diff --git a/common/src/test/java/org/apache/drill/common/expression/PathSegmentTests.java
b/common/src/test/java/org/apache/drill/common/expression/PathSegmentTests.java
new file mode 100644
index 0000000..07b2385
--- /dev/null
+++ b/common/src/test/java/org/apache/drill/common/expression/PathSegmentTests.java
@@ -0,0 +1,45 @@
+/**
+ * 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.drill.common.expression;
+
+import org.apache.drill.test.DrillTest;
+import org.junit.Test;
+
+public class PathSegmentTests extends DrillTest {
+
+  protected PathSegment makeArraySegment(final int len, final PathSegment tail) {
+    PathSegment node = tail;
+    for (int i=0; i<len; i++) {
+      node = new PathSegment.ArraySegment(node);
+    }
+    return node;
+  }
+
+  @Test
+  public void testIfMultiLevelCloneWorks() {
+    final int levels = 10;
+    final PathSegment segment = new PathSegment.NameSegment("test", makeArraySegment(levels,
null));
+    final PathSegment clone = segment.clone();
+    assert segment.equals(clone) : "result of clone & original segments must be identical";
+
+    final PathSegment tail = new PathSegment.NameSegment("tail");
+    final PathSegment newSegment = new PathSegment.NameSegment("test", makeArraySegment(levels,
tail));
+    final PathSegment newClone = segment.cloneWithNewChild(tail);
+    assert newSegment.equals(newClone) : "result of cloneWithChild & original segment
must be identical";
+  }
+}


Mime
View raw message