public Schema create( SchemaPlus parentSchema, String name, Map<String, Object> operand) { SchemaPlus schema = parentSchema.add(name, JdbcSchema.create(parentSchema, name + "$source", operand)); return new CloneSchema(schema); } }
@Override protected Map<String, Table> getTableMap() { final Map<String, Table> map = new LinkedHashMap<String, Table>(); for (String name : sourceSchema.getTableNames()) { final QueryableTable sourceTable = (QueryableTable) sourceSchema.getTable(name); map.put(name, createCloneTable(MATERIALIZATION_CONNECTION, sourceTable, name)); } return map; }
private <T> Table<T> createCloneTable(Table<T> sourceTable, String name) { final TableInSchema tableInSchema = createCloneTable(this, name, sourceTable.getRowType(), sourceTable); addTable(tableInSchema); return tableInSchema.getTable(null); }
/** * Creates a CloneSchema within another schema. * * @param parentSchema Parent schema * @param name Name of new schema * @param sourceSchema Source schema * @return New CloneSchema */ public static CloneSchema create( MutableSchema parentSchema, String name, Schema sourceSchema) { CloneSchema schema = new CloneSchema( parentSchema, name, parentSchema.getSubSchemaExpression(name, Object.class), sourceSchema); parentSchema.addSchema(name, schema); return schema; }
@Override public <E> Table<E> getTable(String name, Class<E> elementType) { // TODO: check elementType matches table.elementType assert elementType != null; Table<E> table = super.getTable(name, elementType); if (table != null) { return table; } // TODO: make thread safe! Table<E> sourceTable = sourceSchema.getTable(name, elementType); if (sourceTable != null) { //noinspection unchecked return createCloneTable(sourceTable, name); } return null; }
@Test public void testCloneSchema() throws ClassNotFoundException, SQLException { final OptiqConnection connection = JdbcTest.getConnection(null, false); Schema foodmart = connection.getRootSchema().getSubSchema("foodmart"); CloneSchema.create(connection.getRootSchema(), "foodmart2", foodmart); Statement statement = connection.createStatement(); ResultSet resultSet = statement.executeQuery( "select count(*) from \"foodmart2\".\"time_by_day\""); assertTrue(resultSet.next()); assertEquals(730, resultSet.getInt(1)); resultSet.close(); connection.close(); }
@Test public void testCloneSchema() throws ClassNotFoundException, SQLException { final OptiqConnection connection = OptiqAssert.getConnection(false); final SchemaPlus rootSchema = connection.getRootSchema(); final SchemaPlus foodmart = rootSchema.getSubSchema("foodmart"); rootSchema.add("foodmart2", new CloneSchema(foodmart)); Statement statement = connection.createStatement(); ResultSet resultSet = statement.executeQuery( "select count(*) from \"foodmart2\".\"time_by_day\""); assertTrue(resultSet.next()); assertEquals(730, resultSet.getInt(1)); resultSet.close(); connection.close(); }
private Table createCloneTable(QueryProvider queryProvider, QueryableTable sourceTable, String name) { final Queryable<Object> queryable = sourceTable.asQueryable(queryProvider, sourceSchema, name); final JavaTypeFactory typeFactory = ((OptiqConnection) queryProvider).getTypeFactory(); return createCloneTable(typeFactory, Schemas.proto(sourceTable), null, queryable); }
"foodmart"); if (withClone) { CloneSchema.create( optiqConnection.getRootSchema(), "foodmart2", foodmart);
foodmart = OptiqAssert.addSchema(rootSchema, SchemaSpec.JDBC_FOODMART); return rootSchema.add("foodmart2", new CloneSchema(foodmart)); case HR: return rootSchema.add("hr",
Schemas.prepare(schema, viewSchemaPath, viewSql); materializedTable = CloneSchema.createCloneTable((MutableSchema) schema, tableName, prepareResult.rowType, new AbstractQueryable<Object>() {
final JavaTypeFactory typeFactory = connection.getTypeFactory(); materializedTable = CloneSchema.createCloneTable(typeFactory, RelDataTypeImpl.proto(prepareResult.rowType), Functions.adapt(prepareResult.structType.columns,