66from civis .io import civis_to_file
77from civis ._utils import maybe_get_random_name
88from civis .base import EmptyResultError
9- from civis .polling import PollableResult , _DEFAULT_POLLING_INTERVAL
9+ from civis .futures import CivisFuture
1010import requests
1111import warnings
1212
3030
3131def read_civis (table , database , columns = None , use_pandas = False ,
3232 job_name = None , api_key = None , credential_id = None ,
33- polling_interval = _DEFAULT_POLLING_INTERVAL ,
34- archive = False , hidden = True , ** kwargs ):
33+ polling_interval = None , archive = False , hidden = True , ** kwargs ):
3534 """Read data from a Civis table.
3635
3736 Parameters
@@ -115,8 +114,8 @@ def read_civis(table, database, columns=None, use_pandas=False,
115114
116115def read_civis_sql (sql , database , use_pandas = False , job_name = None ,
117116 api_key = None , credential_id = None ,
118- polling_interval = _DEFAULT_POLLING_INTERVAL ,
119- archive = False , hidden = True , ** kwargs ):
117+ polling_interval = None , archive = False ,
118+ hidden = True , ** kwargs ):
120119 """Read data from Civis using a custom SQL string.
121120
122121 Parameters
@@ -192,16 +191,16 @@ def read_civis_sql(sql, database, use_pandas=False, job_name=None,
192191 script_id , run_id = _sql_script (client , sql , database ,
193192 job_name , credential_id ,
194193 hidden = hidden )
195- poll = PollableResult (client .scripts .get_sql_runs ,
196- ( script_id , run_id ) ,
197- polling_interval )
194+ fut = CivisFuture (client .scripts .get_sql_runs , ( script_id , run_id ) ,
195+ polling_interval = polling_interval , api_key = api_key ,
196+ poll_on_creation = False )
198197 if archive :
199198
200199 def f (x ):
201200 return client .scripts .put_sql_archive (script_id , True )
202201
203- poll .add_done_callback (f )
204- poll .result ()
202+ fut .add_done_callback (f )
203+ fut .result ()
205204 outputs = client .scripts .get_sql_runs (script_id , run_id )["output" ]
206205 if not outputs :
207206 raise EmptyResultError ("Query {} returned no output."
@@ -218,7 +217,7 @@ def f(x):
218217
219218def civis_to_csv (filename , sql , database , job_name = None , api_key = None ,
220219 credential_id = None , archive = False , hidden = True ,
221- polling_interval = _DEFAULT_POLLING_INTERVAL ):
220+ polling_interval = None ):
222221 """Export data from Civis to a local CSV file.
223222
224223 Parameters
@@ -247,14 +246,14 @@ def civis_to_csv(filename, sql, database, job_name=None, api_key=None,
247246
248247 Returns
249248 -------
250- results : :class:`~civis.polling.PollableResult `
251- A `PollableResult ` object.
249+ results : :class:`~civis.futures.CivisFuture `
250+ A `CivisFuture ` object.
252251
253252 Examples
254253 --------
255254 >>> sql = "SELECT * FROM schema.table"
256- >>> poll = civis_to_csv("file.csv", sql, "my_database")
257- >>> poll .result() # Wait for job to complete
255+ >>> fut = civis_to_csv("file.csv", sql, "my_database")
256+ >>> fut .result() # Wait for job to complete
258257
259258 See Also
260259 --------
@@ -268,27 +267,26 @@ def civis_to_csv(filename, sql, database, job_name=None, api_key=None,
268267 script_id , run_id = _sql_script (client , sql , database ,
269268 job_name , credential_id ,
270269 hidden = hidden )
271- poll = PollableResult (client .scripts .get_sql_runs ,
272- ( script_id , run_id ) ,
273- polling_interval )
270+ fut = CivisFuture (client .scripts .get_sql_runs , ( script_id , run_id ) ,
271+ polling_interval = polling_interval , api_key = api_key ,
272+ poll_on_creation = False )
274273 download = _download_callback (script_id , run_id , client , filename )
275- poll .add_done_callback (download )
274+ fut .add_done_callback (download )
276275 if archive :
277276
278277 def f (x ):
279278 return client .scripts .put_sql_archive (script_id , True )
280279
281- poll .add_done_callback (f )
280+ fut .add_done_callback (f )
282281
283- return poll
282+ return fut
284283
285284
286285def civis_to_multifile_csv (sql , database , job_name = None , api_key = None ,
287286 credential_id = None , include_header = True ,
288287 compression = 'none' , delimiter = '|' ,
289288 unquoted = False , prefix = None ,
290- polling_interval = _DEFAULT_POLLING_INTERVAL ,
291- hidden = True ):
289+ polling_interval = None , hidden = True ):
292290 """Unload the result of SQL query and return presigned urls.
293291
294292 This function is intended for unloading large queries/tables from redshift
@@ -372,11 +370,10 @@ def civis_to_multifile_csv(sql, database, job_name=None, api_key=None,
372370 credential_id , hidden ,
373371 csv_settings = csv_settings )
374372
375- poll = PollableResult (client .scripts .get_sql_runs ,
376- (script_id , run_id ),
377- polling_interval )
378- poll .result ()
379- outputs = client .scripts .get_sql_runs (script_id , run_id )["output" ]
373+ fut = CivisFuture (client .scripts .get_sql_runs , (script_id , run_id ),
374+ polling_interval = polling_interval , api_key = api_key ,
375+ poll_on_creation = False )
376+ outputs = fut .result ()["output" ]
380377 if not outputs :
381378 raise EmptyResultError ("Unload query {} returned no manifest."
382379 .format (script_id ))
@@ -394,7 +391,7 @@ def dataframe_to_civis(df, database, table, api_key=None,
394391 max_errors = None , existing_table_rows = "fail" ,
395392 distkey = None , sortkey1 = None , sortkey2 = None ,
396393 headers = None , credential_id = None ,
397- polling_interval = _DEFAULT_POLLING_INTERVAL ,
394+ polling_interval = None ,
398395 archive = False , hidden = True , ** kwargs ):
399396 """Upload a `pandas` `DataFrame` into a Civis table.
400397
@@ -442,16 +439,16 @@ def dataframe_to_civis(df, database, table, api_key=None,
442439
443440 Returns
444441 -------
445- poll : :class:`~civis.polling.PollableResult `
446- A `PollableResult ` object.
442+ fut : :class:`~civis.futures.CivisFuture `
443+ A `CivisFuture ` object.
447444
448445 Examples
449446 --------
450447 >>> import pandas as pd
451448 >>> df = pd.DataFrame({'a': [1, 2, 3], 'b': [4, 5, 6]})
452- >>> poller = civis.io.dataframe_to_civis(df, 'my-database',
453- ... 'scratch.df_table')
454- >>> poller .result()
449+ >>> fut = civis.io.dataframe_to_civis(df, 'my-database',
450+ ... 'scratch.df_table')
451+ >>> fut .result()
455452 """
456453 if archive :
457454 warnings .warn ("`archive` is deprecated and will be removed in v2.0.0. "
@@ -472,8 +469,7 @@ def csv_to_civis(filename, database, table, api_key=None,
472469 max_errors = None , existing_table_rows = "fail" ,
473470 distkey = None , sortkey1 = None , sortkey2 = None ,
474471 delimiter = "," , headers = None ,
475- credential_id = None ,
476- polling_interval = _DEFAULT_POLLING_INTERVAL ,
472+ credential_id = None , polling_interval = None ,
477473 archive = False , hidden = True ):
478474 """Upload the contents of a local CSV file to Civis.
479475
@@ -520,8 +516,8 @@ def csv_to_civis(filename, database, table, api_key=None,
520516
521517 Returns
522518 -------
523- results : :class:`~civis.polling.PollableResult `
524- A `PollableResult ` object.
519+ results : :class:`~civis.futures.CivisFuture `
520+ A `CivisFuture ` object.
525521
526522 Notes
527523 -----
@@ -531,20 +527,20 @@ def csv_to_civis(filename, database, table, api_key=None,
531527 --------
532528 >>> with open('input_file.csv', 'w') as _input:
533529 ... _input.write('a,b,c\\ n1,2,3')
534- >>> poller = civis.io.csv_to_civis('input_file.csv',
535- ... 'my-database',
536- ... 'scratch.my_data')
537- >>> poller .result()
530+ >>> fut = civis.io.csv_to_civis('input_file.csv',
531+ ... 'my-database',
532+ ... 'scratch.my_data')
533+ >>> fut .result()
538534 """
539535 if archive :
540536 warnings .warn ("`archive` is deprecated and will be removed in v2.0.0. "
541537 "Use `hidden` instead." , FutureWarning )
542538 with open (filename , "rb" ) as data :
543- poll = _import_bytes (data , database , table , api_key , max_errors ,
544- existing_table_rows , distkey , sortkey1 , sortkey2 ,
545- delimiter , headers , credential_id ,
546- polling_interval , archive , hidden = hidden )
547- return poll
539+ fut = _import_bytes (data , database , table , api_key , max_errors ,
540+ existing_table_rows , distkey , sortkey1 , sortkey2 ,
541+ delimiter , headers , credential_id ,
542+ polling_interval , archive , hidden = hidden )
543+ return fut
548544
549545
550546def _sql_script (client , sql , database , job_name , credential_id , hidden = False ,
@@ -615,13 +611,15 @@ def _import_bytes(buf, database, table, api_key, max_errors,
615611 run_job_result = client ._session .post (import_job .run_uri )
616612 run_job_result .raise_for_status ()
617613 run_info = run_job_result .json ()
618- poll = PollableResult (client .imports .get_files_runs ,
619- (run_info ['importId' ], run_info ['id' ]),
620- polling_interval = polling_interval )
614+ fut = CivisFuture (client .imports .get_files_runs ,
615+ (run_info ['importId' ], run_info ['id' ]),
616+ polling_interval = polling_interval ,
617+ api_key = api_key ,
618+ poll_on_creation = False )
621619 if archive :
622620
623621 def f (x ):
624622 return client .imports .put_archive (import_job .id , True )
625623
626- poll .add_done_callback (f )
627- return poll
624+ fut .add_done_callback (f )
625+ return fut
0 commit comments