Skip to content
Snippets Groups Projects
Commit f0e3b710 authored by Reynold Xin's avatar Reynold Xin Committed by Michael Armbrust
Browse files

[SPARK-5840][SQL] HiveContext cannot be serialized due to tuple extraction

Also added test cases for checking the serializability of HiveContext and SQLContext.

Author: Reynold Xin <rxin@databricks.com>

Closes #4628 from rxin/SPARK-5840 and squashes the following commits:

ecb3bcd [Reynold Xin] test cases and reviews.
55eb822 [Reynold Xin] [SPARK-5840][SQL] HiveContext cannot be serialized due to tuple extraction.
parent a8eb92dc
No related branches found
No related tags found
No related merge requests found
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.spark.sql
import org.scalatest.FunSuite
import org.apache.spark.SparkConf
import org.apache.spark.serializer.JavaSerializer
import org.apache.spark.sql.test.TestSQLContext
class SerializationSuite extends FunSuite {
test("[SPARK-5235] SQLContext should be serializable") {
val sqlContext = new SQLContext(TestSQLContext.sparkContext)
new JavaSerializer(new SparkConf()).newInstance().serialize(sqlContext)
}
}
...@@ -222,22 +222,25 @@ class HiveContext(sc: SparkContext) extends SQLContext(sc) { ...@@ -222,22 +222,25 @@ class HiveContext(sc: SparkContext) extends SQLContext(sc) {
* SQLConf. Additionally, any properties set by set() or a SET command inside sql() will be * SQLConf. Additionally, any properties set by set() or a SET command inside sql() will be
* set in the SQLConf *as well as* in the HiveConf. * set in the SQLConf *as well as* in the HiveConf.
*/ */
@transient protected[hive] lazy val (hiveconf, sessionState) = @transient protected[hive] lazy val sessionState: SessionState = {
Option(SessionState.get()) var state = SessionState.get()
.orElse { if (state == null) {
val newState = new SessionState(new HiveConf(classOf[SessionState])) state = new SessionState(new HiveConf(classOf[SessionState]))
// Only starts newly created `SessionState` instance. Any existing `SessionState` instance SessionState.start(state)
// returned by `SessionState.get()` must be the most recently started one. }
SessionState.start(newState) if (state.out == null) {
Some(newState) state.out = new PrintStream(outputBuffer, true, "UTF-8")
} }
.map { state => if (state.err == null) {
setConf(state.getConf.getAllProperties) state.err = new PrintStream(outputBuffer, true, "UTF-8")
if (state.out == null) state.out = new PrintStream(outputBuffer, true, "UTF-8") }
if (state.err == null) state.err = new PrintStream(outputBuffer, true, "UTF-8") state
(state.getConf, state) }
}
.get @transient protected[hive] lazy val hiveconf: HiveConf = {
setConf(sessionState.getConf.getAllProperties)
sessionState.getConf
}
override def setConf(key: String, value: String): Unit = { override def setConf(key: String, value: String): Unit = {
super.setConf(key, value) super.setConf(key, value)
......
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.spark.sql.hive
import org.scalatest.FunSuite
import org.apache.spark.SparkConf
import org.apache.spark.serializer.JavaSerializer
import org.apache.spark.sql.hive.test.TestHive
class SerializationSuite extends FunSuite {
test("[SPARK-5840] HiveContext should be serializable") {
val hiveContext = new HiveContext(TestHive.sparkContext)
hiveContext.hiveconf
new JavaSerializer(new SparkConf()).newInstance().serialize(hiveContext)
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment