|
12 | 12 |
|
13 | 13 | using namespace kuzu::common; |
14 | 14 |
|
| 15 | +#define PyDateTimeTZ_FromDateAndTime(year, month, day, hour, min, sec, usec, timezone) \ |
| 16 | + PyDateTimeAPI->DateTime_FromDateAndTime(year, month, day, hour, \ |
| 17 | + min, sec, usec, timezone, PyDateTimeAPI->DateTimeType) |
| 18 | + |
15 | 19 | void PyQueryResult::initialize(py::handle& m) { |
16 | 20 | py::class_<PyQueryResult>(m, "result") |
17 | 21 | .def("hasNext", &PyQueryResult::hasNext) |
@@ -67,6 +71,17 @@ void PyQueryResult::close() { |
67 | 71 | queryResult.reset(); |
68 | 72 | } |
69 | 73 |
|
| 74 | +static py::object converTimestampToPyObject(timestamp_t& timestamp) { |
| 75 | + int32_t year, month, day, hour, min, sec, micros; |
| 76 | + date_t date; |
| 77 | + dtime_t time; |
| 78 | + Timestamp::convert(timestamp, date, time); |
| 79 | + Date::convert(date, year, month, day); |
| 80 | + Time::Convert(time, hour, min, sec, micros); |
| 81 | + return py::cast<py::object>( |
| 82 | + PyDateTime_FromDateAndTime(year, month, day, hour, min, sec, micros)); |
| 83 | +} |
| 84 | + |
70 | 85 | py::object PyQueryResult::convertValueToPyObject(const Value& value) { |
71 | 86 | if (value.isNull()) { |
72 | 87 | return py::none(); |
@@ -130,14 +145,31 @@ py::object PyQueryResult::convertValueToPyObject(const Value& value) { |
130 | 145 | } |
131 | 146 | case LogicalTypeID::TIMESTAMP: { |
132 | 147 | auto timestampVal = value.getValue<timestamp_t>(); |
| 148 | + return converTimestampToPyObject(timestampVal); |
| 149 | + } |
| 150 | + case LogicalTypeID::TIMESTAMP_TZ: { |
| 151 | + auto timestampVal = value.getValue<timestamp_tz_t>(); |
133 | 152 | int32_t year, month, day, hour, min, sec, micros; |
134 | 153 | date_t date; |
135 | 154 | dtime_t time; |
136 | 155 | Timestamp::convert(timestampVal, date, time); |
137 | 156 | Date::convert(date, year, month, day); |
138 | 157 | Time::Convert(time, hour, min, sec, micros); |
139 | | - return py::cast<py::object>( |
140 | | - PyDateTime_FromDateAndTime(year, month, day, hour, min, sec, micros)); |
| 158 | + |
| 159 | + return py::cast<py::object>(PyDateTimeTZ_FromDateAndTime(year, month, day, hour, min, sec, |
| 160 | + micros, PyDateTime_TimeZone_UTC)); |
| 161 | + } |
| 162 | + case LogicalTypeID::TIMESTAMP_NS: { |
| 163 | + timestamp_t timestampVal = Timestamp::fromEpochNanoSeconds(value.getValue<timestamp_ns_t>().value); |
| 164 | + return converTimestampToPyObject(timestampVal); |
| 165 | + } |
| 166 | + case LogicalTypeID::TIMESTAMP_MS: { |
| 167 | + timestamp_t timestampVal = Timestamp::fromEpochMilliSeconds(value.getValue<timestamp_ms_t>().value); |
| 168 | + return converTimestampToPyObject(timestampVal); |
| 169 | + } |
| 170 | + case LogicalTypeID::TIMESTAMP_SEC: { |
| 171 | + timestamp_t timestampVal = Timestamp::fromEpochSeconds(value.getValue<timestamp_sec_t>().value); |
| 172 | + return converTimestampToPyObject(timestampVal); |
141 | 173 | } |
142 | 174 | case LogicalTypeID::INTERVAL: { |
143 | 175 | auto intervalVal = value.getValue<interval_t>(); |
|
0 commit comments