From 45d1216e91babcfb92470a7b5c314fefa27fce0d Mon Sep 17 00:00:00 2001 From: todd5167 <313328862@qq.com> Date: Fri, 25 Feb 2022 12:31:29 +0800 Subject: [PATCH] [HUDI-3401] fix NPE caused by incorrect beforeKeyGenClassName validation (#4774) --- .../org/apache/spark/sql/hudi/command/SqlKeyGenerator.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/spark/sql/hudi/command/SqlKeyGenerator.scala b/hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/spark/sql/hudi/command/SqlKeyGenerator.scala index e43923804..9d139389f 100644 --- a/hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/spark/sql/hudi/command/SqlKeyGenerator.scala +++ b/hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/spark/sql/hudi/command/SqlKeyGenerator.scala @@ -47,7 +47,7 @@ class SqlKeyGenerator(props: TypedProperties) extends ComplexKeyGenerator(props) // The origin key generator class for this table. private lazy val originKeyGen = { val beforeKeyGenClassName = props.getString(SqlKeyGenerator.ORIGIN_KEYGEN_CLASS_NAME, null) - if (beforeKeyGenClassName != null) { + if (beforeKeyGenClassName != null && beforeKeyGenClassName.nonEmpty) { val keyGenProps = new TypedProperties() keyGenProps.putAll(props) keyGenProps.remove(SqlKeyGenerator.ORIGIN_KEYGEN_CLASS_NAME) @@ -132,7 +132,7 @@ object SqlKeyGenerator { def getRealKeyGenClassName(props: TypedProperties): String = { val beforeKeyGenClassName = props.getString(SqlKeyGenerator.ORIGIN_KEYGEN_CLASS_NAME, null) - if (beforeKeyGenClassName != null) { + if (beforeKeyGenClassName != null && beforeKeyGenClassName.nonEmpty) { HoodieSparkKeyGeneratorFactory.convertToSparkKeyGenerator(beforeKeyGenClassName) } else { classOf[ComplexKeyGenerator].getCanonicalName