From c13551e049de93519fa0fa5bd132056a1616b7f6 Mon Sep 17 00:00:00 2001 From: Laksh Singla Date: Thu, 14 Dec 2023 20:18:23 +0530 Subject: [PATCH] remove wrappers --- .../druid/frame/write/FrameWriterUtils.java | 10 - ...rrayLongGroupByColumnSelectorStrategy.java | 2 + ...yNumericGroupByColumnSelectorStrategy.java | 4 +- ...ayStringGroupByColumnSelectorStrategy.java | 5 +- .../druid/segment/DimensionHandlerUtils.java | 37 +-- .../druid/segment/data/ComparableList.java | 156 ---------- .../segment/data/ComparableStringArray.java | 172 ----------- .../query/groupby/GroupByQueryRunnerTest.java | 268 +++++++++--------- .../druid/query/groupby/GroupByQueryTest.java | 8 +- .../groupby/NestedGroupByArrayQueryTest.java | 34 +-- ...ubleGroupByColumnSelectorStrategyTest.java | 7 +- ...LongGroupByColumnSelectorStrategyTest.java | 7 +- ...ringGroupByColumnSelectorStrategyTest.java | 7 +- .../segment/DimensionHandlerUtilsTest.java | 92 +++--- .../org/apache/druid/segment/TestHelper.java | 12 - .../segment/data/ComparableListTest.java | 75 ----- .../data/ComparableStringArrayTest.java | 76 ----- .../server/ClientQuerySegmentWalkerTest.java | 52 ++-- .../druid/sql/calcite/run/SqlResults.java | 6 - .../druid/sql/calcite/run/SqlResultsTest.java | 10 - 20 files changed, 256 insertions(+), 784 deletions(-) delete mode 100644 processing/src/main/java/org/apache/druid/segment/data/ComparableList.java delete mode 100644 processing/src/main/java/org/apache/druid/segment/data/ComparableStringArray.java delete mode 100644 processing/src/test/java/org/apache/druid/segment/data/ComparableListTest.java delete mode 100644 processing/src/test/java/org/apache/druid/segment/data/ComparableStringArrayTest.java diff --git a/processing/src/main/java/org/apache/druid/frame/write/FrameWriterUtils.java b/processing/src/main/java/org/apache/druid/frame/write/FrameWriterUtils.java index ac9574d7f052..864a9cc183e3 100644 --- a/processing/src/main/java/org/apache/druid/frame/write/FrameWriterUtils.java +++ b/processing/src/main/java/org/apache/druid/frame/write/FrameWriterUtils.java @@ -34,8 +34,6 @@ import org.apache.druid.segment.column.ColumnType; import org.apache.druid.segment.column.RowSignature; import org.apache.druid.segment.data.ComparableIntArray; -import org.apache.druid.segment.data.ComparableList; -import org.apache.druid.segment.data.ComparableStringArray; import org.apache.druid.segment.data.IndexedInts; import javax.annotation.Nullable; @@ -164,10 +162,6 @@ public static List getUtf8ByteBuffersFromStringArraySelector( for (Object value : (Object[]) row) { retVal.add(getUtf8ByteBufferFromString((String) value)); } - } else if (row instanceof ComparableStringArray) { - for (String value : ((ComparableStringArray) row).getDelegate()) { - retVal.add(getUtf8ByteBufferFromString(value)); - } } else { throw new ISE("Unexpected type %s found", row.getClass().getName()); } @@ -201,10 +195,6 @@ public static List getNumericArrayFromObject(Object row) for (Object value : (Object[]) row) { retVal.add((Number) value); } - } else if (row instanceof ComparableList) { - for (Object value : ((ComparableList) row).getDelegate()) { - retVal.add((Number) value); - } } else if (row instanceof ComparableIntArray) { for (int value : ((ComparableIntArray) row).getDelegate()) { retVal.add(value); diff --git a/processing/src/main/java/org/apache/druid/query/groupby/epinephelinae/column/ArrayLongGroupByColumnSelectorStrategy.java b/processing/src/main/java/org/apache/druid/query/groupby/epinephelinae/column/ArrayLongGroupByColumnSelectorStrategy.java index d8bf092768d3..b89ed07eafce 100644 --- a/processing/src/main/java/org/apache/druid/query/groupby/epinephelinae/column/ArrayLongGroupByColumnSelectorStrategy.java +++ b/processing/src/main/java/org/apache/druid/query/groupby/epinephelinae/column/ArrayLongGroupByColumnSelectorStrategy.java @@ -24,10 +24,12 @@ import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; import org.apache.druid.java.util.common.ISE; import org.apache.druid.segment.ColumnValueSelector; +import org.apache.druid.segment.DimensionHandlerUtils; import org.apache.druid.segment.column.ValueType; import java.util.Arrays; import java.util.List; +import java.util.function.Function; import java.util.stream.Collectors; public class ArrayLongGroupByColumnSelectorStrategy extends ArrayNumericGroupByColumnSelectorStrategy diff --git a/processing/src/main/java/org/apache/druid/query/groupby/epinephelinae/column/ArrayNumericGroupByColumnSelectorStrategy.java b/processing/src/main/java/org/apache/druid/query/groupby/epinephelinae/column/ArrayNumericGroupByColumnSelectorStrategy.java index cb8c53446d9b..3f38d44bf013 100644 --- a/processing/src/main/java/org/apache/druid/query/groupby/epinephelinae/column/ArrayNumericGroupByColumnSelectorStrategy.java +++ b/processing/src/main/java/org/apache/druid/query/groupby/epinephelinae/column/ArrayNumericGroupByColumnSelectorStrategy.java @@ -28,7 +28,6 @@ import org.apache.druid.query.ordering.StringComparator; import org.apache.druid.query.ordering.StringComparators; import org.apache.druid.segment.ColumnValueSelector; -import org.apache.druid.segment.data.ComparableList; import javax.annotation.Nullable; import java.nio.ByteBuffer; @@ -39,6 +38,7 @@ public abstract class ArrayNumericGroupByColumnSelectorStrategy { protected static final int GROUP_BY_MISSING_VALUE = -1; + // TODO(laksh): Keep the dictionary types as List instead of Object[] to allow for equality comparisons protected final List> dictionary; protected final Object2IntMap> reverseDictionary; protected long estimatedFootprint = 0L; @@ -83,7 +83,7 @@ public void processValueFromGroupingKey( // GROUP_BY_MISSING_VALUE is used to indicate empty rows, which are omitted from the result map. if (id != GROUP_BY_MISSING_VALUE) { final List value = dictionary.get(id); - resultRow.set(selectorPlus.getResultRowPosition(), new ComparableList(value)); + resultRow.set(selectorPlus.getResultRowPosition(), value); } else { resultRow.set(selectorPlus.getResultRowPosition(), null); } diff --git a/processing/src/main/java/org/apache/druid/query/groupby/epinephelinae/column/ArrayStringGroupByColumnSelectorStrategy.java b/processing/src/main/java/org/apache/druid/query/groupby/epinephelinae/column/ArrayStringGroupByColumnSelectorStrategy.java index 57cd96360ea0..375496671fa2 100644 --- a/processing/src/main/java/org/apache/druid/query/groupby/epinephelinae/column/ArrayStringGroupByColumnSelectorStrategy.java +++ b/processing/src/main/java/org/apache/druid/query/groupby/epinephelinae/column/ArrayStringGroupByColumnSelectorStrategy.java @@ -31,7 +31,6 @@ import org.apache.druid.segment.ColumnValueSelector; import org.apache.druid.segment.column.ValueType; import org.apache.druid.segment.data.ComparableIntArray; -import org.apache.druid.segment.data.ComparableStringArray; import javax.annotation.Nullable; import java.nio.ByteBuffer; @@ -90,11 +89,11 @@ public void processValueFromGroupingKey( final int[] intRepresentation = intListToInt.inverse() .get(id) .getDelegate(); - final String[] stringRepresentaion = new String[intRepresentation.length]; + final Object[] stringRepresentaion = new Object[intRepresentation.length]; for (int i = 0; i < intRepresentation.length; i++) { stringRepresentaion[i] = dictionaryToInt.inverse().get(intRepresentation[i]); } - resultRow.set(selectorPlus.getResultRowPosition(), ComparableStringArray.of(stringRepresentaion)); + resultRow.set(selectorPlus.getResultRowPosition(), stringRepresentaion); } else { resultRow.set(selectorPlus.getResultRowPosition(), null); } diff --git a/processing/src/main/java/org/apache/druid/segment/DimensionHandlerUtils.java b/processing/src/main/java/org/apache/druid/segment/DimensionHandlerUtils.java index 60182b549897..13585eada6b6 100644 --- a/processing/src/main/java/org/apache/druid/segment/DimensionHandlerUtils.java +++ b/processing/src/main/java/org/apache/druid/segment/DimensionHandlerUtils.java @@ -40,12 +40,11 @@ import org.apache.druid.segment.column.ColumnType; import org.apache.druid.segment.column.TypeSignature; import org.apache.druid.segment.column.ValueType; -import org.apache.druid.segment.data.ComparableList; -import org.apache.druid.segment.data.ComparableStringArray; import javax.annotation.Nullable; import java.math.BigDecimal; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Objects; import java.util.concurrent.ConcurrentHashMap; @@ -300,6 +299,9 @@ public static String convertObjectToString(@Nullable Object valObj) { if (valObj == null) { return null; + } else if (valObj instanceof Object[]) { + // TODO(laksh): Get this change vetted + return Arrays.toString((Object[]) valObj); } return valObj.toString(); } @@ -407,11 +409,11 @@ public static Object convertObjectToType( case STRING: return coerceToStringArray(obj); case LONG: - return coerceToObjectWithCoercionFunction(obj, DimensionHandlerUtils::convertObjectToLong); + return coerceToObjectArrayWithElementCoercionFunction(obj, DimensionHandlerUtils::convertObjectToLong); case FLOAT: - return coerceToObjectWithCoercionFunction(obj, DimensionHandlerUtils::convertObjectToFloat); + return coerceToObjectArrayWithElementCoercionFunction(obj, DimensionHandlerUtils::convertObjectToFloat); case DOUBLE: - return coerceToObjectWithCoercionFunction(obj, DimensionHandlerUtils::convertObjectToDouble); + return coerceToObjectArrayWithElementCoercionFunction(obj, DimensionHandlerUtils::convertObjectToDouble); } default: @@ -424,21 +426,23 @@ public static Object[] convertToList(Object obj, ValueType elementType) { switch (elementType) { case LONG: - return coerceToObjectWithCoercionFunction(obj, DimensionHandlerUtils::convertObjectToLong); + return coerceToObjectArrayWithElementCoercionFunction(obj, DimensionHandlerUtils::convertObjectToLong); case FLOAT: - return coerceToObjectWithCoercionFunction(obj, DimensionHandlerUtils::convertObjectToFloat); + return coerceToObjectArrayWithElementCoercionFunction(obj, DimensionHandlerUtils::convertObjectToFloat); case DOUBLE: - return coerceToObjectWithCoercionFunction(obj, DimensionHandlerUtils::convertObjectToDouble); + return coerceToObjectArrayWithElementCoercionFunction(obj, DimensionHandlerUtils::convertObjectToDouble); } throw new ISE( - "Unable to convert object of type[%s] to [%s]", - obj.getClass().getName(), - ComparableList.class.getName() + "Unable to convert object of type[%s] to Object[]", + obj.getClass().getName() ); } - private static Object[] coerceToObjectWithCoercionFunction(Object obj, Function coercionFunction) + public static Object[] coerceToObjectArrayWithElementCoercionFunction( + Object obj, + Function coercionFunction + ) { if (obj == null) { return null; @@ -455,14 +459,13 @@ private static Object[] coerceToObjectWithCoercionFunction(Object obj, Function< Object[] objects = (Object[]) obj; Object[] retVal = new Object[objects.length]; for (int i = 0; i < objects.length; i++) { - retVal[i] = convertObjectToString(objects[i]); + retVal[i] = coercionFunction.apply(objects[i]); } return retVal; } throw new ISE( - "Unable to convert object of type[%s] to [%s]", - obj.getClass().getName(), - ComparableStringArray.class.getName() + "Unable to convert object of type[%s] to Object[]", + obj.getClass().getName() ); } @@ -470,7 +473,7 @@ private static Object[] coerceToObjectWithCoercionFunction(Object obj, Function< @Nullable public static Object[] coerceToStringArray(Object obj) { - return coerceToObjectWithCoercionFunction(obj, DimensionHandlerUtils::convertObjectToString); + return coerceToObjectArrayWithElementCoercionFunction(obj, DimensionHandlerUtils::convertObjectToString); } public static int compareObjectsAsType( diff --git a/processing/src/main/java/org/apache/druid/segment/data/ComparableList.java b/processing/src/main/java/org/apache/druid/segment/data/ComparableList.java deleted file mode 100644 index bf716df085d6..000000000000 --- a/processing/src/main/java/org/apache/druid/segment/data/ComparableList.java +++ /dev/null @@ -1,156 +0,0 @@ -/* - * 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.druid.segment.data; - -import com.fasterxml.jackson.annotation.JsonValue; -import com.google.common.base.Preconditions; -import org.apache.druid.query.ordering.StringComparator; -import org.apache.druid.query.ordering.StringComparators; - -import java.util.List; - - -public class ComparableList -{ - private final List delegate; - - public ComparableList(List input) - { - Preconditions.checkArgument( - input != null, - "Input cannot be null for %s", - ComparableList.class.getName() - ); - this.delegate = input; - } - - @JsonValue - public List getDelegate() - { - return delegate; - } - - @Override - public int hashCode() - { - return delegate.hashCode(); - } - - - @Override - public boolean equals(Object obj) - { - if (this == obj) { - return true; - } - if (obj == null || getClass() != obj.getClass()) { - return false; - } - - return this.delegate.equals(((ComparableList) obj).getDelegate()); - } - - public int compareTo(ComparableList rhs) - { - if (rhs == null) { - return 1; - } - - final int minSize = Math.min(this.getDelegate().size(), rhs.getDelegate().size()); - - if (this.delegate == rhs.getDelegate()) { - return 0; - } else { - for (int i = 0; i < minSize; i++) { - final int cmp; - T first = this.delegate.get(i); - Object second = rhs.getDelegate().get(i); - if (first == null && second == null) { - cmp = 0; - } else if (first == null) { - cmp = -1; - } else if (second == null) { - cmp = 1; - } else { - cmp = first.compareTo(second); - } - if (cmp == 0) { - continue; - } - return cmp; - } - if (this.getDelegate().size() == rhs.getDelegate().size()) { - return 0; - } else if (this.getDelegate().size() < rhs.getDelegate().size()) { - return -1; - } else { - return 1; - } - } - } - - @Override - public String toString() - { - return delegate.toString(); - } - - public static int compareWithComparator( - StringComparator stringComparator, - ComparableList lhsComparableArray, - ComparableList rhsComparableArray - ) - { - final StringComparator comparator = stringComparator == null - ? StringComparators.NUMERIC - : stringComparator; - - if (lhsComparableArray == null && rhsComparableArray == null) { - return 0; - } else if (lhsComparableArray == null) { - return -1; - } else if (rhsComparableArray == null) { - return 1; - } - - List lhs = lhsComparableArray.getDelegate(); - List rhs = rhsComparableArray.getDelegate(); - - int minLength = Math.min(lhs.size(), rhs.size()); - - //noinspection ArrayEquality - if (lhs == rhs) { - return 0; - } - for (int i = 0; i < minLength; i++) { - final int cmp = comparator.compare(String.valueOf(lhs.get(i)), String.valueOf(rhs.get(i))); - if (cmp == 0) { - continue; - } - return cmp; - } - if (lhs.size() == rhs.size()) { - return 0; - } else if (lhs.size() < rhs.size()) { - return -1; - } - return 1; - } -} diff --git a/processing/src/main/java/org/apache/druid/segment/data/ComparableStringArray.java b/processing/src/main/java/org/apache/druid/segment/data/ComparableStringArray.java deleted file mode 100644 index 0f66483a47ec..000000000000 --- a/processing/src/main/java/org/apache/druid/segment/data/ComparableStringArray.java +++ /dev/null @@ -1,172 +0,0 @@ -/* - * 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.druid.segment.data; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonValue; -import org.apache.druid.query.ordering.StringComparator; -import org.apache.druid.query.ordering.StringComparators; - -import java.util.Arrays; - -public class ComparableStringArray implements Comparable -{ - public static final ComparableStringArray EMPTY_ARRAY = new ComparableStringArray(new String[0]); - - final String[] delegate; - private int hashCode; - private boolean hashCodeComputed; - - private ComparableStringArray(String[] array) - { - delegate = array; - } - - @JsonCreator - public static ComparableStringArray of(String... array) - { - if (array.length == 0) { - return EMPTY_ARRAY; - } else { - return new ComparableStringArray(array); - } - } - - @JsonValue - public String[] getDelegate() - { - return delegate; - } - - @Override - public int hashCode() - { - // Check is not thread-safe, but that's fine. Even if used by multiple threads, it's ok to write these primitive - // fields more than once. - // As ComparableIntArray is used in hot loop caching the hashcode - if (!hashCodeComputed) { - hashCode = Arrays.hashCode(delegate); - hashCodeComputed = true; - } - - return hashCode; - } - - @Override - public boolean equals(Object obj) - { - if (this == obj) { - return true; - } - if (obj == null || getClass() != obj.getClass()) { - return false; - } - - return Arrays.equals(delegate, ((ComparableStringArray) obj).getDelegate()); - } - - @Override - public int compareTo(ComparableStringArray rhs) - { - // rhs.getDelegate() cannot be null - if (rhs == null) { - return 1; - } - final int minSize = Math.min(this.getDelegate().length, rhs.getDelegate().length); - //noinspection ArrayEquality - if (this.delegate == rhs.getDelegate()) { - return 0; - } else { - for (int i = 0; i < minSize; i++) { - final int cmp; - String first = this.delegate[i]; - String second = rhs.getDelegate()[i]; - if (first == null && second == null) { - cmp = 0; - } else if (first == null) { - cmp = -1; - } else if (second == null) { - cmp = 1; - } else { - cmp = first.compareTo(second); - } - if (cmp == 0) { - continue; - } - return cmp; - } - if (this.getDelegate().length == rhs.getDelegate().length) { - return 0; - } else if (this.getDelegate().length < rhs.getDelegate().length) { - return -1; - } else { - return 1; - } - } - } - - @Override - public String toString() - { - return Arrays.toString(delegate); - } - - - public static int compareWithComparator( - StringComparator stringComparator, - ComparableStringArray lhsComparableArray, - ComparableStringArray rhsComparableArray - ) - { - final StringComparator comparator = stringComparator == null - ? StringComparators.LEXICOGRAPHIC - : stringComparator; - if (lhsComparableArray == null && rhsComparableArray == null) { - return 0; - } else if (lhsComparableArray == null) { - return -1; - } else if (rhsComparableArray == null) { - return 1; - } - - String[] lhs = lhsComparableArray.getDelegate(); - String[] rhs = rhsComparableArray.getDelegate(); - - int minLength = Math.min(lhs.length, rhs.length); - - //noinspection ArrayEquality - if (lhs == rhs) { - return 0; - } - for (int i = 0; i < minLength; i++) { - final int cmp = comparator.compare(lhs[i], rhs[i]); - if (cmp == 0) { - continue; - } - return cmp; - } - if (lhs.length == rhs.length) { - return 0; - } else if (lhs.length < rhs.length) { - return -1; - } - return 1; - } -} diff --git a/processing/src/test/java/org/apache/druid/query/groupby/GroupByQueryRunnerTest.java b/processing/src/test/java/org/apache/druid/query/groupby/GroupByQueryRunnerTest.java index bb16a5d4b4c0..7dbf78879b09 100644 --- a/processing/src/test/java/org/apache/druid/query/groupby/GroupByQueryRunnerTest.java +++ b/processing/src/test/java/org/apache/druid/query/groupby/GroupByQueryRunnerTest.java @@ -130,8 +130,6 @@ import org.apache.druid.segment.TestHelper; import org.apache.druid.segment.column.ColumnHolder; import org.apache.druid.segment.column.ColumnType; -import org.apache.druid.segment.data.ComparableList; -import org.apache.druid.segment.data.ComparableStringArray; import org.apache.druid.segment.virtual.ExpressionVirtualColumn; import org.apache.druid.testing.InitializedNullHandlingTest; import org.hamcrest.BaseMatcher; @@ -1346,14 +1344,14 @@ public void testMultiValueDimensionAsArray() .build(); List expectedResults = Arrays.asList( - makeRow(query, "2011-04-01", "alias", ComparableStringArray.of("a", "preferred"), "rows", 2L, "idx", 282L), - makeRow(query, "2011-04-01", "alias", ComparableStringArray.of("b", "preferred"), "rows", 2L, "idx", 230L), - makeRow(query, "2011-04-01", "alias", ComparableStringArray.of("e", "preferred"), "rows", 2L, "idx", 324L), - makeRow(query, "2011-04-01", "alias", ComparableStringArray.of("h", "preferred"), "rows", 2L, "idx", 233L), - makeRow(query, "2011-04-01", "alias", ComparableStringArray.of("m", "preferred"), "rows", 6L, "idx", 5317L), - makeRow(query, "2011-04-01", "alias", ComparableStringArray.of("n", "preferred"), "rows", 2L, "idx", 235L), - makeRow(query, "2011-04-01", "alias", ComparableStringArray.of("p", "preferred"), "rows", 6L, "idx", 5405L), - makeRow(query, "2011-04-01", "alias", ComparableStringArray.of("preferred", "t"), "rows", 4L, "idx", 420L) + makeRow(query, "2011-04-01", "alias", new Object[]{"a", "preferred"}, "rows", 2L, "idx", 282L), + makeRow(query, "2011-04-01", "alias", new Object[]{"b", "preferred"}, "rows", 2L, "idx", 230L), + makeRow(query, "2011-04-01", "alias", new Object[]{"e", "preferred"}, "rows", 2L, "idx", 324L), + makeRow(query, "2011-04-01", "alias", new Object[]{"h", "preferred"}, "rows", 2L, "idx", 233L), + makeRow(query, "2011-04-01", "alias", new Object[]{"m", "preferred"}, "rows", 6L, "idx", 5317L), + makeRow(query, "2011-04-01", "alias", new Object[]{"n", "preferred"}, "rows", 2L, "idx", 235L), + makeRow(query, "2011-04-01", "alias", new Object[]{"p", "preferred"}, "rows", 6L, "idx", 5405L), + makeRow(query, "2011-04-01", "alias", new Object[]{"preferred", "t"}, "rows", 4L, "idx", 420L) ); Iterable results = GroupByQueryRunnerTestHelper.runQuery(factory, runner, query); @@ -1386,7 +1384,7 @@ public void testSingleValueDimensionAsArray() List expectedResults = ImmutableList.of( makeRow(query, "2011-04-01", "alias", - ComparableStringArray.of("preferred"), "rows", 26L, "idx", 12446L + new Object[]{"preferred"}, "rows", 26L, "idx", 12446L ) ); @@ -1434,7 +1432,7 @@ public void testMultiValueDimensionAsArrayWithOtherDims() query, "2011-04-01", "alias", - ComparableStringArray.of("a", "preferred"), + new Object[]{"a", "preferred"}, "quality", "automotive", "rows", @@ -1446,7 +1444,7 @@ public void testMultiValueDimensionAsArrayWithOtherDims() query, "2011-04-01", "alias", - ComparableStringArray.of("b", "preferred"), + new Object[]{"b", "preferred"}, "quality", "business", "rows", @@ -1458,7 +1456,7 @@ public void testMultiValueDimensionAsArrayWithOtherDims() query, "2011-04-01", "alias", - ComparableStringArray.of("e", "preferred"), + new Object[]{"e", "preferred"}, "quality", "entertainment", "rows", @@ -1470,7 +1468,7 @@ public void testMultiValueDimensionAsArrayWithOtherDims() query, "2011-04-01", "alias", - ComparableStringArray.of("h", "preferred"), + new Object[]{"h", "preferred"}, "quality", "health", "rows", @@ -1482,7 +1480,7 @@ public void testMultiValueDimensionAsArrayWithOtherDims() query, "2011-04-01", "alias", - ComparableStringArray.of("m", "preferred"), + new Object[]{"m", "preferred"}, "quality", "mezzanine", "rows", @@ -1494,7 +1492,7 @@ public void testMultiValueDimensionAsArrayWithOtherDims() query, "2011-04-01", "alias", - ComparableStringArray.of("n", "preferred"), + new Object[]{"n", "preferred"}, "quality", "news", "rows", @@ -1506,7 +1504,7 @@ public void testMultiValueDimensionAsArrayWithOtherDims() query, "2011-04-01", "alias", - ComparableStringArray.of("p", "preferred"), + new Object[]{"p", "preferred"}, "quality", "premium", "rows", @@ -1518,7 +1516,7 @@ public void testMultiValueDimensionAsArrayWithOtherDims() query, "2011-04-01", "alias", - ComparableStringArray.of("preferred", "t"), + new Object[]{"preferred", "t"}, "quality", "technology", "rows", @@ -1530,7 +1528,7 @@ public void testMultiValueDimensionAsArrayWithOtherDims() query, "2011-04-01", "alias", - ComparableStringArray.of("preferred", "t"), + new Object[]{"preferred", "t"}, "quality", "travel", "rows", @@ -1628,7 +1626,7 @@ public void testSingleValueDimensionAsStringArrayWithoutExpression() query, "2011-04-01", "alias", - ComparableStringArray.of("preferred"), + new Object[]{"preferred"}, "rows", 26L, "idx", @@ -1670,7 +1668,7 @@ public void testMultiValueVirtualDimAsString() { if (!vectorize) { // cannot add exact class cast message due to discrepancies between various JDK versions - expectedException.expect(RuntimeException.class); + expectedException.expect(ISE.class); } cannotVectorize(); @@ -1812,7 +1810,7 @@ public void testVirtualColumnNumericTypeAsStringArray() .setGranularity(QueryRunnerTestHelper.ALL_GRAN) .build(); - GroupByQueryRunnerTestHelper.runQuery(factory, runner, query); + Iterable results = GroupByQueryRunnerTestHelper.runQuery(factory, runner, query); } @Test @@ -1847,14 +1845,14 @@ public void testNestedGroupByWithStringArray() .build(); List expectedResults = Arrays.asList( - makeRow(outer, "2011-04-01", "alias_outer", ComparableStringArray.of("a", "preferred"), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", ComparableStringArray.of("b", "preferred"), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", ComparableStringArray.of("e", "preferred"), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", ComparableStringArray.of("h", "preferred"), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", ComparableStringArray.of("m", "preferred"), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", ComparableStringArray.of("n", "preferred"), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", ComparableStringArray.of("p", "preferred"), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", ComparableStringArray.of("preferred", "t"), "rows", 1L) + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{"a", "preferred"}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{"b", "preferred"}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{"e", "preferred"}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{"h", "preferred"}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{"m", "preferred"}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{"n", "preferred"}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{"p", "preferred"}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{"preferred", "t"}, "rows", 1L) ); Iterable results = GroupByQueryRunnerTestHelper.runQuery(factory, runner, outer); @@ -1893,7 +1891,7 @@ public void testNestedGroupByWithLongArrays() .build(); List expectedResults = ImmutableList.of( - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(1L, 2L)), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{1L, 2L}, "rows", 1L )); @@ -1933,31 +1931,31 @@ public void testGroupByWithLongArrays() List expectedResults = Arrays.asList( - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(78L)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(97L)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(109L)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(110L)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(112L)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(113L)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(114L)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(118L)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(119L)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(120L)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(121L)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(126L)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(135L)), "rows", 2L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(144L)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(147L)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(158L)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(166L)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(1049L)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(1144L)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(1193L)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(1234L)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(1314L)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(1321L)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(1447L)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(1522L)), "rows", 1L) + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{78L}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{97L}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{109L}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{110L}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{112L}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{113L}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{114L}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{118L}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{119L}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{120L}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{121L}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{126L}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{135L}, "rows", 2L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{144L}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{147L}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{158L}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{166L}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{1049L}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{1144L}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{1193L}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{1234L}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{1314L}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{1321L}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{1447L}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{1522L}, "rows", 1L) ); Iterable results = GroupByQueryRunnerTestHelper.runQuery(factory, runner, outer); @@ -1996,31 +1994,31 @@ public void testGroupByWithLongArraysDesc() List expectedResults = Arrays.asList( - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(78L)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(97L)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(109L)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(110L)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(112L)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(113L)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(114L)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(118L)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(119L)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(120L)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(121L)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(126L)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(135L)), "rows", 2L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(144L)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(147L)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(158L)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(166L)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(1049L)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(1144L)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(1193L)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(1234L)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(1314L)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(1321L)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(1447L)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(1522L)), "rows", 1L) + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{78L}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{97L}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{109L}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{110L}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{112L}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{113L}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{114L}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{118L}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{119L}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{120L}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{121L}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{126L}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{135L}, "rows", 2L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{144L}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{147L}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{158L}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{166L}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{1049L}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{1144L}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{1193L}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{1234L}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{1314L}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{1321L}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{1447L}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{1522L}, "rows", 1L) ); // reversing list Collections.reverse(expectedResults); @@ -2060,32 +2058,32 @@ public void testGroupByWithDoubleArrays() List expectedResults = Arrays.asList( - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(78.622547)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(97.387433)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(109.705815)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(110.931934)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(112.987027)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(113.446008)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(114.290141)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(118.57034)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(119.922742)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(120.134704)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(121.583581)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(126.411364)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(135.301506)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(135.885094)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(144.507368)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(147.425935)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(158.747224)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(166.016049)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(1049.738585)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(1144.342401)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(1193.556278)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(1234.247546)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(1314.839715)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(1321.375057)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(1447.34116)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(1522.043733)), "rows", 1L) + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{78.622547}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{97.387433}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{109.705815}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{110.931934}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{112.987027}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{113.446008}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{114.290141}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{118.57034}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{119.922742}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{120.134704}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{121.583581}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{126.411364}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{135.301506}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{135.885094}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{144.507368}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{147.425935}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{158.747224}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{166.016049}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{1049.738585}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{1144.342401}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{1193.556278}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{1234.247546}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{1314.839715}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{1321.375057}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{1447.34116}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{1522.043733}, "rows", 1L) ); Iterable results = GroupByQueryRunnerTestHelper.runQuery(factory, runner, outer); TestHelper.assertExpectedObjects(expectedResults, results, "long-groupby-arrays"); @@ -2124,32 +2122,32 @@ public void testGroupByWithDoubleArraysDesc() List expectedResults = Arrays.asList( - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(78.622547)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(97.387433)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(109.705815)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(110.931934)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(112.987027)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(113.446008)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(114.290141)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(118.57034)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(119.922742)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(120.134704)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(121.583581)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(126.411364)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(135.301506)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(135.885094)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(144.507368)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(147.425935)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(158.747224)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(166.016049)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(1049.738585)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(1144.342401)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(1193.556278)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(1234.247546)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(1314.839715)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(1321.375057)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(1447.34116)), "rows", 1L), - makeRow(outer, "2011-04-01", "alias_outer", new ComparableList(ImmutableList.of(1522.043733)), "rows", 1L) + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{78.622547}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{97.387433}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{109.705815}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{110.931934}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{112.987027}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{113.446008}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{114.290141}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{118.57034}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{119.922742}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{120.134704}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{121.583581}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{126.411364}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{135.301506}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{135.885094}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{144.507368}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{147.425935}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{158.747224}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{166.016049}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{1049.738585}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{1144.342401}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{1193.556278}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{1234.247546}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{1314.839715}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{1321.375057}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{1447.34116}, "rows", 1L), + makeRow(outer, "2011-04-01", "alias_outer", new Object[]{1522.043733}, "rows", 1L) ); // reversing list Collections.reverse(expectedResults); @@ -13158,4 +13156,4 @@ private void cannotVectorize() expectedException.expectMessage("Cannot vectorize!"); } } -} +} \ No newline at end of file diff --git a/processing/src/test/java/org/apache/druid/query/groupby/GroupByQueryTest.java b/processing/src/test/java/org/apache/druid/query/groupby/GroupByQueryTest.java index b80d715d0041..2784d6b89181 100644 --- a/processing/src/test/java/org/apache/druid/query/groupby/GroupByQueryTest.java +++ b/processing/src/test/java/org/apache/druid/query/groupby/GroupByQueryTest.java @@ -42,8 +42,8 @@ import org.apache.druid.query.spec.QuerySegmentSpec; import org.apache.druid.segment.TestHelper; import org.apache.druid.segment.column.ColumnType; -import org.apache.druid.segment.data.ComparableStringArray; import org.apache.druid.segment.virtual.ExpressionVirtualColumn; +import org.apache.druid.testing.InitializedNullHandlingTest; import org.junit.Assert; import org.junit.Test; @@ -51,7 +51,7 @@ import java.util.Collections; import java.util.List; -public class GroupByQueryTest +public class GroupByQueryTest extends InitializedNullHandlingTest { private static final ObjectMapper JSON_MAPPER = TestHelper.makeJsonMapper(); @@ -132,8 +132,8 @@ public void testRowOrderingMixTypes() final Ordering rowOrdering = query.getRowOrdering(false); final int compare = rowOrdering.compare( - ResultRow.of(1, 1f, "a", ComparableStringArray.of("1", "2")), - ResultRow.of(1L, 1d, "b", ComparableStringArray.of("3")) + ResultRow.of(1, 1f, "a", new Object[]{"1", "2"}), + ResultRow.of(1L, 1d, "b", new Object[]{"3"}) ); Assert.assertEquals(-1, compare); } diff --git a/processing/src/test/java/org/apache/druid/query/groupby/NestedGroupByArrayQueryTest.java b/processing/src/test/java/org/apache/druid/query/groupby/NestedGroupByArrayQueryTest.java index a43509de9212..cc3235bd007b 100644 --- a/processing/src/test/java/org/apache/druid/query/groupby/NestedGroupByArrayQueryTest.java +++ b/processing/src/test/java/org/apache/druid/query/groupby/NestedGroupByArrayQueryTest.java @@ -37,8 +37,6 @@ import org.apache.druid.segment.column.ColumnType; import org.apache.druid.segment.column.RowSignature; import org.apache.druid.segment.column.ValueType; -import org.apache.druid.segment.data.ComparableList; -import org.apache.druid.segment.data.ComparableStringArray; import org.apache.druid.segment.virtual.NestedFieldVirtualColumn; import org.junit.After; import org.junit.Assert; @@ -51,7 +49,6 @@ import java.io.IOException; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.List; import java.util.Map; @@ -143,10 +140,10 @@ public void testGroupByRootArrayString() groupQuery, ImmutableList.of( new Object[]{null, 8L}, - new Object[]{ComparableStringArray.of("a", "b"), 8L}, - new Object[]{ComparableStringArray.of("a", "b", "c"), 4L}, - new Object[]{ComparableStringArray.of("b", "c"), 4L}, - new Object[]{ComparableStringArray.of("d", "e"), 4L} + new Object[]{new Object[]{"a", "b"}, 8L}, + new Object[]{new Object[]{"a", "b", "c"}, 4L}, + new Object[]{new Object[]{"b", "c"}, 4L}, + new Object[]{new Object[]{"d", "e"}, 4L} ) ); } @@ -168,10 +165,10 @@ public void testGroupByRootArrayLong() groupQuery, ImmutableList.of( new Object[]{null, 8L}, - new Object[]{asComparableList(1L, 2L, 3L), 8L}, - new Object[]{asComparableList(1L, 2L, 3L, 4L), 4L}, - new Object[]{asComparableList(1L, 4L), 4L}, - new Object[]{asComparableList(2L, 3L), 4L} + new Object[]{new Object[]{1L, 2L, 3L}, 8L}, + new Object[]{new Object[]{1L, 2L, 3L, 4L}, 4L}, + new Object[]{new Object[]{1L, 4L}, 4L}, + new Object[]{new Object[]{2L, 3L}, 4L} ) ); } @@ -193,10 +190,10 @@ public void testGroupByRootArrayDouble() groupQuery, ImmutableList.of( new Object[]{null, 8L}, - new Object[]{asComparableList(1.1, 2.2, 3.3), 8L}, - new Object[]{asComparableList(1.1, 3.3), 4L}, - new Object[]{asComparableList(2.2, 3.3, 4.0), 4L}, - new Object[]{asComparableList(3.3, 4.4, 5.5), 4L} + new Object[]{new Object[]{1.1, 2.2, 3.3}, 8L}, + new Object[]{new Object[]{1.1, 3.3}, 4L}, + new Object[]{new Object[]{2.2, 3.3, 4.0}, 4L}, + new Object[]{new Object[]{3.3, 4.4, 5.5}, 4L} ) ); } @@ -479,15 +476,12 @@ private static void verifyResults(GroupByQuery query, List results, L Assert.assertEquals((Double) expected.get(i)[j], (Double) resultRow[j], 0.01); } else if (rowSignature.getColumnType(j).map(t -> t.is(ValueType.FLOAT)).orElse(false)) { Assert.assertEquals((Float) expected.get(i)[j], (Float) resultRow[j], 0.01); + } else if (rowSignature.getColumnType(j).map(t -> t.isArray()).orElse(false)){ + Assert.assertArrayEquals((Object[]) expected.get(i)[j], (Object[]) resultRow[j]); } else { Assert.assertEquals(expected.get(i)[j], resultRow[j]); } } } } - - public static ComparableList asComparableList(T... objects) - { - return new ComparableList<>(Arrays.asList(objects)); - } } diff --git a/processing/src/test/java/org/apache/druid/query/groupby/epinephelinae/column/ArrayDoubleGroupByColumnSelectorStrategyTest.java b/processing/src/test/java/org/apache/druid/query/groupby/epinephelinae/column/ArrayDoubleGroupByColumnSelectorStrategyTest.java index 294279d0544f..98b6ff094b55 100644 --- a/processing/src/test/java/org/apache/druid/query/groupby/epinephelinae/column/ArrayDoubleGroupByColumnSelectorStrategyTest.java +++ b/processing/src/test/java/org/apache/druid/query/groupby/epinephelinae/column/ArrayDoubleGroupByColumnSelectorStrategyTest.java @@ -25,7 +25,6 @@ import org.apache.druid.query.groupby.epinephelinae.Grouper; import org.apache.druid.query.ordering.StringComparators; import org.apache.druid.segment.ColumnValueSelector; -import org.apache.druid.segment.data.ComparableList; import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -117,7 +116,7 @@ public void testSanity() buffer1.putInt(0); strategy.processValueFromGroupingKey(groupByColumnSelectorPlus, buffer1, row, 0); - Assert.assertEquals(new ComparableList<>(ImmutableList.of(1.0, 2.0)), row.get(0)); + Assert.assertEquals(ImmutableList.of(1.0, 2.0), row.get(0)); } @@ -134,7 +133,7 @@ public void testAddingInDictionary() buffer1.putInt(3); strategy.processValueFromGroupingKey(groupByColumnSelectorPlus, buffer1, row, 0); - Assert.assertEquals(new ComparableList<>(ImmutableList.of(4.0, 2.0)), row.get(0)); + Assert.assertEquals(ImmutableList.of(4.0, 2.0), row.get(0)); } @Test @@ -149,7 +148,7 @@ public void testAddingInDictionaryWithObjects() ResultRow row = ResultRow.create(1); buffer1.putInt(3); strategy.processValueFromGroupingKey(groupByColumnSelectorPlus, buffer1, row, 0); - Assert.assertEquals(new ComparableList<>(ImmutableList.of(4.0, 2.0)), row.get(0)); + Assert.assertEquals(ImmutableList.of(4.0, 2.0), row.get(0)); } @After diff --git a/processing/src/test/java/org/apache/druid/query/groupby/epinephelinae/column/ArrayLongGroupByColumnSelectorStrategyTest.java b/processing/src/test/java/org/apache/druid/query/groupby/epinephelinae/column/ArrayLongGroupByColumnSelectorStrategyTest.java index 4d19191b4259..fcba06778d47 100644 --- a/processing/src/test/java/org/apache/druid/query/groupby/epinephelinae/column/ArrayLongGroupByColumnSelectorStrategyTest.java +++ b/processing/src/test/java/org/apache/druid/query/groupby/epinephelinae/column/ArrayLongGroupByColumnSelectorStrategyTest.java @@ -25,7 +25,6 @@ import org.apache.druid.query.groupby.epinephelinae.Grouper; import org.apache.druid.query.ordering.StringComparators; import org.apache.druid.segment.ColumnValueSelector; -import org.apache.druid.segment.data.ComparableList; import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -120,7 +119,7 @@ public void testSanity() buffer1.putInt(0); strategy.processValueFromGroupingKey(groupByColumnSelectorPlus, buffer1, row, 0); - Assert.assertEquals(new ComparableList<>(ImmutableList.of(1L, 2L)), row.get(0)); + Assert.assertEquals(ImmutableList.of(1L, 2L), row.get(0)); } @@ -137,7 +136,7 @@ public void testAddingInDictionary() buffer1.putInt(3); strategy.processValueFromGroupingKey(groupByColumnSelectorPlus, buffer1, row, 0); - Assert.assertEquals(new ComparableList<>(ImmutableList.of(4L, 2L)), row.get(0)); + Assert.assertEquals(ImmutableList.of(4L, 2L), row.get(0)); } @Test @@ -152,7 +151,7 @@ public void testAddingInDictionaryWithObjects() ResultRow row = ResultRow.create(1); buffer1.putInt(3); strategy.processValueFromGroupingKey(groupByColumnSelectorPlus, buffer1, row, 0); - Assert.assertEquals(new ComparableList<>(ImmutableList.of(4L, 2L)), row.get(0)); + Assert.assertEquals(ImmutableList.of(4L, 2L), row.get(0)); } @After diff --git a/processing/src/test/java/org/apache/druid/query/groupby/epinephelinae/column/ArrayStringGroupByColumnSelectorStrategyTest.java b/processing/src/test/java/org/apache/druid/query/groupby/epinephelinae/column/ArrayStringGroupByColumnSelectorStrategyTest.java index b9f8c8b6f563..b3ed04605fda 100644 --- a/processing/src/test/java/org/apache/druid/query/groupby/epinephelinae/column/ArrayStringGroupByColumnSelectorStrategyTest.java +++ b/processing/src/test/java/org/apache/druid/query/groupby/epinephelinae/column/ArrayStringGroupByColumnSelectorStrategyTest.java @@ -27,7 +27,6 @@ import org.apache.druid.query.ordering.StringComparators; import org.apache.druid.segment.ColumnValueSelector; import org.apache.druid.segment.data.ComparableIntArray; -import org.apache.druid.segment.data.ComparableStringArray; import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -124,7 +123,7 @@ public void testSanity() buffer1.putInt(0); strategy.processValueFromGroupingKey(groupByColumnSelectorPlus, buffer1, row, 0); - Assert.assertEquals(ComparableStringArray.of("a", "b"), row.get(0)); + Assert.assertArrayEquals(new Object[]{"a", "b"}, (Object[]) row.get(0)); } @@ -141,7 +140,7 @@ public void testAddingInDictionary() buffer1.putInt(3); strategy.processValueFromGroupingKey(groupByColumnSelectorPlus, buffer1, row, 0); - Assert.assertEquals(ComparableStringArray.of("f", "a"), row.get(0)); + Assert.assertArrayEquals(new Object[]{"f", "a"}, (Object[]) row.get(0)); } @Test @@ -157,7 +156,7 @@ public void testAddingInDictionaryWithObjects() buffer1.putInt(3); strategy.processValueFromGroupingKey(groupByColumnSelectorPlus, buffer1, row, 0); - Assert.assertEquals(ComparableStringArray.of("f", "a"), row.get(0)); + Assert.assertArrayEquals(new Object[]{"f", "a"}, (Object[]) row.get(0)); } @After diff --git a/processing/src/test/java/org/apache/druid/segment/DimensionHandlerUtilsTest.java b/processing/src/test/java/org/apache/druid/segment/DimensionHandlerUtilsTest.java index 6d80952736eb..6ba7f84f392d 100644 --- a/processing/src/test/java/org/apache/druid/segment/DimensionHandlerUtilsTest.java +++ b/processing/src/test/java/org/apache/druid/segment/DimensionHandlerUtilsTest.java @@ -31,8 +31,6 @@ import org.apache.druid.segment.column.ColumnCapabilitiesImpl; import org.apache.druid.segment.column.ColumnType; import org.apache.druid.segment.column.ValueType; -import org.apache.druid.segment.data.ComparableList; -import org.apache.druid.segment.data.ComparableStringArray; import org.apache.druid.testing.InitializedNullHandlingTest; import org.junit.Assert; import org.junit.BeforeClass; @@ -49,11 +47,11 @@ public class DimensionHandlerUtilsTest extends InitializedNullHandlingTest @Rule public ExpectedException expectedException = ExpectedException.none(); - private static final ComparableList LONG_COMPARABLE_LIST = new ComparableList<>(ImmutableList.of(1L, 2L)); - private static final ComparableList DOUBLE_COMPARABLE_LIST = new ComparableList<>(ImmutableList.of(1.0, 2.0)); - private static final ComparableList FLOAT_COMPARABLE_LIST = new ComparableList<>(ImmutableList.of(1F, 2F)); - private static final ComparableStringArray COMPARABLE_STRING_ARRAY = ComparableStringArray.of("1", "2"); - private static final ComparableStringArray COMPARABLE_STRING_ARRAY_DECIMAL = ComparableStringArray.of("1.0", "2.0"); + private static final Object[] LONG_OBJECT_ARRAY = new Object[]{1L, 2L}; + private static final Object[] DOUBLE_OBJECT_ARRAY = new Object[]{1.0, 2.0}; + private static final Object[] FLOAT_OBJECT_ARRAY = new Object[]{1F, 2F}; + private static final Object[] STRING_OBJECT_ARRAY = new Object[]{"1", "2"}; + private static final Object[] DECIMAL_STRING_OBJECT_ARRAY = new Object[]{"1.0", "2.0"}; @BeforeClass public static void setupTests() @@ -178,20 +176,20 @@ public void testGetHandlerFromLongCapabilities() @Test public void testComparableLongList() { - Assert.assertEquals(null, DimensionHandlerUtils.convertToList(null, ValueType.LONG)); - Assert.assertEquals( - LONG_COMPARABLE_LIST, + Assert.assertArrayEquals(null, DimensionHandlerUtils.convertToList(null, ValueType.LONG)); + Assert.assertArrayEquals( + LONG_OBJECT_ARRAY, DimensionHandlerUtils.convertToList(ImmutableList.of(1L, 2L), ValueType.LONG) ); - Assert.assertEquals( - LONG_COMPARABLE_LIST, + Assert.assertArrayEquals( + LONG_OBJECT_ARRAY, DimensionHandlerUtils.convertToList( - new ComparableList(ImmutableList.of(1L, 2L)), + FLOAT_OBJECT_ARRAY, ValueType.LONG ) ); - assertArrayCases(LONG_COMPARABLE_LIST, ValueType.LONG); + assertArrayCases(LONG_OBJECT_ARRAY, ValueType.LONG); Assert.assertThrows( "Unable to convert object of type[Long] to [ComparableList]", @@ -215,20 +213,20 @@ public void testComparableLongList() @Test public void testComparableFloatList() { - Assert.assertEquals(null, DimensionHandlerUtils.convertToList(null, ValueType.FLOAT)); - Assert.assertEquals( - FLOAT_COMPARABLE_LIST, + Assert.assertArrayEquals(null, DimensionHandlerUtils.convertToList(null, ValueType.FLOAT)); + Assert.assertArrayEquals( + FLOAT_OBJECT_ARRAY, DimensionHandlerUtils.convertToList(ImmutableList.of(1.0F, 2.0F), ValueType.FLOAT) ); - Assert.assertEquals( - FLOAT_COMPARABLE_LIST, + Assert.assertArrayEquals( + FLOAT_OBJECT_ARRAY, DimensionHandlerUtils.convertToList( - new ComparableList(ImmutableList.of(1.0F, 2.0F)), + LONG_OBJECT_ARRAY, ValueType.FLOAT ) ); - assertArrayCases(FLOAT_COMPARABLE_LIST, ValueType.FLOAT); + assertArrayCases(FLOAT_OBJECT_ARRAY, ValueType.FLOAT); Assert.assertThrows( "Unable to convert object of type[Float] to [ComparableList]", @@ -252,20 +250,20 @@ public void testComparableFloatList() @Test public void testComparableDoubleList() { - Assert.assertEquals(null, DimensionHandlerUtils.convertToList(null, ValueType.DOUBLE)); - Assert.assertEquals( - DOUBLE_COMPARABLE_LIST, + Assert.assertArrayEquals(null, DimensionHandlerUtils.convertToList(null, ValueType.DOUBLE)); + Assert.assertArrayEquals( + DOUBLE_OBJECT_ARRAY, DimensionHandlerUtils.convertToList(ImmutableList.of(1.0D, 2.0D), ValueType.DOUBLE) ); - Assert.assertEquals( - DOUBLE_COMPARABLE_LIST, + Assert.assertArrayEquals( + DOUBLE_OBJECT_ARRAY, DimensionHandlerUtils.convertToList( - new ComparableList(ImmutableList.of(1.0D, 2.0D)), + FLOAT_OBJECT_ARRAY, ValueType.DOUBLE ) ); - assertArrayCases(DOUBLE_COMPARABLE_LIST, ValueType.DOUBLE); + assertArrayCases(DOUBLE_OBJECT_ARRAY, ValueType.DOUBLE); Assert.assertThrows( "Unable to convert object of type[Double] to [ComparableList]", @@ -289,30 +287,30 @@ public void testComparableDoubleList() @Test public void testComparableStringArrayList() { - Assert.assertEquals(null, DimensionHandlerUtils.coerceToStringArray(null)); - Assert.assertEquals( - COMPARABLE_STRING_ARRAY, + Assert.assertArrayEquals(null, DimensionHandlerUtils.coerceToStringArray(null)); + Assert.assertArrayEquals( + STRING_OBJECT_ARRAY, DimensionHandlerUtils.coerceToStringArray(ImmutableList.of("1", "2")) ); - Assert.assertEquals( - COMPARABLE_STRING_ARRAY, + Assert.assertArrayEquals( + STRING_OBJECT_ARRAY, DimensionHandlerUtils.coerceToStringArray(new Object[]{1L, 2L}) ); - Assert.assertEquals( - COMPARABLE_STRING_ARRAY, + Assert.assertArrayEquals( + STRING_OBJECT_ARRAY, DimensionHandlerUtils.coerceToStringArray(new Long[]{1L, 2L}) ); - Assert.assertEquals( - COMPARABLE_STRING_ARRAY_DECIMAL, + Assert.assertArrayEquals( + DECIMAL_STRING_OBJECT_ARRAY, DimensionHandlerUtils.coerceToStringArray(new String[]{"1.0", "2.0"}) ); - Assert.assertEquals( - COMPARABLE_STRING_ARRAY_DECIMAL, + Assert.assertArrayEquals( + DECIMAL_STRING_OBJECT_ARRAY, DimensionHandlerUtils.coerceToStringArray(new Double[]{1.0, 2.0}) ); - Assert.assertEquals( - COMPARABLE_STRING_ARRAY_DECIMAL, + Assert.assertArrayEquals( + DECIMAL_STRING_OBJECT_ARRAY, DimensionHandlerUtils.coerceToStringArray(new Float[]{1F, 2F}) ); @@ -323,19 +321,19 @@ public void testComparableStringArrayList() ); } - private static void assertArrayCases(ComparableList expectedComparableList, ValueType elementType) + private static void assertArrayCases(Object[] expectedComparableList, ValueType elementType) { - Assert.assertEquals(expectedComparableList, DimensionHandlerUtils.convertToList(new Object[]{1L, 2L}, elementType)); - Assert.assertEquals(expectedComparableList, DimensionHandlerUtils.convertToList(new Long[]{1L, 2L}, elementType)); - Assert.assertEquals( + Assert.assertArrayEquals(expectedComparableList, DimensionHandlerUtils.convertToList(new Object[]{1L, 2L}, elementType)); + Assert.assertArrayEquals(expectedComparableList, DimensionHandlerUtils.convertToList(new Long[]{1L, 2L}, elementType)); + Assert.assertArrayEquals( expectedComparableList, DimensionHandlerUtils.convertToList(new String[]{"1.0", "2.0"}, elementType) ); - Assert.assertEquals( + Assert.assertArrayEquals( expectedComparableList, DimensionHandlerUtils.convertToList(new Double[]{1.0, 2.0}, elementType) ); - Assert.assertEquals(expectedComparableList, DimensionHandlerUtils.convertToList(new Float[]{1F, 2F}, elementType)); + Assert.assertArrayEquals(expectedComparableList, DimensionHandlerUtils.convertToList(new Float[]{1F, 2F}, elementType)); } private static class TestDimensionSchema extends DimensionSchema diff --git a/processing/src/test/java/org/apache/druid/segment/TestHelper.java b/processing/src/test/java/org/apache/druid/segment/TestHelper.java index c167f6fe9524..8770d3f07fdb 100644 --- a/processing/src/test/java/org/apache/druid/segment/TestHelper.java +++ b/processing/src/test/java/org/apache/druid/segment/TestHelper.java @@ -41,8 +41,6 @@ import org.apache.druid.query.timeseries.TimeseriesResultValue; import org.apache.druid.query.topn.TopNResultValue; import org.apache.druid.segment.column.ColumnConfig; -import org.apache.druid.segment.data.ComparableList; -import org.apache.druid.segment.data.ComparableStringArray; import org.apache.druid.segment.join.JoinableFactoryWrapper; import org.apache.druid.segment.writeout.SegmentWriteOutMediumFactory; import org.apache.druid.timeline.DataSegment.PruneSpecsHolder; @@ -435,16 +433,6 @@ public static void assertRow(String msg, ResultRow expected, ResultRow actual) ((Number) actualValue).doubleValue(), Math.abs(((Number) expectedValue).doubleValue() * 1e-6) ); - } else if (expectedValue instanceof ComparableStringArray && actualValue instanceof List) { - Assert.assertArrayEquals( - ((ComparableStringArray) expectedValue).getDelegate(), - ExprEval.coerceListToArray((List) actualValue, true).rhs - ); - } else if (expectedValue instanceof ComparableList && actualValue instanceof List) { - Assert.assertArrayEquals( - ((ComparableList) expectedValue).getDelegate().toArray(new Object[0]), - ExprEval.coerceListToArray((List) actualValue, true).rhs - ); } else { Assert.assertEquals( message, diff --git a/processing/src/test/java/org/apache/druid/segment/data/ComparableListTest.java b/processing/src/test/java/org/apache/druid/segment/data/ComparableListTest.java deleted file mode 100644 index e67de75be96b..000000000000 --- a/processing/src/test/java/org/apache/druid/segment/data/ComparableListTest.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * 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.druid.segment.data; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Lists; -import org.junit.Assert; -import org.junit.Test; - -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -public class ComparableListTest -{ - private final List integers = ImmutableList.of(1, 2, 3); - private final ComparableList comparableList = new ComparableList(ImmutableList.of(1, 2, 3)); - - @Test - public void testDelegate() - { - Assert.assertEquals(integers, comparableList.getDelegate()); - Assert.assertEquals(0, new ComparableList(ImmutableList.of()).getDelegate().size()); - } - - @Test - public void testHashCode() - { - Assert.assertEquals(integers.hashCode(), comparableList.hashCode()); - Set set = new HashSet<>(); - set.add(comparableList); - set.add(new ComparableList(integers)); - Assert.assertEquals(1, set.size()); - } - - @Test - public void testEquals() - { - Assert.assertTrue(comparableList.equals(new ComparableList(integers))); - Assert.assertFalse(comparableList.equals(new ComparableList(ImmutableList.of(1, 2, 5)))); - Assert.assertFalse(comparableList.equals(null)); - } - - @Test - public void testCompareTo() - { - Assert.assertEquals(0, comparableList.compareTo(new ComparableList(integers))); - Assert.assertEquals(1, comparableList.compareTo(null)); - Assert.assertEquals(1, comparableList.compareTo(new ComparableList(ImmutableList.of(1, 2)))); - Assert.assertEquals(-1, comparableList.compareTo(new ComparableList(ImmutableList.of(1, 2, 3, 4)))); - Assert.assertTrue(comparableList.compareTo(new ComparableList(ImmutableList.of(2))) < 0); - ComparableList nullList = new ComparableList(Lists.newArrayList(null, 1)); - - Assert.assertTrue(comparableList.compareTo(nullList) > 0); - Assert.assertTrue(nullList.compareTo(comparableList) < 0); - Assert.assertTrue(nullList.compareTo(new ComparableList(Lists.newArrayList(null, 1))) == 0); - } -} diff --git a/processing/src/test/java/org/apache/druid/segment/data/ComparableStringArrayTest.java b/processing/src/test/java/org/apache/druid/segment/data/ComparableStringArrayTest.java deleted file mode 100644 index a33ad54901a8..000000000000 --- a/processing/src/test/java/org/apache/druid/segment/data/ComparableStringArrayTest.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * 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.druid.segment.data; - -import org.junit.Assert; -import org.junit.Test; - -import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; - -public class ComparableStringArrayTest -{ - private final String[] array = new String[]{"a", "b", "c"}; - private final ComparableStringArray comparableStringArray = ComparableStringArray.of("a", "b", "c"); - - @Test - public void testDelegate() - { - Assert.assertArrayEquals(array, comparableStringArray.getDelegate()); - Assert.assertEquals(0, ComparableStringArray.of(new String[0]).getDelegate().length); - Assert.assertEquals(0, ComparableStringArray.of().getDelegate().length); - } - - @Test - public void testHashCode() - { - Assert.assertEquals(Arrays.hashCode(array), comparableStringArray.hashCode()); - Set set = new HashSet<>(); - set.add(comparableStringArray); - set.add(ComparableStringArray.of(array)); - Assert.assertEquals(1, set.size()); - } - - @Test - public void testEquals() - { - Assert.assertTrue(comparableStringArray.equals(ComparableStringArray.of(array))); - Assert.assertFalse(comparableStringArray.equals(ComparableStringArray.of("a", "b", "C"))); - Assert.assertFalse(comparableStringArray.equals(ComparableStringArray.EMPTY_ARRAY)); - Assert.assertFalse(comparableStringArray.equals(null)); - } - - @Test - public void testCompareTo() - { - Assert.assertEquals(0, comparableStringArray.compareTo(ComparableStringArray.of(array))); - Assert.assertEquals(1, comparableStringArray.compareTo(null)); - Assert.assertEquals(1, comparableStringArray.compareTo(ComparableStringArray.of("a", "b"))); - Assert.assertEquals(-1, comparableStringArray.compareTo(ComparableStringArray.of("a", "b", "c", "d"))); - Assert.assertTrue(comparableStringArray.compareTo(ComparableStringArray.of("b")) < 0); - - ComparableStringArray nullList = ComparableStringArray.of(null, "a"); - - Assert.assertTrue(comparableStringArray.compareTo(nullList) > 0); - Assert.assertTrue(nullList.compareTo(comparableStringArray) < 0); - Assert.assertTrue(nullList.compareTo(ComparableStringArray.of(null, "a")) == 0); - } -} diff --git a/server/src/test/java/org/apache/druid/server/ClientQuerySegmentWalkerTest.java b/server/src/test/java/org/apache/druid/server/ClientQuerySegmentWalkerTest.java index 140b96da5589..c19211580599 100644 --- a/server/src/test/java/org/apache/druid/server/ClientQuerySegmentWalkerTest.java +++ b/server/src/test/java/org/apache/druid/server/ClientQuerySegmentWalkerTest.java @@ -72,8 +72,6 @@ import org.apache.druid.segment.TestHelper; import org.apache.druid.segment.column.ColumnType; import org.apache.druid.segment.column.RowSignature; -import org.apache.druid.segment.data.ComparableList; -import org.apache.druid.segment.data.ComparableStringArray; import org.apache.druid.segment.join.FrameBasedInlineJoinableFactory; import org.apache.druid.segment.join.InlineJoinableFactory; import org.apache.druid.segment.join.JoinConditionAnalysis; @@ -922,10 +920,10 @@ public void testGroupByOnArraysDoubles() query, ImmutableList.of(ExpectedQuery.cluster(query)), ImmutableList.of( - new Object[]{new ComparableList(ImmutableList.of(1.0, 2.0))}, - new Object[]{new ComparableList(ImmutableList.of(2.0, 4.0))}, - new Object[]{new ComparableList(ImmutableList.of(3.0, 6.0))}, - new Object[]{new ComparableList(ImmutableList.of(4.0, 8.0))} + new Object[]{new Object[]{1.0, 2.0}}, + new Object[]{new Object[]{2.0, 4.0}}, + new Object[]{new Object[]{3.0, 6.0}}, + new Object[]{new Object[]{4.0, 8.0}} ) ); } @@ -946,10 +944,10 @@ public void testGroupByOnArraysDoublesAsString() query, ImmutableList.of(ExpectedQuery.cluster(query)), ImmutableList.of( - new Object[]{new ComparableList(ImmutableList.of(1.0, 2.0)).toString()}, - new Object[]{new ComparableList(ImmutableList.of(2.0, 4.0)).toString()}, - new Object[]{new ComparableList(ImmutableList.of(3.0, 6.0)).toString()}, - new Object[]{new ComparableList(ImmutableList.of(4.0, 8.0)).toString()} + new Object[]{Arrays.toString(new Object[]{1.0, 2.0})}, + new Object[]{Arrays.toString(new Object[]{2.0, 4.0})}, + new Object[]{Arrays.toString(new Object[]{3.0, 6.0})}, + new Object[]{Arrays.toString(new Object[]{4.0, 8.0})} ) ); } @@ -1009,10 +1007,10 @@ public void testGroupByOnArraysLongs() query, ImmutableList.of(ExpectedQuery.cluster(query)), ImmutableList.of( - new Object[]{new ComparableList(ImmutableList.of(1L, 2L))}, - new Object[]{new ComparableList(ImmutableList.of(2L, 4L))}, - new Object[]{new ComparableList(ImmutableList.of(3L, 6L))}, - new Object[]{new ComparableList(ImmutableList.of(4L, 8L))} + new Object[]{new Object[]{1L, 2L}}, + new Object[]{new Object[]{2L, 4L}}, + new Object[]{new Object[]{3L, 6L}}, + new Object[]{new Object[]{4L, 8L}} ) ); } @@ -1029,15 +1027,15 @@ public void testGroupByOnArraysLongsAsString() .build() .withId(DUMMY_QUERY_ID); - // when we donot define an outputType, convert {@link ComparableList} to a string + // when we donot define an outputType, convert {@code Object[]} to a string testQuery( query, ImmutableList.of(ExpectedQuery.cluster(query)), ImmutableList.of( - new Object[]{new ComparableList(ImmutableList.of(1L, 2L)).toString()}, - new Object[]{new ComparableList(ImmutableList.of(2L, 4L)).toString()}, - new Object[]{new ComparableList(ImmutableList.of(3L, 6L)).toString()}, - new Object[]{new ComparableList(ImmutableList.of(4L, 8L)).toString()} + new Object[]{Arrays.toString(new Object[]{1L, 2L})}, + new Object[]{Arrays.toString(new Object[]{2L, 4L})}, + new Object[]{Arrays.toString(new Object[]{3L, 6L})}, + new Object[]{Arrays.toString(new Object[]{4L, 8L})} ) ); } @@ -1092,10 +1090,10 @@ public void testGroupByOnArraysStrings() query, ImmutableList.of(ExpectedQuery.cluster(query)), ImmutableList.of( - new Object[]{ComparableStringArray.of("1.0", "2.0")}, - new Object[]{ComparableStringArray.of("2.0", "4.0")}, - new Object[]{ComparableStringArray.of("3.0", "6.0")}, - new Object[]{ComparableStringArray.of("4.0", "8.0")} + new Object[]{new Object[]{"1.0", "2.0"}}, + new Object[]{new Object[]{"2.0", "4.0"}}, + new Object[]{new Object[]{"3.0", "6.0"}}, + new Object[]{new Object[]{"4.0", "8.0"}} ) ); } @@ -1116,10 +1114,10 @@ public void testGroupByOnArraysStringsasString() query, ImmutableList.of(ExpectedQuery.cluster(query)), ImmutableList.of( - new Object[]{ComparableStringArray.of("1.0", "2.0").toString()}, - new Object[]{ComparableStringArray.of("2.0", "4.0").toString()}, - new Object[]{ComparableStringArray.of("3.0", "6.0").toString()}, - new Object[]{ComparableStringArray.of("4.0", "8.0").toString()} + new Object[]{Arrays.toString(new Object[]{"1.0", "2.0"})}, + new Object[]{Arrays.toString(new Object[]{"2.0", "4.0"})}, + new Object[]{Arrays.toString(new Object[]{"3.0", "6.0"})}, + new Object[]{Arrays.toString(new Object[]{"4.0", "8.0"})} ) ); } diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/run/SqlResults.java b/sql/src/main/java/org/apache/druid/sql/calcite/run/SqlResults.java index d314a3a4cc2e..649d27a1f3a9 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/run/SqlResults.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/run/SqlResults.java @@ -32,8 +32,6 @@ import org.apache.druid.java.util.common.DateTimes; import org.apache.druid.math.expr.Evals; import org.apache.druid.segment.DimensionHandlerUtils; -import org.apache.druid.segment.data.ComparableList; -import org.apache.druid.segment.data.ComparableStringArray; import org.apache.druid.sql.calcite.planner.Calcites; import org.apache.druid.sql.calcite.planner.PlannerContext; import org.joda.time.DateTime; @@ -200,10 +198,6 @@ static Object maybeCoerceArrayToList(Object value, boolean mustCoerce) lst.add(f); } return lst; - } else if (value instanceof ComparableStringArray) { - return Arrays.asList(((ComparableStringArray) value).getDelegate()); - } else if (value instanceof ComparableList) { - return ((ComparableList) value).getDelegate(); } else if (mustCoerce) { return null; } diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/run/SqlResultsTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/run/SqlResultsTest.java index 3c06e52238e7..7d846f434547 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/run/SqlResultsTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/run/SqlResultsTest.java @@ -27,8 +27,6 @@ import org.apache.druid.error.DruidException; import org.apache.druid.java.util.common.StringUtils; import org.apache.druid.segment.TestHelper; -import org.apache.druid.segment.data.ComparableList; -import org.apache.druid.segment.data.ComparableStringArray; import org.apache.druid.testing.InitializedNullHandlingTest; import org.hamcrest.CoreMatchers; import org.hamcrest.MatcherAssert; @@ -59,13 +57,11 @@ public void testCoerceStringArrays() { final List stringList = Arrays.asList("x", "y", "z", null); final Object[] stringArray = new Object[]{"x", "y", "z", null}; - final ComparableStringArray comparableStringArray = ComparableStringArray.of(new String[]{"x", "y", "z", null}); final String[] stringArray2 = new String[]{"x", "y", "z", null}; assertCoerceArrayToList(stringList, stringList); assertCoerceArrayToList(stringList, stringArray); assertCoerceArrayToList(stringList, stringArray2); - assertCoerceArrayToList(stringList, comparableStringArray); } @Test @@ -73,13 +69,11 @@ public void testCoerceLongArrays() { final List listWithNull = Arrays.asList(1L, 2L, null, 3L); final Long[] arrayWithNull = new Long[]{1L, 2L, null, 3L}; - final ComparableList comparableList = new ComparableList<>(listWithNull); final List list = Arrays.asList(1L, 2L, 3L); final long[] array = new long[]{1L, 2L, 3L}; assertCoerceArrayToList(listWithNull, listWithNull); assertCoerceArrayToList(listWithNull, arrayWithNull); - assertCoerceArrayToList(listWithNull, comparableList); assertCoerceArrayToList(list, list); assertCoerceArrayToList(list, array); } @@ -89,13 +83,11 @@ public void testCoerceDoubleArrays() { final List listWithNull = Arrays.asList(1.1, 2.2, null, 3.3); final Double[] arrayWithNull = new Double[]{1.1, 2.2, null, 3.3}; - final ComparableList comparableList = new ComparableList<>(listWithNull); final List list = Arrays.asList(1.1, 2.2, 3.3); final double[] array = new double[]{1.1, 2.2, 3.3}; assertCoerceArrayToList(listWithNull, listWithNull); assertCoerceArrayToList(listWithNull, arrayWithNull); - assertCoerceArrayToList(listWithNull, comparableList); assertCoerceArrayToList(list, list); assertCoerceArrayToList(list, array); } @@ -105,13 +97,11 @@ public void testCoerceFloatArrays() { final List listWithNull = Arrays.asList(1.1f, 2.2f, null, 3.3f); final Float[] arrayWithNull = new Float[]{1.1f, 2.2f, null, 3.3f}; - final ComparableList comparableList = new ComparableList<>(listWithNull); final List list = Arrays.asList(1.1f, 2.2f, 3.3f); final float[] array = new float[]{1.1f, 2.2f, 3.3f}; assertCoerceArrayToList(listWithNull, listWithNull); assertCoerceArrayToList(listWithNull, arrayWithNull); - assertCoerceArrayToList(listWithNull, comparableList); assertCoerceArrayToList(list, list); assertCoerceArrayToList(list, array); }