Skip to content

Commit

Permalink
Merge pull request #78 from kitagry/support-time-partitioning
Browse files Browse the repository at this point in the history
Support _PARTITIONTIME column
  • Loading branch information
kitagry authored Oct 26, 2023
2 parents a453475 + c5ea0dd commit 9ff32f0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions langserver/internal/source/file/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ func (c *Catalog) addTable(path []string) error {
columns[i] = types.NewSimpleColumn(tableName, field.Name, typ)
}

if metadata.TimePartitioning != nil {
columns = append(columns, types.NewSimpleColumn(tableName, "_PARTITIONTIME", types.TimestampType()))
}

if isWildCardTable(path) {
columns = append(columns, types.NewSimpleColumn(tableName, "_TABLE_SUFFIX", types.StringType()))
}
Expand Down
20 changes: 20 additions & 0 deletions langserver/internal/source/file/catalog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,26 @@ func TestCatalog_AddTable(t *testing.T) {
expectTableName: "project.dataset.table*",
expectColumnNames: []string{"name", "_TABLE_SUFFIX"},
},
"partitiontime table": {
path: []string{"project.dataset.table"},
createMockBigQuery: func(ctrl *gomock.Controller) bigquery.Client {
bqClient := mock_bigquery.NewMockClient(ctrl)
bqClient.EXPECT().GetTableMetadata(gomock.Any(), "project", "dataset", "table").Return(&bq.TableMetadata{
Schema: bq.Schema{
{
Name: "name",
Type: bq.StringFieldType,
},
},
TimePartitioning: &bq.TimePartitioning{
Type: bq.DayPartitioningType,
},
}, nil)
return bqClient
},
expectTableName: "project.dataset.table",
expectColumnNames: []string{"name", "_PARTITIONTIME"},
},
}

for n, tt := range tests {
Expand Down

0 comments on commit 9ff32f0

Please sign in to comment.