BigQueryTableProvider extends InMemoryMetaTableProvider { @Override public BeamSqlTable buildBeamSqlTable(Table table) { return new BigQueryTable(table, getConversionOptions(table.getProperties())); }  @Override String getTableType(); @Override BeamSqlTable buildBeamSqlTable(Table table);  }
@Test public void testBuildBeamSqlTable() throws Exception { Table table = fakeTable("hello"); BeamSqlTable sqlTable = provider.buildBeamSqlTable(table); assertNotNull(sqlTable); assertTrue(sqlTable instanceof BigQueryTable); BigQueryTable bqTable = (BigQueryTable) sqlTable; assertEquals("project:dataset.table", bqTable.bqLocation); }
@Test public void testDefaultMethod_whenPropertiesAreNotSet() { Table table = fakeTable("hello"); BigQueryTable sqlTable = (BigQueryTable) provider.buildBeamSqlTable(table); assertEquals(Method.DIRECT_READ, sqlTable.method); }
@Test public void testSelectDefaultMethodExplicitly() { Table table = fakeTableWithProperties( "hello", "{ " + METHOD_PROPERTY + ": " + "\"" + Method.DEFAULT.toString() + "\" }"); BigQueryTable sqlTable = (BigQueryTable) provider.buildBeamSqlTable(table); assertEquals(Method.DEFAULT, sqlTable.method); }
@Test public void testSelectDirectReadMethod() { Table table = fakeTableWithProperties( "hello", "{ " + METHOD_PROPERTY + ": " + "\"" + Method.DIRECT_READ.toString() + "\" }"); BigQueryTable sqlTable = (BigQueryTable) provider.buildBeamSqlTable(table); assertEquals(Method.DIRECT_READ, sqlTable.method); }
@Test public void testSelectExportMethod() { Table table = fakeTableWithProperties( "hello", "{ " + METHOD_PROPERTY + ": " + "\"" + Method.EXPORT.toString() + "\" }"); BigQueryTable sqlTable = (BigQueryTable) provider.buildBeamSqlTable(table); assertEquals(Method.EXPORT, sqlTable.method); }
@Test public void testSelectWriteDispositionMethodTruncate() { Table table = fakeTableWithProperties( "hello", "{ " + WRITE_DISPOSITION_PROPERTY + ": " + "\"" + WriteDisposition.WRITE_TRUNCATE.toString() + "\" }"); BigQueryTable sqlTable = (BigQueryTable) provider.buildBeamSqlTable(table); assertEquals(WriteDisposition.WRITE_TRUNCATE, sqlTable.writeDisposition); }
@Test public void testSelectWriteDispositionMethodAppend() { Table table = fakeTableWithProperties( "hello", "{ " + WRITE_DISPOSITION_PROPERTY + ": " + "\"" + WriteDisposition.WRITE_APPEND.toString() + "\" }"); BigQueryTable sqlTable = (BigQueryTable) provider.buildBeamSqlTable(table); assertEquals(WriteDisposition.WRITE_APPEND, sqlTable.writeDisposition); }
@Test public void testSelectWriteDispositionMethodEmpty() { Table table = fakeTableWithProperties( "hello", "{ " + WRITE_DISPOSITION_PROPERTY + ": " + "\"" + WriteDisposition.WRITE_EMPTY.toString() + "\" }"); BigQueryTable sqlTable = (BigQueryTable) provider.buildBeamSqlTable(table); assertEquals(WriteDisposition.WRITE_EMPTY, sqlTable.writeDisposition); }
@Test public void testRuntimeExceptionThrown_whenAnInvalidPropertyIsSpecified() { Table table = fakeTableWithProperties("hello", "{ " + METHOD_PROPERTY + ": \"blahblah\" }"); assertThrows( RuntimeException.class, () -> { provider.buildBeamSqlTable(table); }); }
@Test public void testRuntimeExceptionThrown_whenAPropertyOfInvalidTypeIsSpecified() { Table table = fakeTableWithProperties("hello", "{ " + METHOD_PROPERTY + ": 1337 }"); assertThrows( RuntimeException.class, () -> { provider.buildBeamSqlTable(table); }); }
@Test public void testDefaultMethod_whenPropertiesAreNotSet() { Table table = fakeTable("hello"); BigQueryTable sqlTable = (BigQueryTable) provider.buildBeamSqlTable(table); assertEquals(Method.DEFAULT, sqlTable.method); }