Skip to content

Commit

Permalink
feat: Partial Projection of Table Metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
farhan0102 committed Jun 14, 2023
1 parent d178593 commit 0985520
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
Expand Up @@ -49,10 +49,10 @@ public static class Builder extends TableInfo.Builder {
private final BigQuery bigquery;
private final TableInfo.BuilderImpl infoBuilder;

Builder(BigQuery bigquery, TableId tableId, TableDefinition defintion) {
Builder(BigQuery bigquery, TableId tableId, TableDefinition definition) {
this.bigquery = bigquery;
this.infoBuilder = new TableInfo.BuilderImpl();
this.infoBuilder.setTableId(tableId).setDefinition(defintion);
this.infoBuilder.setTableId(tableId).setDefinition(definition);
}

Builder(Table table) {
Expand Down
Expand Up @@ -40,7 +40,7 @@
@InternalExtensionOnly
public interface BigQueryRpc extends ServiceRpc {

// These options are part of the Google Cloud BigQuery query parameters
// These options are part of the Google Cloud BigQuery query parameters.
enum Option {
FIELDS("fields"),
DELETE_CONTENTS("deleteContents"),
Expand All @@ -56,7 +56,8 @@ enum Option {
START_INDEX("startIndex"),
STATE_FILTER("stateFilter"),
TIMEOUT("timeoutMs"),
REQUESTED_POLICY_VERSION("requestedPolicyVersion");
REQUESTED_POLICY_VERSION("requestedPolicyVersion"),
TABLE_METADATA_VIEW("view");

private final String value;

Expand Down
Expand Up @@ -294,6 +294,7 @@ public Table getTable(
.get(projectId, datasetId, tableId)
.setPrettyPrint(false)
.setFields(Option.FIELDS.getString(options))
.setView("BASIC")
.execute();
} catch (IOException ex) {
BigQueryException serviceException = translate(ex);
Expand All @@ -304,6 +305,13 @@ public Table getTable(
}
}

private String getTableMetadataOption(Map<Option, ?> options) {
if (options.containsKey("view")) {
return options.get("view").toString();
}
return "STORAGE_STATS";
}

@Override
public Tuple<String, Iterable<Table>> listTables(
String projectId, String datasetId, Map<Option, ?> options) {
Expand Down
Expand Up @@ -1516,6 +1516,8 @@ public void testCreateAndGetTable() {
assertEquals(DATASET, createdTable.getTableId().getDataset());
assertEquals(tableName, createdTable.getTableId().getTable());
Table remoteTable = bigquery.getTable(DATASET, tableName);
System.out.println("Penguins");
System.out.println(remoteTable);
assertNotNull(remoteTable);
assertTrue(remoteTable.getDefinition() instanceof StandardTableDefinition);
assertEquals(createdTable.getTableId(), remoteTable.getTableId());
Expand Down

0 comments on commit 0985520

Please sign in to comment.