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

DM-42257: Make the text type un-sized so length is not required #53

Merged
merged 5 commits into from
Apr 17, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions python/felis/db/_variants.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@
}

COLUMN_VARIANT_OVERRIDE = {
"mysql:datatype": "mysql",
"oracle:datatype": "oracle",
"postgresql:datatype": "postgresql",
"sqlite:datatype": "sqlite",
"mysql_datatype": "mysql",
"oracle_datatype": "oracle",
"postgresql_datatype": "postgresql",
"sqlite_datatype": "sqlite",
}

DIALECT_MODULES = {MYSQL: mysql, ORACLE: oracle, SQLITE: sqlite, POSTGRES: postgresql}
Expand Down Expand Up @@ -87,7 +87,7 @@ def make_variant_dict(column_obj: Column) -> dict[str, TypeEngine[Any]]:
"""
variant_dict = {}
for field_name, value in iter(column_obj):
if field_name in COLUMN_VARIANT_OVERRIDE:
if field_name in COLUMN_VARIANT_OVERRIDE and value is not None:
dialect = COLUMN_VARIANT_OVERRIDE[field_name]
variant: TypeEngine = process_variant_override(dialect, value)
variant_dict[dialect] = variant
Expand Down
6 changes: 3 additions & 3 deletions python/felis/db/sqltypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,9 @@ def unicode(length: builtins.int, **kwargs: Any) -> types.TypeEngine:
return _vary(types.NVARCHAR(length), unicode_map, kwargs, length)


def text(length: builtins.int, **kwargs: Any) -> types.TypeEngine:
def text(**kwargs: Any) -> types.TypeEngine:
"""Return SQLAlchemy type for text."""
return _vary(types.CLOB(length), text_map, kwargs, length)
return _vary(types.TEXT(), text_map, kwargs)


def binary(length: builtins.int, **kwargs: Any) -> types.TypeEngine:
Expand Down Expand Up @@ -198,7 +198,7 @@ def _vary(
variants.update(overrides)
for dialect, variant in variants.items():
# If this is a class and not an instance, instantiate
if isinstance(variant, type):
if callable(variant):
variant = variant(*args)
type_ = type_.with_variant(variant, dialect)
return type_
2 changes: 1 addition & 1 deletion python/felis/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class Unicode(FelisType, felis_name="unicode", votable_name="unicodeChar", is_si
"""Felis definition of unicode string type."""


class Text(FelisType, felis_name="text", votable_name="unicodeChar", is_sized=True):
class Text(FelisType, felis_name="text", votable_name="char"):
"""Felis definition of text type."""


Expand Down
2 changes: 0 additions & 2 deletions tests/data/sales.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ tables:
"@id": "#items.item_id"
datatype: int
description: Unique item identifier
mysql:datatype: INT
tap:principal: 1
- name: order_id
"@id": "#items.order_id"
datatype: int
Expand Down