-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#501 Fix Jdbc Native treating of nullable fields.
- Loading branch information
Showing
7 changed files
with
81 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,6 +64,8 @@ object RdbExampleTable { | |
| description VARCHAR NOT NULL, | ||
| email VARCHAR(50) NOT NULL, | ||
| founded DATE NOT NULL, | ||
| is_tax_free BOOLEAN, | ||
| tax_id BIGINT, | ||
| last_updated TIMESTAMP NOT NULL, | ||
| info_date VARCHAR(10) NOT NULL, | ||
| PRIMARY KEY (id)) | ||
|
@@ -75,10 +77,10 @@ object RdbExampleTable { | |
) | ||
|
||
val inserts: Seq[String] = Seq( | ||
s"INSERT INTO $tableName VALUES (1,'Company1', 'description1', '[email protected]', DATE '2000-10-11', TIMESTAMP '2020-11-04 10:11:00+02:00', '2022-02-18')", | ||
s"INSERT INTO $tableName VALUES (2,'Company2', 'description2', '[email protected]', DATE '2005-03-29', TIMESTAMP '2020-11-04 10:22:33+02:00', '2022-02-18')", | ||
s"INSERT INTO $tableName VALUES (3,'Company3', 'description3', '[email protected]', DATE '2016-12-30', TIMESTAMP '2020-11-04 10:33:59+02:00', '2022-02-18')", | ||
s"INSERT INTO $tableName VALUES (4,'Company4', 'description4', '[email protected]', DATE '2016-12-31', TIMESTAMP '2020-11-04 10:34:22+02:00', '2022-02-19')" | ||
s"INSERT INTO $tableName VALUES (1,'Company1', 'description1', '[email protected]', DATE '2000-10-11', FALSE, 123, TIMESTAMP '2020-11-04 10:11:00+02:00', '2022-02-18')", | ||
s"INSERT INTO $tableName VALUES (2,'Company2', 'description2', '[email protected]', DATE '2005-03-29', TRUE, 456, TIMESTAMP '2020-11-04 10:22:33+02:00', '2022-02-18')", | ||
s"INSERT INTO $tableName VALUES (3,'Company3', 'description3', '[email protected]', DATE '2016-12-30', FALSE, NULL, TIMESTAMP '2020-11-04 10:33:59+02:00', '2022-02-18')", | ||
s"INSERT INTO $tableName VALUES (4,'Company4', 'description4', '[email protected]', DATE '2016-12-31', NULL, NULL, TIMESTAMP '2020-11-04 10:34:22+02:00', '2022-02-19')" | ||
) | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -138,6 +138,16 @@ class JdbcNativeUtilsSuite extends AnyWordSpec with RelationalDbFixture with Spa | |
| "nullable" : true, | ||
| "metadata" : { } | ||
| }, { | ||
| "name" : "IS_TAX_FREE", | ||
| "type" : "boolean", | ||
| "nullable" : true, | ||
| "metadata" : { } | ||
| }, { | ||
| "name" : "TAX_ID", | ||
| "type" : "long", | ||
| "nullable" : true, | ||
| "metadata" : { } | ||
| }, { | ||
| "name" : "LAST_UPDATED", | ||
| "type" : "timestamp", | ||
| "nullable" : true, | ||
|
@@ -163,25 +173,30 @@ class JdbcNativeUtilsSuite extends AnyWordSpec with RelationalDbFixture with Spa | |
| "ID" : 1, | ||
| "NAME" : "Company1", | ||
| "EMAIL" : "[email protected]", | ||
| "FOUNDED" : "2000-10-11" | ||
| "FOUNDED" : "2000-10-11", | ||
| "IS_TAX_FREE" : false, | ||
| "TAX_ID" : 123 | ||
|}, { | ||
| "ID" : 2, | ||
| "NAME" : "Company2", | ||
| "EMAIL" : "[email protected]", | ||
| "FOUNDED" : "2005-03-29" | ||
| "FOUNDED" : "2005-03-29", | ||
| "IS_TAX_FREE" : true, | ||
| "TAX_ID" : 456 | ||
|}, { | ||
| "ID" : 3, | ||
| "NAME" : "Company3", | ||
| "EMAIL" : "[email protected]", | ||
| "FOUNDED" : "2016-12-30" | ||
| "FOUNDED" : "2016-12-30", | ||
| "IS_TAX_FREE" : false | ||
|}, { | ||
| "ID" : 4, | ||
| "NAME" : "Company4", | ||
| "EMAIL" : "[email protected]", | ||
| "FOUNDED" : "2016-12-31" | ||
|} ]""".stripMargin | ||
|
||
val df = JdbcNativeUtils.getJdbcNativeDataFrame(jdbcConfig, jdbcConfig.primaryUrl.get, s"SELECT id, name, email, founded FROM $tableName") | ||
val df = JdbcNativeUtils.getJdbcNativeDataFrame(jdbcConfig, jdbcConfig.primaryUrl.get, s"SELECT id, name, email, founded, is_tax_free, tax_id FROM $tableName") | ||
val actual = SparkUtils.convertDataFrameToPrettyJSON(df) | ||
|
||
compareText(actual, expected) | ||
|
@@ -236,35 +251,35 @@ class JdbcNativeUtilsSuite extends AnyWordSpec with RelationalDbFixture with Spa | |
} | ||
|
||
"getDecimalDataType" should { | ||
val resultSet = mock(classOf[ResultSet]) | ||
val resultSetMetaData = mock(classOf[ResultSetMetaData]) | ||
val resultSet = mock(classOf[ResultSet]) | ||
val resultSetMetaData = mock(classOf[ResultSetMetaData]) | ||
|
||
when(resultSetMetaData.getColumnCount).thenReturn(1) | ||
when(resultSet.getMetaData).thenReturn(resultSetMetaData) | ||
when(resultSetMetaData.getColumnCount).thenReturn(1) | ||
when(resultSet.getMetaData).thenReturn(resultSetMetaData) | ||
|
||
"return normal decimal for correct precision and scale" in { | ||
val iterator = new ResultSetToRowIterator(resultSet, true, incorrectDecimalsAsString = false) | ||
when(resultSetMetaData.getPrecision(0)).thenReturn(10) | ||
when(resultSetMetaData.getScale(0)).thenReturn(2) | ||
"return normal decimal for correct precision and scale" in { | ||
val iterator = new ResultSetToRowIterator(resultSet, true, incorrectDecimalsAsString = false) | ||
when(resultSetMetaData.getPrecision(0)).thenReturn(10) | ||
when(resultSetMetaData.getScale(0)).thenReturn(2) | ||
|
||
assert(iterator.getDecimalDataType(0) == NUMERIC) | ||
} | ||
assert(iterator.getDecimalDataType(0) == NUMERIC) | ||
} | ||
|
||
"return fixed decimal for incorrect precision and scale" in { | ||
val iterator = new ResultSetToRowIterator(resultSet, true, incorrectDecimalsAsString = false) | ||
when(resultSetMetaData.getPrecision(0)).thenReturn(0) | ||
when(resultSetMetaData.getScale(0)).thenReturn(2) | ||
"return fixed decimal for incorrect precision and scale" in { | ||
val iterator = new ResultSetToRowIterator(resultSet, true, incorrectDecimalsAsString = false) | ||
when(resultSetMetaData.getPrecision(0)).thenReturn(0) | ||
when(resultSetMetaData.getScale(0)).thenReturn(2) | ||
|
||
assert(iterator.getDecimalDataType(0) == NUMERIC) | ||
} | ||
assert(iterator.getDecimalDataType(0) == NUMERIC) | ||
} | ||
|
||
"return string type for incorrect precision and scale" in { | ||
val iterator = new ResultSetToRowIterator(resultSet, true, incorrectDecimalsAsString = true) | ||
when(resultSetMetaData.getPrecision(0)).thenReturn(0) | ||
when(resultSetMetaData.getScale(0)).thenReturn(2) | ||
"return string type for incorrect precision and scale" in { | ||
val iterator = new ResultSetToRowIterator(resultSet, true, incorrectDecimalsAsString = true) | ||
when(resultSetMetaData.getPrecision(0)).thenReturn(0) | ||
when(resultSetMetaData.getScale(0)).thenReturn(2) | ||
|
||
assert(iterator.getDecimalDataType(0) == VARCHAR) | ||
} | ||
assert(iterator.getDecimalDataType(0) == VARCHAR) | ||
} | ||
} | ||
|
||
"sanitizeDateTime" when { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters