Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,20 @@ public Aggregation toDruidAggregation(
theAggFactory = aggregatorType.createAggregatorFactory(aggregatorName, fieldName, null, outputType, -1);
break;
case 2:
int maxStringBytes;
try {
maxStringBytes = RexLiteral.intValue(rexNodes.get(1));
}
catch (AssertionError ae) {
plannerContext.setPlanningError("The second argument '%s' to function '%s' is not a number", rexNodes.get(1), aggregateCall.getName());
return null;
}
theAggFactory = aggregatorType.createAggregatorFactory(
aggregatorName,
fieldName,
null,
outputType,
RexLiteral.intValue(rexNodes.get(1))
maxStringBytes
);
break;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,20 @@ public Aggregation toDruidAggregation(
);
break;
case 3:
int maxStringBytes;
try {
maxStringBytes = RexLiteral.intValue(rexNodes.get(2));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the docs, it seems that maxBytesPerString is always the second argument, i.e. rexNodes.get(1)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For EARLIEST_BY/LATEST_BY, it's the third argument. For non _BY aggregators, it's second argument.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed the error message though.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the clarification, I was looking at an older doc in the original PR.

}
catch (AssertionError ae) {
plannerContext.setPlanningError("The third argument '%s' to function '%s' is not a number", rexNodes.get(2), aggregateCall.getName());
return null;
}
theAggFactory = aggregatorType.createAggregatorFactory(
aggregatorName,
fieldName,
EarliestLatestAnySqlAggregator.getColumnName(plannerContext, virtualColumnRegistry, args.get(1), rexNodes.get(1)),
outputType,
RexLiteral.intValue(rexNodes.get(2))
maxStringBytes
);
break;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -998,6 +998,56 @@ public void testStringLatestGroupBy()
);
}

@Test
public void testStringLatestGroupByWithAlwaysFalseCondition()
{
testQuery(
"SELECT LATEST(dim4, 10),dim2 FROM numfoo WHERE (dim1 = 'something' AND dim1 IN( 'something else') ) GROUP BY dim2",
ImmutableList.of(
Druids.newScanQueryBuilder()
.dataSource(InlineDataSource.fromIterable(
ImmutableList.of(),
RowSignature.builder()
.add("EXPR$0", ColumnType.STRING)
.add("dim2", ColumnType.STRING)
.build()
))
.intervals(querySegmentSpec(Filtration.eternity()))
.columns("EXPR$0", "dim2")
.context(QUERY_CONTEXT_DEFAULT)
.resultFormat(ResultFormat.RESULT_FORMAT_COMPACTED_LIST)
.legacy(false)
.build()
),
ImmutableList.of()
);
}

@Test
public void testStringLatestByGroupByWithAlwaysFalseCondition()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Maybe also add a test case to verify error message?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was not able to figure out a query that gets me that error message. This query is not an invalid query. It just goes through a bad stage and doesn't recover before this fix. Now it can.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps a LATEST(dim4, "100") but it's not essential, we can do it later.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that SQL will generate a different error and fails even before reaching the SqlAggregagtor.

{
testQuery(
"SELECT LATEST_BY(dim4, __time, 10),dim2 FROM numfoo WHERE (dim1 = 'something' AND dim1 IN( 'something else') ) GROUP BY dim2",
ImmutableList.of(
Druids.newScanQueryBuilder()
.dataSource(InlineDataSource.fromIterable(
ImmutableList.of(),
RowSignature.builder()
.add("EXPR$0", ColumnType.STRING)
.add("dim2", ColumnType.STRING)
.build()
))
.intervals(querySegmentSpec(Filtration.eternity()))
.columns("EXPR$0", "dim2")
.context(QUERY_CONTEXT_DEFAULT)
.resultFormat(ResultFormat.RESULT_FORMAT_COMPACTED_LIST)
.legacy(false)
.build()
),
ImmutableList.of()
);
}

// This test the off-heap (buffer) version of the EarliestAggregator (Double/Float/Long)
@Test
public void testPrimitiveEarliestInSubquery()
Expand Down