use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.Table in project beam by apache.
the class TableResolutionTest method testResolveWithDots.
/**
* Unit test for resolving a table with no hierarchy but dots in its actual name.
*/
@Test
public void testResolveWithDots() {
String tableName = "fake.table";
when(mockSchemaPlus.getTable(tableName)).thenReturn(mockTable);
Table table = TableResolution.resolveCalciteTable(mockSchemaPlus, ImmutableList.of(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 TableScanConverter method convert.
@Override
public RelNode convert(ResolvedTableScan zetaNode, List<RelNode> inputs) {
List<String> tablePath = getTablePath(zetaNode.getTable());
SchemaPlus defaultSchemaPlus = getConfig().getDefaultSchema();
if (defaultSchemaPlus == null) {
throw new AssertionError("Default schema is null.");
}
// TODO: reject incorrect top-level schema
Table calciteTable = TableResolution.resolveCalciteTable(defaultSchemaPlus, tablePath);
// we already resolved the table before passing the query to Analyzer, so it should be there
checkNotNull(calciteTable, "Unable to resolve the table path %s in schema %s", tablePath, defaultSchemaPlus.getName());
String defaultSchemaName = defaultSchemaPlus.getName();
final CalciteCatalogReader catalogReader = new CalciteCatalogReader(CalciteSchema.from(defaultSchemaPlus), ImmutableList.of(defaultSchemaName), getCluster().getTypeFactory(), new CalciteConnectionConfigImpl(new Properties()));
RelOptTableImpl relOptTable = RelOptTableImpl.create(catalogReader, calciteTable.getRowType(getCluster().getTypeFactory()), calciteTable, ImmutableList.<String>builder().add(defaultSchemaName).addAll(tablePath).build());
if (calciteTable instanceof TranslatableTable) {
return ((TranslatableTable) calciteTable).toRel(createToRelContext(), relOptTable);
} else {
throw new UnsupportedOperationException("Does not support non TranslatableTable type table!");
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.Table in project beam by apache.
the class JdbcDriverTest method testSelectsFromExistingTable.
@Test
public void testSelectsFromExistingTable() throws Exception {
TestTableProvider tableProvider = new TestTableProvider();
Connection connection = JdbcDriver.connect(tableProvider, PipelineOptionsFactory.create());
connection.createStatement().executeUpdate("CREATE EXTERNAL TABLE person (id BIGINT, name VARCHAR) TYPE 'test'");
tableProvider.addRows("person", row(1L, "aaa"), row(2L, "bbb"));
ResultSet selectResult = connection.createStatement().executeQuery("SELECT id, name FROM person");
List<Row> resultRows = readResultSet(selectResult).stream().map(values -> values.stream().collect(toRow(BASIC_SCHEMA))).collect(Collectors.toList());
assertThat(resultRows, containsInAnyOrder(row(1L, "aaa"), row(2L, "bbb")));
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.Table in project beam by apache.
the class JdbcDriverTest method testTimestampWithZeroTimezone.
@Test
public void testTimestampWithZeroTimezone() throws Exception {
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"), Locale.ROOT);
TestTableProvider tableProvider = new TestTableProvider();
Connection connection = JdbcDriver.connect(tableProvider, PipelineOptionsFactory.create());
// A table with one TIMESTAMP column
Schema schema = Schema.builder().addDateTimeField("ts").build();
connection.createStatement().executeUpdate("CREATE EXTERNAL TABLE test (ts TIMESTAMP) TYPE 'test'");
ReadableInstant july1 = ISODateTimeFormat.dateTimeParser().parseDateTime("2018-07-01T01:02:03Z");
tableProvider.addRows("test", Row.withSchema(schema).addValue(july1).build());
ResultSet selectResult = connection.createStatement().executeQuery(String.format("SELECT ts FROM test"));
selectResult.next();
Timestamp ts = selectResult.getTimestamp(1, cal);
assertThat(String.format("Wrote %s to a table, but got back %s", ISODateTimeFormat.basicDateTime().print(july1), ISODateTimeFormat.basicDateTime().print(ts.getTime())), ts.getTime(), equalTo(july1.getMillis()));
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.Table in project beam by apache.
the class JdbcDriverTest method testInsertIntoCreatedTable.
@Test
public void testInsertIntoCreatedTable() throws Exception {
TestTableProvider tableProvider = new TestTableProvider();
Connection connection = JdbcDriver.connect(tableProvider, PipelineOptionsFactory.create());
connection.createStatement().executeUpdate("CREATE EXTERNAL TABLE person (id BIGINT, name VARCHAR) TYPE 'test'");
connection.createStatement().executeUpdate("CREATE EXTERNAL TABLE person_src (id BIGINT, name VARCHAR) TYPE 'test'");
tableProvider.addRows("person_src", row(1L, "aaa"), row(2L, "bbb"));
connection.createStatement().execute("INSERT INTO person SELECT id, name FROM person_src");
ResultSet selectResult = connection.createStatement().executeQuery("SELECT id, name FROM person");
List<Row> resultRows = readResultSet(selectResult).stream().map(resultValues -> resultValues.stream().collect(toRow(BASIC_SCHEMA))).collect(Collectors.toList());
assertThat(resultRows, containsInAnyOrder(row(1L, "aaa"), row(2L, "bbb")));
}
Aggregations