[
https://issues.apache.org/jira/browse/CALCITE-2670?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16689803#comment-16689803
]
Julian Hyde commented on CALCITE-2670:
--------------------------------------
I see what you mean about {{Enum}} parameters. I made the change (see by branch
https://github.com/julianhyde/calcite/tree/2670-refactor-json-functions) and
sure enough, there were some errors, for example
{{CalciteSqlOperatorTest.testJsonArrayAgg}} fails, generating the following
intermediate code:
{code}
public Object current() {
final String current = inputEnumerator.current() == null ? (String)
null : inputEnumerator.current().toString();
return new Object[] {
current == null ? null :
org.apache.calcite.runtime.SqlFunctions.jsonStructuredValueExpression(current),
org.apache.calcite.sql.SqlJsonConstructorNullClause.ABSENT_ON_NULL};
}
};
}
};
java.util.List accumulatorAdders = new java.util.LinkedList();
accumulatorAdders.add(new org.apache.calcite.linq4j.function.Function2() {
public Record1_0 apply(Record1_0 acc, Object[] in) {
org.apache.calcite.runtime.SqlFunctions.jsonArrayAggAdd(acc.f0, in[0],
(Enum) in[1]);
return acc;
}
{code}
The cause seems to be that the flag,
{{org.apache.calcite.sql.SqlJsonConstructorNullClause.ABSENT_ON_NULL}}, is
passed as data {{in[1]}} flowing through the dataflow graph. If it's data, it
has to follow the SQL type system, and of course you can't figure out a more
specific type than Enum. But should it be data? I think the argument should be
hard-coded into the call.
> Combine similar JSON aggregate functions in operator table
> ----------------------------------------------------------
>
> Key: CALCITE-2670
> URL: https://issues.apache.org/jira/browse/CALCITE-2670
> Project: Calcite
> Issue Type: Improvement
> Components: core
> Reporter: Hongze Zhang
> Assignee: Julian Hyde
> Priority: Major
>
> In current code master of Calcite, operator *JSON_ARRAYAGG* and
> *JSON_OBJECTAGG* are separated to *JSON_ARRAYAGG_NULL_ON_NULL*,
> *JSON_ARRAYAGG_ABSENT_ON_NULL*, *JSON_OBJECTAGG_NULL_ON_NULL* and
> *JSON_OBJECTAGG_ABSENT_ON_NULL* in SqlStdOperatorTable.java. This is OK for
> now, but may deliver more difficulty on extending syntax of *JSON_ARRAYAGG*
> and *JSON_OBJECTAGG* and on implementing logical plan by adapters.
> This is basically to combine the 4 operators to 2, this is a improvement list:
> # Combine *JSON_ARRAYAGG_NULL_ON_NULL* and *JSON_ARRAYAGG_ABSENT_ON_NULL;*
> # Combine *JSON_OBJECTAGG_NULL_ON_NULL* and *JSON_OBJECTAGG_ABSENT_ON_NULL;*
> # *SYMBOL* type Support for *JavaTypeFactoryImpl#getJavaClass*
> This is to generate *Enum* java type for *SYMBOL*. Current version of
> Calcite generates *Object[]*, which delivers type casting error, or some
> method compatible problems {color:#333333}when Calcite tries to pass enum
> parameters to an aggregate function;{color}
> # Add SQL-to-Rel test cases for JSON functions.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)