pytd.table.Table
- class pytd.table.Table(client: Client, database: str, table: str)[source]
A table controller module.
- Parameters:
client (
pytd.Client) – Treasure Data client.database (str) – Database name.
table (str) – Table name.
- client
Treasure Data client.
- Type:
- database
Database name.
- Type:
str
- table
Table name.
- Type:
str
Methods
__init__(client, database, table)create([column_names, column_types])Create a table named as configured.
delete()Delete a table from Treasure Data.
import_dataframe(dataframe, writer[, if_exists])Import a given DataFrame to a Treasure Data table.
Attributes
Check if a configured table exists.
- property exists: bool
Check if a configured table exists.
- Return type:
bool
- create(column_names: list[str] | None = None, column_types: list[str] | None = None) None[source]
Create a table named as configured.
When
column_namesandcolumn_typesare given, table is created by a Presto query with the specified schema.- Parameters:
column_names (list of str, optional) – Column names.
column_types (list of str, optional) – Column types corresponding to the names. Note that Treasure Data supports limited amount of types as documented in: https://api-docs.treasuredata.com/en/tools/presto/sql_tips_for_hive_and_presto#treasure-data-native-data-types
- import_dataframe(dataframe: DataFrame, writer: Literal['bulk_import', 'insert_into', 'spark'] | Writer, if_exists: Literal['error', 'overwrite', 'append', 'ignore'] = 'error', **kwargs: Any) None[source]
Import a given DataFrame to a Treasure Data table.
- Parameters:
dataframe (
pandas.DataFrame) – Data loaded to a target table.writer (string, {‘bulk_import’, ‘insert_into’, ‘spark’}, or
pytd.writer.Writer) – A Writer to choose writing method to Treasure Data. If string value, a temporal Writer instance will be created.if_exists (str, {'error', 'overwrite', 'append', 'ignore'}, default: 'error') –
What happens when a target table already exists.
error: raise an exception.
overwrite: drop it, recreate it, and insert data.
append: insert data. Create if does not exist.
ignore: do nothing.