Skip to content
This repository was archived by the owner on Mar 23, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

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
Copy Markdown
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
Copy Markdown
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