Github user marmbrus commented on a diff in the pull request:

    https://github.com/apache/spark/pull/4015#discussion_r28746270
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/SQLContext.scala ---
    @@ -130,18 +170,35 @@ class SQLContext(@transient val sparkContext: 
SparkContext)
       protected[sql] lazy val optimizer: Optimizer = DefaultOptimizer
     
       @transient
    -  protected[sql] val ddlParser = new DDLParser(sqlParser.apply(_))
    -
    -  @transient
    -  protected[sql] val sqlParser = {
    -    val fallback = new catalyst.SqlParser
    -    new SparkSQLParser(fallback(_))
    +  protected[sql] val ddlParser = new DDLParser((sql: String) => { 
getSQLDialect().parse(sql) })
    +  protected[sql] def dialectCache = tlSession.get().dialectCache
    +  protected[sql] def setDialectCache(d: Dialect) = {
    +    tlSession.get().dialectCache = d
       }
     
    -  protected[sql] def parseSql(sql: String): LogicalPlan = {
    -    ddlParser(sql, false).getOrElse(sqlParser(sql))
    +  protected[sql] def getSQLDialect(): Dialect = {
    +    try {
    +      val clazz = Utils.classForName(dialectClassName)
    +      if (dialectCache == null || dialectCache.getClass != clazz) {
    +        // if the cache not exist or the Dialect class is changed
    +        
setDialectCache(clazz.newInstance().asInstanceOf[Dialect].initialize(conf))
    +      }
    +
    +      dialectCache
    +    } catch {
    +      case t: Throwable =>
    +        // Since we didn't find the available SQL Dialect, it will fail 
even for SET command:
    +        // SET spark.sql.dialect=sql; Let's reset as default dialect 
automatically.
    +        val dialect = conf.dialect
    +        resetSQLDialect()
    --- End diff --
    
    I'm saying I don't think we need special handling for this and we can just
    clear the specific find with that existing function.
    On Apr 20, 2015 7:37 PM, "Cheng Hao" <notificati...@github.com> wrote:
    
    > In sql/core/src/main/scala/org/apache/spark/sql/SQLContext.scala
    > <https://github.com/apache/spark/pull/4015#discussion_r28746184>:
    >
    > > -    ddlParser(sql, false).getOrElse(sqlParser(sql))
    > > +  protected[sql] def getSQLDialect(): Dialect = {
    > > +    try {
    > > +      val clazz = Utils.classForName(dialectClassName)
    > > +      if (dialectCache == null || dialectCache.getClass != clazz) {
    > > +        // if the cache not exist or the Dialect class is changed
    > > +        
setDialectCache(clazz.newInstance().asInstanceOf[Dialect].initialize(conf))
    > > +      }
    > > +
    > > +      dialectCache
    > > +    } catch {
    > > +      case t: Throwable =>
    > > +        // Since we didn't find the available SQL Dialect, it will 
fail even for SET command:
    > > +        // SET spark.sql.dialect=sql; Let's reset as default dialect 
automatically.
    > > +        val dialect = conf.dialect
    > > +        resetSQLDialect()
    >
    > Sorry, @marmbrus <https://github.com/marmbrus> do you mean to rename the
    > function resetSQLDialect?
    >
    > —
    > Reply to this email directly or view it on GitHub
    > <https://github.com/apache/spark/pull/4015/files#r28746184>.
    >



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to