/** * Given a table alias, find the corresponding {@link Table} associated with it * */ private Table findTable(String alias) { List<String> names = null; if (tableScope == null) { // no tables to find return null; } for (ScopeChild child : tableScope.children) { if (catalogReader.nameMatcher().matches(child.name, alias)) { names = ((SqlIdentifier) child.namespace.getNode()).names; break; } } if (names == null || names.size() == 0) { return null; } else if (names.size() == 1) { return findTable(catalogReader.getRootSchema(), names.get(0), catalogReader.nameMatcher().isCaseSensitive()); } CalciteSchema.TableEntry entry = SqlValidatorUtil.getTableEntry(catalogReader, names); return entry == null ? null : entry.getTable(); }
for (SqlNode s : select.getSelectList()) { final String alias = SqlValidatorUtil.getAlias(s, -1); if (alias != null && nameMatcher.matches(alias, name)) { expr = s; n++;
@SuppressWarnings("deprecation") public boolean matches(String string, String name) { return nameMatcher.matches(string, name); }
@SuppressWarnings("deprecation") public boolean matches(String string, String name) { return nameMatcher.matches(string, name); }
/** Returns the number of columns in the SELECT clause that have {@code name} * as their implicit (e.g. {@code t.name}) or explicit (e.g. * {@code t.c as name}) alias. */ private int aliasCount(SqlNameMatcher nameMatcher, String name) { int n = 0; for (SqlNode s : select.getSelectList()) { final String alias = SqlValidatorUtil.getAlias(s, -1); if (alias != null && nameMatcher.matches(alias, name)) { n++; } } return n; }
/** Returns the number of columns in the SELECT clause that have {@code name} * as their implicit (e.g. {@code t.name}) or explicit (e.g. * {@code t.c as name}) alias. */ private int aliasCount(SqlNameMatcher nameMatcher, String name) { int n = 0; for (SqlNode s : select.getSelectList()) { final String alias = SqlValidatorUtil.getAlias(s, -1); if (alias != null && nameMatcher.matches(alias, name)) { n++; } } return n; }
/** * Finds and returns {@link CalciteSchema} nested to the given rootSchema * with specified schemaPath. * * <p>Uses the case-sensitivity policy of specified nameMatcher. * * <p>If not found, returns null. * * @param rootSchema root schema * @param schemaPath full schema path of required schema * @param nameMatcher name matcher * * @return CalciteSchema that corresponds specified schemaPath */ public static CalciteSchema getSchema(CalciteSchema rootSchema, Iterable<String> schemaPath, SqlNameMatcher nameMatcher) { CalciteSchema schema = rootSchema; for (String schemaName : schemaPath) { if (schema == rootSchema && nameMatcher.matches(schemaName, schema.getName())) { continue; } schema = schema.getSubSchema(schemaName, nameMatcher.isCaseSensitive()); if (schema == null) { return null; } } return schema; }
/** * Finds and returns {@link CalciteSchema} nested to the given rootSchema * with specified schemaPath. * * <p>Uses the case-sensitivity policy of specified nameMatcher. * * <p>If not found, returns null. * * @param rootSchema root schema * @param schemaPath full schema path of required schema * @param nameMatcher name matcher * * @return CalciteSchema that corresponds specified schemaPath */ public static CalciteSchema getSchema(CalciteSchema rootSchema, Iterable<String> schemaPath, SqlNameMatcher nameMatcher) { CalciteSchema schema = rootSchema; for (String schemaName : schemaPath) { if (schema == rootSchema && nameMatcher.matches(schemaName, schema.getName())) { continue; } schema = schema.getSubSchema(schemaName, nameMatcher.isCaseSensitive()); if (schema == null) { return null; } } return schema; }
nameMatcher.matches(child.name, names.get(0)) ? names.subList(1, names.size()) : names;
for (String schemaName : concat) { if (schema == rootSchema && nameMatcher.matches(schemaName, schema.name)) { remainingNames = Util.skip(remainingNames); continue;
/** * Given a table alias, find the corresponding {@link Table} associated with it * */ private Table findTable(String alias) { List<String> names = null; if (tableScope == null) { // no tables to find return null; } for (ScopeChild child : tableScope.children) { if (catalogReader.nameMatcher().matches(child.name, alias)) { names = ((SqlIdentifier) child.namespace.getNode()).names; break; } } if (names == null || names.size() == 0) { return null; } else if (names.size() == 1) { return findTable(catalogReader.getRootSchema(), names.get(0), catalogReader.nameMatcher().isCaseSensitive()); } CalciteSchema.TableEntry entry = SqlValidatorUtil.getTableEntry(catalogReader, names); return entry == null ? null : entry.getTable(); }
nameMatcher.matches(child.name, names.get(0)) ? names.subList(1, names.size()) : names;
/** * Given a table alias, find the corresponding {@link Table} associated with it * */ private Table findTable(String alias) { List<String> names = null; if (tableScope == null) { // no tables to find return null; } for (ScopeChild child : tableScope.children) { if (catalogReader.nameMatcher().matches(child.name, alias)) { names = ((SqlIdentifier) child.namespace.getNode()).names; break; } } if (names == null || names.size() == 0) { return null; } else if (names.size() == 1) { return findTable(catalogReader.getRootSchema(), names.get(0), catalogReader.nameMatcher().isCaseSensitive()); } CalciteSchema.TableEntry entry = SqlValidatorUtil.getTableEntry(catalogReader, names); return entry == null ? null : entry.getTable(); }
String lastName = Util.last(names); if (child.name != null) { if (!nameMatcher.matches(child.name, lastName)) {
/** * Finds a {@link org.apache.calcite.jdbc.CalciteSchema.TypeEntry} in a * given schema whose type has the given name, possibly qualified. * * @param rootSchema root schema * @param typeName name of the type, may be qualified or fully-qualified * * @return TypeEntry with a table with the given name, or null */ public static CalciteSchema.TypeEntry getTypeEntry( CalciteSchema rootSchema, SqlIdentifier typeName) { final String name; final List<String> path; if (typeName.isSimple()) { path = ImmutableList.of(); name = typeName.getSimple(); } else { path = Util.skipLast(typeName.names); name = Util.last(typeName.names); } CalciteSchema schema = rootSchema; for (String p : path) { if (schema == rootSchema && SqlNameMatchers.withCaseSensitive(true).matches(p, schema.getName())) { continue; } schema = schema.getSubSchema(p, true); } return schema == null ? null : schema.getType(name, false); }
String lastName = Util.last(names); if (child.name != null) { if (!nameMatcher.matches(child.name, lastName)) {
/** * Finds a {@link org.apache.calcite.jdbc.CalciteSchema.TypeEntry} in a * given schema whose type has the given name, possibly qualified. * * @param rootSchema root schema * @param typeName name of the type, may be qualified or fully-qualified * * @return TypeEntry with a table with the given name, or null */ public static CalciteSchema.TypeEntry getTypeEntry( CalciteSchema rootSchema, SqlIdentifier typeName) { final String name; final List<String> path; if (typeName.isSimple()) { path = ImmutableList.of(); name = typeName.getSimple(); } else { path = Util.skipLast(typeName.names); name = Util.last(typeName.names); } CalciteSchema schema = rootSchema; for (String p : path) { if (schema == rootSchema && SqlNameMatchers.withCaseSensitive(true).matches(p, schema.getName())) { continue; } schema = schema.getSubSchema(p, true); } return schema == null ? null : schema.getType(name, false); }
for (String schemaName : concat) { if (schema == rootSchema && nameMatcher.matches(schemaName, schema.name)) { remainingNames = Util.skip(remainingNames); continue;
for (SqlNode s : select.getSelectList()) { final String alias = SqlValidatorUtil.getAlias(s, -1); if (alias != null && nameMatcher.matches(alias, name)) { expr = s; n++;
for (SqlNode s : select.getSelectList()) { final String alias = SqlValidatorUtil.getAlias(s, -1); if (alias != null && nameMatcher.matches(alias, name)) { expr = s; n++;