Skip to content

Commit

Permalink
[SEDONA-636] Parser extension optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
freamdx committed Nov 25, 2024
1 parent b4163e7 commit ceb3cc0
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,6 @@ object ParserRegistrator {
val field = sparkSession.sessionState.getClass.getDeclaredField("sqlParser")
field.setAccessible(true)
field.set(sparkSession.sessionState, parser)
return // return if the new constructor is available
} catch {
case _: Exception =>
}

// try to register the parser with the legacy constructor for spark 3.0
try {
val parserClassName = "org.apache.sedona.sql.parser.SedonaSqlParser"
val delegate: ParserInterface = sparkSession.sessionState.sqlParser

val parser =
ParserFactory.getParser(parserClassName, sparkSession.sessionState.conf, delegate)
val field = sparkSession.sessionState.getClass.getDeclaredField("sqlParser")
field.setAccessible(true)
field.set(sparkSession.sessionState, parser)
} catch {
case _: Exception =>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,8 @@
package org.apache.sedona.sql.parser

import org.apache.spark.sql.catalyst.parser.ParserInterface
import org.apache.spark.sql.catalyst.plans.logical.LogicalPlan
import org.apache.spark.sql.execution.SparkSqlParser

class SedonaSqlParser(delegate: ParserInterface) extends SparkSqlParser {

// The parser builder for the Sedona SQL AST
val parserBuilder = new SedonaSqlAstBuilder

/**
* Parse the SQL text and return the logical plan.
* @param sqlText
* @return
*/
override def parsePlan(sqlText: String): LogicalPlan =
try {
parse(sqlText) { parser =>
parserBuilder.visit(parser.singleStatement()) match {
case plan: LogicalPlan => plan
case _ =>
delegate.parsePlan(sqlText)
}
}
} catch {
case _: Exception =>
delegate.parsePlan(sqlText)
}
override val astBuilder = new SedonaSqlAstBuilder
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,8 @@
package org.apache.sedona.sql.parser

import org.apache.spark.sql.catalyst.parser.ParserInterface
import org.apache.spark.sql.catalyst.plans.logical.LogicalPlan
import org.apache.spark.sql.execution.SparkSqlParser

class SedonaSqlParser(delegate: ParserInterface) extends SparkSqlParser {

// The parser builder for the Sedona SQL AST
val parserBuilder = new SedonaSqlAstBuilder

/**
* Parse the SQL text and return the logical plan.
* @param sqlText
* @return
*/
override def parsePlan(sqlText: String): LogicalPlan =
try {
parse(sqlText) { parser =>
parserBuilder.visit(parser.singleStatement()) match {
case plan: LogicalPlan => plan
case _ =>
delegate.parsePlan(sqlText)
}
}
} catch {
case _: Exception =>
delegate.parsePlan(sqlText)
}
override val astBuilder = new SedonaSqlAstBuilder
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,8 @@
package org.apache.sedona.sql.parser

import org.apache.spark.sql.catalyst.parser.ParserInterface
import org.apache.spark.sql.catalyst.plans.logical.LogicalPlan
import org.apache.spark.sql.execution.SparkSqlParser

class SedonaSqlParser(delegate: ParserInterface) extends SparkSqlParser {

// The parser builder for the Sedona SQL AST
val parserBuilder = new SedonaSqlAstBuilder

/**
* Parse the SQL text and return the logical plan.
* @param sqlText
* @return
*/
override def parsePlan(sqlText: String): LogicalPlan =
try {
parse(sqlText) { parser =>
parserBuilder.visit(parser.singleStatement()) match {
case plan: LogicalPlan => plan
case _ =>
delegate.parsePlan(sqlText)
}
}
} catch {
case _: Exception =>
delegate.parsePlan(sqlText)
}
override val astBuilder = new SedonaSqlAstBuilder
}

0 comments on commit ceb3cc0

Please sign in to comment.