Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

athena iceberg #659

Merged
merged 38 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
0e25102
first iceberg prototype
sh-rp Sep 28, 2023
26f9e41
fix linting and clearing of staging tables
sh-rp Sep 28, 2023
e199bd1
disable tests
sh-rp Sep 28, 2023
b768a63
enable iceberg tests for athena
sh-rp Sep 29, 2023
119ad6e
Merge branch 'devel' into d#/athena-iceberg
sh-rp Oct 4, 2023
29a6d06
fix iceberg detection
sh-rp Oct 4, 2023
439c72f
move athena tests to default sql configs
sh-rp Oct 4, 2023
b964388
finally fix regular athena tests...
sh-rp Oct 4, 2023
2b5f004
some more work
sh-rp Oct 4, 2023
7e82de7
fix replace disposition
sh-rp Oct 5, 2023
202466f
fix datatype support
sh-rp Oct 5, 2023
bd9744c
fix append for merge in iceberg
sh-rp Oct 5, 2023
f627a0f
fix merge jobs for iceberg
sh-rp Oct 5, 2023
9a94d4a
clean up followup jobs code
sh-rp Oct 5, 2023
8682350
set iceberg tests to merge supported
sh-rp Oct 5, 2023
1560768
fix sql merge syntax for iceberg
sh-rp Oct 6, 2023
3f4fb1e
separate regular athena and iceberg tests
sh-rp Oct 6, 2023
92613ec
remove some iceberg specific code
sh-rp Oct 9, 2023
0924bc5
new iceberg approach
sh-rp Oct 9, 2023
122d035
PR changes
sh-rp Oct 11, 2023
7750318
small changes
sh-rp Oct 11, 2023
0deecda
small changes
sh-rp Oct 11, 2023
702fd4b
fix two tests
sh-rp Oct 11, 2023
d70985d
add missing athena fixes
sh-rp Oct 11, 2023
95adc93
Merge branch 'devel' into d#/athena-iceberg
sh-rp Oct 11, 2023
06dbaeb
small changes
sh-rp Oct 12, 2023
baa5e44
fixes
sh-rp Oct 12, 2023
ad8dc9b
update
sh-rp Oct 12, 2023
00e474c
fix some tests
sh-rp Oct 13, 2023
acfcd16
small changes
sh-rp Oct 13, 2023
0707629
small changes
sh-rp Oct 13, 2023
4692e37
make type mapper table format sensitive
sh-rp Oct 14, 2023
10131e4
disable dbt tests for athena iceberg
sh-rp Oct 14, 2023
243246e
update doc
sh-rp Oct 14, 2023
ba0c593
small fix
sh-rp Oct 14, 2023
1e8605c
pr changes
sh-rp Oct 16, 2023
78fc17a
updates athena dbt docs
rudolfix Oct 16, 2023
918c4d5
adds docsting on table format to decorators
rudolfix Oct 16, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions dlt/common/destination/reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from dlt.common.schema import Schema, TTableSchema, TSchemaTables
from dlt.common.schema.typing import TWriteDisposition
from dlt.common.schema.exceptions import InvalidDatasetName
from dlt.common.schema.utils import get_load_table
from dlt.common.configuration import configspec
from dlt.common.configuration.specs import BaseConfiguration, CredentialsConfiguration
from dlt.common.configuration.accessors import config
Expand Down Expand Up @@ -244,9 +245,8 @@ def restore_file_load(self, file_path: str) -> LoadJob:
"""Finds and restores already started loading job identified by `file_path` if destination supports it."""
pass

def get_truncate_destination_table_dispositions(self) -> List[TWriteDisposition]:
# in the base job, all replace strategies are treated the same, see filesystem for example
return ["replace"]
def table_needs_truncating(self, table: TTableSchema) -> bool:
return table["write_disposition"] == "replace"

def create_table_chain_completed_followup_jobs(self, table_chain: Sequence[TTableSchema]) -> List[NewLoadJob]:
"""Creates a list of followup jobs that should be executed after a table chain is completed"""
Expand Down Expand Up @@ -309,9 +309,8 @@ class WithStagingDataset(ABC):
"""Adds capability to use staging dataset and request it from the loader"""

@abstractmethod
def get_stage_dispositions(self) -> List[TWriteDisposition]:
"""Returns a list of write dispositions that require staging dataset"""
return []
def table_needs_staging(self, table: TTableSchema) -> bool:
return False

@abstractmethod
def with_staging_dataset(self)-> ContextManager["JobClientBase"]:
Expand Down
5 changes: 5 additions & 0 deletions dlt/common/schema/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,8 @@ def __init__(self, schema_name: str, init_engine: int, from_engine: int, to_engi
self.from_engine = from_engine
self.to_engine = to_engine
super().__init__(f"No engine upgrade path in schema {schema_name} from {init_engine} to {to_engine}, stopped at {from_engine}")

class UnknownTableException(SchemaException):
def __init__(self, table_name: str) -> None:
self.table_name = table_name
super().__init__(f"Trying to access unknown table {table_name}.")
2 changes: 2 additions & 0 deletions dlt/common/schema/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
TColumnHint = Literal["not_null", "partition", "cluster", "primary_key", "foreign_key", "sort", "unique", "root_key", "merge_key"]
"""Known hints of a column used to declare hint regexes."""
TWriteDisposition = Literal["skip", "append", "replace", "merge"]
TTableFormat = Literal["iceberg"]
TTypeDetections = Literal["timestamp", "iso_timestamp", "large_integer", "hexbytes_to_text", "wei_to_double"]
TTypeDetectionFunc = Callable[[Type[Any], Any], Optional[TDataType]]
TColumnNames = Union[str, Sequence[str]]
Expand Down Expand Up @@ -86,6 +87,7 @@ class TTableSchema(TypedDict, total=False):
filters: Optional[TRowFilters]
columns: TTableSchemaColumns
resource: Optional[str]
table_format: Optional[TTableFormat]


class TPartialTableSchema(TTableSchema):
Expand Down
46 changes: 36 additions & 10 deletions dlt/common/schema/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
from dlt.common.validation import TCustomValidator, validate_dict, validate_dict_ignoring_xkeys
from dlt.common.schema import detections
from dlt.common.schema.typing import (COLUMN_HINTS, SCHEMA_ENGINE_VERSION, LOADS_TABLE_NAME, SIMPLE_REGEX_PREFIX, VERSION_TABLE_NAME, TColumnName, TPartialTableSchema, TSchemaTables, TSchemaUpdate,
TSimpleRegex, TStoredSchema, TTableSchema, TTableSchemaColumns, TColumnSchemaBase, TColumnSchema, TColumnProp,
TSimpleRegex, TStoredSchema, TTableSchema, TTableSchemaColumns, TColumnSchemaBase, TColumnSchema, TColumnProp, TTableFormat,
TColumnHint, TTypeDetectionFunc, TTypeDetections, TWriteDisposition)
from dlt.common.schema.exceptions import (CannotCoerceColumnException, ParentTableNotFoundException, SchemaEngineNoUpgradePathException, SchemaException,
TablePropertiesConflictException, InvalidSchemaName)
TablePropertiesConflictException, InvalidSchemaName, UnknownTableException)

from dlt.common.normalizers.utils import import_normalizers
from dlt.common.schema.typing import TAnySchemaColumns
Expand Down Expand Up @@ -493,18 +493,29 @@ def merge_schema_updates(schema_updates: Sequence[TSchemaUpdate]) -> TSchemaTabl
return aggregated_update


def get_write_disposition(tables: TSchemaTables, table_name: str) -> TWriteDisposition:
"""Returns write disposition of a table if present. If not, looks up into parent table"""
def get_inherited_table_hint(tables: TSchemaTables, table_name: str, table_hint_name: str, allow_none: bool = False) -> Any:
table = tables[table_name]
w_d = table.get("write_disposition")
if w_d:
return w_d
hint = table.get(table_hint_name)
if hint:
return hint

parent = table.get("parent")
if parent:
return get_write_disposition(tables, parent)
return get_inherited_table_hint(tables, parent, table_hint_name, allow_none)

if allow_none:
return None

raise ValueError(f"No table hint '{table_hint_name} found in the chain of tables for '{table_name}'.")


def get_write_disposition(tables: TSchemaTables, table_name: str) -> TWriteDisposition:
"""Returns table hint of a table if present. If not, looks up into parent table"""
return get_inherited_table_hint(tables, table_name, "write_disposition", allow_none=False)


raise ValueError(f"No write disposition found in the chain of tables for '{table_name}'.")
def get_table_format(tables: TSchemaTables, table_name: str) -> TTableFormat:
return get_inherited_table_hint(tables, table_name, "table_format", allow_none=True)


def table_schema_has_type(table: TTableSchema, _typ: TDataType) -> bool:
Expand All @@ -525,6 +536,18 @@ def get_top_level_table(tables: TSchemaTables, table_name: str) -> TTableSchema:
return get_top_level_table(tables, parent)
return table

def get_load_table(tables: TSchemaTables, table_name: str) -> TTableSchema:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be IMO part of JobClient

try:
# make a copy of the schema so modifications do not affect the original document
table = copy(tables[table_name])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we'll need a deepcopy because we will modify columns

# add write disposition if not specified - in child tables
if "write_disposition" not in table:
table["write_disposition"] = get_write_disposition(tables, table_name)
if "table_format" not in table:
table["table_format"] = get_table_format(tables, table_name)
return table
except KeyError:
raise UnknownTableException(table_name)

def get_child_tables(tables: TSchemaTables, table_name: str) -> List[TTableSchema]:
"""Get child tables for table name and return a list of tables ordered by ancestry so the child tables are always after their parents"""
Expand Down Expand Up @@ -637,7 +660,8 @@ def new_table(
write_disposition: TWriteDisposition = None,
columns: Sequence[TColumnSchema] = None,
validate_schema: bool = False,
resource: str = None
resource: str = None,
table_format: TTableFormat = None
) -> TTableSchema:

table: TTableSchema = {
Expand All @@ -652,6 +676,8 @@ def new_table(
# set write disposition only for root tables
table["write_disposition"] = write_disposition or DEFAULT_WRITE_DISPOSITION
table["resource"] = resource or table_name
if table_format:
table["table_format"] = table_format
if validate_schema:
validate_dict_ignoring_xkeys(
spec=TColumnSchema,
Expand Down
5 changes: 4 additions & 1 deletion dlt/common/storages/load_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,11 @@ def list_failed_jobs(self, load_id: str) -> Sequence[str]:
return self.storage.list_folder_files(self._get_job_folder_path(load_id, LoadStorage.FAILED_JOBS_FOLDER))

def list_jobs_for_table(self, load_id: str, table_name: str) -> Sequence[LoadJobInfo]:
return [job for job in self.list_all_jobs(load_id) if job.job_file_info.table_name == table_name]

def list_all_jobs(self, load_id: str) -> Sequence[LoadJobInfo]:
info = self.get_load_package_info(load_id)
return [job for job in flatten_list_or_items(iter(info.jobs.values())) if job.job_file_info.table_name == table_name] # type: ignore
return [job for job in flatten_list_or_items(iter(info.jobs.values()))] # type: ignore

def list_completed_failed_jobs(self, load_id: str) -> Sequence[str]:
return self.storage.list_folder_files(self._get_job_folder_completed_path(load_id, LoadStorage.FAILED_JOBS_FOLDER))
Expand Down
1 change: 1 addition & 0 deletions dlt/destinations/athena/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def capabilities() -> DestinationCapabilitiesContext:
caps.alter_add_multi_column = True
caps.schema_supports_numeric_precision = False
caps.timestamp_precision = 3
caps.supports_truncate_command = False
return caps


Expand Down
62 changes: 48 additions & 14 deletions dlt/destinations/athena/athena.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@
from dlt.common.utils import without_none
from dlt.common.data_types import TDataType
from dlt.common.schema import TColumnSchema, Schema
from dlt.common.schema.typing import TTableSchema, TColumnType
from dlt.common.schema.utils import table_schema_has_type
from dlt.common.schema.typing import TTableSchema, TColumnType, TWriteDisposition
from dlt.common.schema.utils import table_schema_has_type, get_table_format
from dlt.common.destination import DestinationCapabilitiesContext
from dlt.common.destination.reference import LoadJob
from dlt.common.destination.reference import TLoadJobState
from dlt.common.destination.reference import LoadJob, FollowupJob
from dlt.common.destination.reference import TLoadJobState, NewLoadJob
from dlt.common.storages import FileStorage
from dlt.common.data_writers.escape import escape_bigquery_identifier

from dlt.destinations.sql_jobs import SqlStagingCopyJob

from dlt.destinations.typing import DBApi, DBTransaction
from dlt.destinations.exceptions import DatabaseTerminalException, DatabaseTransientException, DatabaseUndefinedRelation, LoadJobTerminalException
from dlt.destinations.athena import capabilities
from dlt.destinations.sql_client import SqlClientBase, DBApiCursorImpl, raise_database_error, raise_open_connection_error
from dlt.destinations.typing import DBApiCursor
from dlt.destinations.job_client_impl import SqlJobClientBase, StorageSchemaInfo
from dlt.destinations.job_client_impl import SqlJobClientWithStaging
from dlt.destinations.athena.configuration import AthenaClientConfiguration
from dlt.destinations.type_mapping import TypeMapper
from dlt.destinations import path_utils
Expand Down Expand Up @@ -69,13 +69,18 @@ class AthenaTypeMapper(TypeMapper):
"int": "bigint",
}

def __init__(self, capabilities: DestinationCapabilitiesContext, iceberg_mode: bool):
super().__init__(capabilities)
self.iceberg_mode = iceberg_mode
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think we need iceberg_mode you just set it up per table


def to_db_integer_type(self, precision: Optional[int]) -> str:
if precision is None:
return "bigint"
# iceberg does not support smallint and tinyint
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: TIMESTAMP is precision 6 on iceberg, 3 on parquet

if precision <= 8:
return "tinyint"
return "int" if self.iceberg_mode else "tinyint"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's why JobClient should create/modify table schema. so you can modify precision there and do not hack the type mapper...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be the cleanest to have a subclass for iceberg and then set that before the table sql is generated? I don't feel like changing the type mapper is hacking at all, that is what it is there for, changing the mapping of the types depending on database / table format you are storing into.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually we could extend the type mapper to have the info which table_format is currently being processed. that might be nice?

elif precision <= 16:
return "smallint"
return "int" if self.iceberg_mode else "smallint"
elif precision <= 32:
return "int"
return "bigint"
Expand Down Expand Up @@ -135,6 +140,11 @@ def exception(self) -> str:
# this part of code should be never reached
raise NotImplementedError()

class DoNothingFollowupJob(DoNothingJob, FollowupJob):
"""The second most lazy class of dlt"""
pass


class AthenaSQLClient(SqlClientBase[Connection]):

capabilities: ClassVar[DestinationCapabilitiesContext] = capabilities()
Expand Down Expand Up @@ -276,7 +286,7 @@ def has_dataset(self) -> bool:
return len(rows) > 0


class AthenaClient(SqlJobClientBase):
class AthenaClient(SqlJobClientWithStaging):

capabilities: ClassVar[DestinationCapabilitiesContext] = capabilities()

Expand All @@ -293,11 +303,12 @@ def __init__(self, schema: Schema, config: AthenaClientConfiguration) -> None:
super().__init__(schema, config, sql_client)
self.sql_client: AthenaSQLClient = sql_client # type: ignore
self.config: AthenaClientConfiguration = config
self.type_mapper = AthenaTypeMapper(self.capabilities)
self.type_mapper = AthenaTypeMapper(self.capabilities, True)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some tables are iceberg, some not. you can't set always True here, see below


def initialize_storage(self, truncate_tables: Iterable[str] = None) -> None:
# never truncate tables in athena
super().initialize_storage([])
# only truncate tables in iceberg mode
truncate_tables = []
super().initialize_storage(truncate_tables)

def _from_db_type(self, hive_t: str, precision: Optional[int], scale: Optional[int]) -> TColumnType:
return self.type_mapper.from_db_type(hive_t, precision, scale)
Expand All @@ -309,15 +320,18 @@ def _get_table_update_sql(self, table_name: str, new_columns: Sequence[TColumnSc

bucket = self.config.staging_config.bucket_url
dataset = self.sql_client.dataset_name

sql: List[str] = []

# for the system tables we need to create empty iceberg tables to be able to run, DELETE and UPDATE queries
is_iceberg = self.schema.tables[table_name].get("write_disposition", None) == "skip"
# or if we are in iceberg mode, we create iceberg tables for all tables
is_iceberg = (self.schema.tables[table_name].get("write_disposition", None) == "skip") or (self._is_iceberg_table(self.schema.tables[table_name]) and not self.in_staging_mode)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this "in staging mode" is still here unfortunately.. i don't know how to do it any other way.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you move the get_load_table to JobClient you can modify table format to keep iceberg (destination dataset) or not (staging dataset). OFC you need to pass is_staging flag to the method. I do not like it but probably it is a good compromise

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as discussed: use get_load_table() to

  • adjust the precision
  • set the table format
    and pass it to the code below

columns = ", ".join([self._get_column_def_sql(c) for c in new_columns])

# this will fail if the table prefix is not properly defined
table_prefix = self.table_prefix_layout.format(table_name=table_name)
location = f"{bucket}/{dataset}/{table_prefix}"

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one thing (maybe helpful) when we create parquet file we are setting precision of various fields ie datetime. make sure we do not have problems here (probably you should take into account both capabilities and table format but I think our current implementation is good - I hope it works)

# use qualified table names
qualified_table_name = self.sql_client.make_qualified_ddl_table_name(table_name)
if is_iceberg and not generate_alter:
Expand Down Expand Up @@ -345,9 +359,29 @@ def start_file_load(self, table: TTableSchema, file_path: str, load_id: str) ->
)
job = super().start_file_load(table, file_path, load_id)
if not job:
job = DoNothingJob(file_path)
job = DoNothingFollowupJob(file_path) if self._is_iceberg_table(table) else DoNothingJob(file_path)
return job

def _create_append_followup_jobs(self, table_chain: Sequence[TTableSchema]) -> List[NewLoadJob]:
if self._is_iceberg_table(table_chain[0]):
return [SqlStagingCopyJob.from_table_chain(table_chain, self.sql_client, {"replace": False})]
return super()._create_append_followup_jobs(table_chain)

def _create_replace_followup_jobs(self, table_chain: Sequence[TTableSchema]) -> List[NewLoadJob]:
if self._is_iceberg_table(table_chain[0]):
return [SqlStagingCopyJob.from_table_chain(table_chain, self.sql_client, {"replace": True})]
return super()._create_replace_followup_jobs(table_chain)

def _is_iceberg_table(self, table: TTableSchema) -> bool:
table_format = get_table_format(self.schema.tables, table["name"])
return table_format == "iceberg"

def table_needs_staging(self, table: TTableSchema) -> bool:
# all iceberg tables need staging
if self._is_iceberg_table(table):
return True
return super().table_needs_staging(table)

@staticmethod
def is_dbapi_exception(ex: Exception) -> bool:
return isinstance(ex, Error)
1 change: 1 addition & 0 deletions dlt/destinations/athena/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class AthenaClientConfiguration(DestinationClientDwhWithStagingConfiguration):
credentials: AwsCredentials = None
athena_work_group: Optional[str] = None
aws_data_catalog: Optional[str] = "awsdatacatalog"
supports_truncate_command: bool = False

__config_gen_annotations__: ClassVar[List[str]] = ["athena_work_group"]

Expand Down
19 changes: 11 additions & 8 deletions dlt/destinations/bigquery/bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
from dlt.common.storages.file_storage import FileStorage
from dlt.common.schema import TColumnSchema, Schema, TTableSchemaColumns
from dlt.common.schema.typing import TTableSchema, TColumnType
from dlt.common.schema.exceptions import UnknownTableException

from dlt.destinations.job_client_impl import SqlJobClientWithStaging
from dlt.destinations.exceptions import DestinationSchemaWillNotUpdate, DestinationTransientException, LoadJobNotExistsException, LoadJobTerminalException, LoadJobUnknownTableException
from dlt.destinations.exceptions import DestinationSchemaWillNotUpdate, DestinationTransientException, LoadJobNotExistsException, LoadJobTerminalException

from dlt.destinations.bigquery import capabilities
from dlt.destinations.bigquery.configuration import BigQueryClientConfiguration
from dlt.destinations.bigquery.sql_client import BigQuerySqlClient, BQ_TERMINAL_REASONS
from dlt.destinations.sql_jobs import SqlMergeJob, SqlStagingCopyJob
from dlt.destinations.sql_jobs import SqlMergeJob, SqlStagingCopyJob, SqlJobParams
from dlt.destinations.job_impl import NewReferenceJob
from dlt.destinations.sql_client import SqlClientBase
from dlt.destinations.type_mapping import TypeMapper
Expand Down Expand Up @@ -138,7 +139,7 @@ def gen_key_table_clauses(cls, root_table_name: str, staging_root_table_name: st
class BigqueryStagingCopyJob(SqlStagingCopyJob):

@classmethod
def generate_sql(cls, table_chain: Sequence[TTableSchema], sql_client: SqlClientBase[Any]) -> List[str]:
def generate_sql(cls, table_chain: Sequence[TTableSchema], sql_client: SqlClientBase[Any], params: Optional[SqlJobParams] = None) -> List[str]:
sql: List[str] = []
for table in table_chain:
with sql_client.with_staging_dataset(staging=True):
Expand Down Expand Up @@ -167,11 +168,13 @@ def __init__(self, schema: Schema, config: BigQueryClientConfiguration) -> None:
self.sql_client: BigQuerySqlClient = sql_client # type: ignore
self.type_mapper = BigQueryTypeMapper(self.capabilities)

def _create_merge_job(self, table_chain: Sequence[TTableSchema]) -> NewLoadJob:
return BigQueryMergeJob.from_table_chain(table_chain, self.sql_client)
def _create_merge_followup_jobs(self, table_chain: Sequence[TTableSchema]) -> List[NewLoadJob]:
return [BigQueryMergeJob.from_table_chain(table_chain, self.sql_client)]

def _create_optimized_replace_job(self, table_chain: Sequence[TTableSchema]) -> NewLoadJob:
return BigqueryStagingCopyJob.from_table_chain(table_chain, self.sql_client)
def _create_replace_followup_jobs(self, table_chain: Sequence[TTableSchema]) -> List[NewLoadJob]:
if self.config.replace_strategy == "staging-optimized":
return [BigqueryStagingCopyJob.from_table_chain(table_chain, self.sql_client)]
return super()._create_replace_followup_jobs(table_chain)

def restore_file_load(self, file_path: str) -> LoadJob:
"""Returns a completed SqlLoadJob or restored BigQueryLoadJob
Expand Down Expand Up @@ -218,7 +221,7 @@ def start_file_load(self, table: TTableSchema, file_path: str, load_id: str) ->
reason = BigQuerySqlClient._get_reason_from_errors(gace)
if reason == "notFound":
# google.api_core.exceptions.NotFound: 404 - table not found
raise LoadJobUnknownTableException(table["name"], file_path)
raise UnknownTableException(table["name"])
elif reason == "duplicate":
# google.api_core.exceptions.Conflict: 409 PUT - already exists
return self.restore_file_load(file_path)
Expand Down
6 changes: 0 additions & 6 deletions dlt/destinations/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,6 @@ def __init__(self, file_path: str, message: str) -> None:
super().__init__(f"Job with id/file name {file_path} encountered unrecoverable problem: {message}")


class LoadJobUnknownTableException(DestinationTerminalException):
def __init__(self, table_name: str, file_name: str) -> None:
self.table_name = table_name
super().__init__(f"Client does not know table {table_name} for load file {file_name}")


class LoadJobInvalidStateTransitionException(DestinationTerminalException):
def __init__(self, from_state: TLoadJobState, to_state: TLoadJobState) -> None:
self.from_state = from_state
Expand Down
Loading
Loading