Note: these functions are aliased and can be called directly from the dbio module, e.g. dbio.replicate().
Import data from a csv file to a database table.
param sqla_url: SQLAlchemy url string to pass to create_engine(). param table: Table in database to load data from filename. param filename: Name of csv file to load from. param append: If True, any data already in the table will be preserved. param analyze: If True, the table will be will be analyzed for query optimization immediately after importing. param disable_indices: If True, table will temporarily disable or drop indices for the duration of the load in the attempt of speeding up the operation. param csv_params: Dictionary of csv parameters. param null_string: String to represent null values with. param create_staging: If True, the old table will be replaced with a new, identical table. If False, there must be an existing table named “table_staging”. param expected_rowcount: The number of rows that are expected to be in the loaded table. If the count does not much, the loading transaction will raise an error and rollback if possible. If the count is set to None, no check will be made. Kwargs:
direct (string): For Vertica. Will apply DIRECT keywprd to COPY command to skip WOS
Query a database and write the results to a csv file.
Parameters: |
|
---|---|
Returns: | The number of rows written to the file. |
Load query results into a table using a named pipe to stream the data.
This method works by simultaneously executing query() and load() with a named pipe shared between the two processes.
Unix only.
param query_db_url: SQLAlchemy engine creation URL for query_db. param load_db_url: SQLAlchemy engine creation URL for load_db. param query: SQL query string to execute. param table: Table in database to load data from filename. param append: If True, any data already in the table will be preserved. param analyze: If True, the table will be will be analyzed for query optimization immediately after importing. param disable_indices: If True, table will temporarily disable or drop indices for the duration of the load in the attempt of speeding up the operation. param query_is_file: If True, the query argument is a filename. param create_staging: If True, the old table will be replaced with a new, identical table. If False, there must be an existing table named “table_staging”. param do_rowcount_check: If True, the replication will only succeed if the query rowcount matches the load rowcount. Kwargs:
direct (string): For Vertica. Will apply DIRECT keywprd to COPY command to skip WOS
raises ReaderError: Reader process did not execute successfully. raises WriterError: Writer process did not execute successfully.
Identitcal to replicate(), but uses a tempfile and disk I/O instead of a named pipe. This method works on any platform and doesn’t require the database to support loading from named pipes.
To add support for an additional database, extend at least one of the following classes.
Designed to be the target of query operations.
Returns: | sqlalchemy engine object. |
---|
Gets a row count for the given query.
Parameters: | query – The query to get the row count for. |
---|---|
Returns: | The row count for the provided query. |
Designed to be the target of load operations.
Checks if the given table has the expected row count.
Parameters: |
|
---|---|
Raises: | UnexpectedRowcountError upon row count mismatch |
Database specific implementation of loading from a CSV
Parameters: |
|
---|
Returns: | sqlalchemy engine object. |
---|