Skip to content

Spark 3.4: Decimal pushdown #247

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,21 @@ class ClickHouseDataTypeSuite extends SparkClickHouseSingleTest {
testDataType(dataType) { (db, tbl) =>
runClickHouseSQL(
s"""INSERT INTO $db.$tbl VALUES
|(1, '11.1')
|(1, '11.1'),
|(2, '22.2')
|""".stripMargin
)
} { df =>
assert(df.schema.length === 2)
assert(df.schema.fields(1).dataType === DecimalType(p, s))
checkAnswer(
df,
Row(1, BigDecimal("11.1", new MathContext(p))) :: Nil
Row(1, BigDecimal("11.1", new MathContext(p))) ::
Row(2, BigDecimal("22.2", new MathContext(p))) :: Nil
)
checkAnswer(
df.filter("value > 20"),
Row(2, BigDecimal("22.2", new MathContext(p))) :: Nil
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import org.apache.commons.lang3.StringUtils
import org.apache.spark.sql.connector.expressions.aggregate._
import org.apache.spark.sql.connector.expressions.NamedReference
import org.apache.spark.sql.sources._
import org.apache.spark.sql.types.DecimalType
import org.apache.spark.unsafe.types.UTF8String
import xenon.clickhouse.Utils._

Expand All @@ -38,6 +39,9 @@ trait SQLHelper {
case localDateTime: LocalDateTime => s"'${dateTimeFmt.format(localDateTime)}'"
case legacyDate: Date => s"'${legacyDateFmt.format(legacyDate)}'"
case localDate: LocalDate => s"'${dateFmt.format(localDate)}'"
case decimal: DecimalType if decimal.precision <= 9 => s"toDecimal32($value, ${decimal.scale})"
case decimal: DecimalType if decimal.precision <= 18 => s"toDecimal64($value, ${decimal.scale})"
case decimal: DecimalType => s"toDecimal128($value, ${decimal.scale})"
case array: Array[Any] => array.map(compileValue).mkString(",")
case _ => value
}
Expand Down