civis.io.civis_file_to_table

civis.io.civis_file_to_table(file_id, database, table, client=None, max_errors=None, existing_table_rows='fail', diststyle=None, distkey=None, sortkey1=None, sortkey2=None, table_columns=None, primary_keys=None, last_modified_keys=None, escaped=False, execution='immediate', delimiter=None, headers=None, credential_id=None, polling_interval=None, hidden=True)[source]
Upload the contents of one or more Civis files to a Civis table.
All provided files will be loaded as an atomic unit in parallel, and should share the same columns in the same order, and be in the same format.
Parameters:
file_id : int or list[int]

Civis file ID or a list of Civis file IDs.

database : str or int

Upload data into this database. Can be the database name or ID.

table : str

The schema and table you want to upload to. E.g., 'scratch.table'.

client : civis.APIClient, optional

If not provided, an civis.APIClient object will be created from the CIVIS_API_KEY.

max_errors : int, optional

The maximum number of rows with errors to remove from the import before failing. If multiple files are provided, this limit applies across all files combined.

existing_table_rows : str, optional

The behaviour if a table with the requested name already exists. One of 'fail', 'truncate', 'append', 'drop', or 'upsert'. Defaults to 'fail'.

diststyle : str, optional

The distribution style for the table. One of 'even', 'all' or 'key'.

distkey : str, optional

The column to use as the distkey for the table.

sortkey1 : str, optional

The column to use as the sortkey for the table.

sortkey2 : str, optional

The second column in a compound sortkey for the table.

table_columns : list[Dict[str, str]], optional

A list of dictionaries corresponding to the columns in the source file. Each dictionary should have keys for column “name” and “sqlType”. The import will only copy these columns regardless if there are more columns in the table.

primary_keys: list[str], optional

A list of the primary key column(s) of the destination table that uniquely identify a record. These columns must not contain null values. If existing_table_rows is “upsert”, this field is required. Note that this is true regardless of whether the destination database itself requires a primary key.

last_modified_keys: list[str], optional

A list of the columns indicating a record has been updated. If existing_table_rows is “upsert”, this field is required.

escaped: bool, optional

A boolean value indicating whether or not the source file(s) escape quotes with a backslash. Defaults to false.

execution: string, optional, default “immediate”

One of “delayed” or “immediate”. If “immediate”, refresh column statistics as part of the run. If “delayed”, flag the table for a deferred statistics update; column statistics may not be available for up to 24 hours. In addition, if existing_table_rows is “upsert”, delayed executions move data from staging table to final table after a brief delay, in order to accommodate multiple concurrent imports to the same destination table.

delimiter : string, optional

The column delimiter. One of ',', '\t' or '|'. If not provided, will attempt to auto-detect.

headers : bool, optional

Whether or not the first row of the file should be treated as headers. The default, None, attempts to autodetect whether or not the first row contains headers.

credential_id : str or int, optional

The ID of the database credential. If None, the default credential will be used.

polling_interval : int or float, optional

Number of seconds to wait between checks for job completion.

hidden : bool, optional

If True (the default), this job will not appear in the Civis UI.

Returns:
results : CivisFuture

A CivisFuture object.

Raises:
CivisImportError

If multiple files are given and determined to be incompatible for import. This may be the case if their columns have different types, their delimiters are different, headers are present in some but not others, or compressions do not match.

Examples

>>> file_id = 100
>>> fut = civis.io.civis_file_to_table(file_id,
...                                    'my-database',
...                                    'scratch.my_data')
>>> fut.result()