Skip to content

Commit d3b7a8b

Browse files
nitin2goyalmarmbrus
authored andcommitted
[SPARK-7331] [SQL] Re-use HiveConf in HiveQl
Re-use HiveConf in HiveQl Author: nitin2goyal <[email protected]> Closes #6036 from nitin2goyal/dev-nitin-1.2 and squashes the following commits: 7ff1f9e [nitin2goyal] [SPARK-7331][SQL] Re-use HiveConf in HiveQl
1 parent c0bd415 commit d3b7a8b

File tree

1 file changed

+13
-1
lines changed
  • sql/hive/src/main/scala/org/apache/spark/sql/hive

1 file changed

+13
-1
lines changed

sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveQl.scala

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import org.apache.hadoop.hive.ql.lib.Node
2424
import org.apache.hadoop.hive.ql.metadata.Table
2525
import org.apache.hadoop.hive.ql.parse._
2626
import org.apache.hadoop.hive.ql.plan.PlanUtils
27+
import org.apache.hadoop.hive.ql.session.SessionState
2728

2829
import org.apache.spark.sql.catalyst.SparkSQLParser
2930
import org.apache.spark.sql.catalyst.analysis._
@@ -224,12 +225,23 @@ private[hive] object HiveQl {
224225
* Otherwise, there will be Null pointer exception,
225226
* when retrieving properties form HiveConf.
226227
*/
227-
val hContext = new Context(new HiveConf())
228+
val hContext = new Context(hiveConf)
228229
val node = ParseUtils.findRootNonNullToken((new ParseDriver).parse(sql, hContext))
229230
hContext.clear()
230231
node
231232
}
232233

234+
/**
235+
* Returns the HiveConf
236+
*/
237+
private[this] def hiveConf(): HiveConf = {
238+
val ss = SessionState.get() // SessionState is lazy initializaion, it can be null here
239+
if (ss == null) {
240+
new HiveConf()
241+
} else {
242+
ss.getConf
243+
}
244+
}
233245

234246
/** Returns a LogicalPlan for a given HiveQL string. */
235247
def parseSql(sql: String): LogicalPlan = hqlParser(sql)

0 commit comments

Comments
 (0)