Skip to content

Commit

Permalink
[SPARK-14211][SQL] Remove ANTLR3 based parser
Browse files Browse the repository at this point in the history
### What changes were proposed in this pull request?

This PR removes the ANTLR3 based parser, and moves the new ANTLR4 based parser into the `org.apache.spark.sql.catalyst.parser package`.

### How was this patch tested?

Existing unit tests.

cc rxin andrewor14 yhuai

Author: Herman van Hovell <[email protected]>

Closes apache#12071 from hvanhovell/SPARK-14211.
  • Loading branch information
hvanhovell authored and rxin committed Mar 31, 2016
1 parent 26445c2 commit a9b93e0
Show file tree
Hide file tree
Showing 47 changed files with 411 additions and 8,283 deletions.
4 changes: 3 additions & 1 deletion dev/deps/spark-deps-hadoop-2.2
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ JavaEWAH-0.3.2.jar
RoaringBitmap-0.5.11.jar
ST4-4.0.4.jar
activation-1.1.jar
antlr-runtime-3.5.2.jar
antlr-2.7.7.jar
antlr-runtime-3.4.jar
antlr4-runtime-4.5.2-1.jar
aopalliance-1.0.jar
apache-log4j-extras-1.2.17.jar
Expand Down Expand Up @@ -173,6 +174,7 @@ spire_2.11-0.7.4.jar
stax-api-1.0-2.jar
stax-api-1.0.1.jar
stream-2.7.0.jar
stringtemplate-3.2.1.jar
super-csv-2.2.0.jar
univocity-parsers-1.5.6.jar
unused-1.0.0.jar
Expand Down
4 changes: 3 additions & 1 deletion dev/deps/spark-deps-hadoop-2.3
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ JavaEWAH-0.3.2.jar
RoaringBitmap-0.5.11.jar
ST4-4.0.4.jar
activation-1.1.1.jar
antlr-runtime-3.5.2.jar
antlr-2.7.7.jar
antlr-runtime-3.4.jar
antlr4-runtime-4.5.2-1.jar
aopalliance-1.0.jar
apache-log4j-extras-1.2.17.jar
Expand Down Expand Up @@ -164,6 +165,7 @@ spire_2.11-0.7.4.jar
stax-api-1.0-2.jar
stax-api-1.0.1.jar
stream-2.7.0.jar
stringtemplate-3.2.1.jar
super-csv-2.2.0.jar
univocity-parsers-1.5.6.jar
unused-1.0.0.jar
Expand Down
4 changes: 3 additions & 1 deletion dev/deps/spark-deps-hadoop-2.4
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ JavaEWAH-0.3.2.jar
RoaringBitmap-0.5.11.jar
ST4-4.0.4.jar
activation-1.1.1.jar
antlr-runtime-3.5.2.jar
antlr-2.7.7.jar
antlr-runtime-3.4.jar
antlr4-runtime-4.5.2-1.jar
aopalliance-1.0.jar
apache-log4j-extras-1.2.17.jar
Expand Down Expand Up @@ -165,6 +166,7 @@ spire_2.11-0.7.4.jar
stax-api-1.0-2.jar
stax-api-1.0.1.jar
stream-2.7.0.jar
stringtemplate-3.2.1.jar
super-csv-2.2.0.jar
univocity-parsers-1.5.6.jar
unused-1.0.0.jar
Expand Down
4 changes: 3 additions & 1 deletion dev/deps/spark-deps-hadoop-2.6
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ JavaEWAH-0.3.2.jar
RoaringBitmap-0.5.11.jar
ST4-4.0.4.jar
activation-1.1.1.jar
antlr-runtime-3.5.2.jar
antlr-2.7.7.jar
antlr-runtime-3.4.jar
antlr4-runtime-4.5.2-1.jar
aopalliance-1.0.jar
apache-log4j-extras-1.2.17.jar
Expand Down Expand Up @@ -171,6 +172,7 @@ spire_2.11-0.7.4.jar
stax-api-1.0-2.jar
stax-api-1.0.1.jar
stream-2.7.0.jar
stringtemplate-3.2.1.jar
super-csv-2.2.0.jar
univocity-parsers-1.5.6.jar
unused-1.0.0.jar
Expand Down
4 changes: 3 additions & 1 deletion dev/deps/spark-deps-hadoop-2.7
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ JavaEWAH-0.3.2.jar
RoaringBitmap-0.5.11.jar
ST4-4.0.4.jar
activation-1.1.1.jar
antlr-runtime-3.5.2.jar
antlr-2.7.7.jar
antlr-runtime-3.4.jar
antlr4-runtime-4.5.2-1.jar
aopalliance-1.0.jar
apache-log4j-extras-1.2.17.jar
Expand Down Expand Up @@ -172,6 +173,7 @@ spire_2.11-0.7.4.jar
stax-api-1.0-2.jar
stax-api-1.0.1.jar
stream-2.7.0.jar
stringtemplate-3.2.1.jar
super-csv-2.2.0.jar
univocity-parsers-1.5.6.jar
unused-1.0.0.jar
Expand Down
6 changes: 0 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@
<jodd.version>3.5.2</jodd.version>
<jsr305.version>1.3.9</jsr305.version>
<libthrift.version>0.9.2</libthrift.version>
<antlr.version>3.5.2</antlr.version>
<antlr4.version>4.5.2-1</antlr4.version>

<test.java.home>${java.home}</test.java.home>
Expand Down Expand Up @@ -1755,11 +1754,6 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr-runtime</artifactId>
<version>${antlr.version}</version>
</dependency>
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr4-runtime</artifactId>
Expand Down
54 changes: 2 additions & 52 deletions project/SparkBuild.scala
Original file line number Diff line number Diff line change
Expand Up @@ -403,59 +403,9 @@ object OldDeps {

object Catalyst {
lazy val settings = antlr4Settings ++ Seq(
antlr4PackageName in Antlr4 := Some("org.apache.spark.sql.catalyst.parser.ng"),
antlr4PackageName in Antlr4 := Some("org.apache.spark.sql.catalyst.parser"),
antlr4GenListener in Antlr4 := true,
antlr4GenVisitor in Antlr4 := true,
// ANTLR code-generation step.
//
// This has been heavily inspired by com.github.stefri.sbt-antlr (0.5.3). It fixes a number of
// build errors in the current plugin.
// Create Parser from ANTLR grammar files.
sourceGenerators in Compile += Def.task {
val log = streams.value.log

val grammarFileNames = Seq(
"SparkSqlLexer.g",
"SparkSqlParser.g")
val sourceDir = (sourceDirectory in Compile).value / "antlr3"
val targetDir = (sourceManaged in Compile).value / "antlr3"

// Create default ANTLR Tool.
val antlr = new org.antlr.Tool

// Setup input and output directories.
antlr.setInputDirectory(sourceDir.getPath)
antlr.setOutputDirectory(targetDir.getPath)
antlr.setForceRelativeOutput(true)
antlr.setMake(true)

// Add grammar files.
grammarFileNames.flatMap(gFileName => (sourceDir ** gFileName).get).foreach { gFilePath =>
val relGFilePath = (gFilePath relativeTo sourceDir).get.getPath
log.info("ANTLR: Grammar file '%s' detected.".format(relGFilePath))
antlr.addGrammarFile(relGFilePath)
// We will set library directory multiple times here. However, only the
// last one has effect. Because the grammar files are located under the same directory,
// We assume there is only one library directory.
antlr.setLibDirectory(gFilePath.getParent)
}

// Generate the parser.
antlr.process()
val errorState = org.antlr.tool.ErrorManager.getErrorState
if (errorState.errors > 0) {
sys.error("ANTLR: Caught %d build errors.".format(errorState.errors))
} else if (errorState.warnings > 0) {
sys.error("ANTLR: Caught %d build warnings.".format(errorState.warnings))
}

// Return all generated java files.
(targetDir ** "*.java").get.toSeq
}.taskValue,
// Include ANTLR tokens files.
resourceGenerators in Compile += Def.task {
((sourceManaged in Compile).value ** "*.tokens").get.toSeq
}.taskValue
antlr4GenVisitor in Antlr4 := true
)
}

Expand Down
3 changes: 0 additions & 3 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ libraryDependencies += "org.ow2.asm" % "asm" % "5.0.3"

libraryDependencies += "org.ow2.asm" % "asm-commons" % "5.0.3"

libraryDependencies += "org.antlr" % "antlr" % "3.5.2"


// TODO I am not sure we want such a dep.
resolvers += "simplytyped" at "http://simplytyped.github.io/repo/releases"

Expand Down
2 changes: 1 addition & 1 deletion python/pyspark/sql/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def deco(*a, **kw):
e.java_exception.getStackTrace()))
if s.startswith('org.apache.spark.sql.AnalysisException: '):
raise AnalysisException(s.split(': ', 1)[1], stackTrace)
if s.startswith('org.apache.spark.sql.catalyst.parser.ng.ParseException: '):
if s.startswith('org.apache.spark.sql.catalyst.parser.ParseException: '):
raise ParseException(s.split(': ', 1)[1], stackTrace)
if s.startswith('java.lang.IllegalArgumentException: '):
raise IllegalArgumentException(s.split(': ', 1)[1], stackTrace)
Expand Down
22 changes: 0 additions & 22 deletions sql/catalyst/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,6 @@
<groupId>org.codehaus.janino</groupId>
<artifactId>janino</artifactId>
</dependency>
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr-runtime</artifactId>
</dependency>
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr4-runtime</artifactId>
Expand Down Expand Up @@ -115,24 +111,6 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.antlr</groupId>
<artifactId>antlr3-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>antlr</goal>
</goals>
</execution>
</executions>
<configuration>
<sourceDirectory>../catalyst/src/main/antlr3</sourceDirectory>
<includes>
<include>**/SparkSqlLexer.g</include>
<include>**/SparkSqlParser.g</include>
</includes>
</configuration>
</plugin>
<plugin>
<groupId>org.antlr</groupId>
<artifactId>antlr4-maven-plugin</artifactId>
Expand Down
Loading

0 comments on commit a9b93e0

Please sign in to comment.