From d3b7a8b1d031895d80a3f322ea2f5f94be663464 Mon Sep 17 00:00:00 2001 From: nitin2goyal Date: Mon, 11 May 2015 19:04:15 -0700 Subject: [PATCH] [SPARK-7331] [SQL] Re-use HiveConf in HiveQl Re-use HiveConf in HiveQl Author: nitin2goyal Closes #6036 from nitin2goyal/dev-nitin-1.2 and squashes the following commits: 7ff1f9e [nitin2goyal] [SPARK-7331][SQL] Re-use HiveConf in HiveQl --- .../scala/org/apache/spark/sql/hive/HiveQl.scala | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveQl.scala b/sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveQl.scala index 3d39e6c1bd120..a76561756789b 100644 --- a/sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveQl.scala +++ b/sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveQl.scala @@ -24,6 +24,7 @@ import org.apache.hadoop.hive.ql.lib.Node import org.apache.hadoop.hive.ql.metadata.Table import org.apache.hadoop.hive.ql.parse._ import org.apache.hadoop.hive.ql.plan.PlanUtils +import org.apache.hadoop.hive.ql.session.SessionState import org.apache.spark.sql.catalyst.SparkSQLParser import org.apache.spark.sql.catalyst.analysis._ @@ -224,12 +225,23 @@ private[hive] object HiveQl { * Otherwise, there will be Null pointer exception, * when retrieving properties form HiveConf. */ - val hContext = new Context(new HiveConf()) + val hContext = new Context(hiveConf) val node = ParseUtils.findRootNonNullToken((new ParseDriver).parse(sql, hContext)) hContext.clear() node } + /** + * Returns the HiveConf + */ + private[this] def hiveConf(): HiveConf = { + val ss = SessionState.get() // SessionState is lazy initializaion, it can be null here + if (ss == null) { + new HiveConf() + } else { + ss.getConf + } + } /** Returns a LogicalPlan for a given HiveQL string. */ def parseSql(sql: String): LogicalPlan = hqlParser(sql)