Java Code Examples for org.apache.calcite.sql.SqlWriter#startList()
The following examples show how to use
org.apache.calcite.sql.SqlWriter#startList() .
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: SqlRollupOperator.java From calcite with Apache License 2.0 | 6 votes |
private void unparseCube(SqlWriter writer, SqlCall call) { writer.keyword(call.getOperator().getName()); final SqlWriter.Frame frame = writer.startList(SqlWriter.FrameTypeEnum.FUN_CALL, "(", ")"); for (SqlNode operand : call.getOperandList()) { writer.sep(","); if (operand.getKind() == SqlKind.ROW) { final SqlWriter.Frame frame2 = writer.startList(SqlWriter.FrameTypeEnum.SIMPLE, "(", ")"); for (SqlNode operand2 : ((SqlCall) operand).getOperandList()) { writer.sep(","); operand2.unparse(writer, 0, 0); } writer.endList(frame2); } else if (operand instanceof SqlNodeList && ((SqlNodeList) operand).size() == 0) { writer.keyword("()"); } else { operand.unparse(writer, 0, 0); } } writer.endList(frame); }
Example 2
Source File: SqlLikeOperator.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.startList("", ""); call.operand(0).unparse(writer, getLeftPrec(), getRightPrec()); writer.sep(getName()); call.operand(1).unparse(writer, getLeftPrec(), getRightPrec()); if (call.operandCount() == 3) { writer.sep("ESCAPE"); call.operand(2).unparse(writer, getLeftPrec(), getRightPrec()); } writer.endList(frame); }
Example 3
Source File: SqlAlterHiveTableSerDe.java From flink with Apache License 2.0 | 6 votes |
@Override public void unparse(SqlWriter writer, int leftPrec, int rightPrec) { super.unparse(writer, leftPrec, rightPrec); writer.keyword("SET"); if (serdeLib != null) { writer.keyword("SERDE"); serdeLib.unparse(writer, leftPrec, rightPrec); } if (origSerDeProps != null && origSerDeProps.size() > 0) { if (serdeLib == null) { writer.keyword("SERDEPROPERTIES"); } else { writer.keyword("WITH SERDEPROPERTIES"); } SqlWriter.Frame withFrame = writer.startList("(", ")"); for (SqlNode property : origSerDeProps) { printIndent(writer); property.unparse(writer, leftPrec, rightPrec); } writer.newlineAndIndent(); writer.endList(withFrame); } }
Example 4
Source File: RelToSqlConverterUtil.java From calcite with Apache License 2.0 | 6 votes |
/** Returns a {@link SqlSpecialOperator} with given operator name, mainly used for * unparse override. */ public static SqlSpecialOperator specialOperatorByName(String opName) { return new SqlSpecialOperator(opName, SqlKind.OTHER_FUNCTION) { public void unparse( SqlWriter writer, SqlCall call, int leftPrec, int rightPrec) { writer.print(getName()); final SqlWriter.Frame frame = writer.startList(SqlWriter.FrameTypeEnum.FUN_CALL, "(", ")"); for (SqlNode operand : call.getOperandList()) { writer.sep(","); operand.unparse(writer, 0, 0); } writer.endList(frame); } }; }
Example 5
Source File: SqlCreateFunction.java From calcite with Apache License 2.0 | 6 votes |
@Override public void unparse(SqlWriter writer, int leftPrec, int rightPrec) { writer.keyword(getReplace() ? "CREATE OR REPLACE" : "CREATE"); writer.keyword("FUNCTION"); if (ifNotExists) { writer.keyword("IF NOT EXISTS"); } name.unparse(writer, 0, 0); writer.keyword("AS"); className.unparse(writer, 0, 0); if (usingList.size() > 0) { writer.keyword("USING"); final SqlWriter.Frame frame = writer.startList(SqlWriter.FrameTypeEnum.SIMPLE); for (Pair<SqlLiteral, SqlLiteral> using : pairs()) { writer.sep(","); using.left.unparse(writer, 0, 0); // FILE, URL or ARCHIVE using.right.unparse(writer, 0, 0); // e.g. 'file:foo/bar.jar' } writer.endList(frame); } }
Example 6
Source File: RichSqlInsert.java From flink with Apache License 2.0 | 6 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 (staticPartitions != null && staticPartitions.size() > 0) { writer.keyword("PARTITION"); staticPartitions.unparse(writer, opLeft, opRight); writer.newlineAndIndent(); } getSource().unparse(writer, 0, 0); }
Example 7
Source File: SqlCreateView.java From calcite with Apache License 2.0 | 6 votes |
@Override public void unparse(SqlWriter writer, int leftPrec, int rightPrec) { if (getReplace()) { writer.keyword("CREATE OR REPLACE"); } else { writer.keyword("CREATE"); } writer.keyword("VIEW"); 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 8
Source File: SqlStdOperatorTable.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.startList("(", ")"); call.operand(0).unparse(writer, 0, 0); writer.endList(frame); }
Example 9
Source File: SqlDotOperator.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.startList(SqlWriter.FrameTypeEnum.IDENTIFIER); call.operand(0).unparse(writer, leftPrec, 0); writer.sep("."); call.operand(1).unparse(writer, 0, 0); writer.endList(frame); }
Example 10
Source File: SqlStdOperatorTable.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.startList("(", ")"); call.operand(0).unparse(writer, 0, 0); writer.endList(frame); }
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: SqlRawTypeNameSpec.java From flink with Apache License 2.0 | 5 votes |
@Override public void unparse(SqlWriter writer, int leftPrec, int rightPrec) { writer.keyword(RAW_TYPE_NAME); final SqlWriter.Frame frame = writer.startList(SqlWriter.FrameTypeEnum.FUN_CALL, "(", ")"); writer.sep(","); // configures the writer className.unparse(writer, leftPrec, rightPrec); writer.sep(","); serializerString.unparse(writer, leftPrec, rightPrec); writer.endList(frame); }
Example 13
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 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: 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 16
Source File: SqlTableLike.java From flink with Apache License 2.0 | 5 votes |
@Override public void unparse(SqlWriter writer, int leftPrec, int rightPrec) { writer.keyword("LIKE"); sourceTable.unparse(writer, leftPrec, rightPrec); SqlWriter.Frame frame = writer.startList("(", ")"); for (SqlTableLikeOption option : options) { writer.newlineAndIndent(); writer.print(" "); writer.keyword(option.mergingStrategy.toString()); writer.keyword(option.featureOption.toString()); } writer.newlineAndIndent(); writer.endList(frame); }
Example 17
Source File: SqlAlterHiveTableProps.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 TBLPROPERTIES"); SqlWriter.Frame withFrame = writer.startList("(", ")"); for (SqlNode property : origProps) { printIndent(writer); property.unparse(writer, leftPrec, rightPrec); } writer.newlineAndIndent(); writer.endList(withFrame); }
Example 18
Source File: ClickHouseSqlDialect.java From calcite with Apache License 2.0 | 5 votes |
/** * Unparses datetime floor for ClickHouse. * * @param writer Writer * @param call Call */ private void unparseFloor(SqlWriter writer, SqlCall call) { final SqlLiteral timeUnitNode = call.operand(1); TimeUnitRange unit = (TimeUnitRange) timeUnitNode.getValue(); String funName; switch (unit) { case YEAR: funName = "toStartOfYear"; break; case MONTH: funName = "toStartOfMonth"; break; case WEEK: funName = "toMonday"; break; case DAY: funName = "toDate"; break; case HOUR: funName = "toStartOfHour"; break; case MINUTE: funName = "toStartOfMinute"; break; default: throw new RuntimeException("ClickHouse does not support FLOOR for time unit: " + unit); } writer.print(funName); SqlWriter.Frame frame = writer.startList("(", ")"); call.operand(0).unparse(writer, 0, 0); writer.endList(frame); }
Example 19
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 20
Source File: SqlLiteralChainOperator.java From Bats with Apache License 2.0 | 4 votes |
public void unparse( SqlWriter writer, SqlCall call, int leftPrec, int rightPrec) { final SqlWriter.Frame frame = writer.startList("", ""); SqlCollation collation = null; for (Ord<SqlNode> operand : Ord.zip(call.getOperandList())) { SqlLiteral rand = (SqlLiteral) operand.e; if (operand.i > 0) { // SQL:2003 says there must be a newline between string // fragments. writer.newlineAndIndent(); } if (rand instanceof SqlCharStringLiteral) { NlsString nls = ((SqlCharStringLiteral) rand).getNlsString(); if (operand.i == 0) { collation = nls.getCollation(); // print with prefix writer.literal(nls.asSql(true, false)); } else { // print without prefix writer.literal(nls.asSql(false, false)); } } else if (operand.i == 0) { // print with prefix rand.unparse(writer, leftPrec, rightPrec); } else { // print without prefix if (rand.getTypeName() == SqlTypeName.BINARY) { BitString bs = (BitString) rand.getValue(); writer.literal("'" + bs.toHexString() + "'"); } else { writer.literal("'" + rand.toValue() + "'"); } } } if (collation != null) { collation.unparse(writer, 0, 0); } writer.endList(frame); }