Skip to content

Commit 8634822

Browse files
authored
fix: Add labels to converter for listTables method (#3735) (#3736)
1 parent b5bfaab commit 8634822

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

Diff for: google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/spi/v2/HttpBigQueryRpc.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,8 @@ public Table apply(TableList.Tables tablePb) {
457457
.setCreationTime(tablePb.getCreationTime())
458458
.setTimePartitioning(tablePb.getTimePartitioning())
459459
.setRangePartitioning(tablePb.getRangePartitioning())
460-
.setClustering(tablePb.getClustering());
460+
.setClustering(tablePb.getClustering())
461+
.setLabels(tablePb.getLabels());
461462
}
462463
}));
463464
}

Diff for: google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/BigQueryImplTest.java

+20
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ public class BigQueryImplTest {
132132
.setField("timestampField");
133133
private static final TimePartitioning TIME_PARTITIONING_NULL_TYPE =
134134
TimePartitioning.fromPb(PB_TIMEPARTITIONING);
135+
private static final ImmutableMap<String, String> LABELS = ImmutableMap.of("key", "value");
135136
private static final StandardTableDefinition TABLE_DEFINITION_WITH_PARTITIONING =
136137
StandardTableDefinition.newBuilder()
137138
.setSchema(TABLE_SCHEMA)
@@ -155,6 +156,8 @@ public class BigQueryImplTest {
155156
TableInfo.of(TABLE_ID, TABLE_DEFINITION_WITH_RANGE_PARTITIONING);
156157
private static final TableInfo TABLE_INFO = TableInfo.of(TABLE_ID, TABLE_DEFINITION);
157158
private static final TableInfo OTHER_TABLE_INFO = TableInfo.of(OTHER_TABLE_ID, TABLE_DEFINITION);
159+
private static final TableInfo OTHER_TABLE_WITH_LABELS_INFO =
160+
TableInfo.newBuilder(OTHER_TABLE_ID, TABLE_DEFINITION).setLabels(LABELS).build();
158161
private static final TableInfo TABLE_INFO_WITH_PROJECT =
159162
TableInfo.of(TABLE_ID_WITH_PROJECT, TABLE_DEFINITION);
160163
private static final TableInfo MODEL_TABLE_INFO_WITH_PROJECT =
@@ -1151,6 +1154,23 @@ public void testListTablesFromDatasetIdWithProject() throws IOException {
11511154
.listTablesSkipExceptionTranslation(OTHER_PROJECT, DATASET, EMPTY_RPC_OPTIONS);
11521155
}
11531156

1157+
@Test
1158+
public void testListTablesWithLabels() throws IOException {
1159+
bigquery = options.getService();
1160+
ImmutableList<Table> tableList =
1161+
ImmutableList.of(
1162+
new Table(bigquery, new TableInfo.BuilderImpl(OTHER_TABLE_WITH_LABELS_INFO)));
1163+
Tuple<String, Iterable<com.google.api.services.bigquery.model.Table>> result =
1164+
Tuple.of(CURSOR, Iterables.transform(tableList, TableInfo.TO_PB_FUNCTION));
1165+
when(bigqueryRpcMock.listTablesSkipExceptionTranslation(PROJECT, DATASET, EMPTY_RPC_OPTIONS))
1166+
.thenReturn(result);
1167+
Page<Table> page = bigquery.listTables(DATASET);
1168+
assertEquals(CURSOR, page.getNextPageToken());
1169+
assertArrayEquals(tableList.toArray(), Iterables.toArray(page.getValues(), Table.class));
1170+
verify(bigqueryRpcMock).listTablesSkipExceptionTranslation(PROJECT, DATASET, EMPTY_RPC_OPTIONS);
1171+
assertEquals(LABELS, page.getValues().iterator().next().getLabels());
1172+
}
1173+
11541174
@Test
11551175
public void testListTablesWithOptions() throws IOException {
11561176
bigquery = options.getService();

0 commit comments

Comments
 (0)