Skip to content

fix: Add labels to converter for listTables method (#3735) #3736

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 1 commit into from
Mar 25, 2025
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 @@ -457,7 +457,8 @@ public Table apply(TableList.Tables tablePb) {
.setCreationTime(tablePb.getCreationTime())
.setTimePartitioning(tablePb.getTimePartitioning())
.setRangePartitioning(tablePb.getRangePartitioning())
.setClustering(tablePb.getClustering());
.setClustering(tablePb.getClustering())
.setLabels(tablePb.getLabels());
}
}));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ public class BigQueryImplTest {
.setField("timestampField");
private static final TimePartitioning TIME_PARTITIONING_NULL_TYPE =
TimePartitioning.fromPb(PB_TIMEPARTITIONING);
private static final ImmutableMap<String, String> LABELS = ImmutableMap.of("key", "value");
private static final StandardTableDefinition TABLE_DEFINITION_WITH_PARTITIONING =
StandardTableDefinition.newBuilder()
.setSchema(TABLE_SCHEMA)
Expand All @@ -155,6 +156,8 @@ public class BigQueryImplTest {
TableInfo.of(TABLE_ID, TABLE_DEFINITION_WITH_RANGE_PARTITIONING);
private static final TableInfo TABLE_INFO = TableInfo.of(TABLE_ID, TABLE_DEFINITION);
private static final TableInfo OTHER_TABLE_INFO = TableInfo.of(OTHER_TABLE_ID, TABLE_DEFINITION);
private static final TableInfo OTHER_TABLE_WITH_LABELS_INFO =
TableInfo.newBuilder(OTHER_TABLE_ID, TABLE_DEFINITION).setLabels(LABELS).build();
private static final TableInfo TABLE_INFO_WITH_PROJECT =
TableInfo.of(TABLE_ID_WITH_PROJECT, TABLE_DEFINITION);
private static final TableInfo MODEL_TABLE_INFO_WITH_PROJECT =
Expand Down Expand Up @@ -1151,6 +1154,23 @@ public void testListTablesFromDatasetIdWithProject() throws IOException {
.listTablesSkipExceptionTranslation(OTHER_PROJECT, DATASET, EMPTY_RPC_OPTIONS);
}

@Test
public void testListTablesWithLabels() throws IOException {
bigquery = options.getService();
ImmutableList<Table> tableList =
ImmutableList.of(
new Table(bigquery, new TableInfo.BuilderImpl(OTHER_TABLE_WITH_LABELS_INFO)));
Tuple<String, Iterable<com.google.api.services.bigquery.model.Table>> result =
Tuple.of(CURSOR, Iterables.transform(tableList, TableInfo.TO_PB_FUNCTION));
when(bigqueryRpcMock.listTablesSkipExceptionTranslation(PROJECT, DATASET, EMPTY_RPC_OPTIONS))
.thenReturn(result);
Page<Table> page = bigquery.listTables(DATASET);
assertEquals(CURSOR, page.getNextPageToken());
assertArrayEquals(tableList.toArray(), Iterables.toArray(page.getValues(), Table.class));
verify(bigqueryRpcMock).listTablesSkipExceptionTranslation(PROJECT, DATASET, EMPTY_RPC_OPTIONS);
assertEquals(LABELS, page.getValues().iterator().next().getLabels());
}

@Test
public void testListTablesWithOptions() throws IOException {
bigquery = options.getService();
Expand Down