aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorHanifi Gunes <hgunes@maprtech.com>2015-01-15 15:40:35 -0800
committerParth Chandra <pchandra@maprtech.com>2015-01-16 16:30:28 -0800
commit289348f955af620403c4a95b01c065918e3e1510 (patch)
tree945411d06b7fe81fd60dc2364e460b0591568f73 /common
parentbd4d669d1b836d6990eb3701e81c56f3d109db18 (diff)
DRILL-1555: fix a problem in ArraySegment cloning logic
Diffstat (limited to 'common')
-rw-r--r--common/src/main/java/org/apache/drill/common/expression/PathSegment.java4
-rw-r--r--common/src/test/java/org/apache/drill/common/expression/PathSegmentTests.java45
2 files changed, 47 insertions, 2 deletions
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 24dd945d4..744a07f63 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 {
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 000000000..07b23851f
--- /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";
+ }
+}