zhongyujiang commented on code in PR #5531:
URL: https://github.com/apache/paimon/pull/5531#discussion_r2062623356
##########
paimon-spark/paimon-spark-common/src/main/scala/org/apache/paimon/spark/catalog/functions/PaimonFunctions.scala:
##########
@@ -98,6 +102,32 @@ class BucketFunction extends UnboundFunction {
override def name: String = BUCKET
}
+object BucketFunction {
+ private val SPARK_TIMESTAMP_PRECISION = 6
+
+ def supportsTable(table: FileStoreTable): Boolean = {
+ table.bucketMode match {
+ case BucketMode.HASH_FIXED =>
+
table.schema().logicalBucketKeyType().getFieldTypes.asScala.forall(supportsType)
+ case _ => false
+ }
+ }
+
+ private def supportsType(t: PaimonDataType): Boolean = t match {
+ case arrayType: ArrayType =>
+ supportsType(arrayType.getElementType)
+ case mapType: MapType =>
+ supportsType(mapType.getKeyType) && supportsType(mapType.getValueType)
+ case rowType: RowType =>
+ rowType.getFieldTypes.asScala.forall(supportsType)
+ case timestamp: TimestampType =>
Review Comment:
I think this is necessary. Because Spark only supports microsecond-precision
Timestamps (precision 6). When the precision in a Paimon table is not 6, it
will still be converted to Spark’s microsecond timestamp type. However, when
calling the Paimon bucket function, we cannot access the schema of the Paimon
table, so we can only support Paimon timestamps with a precision of 6.
##########
paimon-spark/paimon-spark-common/src/main/scala/org/apache/paimon/spark/catalog/functions/PaimonFunctions.scala:
##########
@@ -98,6 +102,32 @@ class BucketFunction extends UnboundFunction {
override def name: String = BUCKET
}
+object BucketFunction {
+ private val SPARK_TIMESTAMP_PRECISION = 6
+
+ def supportsTable(table: FileStoreTable): Boolean = {
+ table.bucketMode match {
+ case BucketMode.HASH_FIXED =>
+
table.schema().logicalBucketKeyType().getFieldTypes.asScala.forall(supportsType)
+ case _ => false
+ }
+ }
+
+ private def supportsType(t: PaimonDataType): Boolean = t match {
+ case arrayType: ArrayType =>
+ supportsType(arrayType.getElementType)
+ case mapType: MapType =>
+ supportsType(mapType.getKeyType) && supportsType(mapType.getValueType)
+ case rowType: RowType =>
+ rowType.getFieldTypes.asScala.forall(supportsType)
+ case timestamp: TimestampType =>
Review Comment:
This is a validation of the Paimon table's data type, not a validation after
converting it to a Spark type, so it is valid. And I added
`org.apache.paimon.spark.catalog.functions.BucketFunctionTest#testTimestampPrecisionNotEqualToSpark`,
When the timestamp precision is inconsistent, the bucket calculated by the
native Paimon bucket extractor will differ from the bucket calculated by the
Spark bucket function.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]