File tree Expand file tree Collapse file tree 4 files changed +23
-7
lines changed
local_data_api/resources/jdbc Expand file tree Collapse file tree 4 files changed +23
-7
lines changed Original file line number Diff line number Diff line change 3636TIMESTAMP = [JDBCType .TIMESTAMP , JDBCType .TIMESTAMP_WITH_TIMEZONE ]
3737
3838
39+ def _fixed_to_datetime (rs : Any , col : Any ) -> Optional [str ]: # pragma: no cover
40+ """
41+ jaydebeapi has a bug that can't be parsed datetime correctly.
42+ This workaround will be removed when the PR is merged.
43+ https://github.com/baztian/jaydebeapi/pull/177
44+ """
45+ java_val = rs .getTimestamp (col )
46+ if not java_val :
47+ return None
48+ import datetime
49+
50+ d = datetime .datetime .strptime (str (java_val )[:19 ], "%Y-%m-%d %H:%M:%S" )
51+ d = d .replace (microsecond = int (str (java_val .getNanos ()).zfill (9 )[:6 ]))
52+ return str (d )
53+
54+
55+ jaydebeapi ._DEFAULT_CONVERTERS ['TIMESTAMP' ] = _fixed_to_datetime
56+
57+
3958def attach_thread_to_jvm () -> None :
4059 "https://github.com/baztian/jaydebeapi/issues/14#issuecomment-261489331"
4160
Original file line number Diff line number Diff line change 11from typing import Any , Optional
22
3- import jaydebeapi
43from sqlalchemy .dialects import mysql
54from sqlalchemy .engine import Dialect
65
76from local_data_api .models import Field
8- from local_data_api .resources .jdbc import JDBC
7+ from local_data_api .resources .jdbc import JDBC , jaydebeapi
98from local_data_api .resources .resource import register_resource_type
109
1110
Original file line number Diff line number Diff line change 11from typing import Any , Optional , Tuple
22
3- import jaydebeapi
4- from jpype import java
53from sqlalchemy .dialects import postgresql
64from sqlalchemy .engine import Dialect
75
86from local_data_api .models import Field
9- from local_data_api .resources .jdbc import JDBC
7+ from local_data_api .resources .jdbc import JDBC , jaydebeapi
108from local_data_api .resources .resource import register_resource_type
119
1210PG_TYPES : Tuple [str , ...] = (
Original file line number Diff line number Diff line change @@ -100,8 +100,8 @@ function test {
100100 --resource-arn $RDS_DATA_API_CLIENT_RESOURCE_ARN \
101101 --secret-arn $RDS_DATA_API_CLIENT_SECRETARN \
102102 --include-result-metadata \
103- --sql $' SELECT CAST(\' 2021-03-10 22:41:04.968123 +02\' AS TIMESTAMPTZ) AS value' \
104- | jq -e ' .records[0][0].stringValue == "2021-03-10 20:41:04.968 "'
103+ --sql $' SELECT CAST(\' 2021-03-10 22:41:04.068123 +02\' AS TIMESTAMPTZ) AS value' \
104+ | jq -e ' .records[0][0].stringValue == "2021-03-10 20:41:04.068 "'
105105 fi
106106
107107 if [ " $db " = " mysql" ]
You can’t perform that action at this time.
0 commit comments