Module API reference

Module contents

class raster_loader.BigQueryConnection(project, credentials: Optional[Credentials] = None)

Bases: DataWarehouseConnection

check_if_table_exists(fqn: str)
check_if_table_is_empty(fqn: str)
delete_bigquery_table(fqn: str)
execute(sql)

Execute a SQL query.

execute_to_dataframe(sql)

Execute a SQL query and return the result as a pandas dataframe. :param sql: SQL query to execute. :type sql: str

Returns

Result of the query.

Return type

pandas.DataFrame

get_labels(version: str)
get_metadata(fqn)

Get metadata from a table. :param fqn: Fully qualified name of the table. :type fqn: str

Returns

Metadata from the table.

Return type

dict

quote(q)

Quote a value. :param value: Value to quote. :type value: str

Returns

Quoted value.

Return type

str

quote_name(name)

Quote a table name. :param name: Name to quote. :type name: str

Returns

Quoted name.

Return type

str

update_labels(fqn, labels)
upload_raster(file_path: str, fqn: str, bands_info: List[Tuple[int, str]] = [(1, None)], chunk_size: Optional[int] = None, overwrite: bool = False, append: bool = False, cleanup_on_failure: bool = False, exact_stats: bool = False, basic_stats: bool = False, compress: bool = False, compression_level: int = 6)

Write a raster file to a BigQuery table.

upload_records(records: Iterable, fqn)
write_metadata(metadata, append_records, fqn)

Write metadata to a table. :param metadata: Metadata to write. :type metadata: dict :param append_records: Whether to update the metadata of an existing table or insert a new record. :type append_records: bool :param fqn: Fully qualified name of the table. :type fqn: str

Returns

True if the insertion was successful, False otherwise.

Return type

bool

class raster_loader.DatabricksConnection(server_hostname, access_token, cluster_id, parallelism=200)

Bases: DataWarehouseConnection

check_if_table_exists(fqn: str)
check_if_table_is_empty(fqn: str)
execute(query: str) list

Execute a SQL query and return results as a list of rows

execute_to_dataframe(query: str) DataFrame

Execute a SQL query and return results as a pandas DataFrame

get_metadata(fqn)

Get metadata from a table. :param fqn: Fully qualified name of the table. :type fqn: str

Returns

Metadata from the table.

Return type

dict

quote(q)

Quote a value. :param value: Value to quote. :type value: str

Returns

Quoted value.

Return type

str

quote_name(name)

Quote a table name with proper escaping for Databricks.

upload_raster(file_path: str, fqn: str, bands_info: Optional[List[Tuple[int, str]]] = None, chunk_size: Optional[int] = None, parallelism: int = 1000, overwrite: bool = False, append: bool = False, cleanup_on_failure: bool = False, exact_stats: bool = False, basic_stats: bool = False, compress: bool = False, compression_level: int = 6)

Write a raster file to a Databricks table.

upload_records(records: Iterable, fqn: str, overwrite: bool = False, parallelism: int = 1000)
wait_for_cluster()

Wait for the Databricks cluster to be ready.

write_metadata(metadata, append_records, fqn)

Write metadata to a table. :param metadata: Metadata to write. :type metadata: dict :param append_records: Whether to update the metadata of an existing table or insert a new record. :type append_records: bool :param fqn: Fully qualified name of the table. :type fqn: str

Returns

True if the insertion was successful, False otherwise.

Return type

bool

class raster_loader.SnowflakeConnection(username, password, account, database, schema, token, private_key_path, private_key_passphrase, role, warehouse)

Bases: DataWarehouseConnection

band_rename_function(band_name: str)
check_if_table_exists(fqn: str)
check_if_table_is_empty(fqn: str)
execute(sql)

Execute a SQL query.

execute_to_dataframe(sql)

Execute a SQL query and return the result as a pandas dataframe. :param sql: SQL query to execute. :type sql: str

Returns

Result of the query.

Return type

pandas.DataFrame

get_metadata(fqn: str)

Get metadata from a table. :param fqn: Fully qualified name of the table. :type fqn: str

Returns

Metadata from the table.

Return type

dict

upload_raster(file_path: str, fqn: str, bands_info: Optional[List[Tuple[int, str]]] = None, chunk_size: Optional[int] = None, overwrite: bool = False, append: bool = False, cleanup_on_failure: bool = False, exact_stats: bool = False, basic_stats: bool = False, compress: bool = False, compression_level: int = 6) bool

Write a raster file to a Snowflake table.

upload_records(records: Iterable, fqn: str, overwrite: bool)
write_metadata(metadata, append_records, fqn)

Write metadata to a table. :param metadata: Metadata to write. :type metadata: dict :param append_records: Whether to update the metadata of an existing table or insert a new record. :type append_records: bool :param fqn: Fully qualified name of the table. :type fqn: str

Returns

True if the insertion was successful, False otherwise.

Return type

bool