Java Code Examples for org.apache.calcite.sql.SqlCall#unparse()
The following examples show how to use
org.apache.calcite.sql.SqlCall#unparse() .
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 |
/** * For usage of TRIM, LTRIM and RTRIM in Hive, see * <a href="https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF">Hive UDF usage</a>. */ public static void unparseHiveTrim( SqlWriter writer, SqlCall call, int leftPrec, int rightPrec) { final SqlLiteral valueToTrim = call.operand(1); if (valueToTrim.toValue().matches("\\s+")) { unparseTrimWithSpace(writer, call, leftPrec, rightPrec); } else { // SELECT TRIM(both 'A' from "ABC") -> SELECT REGEXP_REPLACE("ABC", '^(A)*', '') final SqlLiteral trimFlag = call.operand(0); final SqlCharStringLiteral regexNode = createRegexPatternLiteral(call.operand(1), trimFlag); final SqlCharStringLiteral blankLiteral = SqlLiteral.createCharString("", call.getParserPosition()); final SqlNode[] trimOperands = new SqlNode[] { call.operand(2), regexNode, blankLiteral }; final SqlCall regexReplaceCall = REGEXP_REPLACE.createCall(SqlParserPos.ZERO, trimOperands); regexReplaceCall.unparse(writer, leftPrec, rightPrec); } }
Example 2
Source File: SqlCreateTable.java From flink with Apache License 2.0 | 4 votes |
@Override public void unparse( SqlWriter writer, int leftPrec, int rightPrec) { writer.keyword("CREATE"); if (isTemporary()) { writer.keyword("TEMPORARY"); } writer.keyword("TABLE"); tableName.unparse(writer, leftPrec, rightPrec); SqlWriter.Frame frame = writer.startList(SqlWriter.FrameTypeEnum.create("sds"), "(", ")"); for (SqlNode column : columnList) { printIndent(writer); if (column instanceof SqlBasicCall) { SqlCall call = (SqlCall) column; SqlCall newCall = call.getOperator().createCall( SqlParserPos.ZERO, call.operand(1), call.operand(0)); newCall.unparse(writer, leftPrec, rightPrec); } else { column.unparse(writer, leftPrec, rightPrec); } } if (tableConstraints.size() > 0) { for (SqlTableConstraint constraint : tableConstraints) { printIndent(writer); constraint.unparse(writer, leftPrec, rightPrec); } } if (watermark != null) { printIndent(writer); watermark.unparse(writer, leftPrec, rightPrec); } writer.newlineAndIndent(); writer.endList(frame); if (comment != null) { writer.newlineAndIndent(); writer.keyword("COMMENT"); comment.unparse(writer, leftPrec, rightPrec); } if (this.partitionKeyList.size() > 0) { writer.newlineAndIndent(); writer.keyword("PARTITIONED BY"); SqlWriter.Frame partitionedByFrame = writer.startList("(", ")"); this.partitionKeyList.unparse(writer, leftPrec, rightPrec); writer.endList(partitionedByFrame); writer.newlineAndIndent(); } if (this.propertyList.size() > 0) { writer.keyword("WITH"); SqlWriter.Frame withFrame = writer.startList("(", ")"); for (SqlNode property : propertyList) { printIndent(writer); property.unparse(writer, leftPrec, rightPrec); } writer.newlineAndIndent(); writer.endList(withFrame); } if (this.tableLike != null) { writer.newlineAndIndent(); this.tableLike.unparse(writer, leftPrec, rightPrec); } }