Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[SPARK-26538][SQL] Set default precision and scale for elements of po…
…stgres numeric array
  • Loading branch information
a-shkarupin committed Jan 4, 2019
commit b004ee365f73195d62a9b1457bf67328cdfcce5d
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ private object PostgresDialect extends JdbcDialect {
case "bytea" => Some(BinaryType)
case "timestamp" | "timestamptz" | "time" | "timetz" => Some(TimestampType)
case "date" => Some(DateType)
case "numeric" | "decimal" => Some(DecimalType.bounded(precision, scale))
case "numeric" | "decimal" if precision != 0 => Some(DecimalType.bounded(precision, scale))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about

case "numeric" | "decimal" => if (precision > 0) {
    Some(DecimalType.bounded(precision, scale))
  } else {
    // Here a small comment explaining when this can happen and why we do this.
    Some(DecimalType. SYSTEM_DEFAULT)
  }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated per your suggestion.

case "numeric" | "decimal" => Some(DecimalType.SYSTEM_DEFAULT)
case _ => None
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -850,8 +850,11 @@ class JDBCSuite extends QueryTest

test("PostgresDialect type mapping") {
val Postgres = JdbcDialects.get("jdbc:postgresql://127.0.0.1/db")
val md = new MetadataBuilder().putLong("scale", 0)
assert(Postgres.getCatalystType(java.sql.Types.OTHER, "json", 1, null) === Some(StringType))
assert(Postgres.getCatalystType(java.sql.Types.OTHER, "jsonb", 1, null) === Some(StringType))
assert(Postgres.getCatalystType(java.sql.Types.ARRAY, "_numeric", 0, md) ==
Some(ArrayType(DecimalType.SYSTEM_DEFAULT)))
assert(Postgres.getJDBCType(FloatType).map(_.databaseTypeDefinition).get == "FLOAT4")
assert(Postgres.getJDBCType(DoubleType).map(_.databaseTypeDefinition).get == "FLOAT8")
val errMsg = intercept[IllegalArgumentException] {
Expand Down