use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.Table in project beam by apache.
the class TableResolutionTest method testMissingFlat.
/**
* Unit test for failing to resolve a table with no subschemas.
*/
@Test
public void testMissingFlat() {
String tableName = "fake_table";
when(mockSchemaPlus.getTable(tableName)).thenReturn(null);
Table table = TableResolution.resolveCalciteTable(mockSchemaPlus, ImmutableList.of(tableName));
assertThat(table, Matchers.nullValue());
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.Table in project beam by apache.
the class TableResolutionTest method testResolveNested.
/**
* Unit test for resolving a table with some hierarchy.
*/
@Test
public void testResolveNested() {
String subSchema = "fake_schema";
String tableName = "fake_table";
when(mockSchemaPlus.getSubSchema(subSchema)).thenReturn(innerSchemaPlus);
when(innerSchemaPlus.getTable(tableName)).thenReturn(mockTable);
Table table = TableResolution.resolveCalciteTable(mockSchemaPlus, ImmutableList.of(subSchema, tableName));
assertThat(table, Matchers.is(mockTable));
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.Table in project beam by apache.
the class SqlTransform method toTableMap.
@SuppressWarnings("unchecked")
private Map<String, BeamSqlTable> toTableMap(PInput inputs) {
/**
* A single PCollection is transformed to a table named PCOLLECTION, other input types are
* expanded and converted to tables using the tags as names.
*/
if (inputs instanceof PCollection) {
PCollection<?> pCollection = (PCollection<?>) inputs;
return ImmutableMap.of(PCOLLECTION_NAME, new BeamPCollectionTable(pCollection));
}
ImmutableMap.Builder<String, BeamSqlTable> tables = ImmutableMap.builder();
for (Map.Entry<TupleTag<?>, PValue> input : inputs.expand().entrySet()) {
PCollection<?> pCollection = (PCollection<?>) input.getValue();
tables.put(input.getKey().getId(), new BeamPCollectionTable(pCollection));
}
return tables.build();
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.Table in project beam by apache.
the class ZetaSqlJavaUdfTypeTest method setUp.
@Before
public void setUp() throws NoSuchMethodException {
initialize();
// Register test table.
JdbcConnection jdbcConnection = JdbcDriver.connect(new ReadOnlyTableProvider("table_provider", ImmutableMap.of("table", table)), PipelineOptionsFactory.create());
// Register UDFs.
SchemaPlus schema = jdbcConnection.getCurrentSchemaPlus();
schema.add("test_boolean", ScalarFunctionImpl.create(BooleanIdentityFn.class.getMethod("eval", Boolean.class)));
schema.add("test_int64", ScalarFunctionImpl.create(Int64IdentityFn.class.getMethod("eval", Long.class)));
schema.add("test_string", ScalarFunctionImpl.create(StringIdentityFn.class.getMethod("eval", String.class)));
schema.add("test_bytes", ScalarFunctionImpl.create(BytesIdentityFn.class.getMethod("eval", byte[].class)));
schema.add("test_float64", ScalarFunctionImpl.create(DoubleIdentityFn.class.getMethod("eval", Double.class)));
schema.add("test_date", ScalarFunctionImpl.create(DateIdentityFn.class.getMethod("eval", Date.class)));
schema.add("test_timestamp", ScalarFunctionImpl.create(TimestampIdentityFn.class.getMethod("eval", Timestamp.class)));
schema.add("test_array", ScalarFunctionImpl.create(ListIdentityFn.class.getMethod("eval", List.class)));
schema.add("test_numeric", ScalarFunctionImpl.create(BigDecimalIdentityFn.class.getMethod("eval", BigDecimal.class)));
this.config = Frameworks.newConfigBuilder(config).defaultSchema(schema).build();
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.Table in project beam by apache.
the class DataStoreReadWriteIT method testDataStoreV1SqlWriteRead_withoutKey.
@Test
public void testDataStoreV1SqlWriteRead_withoutKey() {
BeamSqlEnv sqlEnv = BeamSqlEnv.inMemory(new DataStoreV1TableProvider());
String projectId = options.getProject();
String createTableStatement = "CREATE EXTERNAL TABLE TEST( \n" + " `content` VARCHAR \n" + ") \n" + "TYPE 'datastoreV1' \n" + "LOCATION '" + projectId + "/" + KIND + "'";
sqlEnv.executeDdl(createTableStatement);
String insertStatement = "INSERT INTO TEST VALUES ( '3000' )";
BeamSqlRelUtils.toPCollection(writePipeline, sqlEnv.parseQuery(insertStatement));
writePipeline.run().waitUntilFinish();
String selectTableStatement = "SELECT * FROM TEST";
PCollection<Row> output = BeamSqlRelUtils.toPCollection(readPipeline, sqlEnv.parseQuery(selectTableStatement));
assertThat(output.getSchema(), equalTo(SOURCE_SCHEMA_WITHOUT_KEY));
PipelineResult.State state = readPipeline.run().waitUntilFinish(Duration.standardMinutes(5));
assertThat(state, equalTo(State.DONE));
}
Aggregations