Skip to content

Commit f3604a7

Browse files
authored
Fix null on jdbc (#93)
* Fix null on jdbc * Add unittest
1 parent 18a8d3f commit f3604a7

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

local_data_api/resources/jdbc/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ def get_filed_from_jdbc_type(self, value: Any, jdbc_type: Optional[int]) -> Fiel
105105
except ValueError:
106106
pass
107107
if type_:
108-
if type_ in LONG:
108+
if value is None:
109+
return Field(isNull=True)
110+
elif type_ in LONG:
109111
return Field(longValue=value)
110112
elif type_ in DOUBLE:
111113
return Field(doubleValue=value)

scripts/integration-test.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,15 @@ function test {
102102
--include-result-metadata \
103103
--sql $'SELECT CAST(\'2021-03-10 22:41:04.068123+02\' AS TIMESTAMPTZ) AS value' \
104104
| jq -e '.records[0][0].stringValue == "2021-03-10 20:41:04.068"'
105+
106+
aws rds-data execute-statement \
107+
--endpoint-url 'http://localhost:8080' \
108+
--database 'test' \
109+
--resource-arn $RDS_DATA_API_CLIENT_RESOURCE_ARN \
110+
--secret-arn $RDS_DATA_API_CLIENT_SECRETARN \
111+
--include-result-metadata \
112+
--sql $'SELECT CAST(null AS TIMESTAMPTZ) AS value' \
113+
| jq -e '.records[0][0].isNull == true'
105114
fi
106115

107116
if [ "$db" = "mysql" ]
@@ -114,6 +123,16 @@ function test {
114123
--include-result-metadata \
115124
--sql $'SELECT CAST(\'2021-03-10 22:41:04.968123\' AS DATETIME) AS value' \
116125
| jq -e '.records[0][0].stringValue == "2021-03-10 22:41:05"'
126+
127+
aws rds-data execute-statement \
128+
--endpoint-url 'http://localhost:8080' \
129+
--database 'test' \
130+
--resource-arn $RDS_DATA_API_CLIENT_RESOURCE_ARN \
131+
--secret-arn $RDS_DATA_API_CLIENT_SECRETARN \
132+
--include-result-metadata \
133+
--sql $'SELECT CAST(null AS DATETIME) AS value' \
134+
| jq -e '.records[0][0].isNull == true'
135+
117136
fi
118137

119138
# TODO list, JSON, enum

tests/test_resource/test_jdbc/test_jdbc.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,11 @@ def test_create_connection_maker_error(mocker):
175175
JDBCType.TIMESTAMP,
176176
{'stringValue': '2021-03-10 22:41:04.968'},
177177
),
178+
(
179+
None,
180+
JDBCType.TIMESTAMP,
181+
{'isNull': True},
182+
),
178183
],
179184
)
180185
def test_get_filed_from_jdbc_type(value, jdbc_type, expected):

0 commit comments

Comments
 (0)