diff --git a/paimon-spark/paimon-spark-common/src/main/scala/org/apache/spark/sql/paimon/shims/SparkShimLoader.scala b/paimon-spark/paimon-spark-common/src/main/scala/org/apache/spark/sql/paimon/shims/SparkShimLoader.scala index ac6eeffdb29f..920896547a1e 100644 --- a/paimon-spark/paimon-spark-common/src/main/scala/org/apache/spark/sql/paimon/shims/SparkShimLoader.scala +++ b/paimon-spark/paimon-spark-common/src/main/scala/org/apache/spark/sql/paimon/shims/SparkShimLoader.scala @@ -25,19 +25,18 @@ import scala.collection.JavaConverters._ /** Load a [[SparkShim]]'s implementation. */ object SparkShimLoader { - private var sparkShim: SparkShim = _ + private lazy val sparkShim: SparkShim = loadSparkShim() def getSparkShim: SparkShim = { - if (sparkShim == null) { - sparkShim = loadSparkShim() - } sparkShim } private def loadSparkShim(): SparkShim = { val shims = ServiceLoader.load(classOf[SparkShim]).asScala - if (shims.size != 1) { + if (shims.isEmpty) { throw new IllegalStateException("No available spark shim here.") + } else if (shims.size > 1) { + throw new IllegalStateException("Found more than one spark shim here.") } shims.head } diff --git a/paimon-spark/paimon-spark3-common/src/main/scala/org/apache/spark/sql/catalyst/parser/extensions/PaimonSparkSqlExtensionsParser.scala b/paimon-spark/paimon-spark3-common/src/main/scala/org/apache/paimon/spark/catalyst/parser/extensions/PaimonSpark3SqlExtensionsParser.scala similarity index 80% rename from paimon-spark/paimon-spark3-common/src/main/scala/org/apache/spark/sql/catalyst/parser/extensions/PaimonSparkSqlExtensionsParser.scala rename to paimon-spark/paimon-spark3-common/src/main/scala/org/apache/paimon/spark/catalyst/parser/extensions/PaimonSpark3SqlExtensionsParser.scala index 5cec8a2c23a7..07481b6f639f 100644 --- a/paimon-spark/paimon-spark3-common/src/main/scala/org/apache/spark/sql/catalyst/parser/extensions/PaimonSparkSqlExtensionsParser.scala +++ b/paimon-spark/paimon-spark3-common/src/main/scala/org/apache/paimon/spark/catalyst/parser/extensions/PaimonSpark3SqlExtensionsParser.scala @@ -16,9 +16,10 @@ * limitations under the License. */ -package org.apache.spark.sql.catalyst.parser.extensions +package org.apache.paimon.spark.catalyst.parser.extensions import org.apache.spark.sql.catalyst.parser.ParserInterface +import org.apache.spark.sql.catalyst.parser.extensions.AbstractPaimonSparkSqlExtensionsParser -class PaimonSparkSqlExtensionsParser(override val delegate: ParserInterface) +class PaimonSpark3SqlExtensionsParser(override val delegate: ParserInterface) extends AbstractPaimonSparkSqlExtensionsParser(delegate) {} diff --git a/paimon-spark/paimon-spark3-common/src/main/scala/org/apache/spark/sql/paimon/shims/Spark3Shim.scala b/paimon-spark/paimon-spark3-common/src/main/scala/org/apache/spark/sql/paimon/shims/Spark3Shim.scala index 45bcece3e31e..57d79d6474e9 100644 --- a/paimon-spark/paimon-spark3-common/src/main/scala/org/apache/spark/sql/paimon/shims/Spark3Shim.scala +++ b/paimon-spark/paimon-spark3-common/src/main/scala/org/apache/spark/sql/paimon/shims/Spark3Shim.scala @@ -18,13 +18,13 @@ package org.apache.spark.sql.paimon.shims +import org.apache.paimon.spark.catalyst.parser.extensions.PaimonSpark3SqlExtensionsParser import org.apache.paimon.spark.data.{Spark3ArrayData, Spark3InternalRow, SparkArrayData, SparkInternalRow} import org.apache.paimon.types.{DataType, RowType} import org.apache.spark.sql.{Column, SparkSession} import org.apache.spark.sql.catalyst.expressions.{Attribute, Expression} import org.apache.spark.sql.catalyst.parser.ParserInterface -import org.apache.spark.sql.catalyst.parser.extensions.PaimonSparkSqlExtensionsParser import org.apache.spark.sql.catalyst.plans.logical.Aggregate import org.apache.spark.sql.connector.catalog.{Identifier, Table, TableCatalog} import org.apache.spark.sql.connector.expressions.Transform @@ -35,7 +35,7 @@ import java.util.{Map => JMap} class Spark3Shim extends SparkShim { override def createSparkParser(delegate: ParserInterface): ParserInterface = { - new PaimonSparkSqlExtensionsParser(delegate) + new PaimonSpark3SqlExtensionsParser(delegate) } override def createSparkInternalRow(rowType: RowType): SparkInternalRow = { diff --git a/paimon-spark/paimon-spark4-common/src/main/scala/org/apache/spark/sql/catalyst/parser/extensions/PaimonSparkSqlExtensionsParser.scala b/paimon-spark/paimon-spark4-common/src/main/scala/org/apache/paimon/spark/catalyst/parser/extensions/PaimonSpark4SqlExtensionsParser.scala similarity index 81% rename from paimon-spark/paimon-spark4-common/src/main/scala/org/apache/spark/sql/catalyst/parser/extensions/PaimonSparkSqlExtensionsParser.scala rename to paimon-spark/paimon-spark4-common/src/main/scala/org/apache/paimon/spark/catalyst/parser/extensions/PaimonSpark4SqlExtensionsParser.scala index 2066bc8dec3e..ef1f5763d27b 100644 --- a/paimon-spark/paimon-spark4-common/src/main/scala/org/apache/spark/sql/catalyst/parser/extensions/PaimonSparkSqlExtensionsParser.scala +++ b/paimon-spark/paimon-spark4-common/src/main/scala/org/apache/paimon/spark/catalyst/parser/extensions/PaimonSpark4SqlExtensionsParser.scala @@ -16,11 +16,12 @@ * limitations under the License. */ -package org.apache.spark.sql.catalyst.parser.extensions +package org.apache.paimon.spark.catalyst.parser.extensions import org.apache.spark.sql.catalyst.parser.{CompoundBody, ParserInterface} +import org.apache.spark.sql.catalyst.parser.extensions.AbstractPaimonSparkSqlExtensionsParser -class PaimonSparkSqlExtensionsParser(override val delegate: ParserInterface) +class PaimonSpark4SqlExtensionsParser(override val delegate: ParserInterface) extends AbstractPaimonSparkSqlExtensionsParser(delegate) { def parseScript(sqlScriptText: String): CompoundBody = delegate.parseScript(sqlScriptText) diff --git a/paimon-spark/paimon-spark4-common/src/main/scala/org/apache/spark/sql/paimon/shims/Spark4Shim.scala b/paimon-spark/paimon-spark4-common/src/main/scala/org/apache/spark/sql/paimon/shims/Spark4Shim.scala index 54785ecc18b0..dfec4eb71f4f 100644 --- a/paimon-spark/paimon-spark4-common/src/main/scala/org/apache/spark/sql/paimon/shims/Spark4Shim.scala +++ b/paimon-spark/paimon-spark4-common/src/main/scala/org/apache/spark/sql/paimon/shims/Spark4Shim.scala @@ -18,13 +18,13 @@ package org.apache.spark.sql.paimon.shims +import org.apache.paimon.spark.catalyst.parser.extensions.PaimonSpark4SqlExtensionsParser import org.apache.paimon.spark.data.{Spark4ArrayData, Spark4InternalRow, SparkArrayData, SparkInternalRow} import org.apache.paimon.types.{DataType, RowType} import org.apache.spark.sql.{Column, SparkSession} import org.apache.spark.sql.catalyst.expressions.{Attribute, Expression} import org.apache.spark.sql.catalyst.parser.ParserInterface -import org.apache.spark.sql.catalyst.parser.extensions.PaimonSparkSqlExtensionsParser import org.apache.spark.sql.catalyst.plans.logical.Aggregate import org.apache.spark.sql.connector.catalog.{CatalogV2Util, Identifier, Table, TableCatalog} import org.apache.spark.sql.connector.expressions.Transform @@ -36,7 +36,7 @@ import java.util.{Map => JMap} class Spark4Shim extends SparkShim { override def createSparkParser(delegate: ParserInterface): ParserInterface = { - new PaimonSparkSqlExtensionsParser(delegate) + new PaimonSpark4SqlExtensionsParser(delegate) } override def createSparkInternalRow(rowType: RowType): SparkInternalRow = { new Spark4InternalRow(rowType)