@@ -225,7 +225,7 @@ def test_order(self):
225
225
"""Ensure that render order can work under expected conditions."""
226
226
from bigquery .query_builder import _render_order
227
227
228
- result = _render_order ({'field ' : 'foo' , 'direction' : 'desc' })
228
+ result = _render_order ({'fields ' : [ 'foo' ] , 'direction' : 'desc' })
229
229
230
230
self .assertEqual (result , "ORDER BY foo desc" )
231
231
@@ -298,13 +298,13 @@ def test_full_query(self):
298
298
}
299
299
],
300
300
groupings = ['timestamp' , 'status' ],
301
- order_by = {'field ' : 'timestamp' , 'direction' : 'desc' })
301
+ order_by = {'fields ' : [ 'timestamp' ] , 'direction' : 'desc' })
302
302
303
303
expected_query = ("SELECT status as status, start_time as timestamp, "
304
304
"resource as url FROM [dataset.2013_06_appspot_1]"
305
305
" WHERE (start_time <= INTEGER('1371566954')) AND "
306
306
"(start_time >= INTEGER('1371556954')) GROUP BY "
307
- "timestamp, status ORDER BY timestamp desc" )
307
+ "timestamp, status ORDER BY timestamp desc" )
308
308
expected_select = (expected_query [len ('SELECT ' ):]
309
309
.split ('FROM' )[0 ].strip ().split (', ' ))
310
310
expected_from = expected_query [len ('SELECT ' ):].split ('FROM' )[1 ]
@@ -327,17 +327,18 @@ def test_empty_conditions(self):
327
327
'resource' : {'alias' : 'url' }
328
328
},
329
329
conditions = [],
330
- order_by = {'field ' : 'timestamp' , 'direction' : 'desc' })
330
+ order_by = {'fields ' : [ 'timestamp' ] , 'direction' : 'desc' })
331
331
332
332
expected_query = ("SELECT status as status, start_time as timestamp, "
333
333
"resource as url FROM "
334
- "[dataset.2013_06_appspot_1] ORDER BY "
334
+ "[dataset.2013_06_appspot_1] ORDER BY "
335
335
"timestamp desc" )
336
336
expected_select = (expected_query [len ('SELECT ' ):]
337
337
.split ('FROM' )[0 ].strip ().split (', ' ))
338
338
expected_from = expected_query [len ('SELECT ' ):].split ('FROM' )[1 ]
339
339
result_select = (result [len ('SELECT ' ):].split ('FROM' )[0 ]
340
340
.strip ().split (', ' ))
341
+
341
342
result_from = result [len ('SELECT ' ):].split ('FROM' )[1 ]
342
343
six .assertCountEqual (self , expected_select , result_select )
343
344
six .assertCountEqual (self , expected_from , result_from )
@@ -363,11 +364,11 @@ def test_incorrect_conditions(self):
363
364
'negate' : False },
364
365
'compoorattor' : '>=' , 'type' : 'INTEGER' }
365
366
],
366
- order_by = {'field ' : 'timestamp' , 'direction' : 'desc' })
367
+ order_by = {'fields ' : [ 'timestamp' ] , 'direction' : 'desc' })
367
368
368
369
expected_query = ("SELECT status as status, start_time as timestamp, "
369
370
"resource as url FROM "
370
- "[dataset.2013_06_appspot_1] ORDER BY "
371
+ "[dataset.2013_06_appspot_1] ORDER BY "
371
372
"timestamp desc" )
372
373
expected_select = (expected_query [len ('SELECT ' ):]
373
374
.split ('FROM' )[0 ].strip ().split (', ' ))
@@ -411,7 +412,7 @@ def test_multiple_condition_values(self):
411
412
'negate' : False }],
412
413
'type' : 'STRING' }
413
414
],
414
- order_by = {'field ' : 'timestamp' , 'direction' : 'desc' })
415
+ order_by = {'fields ' : [ 'timestamp' ] , 'direction' : 'desc' })
415
416
416
417
expected_query = ("SELECT status as status, start_time as timestamp, "
417
418
"resource as url FROM "
@@ -420,7 +421,7 @@ def test_multiple_condition_values(self):
420
421
"INTEGER('1371556954')) AND "
421
422
"((resource CONTAINS STRING('foo') AND resource "
422
423
"CONTAINS STRING('baz')) AND (NOT resource CONTAINS "
423
- "STRING('bar'))) ORDER BY timestamp desc" )
424
+ "STRING('bar'))) ORDER BY timestamp desc" )
424
425
expected_select = (expected_query [len ('SELECT ' ):]
425
426
.split ('FROM' )[0 ].strip ().split (', ' ))
426
427
expected_from = expected_query [len ('SELECT ' ):].split ('FROM' )[1 ]
@@ -449,12 +450,12 @@ def test_negated_condition_value(self):
449
450
'negate' : True }],
450
451
'type' : 'STRING' }
451
452
],
452
- order_by = {'field ' : 'timestamp' , 'direction' : 'desc' })
453
+ order_by = {'fields ' : [ 'timestamp' ] , 'direction' : 'desc' })
453
454
454
455
expected_query = ("SELECT status as status, start_time as timestamp, "
455
456
"resource as url FROM "
456
457
"[dataset.2013_06_appspot_1] WHERE (NOT resource "
457
- "CONTAINS STRING('foo')) ORDER BY timestamp desc" )
458
+ "CONTAINS STRING('foo')) ORDER BY timestamp desc" )
458
459
expected_select = (expected_query [len ('SELECT ' ):]
459
460
.split ('FROM' )[0 ].strip ().split (', ' ))
460
461
expected_from = expected_query [len ('SELECT ' ):].split ('FROM' )[1 ]
@@ -490,14 +491,14 @@ def test_multiple_negated_condition_values(self):
490
491
'negate' : True }],
491
492
'type' : 'STRING' }
492
493
],
493
- order_by = {'field ' : 'timestamp' , 'direction' : 'desc' })
494
+ order_by = {'fields ' : [ 'timestamp' ] , 'direction' : 'desc' })
494
495
495
496
expected_query = ("SELECT status as status, start_time as timestamp, "
496
497
"resource as url FROM "
497
498
"[dataset.2013_06_appspot_1] WHERE (NOT resource "
498
499
"CONTAINS STRING('foo') AND NOT resource CONTAINS "
499
500
"STRING('baz') AND NOT resource CONTAINS "
500
- "STRING('bar')) ORDER BY timestamp desc" )
501
+ "STRING('bar')) ORDER BY timestamp desc" )
501
502
expected_select = (expected_query [len ('SELECT ' ):]
502
503
.split ('FROM' )[0 ].strip ().split (', ' ))
503
504
expected_from = expected_query [len ('SELECT ' ):].split ('FROM' )[1 ]
@@ -535,7 +536,7 @@ def test_empty_order(self):
535
536
"resource as url FROM "
536
537
"[dataset.2013_06_appspot_1] WHERE (start_time "
537
538
"<= INTEGER('1371566954')) AND (start_time >= "
538
- "INTEGER('1371556954')) " )
539
+ "INTEGER('1371556954')) " )
539
540
expected_select = (expected_query [len ('SELECT ' ):]
540
541
.split ('FROM' )[0 ].strip ().split (', ' ))
541
542
expected_from = expected_query [len ('SELECT ' ):].split ('FROM' )[1 ]
@@ -573,7 +574,7 @@ def test_incorrect_order(self):
573
574
"resource as url FROM "
574
575
"[dataset.2013_06_appspot_1] WHERE (start_time "
575
576
"<= INTEGER('1371566954')) AND (start_time >= "
576
- "INTEGER('1371556954')) " )
577
+ "INTEGER('1371556954')) " )
577
578
expected_select = (expected_query [len ('SELECT ' ):]
578
579
.split ('FROM' )[0 ].strip ().split (', ' ))
579
580
expected_from = expected_query [len ('SELECT ' ):].split ('FROM' )[1 ]
@@ -601,11 +602,11 @@ def test_empty_select(self):
601
602
'negate' : False }],
602
603
'type' : 'INTEGER' },
603
604
],
604
- order_by = {'field ' : 'timestamp' , 'direction' : 'desc' })
605
+ order_by = {'fields ' : [ 'timestamp' ] , 'direction' : 'desc' })
605
606
606
607
expected_query = ("SELECT * FROM [dataset.2013_06_appspot_1] "
607
608
"WHERE (start_time <= INTEGER('1371566954')) AND "
608
- "(start_time >= INTEGER('1371556954')) ORDER BY "
609
+ "(start_time >= INTEGER('1371556954')) ORDER BY "
609
610
"timestamp desc" )
610
611
self .assertEqual (result , expected_query )
611
612
@@ -631,12 +632,12 @@ def test_no_alias(self):
631
632
'negate' : False }],
632
633
'type' : 'INTEGER' }
633
634
],
634
- order_by = {'field ' : 'start_time' , 'direction' : 'desc' })
635
+ order_by = {'fields ' : [ 'start_time' ] , 'direction' : 'desc' })
635
636
636
637
expected_query = ("SELECT status , start_time , resource FROM "
637
638
"[dataset.2013_06_appspot_1] WHERE (start_time "
638
639
"<= INTEGER('1371566954')) AND (start_time >= "
639
- "INTEGER('1371556954')) ORDER BY start_time desc" )
640
+ "INTEGER('1371556954')) ORDER BY start_time desc" )
640
641
expected_select = (field .strip () for field in
641
642
expected_query [len ('SELECT ' ):]
642
643
.split ('FROM' )[0 ].strip ().split (', ' ))
@@ -674,14 +675,14 @@ def test_formatting(self):
674
675
'negate' : False }],
675
676
'type' : 'INTEGER' },
676
677
],
677
- order_by = {'field ' : 'timestamp' , 'direction' : 'desc' })
678
+ order_by = {'fields ' : [ 'timestamp' ] , 'direction' : 'desc' })
678
679
679
680
expected_query = ("SELECT status as status, "
680
681
"FORMAT_UTC_USEC(INTEGER(start_time)) as timestamp, "
681
682
"resource as url FROM "
682
683
"[dataset.2013_06_appspot_1] WHERE (start_time "
683
684
"<= INTEGER('1371566954')) AND (start_time >= "
684
- "INTEGER('1371556954')) ORDER BY timestamp desc" )
685
+ "INTEGER('1371556954')) ORDER BY timestamp desc" )
685
686
expected_select = (expected_query [len ('SELECT ' ):]
686
687
.split ('FROM' )[0 ].strip ().split (', ' ))
687
688
expected_from = expected_query [len ('SELECT ' ):].split ('FROM' )[1 ]
@@ -725,15 +726,15 @@ def test_formatting_duplicate_columns(self):
725
726
'negate' : False }],
726
727
'type' : 'INTEGER' },
727
728
],
728
- order_by = {'field ' : 'timestamp' , 'direction' : 'desc' })
729
+ order_by = {'fields ' : [ 'timestamp' ] , 'direction' : 'desc' })
729
730
730
731
expected_query = ("SELECT status as status, "
731
732
"FORMAT_UTC_USEC(INTEGER(start_time)) as timestamp, "
732
733
"LEFT(FORMAT_UTC_USEC(INTEGER(start_time*1000000)),"
733
734
"10) as day, resource as url FROM "
734
735
"[dataset.2013_06_appspot_1] WHERE "
735
736
"(start_time <= INTEGER('1371566954')) AND "
736
- "(start_time >= INTEGER('1371556954')) ORDER BY "
737
+ "(start_time >= INTEGER('1371556954')) ORDER BY "
737
738
"timestamp desc" )
738
739
expected_select = (expected_query [len ('SELECT ' ):]
739
740
.split ('FROM' )[0 ].strip ().split (', ' ))
@@ -771,14 +772,14 @@ def test_sec_to_micro_formatting(self):
771
772
'negate' : False }],
772
773
'type' : 'INTEGER' },
773
774
],
774
- order_by = {'field ' : 'timestamp' , 'direction' : 'desc' })
775
+ order_by = {'fields ' : [ 'timestamp' ] , 'direction' : 'desc' })
775
776
776
777
expected_query = ("SELECT status as status, "
777
778
"SEC_TO_TIMESTAMP(INTEGER(start_time*1000000)) as "
778
779
"timestamp, resource as url FROM "
779
780
"[dataset.2013_06_appspot_1] WHERE (start_time "
780
781
"<= INTEGER('1371566954')) AND (start_time >= "
781
- "INTEGER('1371556954')) ORDER BY timestamp desc" )
782
+ "INTEGER('1371556954')) ORDER BY timestamp desc" )
782
783
expected_select = (expected_query [len ('SELECT ' ):]
783
784
.split ('FROM' )[0 ].strip ().split (', ' ))
784
785
expected_from = expected_query [len ('SELECT ' ):].split ('FROM' )[1 ]
@@ -812,7 +813,7 @@ def test_no_table_or_dataset(self):
812
813
'negate' : False }],
813
814
'type' : 'INTEGER' },
814
815
],
815
- order_by = {'field ' : 'timestamp' , 'direction' : 'desc' })
816
+ order_by = {'fields ' : [ 'timestamp' ] , 'direction' : 'desc' })
816
817
817
818
self .assertIsNone (result )
818
819
@@ -829,11 +830,11 @@ def test_empty_groupings(self):
829
830
'resource' : {'alias' : 'url' }
830
831
},
831
832
groupings = [],
832
- order_by = {'field ' : 'timestamp' , 'direction' : 'desc' })
833
+ order_by = {'fields ' : [ 'timestamp' ] , 'direction' : 'desc' })
833
834
834
835
expected_query = ("SELECT status as status, start_time as timestamp, "
835
836
"resource as url FROM "
836
- "[dataset.2013_06_appspot_1] ORDER BY "
837
+ "[dataset.2013_06_appspot_1] ORDER BY "
837
838
"timestamp desc" )
838
839
expected_select = (expected_query [len ('SELECT ' ):]
839
840
.split ('FROM' )[0 ].strip ().split (', ' ))
@@ -844,7 +845,6 @@ def test_empty_groupings(self):
844
845
six .assertCountEqual (self , expected_select , result_select )
845
846
six .assertCountEqual (self , expected_from , result_from )
846
847
847
-
848
848
def test_multi_tables (self ):
849
849
"""Ensure that render query arguments work with multiple tables."""
850
850
from bigquery .query_builder import render_query
@@ -868,14 +868,14 @@ def test_multi_tables(self):
868
868
'type' : 'INTEGER' },
869
869
],
870
870
groupings = ['timestamp' , 'status' ],
871
- order_by = {'field ' : 'timestamp' , 'direction' : 'desc' })
871
+ order_by = {'fields ' : [ 'timestamp' ] , 'direction' : 'desc' })
872
872
873
873
expected_query = ("SELECT status as status, start_time as timestamp, "
874
874
"resource as url FROM "
875
875
"[dataset.2013_06_appspot_1], "
876
876
"[dataset.2013_07_appspot_1] WHERE (start_time "
877
877
"<= INTEGER('1371566954')) AND (start_time >= "
878
- "INTEGER('1371556954')) GROUP BY timestamp, status "
878
+ "INTEGER('1371556954')) GROUP BY timestamp, status "
879
879
"ORDER BY timestamp desc" )
880
880
expected_select = (expected_query [len ('SELECT ' ):]
881
881
.split ('FROM' )[0 ].strip ().split (', ' ))
0 commit comments