Skip to content

Commit d9f26b4

Browse files
committed
Spark 3.4: Decimal pushdown
1 parent 0b12f1c commit d9f26b4

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

spark-3.4/clickhouse-spark-it/src/test/scala/org/apache/spark/sql/clickhouse/single/ClickHouseDataTypeSuite.scala

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,15 +159,21 @@ class ClickHouseDataTypeSuite extends SparkClickHouseSingleTest {
159159
testDataType(dataType) { (db, tbl) =>
160160
runClickHouseSQL(
161161
s"""INSERT INTO $db.$tbl VALUES
162-
|(1, '11.1')
162+
|(1, '11.1'),
163+
|(2, '22.2')
163164
|""".stripMargin
164165
)
165166
} { df =>
166167
assert(df.schema.length === 2)
167168
assert(df.schema.fields(1).dataType === DecimalType(p, s))
168169
checkAnswer(
169170
df,
170-
Row(1, BigDecimal("11.1", new MathContext(p))) :: Nil
171+
Row(1, BigDecimal("11.1", new MathContext(p))) ::
172+
Row(2, BigDecimal("22.2", new MathContext(p))) :: Nil
173+
)
174+
checkAnswer(
175+
df.filter("value > 20"),
176+
Row(2, BigDecimal("22.2", new MathContext(p))) :: Nil
171177
)
172178
}
173179
}

spark-3.4/clickhouse-spark/src/main/scala/xenon/clickhouse/SQLHelper.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import org.apache.commons.lang3.StringUtils
2020
import org.apache.spark.sql.connector.expressions.aggregate._
2121
import org.apache.spark.sql.connector.expressions.NamedReference
2222
import org.apache.spark.sql.sources._
23+
import org.apache.spark.sql.types.DecimalType
2324
import org.apache.spark.unsafe.types.UTF8String
2425
import xenon.clickhouse.Utils._
2526

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

0 commit comments

Comments
 (0)