use of org.apache.beam.sdk.extensions.sql.meta.provider.InvalidTableException in project beam by apache.
the class BigtableTableCreationFailuresTest method testShouldFailOnIncorrectLocation.
@Test
public void testShouldFailOnIncorrectLocation() {
String createTable = "CREATE EXTERNAL TABLE fail(key VARCHAR, q BIGINT) \n" + "TYPE bigtable \n" + "LOCATION 'googleapis.com/incorrect/projects/fakeProject/instances/fakeInstance/tables/beamTable' \n" + "TBLPROPERTIES '{\"columnsMapping\": \"f:q\"}'";
cli.execute(createTable);
Table table = metaStore.getTables().get("fail");
InvalidTableException e = assertThrows(InvalidTableException.class, () -> tableProvider.buildBeamSqlTable(table));
checkMessage(e.getMessage(), "Bigtable location must be in the following format:");
}
use of org.apache.beam.sdk.extensions.sql.meta.provider.InvalidTableException in project beam by apache.
the class TextTableProvider method buildBeamSqlTable.
@Override
public BeamSqlTable buildBeamSqlTable(Table table) {
Schema schema = table.getSchema();
String filePattern = table.getLocation();
JSONObject properties = table.getProperties();
String format = MoreObjects.firstNonNull(properties.getString("format"), "csv");
String deadLetterFile = properties.getString("deadLetterFile");
// Backwards compatibility: previously "type": "text" meant CSV and "format" was where the
// CSV format went. So assume that any other format is the CSV format.
@Nullable String legacyCsvFormat = null;
if (!ImmutableSet.of("csv", "lines", "json").contains(format)) {
legacyCsvFormat = format;
format = "csv";
}
switch(format) {
case "csv":
String specifiedCsvFormat = properties.getString("csvformat");
CSVFormat csvFormat = specifiedCsvFormat != null ? CSVFormat.valueOf(specifiedCsvFormat) : (legacyCsvFormat != null ? CSVFormat.valueOf(legacyCsvFormat) : CSVFormat.DEFAULT);
return new TextTable(schema, filePattern, new CsvToRow(schema, csvFormat), new RowToCsv(csvFormat));
case "json":
return new TextJsonTable(schema, filePattern, JsonToRow.create(schema, deadLetterFile), RowToJson.create());
case "lines":
if (!(schema.getFieldCount() == 1 && schema.getField(0).getType().getTypeName().equals(TypeName.STRING))) {
throw new InvalidTableException("Table with type 'text' and format 'lines' " + "must have exactly one STRING/VARCHAR/CHAR column ");
}
return new TextTable(schema, filePattern, new LinesReadConverter(), new LinesWriteConverter());
default:
throw new InvalidTableException("Table with type 'text' must have format 'csv' or 'lines' or 'json'");
}
}
Aggregations