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

fix: Additional logging for failures related to Table creation, and Column altering #129

Merged
merged 1 commit into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
41 changes: 36 additions & 5 deletions target_snowflake/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,15 @@ def prepare_column(
if '"' in formatter.format_collation(column_name):
column_name = column_name.upper()

super().prepare_column(
full_table_name,
column_name,
sql_type,
)
try:
super().prepare_column(
full_table_name,
column_name,
sql_type,
)
except Exception as e:
self.logger.error(f"Error preparing column for {full_table_name=} {column_name=}")
raise e

@staticmethod
def get_column_rename_ddl(
Expand Down Expand Up @@ -558,3 +562,30 @@ def get_initialize_script(role, user, password, warehouse, database):
commit;

"""

def _adapt_column_type(
self,
full_table_name: str,
column_name: str,
sql_type: sqlalchemy.types.TypeEngine,
) -> None:
"""Adapt table column type to support the new JSON schema type.

Args:
full_table_name: The target table name.
column_name: The target column name.
sql_type: The new SQLAlchemy type.

Raises:
NotImplementedError: if altering columns is not supported.
"""

try:
super()._adapt_column_type(full_table_name, column_name, sql_type)
except Exception as e:
current_type: sqlalchemy.types.TypeEngine = self._get_column_type(
full_table_name,
column_name,
)
self.logger.error(f"Error adapting column type for {full_table_name=} {column_name=}, {current_type=} {sql_type=} (new sql type)")
raise e
17 changes: 11 additions & 6 deletions target_snowflake/sinks.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,17 @@ def setup(self) -> None:
object_type="schema"
),
)
self.connector.prepare_table(
full_table_name=self.full_table_name,
schema=self.conform_schema(self.schema),
primary_keys=self.key_properties,
as_temp_table=False,
)
try:
self.connector.prepare_table(
full_table_name=self.full_table_name,
schema=self.conform_schema(self.schema),
primary_keys=self.key_properties,
as_temp_table=False,
)
except Exception as e:
self.logger.error(f"Error creating {self.full_table_name=} {self.conform_schema(self.schema)=}")
raise e


def conform_name(
self,
Expand Down
Loading