Java Code Examples for org.apache.calcite.sql.SqlWriter#Frame
The following examples show how to use
org.apache.calcite.sql.SqlWriter#Frame .
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: SqlJsonQueryFunction.java From Bats with Apache License 2.0 | 6 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); final SqlJsonQueryWrapperBehavior wrapperBehavior = getEnumValue(call.operand(1)); 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(2))); writer.keyword("ON EMPTY"); unparseEmptyOrErrorBehavior(writer, getEnumValue(call.operand(3))); writer.keyword("ON ERROR"); writer.endFunCall(frame); }
Example 2
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 3
Source File: SqlCreateMaterializedView.java From calcite with Apache License 2.0 | 6 votes |
@Override public void unparse(SqlWriter writer, int leftPrec, int rightPrec) { writer.keyword("CREATE"); writer.keyword("MATERIALIZED VIEW"); if (ifNotExists) { writer.keyword("IF NOT EXISTS"); } name.unparse(writer, leftPrec, rightPrec); if (columnList != null) { SqlWriter.Frame frame = writer.startList("(", ")"); for (SqlNode c : columnList) { writer.sep(","); c.unparse(writer, 0, 0); } writer.endList(frame); } writer.keyword("AS"); writer.newlineAndIndent(); query.unparse(writer, 0, 0); }
Example 4
Source File: SqlMapTypeNameSpec.java From flink with Apache License 2.0 | 6 votes |
@Override public void unparse(SqlWriter writer, int leftPrec, int rightPrec) { writer.keyword("MAP"); SqlWriter.Frame frame = writer.startList(SqlWriter.FrameTypeEnum.FUN_CALL, "<", ">"); writer.sep(","); // configures the writer keyType.unparse(writer, leftPrec, rightPrec); // Default is nullable. if (!keyType.getNullable()) { writer.keyword("NOT NULL"); } writer.sep(","); valType.unparse(writer, leftPrec, rightPrec); // Default is nullable. if (!valType.getNullable()) { writer.keyword("NOT NULL"); } writer.endList(frame); }
Example 5
Source File: ConvSqlWriter.java From kylin with Apache License 2.0 | 6 votes |
@Override public void userDefinedType(SqlDataTypeSpec typeSpec, int leftPrec, int rightPrec) { keyword(typeSpec.getTypeName().getSimple()); // also print precision and scale for user-defined-type int precision = typeSpec.getPrecision(); int scale = typeSpec.getScale(); if (precision >= 0) { final SqlWriter.Frame frame = startList(SqlWriter.FrameTypeEnum.FUN_CALL, "(", ")"); this.print(precision); if (scale >= 0) { this.sep(",", true); this.print(scale); } this.endList(frame); } }
Example 6
Source File: SqlAlterViewProperties.java From flink with Apache License 2.0 | 5 votes |
@Override public void unparse(SqlWriter writer, int leftPrec, int rightPrec) { super.unparse(writer, leftPrec, rightPrec); writer.keyword("SET"); SqlWriter.Frame withFrame = writer.startList("(", ")"); for (SqlNode property : propertyList) { printIndent(writer); property.unparse(writer, leftPrec, rightPrec); } writer.newlineAndIndent(); writer.endList(withFrame); }
Example 7
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 8
Source File: SqlTimeType.java From flink with Apache License 2.0 | 5 votes |
@Override public void unparse(SqlWriter writer, int leftPrec, int rightPrec) { writer.keyword(SqlTypeName.TIME.name()); if (this.precision >= 0) { final SqlWriter.Frame frame = writer.startList(SqlWriter.FrameTypeEnum.FUN_CALL, "(", ")"); writer.print(precision); writer.endList(frame); } if (this.withLocalTimeZone) { writer.keyword("WITH LOCAL TIME ZONE"); } }
Example 9
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 10
Source File: RichSqlHiveInsert.java From flink with Apache License 2.0 | 5 votes |
@Override public void unparse(SqlWriter writer, int leftPrec, int rightPrec) { writer.startList(SqlWriter.FrameTypeEnum.SELECT); String insertKeyword = "INSERT INTO"; if (isUpsert()) { insertKeyword = "UPSERT INTO"; } else if (isOverwrite()) { insertKeyword = "INSERT OVERWRITE"; } writer.sep(insertKeyword); final int opLeft = getOperator().getLeftPrec(); final int opRight = getOperator().getRightPrec(); getTargetTable().unparse(writer, opLeft, opRight); if (getTargetColumnList() != null) { getTargetColumnList().unparse(writer, opLeft, opRight); } writer.newlineAndIndent(); if (allPartKeys != null && allPartKeys.size() > 0) { writer.keyword("PARTITION"); SqlWriter.Frame frame = writer.startList("(", ")"); for (SqlNode node : allPartKeys) { writer.sep(",", false); SqlIdentifier partKey = (SqlIdentifier) node; SqlProperty spec = partKeyToSpec.get(partKey); if (spec != null) { spec.unparse(writer, leftPrec, rightPrec); } else { partKey.unparse(writer, leftPrec, rightPrec); } } writer.endList(frame); writer.newlineAndIndent(); } getSource().unparse(writer, 0, 0); }
Example 11
Source File: MssqlSqlDialect.java From calcite with Apache License 2.0 | 5 votes |
private void unparseFloorWithUnit(SqlWriter writer, SqlCall call, int charLen, String offset) { writer.print("CONVERT"); SqlWriter.Frame frame = writer.startList("(", ")"); writer.print("DATETIME, CONVERT(VARCHAR(" + charLen + "), "); call.operand(0).unparse(writer, 0, 0); writer.print(", 126)"); if (offset.length() > 0) { writer.print("+'" + offset + "'"); } writer.endList(frame); }
Example 12
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 13
Source File: SqlExtractFunction.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.sep("FROM"); call.operand(1).unparse(writer, 0, 0); writer.endFunCall(frame); }
Example 14
Source File: SqlColumnListConstructor.java From Bats with Apache License 2.0 | 5 votes |
public void unparse( SqlWriter writer, SqlCall call, int leftPrec, int rightPrec) { writer.keyword("ROW"); final SqlWriter.Frame frame = writer.startList("(", ")"); for (SqlNode operand : call.getOperandList()) { writer.sep(","); operand.unparse(writer, leftPrec, rightPrec); } writer.endList(frame); }
Example 15
Source File: ConvSqlWriter.java From kylin with Apache License 2.0 | 5 votes |
@Override public void writeWith(SqlCall call, int leftPrec, int rightPrec) { final SqlWith with = (SqlWith) call; final SqlWriter.Frame frame = this.startList(SqlWriter.FrameTypeEnum.WITH, "WITH", ""); for (SqlNode node : with.withList) { this.sep(","); node.unparse(this, 0, 0); } with.body.unparse(this, 100, 100); this.endList(frame); }
Example 16
Source File: SqlUploadJarNode.java From calcite with Apache License 2.0 | 5 votes |
@Override protected void unparseAlterOperation(SqlWriter writer, int leftPrec, int rightPrec) { writer.keyword("UPLOAD"); writer.keyword("JAR"); SqlWriter.Frame frame = writer.startList("", ""); for (SqlNode jarPath : jarPaths) { jarPath.unparse(writer, leftPrec, rightPrec); } writer.endList(frame); }
Example 17
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 18
Source File: SqlCreateHiveDatabase.java From flink with Apache License 2.0 | 5 votes |
@Override public void unparse(SqlWriter writer, int leftPrec, int rightPrec) { writer.keyword("CREATE DATABASE"); if (isIfNotExists()) { writer.keyword("IF NOT EXISTS"); } getDatabaseName().unparse(writer, leftPrec, rightPrec); if (getComment().isPresent()) { writer.newlineAndIndent(); writer.keyword("COMMENT"); getComment().get().unparse(writer, leftPrec, rightPrec); } if (location != null) { writer.newlineAndIndent(); writer.keyword("LOCATION"); location.unparse(writer, leftPrec, rightPrec); } if (originPropList.size() > 0) { writer.keyword("WITH DBPROPERTIES"); SqlWriter.Frame withFrame = writer.startList("(", ")"); for (SqlNode property : originPropList) { printIndent(writer); property.unparse(writer, leftPrec, rightPrec); } writer.newlineAndIndent(); writer.endList(withFrame); } }
Example 19
Source File: SqlAlterTableProperties.java From flink with Apache License 2.0 | 5 votes |
@Override public void unparse(SqlWriter writer, int leftPrec, int rightPrec) { super.unparse(writer, leftPrec, rightPrec); writer.keyword("SET"); SqlWriter.Frame withFrame = writer.startList("(", ")"); for (SqlNode property : propertyList) { printIndent(writer); property.unparse(writer, leftPrec, rightPrec); } writer.newlineAndIndent(); writer.endList(withFrame); }
Example 20
Source File: BigQuerySqlDialect.java From calcite with Apache License 2.0 | 4 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()) { super.unparseCall(writer, call, leftPrec, rightPrec); } else { SqlSyntax.BINARY.unparse(writer, UNION_DISTINCT, call, leftPrec, rightPrec); } break; case EXCEPT: if (((SqlSetOperator) call.getOperator()).isAll()) { throw new RuntimeException("BigQuery does not support EXCEPT ALL"); } SqlSyntax.BINARY.unparse(writer, EXCEPT_DISTINCT, call, leftPrec, rightPrec); break; case INTERSECT: if (((SqlSetOperator) call.getOperator()).isAll()) { throw new RuntimeException("BigQuery does not support INTERSECT ALL"); } SqlSyntax.BINARY.unparse(writer, INTERSECT_DISTINCT, call, leftPrec, rightPrec); break; case TRIM: unparseTrim(writer, call, leftPrec, rightPrec); break; default: super.unparseCall(writer, call, leftPrec, rightPrec); } }