Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow EARLIEST/EARLIEST_BY/LATEST/LATEST_BY for STRING columns without specifying maxStringBytes #14848

Merged
merged 17 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from 7 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 @@ -82,7 +82,7 @@ AggregatorFactory createAggregatorFactory(
String fieldName,
String timeColumn,
ColumnType type,
int maxStringBytes
Integer maxStringBytes
)
{
switch (type.getType()) {
Expand All @@ -108,7 +108,7 @@ AggregatorFactory createAggregatorFactory(
String fieldName,
String timeColumn,
ColumnType type,
int maxStringBytes
Integer maxStringBytes
)
{
switch (type.getType()) {
Expand All @@ -134,7 +134,7 @@ AggregatorFactory createAggregatorFactory(
String fieldName,
String timeColumn,
ColumnType type,
int maxStringBytes
Integer maxStringBytes
)
{
switch (type.getType()) {
Expand All @@ -157,7 +157,7 @@ abstract AggregatorFactory createAggregatorFactory(
String fieldName,
String timeColumn,
ColumnType outputType,
int maxStringBytes
Integer maxStringBytes
);
}

Expand Down Expand Up @@ -236,7 +236,7 @@ public Aggregation toDruidAggregation(
final AggregatorFactory theAggFactory;
switch (args.size()) {
case 1:
theAggFactory = aggregatorType.createAggregatorFactory(aggregatorName, fieldName, null, outputType, -1);
theAggFactory = aggregatorType.createAggregatorFactory(aggregatorName, fieldName, null, outputType, null);
break;
case 2:
int maxStringBytes;
Expand Down Expand Up @@ -327,8 +327,7 @@ private static class EarliestLatestSqlAggFunction extends SqlAggFunction
EARLIEST_LATEST_ARG0_RETURN_TYPE_INFERENCE,
InferTypes.RETURN_TYPE,
OperandTypes.or(
OperandTypes.NUMERIC,
OperandTypes.BOOLEAN,
OperandTypes.ANY,
OperandTypes.sequence(
"'" + aggregatorType.name() + "(expr, maxBytesPerString)'",
OperandTypes.ANY,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public Aggregation toDruidAggregation(
rexNodes.get(1)
),
outputType,
-1
null
);
break;
case 3:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13957,13 +13957,13 @@ public void testGreatestFunctionForStringWithIsNull()
.setVirtualColumns(
expressionVirtualColumn(
"v0",
"CAST(greatest(\"dim1\",\"dim2\"), 'DOUBLE')",
ColumnType.DOUBLE
"greatest(\"dim1\",\"dim2\")",
ColumnType.STRING
)
)
.setGranularity(Granularities.ALL)
.addDimension(new DefaultDimensionSpec("l1", "_d0", ColumnType.LONG))
.addAggregator(new DoubleLastAggregatorFactory("a0", "v0", null))
.addAggregator(new StringLastAggregatorFactory("a0", "v0", null, 1024))
.setPostAggregatorSpecs(ImmutableList.of(
expressionPostAgg("p0", "isnull(\"a0\")")
))
Expand Down Expand Up @@ -14269,4 +14269,31 @@ public void testFilterWithNVLAndNotIn()
)
);
}

@Test
public void testLatestByOnStringColumnWithoutMaxBytesSpecified()
{
testQuery(
"SELECT dim2,LATEST(dim3),LATEST_BY(dim1, __time) FROM druid.foo where dim2='abc' group by 1",
ImmutableList.of(
GroupByQuery.builder()
.setDataSource(CalciteTests.DATASOURCE1)
.setInterval(querySegmentSpec(Filtration.eternity()))
.setGranularity(Granularities.ALL)
.setVirtualColumns(
expressionVirtualColumn("v0", "'abc'", ColumnType.STRING))
.setDimFilter(equality("dim2", "abc", ColumnType.STRING))
.setDimensions(
dimensions(new DefaultDimensionSpec("v0", "d0", ColumnType.STRING)))
.setAggregatorSpecs(
aggregators(
new StringLastAggregatorFactory("a0", "dim3", "__time", 1024),
new StringLastAggregatorFactory("a1", "dim1", "__time", 1024)))
.build()

),
ImmutableList.of(
new Object[] {"abc", useDefault ? "" : null, "def"}
));
}
}