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

destination-duckdb: fix formatting #36415

Merged
merged 1 commit into from
Mar 23, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,7 @@
import duckdb
from airbyte_cdk import AirbyteLogger
from airbyte_cdk.destinations import Destination
from airbyte_cdk.models import (
AirbyteConnectionStatus,
AirbyteMessage,
ConfiguredAirbyteCatalog,
DestinationSyncMode,
Status,
Type,
)
from airbyte_cdk.models import AirbyteConnectionStatus, AirbyteMessage, ConfiguredAirbyteCatalog, DestinationSyncMode, Status, Type

logger = getLogger("airbyte")

Expand All @@ -46,9 +39,7 @@ def _get_destination_path(destination_path: str) -> str:
Get a normalized version of the destination path.
Automatically append /local/ to the start of the path
"""
if destination_path.startswith("md:") or destination_path.startswith(
"motherduck:"
):
if destination_path.startswith("md:") or destination_path.startswith("motherduck:"):
return destination_path

if not destination_path.startswith("/local"):
Expand All @@ -57,8 +48,7 @@ def _get_destination_path(destination_path: str) -> str:
destination_path = os.path.normpath(destination_path)
if not destination_path.startswith("/local"):
raise ValueError(
f"destination_path={destination_path} is not a valid path."
"A valid path shall start with /local or no / prefix"
f"destination_path={destination_path} is not a valid path." "A valid path shall start with /local or no / prefix"
)

return destination_path
Expand Down Expand Up @@ -142,9 +132,7 @@ def write(
data = message.record.data
stream = message.record.stream
if stream not in streams:
logger.debug(
f"Stream {stream} was not present in configured streams, skipping"
)
logger.debug(f"Stream {stream} was not present in configured streams, skipping")
continue

# add to buffer
Expand All @@ -169,9 +157,7 @@ def write(
con.executemany(query, buffer[stream_name])
con.commit()

def check(
self, logger: AirbyteLogger, config: Mapping[str, Any]
) -> AirbyteConnectionStatus:
def check(self, logger: AirbyteLogger, config: Mapping[str, Any]) -> AirbyteConnectionStatus:
"""
Tests if the input configuration can be used to successfully connect to the destination with the needed permissions
e.g: if a provided API token or password can be used to connect and write to the destination.
Expand All @@ -193,9 +179,7 @@ def check(

duckdb_config = {}
if CONFIG_MOTHERDUCK_API_KEY in config:
duckdb_config["motherduck_token"] = str(
config[CONFIG_MOTHERDUCK_API_KEY]
)
duckdb_config["motherduck_token"] = str(config[CONFIG_MOTHERDUCK_API_KEY])
duckdb_config["custom_user_agent"] = "airbyte"

con = duckdb.connect(database=path, read_only=False, config=duckdb_config)
Expand All @@ -204,6 +188,4 @@ def check(
return AirbyteConnectionStatus(status=Status.SUCCEEDED)

except Exception as e:
return AirbyteConnectionStatus(
status=Status.FAILED, message=f"An exception occurred: {repr(e)}"
)
return AirbyteConnectionStatus(status=Status.FAILED, message=f"An exception occurred: {repr(e)}")
Loading