use of org.apache.druid.segment.data.ComparableList in project druid by druid-io.
the class GroupByQuery method compareDimsForLimitPushDown.
private static int compareDimsForLimitPushDown(final IntList fields, final List<Boolean> needsReverseList, final List<ColumnType> dimensionTypes, final List<StringComparator> comparators, final ResultRow lhs, final ResultRow rhs) {
for (int i = 0; i < fields.size(); i++) {
final int fieldNumber = fields.getInt(i);
final StringComparator comparator = comparators.get(i);
final ColumnType dimensionType = dimensionTypes.get(i);
final int dimCompare;
final Object lhsObj = lhs.get(fieldNumber);
final Object rhsObj = rhs.get(fieldNumber);
if (dimensionType.isNumeric()) {
if (comparator.equals(StringComparators.NUMERIC)) {
dimCompare = DimensionHandlerUtils.compareObjectsAsType(lhsObj, rhsObj, dimensionType);
} else {
dimCompare = comparator.compare(String.valueOf(lhsObj), String.valueOf(rhsObj));
}
} else if (dimensionType.equals(ColumnType.STRING_ARRAY)) {
final ComparableStringArray lhsArr = DimensionHandlerUtils.convertToComparableStringArray(lhsObj);
final ComparableStringArray rhsArr = DimensionHandlerUtils.convertToComparableStringArray(rhsObj);
dimCompare = Comparators.<Comparable>naturalNullsFirst().compare(lhsArr, rhsArr);
} else if (dimensionType.equals(ColumnType.LONG_ARRAY) || dimensionType.equals(ColumnType.DOUBLE_ARRAY)) {
final ComparableList lhsArr = DimensionHandlerUtils.convertToList(lhsObj);
final ComparableList rhsArr = DimensionHandlerUtils.convertToList(rhsObj);
dimCompare = Comparators.<Comparable>naturalNullsFirst().compare(lhsArr, rhsArr);
} else {
dimCompare = comparator.compare((String) lhsObj, (String) rhsObj);
}
if (dimCompare != 0) {
return needsReverseList.get(i) ? -dimCompare : dimCompare;
}
}
return 0;
}
use of org.apache.druid.segment.data.ComparableList in project druid by druid-io.
the class ArrayNumericGroupByColumnSelectorStrategy method processValueFromGroupingKey.
@Override
public void processValueFromGroupingKey(GroupByColumnSelectorPlus selectorPlus, ByteBuffer key, ResultRow resultRow, int keyBufferPosition) {
final int id = key.getInt(keyBufferPosition);
// 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<T> value = dictionary.get(id);
resultRow.set(selectorPlus.getResultRowPosition(), new ComparableList(value));
} else {
resultRow.set(selectorPlus.getResultRowPosition(), null);
}
}
use of org.apache.druid.segment.data.ComparableList in project druid by druid-io.
the class ArrayDoubleGroupByColumnSelectorStrategyTest method testAddingInDictionaryWithObjects.
@Test
public void testAddingInDictionaryWithObjects() {
ColumnValueSelector columnValueSelector = Mockito.mock(ColumnValueSelector.class);
Mockito.when(columnValueSelector.getObject()).thenReturn(new Object[] { 4.0D, 2.0D });
Assert.assertEquals(3, strategy.getOnlyValue(columnValueSelector));
GroupByColumnSelectorPlus groupByColumnSelectorPlus = Mockito.mock(GroupByColumnSelectorPlus.class);
Mockito.when(groupByColumnSelectorPlus.getResultRowPosition()).thenReturn(0);
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));
}
use of org.apache.druid.segment.data.ComparableList in project druid by druid-io.
the class ArrayDoubleGroupByColumnSelectorStrategyTest method testSanity.
@Test
public void testSanity() {
ColumnValueSelector columnValueSelector = Mockito.mock(ColumnValueSelector.class);
Mockito.when(columnValueSelector.getObject()).thenReturn(ImmutableList.of(1.0, 2.0));
Assert.assertEquals(0, strategy.getOnlyValue(columnValueSelector));
GroupByColumnSelectorPlus groupByColumnSelectorPlus = Mockito.mock(GroupByColumnSelectorPlus.class);
Mockito.when(groupByColumnSelectorPlus.getResultRowPosition()).thenReturn(0);
ResultRow row = ResultRow.create(1);
buffer1.putInt(0);
strategy.processValueFromGroupingKey(groupByColumnSelectorPlus, buffer1, row, 0);
Assert.assertEquals(new ComparableList(ImmutableList.of(1.0, 2.0)), row.get(0));
}
use of org.apache.druid.segment.data.ComparableList in project druid by druid-io.
the class ClientQuerySegmentWalkerTest method testGroupByOnArraysLongsAsString.
@Test
public void testGroupByOnArraysLongsAsString() {
final GroupByQuery query = (GroupByQuery) GroupByQuery.builder().setDataSource(ARRAY).setGranularity(Granularities.ALL).setInterval(Collections.singletonList(INTERVAL)).setDimensions(DefaultDimensionSpec.of("al")).build().withId(DUMMY_QUERY_ID);
// when we donot define an outputType, convert {@link ComparableList} 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() }));
}
Aggregations