akashrn5 commented on a change in pull request #4141:
URL: https://github.com/apache/carbondata/pull/4141#discussion_r655292078
##########
File path:
examples/spark/src/test/scala/org/apache/carbondata/examplesCI/RunExamples.scala
##########
@@ -104,7 +104,8 @@ class RunExamples extends QueryTest with BeforeAndAfterAll {
TableLevelCompactionOptionExample.exampleBody(spark)
}
- test("LuceneIndexExample") {
+ // Below test case ignored due to the Deadlock in spark code
Review comment:
add a spark jira if its reported already, and add a TODO here to revert
once the spark jira is resolved
##########
File path:
integration/spark/src/main/scala/org/apache/spark/sql/hive/CarbonAnalysisRules.scala
##########
@@ -135,34 +137,34 @@ case class CarbonIUDAnalysisRule(sparkSession:
SparkSession) extends Rule[Logica
var transformed: Boolean = false
// Create a dummy projection to include filter conditions
var newPlan: LogicalPlan = null
- if (table.tableIdentifier.database.isDefined) {
+ if (tableIdentifier.database.isDefined) {
newPlan = parser.parsePlan("select * from " +
- table.tableIdentifier.database.getOrElse("") + "." +
- table.tableIdentifier.table + " " + alias.getOrElse("") + " " +
filter)
+ tableIdentifier.database.getOrElse("") + "." +
Review comment:
can you replace with POINT in all places in this class?
##########
File path:
integration/spark/src/main/scala/org/apache/spark/sql/parser/CarbonSpark2SqlParser.scala
##########
@@ -772,58 +774,62 @@ class CarbonSpark2SqlParser extends CarbonDDLSqlParser {
}
def getFields(schema: Seq[StructField], isExternal: Boolean = false):
Seq[Field] = {
- def getScannerInput(col: StructField,
- columnComment: String,
- columnName: String) = {
- if (col.dataType.catalogString == "float" && !isExternal) {
- '`' + columnName + '`' + " double" + columnComment
+ schema.map { col =>
+ // TODO: Spark has started supporting CharType/VarChar types in Spark
3.1 but both are
+ // marked as experimental. Adding a hack to change to string for now.
Review comment:
please mention the jira here in TODO
##########
File path:
integration/spark/src/main/scala/org/apache/spark/sql/execution/command/mutation/IUDCommonUtil.scala
##########
@@ -44,7 +44,7 @@ object IUDCommonUtil {
case unresolvedRelation: UnresolvedRelation =>
val dbAndTb =
sparkSession.sessionState.catalog.asInstanceOf[HiveSessionCatalog].getCurrentDatabase
+
- "." + unresolvedRelation.tableIdentifier.table
+ "." +
CarbonToSparkAdapter.getTableIdentifier(unresolvedRelation).get.table
Review comment:
replace with constant POINT here
##########
File path:
integration/spark/src/main/spark3.1/org/apache/spark/sql/parser/CarbonSparkSqlParser.scala
##########
@@ -0,0 +1,153 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.spark.sql.parser
+
+import scala.collection.mutable
+
+import org.antlr.v4.runtime.tree.TerminalNode
+import org.apache.spark.sql.{CarbonThreadUtil, CarbonToSparkAdapter,
SparkSession}
+import org.apache.spark.sql.catalyst.parser.{AbstractSqlParser, SqlBaseParser}
+import org.apache.spark.sql.catalyst.parser.SqlBaseParser._
+import org.apache.spark.sql.catalyst.plans.logical.LogicalPlan
+import org.apache.spark.sql.execution.{SparkSqlAstBuilder, SparkSqlParser}
+import org.apache.spark.sql.internal.{SQLConf, VariableSubstitution}
+import org.apache.spark.sql.types.StructField
+import org.apache.spark.sql.util.CarbonException
+import org.apache.spark.util.CarbonReflectionUtils
+
+import
org.apache.carbondata.common.exceptions.sql.MalformedCarbonCommandException
+import org.apache.carbondata.spark.util.CarbonScalaUtil
+
+/**
+ * Concrete parser for Spark SQL statements and carbon specific
+ * statements
+ */
+class CarbonSparkSqlParser(conf: SQLConf, sparkSession: SparkSession) extends
SparkSqlParser {
+
+ val parser = new CarbonSpark2SqlParser
+
+ override val astBuilder = CarbonReflectionUtils.getAstBuilder(conf, parser,
sparkSession)
+
+ private val substitutor = new VariableSubstitution
+
+ override def parsePlan(sqlText: String): LogicalPlan = {
+ CarbonThreadUtil.updateSessionInfoToCurrentThread(sparkSession)
+ try {
+ val parsedPlan = super.parsePlan(sqlText)
+ CarbonScalaUtil.cleanParserThreadLocals
+ parsedPlan
+ } catch {
+ case ce: MalformedCarbonCommandException =>
+ CarbonScalaUtil.cleanParserThreadLocals
+ throw ce
+ case ex: Throwable =>
+ try {
+ parser.parse(sqlText)
+ } catch {
+ case mce: MalformedCarbonCommandException =>
+ throw mce
+ case e: Throwable =>
+ CarbonException.analysisException(
+ s"""== Parse1 ==
+ |${ex.getMessage}
+ |== Parse2 ==
+ |${e.getMessage}
+ """.stripMargin.trim)
+ }
+ }
+ }
+
+ protected override def parse[T](command: String)(toResult: SqlBaseParser =>
T): T = {
+ super.parse(substitutor.substitute(command))(toResult)
+ }
+}
+
+class CarbonHelperSqlAstBuilder(conf: SQLConf,
+ parser: CarbonSpark2SqlParser,
+ sparkSession: SparkSession)
+ extends SparkSqlAstBuilderWrapper(conf) {
+ /**
+ * Parse a key-value map from a [[TablePropertyListContext]], assuming all
values are specified.
+ */
+ override def visitPropertyKeyValues(ctx: TablePropertyListContext):
Map[String, String] = {
+ val props = visitTablePropertyList(ctx)
+ CarbonSparkSqlParserUtil.visitPropertyKeyValues(ctx, props)
+ }
+
+ def getPropertyKeyValues(ctx: TablePropertyListContext): Map[String, String]
+ = {
Review comment:
move this line above
##########
File path:
integration/spark/src/main/spark3.1/org/apache/spark/sql/CarbonToSparkAdapter.scala
##########
@@ -0,0 +1,263 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.sql
+
+import java.net.URI
+
+import scala.collection.mutable.ArrayBuffer
+
+import org.apache.spark.{SparkContext, TaskContext}
+import org.apache.spark.scheduler.{SparkListener, SparkListenerApplicationEnd}
+import
org.apache.spark.sql.carbondata.execution.datasources.CarbonFileIndexReplaceRule
+import org.apache.spark.sql.catalyst.catalog.{CatalogStorageFormat,
ExternalCatalogWithListener}
+import org.apache.spark.sql.catalyst.expressions.{Alias, Attribute,
AttributeReference, AttributeSet, Expression, ExprId, NamedExpression,
ScalaUDF, SortOrder, SubqueryExpression}
+import org.apache.spark.sql.catalyst.expressions.codegen._
+import org.apache.spark.sql.catalyst.expressions.codegen.Block._
+import org.apache.spark.sql.catalyst.optimizer.Optimizer
+import org.apache.spark.sql.catalyst.plans.logical.{LogicalPlan, SubqueryAlias}
+import org.apache.spark.sql.catalyst.rules.Rule
+import org.apache.spark.sql.execution.datasources.{DataSourceStrategy,
FilePartition, PartitionedFile}
+import org.apache.spark.sql.hive.HiveExternalCatalog
+import org.apache.spark.sql.optimizer.{CarbonIUDRule, CarbonUDFTransformRule,
MVRewriteRule}
+import org.apache.spark.sql.secondaryindex.optimizer.CarbonSITransformationRule
+import org.apache.spark.sql.types.{DataType, Metadata, StringType}
+
+import org.apache.carbondata.core.util.{CarbonProperties,
ThreadLocalSessionInfo}
+import org.apache.carbondata.geo.{InPolygonJoinUDF, ToRangeListAsStringUDF}
+
+object CarbonToSparkAdapter extends SparkVersionAdapter {
+
+ def createFilePartition(index: Int, files: ArrayBuffer[PartitionedFile]):
FilePartition = {
+ FilePartition(index, files.toArray)
+ }
+
+ def addSparkSessionListener(sparkSession: SparkSession): Unit = {
+ sparkSession.sparkContext.addSparkListener(new SparkListener {
+ override def onApplicationEnd(applicationEnd:
SparkListenerApplicationEnd): Unit = {
+ CarbonEnv.carbonEnvMap.remove(sparkSession)
+ ThreadLocalSessionInfo.unsetAll()
+ }
+ })
+ }
+
+ def addSparkListener(sparkContext: SparkContext): Unit = {
+ sparkContext.addSparkListener(new SparkListener {
+ override def onApplicationEnd(applicationEnd:
SparkListenerApplicationEnd): Unit = {
+ SparkSession.setDefaultSession(null)
+ }
+ })
+ }
+
+ def createAttributeReference(
+ name: String,
+ dataType: DataType,
+ nullable: Boolean,
+ metadata: Metadata,
+ exprId: ExprId,
+ qualifier: Option[String],
+ attrRef : NamedExpression = null): AttributeReference = {
+ val qf = if (qualifier.nonEmpty) Seq(qualifier.get) else Seq.empty
+ AttributeReference(
+ name,
+ dataType,
+ nullable,
+ metadata)(exprId, qf)
+ }
+
+ def createAttributeReference(
+ name: String,
+ dataType: DataType,
+ nullable: Boolean,
+ metadata: Metadata,
+ exprId: ExprId,
+ qualifier: Seq[String]): AttributeReference = {
+ AttributeReference(
+ name,
+ dataType,
+ nullable,
+ metadata)(exprId, qualifier)
+ }
+
+ def lowerCaseAttribute(expression: Expression): Expression =
expression.transform {
+ case attr: AttributeReference =>
+ CarbonToSparkAdapter.createAttributeReference(
+ attr.name.toLowerCase,
+ attr.dataType,
+ attr.nullable,
+ attr.metadata,
+ attr.exprId,
+ attr.qualifier)
+ }
+
+ def createAttributeReference(attr: AttributeReference,
+ attrName: String,
+ newSubsume: String): AttributeReference = {
+ AttributeReference(attrName, attr.dataType)(
+ exprId = attr.exprId,
+ qualifier = newSubsume.split("\n").map(_.trim))
+ }
+
+ def createScalaUDF(s: ScalaUDF, reference: AttributeReference): ScalaUDF = {
+ s.copy(children = Seq(reference))
+ }
+
+ def createExprCode(code: String, isNull: String, value: String, dataType:
DataType): ExprCode = {
+ ExprCode(
+ code"$code",
+ JavaCode.isNullVariable(isNull),
+ JavaCode.variable(value, dataType))
+ }
+
+ def createAliasRef(
+ child: Expression,
+ name: String,
+ exprId: ExprId = NamedExpression.newExprId,
+ qualifier: Seq[String] = Seq.empty,
+ explicitMetadata: Option[Metadata] = None) : Alias = {
+ Alias(child, name)(exprId, qualifier, explicitMetadata)
+ }
+
+ def createAliasRef(
+ child: Expression,
+ name: String,
+ exprId: ExprId,
+ qualifier: Option[String]) : Alias = {
+ Alias(child, name)(exprId,
+ if (qualifier.isEmpty) Seq.empty else Seq(qualifier.get),
+ None)
Review comment:
move this line above
##########
File path:
integration/spark/src/main/scala/org/apache/spark/sql/parser/CarbonSpark2SqlParser.scala
##########
@@ -835,10 +841,21 @@ class CarbonSpark2SqlParser extends CarbonDDLSqlParser {
field.dataType = Some("double")
}
field.rawSchema = scannerInput
- if (col.getComment().isDefined) {
+ if (comment.isDefined) {
field.columnComment = plainComment
}
field
+ }
+
+ def getScannerInput(dataType: DataType,
+ columnComment: String,
+ columnName: String,
+ isExternal: Boolean): String = {
Review comment:
please correct the code style here
##########
File path:
mv/plan/src/main/spark2.3/org/apache/carbondata/mv/plans/modular/ExpressionHelper.scala
##########
@@ -17,7 +17,7 @@
package org.apache.carbondata.mv.plans.modular
-import org.apache.spark.sql.catalyst.expressions.{Alias, AttributeReference,
ExprId, Expression, NamedExpression}
+import org.apache.spark.sql.catalyst.expressions.{Alias, AttributeReference,
Expression, ExprId, NamedExpression}
Review comment:
revert this
--
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.
For queries about this service, please contact Infrastructure at:
[email protected]