Java Code Examples for org.apache.calcite.sql.SqlNode#getParserPosition()
The following examples show how to use
org.apache.calcite.sql.SqlNode#getParserPosition() .
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: SqlLiteralChainOperator.java From Bats with Apache License 2.0 | 6 votes |
public void validateCall( SqlCall call, SqlValidator validator, SqlValidatorScope scope, SqlValidatorScope operandScope) { // per the SQL std, each string fragment must be on a different line final List<SqlNode> operandList = call.getOperandList(); for (int i = 1; i < operandList.size(); i++) { SqlParserPos prevPos = operandList.get(i - 1).getParserPosition(); final SqlNode operand = operandList.get(i); SqlParserPos pos = operand.getParserPosition(); if (pos.getLineNum() <= prevPos.getLineNum()) { throw validator.newValidationError(operand, RESOURCE.stringFragsOnSameLine()); } } }
Example 2
Source File: CalciteParser.java From kylin-on-parquet-v2 with Apache License 2.0 | 6 votes |
public static Pair<Integer, Integer> getReplacePos(SqlNode node, String inputSql) { if (inputSql == null) { return Pair.newPair(0, 0); } String[] lines = inputSql.split("\n"); SqlParserPos pos = node.getParserPosition(); int lineStart = pos.getLineNum(); int lineEnd = pos.getEndLineNum(); int columnStart = pos.getColumnNum() - 1; int columnEnd = pos.getEndColumnNum(); //for the case that sql is multi lines for (int i = 0; i < lineStart - 1; i++) { columnStart += lines[i].length() + 1; } for (int i = 0; i < lineEnd - 1; i++) { columnEnd += lines[i].length() + 1; } //for calcite's bug CALCITE-1875 Pair<Integer, Integer> startEndPos = getPosWithBracketsCompletion(inputSql, columnStart, columnEnd); return startEndPos; }
Example 3
Source File: CalciteParser.java From kylin with Apache License 2.0 | 6 votes |
public static Pair<Integer, Integer> getReplacePos(SqlNode node, String inputSql) { if (inputSql == null) { return Pair.newPair(0, 0); } String[] lines = inputSql.split("\n"); SqlParserPos pos = node.getParserPosition(); int lineStart = pos.getLineNum(); int lineEnd = pos.getEndLineNum(); int columnStart = pos.getColumnNum() - 1; int columnEnd = pos.getEndColumnNum(); //for the case that sql is multi lines for (int i = 0; i < lineStart - 1; i++) { columnStart += lines[i].length() + 1; } for (int i = 0; i < lineEnd - 1; i++) { columnEnd += lines[i].length() + 1; } //for calcite's bug CALCITE-1875 Pair<Integer, Integer> startEndPos = getPosWithBracketsCompletion(inputSql, columnStart, columnEnd); return startEndPos; }
Example 4
Source File: ServerDdlExecutor.java From calcite with Apache License 2.0 | 6 votes |
/** Wraps a query to rename its columns. Used by CREATE VIEW and CREATE * MATERIALIZED VIEW. */ static SqlNode renameColumns(SqlNodeList columnList, SqlNode query) { if (columnList == null) { return query; } final SqlParserPos p = query.getParserPosition(); final SqlNodeList selectList = SqlNodeList.SINGLETON_STAR; final SqlCall from = SqlStdOperatorTable.AS.createCall(p, ImmutableList.<SqlNode>builder() .add(query) .add(new SqlIdentifier("_", p)) .addAll(columnList) .build()); return new SqlSelect(p, null, selectList, from, null, null, null, null, null, null, null, null); }
Example 5
Source File: SqlLiteralChainOperator.java From calcite with Apache License 2.0 | 6 votes |
public void validateCall( SqlCall call, SqlValidator validator, SqlValidatorScope scope, SqlValidatorScope operandScope) { // per the SQL std, each string fragment must be on a different line final List<SqlNode> operandList = call.getOperandList(); for (int i = 1; i < operandList.size(); i++) { SqlParserPos prevPos = operandList.get(i - 1).getParserPosition(); final SqlNode operand = operandList.get(i); SqlParserPos pos = operand.getParserPosition(); if (pos.getLineNum() <= prevPos.getLineNum()) { throw validator.newValidationError(operand, RESOURCE.stringFragsOnSameLine()); } } }
Example 6
Source File: SqlValidatorUtil.java From Bats with Apache License 2.0 | 5 votes |
/** * Converts an expression "expr" into "expr AS alias". */ public static SqlNode addAlias( SqlNode expr, String alias) { final SqlParserPos pos = expr.getParserPosition(); final SqlIdentifier id = new SqlIdentifier(alias, pos); return SqlStdOperatorTable.AS.createCall(pos, expr, id); }
Example 7
Source File: SqlValidatorImpl.java From dremio-oss with Apache License 2.0 | 5 votes |
@Override public void validateAggregateParams(SqlCall aggCall, SqlNode filter, SqlValidatorScope scope) { if (filter != null) { Exception e = new SqlValidatorException("Dremio does not currently support aggregate functions with a filter clause", null); SqlParserPos pos = filter.getParserPosition(); CalciteContextException ex = RESOURCE.validatorContextPoint(pos.getLineNum(), pos.getColumnNum()).ex(e); ex.setPosition(pos.getLineNum(), pos.getColumnNum()); throw ex; } super.validateAggregateParams(aggCall, filter, scope); }
Example 8
Source File: SqlValidatorUtil.java From calcite with Apache License 2.0 | 5 votes |
/** * Converts an expression "expr" into "expr AS alias". */ public static SqlNode addAlias( SqlNode expr, String alias) { final SqlParserPos pos = expr.getParserPosition(); final SqlIdentifier id = new SqlIdentifier(alias, pos); return SqlStdOperatorTable.AS.createCall(pos, expr, id); }
Example 9
Source File: Hoist.java From calcite with 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 10
Source File: SideParser.java From alchemy with Apache License 2.0 | 4 votes |
private static SqlNode createNewFrom(String table, String alias, SqlNode from) { SqlIdentifier identifierFirst = new SqlIdentifier(table, from.getParserPosition()); SqlIdentifier identifierSecond = new SqlIdentifier(alias, from.getParserPosition()); return new SqlBasicCall(new SqlAsOperator(), new SqlNode[] {identifierFirst, identifierSecond}, from.getParserPosition()); }