Skip to content

Commit

Permalink
Allow override for target table name (#17)
Browse files Browse the repository at this point in the history
* Fix

* Fix version
  • Loading branch information
BTheunissen authored Jul 31, 2023
1 parent 436511d commit e46e859
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "shaped-target-clickhouse"
version = "0.0.3"
version = "0.0.4"
description = "`target-clickhouse` is a Singer target for clickhouse, built with the Meltano Singer SDK."
readme = "README.md"
authors = ["Ben Theunissen"]
Expand Down
22 changes: 22 additions & 0 deletions target_clickhouse/sinks.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ def create_empty_table(
_ = partition_keys # Not supported in generic implementation.

_, _, table_name = self.parse_full_table_name(full_table_name)

# If config table name is set, then use it instead of the table name.
if self.config.get("table_name"):
table_name = self.config.get("table_name")

# Do not set schema, as it is not supported by Clickhouse.
meta = MetaData(schema=None, bind=self._engine)
columns: list[Column] = []
Expand Down Expand Up @@ -132,3 +137,20 @@ class ClickhouseSink(SQLSink):
"""clickhouse target sink class."""

connector_class = ClickhouseConnector

@property
def full_table_name(self) -> str:
"""Return the fully qualified table name.
Returns
The fully qualified table name.
"""
# Use the config table name if set.
if self.config.get("table_name"):
return self.config.get("table_name")

return self.connector.get_fully_qualified_name(
table_name=self.table_name,
schema_name=self.schema_name,
db_name=self.database_name,
)

0 comments on commit e46e859

Please sign in to comment.