Skip to content

Commit

Permalink
Merge pull request #3116 from tseaver/3029-bigquery-systest-legacy_da…
Browse files Browse the repository at this point in the history
…tatypes

Add system tests for legacy data types.
  • Loading branch information
tseaver authored Mar 8, 2017
2 parents 10a624e + 12ab358 commit 8b39bb0
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion system_tests/bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,14 +479,54 @@ def _job_done(instance):
# raise an error, and that the job completed (in the `retry()`
# above).

def test_sync_query_w_legacy_sql_types(self):
import datetime
from google.cloud._helpers import UTC
naive = datetime.datetime(2016, 12, 5, 12, 41, 9)
stamp = '%s %s' % (naive.date().isoformat(), naive.time().isoformat())
zoned = naive.replace(tzinfo=UTC)
EXAMPLES = [
{
'sql': 'SELECT 1',
'expected': 1,
},
{
'sql': 'SELECT 1.3',
'expected': 1.3,
},
{
'sql': 'SELECT TRUE',
'expected': True,
},
{
'sql': 'SELECT "ABC"',
'expected': 'ABC',
},
{
'sql': 'SELECT CAST("foo" AS BYTES)',
'expected': b'foo',
},
{
'sql': 'SELECT CAST("%s" AS TIMESTAMP)' % (stamp,),
'expected': zoned,
},
]
for example in EXAMPLES:
query = Config.CLIENT.run_sync_query(example['sql'])
query.use_legacy_sql = True
query.run()
self.assertEqual(len(query.rows), 1)
self.assertEqual(len(query.rows[0]), 1)
self.assertEqual(query.rows[0][0], example['expected'])

def test_sync_query_w_standard_sql_types(self):
import datetime
from google.cloud._helpers import UTC
from google.cloud.bigquery._helpers import ArrayQueryParameter
from google.cloud.bigquery._helpers import ScalarQueryParameter
from google.cloud.bigquery._helpers import StructQueryParameter
naive = datetime.datetime(2016, 12, 5, 12, 41, 9)
stamp = "%s %s" % (naive.date().isoformat(), naive.time().isoformat())
stamp = '%s %s' % (naive.date().isoformat(), naive.time().isoformat())
zoned = naive.replace(tzinfo=UTC)
zoned_param = ScalarQueryParameter(
name='zoned', type_='TIMESTAMP', value=zoned)
Expand Down

0 comments on commit 8b39bb0

Please sign in to comment.