use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.SchemaPlus in project calcite by apache.
the class LookupOperatorOverloadsTest method test.
@Test
public void test() throws SQLException {
final String schemaName = "MySchema";
final String funcName = "MyFUNC";
final String anotherName = "AnotherFunc";
try (Connection connection = DriverManager.getConnection("jdbc:calcite:")) {
CalciteConnection calciteConnection = connection.unwrap(CalciteConnection.class);
SchemaPlus rootSchema = calciteConnection.getRootSchema();
SchemaPlus schema = rootSchema.add(schemaName, new AbstractSchema());
final TableFunction table = TableFunctionImpl.create(Smalls.MAZE_METHOD);
schema.add(funcName, table);
schema.add(anotherName, table);
final TableFunction table2 = TableFunctionImpl.create(Smalls.MAZE3_METHOD);
schema.add(funcName, table2);
final CalciteServerStatement statement = connection.createStatement().unwrap(CalciteServerStatement.class);
final CalcitePrepare.Context prepareContext = statement.createPrepareContext();
final JavaTypeFactory typeFactory = prepareContext.getTypeFactory();
CalciteCatalogReader reader = new CalciteCatalogReader(prepareContext.getRootSchema(), ImmutableList.<String>of(), typeFactory, prepareContext.config());
final List<SqlOperator> operatorList = new ArrayList<>();
SqlIdentifier myFuncIdentifier = new SqlIdentifier(Lists.newArrayList(schemaName, funcName), null, SqlParserPos.ZERO, null);
reader.lookupOperatorOverloads(myFuncIdentifier, SqlFunctionCategory.USER_DEFINED_TABLE_FUNCTION, SqlSyntax.FUNCTION, operatorList);
checkFunctionType(2, funcName, operatorList);
operatorList.clear();
reader.lookupOperatorOverloads(myFuncIdentifier, SqlFunctionCategory.USER_DEFINED_FUNCTION, SqlSyntax.FUNCTION, operatorList);
checkFunctionType(0, null, operatorList);
operatorList.clear();
SqlIdentifier anotherFuncIdentifier = new SqlIdentifier(Lists.newArrayList(schemaName, anotherName), null, SqlParserPos.ZERO, null);
reader.lookupOperatorOverloads(anotherFuncIdentifier, SqlFunctionCategory.USER_DEFINED_TABLE_FUNCTION, SqlSyntax.FUNCTION, operatorList);
checkFunctionType(1, anotherName, operatorList);
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.SchemaPlus in project calcite by apache.
the class RelToSqlConverterTest method getPlanner.
private static Planner getPlanner(List<RelTraitDef> traitDefs, SqlParser.Config parserConfig, CalciteAssert.SchemaSpec schemaSpec, SqlToRelConverter.Config sqlToRelConf, Program... programs) {
final SchemaPlus rootSchema = Frameworks.createRootSchema(true);
final FrameworkConfig config = Frameworks.newConfigBuilder().parserConfig(parserConfig).defaultSchema(CalciteAssert.addSchema(rootSchema, schemaSpec)).traitDefs(traitDefs).sqlToRelConverterConfig(sqlToRelConf).programs(programs).build();
return Frameworks.getPlanner(config);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.SchemaPlus in project calcite by apache.
the class JdbcExample method run.
public void run() throws ClassNotFoundException, SQLException {
Class.forName("org.apache.calcite.jdbc.Driver");
Connection connection = DriverManager.getConnection("jdbc:calcite:");
CalciteConnection calciteConnection = connection.unwrap(CalciteConnection.class);
SchemaPlus rootSchema = calciteConnection.getRootSchema();
rootSchema.add("hr", new ReflectiveSchema(new Hr()));
rootSchema.add("foodmart", new ReflectiveSchema(new Foodmart()));
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery("select *\n" + "from \"foodmart\".\"sales_fact_1997\" as s\n" + "join \"hr\".\"emps\" as e\n" + "on e.\"empid\" = s.\"cust_id\"");
final StringBuilder buf = new StringBuilder();
while (resultSet.next()) {
int n = resultSet.getMetaData().getColumnCount();
for (int i = 1; i <= n; i++) {
buf.append(i > 1 ? "; " : "").append(resultSet.getMetaData().getColumnLabel(i)).append("=").append(resultSet.getObject(i));
}
System.out.println(buf.toString());
buf.setLength(0);
}
resultSet.close();
statement.close();
connection.close();
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.SchemaPlus in project calcite by apache.
the class ExampleFunctionTest method checkMazeTableFunction.
public void checkMazeTableFunction(Boolean solution, String maze) throws SQLException, ClassNotFoundException {
Connection connection = DriverManager.getConnection("jdbc:calcite:");
CalciteConnection calciteConnection = connection.unwrap(CalciteConnection.class);
SchemaPlus rootSchema = calciteConnection.getRootSchema();
SchemaPlus schema = rootSchema.add("s", new AbstractSchema());
final TableFunction table = TableFunctionImpl.create(MAZE_METHOD);
schema.add("Maze", table);
final TableFunction table2 = TableFunctionImpl.create(SOLVE_METHOD);
schema.add("Solve", table2);
final String sql;
if (solution) {
sql = "select *\n" + "from table(\"s\".\"Solve\"(5, 3, 1)) as t(s)";
} else {
sql = "select *\n" + "from table(\"s\".\"Maze\"(5, 3, 1)) as t(s)";
}
ResultSet resultSet = connection.createStatement().executeQuery(sql);
final StringBuilder b = new StringBuilder();
while (resultSet.next()) {
b.append(resultSet.getString(1)).append("\n");
}
assertThat(b.toString(), is(maze));
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.SchemaPlus in project drill by axbaretto.
the class HBaseSchemaFactory method registerSchemas.
@Override
public void registerSchemas(SchemaConfig schemaConfig, SchemaPlus parent) throws IOException {
HBaseSchema schema = new HBaseSchema(schemaName);
SchemaPlus hPlus = parent.add(schemaName, schema);
schema.setHolder(hPlus);
}
Aggregations