Skip to content

Commit 8a4e55f

Browse files
author
Tommy Healy
committed
Rebase + fixes
1 parent 437ae35 commit 8a4e55f

9 files changed

Lines changed: 56 additions & 15 deletions

File tree

src/tinybird_sdk/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@
3232
"is_kafka_connection_definition": ("tinybird_sdk.schema", "is_kafka_connection_definition"),
3333
"is_s3_connection_definition": ("tinybird_sdk.schema", "is_s3_connection_definition"),
3434
"is_gcs_connection_definition": ("tinybird_sdk.schema", "is_gcs_connection_definition"),
35-
"is_dynamodb_connection_definition": ("tinybird_sdk.schema", "is_dynamodb_connection_definition"),
35+
"is_dynamodb_connection_definition": (
36+
"tinybird_sdk.schema",
37+
"is_dynamodb_connection_definition",
38+
),
3639
"secret": ("tinybird_sdk.schema", "secret"),
3740
"define_token": ("tinybird_sdk.schema", "define_token"),
3841
"is_token_definition": ("tinybird_sdk.schema", "is_token_definition"),

src/tinybird_sdk/generator/connection.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,13 @@ def generate_connection(connection: ConnectionDefinition) -> GeneratedConnection
9292
name=connection._name, content=_generate_s3_connection(connection)
9393
)
9494
if isinstance(connection, GCSConnectionDefinition):
95-
return GeneratedConnection(name=connection._name, content=_generate_gcs_connection(connection))
95+
return GeneratedConnection(
96+
name=connection._name, content=_generate_gcs_connection(connection)
97+
)
9698
if isinstance(connection, DynamoDBConnectionDefinition):
97-
return GeneratedConnection(name=connection._name, content=_generate_dynamodb_connection(connection))
99+
return GeneratedConnection(
100+
name=connection._name, content=_generate_dynamodb_connection(connection)
101+
)
98102
raise ValueError(f"Unsupported connection type: {connection._connectionType}")
99103

100104

src/tinybird_sdk/migrate/emit_ts.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,9 @@ def _emit_gcs_connection(connection: GCSConnectionModel) -> str:
348348
def _emit_dynamodb_connection(connection: DynamoDBConnectionModel) -> str:
349349
variable_name = to_snake_case(connection.name)
350350
lines: list[str] = []
351-
lines.append(f"{variable_name} = define_dynamodb_connection({_escape_string(connection.name)}, {{")
351+
lines.append(
352+
f"{variable_name} = define_dynamodb_connection({_escape_string(connection.name)}, {{"
353+
)
352354
lines.append(f" 'region': {_escape_string(connection.region)},")
353355
lines.append(f" 'arn': {_escape_string(connection.arn)},")
354356
lines.append("})")
@@ -357,7 +359,10 @@ def _emit_dynamodb_connection(connection: DynamoDBConnectionModel) -> str:
357359

358360

359361
def _emit_connection(
360-
connection: KafkaConnectionModel | S3ConnectionModel | GCSConnectionModel | DynamoDBConnectionModel,
362+
connection: KafkaConnectionModel
363+
| S3ConnectionModel
364+
| GCSConnectionModel
365+
| DynamoDBConnectionModel,
361366
) -> str:
362367
if isinstance(connection, S3ConnectionModel):
363368
return _emit_s3_connection(connection)

src/tinybird_sdk/migrate/parse_connection.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
from __future__ import annotations
22

3-
from .parser_utils import MigrationParseError, is_blank, parse_directive_line, parse_quoted_value, read_directive_block, split_lines
3+
from .parser_utils import (
4+
MigrationParseError,
5+
is_blank,
6+
parse_directive_line,
7+
parse_quoted_value,
8+
read_directive_block,
9+
split_lines,
10+
)
411
from .types import (
512
ConnectionModel,
613
DynamoDBConnectionModel,

src/tinybird_sdk/migrate/runner.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,9 @@ def run_migrate(options: MigrateOptions | dict[str, Any]) -> MigrationResult:
194194
)
195195

196196
if datasource.dynamodb:
197-
dynamodb_connection_type = parsed_connection_type_by_name.get(datasource.dynamodb.connection_name)
197+
dynamodb_connection_type = parsed_connection_type_by_name.get(
198+
datasource.dynamodb.connection_name
199+
)
198200
if dynamodb_connection_type != "dynamodb":
199201
errors.append(
200202
MigrationError(

src/tinybird_sdk/migrate/types.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,9 @@ class DynamoDBConnectionModel:
227227
arn: str
228228

229229

230-
ConnectionModel = KafkaConnectionModel | S3ConnectionModel | GCSConnectionModel | DynamoDBConnectionModel
230+
ConnectionModel = (
231+
KafkaConnectionModel | S3ConnectionModel | GCSConnectionModel | DynamoDBConnectionModel
232+
)
231233

232234
ParsedResource = (
233235
DatasourceModel

src/tinybird_sdk/schema/connection.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,10 @@ class DynamoDBConnectionDefinition:
8080

8181

8282
ConnectionDefinition = (
83-
KafkaConnectionDefinition | S3ConnectionDefinition | GCSConnectionDefinition | DynamoDBConnectionDefinition
83+
KafkaConnectionDefinition
84+
| S3ConnectionDefinition
85+
| GCSConnectionDefinition
86+
| DynamoDBConnectionDefinition
8487
)
8588

8689

@@ -133,7 +136,11 @@ def define_dynamodb_connection(
133136
name: str, options: dict[str, Any] | DynamoDBConnectionOptions
134137
) -> DynamoDBConnectionDefinition:
135138
_validate_connection_name(name)
136-
normalized = options if isinstance(options, DynamoDBConnectionOptions) else DynamoDBConnectionOptions(**options)
139+
normalized = (
140+
options
141+
if isinstance(options, DynamoDBConnectionOptions)
142+
else DynamoDBConnectionOptions(**options)
143+
)
137144

138145
if not normalized.region.strip():
139146
raise ValueError("DynamoDB connection `region` is required.")
@@ -147,7 +154,12 @@ def define_dynamodb_connection(
147154
def is_connection_definition(value: Any) -> bool:
148155
return isinstance(
149156
value,
150-
(KafkaConnectionDefinition, S3ConnectionDefinition, GCSConnectionDefinition, DynamoDBConnectionDefinition),
157+
(
158+
KafkaConnectionDefinition,
159+
S3ConnectionDefinition,
160+
GCSConnectionDefinition,
161+
DynamoDBConnectionDefinition,
162+
),
151163
)
152164

153165

src/tinybird_sdk/schema/datasource.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,9 @@ def define_datasource(
134134
gcs_cfg = options.get("gcs")
135135
gcs = GCSConfig(**gcs_cfg) if isinstance(gcs_cfg, dict) else gcs_cfg
136136
dynamodb_cfg = options.get("dynamodb")
137-
dynamodb = DynamoDBConfig(**dynamodb_cfg) if isinstance(dynamodb_cfg, dict) else dynamodb_cfg
137+
dynamodb = (
138+
DynamoDBConfig(**dynamodb_cfg) if isinstance(dynamodb_cfg, dict) else dynamodb_cfg
139+
)
138140
normalized = DatasourceOptions(
139141
description=options.get("description"),
140142
schema=options["schema"],
@@ -152,10 +154,14 @@ def define_datasource(
152154
)
153155

154156
ingestion_count = sum(
155-
1 for x in [normalized.kafka, normalized.s3, normalized.gcs, normalized.dynamodb] if x is not None
157+
1
158+
for x in [normalized.kafka, normalized.s3, normalized.gcs, normalized.dynamodb]
159+
if x is not None
156160
)
157161
if ingestion_count > 1:
158-
raise ValueError("Datasource can only define one ingestion option: `kafka`, `s3`, `gcs`, or `dynamodb`.")
162+
raise ValueError(
163+
"Datasource can only define one ingestion option: `kafka`, `s3`, `gcs`, or `dynamodb`."
164+
)
159165

160166
if normalized.backfill not in {None, "skip"}:
161167
raise ValueError('Invalid datasource backfill value: only "skip" is supported.')

tests/test_dynamodb_connector.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ def test_emit_ts_round_trip_for_dynamodb() -> None:
205205

206206
output = emit_migration_file_content([connection, datasource])
207207
assert "define_dynamodb_connection" in output
208-
assert "events_dynamodb = define_dynamodb_connection(\"events_dynamodb\"" in output
208+
assert 'events_dynamodb = define_dynamodb_connection("events_dynamodb"' in output
209209
assert "'dynamodb': {" in output
210210
assert "'table_arn': \"arn:aws:dynamodb:us-east-1:1:table/orders\"" in output
211211
assert "'export_bucket': \"s3://export\"" in output

0 commit comments

Comments
 (0)