Skip to content

Commit

Permalink
Make JDBC Native connector close to Spark behavior by default.
Browse files Browse the repository at this point in the history
  • Loading branch information
yruslan committed Apr 26, 2024
1 parent 132ce9f commit 65265e2
Showing 2 changed files with 6 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -77,7 +77,7 @@ object JdbcConfig {
retries = ConfigUtils.getOptionInt(conf, JDBC_RETRIES),
connectionTimeoutSeconds = ConfigUtils.getOptionInt(conf, JDBC_CONNECTION_TIMEOUT),
sanitizeDateTime = ConfigUtils.getOptionBoolean(conf, JDBC_SANITIZE_DATETIME).getOrElse(true),
incorrectDecimalsAsString = ConfigUtils.getOptionBoolean(conf, JDBC_INCORRECT_PRECISION_AS_STRING).getOrElse(true),
incorrectDecimalsAsString = ConfigUtils.getOptionBoolean(conf, JDBC_INCORRECT_PRECISION_AS_STRING).getOrElse(false),
extraOptions = ConfigUtils.getExtraOptions(conf, JDBC_EXTRA_OPTIONS_PREFIX)
)
}
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@ import za.co.absa.pramen.core.samples.RdbExampleTable
import za.co.absa.pramen.core.utils.impl.ResultSetToRowIterator
import za.co.absa.pramen.core.utils.{JdbcNativeUtils, SparkUtils}

import java.math.BigDecimal
import java.sql.Types.{NUMERIC, VARCHAR}
import java.sql._
import java.time.{Instant, ZoneId}
import java.util.{Calendar, GregorianCalendar, TimeZone}
@@ -235,46 +235,37 @@ class JdbcNativeUtilsSuite extends AnyWordSpec with RelationalDbFixture with Spa
}
}

/* "getDecimalData" should {
"getDecimalDataType" should {
val resultSet = mock(classOf[ResultSet])
val resultSetMetaData = mock(classOf[ResultSetMetaData])

when(resultSetMetaData.getColumnCount).thenReturn(1)
when(resultSet.getMetaData).thenReturn(resultSetMetaData)
when(resultSet.getBigDecimal(0)).thenReturn(new BigDecimal(1.0))
when(resultSet.getString(0)).thenReturn("1")

"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)

val v = iterator.getDecimalData(0)
assert(v.isInstanceOf[BigDecimal])
assert(v.asInstanceOf[BigDecimal].toString == "1")
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)

val v = iterator.getDecimalData(0)
assert(v.isInstanceOf[BigDecimal])
assert(v.asInstanceOf[BigDecimal].toString == "1")
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)

val v = iterator.getDecimalData(0)
assert(v.isInstanceOf[String])
assert(v.asInstanceOf[String] == "1")
assert(iterator.getDecimalDataType(0) == VARCHAR)
}
}
*/

"sanitizeDateTime" when {
// Variable names come from PostgreSQL "constant field docs":

0 comments on commit 65265e2

Please sign in to comment.