You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hudi.apache.org by si...@apache.org on 2022/04/22 00:36:59 UTC
[hudi] 12/15: fix undeterministic ctor order
This is an automated email from the ASF dual-hosted git repository.
sivabalan pushed a commit to branch release-0.11-0-apr21-5378-patched
in repository https://gitbox.apache.org/repos/asf/hudi.git
commit f0beb5311b65267eca6d6b96e5182f28a83dea5d
Author: Raymond Xu <27...@users.noreply.github.com>
AuthorDate: Thu Apr 21 22:05:03 2022 +0800
fix undeterministic ctor order
---
.../parquet/Spark32HoodieParquetFileFormat.scala | 17 +++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)
diff --git a/hudi-spark-datasource/hudi-spark3/src/main/scala/org/apache/spark/sql/execution/datasources/parquet/Spark32HoodieParquetFileFormat.scala b/hudi-spark-datasource/hudi-spark3/src/main/scala/org/apache/spark/sql/execution/datasources/parquet/Spark32HoodieParquetFileFormat.scala
index 3ba5d38623..ec522fb31b 100644
--- a/hudi-spark-datasource/hudi-spark3/src/main/scala/org/apache/spark/sql/execution/datasources/parquet/Spark32HoodieParquetFileFormat.scala
+++ b/hudi-spark-datasource/hudi-spark3/src/main/scala/org/apache/spark/sql/execution/datasources/parquet/Spark32HoodieParquetFileFormat.scala
@@ -397,26 +397,27 @@ object Spark32HoodieParquetFileFormat {
private def createParquetFilters(args: Any*): ParquetFilters = {
// NOTE: ParquetFilters ctor args contain Scala enum, therefore we can't look it
- // up by arg types, and have to instead rely on relative order of ctors
- val ctor = classOf[ParquetFilters].getConstructors.head
+ // up by arg types, and have to instead rely on the number of args based on individual class;
+ // the ctor order is not guaranteed
+ val ctor = classOf[ParquetFilters].getConstructors.maxBy(_.getParameterCount)
ctor.newInstance(args.map(_.asInstanceOf[AnyRef]): _*)
.asInstanceOf[ParquetFilters]
}
private def createParquetReadSupport(args: Any*): ParquetReadSupport = {
// NOTE: ParquetReadSupport ctor args contain Scala enum, therefore we can't look it
- // up by arg types, and have to instead rely on relative order of ctors
- val ctor = classOf[ParquetReadSupport].getConstructors.head
+ // up by arg types, and have to instead rely on the number of args based on individual class;
+ // the ctor order is not guaranteed
+ val ctor = classOf[ParquetReadSupport].getConstructors.maxBy(_.getParameterCount)
ctor.newInstance(args.map(_.asInstanceOf[AnyRef]): _*)
.asInstanceOf[ParquetReadSupport]
}
private def createVectorizedParquetRecordReader(args: Any*): VectorizedParquetRecordReader = {
// NOTE: ParquetReadSupport ctor args contain Scala enum, therefore we can't look it
- // up by arg types, and have to instead rely on relative order of ctors
- // NOTE: VectorizedParquetRecordReader has 2 ctors and the one we need is 2nd on the array
- // This is a hacky workaround for the fixed version of Class.
- val ctor = classOf[VectorizedParquetRecordReader].getConstructors.last
+ // up by arg types, and have to instead rely on the number of args based on individual class;
+ // the ctor order is not guaranteed
+ val ctor = classOf[VectorizedParquetRecordReader].getConstructors.maxBy(_.getParameterCount)
ctor.newInstance(args.map(_.asInstanceOf[AnyRef]): _*)
.asInstanceOf[VectorizedParquetRecordReader]
}