@@ -787,7 +787,9 @@ def test_result(self):
787
787
"location" : "EU" ,
788
788
},
789
789
"schema" : {"fields" : [{"name" : "col1" , "type" : "STRING" }]},
790
- "totalRows" : "2" ,
790
+ "totalRows" : "3" ,
791
+ "rows" : [{"f" : [{"v" : "abc" }]}],
792
+ "pageToken" : "next-page" ,
791
793
}
792
794
job_resource = self ._make_resource (started = True , location = "EU" )
793
795
job_resource_done = self ._make_resource (started = True , ended = True , location = "EU" )
@@ -799,9 +801,9 @@ def test_result(self):
799
801
query_page_resource = {
800
802
# Explicitly set totalRows to be different from the initial
801
803
# response to test update during iteration.
802
- "totalRows" : "1 " ,
804
+ "totalRows" : "2 " ,
803
805
"pageToken" : None ,
804
- "rows" : [{"f" : [{"v" : "abc " }]}],
806
+ "rows" : [{"f" : [{"v" : "def " }]}],
805
807
}
806
808
conn = _make_connection (
807
809
query_resource , query_resource_done , job_resource_done , query_page_resource
@@ -812,19 +814,20 @@ def test_result(self):
812
814
result = job .result ()
813
815
814
816
self .assertIsInstance (result , RowIterator )
815
- self .assertEqual (result .total_rows , 2 )
817
+ self .assertEqual (result .total_rows , 3 )
816
818
rows = list (result )
817
- self .assertEqual (len (rows ), 1 )
819
+ self .assertEqual (len (rows ), 2 )
818
820
self .assertEqual (rows [0 ].col1 , "abc" )
821
+ self .assertEqual (rows [1 ].col1 , "def" )
819
822
# Test that the total_rows property has changed during iteration, based
820
823
# on the response from tabledata.list.
821
- self .assertEqual (result .total_rows , 1 )
824
+ self .assertEqual (result .total_rows , 2 )
822
825
823
826
query_results_path = f"/projects/{ self .PROJECT } /queries/{ self .JOB_ID } "
824
827
query_results_call = mock .call (
825
828
method = "GET" ,
826
829
path = query_results_path ,
827
- query_params = {"maxResults" : 0 , " location" : "EU" },
830
+ query_params = {"location" : "EU" },
828
831
timeout = None ,
829
832
)
830
833
reload_call = mock .call (
@@ -839,6 +842,7 @@ def test_result(self):
839
842
query_params = {
840
843
"fields" : _LIST_ROWS_FROM_QUERY_RESULTS_FIELDS ,
841
844
"location" : "EU" ,
845
+ "pageToken" : "next-page" ,
842
846
},
843
847
timeout = None ,
844
848
)
@@ -851,7 +855,9 @@ def test_result_with_done_job_calls_get_query_results(self):
851
855
"jobComplete" : True ,
852
856
"jobReference" : {"projectId" : self .PROJECT , "jobId" : self .JOB_ID },
853
857
"schema" : {"fields" : [{"name" : "col1" , "type" : "STRING" }]},
854
- "totalRows" : "1" ,
858
+ "totalRows" : "2" ,
859
+ "rows" : [{"f" : [{"v" : "abc" }]}],
860
+ "pageToken" : "next-page" ,
855
861
}
856
862
job_resource = self ._make_resource (started = True , ended = True , location = "EU" )
857
863
job_resource ["configuration" ]["query" ]["destinationTable" ] = {
@@ -860,9 +866,9 @@ def test_result_with_done_job_calls_get_query_results(self):
860
866
"tableId" : "dest_table" ,
861
867
}
862
868
results_page_resource = {
863
- "totalRows" : "1 " ,
869
+ "totalRows" : "2 " ,
864
870
"pageToken" : None ,
865
- "rows" : [{"f" : [{"v" : "abc " }]}],
871
+ "rows" : [{"f" : [{"v" : "def " }]}],
866
872
}
867
873
conn = _make_connection (query_resource_done , results_page_resource )
868
874
client = _make_client (self .PROJECT , connection = conn )
@@ -871,14 +877,15 @@ def test_result_with_done_job_calls_get_query_results(self):
871
877
result = job .result ()
872
878
873
879
rows = list (result )
874
- self .assertEqual (len (rows ), 1 )
880
+ self .assertEqual (len (rows ), 2 )
875
881
self .assertEqual (rows [0 ].col1 , "abc" )
882
+ self .assertEqual (rows [1 ].col1 , "def" )
876
883
877
884
query_results_path = f"/projects/{ self .PROJECT } /queries/{ self .JOB_ID } "
878
885
query_results_call = mock .call (
879
886
method = "GET" ,
880
887
path = query_results_path ,
881
- query_params = {"maxResults" : 0 , " location" : "EU" },
888
+ query_params = {"location" : "EU" },
882
889
timeout = None ,
883
890
)
884
891
query_results_page_call = mock .call (
@@ -887,6 +894,7 @@ def test_result_with_done_job_calls_get_query_results(self):
887
894
query_params = {
888
895
"fields" : _LIST_ROWS_FROM_QUERY_RESULTS_FIELDS ,
889
896
"location" : "EU" ,
897
+ "pageToken" : "next-page" ,
890
898
},
891
899
timeout = None ,
892
900
)
@@ -900,6 +908,12 @@ def test_result_with_max_results(self):
900
908
"jobReference" : {"projectId" : self .PROJECT , "jobId" : self .JOB_ID },
901
909
"schema" : {"fields" : [{"name" : "col1" , "type" : "STRING" }]},
902
910
"totalRows" : "5" ,
911
+ # These rows are discarded because max_results is set.
912
+ "rows" : [
913
+ {"f" : [{"v" : "xyz" }]},
914
+ {"f" : [{"v" : "uvw" }]},
915
+ {"f" : [{"v" : "rst" }]},
916
+ ],
903
917
}
904
918
query_page_resource = {
905
919
"totalRows" : "5" ,
@@ -925,6 +939,7 @@ def test_result_with_max_results(self):
925
939
rows = list (result )
926
940
927
941
self .assertEqual (len (rows ), 3 )
942
+ self .assertEqual (rows [0 ].col1 , "abc" )
928
943
self .assertEqual (len (connection .api_request .call_args_list ), 2 )
929
944
query_page_request = connection .api_request .call_args_list [1 ]
930
945
self .assertEqual (
@@ -979,7 +994,7 @@ def test_result_w_retry(self):
979
994
query_results_call = mock .call (
980
995
method = "GET" ,
981
996
path = f"/projects/{ self .PROJECT } /queries/{ self .JOB_ID } " ,
982
- query_params = {"maxResults" : 0 , " location" : "asia-northeast1" },
997
+ query_params = {"location" : "asia-northeast1" },
983
998
timeout = None ,
984
999
)
985
1000
reload_call = mock .call (
@@ -1079,6 +1094,12 @@ def test_result_w_page_size(self):
1079
1094
"jobReference" : {"projectId" : self .PROJECT , "jobId" : self .JOB_ID },
1080
1095
"schema" : {"fields" : [{"name" : "col1" , "type" : "STRING" }]},
1081
1096
"totalRows" : "4" ,
1097
+ # These rows are discarded because page_size is set.
1098
+ "rows" : [
1099
+ {"f" : [{"v" : "xyz" }]},
1100
+ {"f" : [{"v" : "uvw" }]},
1101
+ {"f" : [{"v" : "rst" }]},
1102
+ ],
1082
1103
}
1083
1104
job_resource = self ._make_resource (started = True , ended = True , location = "US" )
1084
1105
q_config = job_resource ["configuration" ]["query" ]
@@ -1109,6 +1130,7 @@ def test_result_w_page_size(self):
1109
1130
# Assert
1110
1131
actual_rows = list (result )
1111
1132
self .assertEqual (len (actual_rows ), 4 )
1133
+ self .assertEqual (actual_rows [0 ].col1 , "row1" )
1112
1134
1113
1135
query_results_path = f"/projects/{ self .PROJECT } /queries/{ self .JOB_ID } "
1114
1136
query_page_1_call = mock .call (
@@ -1142,6 +1164,12 @@ def test_result_with_start_index(self):
1142
1164
"jobReference" : {"projectId" : self .PROJECT , "jobId" : self .JOB_ID },
1143
1165
"schema" : {"fields" : [{"name" : "col1" , "type" : "STRING" }]},
1144
1166
"totalRows" : "5" ,
1167
+ # These rows are discarded because start_index is set.
1168
+ "rows" : [
1169
+ {"f" : [{"v" : "xyz" }]},
1170
+ {"f" : [{"v" : "uvw" }]},
1171
+ {"f" : [{"v" : "rst" }]},
1172
+ ],
1145
1173
}
1146
1174
tabledata_resource = {
1147
1175
"totalRows" : "5" ,
@@ -1168,6 +1196,7 @@ def test_result_with_start_index(self):
1168
1196
rows = list (result )
1169
1197
1170
1198
self .assertEqual (len (rows ), 4 )
1199
+ self .assertEqual (rows [0 ].col1 , "abc" )
1171
1200
self .assertEqual (len (connection .api_request .call_args_list ), 2 )
1172
1201
tabledata_list_request = connection .api_request .call_args_list [1 ]
1173
1202
self .assertEqual (
0 commit comments