Skip to content

Commit

Permalink
#398 Fix decimal auto-correctness for Hive JDBC source.
Browse files Browse the repository at this point in the history
  • Loading branch information
yruslan committed Dec 9, 2024
1 parent fe130d3 commit 423c46b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import za.co.absa.pramen.api.Query
import za.co.absa.pramen.api.offset.OffsetValue
import za.co.absa.pramen.core.config.Keys
import za.co.absa.pramen.core.reader.model.TableReaderJdbcConfig
import za.co.absa.pramen.core.utils.{ConfigUtils, JdbcNativeUtils, JdbcSparkUtils, TimeUtils}
import za.co.absa.pramen.core.utils._

import java.time.{Instant, LocalDate}
import scala.annotation.tailrec
Expand Down Expand Up @@ -198,6 +198,10 @@ class TableReaderJdbc(jdbcReaderConfig: TableReaderJdbcConfig,
.load()

if (jdbcReaderConfig.correctDecimalsInSchema || jdbcReaderConfig.correctDecimalsFixPrecision) {
if (isDataQuery) {
df = SparkUtils.sanitizeDfColumns(df, jdbcReaderConfig.specialCharacters)
}

JdbcSparkUtils.getCorrectedDecimalsSchema(df, jdbcReaderConfig.correctDecimalsFixPrecision).foreach(schema =>
df = spark
.read
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import org.slf4j.LoggerFactory
import za.co.absa.pramen.api.offset.OffsetInfo
import za.co.absa.pramen.api.sql.{QuotingPolicy, SqlColumnType}
import za.co.absa.pramen.core.config.Keys
import za.co.absa.pramen.core.config.Keys.SPECIAL_CHARACTERS_IN_COLUMN_NAMES
import za.co.absa.pramen.core.utils.ConfigUtils

import java.time.ZoneId
Expand All @@ -38,6 +39,7 @@ case class TableReaderJdbcConfig(
correctDecimalsFixPrecision: Boolean = false,
enableSchemaMetadata: Boolean = false,
useJdbcNative: Boolean = false,
specialCharacters: String = " ",
serverTimeZone: ZoneId = ZoneId.systemDefault(),
identifierQuotingPolicy: QuotingPolicy = QuotingPolicy.Auto,
sqlGeneratorClass: Option[String] = None
Expand Down Expand Up @@ -98,6 +100,8 @@ object TableReaderJdbcConfig {
.map(s => QuotingPolicy.fromString(s))
.getOrElse(QuotingPolicy.Auto)

val specialCharacters = ConfigUtils.getOptionString(workflowConf, SPECIAL_CHARACTERS_IN_COLUMN_NAMES).getOrElse(" ")

TableReaderJdbcConfig(
jdbcConfig = JdbcConfig.load(conf, parent),
hasInfoDate = conf.getBoolean(HAS_INFO_DATE),
Expand All @@ -111,6 +115,7 @@ object TableReaderJdbcConfig {
correctDecimalsFixPrecision = ConfigUtils.getOptionBoolean(conf, CORRECT_DECIMALS_FIX_PRECISION).getOrElse(false),
enableSchemaMetadata = ConfigUtils.getOptionBoolean(conf, ENABLE_SCHEMA_METADATA_KEY).getOrElse(false),
useJdbcNative = ConfigUtils.getOptionBoolean(conf, USE_JDBC_NATIVE).getOrElse(false),
specialCharacters,
serverTimezone,
identifierQuotingPolicy = identifierQuotingPolicy,
sqlGeneratorClass = ConfigUtils.getOptionString(conf, SQL_GENERATOR_CLASS_KEY)
Expand Down

0 comments on commit 423c46b

Please sign in to comment.