From 289348f955af620403c4a95b01c065918e3e1510 Mon Sep 17 00:00:00 2001 From: Hanifi Gunes Date: Thu, 15 Jan 2015 15:40:35 -0800 Subject: DRILL-1555: fix a problem in ArraySegment cloning logic --- .../drill/common/expression/PathSegment.java | 4 +- .../drill/common/expression/PathSegmentTests.java | 45 ++++++++++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 common/src/test/java/org/apache/drill/common/expression/PathSegmentTests.java (limited to 'common') 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