Skip to content

Commit 04a91e1

Browse files
committed
[KYUUBI #2517] Rename ZorderSqlAstBuilder to KyuubiSparkSQLAstBuilder
### _Why are the changes needed?_ Rename `ZorderSqlAstBuilder` to a generic name and then we can extend other syntax than z-order, e.g. `SHOW CATALOGS` for Spark 3.1/3.2 ### _How was this patch tested?_ - [ ] Add some test cases that check the changes thoroughly including negative and positive cases if possible - [ ] Add screenshots for manual tests if appropriate - [ ] [Run test](https://kyuubi.apache.org/docs/latest/develop_tools/testing.html#running-tests) locally before make a pull request Closes #2517 from pan3793/rename. Closes #2517 905189e [Cheng Pan] rename 1541acf [Cheng Pan] Rename ZorderSqlAstBuilder to KyuubiSQLParser Authored-by: Cheng Pan <chengpan@apache.org> Signed-off-by: Cheng Pan <chengpan@apache.org>
1 parent 02356a3 commit 04a91e1

File tree

4 files changed

+28
-28
lines changed

4 files changed

+28
-28
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18-
grammar ZorderSqlExtensions;
18+
grammar KyuubiSparkSQL;
1919

2020
@members {
2121
/**
Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18-
package org.apache.kyuubi.sql.zorder
18+
package org.apache.kyuubi.sql
1919

2020
import java.time.LocalDate
2121
import java.util.Locale
@@ -29,7 +29,7 @@ import org.antlr.v4.runtime.tree.{ParseTree, TerminalNode}
2929
import org.apache.commons.codec.binary.Hex
3030
import org.apache.spark.sql.AnalysisException
3131
import org.apache.spark.sql.catalyst.analysis.{UnresolvedAttribute, UnresolvedRelation, UnresolvedStar}
32-
import org.apache.spark.sql.catalyst.expressions.{And, Ascending, EqualNullSafe, EqualTo, Expression, GreaterThan, GreaterThanOrEqual, LessThan, LessThanOrEqual, Literal, Not, NullsLast, Or, SortOrder}
32+
import org.apache.spark.sql.catalyst.expressions._
3333
import org.apache.spark.sql.catalyst.parser.ParseException
3434
import org.apache.spark.sql.catalyst.parser.ParserUtils.{string, stringWithoutUnescape, withOrigin}
3535
import org.apache.spark.sql.catalyst.plans.logical.{Filter, LogicalPlan, Project, Sort}
@@ -40,10 +40,10 @@ import org.apache.spark.sql.internal.SQLConf
4040
import org.apache.spark.sql.types._
4141
import org.apache.spark.unsafe.types.UTF8String
4242

43-
import org.apache.kyuubi.sql.KyuubiSQLConf
44-
import org.apache.kyuubi.sql.zorder.ZorderSqlExtensionsParser.{BigDecimalLiteralContext, BigIntLiteralContext, BooleanLiteralContext, DecimalLiteralContext, DoubleLiteralContext, IntegerLiteralContext, LogicalBinaryContext, MultipartIdentifierContext, NullLiteralContext, NumberContext, OptimizeZorderContext, PassThroughContext, QueryContext, SingleStatementContext, SmallIntLiteralContext, StringLiteralContext, TinyIntLiteralContext, TypeConstructorContext, ZorderClauseContext}
43+
import org.apache.kyuubi.sql.KyuubiSparkSQLParser._
44+
import org.apache.kyuubi.sql.zorder.{OptimizeZorderStatement, OptimizeZorderStatementBase, Zorder, ZorderBase}
4545

46-
abstract class ZorderSqlAstBuilderBase extends ZorderSqlExtensionsBaseVisitor[AnyRef] {
46+
abstract class KyuubiSparkSQLAstBuilderBase extends KyuubiSparkSQLBaseVisitor[AnyRef] {
4747
def buildZorder(child: Seq[Expression]): ZorderBase
4848
def buildOptimizeZorderStatement(
4949
tableIdentifier: Seq[String],
@@ -105,28 +105,28 @@ abstract class ZorderSqlAstBuilderBase extends ZorderSqlExtensionsBaseVisitor[An
105105
val right = expression(ctx.constant())
106106
val operator = ctx.comparisonOperator().getChild(0).asInstanceOf[TerminalNode]
107107
operator.getSymbol.getType match {
108-
case ZorderSqlExtensionsParser.EQ =>
108+
case KyuubiSparkSQLParser.EQ =>
109109
EqualTo(left, right)
110-
case ZorderSqlExtensionsParser.NSEQ =>
110+
case KyuubiSparkSQLParser.NSEQ =>
111111
EqualNullSafe(left, right)
112-
case ZorderSqlExtensionsParser.NEQ | ZorderSqlExtensionsParser.NEQJ =>
112+
case KyuubiSparkSQLParser.NEQ | KyuubiSparkSQLParser.NEQJ =>
113113
Not(EqualTo(left, right))
114-
case ZorderSqlExtensionsParser.LT =>
114+
case KyuubiSparkSQLParser.LT =>
115115
LessThan(left, right)
116-
case ZorderSqlExtensionsParser.LTE =>
116+
case KyuubiSparkSQLParser.LTE =>
117117
LessThanOrEqual(left, right)
118-
case ZorderSqlExtensionsParser.GT =>
118+
case KyuubiSparkSQLParser.GT =>
119119
GreaterThan(left, right)
120-
case ZorderSqlExtensionsParser.GTE =>
120+
case KyuubiSparkSQLParser.GTE =>
121121
GreaterThanOrEqual(left, right)
122122
}
123123
}
124124

125125
override def visitLogicalBinary(ctx: LogicalBinaryContext): Expression = withOrigin(ctx) {
126126
val expressionType = ctx.operator.getType
127127
val expressionCombiner = expressionType match {
128-
case ZorderSqlExtensionsParser.AND => And.apply _
129-
case ZorderSqlExtensionsParser.OR => Or.apply _
128+
case KyuubiSparkSQLParser.AND => And.apply _
129+
case KyuubiSparkSQLParser.OR => Or.apply _
130130
}
131131

132132
// Collect all similar left hand contexts.
@@ -437,7 +437,7 @@ abstract class ZorderSqlAstBuilderBase extends ZorderSqlExtensionsBaseVisitor[An
437437
}
438438
}
439439

440-
class ZorderSqlAstBuilder extends ZorderSqlAstBuilderBase {
440+
class KyuubiSparkSQLAstBuilder extends KyuubiSparkSQLAstBuilderBase {
441441
override def buildZorder(child: Seq[Expression]): ZorderBase = {
442442
Zorder(child)
443443
}

extensions/spark/kyuubi-extension-spark-common/src/main/scala/org/apache/kyuubi/sql/KyuubiSparkSQLCommonExtension.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ package org.apache.kyuubi.sql
1919

2020
import org.apache.spark.sql.SparkSessionExtensions
2121

22-
import org.apache.kyuubi.sql.zorder.{InsertZorderBeforeWritingDatasource, InsertZorderBeforeWritingHive, ResolveZorder, ZorderSparkSqlExtensionsParser}
22+
import org.apache.kyuubi.sql.zorder.{InsertZorderBeforeWritingDatasource, InsertZorderBeforeWritingHive, ResolveZorder}
2323

2424
class KyuubiSparkSQLCommonExtension extends (SparkSessionExtensions => Unit) {
2525
override def apply(extensions: SparkSessionExtensions): Unit = {
@@ -30,7 +30,7 @@ class KyuubiSparkSQLCommonExtension extends (SparkSessionExtensions => Unit) {
3030
object KyuubiSparkSQLCommonExtension {
3131
def injectCommonExtensions(extensions: SparkSessionExtensions): Unit = {
3232
// inject zorder parser and related rules
33-
extensions.injectParser { case (_, parser) => new ZorderSparkSqlExtensionsParser(parser) }
33+
extensions.injectParser { case (_, parser) => new SparkKyuubiSparkSQLParser(parser) }
3434
extensions.injectResolutionRule(ResolveZorder)
3535

3636
// Note that:
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18-
package org.apache.kyuubi.sql.zorder
18+
package org.apache.kyuubi.sql
1919

2020
import org.antlr.v4.runtime._
2121
import org.antlr.v4.runtime.atn.PredictionMode
@@ -28,9 +28,9 @@ import org.apache.spark.sql.catalyst.plans.logical.LogicalPlan
2828
import org.apache.spark.sql.catalyst.trees.Origin
2929
import org.apache.spark.sql.types.{DataType, StructType}
3030

31-
abstract class ZorderSparkSqlExtensionsParserBase extends ParserInterface {
31+
abstract class KyuubiSparkSQLParserBase extends ParserInterface {
3232
def delegate: ParserInterface
33-
def astBuilder: ZorderSqlAstBuilderBase
33+
def astBuilder: KyuubiSparkSQLAstBuilderBase
3434

3535
override def parsePlan(sqlText: String): LogicalPlan = parse(sqlText) { parser =>
3636
astBuilder.visit(parser.singleStatement()) match {
@@ -39,14 +39,14 @@ abstract class ZorderSparkSqlExtensionsParserBase extends ParserInterface {
3939
}
4040
}
4141

42-
protected def parse[T](command: String)(toResult: ZorderSqlExtensionsParser => T): T = {
43-
val lexer = new ZorderSqlExtensionsLexer(
42+
protected def parse[T](command: String)(toResult: KyuubiSparkSQLParser => T): T = {
43+
val lexer = new KyuubiSparkSQLLexer(
4444
new UpperCaseCharStream(CharStreams.fromString(command)))
4545
lexer.removeErrorListeners()
4646
lexer.addErrorListener(ParseErrorListener)
4747

4848
val tokenStream = new CommonTokenStream(lexer)
49-
val parser = new ZorderSqlExtensionsParser(tokenStream)
49+
val parser = new KyuubiSparkSQLParser(tokenStream)
5050
parser.addParseListener(PostProcessor)
5151
parser.removeErrorListeners()
5252
parser.addErrorListener(ParseErrorListener)
@@ -102,15 +102,15 @@ abstract class ZorderSparkSqlExtensionsParserBase extends ParserInterface {
102102
}
103103
}
104104

105-
class ZorderSparkSqlExtensionsParser(
105+
class SparkKyuubiSparkSQLParser(
106106
override val delegate: ParserInterface)
107-
extends ZorderSparkSqlExtensionsParserBase {
108-
def astBuilder: ZorderSqlAstBuilderBase = new ZorderSqlAstBuilder
107+
extends KyuubiSparkSQLParserBase {
108+
def astBuilder: KyuubiSparkSQLAstBuilderBase = new KyuubiSparkSQLAstBuilder
109109
}
110110

111111
/* Copied from Apache Spark's to avoid dependency on Spark Internals */
112112
class UpperCaseCharStream(wrapped: CodePointCharStream) extends CharStream {
113-
override def consume(): Unit = wrapped.consume
113+
override def consume(): Unit = wrapped.consume()
114114
override def getSourceName(): String = wrapped.getSourceName
115115
override def index(): Int = wrapped.index
116116
override def mark(): Int = wrapped.mark

0 commit comments

Comments
 (0)