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 array_to_mv to support expression inputs #15528

Merged
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 @@ -3231,14 +3231,6 @@ public ExprEval apply(List<Expr> args, Expr.ObjectBinding bindings)
public void validateArguments(List<Expr> args)
{
validationHelperCheckArgumentCount(args, 1);
IdentifierExpr expr = args.get(0).getIdentifierExprIfIdentifierExpr();

if (expr == null) {
throw validationFailed(
"argument %s should be an identifier expression. Use array() instead",
args.get(0).toString()
);
}
}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1163,6 +1163,13 @@ public void testArrayToMultiValueStringWithValidInputs()
assertArrayExpr("array_to_mv(a)", new String[]{"foo", "bar", "baz", "foobar"});
assertArrayExpr("array_to_mv(b)", new String[]{"1", "2", "3", "4", "5"});
assertArrayExpr("array_to_mv(c)", new String[]{"3.1", "4.2", "5.3"});
assertArrayExpr("array_to_mv(array(y,z))", new String[]{"2", "3"});
// array type is determined by the first array type
assertArrayExpr("array_to_mv(array_concat(b,c))", new String[]{"1", "2", "3", "4", "5", "3", "4", "5"});
assertArrayExpr(
"array_to_mv(array_concat(c,b))",
new String[]{"3.1", "4.2", "5.3", "1.0", "2.0", "3.0", "4.0", "5.0"}
);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,4 @@ public ArrayToMultiValueStringOperatorConversion()
{
super(SQL_FUNCTION, "array_to_mv");
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -5344,6 +5344,58 @@ public void testGroupByRootSingleTypeArrayLongNullsAsMvd()
.run();
}

@Test
public void testGroupByRootSingleTypeArrayLongNullsAsMvdWithExpression()
{
cannotVectorize();
testBuilder()
.sql(
"SELECT "
+ "ARRAY_TO_MV(ARRAY_CONCAT(arrayLongNulls, arrayLong)), "
+ "SUM(cnt) "
+ "FROM druid.arrays GROUP BY 1"
)
.queryContext(QUERY_CONTEXT_NO_STRINGIFY_ARRAY)
.expectedQueries(
ImmutableList.of(
GroupByQuery.builder()
.setDataSource(TableDataSource.create(DATA_SOURCE_ARRAYS))
.setInterval(querySegmentSpec(Filtration.eternity()))
.setGranularity(Granularities.ALL)
.setDimensions(
dimensions(
new DefaultDimensionSpec("v0", "d0", ColumnType.STRING)
)
)
.setVirtualColumns(expressionVirtualColumn(
"v0",
"array_to_mv(array_concat(\"arrayLongNulls\",\"arrayLong\"))",
ColumnType.STRING
))
.setAggregatorSpecs(aggregators(new LongSumAggregatorFactory("a0", "cnt")))
.setContext(QUERY_CONTEXT_NO_STRINGIFY_ARRAY)
.build()
)
)
.expectedResults(
// 9 isn't present in result because arrayLong rows are null in rows of arrayLongNulls that have value 9
ImmutableList.of(
new Object[]{NullHandling.defaultStringValue(), 10L},
new Object[]{"1", 12L},
new Object[]{"2", 7L},
new Object[]{"3", 9L},
new Object[]{"4", 4L}
)
)
.expectedSignature(
RowSignature.builder()
.add("EXPR$0", ColumnType.STRING)
.add("EXPR$1", ColumnType.LONG)
.build()
)
.run();
}

/**
* MVD version of {@link #testGroupByRootSingleTypeArrayLongNullsFiltered()}
* - implicit unnest since it is an mvd instead of array grouping
Expand Down