Skip to content

Instantly share code, notes, and snippets.

View fmarchand's full-sized avatar

Franck Marchand fmarchand

View GitHub Profile
<project ...>
<modelVersion>4.0.0</modelVersion>
<groupId>com.agaetis.antlr4.mysql</groupId>
<artifactId>parslex</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>MySQL Antlr 4 Lexer/Parser</name>
<properties>
...
<antlr4.visitor>true</antlr4.visitor>
val options = Map(
"url" -> dbUrl,
"dbtable" -> tableName,
"user" -> userName,
"password" -> userPassword,
"driver" -> "com.mysql.jdbc.Driver"
)
val queries = spark.read.format("jdbc").options(options).load
queries.cache()
queries.count
def evalComplexityUdf = udf((input:String) => {
evalComplexity(input, "EXPR")
})
val allQueriesWithComplexity = allQueries.withColumn("valCplx", evalComplexityUdf($"query"))
import com.agaetis.antlr4.mysql.MySqlParserBaseListener
import com.agaetis.antlr4.mysql.MySqlLexer
import com.agaetis.antlr4.mysql.MySqlParser
import org.antlr.v4.runtime.ParserRuleContext
import org.antlr.v4.runtime.CharStream
import org.antlr.v4.runtime.CharStreams
import org.antlr.v4.runtime.CommonTokenStream
import org.antlr.v4.runtime.tree.ParseTree
import org.antlr.v4.runtime.tree.ParseTreeWalker
import scala.collection.mutable.Map