@@ -44,20 +44,29 @@ def primary_key(self) -> Optional[Union[str, List[str], List[List[str]]]]:
44
44
def url_base (self ) -> str :
45
45
return self .sf_api .instance_url
46
46
47
- def path (self , ** kwargs ) -> str :
47
+ def path (self , next_page_token : Mapping [str , Any ] = None , ** kwargs ) -> str :
48
+ if next_page_token :
49
+ """
50
+ If `next_page_token` is set, subsequent requests use `nextRecordsUrl`.
51
+ """
52
+ return next_page_token
48
53
return f"/services/data/{ self .sf_api .version } /queryAll"
49
54
50
55
def next_page_token (self , response : requests .Response ) -> str :
51
56
response_data = response .json ()
52
- if len (response_data ["records" ]) == self .page_size and self .primary_key and self .name not in UNSUPPORTED_FILTERING_STREAMS :
53
- return f"WHERE { self .primary_key } >= '{ response_data ['records' ][- 1 ][self .primary_key ]} ' "
57
+ return response_data .get ("nextRecordsUrl" )
54
58
55
59
def request_params (
56
60
self , stream_state : Mapping [str , Any ], stream_slice : Mapping [str , any ] = None , next_page_token : Mapping [str , Any ] = None
57
61
) -> MutableMapping [str , Any ]:
58
62
"""
59
63
Salesforce SOQL Query: https://developer.salesforce.com/docs/atlas.en-us.232.0.api_rest.meta/api_rest/dome_queryall.htm
60
64
"""
65
+ if next_page_token :
66
+ """
67
+ If `next_page_token` is set, subsequent requests use `nextRecordsUrl`, and do not include any parameters.
68
+ """
69
+ return {}
61
70
62
71
selected_properties = self .get_json_schema ().get ("properties" , {})
63
72
@@ -70,11 +79,9 @@ def request_params(
70
79
}
71
80
72
81
query = f"SELECT { ',' .join (selected_properties .keys ())} FROM { self .name } "
73
- if next_page_token :
74
- query += next_page_token
75
82
76
83
if self .primary_key and self .name not in UNSUPPORTED_FILTERING_STREAMS :
77
- query += f"ORDER BY { self .primary_key } ASC LIMIT { self . page_size } "
84
+ query += f"ORDER BY { self .primary_key } ASC"
78
85
79
86
return {"q" : query }
80
87
@@ -259,6 +266,32 @@ def next_page_token(self, last_record: dict) -> str:
259
266
if self .primary_key and self .name not in UNSUPPORTED_FILTERING_STREAMS :
260
267
return f"WHERE { self .primary_key } >= '{ last_record [self .primary_key ]} ' "
261
268
269
+ def request_params (
270
+ self , stream_state : Mapping [str , Any ], stream_slice : Mapping [str , any ] = None , next_page_token : Mapping [str , Any ] = None
271
+ ) -> MutableMapping [str , Any ]:
272
+ """
273
+ Salesforce SOQL Query: https://developer.salesforce.com/docs/atlas.en-us.232.0.api_rest.meta/api_rest/dome_queryall.htm
274
+ """
275
+
276
+ selected_properties = self .get_json_schema ().get ("properties" , {})
277
+
278
+ # Salesforce BULK API currently does not support loading fields with data type base64 and compound data
279
+ if self .sf_api .api_type == "BULK" :
280
+ selected_properties = {
281
+ key : value
282
+ for key , value in selected_properties .items ()
283
+ if value .get ("format" ) != "base64" and "object" not in value ["type" ]
284
+ }
285
+
286
+ query = f"SELECT { ',' .join (selected_properties .keys ())} FROM { self .name } "
287
+ if next_page_token :
288
+ query += next_page_token
289
+
290
+ if self .primary_key and self .name not in UNSUPPORTED_FILTERING_STREAMS :
291
+ query += f"ORDER BY { self .primary_key } ASC LIMIT { self .page_size } "
292
+
293
+ return {"q" : query }
294
+
262
295
def read_records (
263
296
self ,
264
297
sync_mode : SyncMode ,
@@ -305,14 +338,15 @@ def format_start_date(start_date: Optional[str]) -> Optional[str]:
305
338
if start_date :
306
339
return pendulum .parse (start_date ).strftime ("%Y-%m-%dT%H:%M:%SZ" )
307
340
308
- def next_page_token (self , response : requests .Response ) -> str :
309
- response_data = response .json ()
310
- if len (response_data ["records" ]) == self .page_size and self .name not in UNSUPPORTED_FILTERING_STREAMS :
311
- return response_data ["records" ][- 1 ][self .cursor_field ]
312
-
313
341
def request_params (
314
342
self , stream_state : Mapping [str , Any ], stream_slice : Mapping [str , any ] = None , next_page_token : Mapping [str , Any ] = None
315
343
) -> MutableMapping [str , Any ]:
344
+ if next_page_token :
345
+ """
346
+ If `next_page_token` is set, subsequent requests use `nextRecordsUrl`, and do not include any parameters.
347
+ """
348
+ return {}
349
+
316
350
selected_properties = self .get_json_schema ().get ("properties" , {})
317
351
318
352
# Salesforce BULK API currently does not support loading fields with data type base64 and compound data
@@ -324,13 +358,13 @@ def request_params(
324
358
}
325
359
326
360
stream_date = stream_state .get (self .cursor_field )
327
- start_date = next_page_token or stream_date or self .start_date
361
+ start_date = stream_date or self .start_date
328
362
329
363
query = f"SELECT { ',' .join (selected_properties .keys ())} FROM { self .name } "
330
364
if start_date :
331
365
query += f"WHERE { self .cursor_field } >= { start_date } "
332
366
if self .name not in UNSUPPORTED_FILTERING_STREAMS :
333
- query += f"ORDER BY { self .cursor_field } ASC LIMIT { self . page_size } "
367
+ query += f"ORDER BY { self .cursor_field } ASC"
334
368
return {"q" : query }
335
369
336
370
@property
@@ -352,3 +386,26 @@ class BulkIncrementalSalesforceStream(BulkSalesforceStream, IncrementalSalesforc
352
386
def next_page_token (self , last_record : dict ) -> str :
353
387
if self .name not in UNSUPPORTED_FILTERING_STREAMS :
354
388
return last_record [self .cursor_field ]
389
+
390
+ def request_params (
391
+ self , stream_state : Mapping [str , Any ], stream_slice : Mapping [str , any ] = None , next_page_token : Mapping [str , Any ] = None
392
+ ) -> MutableMapping [str , Any ]:
393
+ selected_properties = self .get_json_schema ().get ("properties" , {})
394
+
395
+ # Salesforce BULK API currently does not support loading fields with data type base64 and compound data
396
+ if self .sf_api .api_type == "BULK" :
397
+ selected_properties = {
398
+ key : value
399
+ for key , value in selected_properties .items ()
400
+ if value .get ("format" ) != "base64" and "object" not in value ["type" ]
401
+ }
402
+
403
+ stream_date = stream_state .get (self .cursor_field )
404
+ start_date = next_page_token or stream_date or self .start_date
405
+
406
+ query = f"SELECT { ',' .join (selected_properties .keys ())} FROM { self .name } "
407
+ if start_date :
408
+ query += f"WHERE { self .cursor_field } >= { start_date } "
409
+ if self .name not in UNSUPPORTED_FILTERING_STREAMS :
410
+ query += f"ORDER BY { self .cursor_field } ASC LIMIT { self .page_size } "
411
+ return {"q" : query }
0 commit comments