@@ -225,7 +225,7 @@ def test_order(self):
225225 """Ensure that render order can work under expected conditions."""
226226 from bigquery .query_builder import _render_order
227227
228- result = _render_order ({'field ' : 'foo' , 'direction' : 'desc' })
228+ result = _render_order ({'fields ' : [ 'foo' ] , 'direction' : 'desc' })
229229
230230 self .assertEqual (result , "ORDER BY foo desc" )
231231
@@ -298,13 +298,13 @@ def test_full_query(self):
298298 }
299299 ],
300300 groupings = ['timestamp' , 'status' ],
301- order_by = {'field ' : 'timestamp' , 'direction' : 'desc' })
301+ order_by = {'fields ' : [ 'timestamp' ] , 'direction' : 'desc' })
302302
303303 expected_query = ("SELECT status as status, start_time as timestamp, "
304304 "resource as url FROM [dataset.2013_06_appspot_1]"
305305 " WHERE (start_time <= INTEGER('1371566954')) AND "
306306 "(start_time >= INTEGER('1371556954')) GROUP BY "
307- "timestamp, status ORDER BY timestamp desc" )
307+ "timestamp, status ORDER BY timestamp desc" )
308308 expected_select = (expected_query [len ('SELECT ' ):]
309309 .split ('FROM' )[0 ].strip ().split (', ' ))
310310 expected_from = expected_query [len ('SELECT ' ):].split ('FROM' )[1 ]
@@ -327,17 +327,18 @@ def test_empty_conditions(self):
327327 'resource' : {'alias' : 'url' }
328328 },
329329 conditions = [],
330- order_by = {'field ' : 'timestamp' , 'direction' : 'desc' })
330+ order_by = {'fields ' : [ 'timestamp' ] , 'direction' : 'desc' })
331331
332332 expected_query = ("SELECT status as status, start_time as timestamp, "
333333 "resource as url FROM "
334- "[dataset.2013_06_appspot_1] ORDER BY "
334+ "[dataset.2013_06_appspot_1] ORDER BY "
335335 "timestamp desc" )
336336 expected_select = (expected_query [len ('SELECT ' ):]
337337 .split ('FROM' )[0 ].strip ().split (', ' ))
338338 expected_from = expected_query [len ('SELECT ' ):].split ('FROM' )[1 ]
339339 result_select = (result [len ('SELECT ' ):].split ('FROM' )[0 ]
340340 .strip ().split (', ' ))
341+
341342 result_from = result [len ('SELECT ' ):].split ('FROM' )[1 ]
342343 six .assertCountEqual (self , expected_select , result_select )
343344 six .assertCountEqual (self , expected_from , result_from )
@@ -363,11 +364,11 @@ def test_incorrect_conditions(self):
363364 'negate' : False },
364365 'compoorattor' : '>=' , 'type' : 'INTEGER' }
365366 ],
366- order_by = {'field ' : 'timestamp' , 'direction' : 'desc' })
367+ order_by = {'fields ' : [ 'timestamp' ] , 'direction' : 'desc' })
367368
368369 expected_query = ("SELECT status as status, start_time as timestamp, "
369370 "resource as url FROM "
370- "[dataset.2013_06_appspot_1] ORDER BY "
371+ "[dataset.2013_06_appspot_1] ORDER BY "
371372 "timestamp desc" )
372373 expected_select = (expected_query [len ('SELECT ' ):]
373374 .split ('FROM' )[0 ].strip ().split (', ' ))
@@ -411,7 +412,7 @@ def test_multiple_condition_values(self):
411412 'negate' : False }],
412413 'type' : 'STRING' }
413414 ],
414- order_by = {'field ' : 'timestamp' , 'direction' : 'desc' })
415+ order_by = {'fields ' : [ 'timestamp' ] , 'direction' : 'desc' })
415416
416417 expected_query = ("SELECT status as status, start_time as timestamp, "
417418 "resource as url FROM "
@@ -420,7 +421,7 @@ def test_multiple_condition_values(self):
420421 "INTEGER('1371556954')) AND "
421422 "((resource CONTAINS STRING('foo') AND resource "
422423 "CONTAINS STRING('baz')) AND (NOT resource CONTAINS "
423- "STRING('bar'))) ORDER BY timestamp desc" )
424+ "STRING('bar'))) ORDER BY timestamp desc" )
424425 expected_select = (expected_query [len ('SELECT ' ):]
425426 .split ('FROM' )[0 ].strip ().split (', ' ))
426427 expected_from = expected_query [len ('SELECT ' ):].split ('FROM' )[1 ]
@@ -449,12 +450,12 @@ def test_negated_condition_value(self):
449450 'negate' : True }],
450451 'type' : 'STRING' }
451452 ],
452- order_by = {'field ' : 'timestamp' , 'direction' : 'desc' })
453+ order_by = {'fields ' : [ 'timestamp' ] , 'direction' : 'desc' })
453454
454455 expected_query = ("SELECT status as status, start_time as timestamp, "
455456 "resource as url FROM "
456457 "[dataset.2013_06_appspot_1] WHERE (NOT resource "
457- "CONTAINS STRING('foo')) ORDER BY timestamp desc" )
458+ "CONTAINS STRING('foo')) ORDER BY timestamp desc" )
458459 expected_select = (expected_query [len ('SELECT ' ):]
459460 .split ('FROM' )[0 ].strip ().split (', ' ))
460461 expected_from = expected_query [len ('SELECT ' ):].split ('FROM' )[1 ]
@@ -490,14 +491,14 @@ def test_multiple_negated_condition_values(self):
490491 'negate' : True }],
491492 'type' : 'STRING' }
492493 ],
493- order_by = {'field ' : 'timestamp' , 'direction' : 'desc' })
494+ order_by = {'fields ' : [ 'timestamp' ] , 'direction' : 'desc' })
494495
495496 expected_query = ("SELECT status as status, start_time as timestamp, "
496497 "resource as url FROM "
497498 "[dataset.2013_06_appspot_1] WHERE (NOT resource "
498499 "CONTAINS STRING('foo') AND NOT resource CONTAINS "
499500 "STRING('baz') AND NOT resource CONTAINS "
500- "STRING('bar')) ORDER BY timestamp desc" )
501+ "STRING('bar')) ORDER BY timestamp desc" )
501502 expected_select = (expected_query [len ('SELECT ' ):]
502503 .split ('FROM' )[0 ].strip ().split (', ' ))
503504 expected_from = expected_query [len ('SELECT ' ):].split ('FROM' )[1 ]
@@ -535,7 +536,7 @@ def test_empty_order(self):
535536 "resource as url FROM "
536537 "[dataset.2013_06_appspot_1] WHERE (start_time "
537538 "<= INTEGER('1371566954')) AND (start_time >= "
538- "INTEGER('1371556954')) " )
539+ "INTEGER('1371556954')) " )
539540 expected_select = (expected_query [len ('SELECT ' ):]
540541 .split ('FROM' )[0 ].strip ().split (', ' ))
541542 expected_from = expected_query [len ('SELECT ' ):].split ('FROM' )[1 ]
@@ -573,7 +574,7 @@ def test_incorrect_order(self):
573574 "resource as url FROM "
574575 "[dataset.2013_06_appspot_1] WHERE (start_time "
575576 "<= INTEGER('1371566954')) AND (start_time >= "
576- "INTEGER('1371556954')) " )
577+ "INTEGER('1371556954')) " )
577578 expected_select = (expected_query [len ('SELECT ' ):]
578579 .split ('FROM' )[0 ].strip ().split (', ' ))
579580 expected_from = expected_query [len ('SELECT ' ):].split ('FROM' )[1 ]
@@ -601,11 +602,11 @@ def test_empty_select(self):
601602 'negate' : False }],
602603 'type' : 'INTEGER' },
603604 ],
604- order_by = {'field ' : 'timestamp' , 'direction' : 'desc' })
605+ order_by = {'fields ' : [ 'timestamp' ] , 'direction' : 'desc' })
605606
606607 expected_query = ("SELECT * FROM [dataset.2013_06_appspot_1] "
607608 "WHERE (start_time <= INTEGER('1371566954')) AND "
608- "(start_time >= INTEGER('1371556954')) ORDER BY "
609+ "(start_time >= INTEGER('1371556954')) ORDER BY "
609610 "timestamp desc" )
610611 self .assertEqual (result , expected_query )
611612
@@ -631,12 +632,12 @@ def test_no_alias(self):
631632 'negate' : False }],
632633 'type' : 'INTEGER' }
633634 ],
634- order_by = {'field ' : 'start_time' , 'direction' : 'desc' })
635+ order_by = {'fields ' : [ 'start_time' ] , 'direction' : 'desc' })
635636
636637 expected_query = ("SELECT status , start_time , resource FROM "
637638 "[dataset.2013_06_appspot_1] WHERE (start_time "
638639 "<= INTEGER('1371566954')) AND (start_time >= "
639- "INTEGER('1371556954')) ORDER BY start_time desc" )
640+ "INTEGER('1371556954')) ORDER BY start_time desc" )
640641 expected_select = (field .strip () for field in
641642 expected_query [len ('SELECT ' ):]
642643 .split ('FROM' )[0 ].strip ().split (', ' ))
@@ -674,14 +675,14 @@ def test_formatting(self):
674675 'negate' : False }],
675676 'type' : 'INTEGER' },
676677 ],
677- order_by = {'field ' : 'timestamp' , 'direction' : 'desc' })
678+ order_by = {'fields ' : [ 'timestamp' ] , 'direction' : 'desc' })
678679
679680 expected_query = ("SELECT status as status, "
680681 "FORMAT_UTC_USEC(INTEGER(start_time)) as timestamp, "
681682 "resource as url FROM "
682683 "[dataset.2013_06_appspot_1] WHERE (start_time "
683684 "<= INTEGER('1371566954')) AND (start_time >= "
684- "INTEGER('1371556954')) ORDER BY timestamp desc" )
685+ "INTEGER('1371556954')) ORDER BY timestamp desc" )
685686 expected_select = (expected_query [len ('SELECT ' ):]
686687 .split ('FROM' )[0 ].strip ().split (', ' ))
687688 expected_from = expected_query [len ('SELECT ' ):].split ('FROM' )[1 ]
@@ -725,15 +726,15 @@ def test_formatting_duplicate_columns(self):
725726 'negate' : False }],
726727 'type' : 'INTEGER' },
727728 ],
728- order_by = {'field ' : 'timestamp' , 'direction' : 'desc' })
729+ order_by = {'fields ' : [ 'timestamp' ] , 'direction' : 'desc' })
729730
730731 expected_query = ("SELECT status as status, "
731732 "FORMAT_UTC_USEC(INTEGER(start_time)) as timestamp, "
732733 "LEFT(FORMAT_UTC_USEC(INTEGER(start_time*1000000)),"
733734 "10) as day, resource as url FROM "
734735 "[dataset.2013_06_appspot_1] WHERE "
735736 "(start_time <= INTEGER('1371566954')) AND "
736- "(start_time >= INTEGER('1371556954')) ORDER BY "
737+ "(start_time >= INTEGER('1371556954')) ORDER BY "
737738 "timestamp desc" )
738739 expected_select = (expected_query [len ('SELECT ' ):]
739740 .split ('FROM' )[0 ].strip ().split (', ' ))
@@ -771,14 +772,14 @@ def test_sec_to_micro_formatting(self):
771772 'negate' : False }],
772773 'type' : 'INTEGER' },
773774 ],
774- order_by = {'field ' : 'timestamp' , 'direction' : 'desc' })
775+ order_by = {'fields ' : [ 'timestamp' ] , 'direction' : 'desc' })
775776
776777 expected_query = ("SELECT status as status, "
777778 "SEC_TO_TIMESTAMP(INTEGER(start_time*1000000)) as "
778779 "timestamp, resource as url FROM "
779780 "[dataset.2013_06_appspot_1] WHERE (start_time "
780781 "<= INTEGER('1371566954')) AND (start_time >= "
781- "INTEGER('1371556954')) ORDER BY timestamp desc" )
782+ "INTEGER('1371556954')) ORDER BY timestamp desc" )
782783 expected_select = (expected_query [len ('SELECT ' ):]
783784 .split ('FROM' )[0 ].strip ().split (', ' ))
784785 expected_from = expected_query [len ('SELECT ' ):].split ('FROM' )[1 ]
@@ -812,7 +813,7 @@ def test_no_table_or_dataset(self):
812813 'negate' : False }],
813814 'type' : 'INTEGER' },
814815 ],
815- order_by = {'field ' : 'timestamp' , 'direction' : 'desc' })
816+ order_by = {'fields ' : [ 'timestamp' ] , 'direction' : 'desc' })
816817
817818 self .assertIsNone (result )
818819
@@ -829,11 +830,11 @@ def test_empty_groupings(self):
829830 'resource' : {'alias' : 'url' }
830831 },
831832 groupings = [],
832- order_by = {'field ' : 'timestamp' , 'direction' : 'desc' })
833+ order_by = {'fields ' : [ 'timestamp' ] , 'direction' : 'desc' })
833834
834835 expected_query = ("SELECT status as status, start_time as timestamp, "
835836 "resource as url FROM "
836- "[dataset.2013_06_appspot_1] ORDER BY "
837+ "[dataset.2013_06_appspot_1] ORDER BY "
837838 "timestamp desc" )
838839 expected_select = (expected_query [len ('SELECT ' ):]
839840 .split ('FROM' )[0 ].strip ().split (', ' ))
@@ -844,7 +845,6 @@ def test_empty_groupings(self):
844845 six .assertCountEqual (self , expected_select , result_select )
845846 six .assertCountEqual (self , expected_from , result_from )
846847
847-
848848 def test_multi_tables (self ):
849849 """Ensure that render query arguments work with multiple tables."""
850850 from bigquery .query_builder import render_query
@@ -868,14 +868,14 @@ def test_multi_tables(self):
868868 'type' : 'INTEGER' },
869869 ],
870870 groupings = ['timestamp' , 'status' ],
871- order_by = {'field ' : 'timestamp' , 'direction' : 'desc' })
871+ order_by = {'fields ' : [ 'timestamp' ] , 'direction' : 'desc' })
872872
873873 expected_query = ("SELECT status as status, start_time as timestamp, "
874874 "resource as url FROM "
875875 "[dataset.2013_06_appspot_1], "
876876 "[dataset.2013_07_appspot_1] WHERE (start_time "
877877 "<= INTEGER('1371566954')) AND (start_time >= "
878- "INTEGER('1371556954')) GROUP BY timestamp, status "
878+ "INTEGER('1371556954')) GROUP BY timestamp, status "
879879 "ORDER BY timestamp desc" )
880880 expected_select = (expected_query [len ('SELECT ' ):]
881881 .split ('FROM' )[0 ].strip ().split (', ' ))
0 commit comments