Skip to content

feat: set Table.Schema for permanent external tables #1701

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,12 @@ public Table create(TableInfo tableInfo, TableOption... options) {
? getOptions().getProjectId()
: tableInfo.getTableId().getProject())
.toPb();
// Set schema on the Table for permanent external table
if (tablePb.getExternalDataConfiguration() != null) {
tablePb.setSchema(tablePb.getExternalDataConfiguration().getSchema());
// clear table schema on ExternalDataConfiguration
tablePb.getExternalDataConfiguration().setSchema(null);
}
final Map<BigQueryRpc.Option, ?> optionsMap = optionMap(options);
try {
return Table.fromPb(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1136,6 +1136,28 @@ public void testCreateExternalTable() throws InterruptedException {
assertTrue(remoteTable.delete());
}

@Test
public void testSetPermExternalTableSchema() {
String tableName = "test_create_external_table_perm";
TableId tableId = TableId.of(DATASET, tableName);
ExternalTableDefinition externalTableDefinition =
ExternalTableDefinition.newBuilder(
"gs://" + BUCKET + "/" + JSON_LOAD_FILE, FormatOptions.json())
.setSchema(TABLE_SCHEMA)
.setConnectionId(
"projects/java-docs-samples-testing/locations/us/connections/DEVREL_TEST_CONNECTION")
.build();
TableInfo tableInfo = TableInfo.of(tableId, externalTableDefinition);
Table createdTable = bigquery.create(tableInfo);

assertNotNull(createdTable);
assertEquals(DATASET, createdTable.getTableId().getDataset());
assertEquals(tableName, createdTable.getTableId().getTable());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like the significant change here is where schema is set, but you're not really probing that with this test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

without the code change the IT will fail.

Table remoteTable = bigquery.getTable(DATASET, tableName);
assertNotNull(remoteTable);
assertTrue(remoteTable.delete());
}

@Test
public void testCreateViewTable() throws InterruptedException {
String tableName = "test_create_view_table";
Expand Down