in zetasql-toolkit-bigquery/src/main/java/com/google/zetasql/toolkit/catalog/bigquery/BigQueryAPIResourceProvider.java [200:238]
private List<SimpleColumn> extractColumnsFromBigQueryTable(Table table) {
TableId tableId = table.getTableId();
if (table.getDefinition().getSchema() == null) {
// BigQuery tables can have no columns, in which case the schema is null
// One such table is
// bigquery-public-data.america_health_rankings.america_health_rankings
return ImmutableList.of();
}
ArrayList<SimpleColumn> columns =
table.getDefinition().getSchema().getFields().stream()
.map(
field ->
new SimpleColumn(
tableId.getTable(),
field.getName(),
this.extractTypeFromBigQueryTableField(field)))
.collect(Collectors.toCollection(ArrayList::new));
if (this.tableHasTimePartitioningPseudoColumns(table)) {
columns.addAll(
ImmutableList.of(
new SimpleColumn(
tableId.getTable(),
"_PARTITIONTIME",
TypeFactory.createSimpleType(TypeKind.TYPE_TIMESTAMP),
/* isPseudoColumn= */ true,
/* isWriteableColumn= */ false),
new SimpleColumn(
tableId.getTable(),
"_PARTITIONDATE",
TypeFactory.createSimpleType(TypeKind.TYPE_DATE),
/* isPseudoColumn= */ true,
/* isWriteableColumn= */ false)));
}
return columns;
}