Java Code Examples for org.apache.calcite.sql.parser.SqlParserPos#getEndColumnNum()

The following examples show how to use org.apache.calcite.sql.parser.SqlParserPos#getEndColumnNum() . 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: CalciteParser.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
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 2
Source File: CalciteParser.java    From kylin with Apache License 2.0 6 votes vote down vote up
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: SqlValidatorFeatureTest.java    From calcite with Apache License 2.0 6 votes vote down vote up
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());
  }
}
 
Example 4
Source File: SqlAdvisor.java    From Bats with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 5
Source File: SqlUtil.java    From Bats with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 6
Source File: SqlAdvisor.java    From calcite with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 7
Source File: SqlUtil.java    From calcite with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 8
Source File: SqlValidatorImpl.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
private void throwException(SqlParserPos parserPos) {
  throw new CalciteContextException("Failure parsing the query",
                                    new SqlValidatorException("Flatten is not supported as part of join condition", null),
                                    parserPos.getLineNum(), parserPos.getEndLineNum(),
                                    parserPos.getColumnNum(), parserPos.getEndColumnNum());
}