This is an automated email from the ASF dual-hosted git repository. jhyde pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git
commit 5cd75b481943cf7c0069c8d17e521dae6a442e37 Author: Julian Hyde <[email protected]> AuthorDate: Mon Oct 19 22:53:29 2020 -0700 Add an overloaded SqlOperator.createCall --- .../apache/calcite/rel/rel2sql/SqlImplementor.java | 10 ++--- .../main/java/org/apache/calcite/sql/SqlCall.java | 3 +- .../java/org/apache/calcite/sql/SqlOperator.java | 43 ++++++++++++++++------ .../calcite/sql/fun/SqlJsonDepthFunction.java | 5 --- .../calcite/sql/fun/SqlJsonPrettyFunction.java | 5 --- .../calcite/sql/fun/SqlJsonTypeFunction.java | 5 --- .../calcite/sql/SqlSetOptionOperatorTest.java | 5 +-- .../apache/calcite/sql/test/AbstractSqlTester.java | 7 +--- 8 files changed, 40 insertions(+), 43 deletions(-) diff --git a/core/src/main/java/org/apache/calcite/rel/rel2sql/SqlImplementor.java b/core/src/main/java/org/apache/calcite/rel/rel2sql/SqlImplementor.java index 61fa55f..b61e4b8 100644 --- a/core/src/main/java/org/apache/calcite/rel/rel2sql/SqlImplementor.java +++ b/core/src/main/java/org/apache/calcite/rel/rel2sql/SqlImplementor.java @@ -1182,15 +1182,13 @@ public abstract class SqlImplementor { return toSql(op, distinct, newOperandList, -1, collation); } - final SqlNode[] operands; if (op instanceof SqlCountAggFunction && operandList.isEmpty()) { - // If there is no parameter in "count" function, add a star identifier to it - operands = new SqlNode[] {SqlIdentifier.STAR}; - } else { - operands = operandList.toArray(new SqlNode[0]); + // If there is no parameter in "count" function, add a star identifier + // to it. + operandList = ImmutableList.of(SqlIdentifier.STAR); } final SqlCall call = - op.createCall(qualifier, POS, operands); + op.createCall(qualifier, POS, operandList); // Handle filter by generating FILTER (WHERE ...) final SqlCall call2; diff --git a/core/src/main/java/org/apache/calcite/sql/SqlCall.java b/core/src/main/java/org/apache/calcite/sql/SqlCall.java index 389d21f..37cafbf 100755 --- a/core/src/main/java/org/apache/calcite/sql/SqlCall.java +++ b/core/src/main/java/org/apache/calcite/sql/SqlCall.java @@ -83,9 +83,8 @@ public abstract class SqlCall extends SqlNode { } @Override public SqlNode clone(SqlParserPos pos) { - final List<SqlNode> operandList = getOperandList(); return getOperator().createCall(getFunctionQuantifier(), pos, - operandList.toArray(new SqlNode[0])); + getOperandList()); } @Override public void unparse( diff --git a/core/src/main/java/org/apache/calcite/sql/SqlOperator.java b/core/src/main/java/org/apache/calcite/sql/SqlOperator.java index c69596b..5c93326 100644 --- a/core/src/main/java/org/apache/calcite/sql/SqlOperator.java +++ b/core/src/main/java/org/apache/calcite/sql/SqlOperator.java @@ -37,6 +37,7 @@ import org.apache.calcite.util.Litmus; import org.apache.calcite.util.Util; import com.google.common.collect.ImmutableList; +import com.google.common.collect.Iterables; import java.util.Arrays; import java.util.List; @@ -231,14 +232,14 @@ public abstract class SqlOperator { public abstract SqlSyntax getSyntax(); /** - * Creates a call to this operand with an array of operands. + * Creates a call to this operator with an array of operands. * - * <p>The position of the resulting call is the union of the <code> - * pos</code> and the positions of all of the operands. + * <p>The position of the resulting call is the union of the {@code pos} + * and the positions of all of the operands. * - * @param functionQualifier function qualifier (e.g. "DISTINCT"), may be - * @param pos parser position of the identifier of the call - * @param operands array of operands + * @param functionQualifier Function qualifier (e.g. "DISTINCT"), or null + * @param pos Parser position of the identifier of the call + * @param operands Array of operands */ public SqlCall createCall( SqlLiteral functionQualifier, @@ -249,7 +250,25 @@ public abstract class SqlOperator { } /** - * Creates a call to this operand with an array of operands. + * Creates a call to this operator with a list of operands. + * + * <p>The position of the resulting call is the union of the {@code pos} + * and the positions of all of the operands. + * + * @param functionQualifier Function qualifier (e.g. "DISTINCT"), or null + * @param pos Parser position of the identifier of the call + * @param operands List of operands + */ + public final SqlCall createCall( + SqlLiteral functionQualifier, + SqlParserPos pos, + Iterable<? extends SqlNode> operands) { + return createCall(functionQualifier, pos, + Iterables.toArray(operands, SqlNode.class)); + } + + /** + * Creates a call to this operator with an array of operands. * * <p>The position of the resulting call is the union of the <code> * pos</code> and the positions of all of the operands. @@ -265,10 +284,10 @@ public abstract class SqlOperator { } /** - * Creates a call to this operand with a list of operands contained in a + * Creates a call to this operator with a list of operands contained in a * {@link SqlNodeList}. * - * <p>The position of the resulting call inferred from the SqlNodeList. + * <p>The position of the resulting call is inferred from the SqlNodeList. * * @param nodeList List of arguments * @return call to this operator @@ -282,10 +301,10 @@ public abstract class SqlOperator { } /** - * Creates a call to this operand with a list of operands. + * Creates a call to this operator with a list of operands. * - * <p>The position of the resulting call is the union of the <code> - * pos</code> and the positions of all of the operands. + * <p>The position of the resulting call is the union of the {@code pos} + * and the positions of all of the operands. */ public final SqlCall createCall( SqlParserPos pos, diff --git a/core/src/main/java/org/apache/calcite/sql/fun/SqlJsonDepthFunction.java b/core/src/main/java/org/apache/calcite/sql/fun/SqlJsonDepthFunction.java index 94dbb7b..2ade212 100644 --- a/core/src/main/java/org/apache/calcite/sql/fun/SqlJsonDepthFunction.java +++ b/core/src/main/java/org/apache/calcite/sql/fun/SqlJsonDepthFunction.java @@ -52,9 +52,4 @@ public class SqlJsonDepthFunction extends SqlFunction { SqlOperandTypeChecker argType, SqlCall call) { assert call.operandCount() == 1; } - - @Override public SqlCall createCall(SqlLiteral functionQualifier, - SqlParserPos pos, SqlNode... operands) { - return super.createCall(functionQualifier, pos, operands); - } } diff --git a/core/src/main/java/org/apache/calcite/sql/fun/SqlJsonPrettyFunction.java b/core/src/main/java/org/apache/calcite/sql/fun/SqlJsonPrettyFunction.java index 23d77b6..c282cf5 100644 --- a/core/src/main/java/org/apache/calcite/sql/fun/SqlJsonPrettyFunction.java +++ b/core/src/main/java/org/apache/calcite/sql/fun/SqlJsonPrettyFunction.java @@ -50,9 +50,4 @@ public class SqlJsonPrettyFunction extends SqlFunction { SqlOperandTypeChecker argType, SqlCall call) { assert call.operandCount() == 1; } - - @Override public SqlCall createCall(SqlLiteral functionQualifier, - SqlParserPos pos, SqlNode... operands) { - return super.createCall(functionQualifier, pos, operands); - } } diff --git a/core/src/main/java/org/apache/calcite/sql/fun/SqlJsonTypeFunction.java b/core/src/main/java/org/apache/calcite/sql/fun/SqlJsonTypeFunction.java index e477194..4609381 100644 --- a/core/src/main/java/org/apache/calcite/sql/fun/SqlJsonTypeFunction.java +++ b/core/src/main/java/org/apache/calcite/sql/fun/SqlJsonTypeFunction.java @@ -51,9 +51,4 @@ public class SqlJsonTypeFunction extends SqlFunction { SqlOperandTypeChecker argType, SqlCall call) { assert call.operandCount() == 1; } - - @Override public SqlCall createCall(SqlLiteral functionQualifier, - SqlParserPos pos, SqlNode... operands) { - return super.createCall(functionQualifier, pos, operands); - } } diff --git a/core/src/test/java/org/apache/calcite/sql/SqlSetOptionOperatorTest.java b/core/src/test/java/org/apache/calcite/sql/SqlSetOptionOperatorTest.java index 57ace1d..f0abda9 100644 --- a/core/src/test/java/org/apache/calcite/sql/SqlSetOptionOperatorTest.java +++ b/core/src/test/java/org/apache/calcite/sql/SqlSetOptionOperatorTest.java @@ -56,12 +56,11 @@ class SqlSetOptionOperatorTest { private static void checkSqlSetOptionSame(SqlNode node) { SqlSetOption opt = (SqlSetOption) node; - SqlNode[] sqlNodes = new SqlNode[opt.getOperandList().size()]; SqlCall returned = opt.getOperator().createCall( opt.getFunctionQuantifier(), opt.getParserPosition(), - opt.getOperandList().toArray(sqlNodes)); - assertThat((Class) opt.getClass(), equalTo((Class) returned.getClass())); + opt.getOperandList()); + assertThat(opt.getClass(), equalTo(returned.getClass())); SqlSetOption optRet = (SqlSetOption) returned; assertThat(optRet.getScope(), is(opt.getScope())); assertThat(optRet.getName(), is(opt.getName())); diff --git a/core/src/test/java/org/apache/calcite/sql/test/AbstractSqlTester.java b/core/src/test/java/org/apache/calcite/sql/test/AbstractSqlTester.java index b38c84d..f4863dc 100644 --- a/core/src/test/java/org/apache/calcite/sql/test/AbstractSqlTester.java +++ b/core/src/test/java/org/apache/calcite/sql/test/AbstractSqlTester.java @@ -624,11 +624,8 @@ public abstract class AbstractSqlTester implements SqlTester, AutoCloseable { unresolvedFunction.getFunctionType()); if (lookup != null) { operator = lookup; - final SqlNode[] operands = call.getOperandList().toArray(SqlNode.EMPTY_ARRAY); - call = operator.createCall( - call.getFunctionQuantifier(), - call.getParserPosition(), - operands); + call = operator.createCall(call.getFunctionQuantifier(), + call.getParserPosition(), call.getOperandList()); } } if (operator == SqlStdOperatorTable.CAST
