Skip to content

Commit

Permalink
Merge pull request #104 from goccy/update-zetasqlite
Browse files Browse the repository at this point in the history
Update zetasqlite version to v0.11.1
  • Loading branch information
goccy authored Nov 30, 2022
2 parents 3056d38 + b7b5071 commit 8e7b094
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 3 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,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.0
github.com/goccy/go-zetasqlite v0.11.0
github.com/goccy/go-zetasqlite v0.11.1
github.com/google/go-cmp v0.5.9
github.com/googleapis/gax-go/v2 v2.7.0
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 @@ -487,8 +487,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.0 h1:vtHzqxC3awpTsScmFR/4slZQdDS92N/KIOjm4zVVQFA=
github.com/goccy/go-zetasql v0.5.0/go.mod h1:6W14CJVKh7crrSPyj6NPk4c49L2NWnxvyDLsRkOm4BI=
github.com/goccy/go-zetasqlite v0.11.0 h1:zBINgiIUic8AHpFnjcjKkVJTy3CE1QayGK0WH8LfMkg=
github.com/goccy/go-zetasqlite v0.11.0/go.mod h1:PQYsc0OQg6PwMyZMaaMYpWbDhnLCtt/2LoikiuIp98A=
github.com/goccy/go-zetasqlite v0.11.1 h1:kR2BThN3PID4aod5+31N6UJn27uKF/GfPvGUKlcr+0w=
github.com/goccy/go-zetasqlite v0.11.1/go.mod h1:PQYsc0OQg6PwMyZMaaMYpWbDhnLCtt/2LoikiuIp98A=
github.com/gofrs/uuid v4.3.1+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
Expand Down
103 changes: 103 additions & 0 deletions server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1345,3 +1345,106 @@ func TestLoadJSON(t *testing.T) {
t.Errorf("(-want +got):\n%s", diff)
}
}

func TestQueryWithNamedParams(t *testing.T) {
const (
projectID = "test"
datasetID = "test_dataset"
tableID = "test_table"
)

ctx := context.Background()

bqServer, err := server.New(server.TempStorage)
if err != nil {
t.Fatal(err)
}
project := types.NewProject(
projectID,
types.NewDataset(
datasetID,
types.NewTable(
tableID,
[]*types.Column{
types.NewColumn("created_at", types.TIMESTAMP),
types.NewColumn("item", types.STRING),
types.NewColumn("qty", types.NUMERIC),
},
types.Data{
{
"created_at": time.Now(),
"item": "something",
"qty": "123.45",
},
},
),
),
)
if err := bqServer.Load(server.StructSource(project)); err != nil {
t.Fatal(err)
}

testServer := bqServer.TestServer()
defer func() {
testServer.Close()
bqServer.Close()
}()

client, err := bigquery.NewClient(
ctx,
projectID,
option.WithEndpoint(testServer.URL),
option.WithoutAuthentication(),
)
if err != nil {
t.Fatal(err)
}
defer client.Close()
query := client.Query(`
SELECT
item, qty
FROM test_dataset.test_table
WHERE
created_at > @someday AND
qty >= @min_qty AND
created_at > @someday - INTERVAL 1 DAY
ORDER BY qty DESC;`)
query.Parameters = []bigquery.QueryParameter{
{
Name: "someday",
Value: time.Date(2022, 9, 9, 0, 0, 0, 0, time.UTC),
},
{
Name: "min_qty",
Value: 100,
},
}

job, err := query.Run(ctx)
if err != nil {
t.Fatal(err)
}
status, err := job.Wait(ctx)
if err != nil {
t.Fatal(err)
}
if err := status.Err(); err != nil {
t.Fatal(err)
}
it, err := job.Read(ctx)
if err != nil {
t.Fatal(err)
}
for {
var row []bigquery.Value
if err := it.Next(&row); err != nil {
if err == iterator.Done {
break
}
if err != nil {
t.Fatal(err)
}
}
fmt.Println(row)
}
}

0 comments on commit 8e7b094

Please sign in to comment.