Skip to content

Commit

Permalink
Merge pull request #202 from goccy/care-information-schema
Browse files Browse the repository at this point in the history
Care INFORMATION_SCHEMA View
  • Loading branch information
goccy authored Jun 20, 2023
2 parents 9ffd5ea + fed4f15 commit 17941a5
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 3 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
109 changes: 109 additions & 0 deletions server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
})

}

0 comments on commit 17941a5

Please sign in to comment.