[
https://issues.apache.org/jira/browse/CALCITE-5884?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17750058#comment-17750058
]
Mihai Budiu edited comment on CALCITE-5884 at 8/2/23 1:22 AM:
--------------------------------------------------------------
I have changed this to a bug. This is not just a matter of efficiency, it looks
like PROJECT_REDUCE_EXPRESSIONS uses this information to incorrectly reduce the
above query to a NULL result.
The following test in RelOptRulesTest shows this:
{code:java}
@Test void testArrayToString() {
final String sql = "select array_to_string(array['1','2','3','4',NULL,'6'],
NULL)";
sql(sql).withFactory(
t -> t.withOperatorTable(opTab ->
SqlLibraryOperatorTableFactory.INSTANCE.getOperatorTable(
SqlLibrary.STANDARD, SqlLibrary.BIG_QUERY))) // needed for
array_to_string function
.withRule(CoreRules.PROJECT_REDUCE_EXPRESSIONS)
.check();
}
{code}
The resulting plan is:
{code}
LogicalProject(EXPR$0=[null:VARCHAR])
LogicalValues(tuples=[[{ 0 }]])
{code}
was (Author: JIRAUSER295926):
I have changed this to a bug. This is not just a matter of efficiency, it looks
like PROJECT_REDUCE_EXPRESSIONS uses this information to incorrectly reduce the
above query to a NULL result.
The following test in RelOptRulesTest shows this:
{code:java}
@Test void testArrayToString() {
final String sql = "select array_to_string(array['1','2','3','4',NULL,'6'],
NULL)";
sql(sql).withFactory(
t -> t.withOperatorTable(opTab ->
SqlLibraryOperatorTableFactory.INSTANCE.getOperatorTable(
SqlLibrary.STANDARD, SqlLibrary.BIG_QUERY))) // needed for
array_to_string function
.withRule(CoreRules.PROJECT_REDUCE_EXPRESSIONS)
.check();
}
{code}
The resulting plan is:
LogicalProject(EXPR$0=[null:VARCHAR])
LogicalValues(tuples=[[{ 0 }]])
> Type Inference rule for ARRAY_TO_STRING is incorrect
> ----------------------------------------------------
>
> Key: CALCITE-5884
> URL: https://issues.apache.org/jira/browse/CALCITE-5884
> Project: Calcite
> Issue Type: Bug
> Components: core
> Affects Versions: 1.35.0
> Reporter: Mihai Budiu
> Priority: Trivial
>
> This is the current definition of the function ARRAY_TO_STRING in
> SqlLibraryOperators:
> {code:java}
> /** The "ARRAY_TO_STRING(array, delimiter [, nullText ])" function. */
> @LibraryOperator(libraries = {BIG_QUERY})
> public static final SqlFunction ARRAY_TO_STRING =
> SqlBasicFunction.create(SqlKind.ARRAY_TO_STRING,
> ReturnTypes.VARCHAR_NULLABLE,
> OperandTypes.STRING_ARRAY_CHARACTER_OPTIONAL_CHARACTER);
> {code}
> So the result is nullable if any of the arguments is nullable. However, the
> nullability of the last argument does not influence the result nullabillity:
> a NULL value for the third optional argument will not cause a NULL value to
> be output.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)