Java Code Examples for org.apache.calcite.sql.SqlWriter#endFunCall()
The following examples show how to use
org.apache.calcite.sql.SqlWriter#endFunCall() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RelToSqlConverterUtil.java From calcite with Apache License 2.0 | 6 votes |
/** * Unparses TRIM function with value as space. * * <p>For example : * * <blockquote><pre> * SELECT TRIM(both ' ' from "ABC") → SELECT TRIM(ABC) * </pre></blockquote> * * @param writer writer * @param call the call */ private static void unparseTrimWithSpace( SqlWriter writer, SqlCall call, int leftPrec, int rightPrec) { final String operatorName; final SqlLiteral trimFlag = call.operand(0); switch (trimFlag.getValueAs(SqlTrimFunction.Flag.class)) { case LEADING: operatorName = "LTRIM"; break; case TRAILING: operatorName = "RTRIM"; break; default: operatorName = call.getOperator().getName(); break; } final SqlWriter.Frame trimFrame = writer.startFunCall(operatorName); call.operand(2).unparse(writer, leftPrec, rightPrec); writer.endFunCall(trimFrame); }
Example 2
Source File: SqlSubstringFunction.java From calcite with Apache License 2.0 | 6 votes |
public void unparse( SqlWriter writer, SqlCall call, int leftPrec, int rightPrec) { final SqlWriter.Frame frame = writer.startFunCall(getName()); call.operand(0).unparse(writer, leftPrec, rightPrec); writer.sep("FROM"); call.operand(1).unparse(writer, leftPrec, rightPrec); if (3 == call.operandCount()) { writer.sep("FOR"); call.operand(2).unparse(writer, leftPrec, rightPrec); } writer.endFunCall(frame); }
Example 3
Source File: SqlOverlayFunction.java From Bats with Apache License 2.0 | 6 votes |
public void unparse( SqlWriter writer, SqlCall call, int leftPrec, int rightPrec) { final SqlWriter.Frame frame = writer.startFunCall(getName()); call.operand(0).unparse(writer, leftPrec, rightPrec); writer.sep("PLACING"); call.operand(1).unparse(writer, leftPrec, rightPrec); writer.sep("FROM"); call.operand(2).unparse(writer, leftPrec, rightPrec); if (4 == call.operandCount()) { writer.sep("FOR"); call.operand(3).unparse(writer, leftPrec, rightPrec); } writer.endFunCall(frame); }
Example 4
Source File: SqlPositionFunction.java From calcite with Apache License 2.0 | 5 votes |
public void unparse( SqlWriter writer, SqlCall call, int leftPrec, int rightPrec) { final SqlWriter.Frame frame = writer.startFunCall(getName()); call.operand(0).unparse(writer, leftPrec, rightPrec); writer.sep("IN"); call.operand(1).unparse(writer, leftPrec, rightPrec); if (3 == call.operandCount()) { writer.sep("FROM"); call.operand(2).unparse(writer, leftPrec, rightPrec); } writer.endFunCall(frame); }
Example 5
Source File: BigQuerySqlDialect.java From Bats with Apache License 2.0 | 5 votes |
@Override public void unparseCall(final SqlWriter writer, final SqlCall call, final int leftPrec, final int rightPrec) { switch (call.getKind()) { case POSITION: final SqlWriter.Frame frame = writer.startFunCall("STRPOS"); writer.sep(","); call.operand(1).unparse(writer, leftPrec, rightPrec); writer.sep(","); call.operand(0).unparse(writer, leftPrec, rightPrec); if (3 == call.operandCount()) { throw new RuntimeException("3rd operand Not Supported for Function STRPOS in Big Query"); } writer.endFunCall(frame); break; case UNION: if (!((SqlSetOperator) call.getOperator()).isAll()) { SqlSyntax.BINARY.unparse(writer, UNION_DISTINCT, call, leftPrec, rightPrec); } break; case EXCEPT: if (!((SqlSetOperator) call.getOperator()).isAll()) { SqlSyntax.BINARY.unparse(writer, EXCEPT_DISTINCT, call, leftPrec, rightPrec); } break; case INTERSECT: if (!((SqlSetOperator) call.getOperator()).isAll()) { SqlSyntax.BINARY.unparse(writer, INTERSECT_DISTINCT, call, leftPrec, rightPrec); } break; default: super.unparseCall(writer, call, leftPrec, rightPrec); } }
Example 6
Source File: SqlJsonQueryFunction.java From calcite with Apache License 2.0 | 5 votes |
@Override public void unparse(SqlWriter writer, SqlCall call, int leftPrec, int rightPrec) { final SqlWriter.Frame frame = writer.startFunCall(getName()); call.operand(0).unparse(writer, 0, 0); writer.sep(",", true); call.operand(1).unparse(writer, 0, 0); final SqlJsonQueryWrapperBehavior wrapperBehavior = getEnumValue(call.operand(2)); switch (wrapperBehavior) { case WITHOUT_ARRAY: writer.keyword("WITHOUT ARRAY"); break; case WITH_CONDITIONAL_ARRAY: writer.keyword("WITH CONDITIONAL ARRAY"); break; case WITH_UNCONDITIONAL_ARRAY: writer.keyword("WITH UNCONDITIONAL ARRAY"); break; default: throw new IllegalStateException("unreachable code"); } writer.keyword("WRAPPER"); unparseEmptyOrErrorBehavior(writer, getEnumValue(call.operand(3))); writer.keyword("ON EMPTY"); unparseEmptyOrErrorBehavior(writer, getEnumValue(call.operand(4))); writer.keyword("ON ERROR"); writer.endFunCall(frame); }
Example 7
Source File: SqlFloorFunction.java From calcite with Apache License 2.0 | 5 votes |
@Override public void unparse(SqlWriter writer, SqlCall call, int leftPrec, int rightPrec) { final SqlWriter.Frame frame = writer.startFunCall(getName()); if (call.operandCount() == 2) { call.operand(0).unparse(writer, 0, 100); writer.sep("TO"); call.operand(1).unparse(writer, 100, 0); } else { call.operand(0).unparse(writer, 0, 0); } writer.endFunCall(frame); }
Example 8
Source File: HiveSqlDialect.java From calcite with Apache License 2.0 | 5 votes |
@Override public void unparseCall(final SqlWriter writer, final SqlCall call, final int leftPrec, final int rightPrec) { switch (call.getKind()) { case POSITION: final SqlWriter.Frame frame = writer.startFunCall("INSTR"); writer.sep(","); call.operand(1).unparse(writer, leftPrec, rightPrec); writer.sep(","); call.operand(0).unparse(writer, leftPrec, rightPrec); if (3 == call.operandCount()) { throw new RuntimeException("3rd operand Not Supported for Function INSTR in Hive"); } writer.endFunCall(frame); break; case MOD: SqlOperator op = SqlStdOperatorTable.PERCENT_REMAINDER; SqlSyntax.BINARY.unparse(writer, op, call, leftPrec, rightPrec); break; case TRIM: RelToSqlConverterUtil.unparseHiveTrim(writer, call, leftPrec, rightPrec); break; case OTHER_FUNCTION: if (call.getOperator() instanceof SqlSubstringFunction) { final SqlWriter.Frame funCallFrame = writer.startFunCall(call.getOperator().getName()); call.operand(0).unparse(writer, leftPrec, rightPrec); writer.sep(",", true); call.operand(1).unparse(writer, leftPrec, rightPrec); if (3 == call.operandCount()) { writer.sep(",", true); call.operand(2).unparse(writer, leftPrec, rightPrec); } writer.endFunCall(funCallFrame); } else { super.unparseCall(writer, call, leftPrec, rightPrec); } break; default: super.unparseCall(writer, call, leftPrec, rightPrec); } }
Example 9
Source File: BigQuerySqlDialect.java From calcite with Apache License 2.0 | 5 votes |
/** * For usage of TRIM, LTRIM and RTRIM in BQ see * <a href="https://cloud.google.com/bigquery/docs/reference/standard-sql/functions-and-operators#trim"> * BQ Trim Function</a>. */ private void unparseTrim(SqlWriter writer, SqlCall call, int leftPrec, int rightPrec) { final String operatorName; SqlLiteral trimFlag = call.operand(0); SqlLiteral valueToTrim = call.operand(1); switch (trimFlag.getValueAs(SqlTrimFunction.Flag.class)) { case LEADING: operatorName = "LTRIM"; break; case TRAILING: operatorName = "RTRIM"; break; default: operatorName = call.getOperator().getName(); break; } final SqlWriter.Frame trimFrame = writer.startFunCall(operatorName); call.operand(2).unparse(writer, leftPrec, rightPrec); // If the trimmed character is a non-space character, add it to the target SQL. // eg: TRIM(BOTH 'A' from 'ABCD' // Output Query: TRIM('ABC', 'A') if (!valueToTrim.toValue().matches("\\s+")) { writer.literal(","); call.operand(1).unparse(writer, leftPrec, rightPrec); } writer.endFunCall(trimFrame); }
Example 10
Source File: SqlThrowOperator.java From calcite with Apache License 2.0 | 5 votes |
public void unparse( SqlWriter writer, SqlCall call, int leftPrec, int rightPrec) { final SqlWriter.Frame frame = writer.startFunCall(getName()); call.operand(0).unparse(writer, 0, 0); writer.endFunCall(frame); }
Example 11
Source File: SqlConvertFunction.java From Bats with Apache License 2.0 | 5 votes |
public void unparse( SqlWriter writer, SqlCall call, int leftPrec, int rightPrec) { final SqlWriter.Frame frame = writer.startFunCall(getName()); call.operand(0).unparse(writer, leftPrec, rightPrec); writer.sep("USING"); call.operand(1).unparse(writer, leftPrec, rightPrec); writer.endFunCall(frame); }
Example 12
Source File: SqlThrowOperator.java From Bats with Apache License 2.0 | 5 votes |
public void unparse( SqlWriter writer, SqlCall call, int leftPrec, int rightPrec) { final SqlWriter.Frame frame = writer.startFunCall(getName()); call.operand(0).unparse(writer, 0, 0); writer.endFunCall(frame); }
Example 13
Source File: SqlTranslate3Function.java From Bats with Apache License 2.0 | 5 votes |
@Override public void unparse(SqlWriter writer, SqlCall call, int leftPrec, int rightPrec) { final SqlWriter.Frame frame = writer.startFunCall("TRANSLATE"); for (SqlNode sqlNode : call.getOperandList()) { writer.sep(","); sqlNode.unparse(writer, leftPrec, rightPrec); } writer.endFunCall(frame); }
Example 14
Source File: SqlConvertFunction.java From calcite with Apache License 2.0 | 5 votes |
public void unparse( SqlWriter writer, SqlCall call, int leftPrec, int rightPrec) { final SqlWriter.Frame frame = writer.startFunCall(getName()); call.operand(0).unparse(writer, leftPrec, rightPrec); writer.sep("USING"); call.operand(1).unparse(writer, leftPrec, rightPrec); writer.endFunCall(frame); }
Example 15
Source File: SqlJsonExistsFunction.java From Bats with Apache License 2.0 | 5 votes |
@Override public void unparse(SqlWriter writer, SqlCall call, int leftPrec, int rightPrec) { final SqlWriter.Frame frame = writer.startFunCall(getName()); call.operand(0).unparse(writer, 0, 0); if (call.operandCount() == 2) { call.operand(1).unparse(writer, 0, 0); writer.keyword("ON ERROR"); } writer.endFunCall(frame); }
Example 16
Source File: SqlPositionFunction.java From Bats with Apache License 2.0 | 5 votes |
public void unparse( SqlWriter writer, SqlCall call, int leftPrec, int rightPrec) { final SqlWriter.Frame frame = writer.startFunCall(getName()); call.operand(0).unparse(writer, leftPrec, rightPrec); writer.sep("IN"); call.operand(1).unparse(writer, leftPrec, rightPrec); if (3 == call.operandCount()) { writer.sep("FROM"); call.operand(2).unparse(writer, leftPrec, rightPrec); } writer.endFunCall(frame); }
Example 17
Source File: SqlExtractFunction.java From Bats with Apache License 2.0 | 5 votes |
public void unparse( SqlWriter writer, SqlCall call, int leftPrec, int rightPrec) { final SqlWriter.Frame frame = writer.startFunCall(getName()); call.operand(0).unparse(writer, 0, 0); writer.sep("FROM"); call.operand(1).unparse(writer, 0, 0); writer.endFunCall(frame); }
Example 18
Source File: SqlJsonExistsFunction.java From calcite with Apache License 2.0 | 5 votes |
@Override public void unparse(SqlWriter writer, SqlCall call, int leftPrec, int rightPrec) { final SqlWriter.Frame frame = writer.startFunCall(getName()); call.operand(0).unparse(writer, 0, 0); writer.sep(",", true); for (int i = 1; i < call.operandCount(); i++) { call.operand(i).unparse(writer, leftPrec, rightPrec); } if (call.operandCount() == 3) { writer.keyword("ON ERROR"); } writer.endFunCall(frame); }
Example 19
Source File: SqlFloorFunction.java From Bats with Apache License 2.0 | 5 votes |
@Override public void unparse(SqlWriter writer, SqlCall call, int leftPrec, int rightPrec) { final SqlWriter.Frame frame = writer.startFunCall(getName()); if (call.operandCount() == 2) { call.operand(0).unparse(writer, 0, 100); writer.sep("TO"); call.operand(1).unparse(writer, 100, 0); } else { call.operand(0).unparse(writer, 0, 0); } writer.endFunCall(frame); }
Example 20
Source File: SqlTranslate3Function.java From calcite with Apache License 2.0 | 5 votes |
@Override public void unparse(SqlWriter writer, SqlCall call, int leftPrec, int rightPrec) { final SqlWriter.Frame frame = writer.startFunCall("TRANSLATE"); for (SqlNode sqlNode : call.getOperandList()) { writer.sep(","); sqlNode.unparse(writer, leftPrec, rightPrec); } writer.endFunCall(frame); }