Skip to content

Commit

Permalink
BigQuery uses [ identity escape syntax refs
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Raddon committed Aug 19, 2017
1 parent 84c2b98 commit d712ccd
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion backends/bigquery/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Google BigQuery Data source
--------------------------------------

Provides MySQL acess to [Google BigQuery](https://cloud.google.com/bigquery/)
which opens up the usage of bigquery for bi tools that don't have native
which opens up the usage of bigquery via standard sql allowing tools that don't have native
bigquery clients.


Expand Down
12 changes: 12 additions & 0 deletions backends/bigquery/bq_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,18 @@ func TestSelectLimit(t *testing.T) {
})
}

func TestSelectEscapeSyntax(t *testing.T) {
data := struct {
Name string
}{}
validateQuerySpec(t, tu.QuerySpec{
Sql: "select `name` from `bikeshare_stations` LIMIT 1;",
ExpectRowCt: 1,
ValidateRowData: func() {},
RowData: &data,
})
}

func TestSelectGroupBy(t *testing.T) {
data := struct {
Landmark string
Expand Down
6 changes: 5 additions & 1 deletion backends/bigquery/resultreader.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"github.com/araddon/qlbridge/datasource"
"github.com/araddon/qlbridge/exec"
"github.com/araddon/qlbridge/expr"
"github.com/araddon/qlbridge/rel"
"github.com/araddon/qlbridge/value"
)
Expand Down Expand Up @@ -129,7 +130,10 @@ func (m *ResultReader) Run() error {
u.Warnf("Could not create bigquery client billing_project=%q err=%v", m.Req.s.billingProject, err)
return err
}
q := client.Query(sel.String())

bqWriter := expr.NewDialectWriter('"', '[')
sel.WriteDialect(bqWriter)
q := client.Query(bqWriter.String())

ctx := context.Background()
job, err := q.Run(ctx)
Expand Down
3 changes: 3 additions & 0 deletions backends/bigquery/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type Source struct {
billingProject string
dataProject string
dataset string
legacySyntax bool
tables []string // Lower cased
tablemap map[string]*schema.Table
conf *schema.ConfigSource
Expand Down Expand Up @@ -107,6 +108,8 @@ func (m *Source) Setup(ss *schema.SchemaSource) error {
return fmt.Errorf("No 'dataset' for bigquery found in config %v", m.conf.Settings)
}

m.legacySyntax = m.conf.Settings.Bool("legacy_syntax")

m.loadSchema()
return nil
}
Expand Down

0 comments on commit d712ccd

Please sign in to comment.