Skip to content

Commit

Permalink
Add container_type field to TColumnSchema
Browse files Browse the repository at this point in the history
  • Loading branch information
Sultan Iman committed Jan 22, 2024
1 parent 4d4a54a commit ae2471e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions dlt/common/libs/pydantic.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ def pydantic_to_table_schema_columns(
# try to coerce unknown type to text
data_type = "text"

# This is when we have List[BaseModel]
# We need to access first argument
# to extract type hint to extract schema
if data_type == "complex" and inner_type == list:
args = get_args(annotation)
# If it is just a generic List annotation
Expand All @@ -140,9 +143,12 @@ def pydantic_to_table_schema_columns(
"nullable": nullable,
"container_type": list
}
continue

# if not is_inner_type_pydantic_model and data_type == "complex" and skip_complex_types:
# continue

# This case is for a single field schema/model
elif is_inner_type_pydantic_model:
schema_hints = pydantic_to_table_schema_columns(field.annotation)

Expand Down
2 changes: 2 additions & 0 deletions dlt/common/schema/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
Optional,
Sequence,
Set,
Tuple,
Type,
TypedDict,
NewType,
Expand Down Expand Up @@ -111,6 +112,7 @@ class TColumnSchema(TColumnSchemaBase, total=False):
root_key: Optional[bool]
merge_key: Optional[bool]
variant: Optional[bool]
container_type: Optional[Union[List, Tuple]]


TTableSchemaColumns = Dict[str, TColumnSchema]
Expand Down
6 changes: 6 additions & 0 deletions dlt/extract/hints.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,12 @@ def new_table_template(
clean_columns = columns
if columns is not None:
clean_columns = ensure_table_schema_columns_hint(columns)
# TODO: extract all schema items with container_type set
# and and create tables
for column_name, column_schema in clean_columns.items():
if column_schema.get("container_type") is not None:
clean_columns.pop(column_name)

if not callable(clean_columns):
clean_columns = clean_columns.values() # type: ignore
# create a table schema template where hints can be functions taking TDataItem
Expand Down

0 comments on commit ae2471e

Please sign in to comment.