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; }
/** * Creates a new ValidateErrorInfo with a SqlParserPos and an error * string. * * @param pos Error position * @param errorMsg Error message */ public ValidateErrorInfo( SqlParserPos pos, String errorMsg) { this.startLineNum = pos.getLineNum(); this.startColumnNum = pos.getColumnNum(); this.endLineNum = pos.getEndLineNum(); this.endColumnNum = pos.getEndColumnNum(); this.errorMsg = errorMsg; }
/** * Creates a new ValidateErrorInfo with a SqlParserPos and an error * string. * * @param pos Error position * @param errorMsg Error message */ public ValidateErrorInfo( SqlParserPos pos, String errorMsg) { this.startLineNum = pos.getLineNum(); this.startColumnNum = pos.getColumnNum(); this.endLineNum = pos.getEndLineNum(); this.endColumnNum = pos.getEndColumnNum(); this.errorMsg = errorMsg; }
/** * Wraps an exception with context. */ public static CalciteContextException newContextException( final SqlParserPos pos, Resources.ExInst<?> e) { int line = pos.getLineNum(); int col = pos.getColumnNum(); int endLine = pos.getEndLineNum(); int endCol = pos.getEndColumnNum(); return newContextException(line, col, endLine, endCol, e); }
/** * Wraps an exception with context. */ public static CalciteContextException newContextException( final SqlParserPos pos, Resources.ExInst<?> e) { int line = pos.getLineNum(); int col = pos.getColumnNum(); int endLine = pos.getEndLineNum(); int endCol = pos.getEndColumnNum(); return newContextException(line, col, endLine, endCol, e); }
/** * Combines this parser position with another to create a * position that spans from the first point in the first to the last point * in the other. */ public SqlParserPos plus(SqlParserPos pos) { return new SqlParserPos( getLineNum(), getColumnNum(), pos.getEndLineNum(), pos.getEndColumnNum()); }
/** * Combines this parser position with another to create a * position that spans from the first point in the first to the last point * in the other. */ public SqlParserPos plus(SqlParserPos pos) { return new SqlParserPos( getLineNum(), getColumnNum(), pos.getEndLineNum(), pos.getEndColumnNum()); }
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; }
/** * Combines this parser position with a list of positions. */ public SqlParserPos plusAll(Collection<SqlNode> nodeList) { int line = getLineNum(); int column = getColumnNum(); int endLine = getEndLineNum(); int endColumn = getEndColumnNum(); return sum(toPos(nodeList), line, column, endLine, endColumn); }
/** * Combines this parser position with a list of positions. */ public SqlParserPos plusAll(Collection<SqlNode> nodeList) { int line = getLineNum(); int column = getColumnNum(); int endLine = getEndLineNum(); int endColumn = getEndColumnNum(); return sum(toPos(nodeList), line, column, endLine, endColumn); }
private static UserException.Builder addParseContext(UserException.Builder builder, String query, SqlParserPos pos){ // Calcite convention is to return column and line numbers as 1-based inclusive positions. return builder.addContext(SQL_QUERY_CONTEXT, query) .addContext(START_LINE_CONTEXT, pos.getLineNum()) .addContext(START_COLUMN_CONTEXT, pos.getColumnNum()) .addContext(END_LINE_CONTEXT, pos.getEndLineNum()) .addContext(END_COLUMN_CONTEXT, pos.getEndColumnNum()); }
testLine = pos.getEndLineNum(); testColumn = pos.getEndColumnNum(); if (testLine > endLine || testLine == endLine && testColumn > endColumn) {
testLine = pos.getEndLineNum(); testColumn = pos.getEndColumnNum(); if (testLine > endLine || testLine == endLine && testColumn > endColumn) {
actualLine = spe.getPos().getLineNum(); actualColumn = spe.getPos().getColumnNum(); actualEndLine = spe.getPos().getEndLineNum(); actualEndColumn = spe.getPos().getEndColumnNum(); if (spe.getCause() != null) { && (actualLine != sap.pos.getLineNum() || actualColumn != sap.pos.getColumnNum() || actualEndLine != sap.pos.getEndLineNum() || actualEndColumn != sap.pos.getEndColumnNum())) { fail(stage.componentName + " threw expected "
protected void validateFeature( Feature feature, SqlParserPos context) { if (feature.equals(disabledFeature)) { CalciteException ex = new CalciteException( FEATURE_DISABLED, null); if (context == null) { throw ex; } throw new CalciteContextException( "location", ex, context.getLineNum(), context.getColumnNum(), context.getEndLineNum(), context.getEndColumnNum()); } } }
SqlParserUtil.lineColToIndex( sql, pos.getEndLineNum(), pos.getEndColumnNum()) + 1; String param = "p" + (p++);
SqlParserUtil.lineColToIndex( sql, pos.getEndLineNum(), pos.getEndColumnNum()) + 1; String param = "p" + (p++);
protected void validateFeature( Feature feature, SqlParserPos context) { if (feature.equals(disabledFeature)) { CalciteException ex = new CalciteException( FEATURE_DISABLED, null); if (context == null) { throw ex; } throw new CalciteContextException( "location", ex, context.getLineNum(), context.getColumnNum(), context.getEndLineNum(), context.getEndColumnNum()); } } }
if ((opOrdinal + 2) >= list.size()) { SqlParserPos lastPos = list.pos(list.size() - 1); final int line = lastPos.getEndLineNum(); final int col = lastPos.getEndColumnNum() + 1; SqlParserPos errPos = new SqlParserPos(line, col, line, col);
if ((opOrdinal + 2) >= list.size()) { SqlParserPos lastPos = list.pos(list.size() - 1); final int line = lastPos.getEndLineNum(); final int col = lastPos.getEndColumnNum() + 1; SqlParserPos errPos = new SqlParserPos(line, col, line, col);