Skip to content
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
15 changes: 11 additions & 4 deletions splitgraph/cloud/project/generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,15 @@ def get_comment(jsonschema_object: Any) -> str:
return ". ".join(result).strip()


_SCALARS = ("string", "integer", "boolean")


def jsonschema_object_to_example(obj: Any, type_override=None) -> Any:
"""
Get an example value for a JSONSchema property
"""
obj_type = type_override or obj["type"]
if obj_type in ("string", "integer", "boolean"):
if obj_type in _SCALARS:
if "examples" in obj:
return obj["examples"][0]
elif "default" in obj:
Expand All @@ -59,12 +62,16 @@ def jsonschema_object_to_example(obj: Any, type_override=None) -> Any:
else:
return {"string": "", "integer": 0, "boolean": False}.get(obj_type)
elif obj_type == "array":
example = jsonschema_object_to_example(obj["items"])
seq = CS([example])
# For simple lists of scalars, don't drill down and just return an empty list
if obj["items"]["type"] in _SCALARS:
seq = CS([])
else:
example = jsonschema_object_to_example(obj["items"])
seq = CS([example])
comment = get_comment(obj["items"])
if comment:
seq.yaml_set_start_comment(comment)
return [example]
return seq
elif obj_type == "object":
if "properties" in obj:
return _get_object_example(obj)
Expand Down
5 changes: 5 additions & 0 deletions splitgraph/hooks/data_source/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ def load(self, repository: "Repository", tables: Optional[TableInfo] = None) ->
schema=tmp_schema,
)
add_timestamp_tags(repository, image_hash)
except BaseException:
repository.rollback_engines()
repository.images.delete([image_hash])
repository.commit_engines()
raise
finally:
repository.object_engine.delete_schema(tmp_schema)
repository.commit_engines()
Expand Down
4 changes: 2 additions & 2 deletions splitgraph/ingestion/airbyte/data_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ class AirbyteDataSource(SyncableDataSource, ABC):
table_params_schema = {
"type": "object",
"properties": {
"airbyte_cursor_fields": {
"airbyte_cursor_field": {
"type": "array",
"title": "Cursor field(s)",
"description": "Fields in this stream to be used as a cursor "
"for incremental replication (overrides Airbyte configuration's cursor_field)",
"items": {"type": "string"},
},
"airbyte_primary_key_fields": {
"airbyte_primary_key_field": {
"type": "array",
"title": "Primary key field(s)",
"description": "Fields in this stream to be used as a primary key for deduplication "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,8 @@ repositories:
sample_table:
# Plugin-specific table parameters matching the plugin's schema
options:
airbyte_cursor_fields: # Cursor field(s). Fields in this stream to be used as a cursor for incremental replication (overrides Airbyte configuration's cursor_field)
- ''
airbyte_primary_key_fields: # Primary key field(s). Fields in this stream to be used as a primary key for deduplication (overrides Airbyte configuration's primary_key)
- ''
airbyte_cursor_fields: [] # Cursor field(s). Fields in this stream to be used as a cursor for incremental replication (overrides Airbyte configuration's cursor_field)
airbyte_primary_key_fields: [] # Primary key field(s). Fields in this stream to be used as a primary key for deduplication (overrides Airbyte configuration's primary_key)
# Schema of the table, a list of objects with `name` and `type`. If set to `[]`, will infer.
schema: []
# Whether live querying is enabled for the plugin (creates a "live" tag in the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,8 @@ repositories:
sample_table:
# Plugin-specific table parameters matching the plugin's schema
options:
airbyte_cursor_fields: # Cursor field(s). Fields in this stream to be used as a cursor for incremental replication (overrides Airbyte configuration's cursor_field)
- ''
airbyte_primary_key_fields: # Primary key field(s). Fields in this stream to be used as a primary key for deduplication (overrides Airbyte configuration's primary_key)
- ''
airbyte_cursor_fields: [] # Cursor field(s). Fields in this stream to be used as a cursor for incremental replication (overrides Airbyte configuration's cursor_field)
airbyte_primary_key_fields: [] # Primary key field(s). Fields in this stream to be used as a primary key for deduplication (overrides Airbyte configuration's primary_key)
# Schema of the table, a list of objects with `name` and `type`. If set to `[]`, will infer.
schema: []
# Whether live querying is enabled for the plugin (creates a "live" tag in the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,8 @@ repositories:
sample_table:
# Plugin-specific table parameters matching the plugin's schema
options:
airbyte_cursor_fields: # Cursor field(s). Fields in this stream to be used as a cursor for incremental replication (overrides Airbyte configuration's cursor_field)
- ''
airbyte_primary_key_fields: # Primary key field(s). Fields in this stream to be used as a primary key for deduplication (overrides Airbyte configuration's primary_key)
- ''
airbyte_cursor_fields: [] # Cursor field(s). Fields in this stream to be used as a cursor for incremental replication (overrides Airbyte configuration's cursor_field)
airbyte_primary_key_fields: [] # Primary key field(s). Fields in this stream to be used as a primary key for deduplication (overrides Airbyte configuration's primary_key)
# Schema of the table, a list of objects with `name` and `type`. If set to `[]`, will infer.
schema: []
# Whether live querying is enabled for the plugin (creates a "live" tag in the
Expand Down