@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(); }
/** * * @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(); }
private String getViewSubQuerySql(SqlInfo sqlInfo, SqlCreateView sqlNode) { int lineNum = sqlNode.getQuery().getParserPosition().getLineNum(); int columnNum = sqlNode.getQuery().getParserPosition().getColumnNum(); String sql = sqlInfo.getSqlContent(); BufferedReader br = new BufferedReader(new InputStreamReader( new ByteArrayInputStream(sql.getBytes(Charset.forName("utf8"))), Charset.forName("utf8"))); String line; int i = 1; StringBuilder stringBuilder = new StringBuilder(); try { while ((line = br.readLine()) != null) { //System.out.println(line); if (i < lineNum) { stringBuilder.append("\n"); } else if (i == lineNum) { for (int j = 1; j < columnNum; j++) { stringBuilder.append(" "); } stringBuilder.append(line.substring(columnNum - 1)).append('\n'); } else { stringBuilder.append(line).append('\n'); } i++; } } catch (IOException e) { e.printStackTrace(); } return stringBuilder.toString(); }
@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; }
/** * 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); } }
/** * 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()); } } }