Skip to content
This repository has been archived by the owner on Jun 12, 2019. It is now read-only.

Add support for standard SQL queries #51

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/big_query/client/query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module Query
# @option options [Boolean] dryRun Don't actually run this job
# @option options [Integer] maxResults The maximum number of rows of data to return per page of results.
# @option options [Boolean] useQueryCache Whether to look for the result in the query cache.
# @option options [Boolean] useLegacySql Whether to use BigQuery's legacy SQL dialect for this query.
# @return [Hash] json api response
# @see https://cloud.google.com/bigquery/docs/reference/v2/jobs/query
def query(given_query, options={})
Expand All @@ -19,6 +20,7 @@ def query(given_query, options={})
query_request.max_results = options[:maxResults] if options[:maxResults]
query_request.dry_run = options[:dryRun] if options.has_key?(:dryRun)
query_request.use_query_cache = options[:useQueryCache] if options.has_key?(:useQueryCache)
query_request.use_legacy_sql = options[:useLegacySql] if options.has_key?(:useLegacySql)

api(
@client.query_job(
Expand Down
7 changes: 7 additions & 0 deletions test/bigquery.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,13 @@ def test_for_query_dryRun
assert_equal result['jobReference']['jobId'], nil
end

def test_for_query_useLegacySql
result = @bq.query("SELECT * FROM `#{config['dataset']}.test` LIMIT 1", useLegacySql: false)

assert_equal result['kind'], "bigquery#queryResponse"
assert_equal result['jobComplete'], true
end

def test_for_insert
result = @bq.insert('test' ,"id" => 123, "type" => "Task")

Expand Down