use of org.apache.beam.sdk.extensions.sql.meta.provider.test.TestTableProvider in project beam by apache.
the class MongoDbFilterTest method buildUp.
@Before
public void buildUp() {
TestTableProvider tableProvider = new TestTableProvider();
Table table = getTable("TEST", PushDownOptions.NONE);
tableProvider.createTable(table);
tableProvider.addRows(table.getName(), row(BASIC_SCHEMA, 100, 1, "one", (short) 100, true), row(BASIC_SCHEMA, 200, 2, "two", (short) 200, false));
sqlEnv = BeamSqlEnv.builder(tableProvider).setPipelineOptions(PipelineOptionsFactory.create()).build();
}
use of org.apache.beam.sdk.extensions.sql.meta.provider.test.TestTableProvider in project beam by apache.
the class BeamSqlEnvTest method testPlannerClassNotFound.
@Test
public void testPlannerClassNotFound() {
exceptions.expect(RuntimeException.class);
exceptions.expectCause(hasMessage(containsString("org.test.ClassNotFound")));
TestTableProvider root = new TestTableProvider();
BeamSqlEnv.builder(root).setQueryPlannerClassName("org.test.ClassNotFound").setPipelineOptions(PipelineOptionsFactory.create()).build();
}
use of org.apache.beam.sdk.extensions.sql.meta.provider.test.TestTableProvider in project beam by apache.
the class BeamSqlEnvTest method testCreateExternalTableInNestedTableProvider.
@Test
public void testCreateExternalTableInNestedTableProvider() throws Exception {
TestTableProvider root = new TestTableProvider();
TestTableProvider nested = new TestTableProvider();
TestTableProvider anotherOne = new TestTableProvider();
BeamSqlEnv env = BeamSqlEnv.builder(root).addSchema("nested", nested).addSchema("anotherOne", anotherOne).setPipelineOptions(PipelineOptionsFactory.create()).build();
Connection connection = env.connection;
connection.createStatement().execute("CREATE EXTERNAL TABLE nested.person (id INT) TYPE test");
connection.createStatement().execute("INSERT INTO nested.person(id) VALUES (1), (2), (6)");
ResultSet rs = connection.createStatement().executeQuery("SELECT SUM(id) FROM nested.person");
rs.next();
assertEquals(9, rs.getInt(1));
}
use of org.apache.beam.sdk.extensions.sql.meta.provider.test.TestTableProvider 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.sdk.extensions.sql.meta.provider.test.TestTableProvider 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()));
}
Aggregations