@Override public int compare(SqlIdentifier o1, SqlIdentifier o2) { int linegap = o2.getParserPosition().getLineNum() - o1.getParserPosition().getLineNum(); if (linegap != 0) return linegap; return o2.getParserPosition().getColumnNum() - o1.getParserPosition().getColumnNum(); } });
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; }
/** * * @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) { 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(); }
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()); } } }
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()); } } }
@Override public int compare(SqlIdentifier o1, SqlIdentifier o2) { int linegap = o2.getParserPosition().getLineNum() - o1.getParserPosition().getLineNum(); if (linegap != 0) return linegap; return o2.getParserPosition().getColumnNum() - o1.getParserPosition().getColumnNum(); } });
/** * 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; }
@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); } }
/** * 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()); }
private static Node of(int idCounter, SqlTreeNode treeNode) { return new Node( idCounter, treeNode.getNodeType().toString(), treeNode.explain(), new Position( treeNode.getParserPosition().getLineNum(), treeNode.getParserPosition().getColumnNum())); }
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()); } } }
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()); } } }