use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.jdbc.CalciteSchema in project calcite by apache.
the class CalciteCatalogReader method getFunctionsFrom.
private Collection<Function> getFunctionsFrom(List<String> names) {
final List<Function> functions2 = Lists.newArrayList();
final List<List<String>> schemaNameList = new ArrayList<>();
if (names.size() > 1) {
// the last 2 items in the path.
if (schemaPaths.size() > 1) {
schemaNameList.addAll(Util.skip(schemaPaths));
} else {
schemaNameList.addAll(schemaPaths);
}
} else {
for (List<String> schemaPath : schemaPaths) {
CalciteSchema schema = SqlValidatorUtil.getSchema(rootSchema, schemaPath, nameMatcher);
if (schema != null) {
schemaNameList.addAll(schema.getPath());
}
}
}
for (List<String> schemaNames : schemaNameList) {
CalciteSchema schema = SqlValidatorUtil.getSchema(rootSchema, Iterables.concat(schemaNames, Util.skipLast(names)), nameMatcher);
if (schema != null) {
final String name = Util.last(names);
functions2.addAll(schema.getFunctions(name, true));
}
}
return functions2;
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.jdbc.CalciteSchema in project calcite by apache.
the class SqlValidatorUtil method getTableEntry.
/**
* Finds a {@link org.apache.calcite.jdbc.CalciteSchema.TableEntry} in a
* given catalog reader whose table has the given name, possibly qualified.
*
* <p>Uses the case-sensitivity policy of the specified catalog reader.
*
* <p>If not found, returns null.
*
* @param catalogReader accessor to the table metadata
* @param names Name of table, may be qualified or fully-qualified
*
* @return TableEntry with a table with the given name, or null
*/
public static CalciteSchema.TableEntry getTableEntry(SqlValidatorCatalogReader catalogReader, List<String> names) {
// If not found, look in the root schema.
for (List<String> schemaPath : catalogReader.getSchemaPaths()) {
CalciteSchema schema = getSchema(catalogReader.getRootSchema(), Iterables.concat(schemaPath, Util.skipLast(names)), catalogReader.nameMatcher());
if (schema == null) {
continue;
}
CalciteSchema.TableEntry entry = getTableEntryFrom(schema, Util.last(names), catalogReader.nameMatcher().isCaseSensitive());
if (entry != null) {
return entry;
}
}
return null;
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.jdbc.CalciteSchema in project drill by apache.
the class DrillValidator method replaceAliasWithActualName.
private void replaceAliasWithActualName(SqlIdentifier tempNode) {
CalciteSchema schema = getCatalogReader().getRootSchema();
if (schema instanceof DynamicRootSchema) {
DynamicRootSchema rootSchema = (DynamicRootSchema) schema;
String alias = SchemaPath.getCompoundPath(tempNode.names.toArray(new String[0])).toExpr();
SchemaPath actualPath = rootSchema.resolveTableAlias(alias);
if (actualPath != null) {
List<String> names = new ArrayList<>();
PathSegment pathSegment = actualPath.getRootSegment();
while (pathSegment != null) {
names.add(pathSegment.getNameSegment().getPath());
pathSegment = pathSegment.getChild();
}
changeNames(tempNode, names);
}
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.jdbc.CalciteSchema in project beam by apache.
the class JdbcFactory method newConnection.
@Override
public AvaticaConnection newConnection(UnregisteredDriver driver, AvaticaFactory avaticaFactory, String url, Properties info, @Nullable CalciteSchema rootSchema, @Nullable JavaTypeFactory typeFactory) {
Properties connectionProps = ensureDefaultProperties(info);
CalciteSchema actualRootSchema = rootSchema;
if (rootSchema == null) {
actualRootSchema = CalciteSchema.createRootSchema(true, false, "");
}
return super.newConnection(driver, avaticaFactory, url, connectionProps, actualRootSchema, typeFactory);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.jdbc.CalciteSchema in project beam by apache.
the class BeamZetaSqlCatalogTest method loadsUserDefinedFunctionsFromSchema.
@Test
public void loadsUserDefinedFunctionsFromSchema() throws NoSuchMethodException {
JdbcConnection jdbcConnection = createJdbcConnection();
SchemaPlus calciteSchema = jdbcConnection.getCurrentSchemaPlus();
Method method = IncrementFn.class.getMethod("eval", Long.class);
calciteSchema.add("increment", ScalarFunctionImpl.create(method));
BeamZetaSqlCatalog beamCatalog = BeamZetaSqlCatalog.create(calciteSchema, jdbcConnection.getTypeFactory(), SqlAnalyzer.baseAnalyzerOptions());
assertNotNull("ZetaSQL catalog contains function signature.", beamCatalog.getZetaSqlCatalog().getFunctionByFullName(USER_DEFINED_JAVA_SCALAR_FUNCTIONS + ":increment"));
assertEquals("Beam catalog contains function definition.", UserFunctionDefinitions.JavaScalarFunction.create(method, ""), beamCatalog.getUserFunctionDefinitions().javaScalarFunctions().get(ImmutableList.of("increment")));
}
Aggregations