Java Code Examples for org.apache.calcite.avatica.util.Casing#TO_UPPER

The following examples show how to use org.apache.calcite.avatica.util.Casing#TO_UPPER . 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: SqlAdvisor.java    From Quicksql with MIT License 6 votes vote down vote up
/**
 * Returns casing which is preferred for replacement.
 * For instance, {@code en => ename, EN => ENAME}.
 * When input has mixed case, {@code Casing.UNCHANGED} is returned.
 * @param word input word
 * @return preferred casing when replacing input word
 */
private Casing getPreferredCasing(String word) {
  if (word == prevWord) {
    return prevPreferredCasing;
  }
  boolean hasLower = false;
  boolean hasUpper = false;
  int i = 0;
  while (i < word.length() && !(hasLower && hasUpper)) {
    int codePoint = word.codePointAt(i);
    hasLower |= Character.isLowerCase(codePoint);
    hasUpper |= Character.isUpperCase(codePoint);
    i += Character.charCount(codePoint);
  }
  Casing preferredCasing;
  if (hasUpper && !hasLower) {
    preferredCasing = Casing.TO_UPPER;
  } else if (!hasUpper && hasLower) {
    preferredCasing = Casing.TO_LOWER;
  } else {
    preferredCasing = Casing.UNCHANGED;
  }
  prevWord = word;
  prevPreferredCasing = preferredCasing;
  return preferredCasing;
}
 
Example 2
Source File: SqlDialectFactoryImpl.java    From Quicksql with MIT License 6 votes vote down vote up
private Casing getCasing(DatabaseMetaData databaseMetaData, boolean quoted) {
  try {
    if (quoted
        ? databaseMetaData.storesUpperCaseQuotedIdentifiers()
        : databaseMetaData.storesUpperCaseIdentifiers()) {
      return Casing.TO_UPPER;
    } else if (quoted
        ? databaseMetaData.storesLowerCaseQuotedIdentifiers()
        : databaseMetaData.storesLowerCaseIdentifiers()) {
      return Casing.TO_LOWER;
    } else if (quoted
        ? (databaseMetaData.storesMixedCaseQuotedIdentifiers()
            || databaseMetaData.supportsMixedCaseQuotedIdentifiers())
        : (databaseMetaData.storesMixedCaseIdentifiers()
            || databaseMetaData.supportsMixedCaseIdentifiers())) {
      return Casing.UNCHANGED;
    } else {
      return Casing.UNCHANGED;
    }
  } catch (SQLException e) {
    throw new IllegalArgumentException("cannot deduce casing", e);
  }
}
 
Example 3
Source File: SqlAdvisor.java    From calcite with Apache License 2.0 6 votes vote down vote up
/**
 * Returns casing which is preferred for replacement.
 * For instance, {@code en => ename, EN => ENAME}.
 * When input has mixed case, {@code Casing.UNCHANGED} is returned.
 * @param word input word
 * @return preferred casing when replacing input word
 */
private Casing getPreferredCasing(String word) {
  if (word == prevWord) {
    return prevPreferredCasing;
  }
  boolean hasLower = false;
  boolean hasUpper = false;
  int i = 0;
  while (i < word.length() && !(hasLower && hasUpper)) {
    int codePoint = word.codePointAt(i);
    hasLower |= Character.isLowerCase(codePoint);
    hasUpper |= Character.isUpperCase(codePoint);
    i += Character.charCount(codePoint);
  }
  Casing preferredCasing;
  if (hasUpper && !hasLower) {
    preferredCasing = Casing.TO_UPPER;
  } else if (!hasUpper && hasLower) {
    preferredCasing = Casing.TO_LOWER;
  } else {
    preferredCasing = Casing.UNCHANGED;
  }
  prevWord = word;
  prevPreferredCasing = preferredCasing;
  return preferredCasing;
}
 
Example 4
Source File: SqlDialectFactoryImpl.java    From calcite with Apache License 2.0 6 votes vote down vote up
private Casing getCasing(DatabaseMetaData databaseMetaData, boolean quoted) {
  try {
    if (quoted
        ? databaseMetaData.storesUpperCaseQuotedIdentifiers()
        : databaseMetaData.storesUpperCaseIdentifiers()) {
      return Casing.TO_UPPER;
    } else if (quoted
        ? databaseMetaData.storesLowerCaseQuotedIdentifiers()
        : databaseMetaData.storesLowerCaseIdentifiers()) {
      return Casing.TO_LOWER;
    } else if (quoted
        ? (databaseMetaData.storesMixedCaseQuotedIdentifiers()
            || databaseMetaData.supportsMixedCaseQuotedIdentifiers())
        : (databaseMetaData.storesMixedCaseIdentifiers()
            || databaseMetaData.supportsMixedCaseIdentifiers())) {
      return Casing.UNCHANGED;
    } else {
      return Casing.UNCHANGED;
    }
  } catch (SQLException e) {
    throw new IllegalArgumentException("cannot deduce casing", e);
  }
}
 
Example 5
Source File: SqlDialect.java    From Quicksql with MIT License 5 votes vote down vote up
/** Creates an empty context. Use {@link #EMPTY_CONTEXT} if possible. */
protected static Context emptyContext() {
  return new ContextImpl(DatabaseProduct.UNKNOWN, null, null, -1, -1,
      "'", "''", null,
      Casing.UNCHANGED, Casing.TO_UPPER, true, SqlConformanceEnum.DEFAULT,
      NullCollation.HIGH, RelDataTypeSystemImpl.DEFAULT,
      JethroDataSqlDialect.JethroInfo.EMPTY);
}
 
Example 6
Source File: SqlDialect.java    From calcite with Apache License 2.0 5 votes vote down vote up
/** Creates an empty context. Use {@link #EMPTY_CONTEXT} to reference the instance. */
private static Context emptyContext() {
  return new ContextImpl(DatabaseProduct.UNKNOWN, null, null, -1, -1,
      "'", "''", null,
      Casing.UNCHANGED, Casing.TO_UPPER, true, SqlConformanceEnum.DEFAULT,
      NullCollation.HIGH, RelDataTypeSystemImpl.DEFAULT,
      JethroDataSqlDialect.JethroInfo.EMPTY);
}
 
Example 7
Source File: SqlAdvisor.java    From Quicksql with MIT License 4 votes vote down vote up
/**
 * Gets completion hints for a syntactically correct sql statement with dummy
 * SqlIdentifier
 *
 * @param sql A syntactically correct sql statement for which to retrieve
 *            completion hints
 * @param pos to indicate the line and column position in the query at which
 *            completion hints need to be retrieved. For example, "select
 *            a.ename, b.deptno from sales.emp a join sales.dept b "on
 *            a.deptno=b.deptno where empno=1"; setting pos to 'Line 1, Column
 *            17' returns all the possible column names that can be selected
 *            from sales.dept table setting pos to 'Line 1, Column 31' returns
 *            all the possible table names in 'sales' schema
 * @return an array of hints ({@link SqlMoniker}) that can fill in at the
 * indicated position
 */
public List<SqlMoniker> getCompletionHints(String sql, SqlParserPos pos) {
  // First try the statement they gave us. If this fails, just return
  // the tokens which were expected at the failure point.
  List<SqlMoniker> hintList = new ArrayList<>();
  SqlNode sqlNode = tryParse(sql, hintList);
  if (sqlNode == null) {
    return hintList;
  }

  // Now construct a statement which is bound to fail. (Character 7 BEL
  // is not legal in any SQL statement.)
  final int x = pos.getColumnNum() - 1;
  sql = sql.substring(0, x)
      + " \07"
      + sql.substring(x);
  tryParse(sql, hintList);

  final SqlMoniker star =
      new SqlMonikerImpl(ImmutableList.of("*"), SqlMonikerType.KEYWORD);
  String hintToken =
      parserConfig.unquotedCasing() == Casing.TO_UPPER ? UPPER_HINT_TOKEN : HINT_TOKEN;
  if (hintList.contains(star) && !isSelectListItem(sqlNode, pos, hintToken)) {
    hintList.remove(star);
  }

  // Add the identifiers which are expected at the point of interest.
  try {
    validator.validate(sqlNode);
  } catch (Exception e) {
    // mask any exception that is thrown during the validation, i.e.
    // try to continue even if the sql is invalid. we are doing a best
    // effort here to try to come up with the requested completion
    // hints
    Util.swallow(e, LOGGER);
  }
  final List<SqlMoniker> validatorHints =
      validator.lookupHints(sqlNode, pos);
  hintList.addAll(validatorHints);
  return hintList;
}
 
Example 8
Source File: AvaticaDatabaseMetaData.java    From calcite-avatica with Apache License 2.0 4 votes vote down vote up
public boolean storesUpperCaseIdentifiers() throws SQLException {
  return unquotedCasing() == Casing.TO_UPPER;
}
 
Example 9
Source File: AvaticaDatabaseMetaData.java    From calcite-avatica with Apache License 2.0 4 votes vote down vote up
public boolean storesUpperCaseQuotedIdentifiers() throws SQLException {
  return quotedCasing() == Casing.TO_UPPER;
}
 
Example 10
Source File: SqlAdvisor.java    From calcite with Apache License 2.0 4 votes vote down vote up
/**
 * Gets completion hints for a syntactically correct sql statement with dummy
 * SqlIdentifier
 *
 * @param sql A syntactically correct sql statement for which to retrieve
 *            completion hints
 * @param pos to indicate the line and column position in the query at which
 *            completion hints need to be retrieved. For example, "select
 *            a.ename, b.deptno from sales.emp a join sales.dept b "on
 *            a.deptno=b.deptno where empno=1"; setting pos to 'Line 1, Column
 *            17' returns all the possible column names that can be selected
 *            from sales.dept table setting pos to 'Line 1, Column 31' returns
 *            all the possible table names in 'sales' schema
 * @return an array of hints ({@link SqlMoniker}) that can fill in at the
 * indicated position
 */
public List<SqlMoniker> getCompletionHints(String sql, SqlParserPos pos) {
  // First try the statement they gave us. If this fails, just return
  // the tokens which were expected at the failure point.
  List<SqlMoniker> hintList = new ArrayList<>();
  SqlNode sqlNode = tryParse(sql, hintList);
  if (sqlNode == null) {
    return hintList;
  }

  // Now construct a statement which is bound to fail. (Character 7 BEL
  // is not legal in any SQL statement.)
  final int x = pos.getColumnNum() - 1;
  sql = sql.substring(0, x)
      + " \07"
      + sql.substring(x);
  tryParse(sql, hintList);

  final SqlMoniker star =
      new SqlMonikerImpl(ImmutableList.of("*"), SqlMonikerType.KEYWORD);
  String hintToken =
      parserConfig.unquotedCasing() == Casing.TO_UPPER ? UPPER_HINT_TOKEN : HINT_TOKEN;
  if (hintList.contains(star) && !isSelectListItem(sqlNode, pos, hintToken)) {
    hintList.remove(star);
  }

  // Add the identifiers which are expected at the point of interest.
  try {
    validator.validate(sqlNode);
  } catch (Exception e) {
    // mask any exception that is thrown during the validation, i.e.
    // try to continue even if the sql is invalid. we are doing a best
    // effort here to try to come up with the requested completion
    // hints
    Util.swallow(e, LOGGER);
  }
  final List<SqlMoniker> validatorHints =
      validator.lookupHints(sqlNode, pos);
  hintList.addAll(validatorHints);
  return hintList;
}