Java Code Examples for org.apache.calcite.sql.parser.SqlParserPos
The following examples show how to use
org.apache.calcite.sql.parser.SqlParserPos. These examples are extracted from open source projects.
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 Project: flink Source File: SqlCreateTable.java License: Apache License 2.0 | 6 votes |
public SqlCreateTable( SqlParserPos pos, SqlIdentifier tableName, SqlNodeList columnList, List<SqlTableConstraint> tableConstraints, SqlNodeList propertyList, SqlNodeList partitionKeyList, @Nullable SqlWatermark watermark, @Nullable SqlCharStringLiteral comment, @Nullable SqlTableLike tableLike, boolean isTemporary) { super(OPERATOR, pos, false, false); this.tableName = requireNonNull(tableName, "tableName should not be null"); this.columnList = requireNonNull(columnList, "columnList should not be null"); this.tableConstraints = requireNonNull(tableConstraints, "table constraints should not be null"); this.propertyList = requireNonNull(propertyList, "propertyList should not be null"); this.partitionKeyList = requireNonNull(partitionKeyList, "partitionKeyList should not be null"); this.watermark = watermark; this.comment = comment; this.tableLike = tableLike; this.isTemporary = isTemporary; }
Example 2
Source Project: Bats Source File: SqlMatchRecognize.java License: Apache License 2.0 | 6 votes |
/** Creates a SqlMatchRecognize. */ public SqlMatchRecognize(SqlParserPos pos, SqlNode tableRef, SqlNode pattern, SqlLiteral strictStart, SqlLiteral strictEnd, SqlNodeList patternDefList, SqlNodeList measureList, SqlNode after, SqlNodeList subsetList, SqlLiteral rowsPerMatch, SqlNodeList partitionList, SqlNodeList orderList, SqlLiteral interval) { super(pos); this.tableRef = Objects.requireNonNull(tableRef); this.pattern = Objects.requireNonNull(pattern); this.strictStart = strictStart; this.strictEnd = strictEnd; this.patternDefList = Objects.requireNonNull(patternDefList); Preconditions.checkArgument(patternDefList.size() > 0); this.measureList = Objects.requireNonNull(measureList); this.after = after; this.subsetList = subsetList; Preconditions.checkArgument(rowsPerMatch == null || rowsPerMatch.value instanceof RowsPerMatchOption); this.rowsPerMatch = rowsPerMatch; this.partitionList = Objects.requireNonNull(partitionList); this.orderList = Objects.requireNonNull(orderList); this.interval = interval; }
Example 3
Source Project: Flink-CEPplus Source File: SqlValidatorImpl.java License: Apache License 2.0 | 6 votes |
/** * Creates the SELECT statement that putatively feeds rows into an UPDATE * statement to be updated. * * @param call Call to the UPDATE operator * @return select statement */ protected SqlSelect createSourceSelectForUpdate(SqlUpdate call) { final SqlNodeList selectList = new SqlNodeList(SqlParserPos.ZERO); selectList.add(SqlIdentifier.star(SqlParserPos.ZERO)); int ordinal = 0; for (SqlNode exp : call.getSourceExpressionList()) { // Force unique aliases to avoid a duplicate for Y with // SET X=Y String alias = SqlUtil.deriveAliasFromOrdinal(ordinal); selectList.add(SqlValidatorUtil.addAlias(exp, alias)); ++ordinal; } SqlNode sourceTable = call.getTargetTable(); if (call.getAlias() != null) { sourceTable = SqlValidatorUtil.addAlias( sourceTable, call.getAlias().getSimple()); } return new SqlSelect(SqlParserPos.ZERO, null, selectList, sourceTable, call.getCondition(), null, null, null, null, null, null); }
Example 4
Source Project: Bats Source File: SqlSelect.java License: Apache License 2.0 | 6 votes |
public SqlSelect(SqlParserPos pos, SqlNodeList keywordList, SqlNodeList selectList, SqlNode from, SqlNode where, SqlNodeList groupBy, SqlNode having, SqlNodeList windowDecls, SqlNodeList orderBy, SqlNode offset, SqlNode fetch) { super(pos); this.keywordList = Objects.requireNonNull(keywordList != null ? keywordList : new SqlNodeList(pos)); this.selectList = selectList; this.from = from; this.where = where; this.groupBy = groupBy; this.having = having; this.windowDecls = Objects.requireNonNull(windowDecls != null ? windowDecls : new SqlNodeList(pos)); this.orderBy = orderBy; this.offset = offset; this.fetch = fetch; }
Example 5
Source Project: calcite Source File: SqlProcedureCallOperator.java License: Apache License 2.0 | 6 votes |
public SqlNode rewriteCall(SqlValidator validator, SqlCall call) { // for now, rewrite "CALL f(x)" to "SELECT f(x) FROM VALUES(0)" // TODO jvs 18-Jan-2005: rewrite to SELECT * FROM TABLE f(x) // once we support function calls as tables return new SqlSelect(SqlParserPos.ZERO, null, new SqlNodeList( Collections.singletonList(call.operand(0)), SqlParserPos.ZERO), SqlStdOperatorTable.VALUES.createCall( SqlParserPos.ZERO, SqlStdOperatorTable.ROW.createCall( SqlParserPos.ZERO, SqlLiteral.createExactNumeric("0", SqlParserPos.ZERO))), null, null, null, null, null, null, null, null); }
Example 6
Source Project: Bats Source File: SqlSelectOperator.java License: Apache License 2.0 | 6 votes |
public SqlCall createCall( SqlLiteral functionQualifier, SqlParserPos pos, SqlNode... operands) { assert functionQualifier == null; return new SqlSelect(pos, (SqlNodeList) operands[0], (SqlNodeList) operands[1], operands[2], operands[3], (SqlNodeList) operands[4], operands[5], (SqlNodeList) operands[6], (SqlNodeList) operands[7], operands[8], operands[9]); }
Example 7
Source Project: Bats Source File: SqlConverter.java License: Apache License 2.0 | 6 votes |
/** * * @param sql * the SQL sent to the server * @param pos * the position of the error * @return The sql with a ^ character under the error */ static String formatSQLParsingError(String sql, SqlParserPos pos) { if (pos == null) { return sql; } StringBuilder sb = new StringBuilder(); String[] lines = sql.split("\n"); for (int i = 0; i < lines.length; i++) { String line = lines[i]; sb.append(line).append("\n"); if (i == (pos.getLineNum() - 1)) { for (int j = 0; j < pos.getColumnNum() - 1; j++) { sb.append(" "); } sb.append("^\n"); } } return sb.toString(); }
Example 8
Source Project: flink Source File: SqlAlterFunction.java License: Apache License 2.0 | 6 votes |
public SqlAlterFunction( SqlParserPos pos, SqlIdentifier functionIdentifier, SqlCharStringLiteral functionClassName, String functionLanguage, boolean ifExists, boolean isTemporary, boolean isSystemFunction) { super(pos); this.functionIdentifier = requireNonNull(functionIdentifier, "functionIdentifier should not be null"); this.functionClassName = requireNonNull(functionClassName, "functionClassName should not be null"); this.isSystemFunction = requireNonNull(isSystemFunction); this.isTemporary = isTemporary; this.functionLanguage = functionLanguage; this.ifExists = ifExists; }
Example 9
Source Project: flink Source File: SqlCreateTable.java License: Apache License 2.0 | 6 votes |
public SqlCreateTable( SqlParserPos pos, SqlIdentifier tableName, SqlNodeList columnList, SqlNodeList primaryKeyList, List<SqlNodeList> uniqueKeysList, SqlNodeList propertyList, SqlNodeList partitionKeyList, SqlCharStringLiteral comment) { super(OPERATOR, pos, false, false); this.tableName = requireNonNull(tableName, "Table name is missing"); this.columnList = requireNonNull(columnList, "Column list should not be null"); this.primaryKeyList = primaryKeyList; this.uniqueKeysList = uniqueKeysList; this.propertyList = propertyList; this.partitionKeyList = partitionKeyList; this.comment = comment; }
Example 10
Source Project: Bats Source File: SqlDataTypeSpec.java License: Apache License 2.0 | 5 votes |
public SqlNode clone(SqlParserPos pos) { return (collectionsTypeName != null) ? new SqlDataTypeSpec(collectionsTypeName, typeName, precision, scale, charSetName, pos) : new SqlDataTypeSpec(typeName, precision, scale, charSetName, timeZone, pos); }
Example 11
Source Project: flink Source File: SqlCreateView.java License: Apache License 2.0 | 5 votes |
@Override public List<SqlNode> getOperandList() { List<SqlNode> ops = new ArrayList<>(); ops.add(viewName); ops.add(fieldList); ops.add(query); ops.add(SqlLiteral.createBoolean(getReplace(), SqlParserPos.ZERO)); return ops; }
Example 12
Source Project: calcite Source File: SqlExplain.java License: Apache License 2.0 | 5 votes |
public SqlExplain(SqlParserPos pos, SqlNode explicandum, SqlLiteral detailLevel, SqlLiteral depth, SqlLiteral format, int dynamicParameterCount) { super(pos); this.explicandum = explicandum; this.detailLevel = detailLevel; this.depth = depth; this.format = format; this.dynamicParameterCount = dynamicParameterCount; }
Example 13
Source Project: flink Source File: SqlValidatorImpl.java License: Apache License 2.0 | 5 votes |
private void lookupSelectHints( SqlValidatorNamespace ns, SqlParserPos pos, Collection<SqlMoniker> hintList) { final SqlNode node = ns.getNode(); if (node instanceof SqlSelect) { lookupSelectHints((SqlSelect) node, pos, hintList); } }
Example 14
Source Project: quark Source File: SqlCreateQuarkView.java License: Apache License 2.0 | 5 votes |
public SqlCreateQuarkView(SqlParserPos pos, SqlIdentifier viewName, SqlIdentifier tableName, SqlNode query) { super(pos); this.viewName = viewName; this.query = query; this.tableName = tableName; }
Example 15
Source Project: Flink-CEPplus Source File: SqlValidatorImpl.java License: Apache License 2.0 | 5 votes |
/** Moves fields according to the permutation. */ public void permute(List<SqlNode> selectItems, List<Map.Entry<String, RelDataType>> fields) { if (trivial) { return; } final List<SqlNode> oldSelectItems = ImmutableList.copyOf(selectItems); selectItems.clear(); final List<Map.Entry<String, RelDataType>> oldFields = ImmutableList.copyOf(fields); fields.clear(); for (ImmutableIntList source : sources) { final int p0 = source.get(0); Map.Entry<String, RelDataType> field = oldFields.get(p0); final String name = field.getKey(); RelDataType type = field.getValue(); SqlNode selectItem = oldSelectItems.get(p0); for (int p1 : Util.skip(source)) { final Map.Entry<String, RelDataType> field1 = oldFields.get(p1); final SqlNode selectItem1 = oldSelectItems.get(p1); final RelDataType type1 = field1.getValue(); // output is nullable only if both inputs are final boolean nullable = type.isNullable() && type1.isNullable(); final RelDataType type2 = SqlTypeUtil.leastRestrictiveForComparison(typeFactory, type, type1); selectItem = SqlStdOperatorTable.AS.createCall(SqlParserPos.ZERO, SqlStdOperatorTable.COALESCE.createCall(SqlParserPos.ZERO, maybeCast(selectItem, type, type2), maybeCast(selectItem1, type1, type2)), new SqlIdentifier(name, SqlParserPos.ZERO)); type = typeFactory.createTypeWithNullability(type2, nullable); } fields.add(Pair.of(name, type)); selectItems.add(selectItem); } }
Example 16
Source Project: calcite Source File: SqlSetOption.java License: Apache License 2.0 | 5 votes |
@Override public List<SqlNode> getOperandList() { final List<SqlNode> operandList = new ArrayList<>(); if (scope == null) { operandList.add(null); } else { operandList.add(new SqlIdentifier(scope, SqlParserPos.ZERO)); } operandList.add(name); operandList.add(value); return ImmutableNullableList.copyOf(operandList); }
Example 17
Source Project: flink Source File: SqlAlterTableDropConstraint.java License: Apache License 2.0 | 5 votes |
/** * Creates an alter table drop constraint node. * * @param tableID Table ID * @param constraintName Constraint name * @param pos Parser position */ public SqlAlterTableDropConstraint( SqlIdentifier tableID, SqlIdentifier constraintName, SqlParserPos pos) { super(pos, tableID); this.constraintName = constraintName; }
Example 18
Source Project: dremio-oss Source File: SqlRefreshReflection.java License: Apache License 2.0 | 5 votes |
@Override public SqlCall createCall(SqlLiteral functionQualifier, SqlParserPos pos, SqlNode... operands) { Preconditions.checkArgument(operands.length == 2, "SqlRefreshReflection.createCall() has to get 3 operands!"); return new SqlRefreshReflection( pos, (SqlLiteral) operands[0], (SqlLiteral) operands[1] ); }
Example 19
Source Project: Mycat2 Source File: MycatCalciteMySqlNodeVisitor.java License: GNU General Public License v3.0 | 5 votes |
public boolean visit(SQLExistsExpr x) { SqlOperator sqlOperator = SqlStdOperatorTable.EXISTS; SqlNode sqlNode = sqlOperator.createCall(SqlParserPos.ZERO, convertToSqlNode(x.getSubQuery())); if(x.isNot()){ sqlNode = SqlStdOperatorTable.NOT.createCall(SqlParserPos.ZERO,sqlNode); } this.sqlNode = sqlNode; return false; }
Example 20
Source Project: Bats Source File: RexSqlStandardConvertletTable.java License: Apache License 2.0 | 5 votes |
public SqlNode convertCall(RexToSqlNodeConverter converter, RexCall call) { SqlNode[] operands = convertExpressionList(converter, call.getOperands()); if (operands == null) { return null; } return new SqlBasicCall(op, operands, SqlParserPos.ZERO); }
Example 21
Source Project: Mycat2 Source File: MycatCalciteMySqlNodeVisitor.java License: GNU General Public License v3.0 | 5 votes |
public boolean visit(SQLTimestampExpr x) { String literal = x.getLiteral(); int precision = 0; if (literal.endsWith("00")) { char c3 = literal.charAt(literal.length() - 3); if (c3 >= '0' && c3 <= '9') { literal = literal.substring(0, literal.length() - 2); precision = 3; } } TimestampString ts = new TimestampString(literal); sqlNode = SqlLiteral.createTimestamp(ts, precision, SqlParserPos.ZERO); return false; }
Example 22
Source Project: Mycat2 Source File: MycatCalciteMySqlNodeVisitor.java License: GNU General Public License v3.0 | 5 votes |
@Override public boolean visit(SQLExtractExpr x) { x.getValue().accept(this); TimeUnit timeUnits[] = getTimeUnit(x.getUnit()); sqlNode = SqlStdOperatorTable.EXTRACT .createCall(SqlParserPos.ZERO , new SqlIntervalQualifier(timeUnits[0], timeUnits[1], SqlParserPos.ZERO) , sqlNode); return false; }
Example 23
Source Project: Bats Source File: SqlIdentifier.java License: Apache License 2.0 | 5 votes |
/** Returns an identifier that is the same as this except with a component * added at a given position. Does not modify this identifier. */ public SqlIdentifier add(int i, String name, SqlParserPos pos) { final List<String> names2 = new ArrayList<>(names); names2.add(i, name); final List<SqlParserPos> pos2; if (componentPositions == null) { pos2 = null; } else { pos2 = new ArrayList<>(componentPositions); pos2.add(i, pos); } return new SqlIdentifier(names2, collation, pos, pos2); }
Example 24
Source Project: calcite Source File: HsqldbSqlDialect.java License: Apache License 2.0 | 5 votes |
@Override public SqlNode rewriteSingleValueExpr(SqlNode aggCall) { final SqlNode operand = ((SqlBasicCall) aggCall).operand(0); final SqlLiteral nullLiteral = SqlLiteral.createNull(SqlParserPos.ZERO); final SqlNode unionOperand = SqlStdOperatorTable.VALUES.createCall(SqlParserPos.ZERO, SqlLiteral.createApproxNumeric("0", SqlParserPos.ZERO)); // For hsqldb, generate // CASE COUNT(*) // WHEN 0 THEN NULL // WHEN 1 THEN MIN(<result>) // ELSE (VALUES 1 UNION ALL VALUES 1) // END final SqlNode caseExpr = new SqlCase(SqlParserPos.ZERO, SqlStdOperatorTable.COUNT.createCall(SqlParserPos.ZERO, operand), SqlNodeList.of( SqlLiteral.createExactNumeric("0", SqlParserPos.ZERO), SqlLiteral.createExactNumeric("1", SqlParserPos.ZERO)), SqlNodeList.of( nullLiteral, SqlStdOperatorTable.MIN.createCall(SqlParserPos.ZERO, operand)), SqlStdOperatorTable.SCALAR_QUERY.createCall(SqlParserPos.ZERO, SqlStdOperatorTable.UNION_ALL .createCall(SqlParserPos.ZERO, unionOperand, unionOperand))); LOGGER.debug("SINGLE_VALUE rewritten into [{}]", caseExpr); return caseExpr; }
Example 25
Source Project: calcite Source File: StandardConvertletTable.java License: Apache License 2.0 | 5 votes |
private SqlNode getCastedSqlNode(SqlNode argInput, RelDataType varType, SqlParserPos pos, RexNode argRex) { SqlNode arg; if (argRex != null && !argRex.getType().equals(varType)) { arg = SqlStdOperatorTable.CAST.createCall( pos, argInput, SqlTypeUtil.convertTypeToSpec(varType)); } else { arg = argInput; } return arg; }
Example 26
Source Project: Bats Source File: SqlLiteral.java License: Apache License 2.0 | 5 votes |
@Deprecated // to be removed before 2.0 public static SqlTimeLiteral createTime( Calendar calendar, int precision, SqlParserPos pos) { return createTime(TimeString.fromCalendarFields(calendar), precision, pos); }
Example 27
Source Project: calcite Source File: SqlSelect.java License: Apache License 2.0 | 5 votes |
public SqlSelect(SqlParserPos pos, SqlNodeList keywordList, SqlNodeList selectList, SqlNode from, SqlNode where, SqlNodeList groupBy, SqlNode having, SqlNodeList windowDecls, SqlNodeList orderBy, SqlNode offset, SqlNode fetch, SqlNodeList hints) { super(pos); this.keywordList = Objects.requireNonNull(keywordList != null ? keywordList : new SqlNodeList(pos)); this.selectList = selectList; this.from = from; this.where = where; this.groupBy = groupBy; this.having = having; this.windowDecls = Objects.requireNonNull(windowDecls != null ? windowDecls : new SqlNodeList(pos)); this.orderBy = orderBy; this.offset = offset; this.fetch = fetch; this.hints = hints; }
Example 28
Source Project: Mycat2 Source File: MycatCalciteMySqlNodeVisitor.java License: GNU General Public License v3.0 | 5 votes |
public boolean visit(SQLInListExpr x) { SqlNodeList sqlNodes = convertToSqlNodeList(x.getTargetList()); SqlOperator sqlOperator = x.isNot() ? SqlStdOperatorTable.NOT_IN : SqlStdOperatorTable.IN; sqlNode = new SqlBasicCall(sqlOperator, new SqlNode[] { convertToSqlNode(x.getExpr()), sqlNodes }, SqlParserPos.ZERO); return false; }
Example 29
Source Project: calcite Source File: Hoist.java License: Apache License 2.0 | 5 votes |
private Variable(String originalSql, int ordinal, SqlNode node) { this.originalSql = Objects.requireNonNull(originalSql); this.ordinal = ordinal; this.node = Objects.requireNonNull(node); final SqlParserPos pos = node.getParserPosition(); start = SqlParserUtil.lineColToIndex(originalSql, pos.getLineNum(), pos.getColumnNum()); end = SqlParserUtil.lineColToIndex(originalSql, pos.getEndLineNum(), pos.getEndColumnNum()) + 1; Preconditions.checkArgument(ordinal >= 0); Preconditions.checkArgument(start >= 0); Preconditions.checkArgument(start <= end); Preconditions.checkArgument(end <= originalSql.length()); }
Example 30
Source Project: Bats Source File: SqlJdbcFunctionCall.java License: Apache License 2.0 | 5 votes |
public SqlCall getLookupCall() { if (null == lookupCall) { lookupCall = lookupMakeCallObj.createCall(SqlParserPos.ZERO, thisOperands); } return lookupCall; }