Java Code Examples for org.apache.calcite.avatica.util.Casing#UNCHANGED
The following examples show how to use
org.apache.calcite.avatica.util.Casing#UNCHANGED .
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 |
/** * 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 |
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 |
/** * 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 |
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 |
/** 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 |
/** 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 |
/** * Gets completion hints for a partially completed or syntactically incorrect * sql statement with cursor pointing to the position where completion hints * are requested. * * <p>Writes into <code>replaced[0]</code> the string that is being * replaced. Includes the cursor and the preceding identifier. For example, * if <code>sql</code> is "select abc^de from t", sets <code> * replaced[0]</code> to "abc". If the cursor is in the middle of * whitespace, the replaced string is empty. The replaced string is never * null. * * @param sql A partial or syntactically incorrect sql statement for * which to retrieve completion hints * @param cursor to indicate the 0-based cursor position in the query at * @param replaced String which is being replaced (output) * @return completion hints */ public List<SqlMoniker> getCompletionHints( String sql, int cursor, String[] replaced) { // search backward starting from current position to find a "word" int wordStart = cursor; boolean quoted = false; while (wordStart > 0 && Character.isJavaIdentifierPart(sql.charAt(wordStart - 1))) { --wordStart; } if ((wordStart > 0) && (sql.charAt(wordStart - 1) == quoteStart())) { quoted = true; --wordStart; } if (wordStart < 0) { return Collections.emptyList(); } // Search forwards to the end of the word we should remove. Eat up // trailing double-quote, if any int wordEnd = cursor; while (wordEnd < sql.length() && Character.isJavaIdentifierPart(sql.charAt(wordEnd))) { ++wordEnd; } if (quoted && (wordEnd < sql.length()) && (sql.charAt(wordEnd) == quoteEnd())) { ++wordEnd; } // remove the partially composed identifier from the // sql statement - otherwise we get a parser exception String word = replaced[0] = sql.substring(wordStart, cursor); if (wordStart < wordEnd) { sql = sql.substring(0, wordStart) + sql.substring(wordEnd); } final List<SqlMoniker> completionHints = getCompletionHints0(sql, wordStart); if (quoted) { word = word.substring(1); } if (word.isEmpty()) { return completionHints; } // If cursor was part of the way through a word, only include hints // which start with that word in the result. final List<SqlMoniker> result = new ArrayList<>(); Casing preferredCasing = getPreferredCasing(word); boolean ignoreCase = preferredCasing != Casing.UNCHANGED; for (SqlMoniker hint : completionHints) { List<String> names = hint.getFullyQualifiedNames(); // For now we treat only simple cases where the added name is the last // See [CALCITE-2439] Smart complete for SqlAdvisor String cname = Util.last(names); if (cname.regionMatches(ignoreCase, 0, word, 0, word.length())) { result.add(hint); } } return result; }
Example 8
Source File: AvaticaDatabaseMetaData.java From calcite-avatica with Apache License 2.0 | 4 votes |
public boolean storesMixedCaseIdentifiers() throws SQLException { return !caseSensitive() && unquotedCasing() == Casing.UNCHANGED; }
Example 9
Source File: AvaticaDatabaseMetaData.java From calcite-avatica with Apache License 2.0 | 4 votes |
public boolean supportsMixedCaseIdentifiers() throws SQLException { return caseSensitive() && unquotedCasing() == Casing.UNCHANGED; }
Example 10
Source File: AvaticaDatabaseMetaData.java From calcite-avatica with Apache License 2.0 | 4 votes |
public boolean storesMixedCaseQuotedIdentifiers() throws SQLException { return !caseSensitive() && quotedCasing() == Casing.UNCHANGED; }
Example 11
Source File: AvaticaDatabaseMetaData.java From calcite-avatica with Apache License 2.0 | 4 votes |
public boolean supportsMixedCaseQuotedIdentifiers() throws SQLException { return caseSensitive() && quotedCasing() == Casing.UNCHANGED; }
Example 12
Source File: ParserConfig.java From dremio-oss with Apache License 2.0 | 4 votes |
@Override public Casing quotedCasing() { return Casing.UNCHANGED; }
Example 13
Source File: ParserConfig.java From dremio-oss with Apache License 2.0 | 4 votes |
@Override public Casing unquotedCasing() { return Casing.UNCHANGED; }
Example 14
Source File: SqlAdvisor.java From calcite with Apache License 2.0 | 4 votes |
/** * Gets completion hints for a partially completed or syntactically incorrect * sql statement with cursor pointing to the position where completion hints * are requested. * * <p>Writes into <code>replaced[0]</code> the string that is being * replaced. Includes the cursor and the preceding identifier. For example, * if <code>sql</code> is "select abc^de from t", sets <code> * replaced[0]</code> to "abc". If the cursor is in the middle of * whitespace, the replaced string is empty. The replaced string is never * null. * * @param sql A partial or syntactically incorrect sql statement for * which to retrieve completion hints * @param cursor to indicate the 0-based cursor position in the query at * @param replaced String which is being replaced (output) * @return completion hints */ public List<SqlMoniker> getCompletionHints( String sql, int cursor, String[] replaced) { // search backward starting from current position to find a "word" int wordStart = cursor; boolean quoted = false; while (wordStart > 0 && Character.isJavaIdentifierPart(sql.charAt(wordStart - 1))) { --wordStart; } if ((wordStart > 0) && (sql.charAt(wordStart - 1) == quoteStart())) { quoted = true; --wordStart; } if (wordStart < 0) { return Collections.emptyList(); } // Search forwards to the end of the word we should remove. Eat up // trailing double-quote, if any int wordEnd = cursor; while (wordEnd < sql.length() && Character.isJavaIdentifierPart(sql.charAt(wordEnd))) { ++wordEnd; } if (quoted && (wordEnd < sql.length()) && (sql.charAt(wordEnd) == quoteEnd())) { ++wordEnd; } // remove the partially composed identifier from the // sql statement - otherwise we get a parser exception String word = replaced[0] = sql.substring(wordStart, cursor); if (wordStart < wordEnd) { sql = sql.substring(0, wordStart) + sql.substring(wordEnd); } final List<SqlMoniker> completionHints = getCompletionHints0(sql, wordStart); if (quoted) { word = word.substring(1); } if (word.isEmpty()) { return completionHints; } // If cursor was part of the way through a word, only include hints // which start with that word in the result. final List<SqlMoniker> result = new ArrayList<>(); Casing preferredCasing = getPreferredCasing(word); boolean ignoreCase = preferredCasing != Casing.UNCHANGED; for (SqlMoniker hint : completionHints) { List<String> names = hint.getFullyQualifiedNames(); // For now we treat only simple cases where the added name is the last // See [CALCITE-2439] Smart complete for SqlAdvisor String cname = Util.last(names); if (cname.regionMatches(ignoreCase, 0, word, 0, word.length())) { result.add(hint); } } return result; }