diff --git a/go.mod b/go.mod index 28a6cae7a..a187a31f6 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/goccy/go-json v0.10.0 github.com/goccy/go-yaml v1.9.5 github.com/goccy/go-zetasql v0.5.1 - github.com/goccy/go-zetasqlite v0.17.0 + github.com/goccy/go-zetasqlite v0.17.1 github.com/google/go-cmp v0.5.9 github.com/googleapis/gax-go/v2 v2.7.1 github.com/gorilla/mux v1.8.0 diff --git a/go.sum b/go.sum index aa4a2b2bc..0b8e93dae 100644 --- a/go.sum +++ b/go.sum @@ -79,8 +79,8 @@ github.com/goccy/go-yaml v1.9.5 h1:Eh/+3uk9kLxG4koCX6lRMAPS1OaMSAi+FJcya0INdB0= github.com/goccy/go-yaml v1.9.5/go.mod h1:U/jl18uSupI5rdI2jmuCswEA2htH9eXfferR3KfscvA= github.com/goccy/go-zetasql v0.5.1 h1:vP9wgUH5gylw8yL+gwO0wF7uW/fW5Dr1AAAzi8Kgevg= github.com/goccy/go-zetasql v0.5.1/go.mod h1:6W14CJVKh7crrSPyj6NPk4c49L2NWnxvyDLsRkOm4BI= -github.com/goccy/go-zetasqlite v0.17.0 h1:bz+YQHl5a35gMPlPdMiiTstjNHHPR8A5uQvAaD84W/g= -github.com/goccy/go-zetasqlite v0.17.0/go.mod h1:ikLN7nRFum4sXL6kDxgIWrhH/9iZSdwXWXZzMUnuTjM= +github.com/goccy/go-zetasqlite v0.17.1 h1:1G9fkZF4PJJYn3DMVeY6NaLtNRcfbmDyIZuAUOVZTYw= +github.com/goccy/go-zetasqlite v0.17.1/go.mod h1:ikLN7nRFum4sXL6kDxgIWrhH/9iZSdwXWXZzMUnuTjM= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= diff --git a/server/server_test.go b/server/server_test.go index 28f051705..7d518bf49 100644 --- a/server/server_test.go +++ b/server/server_test.go @@ -2209,3 +2209,112 @@ func TestMultipleProject(t *testing.T) { t.Fatalf("failed to get data from sub project: %s", name) } } + +func TestInformationSchema(t *testing.T) { + const ( + projectID = "test" + datasetID = "test_dataset" + subProjectID = "sub" + ) + + ctx := context.Background() + + bqServer, err := server.New(server.TempStorage) + if err != nil { + t.Fatal(err) + } + if err := bqServer.Load( + server.StructSource( + types.NewProject( + projectID, + types.NewDataset( + datasetID, + types.NewTable( + "INFORMATION_SCHEMA.COLUMNS", + []*types.Column{ + types.NewColumn("table_schema", types.STRING), + types.NewColumn("table_name", types.STRING), + types.NewColumn("column_name", types.STRING), + }, + types.Data{ + { + "table_schema": "test_ds", + "table_name": "table_type_graph", + "column_name": "id", + }, + }, + ), + ), + ), + types.NewProject(subProjectID), + ), + ); err != nil { + t.Fatal(err) + } + testServer := bqServer.TestServer() + defer func() { + testServer.Close() + bqServer.Stop(ctx) + }() + + t.Run("query from same project", func(t *testing.T) { + client, err := bigquery.NewClient( + ctx, + projectID, + option.WithEndpoint(testServer.URL), + option.WithoutAuthentication(), + ) + if err != nil { + t.Fatal(err) + } + defer client.Close() + + it, err := client.Query("SELECT * FROM test_dataset.INFORMATION_SCHEMA.COLUMNS").Read(ctx) + if err != nil { + t.Fatal(err) + } + for { + var row []bigquery.Value + if err := it.Next(&row); err != nil { + if err != iterator.Done { + t.Fatal(err) + } + break + } + if len(row) != 3 { + t.Fatalf("failed to get row: %v", row) + } + } + }) + + t.Run("query from sub project", func(t *testing.T) { + client, err := bigquery.NewClient( + ctx, + subProjectID, + option.WithEndpoint(testServer.URL), + option.WithoutAuthentication(), + ) + if err != nil { + t.Fatal(err) + } + defer client.Close() + + it, err := client.Query("SELECT * FROM test.test_dataset.INFORMATION_SCHEMA.COLUMNS").Read(ctx) + if err != nil { + t.Fatal(err) + } + for { + var row []bigquery.Value + if err := it.Next(&row); err != nil { + if err != iterator.Done { + t.Fatal(err) + } + break + } + if len(row) != 3 { + t.Fatalf("failed to get row: %v", row) + } + } + }) + +}