-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-52837][CONNECT][PYTHON] Support TimeType in pyspark #51515
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
Changes from 1 commit
55a119d
2ad1338
f057a0c
7ef78dd
bd01205
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -80,6 +80,7 @@ | |
| "BinaryType", | ||
| "BooleanType", | ||
| "DateType", | ||
| "TimeType", | ||
| "TimestampType", | ||
| "TimestampNTZType", | ||
| "DecimalType", | ||
|
|
@@ -384,6 +385,33 @@ def fromInternal(self, v: int) -> datetime.date: | |
| return datetime.date.fromordinal(v + self.EPOCH_ORDINAL) | ||
|
|
||
|
|
||
| class TimeType(AtomicType): | ||
|
||
| """Time (datetime.time) data type.""" | ||
|
|
||
| def __init__(self, precision: int = 6): | ||
| self.precision = precision | ||
|
|
||
| def needConversion(self) -> bool: | ||
| return True | ||
|
|
||
| def toInternal(self, t: datetime.time) -> int: | ||
| if t is not None: | ||
| return ( | ||
| t.hour * 3_600_000_000_000 | ||
| + t.minute * 60_000_000_000 | ||
| + t.second * 1_000_000_000 | ||
| + t.microsecond * 1_000 | ||
| ) | ||
|
|
||
| def fromInternal(self, nano: int) -> datetime.time: | ||
| if nano is not None: | ||
| hours, remainder = divmod(nano, 3_600_000_000_000) | ||
| minutes, remainder = divmod(remainder, 60_000_000_000) | ||
| seconds, remainder = divmod(remainder, 1_000_000_000) | ||
| microseconds = remainder // 1_000 | ||
| return datetime.time(hours, minutes, seconds, microseconds) | ||
|
|
||
|
|
||
| class TimestampType(AtomicType, metaclass=DataTypeSingleton): | ||
| """Timestamp (datetime.datetime) data type.""" | ||
|
|
||
|
|
@@ -1846,6 +1874,7 @@ def parseJson(cls, json_str: str) -> "VariantVal": | |
| _FIXED_DECIMAL = re.compile(r"decimal\(\s*(\d+)\s*,\s*(-?\d+)\s*\)") | ||
| _INTERVAL_DAYTIME = re.compile(r"interval (day|hour|minute|second)( to (day|hour|minute|second))?") | ||
| _INTERVAL_YEARMONTH = re.compile(r"interval (year|month)( to (year|month))?") | ||
| _TIME = re.compile(r"time\(\s*(\d+)\s*\)") | ||
|
|
||
| _COLLATIONS_METADATA_KEY = "__COLLATIONS" | ||
|
|
||
|
|
@@ -1987,6 +2016,9 @@ def _parse_datatype_json_value( | |
| elif _FIXED_DECIMAL.match(json_value): | ||
| m = _FIXED_DECIMAL.match(json_value) | ||
| return DecimalType(int(m.group(1)), int(m.group(2))) # type: ignore[union-attr] | ||
| elif _TIME.match(json_value): | ||
| m = _TIME.match(json_value) | ||
| return TimeType(int(m.group(1))) # type: ignore[union-attr] | ||
| elif _INTERVAL_DAYTIME.match(json_value): | ||
| m = _INTERVAL_DAYTIME.match(json_value) | ||
| inverted_fields = DayTimeIntervalType._inverted_fields | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this test seems redundant.
Tests in
test_columnandtest_functionswill be reused on connect modeThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test file is mainly for directly comparing behavior between connect and classic