lift restriction of array_to_mv to only support direct column access (#15528)

This commit is contained in:
Clint Wylie 2023-12-08 16:27:17 -08:00 committed by GitHub
parent e68979e03b
commit e7c8f2e208
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 59 additions and 10 deletions

View File

@ -3231,14 +3231,6 @@ public interface Function extends NamedFunction
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

View File

@ -1163,6 +1163,13 @@ public class FunctionTest extends InitializedNullHandlingTest
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

View File

@ -45,6 +45,4 @@ public class ArrayToMultiValueStringOperatorConversion extends DirectOperatorCon
{
super(SQL_FUNCTION, "array_to_mv");
}
}

View File

@ -5344,6 +5344,58 @@ public class CalciteNestedDataQueryTest extends BaseCalciteQueryTest
.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