use of org.apache.beam.sdk.extensions.sql.meta.provider.test.TestTableProvider in project beam by apache.
the class BeamSqlCliTest method test_time_types.
@Test
public void test_time_types() throws Exception {
InMemoryMetaStore metaStore = new InMemoryMetaStore();
TestTableProvider testTableProvider = new TestTableProvider();
metaStore.registerProvider(testTableProvider);
BeamSqlCli cli = new BeamSqlCli().metaStore(metaStore);
cli.execute("CREATE EXTERNAL TABLE test_table (\n" + "f_date DATE, \n" + "f_time TIME, \n" + "f_ts TIMESTAMP" + ") \n" + "TYPE 'test'");
cli.execute("INSERT INTO test_table VALUES (" + "DATE '2018-11-01', " + "TIME '15:23:59', " + "TIMESTAMP '2018-07-01 21:26:07.123' )");
Table table = metaStore.getTables().get("test_table");
assertNotNull(table);
TestTableProvider.TableWithRows tableWithRows = testTableProvider.tables().get(table.getName());
assertEquals(1, tableWithRows.getRows().size());
Row row = tableWithRows.getRows().get(0);
assertEquals(3, row.getFieldCount());
// test DATE field
assertEquals("2018-11-01", row.getLogicalTypeValue("f_date", LocalDate.class).toString());
// test TIME field
assertEquals("15:23:59", row.getLogicalTypeValue("f_time", LocalTime.class).toString());
// test TIMESTAMP field
assertEquals(parseTimestampWithUTCTimeZone("2018-07-01 21:26:07.123"), row.getDateTime("f_ts"));
}
use of org.apache.beam.sdk.extensions.sql.meta.provider.test.TestTableProvider in project beam by apache.
the class JdbcDriverTest method testTimestampWithDefaultTimezone.
@Test
public void testTimestampWithDefaultTimezone() throws Exception {
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);
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.sdk.extensions.sql.meta.provider.test.TestTableProvider in project beam by apache.
the class JdbcDriverTest method testTimestampWithNonzeroTimezone.
@Test
@Ignore("https://issues.apache.org/jira/browse/CALCITE-2394")
public void testTimestampWithNonzeroTimezone() throws Exception {
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("Asia/Tokyo"), 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.sdk.extensions.sql.meta.provider.test.TestTableProvider in project beam by apache.
the class BeamDDLTest method testParseCreateExternalTable_full.
@Test
public void testParseCreateExternalTable_full() throws Exception {
TestTableProvider tableProvider = new TestTableProvider();
BeamSqlEnv env = BeamSqlEnv.withTableProvider(tableProvider);
JSONObject properties = new JSONObject();
JSONArray hello = new JSONArray();
hello.add("james");
hello.add("bond");
properties.put("hello", hello);
env.executeDdl("CREATE EXTERNAL TABLE person (\n" + "id int COMMENT 'id', \n" + "name varchar COMMENT 'name') \n" + "TYPE 'text' \n" + "COMMENT 'person table' \n" + "LOCATION '/home/admin/person'\n" + "TBLPROPERTIES '{\"hello\": [\"james\", \"bond\"]}'");
assertEquals(mockTable("person", "text", "person table", properties), tableProvider.getTables().get("person"));
}
use of org.apache.beam.sdk.extensions.sql.meta.provider.test.TestTableProvider in project beam by apache.
the class BeamDDLTest method testParseCreateExternalTable_withDatabase.
@Test
public void testParseCreateExternalTable_withDatabase() throws Exception {
TestTableProvider rootProvider = new TestTableProvider();
TestTableProvider testProvider = new TestTableProvider();
BeamSqlEnv env = BeamSqlEnv.builder(rootProvider).addSchema("test", testProvider).setPipelineOptions(PipelineOptionsFactory.create()).build();
assertNull(testProvider.getTables().get("person"));
env.executeDdl("CREATE EXTERNAL TABLE test.person (id INT) TYPE text");
assertNotNull(testProvider.getTables().get("person"));
}
Aggregations