Skip to content

Commit 532dc3f

Browse files
committed
#240: Enhanced schema.column_type.ColumnType
1 parent 4768c78 commit 532dc3f

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

doc/changes/unreleased.md

+4
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@
33
## Documentation
44

55
* #283: Updated description and README
6+
7+
## Refactorings
8+
9+
* #240: Enhanced `schema.column_type.ColumnType`

exasol/analytics/schema/column_type.py

+15
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,29 @@ class SizeUnit(Enum):
2323
class ColumnType:
2424
name: str
2525
precision: Optional[int] = None
26+
"""For column types DECIMAL and INTEGER."""
2627
scale: Optional[int] = None
28+
"""For column types DECIMAL and INTEGER."""
2729
size: Optional[int] = None
30+
"""For column types CHAR and VARCHAR."""
2831
characterSet: Optional[str] = None
32+
"""For column types CHAR and VARCHAR. Supported values: "ASCII" and "UTF8"."""
2933
withLocalTimeZone: Optional[bool] = None
34+
"""Only for column type TIMESTAMP."""
3035
fraction: Optional[int] = None
36+
"""Number of fractional seconds for column type TIMESTAMP."""
3137
srid: Optional[int] = None
38+
"""Spatial reference system identifier, only for column type GEOMETRY."""
3239
unit: Optional[SizeUnit] = None
40+
"""Only for column type HASHTYPE. Supported values: "BYTE" and "BIT"."""
3341

3442
@property
3543
def rendered(self) -> str:
44+
"""
45+
Return a string representing the type including all parameters
46+
such as scale or precision appropriate for creating an SQL statement
47+
CREATE TABLE.
48+
"""
3649
name = self.name.upper()
3750

3851
def args() -> Iterator[Any]:
@@ -57,6 +70,8 @@ def elements() -> Iterator[str]:
5770
yield f"({infix})"
5871
if name == "VARCHAR":
5972
yield f' {self.characterSet or "UTF8"}'
73+
if (name == "TIMESTAMP") and self.withLocalTimeZone:
74+
yield " WITH LOCAL TIME ZONE"
6075

6176
return "".join(elements())
6277

tests/unit_tests/data_science_utils/schema/test_column_type.py

+2
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,8 @@ def test_hash_inequality_table():
242242
(ColumnType("DECIMAL", scale=2), "DECIMAL"),
243243
(ColumnType("TIMESTAMP"), "TIMESTAMP"),
244244
(ColumnType("TIMESTAMP", precision=2), "TIMESTAMP(2)"),
245+
(ColumnType("TIMESTAMP", precision=2, withLocalTimeZone=True),
246+
"TIMESTAMP(2) WITH LOCAL TIME ZONE"),
245247
(ColumnType("HASHTYPE"), "HASHTYPE(16 BYTE)"),
246248
(ColumnType("HASHTYPE", size=10), "HASHTYPE(16 BYTE)"),
247249
(ColumnType("HASHTYPE", unit=SizeUnit.BIT), "HASHTYPE(16 BYTE)"),

0 commit comments

Comments
 (0)