From 5b2a11b7c1b35d78985dfc523fe616a095e95864 Mon Sep 17 00:00:00 2001 From: Mehant Baid Date: Fri, 23 Jan 2015 14:00:46 -0800 Subject: [PATCH] DRILL-2066: Clear target vectors before performing transfer() --- .../codegen/templates/FixedValueVectors.java | 1 + .../templates/RepeatedValueVectors.java | 1 + .../templates/VariableLengthVectors.java | 1 + .../exec/physical/impl/sort/TestSort.java | 33 +++++++++++++++++++ .../jsoninput/repeatedmap_sort_bug.json | 1 + 5 files changed, 37 insertions(+) create mode 100644 exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/sort/TestSort.java create mode 100644 exec/java-exec/src/test/resources/jsoninput/repeatedmap_sort_bug.json diff --git a/exec/java-exec/src/main/codegen/templates/FixedValueVectors.java b/exec/java-exec/src/main/codegen/templates/FixedValueVectors.java index 166353475ac..b6eb0840c82 100644 --- a/exec/java-exec/src/main/codegen/templates/FixedValueVectors.java +++ b/exec/java-exec/src/main/codegen/templates/FixedValueVectors.java @@ -159,6 +159,7 @@ public TransferPair makeTransferPair(ValueVector to) { } public void transferTo(${minor.class}Vector target){ + target.clear(); target.data = data; target.data.retain(); target.data.writerIndex(data.writerIndex()); diff --git a/exec/java-exec/src/main/codegen/templates/RepeatedValueVectors.java b/exec/java-exec/src/main/codegen/templates/RepeatedValueVectors.java index 572181e1529..d39040e4731 100644 --- a/exec/java-exec/src/main/codegen/templates/RepeatedValueVectors.java +++ b/exec/java-exec/src/main/codegen/templates/RepeatedValueVectors.java @@ -100,6 +100,7 @@ public TransferPair makeTransferPair(ValueVector to) { } public void transferTo(Repeated${minor.class}Vector target){ + target.clear(); offsets.transferTo(target.offsets); values.transferTo(target.values); target.parentValueCount = parentValueCount; diff --git a/exec/java-exec/src/main/codegen/templates/VariableLengthVectors.java b/exec/java-exec/src/main/codegen/templates/VariableLengthVectors.java index 9c6454e0388..aa5b702210b 100644 --- a/exec/java-exec/src/main/codegen/templates/VariableLengthVectors.java +++ b/exec/java-exec/src/main/codegen/templates/VariableLengthVectors.java @@ -161,6 +161,7 @@ public TransferPair makeTransferPair(ValueVector to) { } public void transferTo(${minor.class}Vector target){ + target.clear(); this.offsetVector.transferTo(target.offsetVector); target.data = data; target.data.retain(); diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/sort/TestSort.java b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/sort/TestSort.java new file mode 100644 index 00000000000..5dc81b5ee8a --- /dev/null +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/sort/TestSort.java @@ -0,0 +1,33 @@ +/** + * 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.exec.physical.impl.sort; + +import org.apache.drill.BaseTestQuery; +import org.junit.Test; + +/** + * Placeholder for all sort related test. Can be used as we move + * more tests to use the new test framework + */ +public class TestSort extends BaseTestQuery { + + @Test + public void testSortWithComplexInput() throws Exception { + test("select t.a from cp.`jsoninput/repeatedmap_sort_bug.json` t order by t.b"); + } +} \ No newline at end of file diff --git a/exec/java-exec/src/test/resources/jsoninput/repeatedmap_sort_bug.json b/exec/java-exec/src/test/resources/jsoninput/repeatedmap_sort_bug.json new file mode 100644 index 00000000000..1968133a37a --- /dev/null +++ b/exec/java-exec/src/test/resources/jsoninput/repeatedmap_sort_bug.json @@ -0,0 +1 @@ +{"a" : [ {"c": 1} ], "b" : 2.1} \ No newline at end of file