Skip to content

[SPARK-3939][SQL] NPE caused by SessionState.out not set in thriftserver2 #2812

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package org.apache.spark.sql.hive.thriftserver

import java.io.PrintStream

import scala.collection.JavaConversions._

import org.apache.commons.logging.LogFactory
Expand Down Expand Up @@ -69,6 +71,10 @@ object HiveThriftServer2 extends Logging {
logInfo("Starting SparkContext")
SparkSQLEnv.init()
SessionState.start(ss)
SparkSQLEnv.hiveContext.sessionState.err =
new PrintStream(SparkSQLEnv.hiveContext.outputBuffer, true, "UTF-8")
SparkSQLEnv.hiveContext.sessionState.out =
new PrintStream(SparkSQLEnv.hiveContext.outputBuffer, true, "UTF-8")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of duplicating this code, can we just change the line above to SessionState.start(SparkSQLEnv.hiveContext.sessionState). out and err would be initialized then. I'm actually not sure why we are creating our own session state here at all instead of using the one provided by the context.


Runtime.getRuntime.addShutdownHook(
new Thread() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ class HiveContext(sc: SparkContext) extends SQLContext(sc) {

// Circular buffer to hold what hive prints to STDOUT and ERR. Only printed when failures occur.
@transient
protected lazy val outputBuffer = new java.io.OutputStream {
protected[hive] lazy val outputBuffer = new java.io.OutputStream {
var pos: Int = 0
var buffer = new Array[Int](10240)
def write(i: Int): Unit = {
Expand Down