Skip to content
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 @@ -156,6 +156,9 @@ private[hive] object SparkSQLCLIDriver extends Logging {
// Execute -i init files (always in silent mode)
cli.processInitFiles(sessionState)

// Respect the configurations from the command line and .hiverc for backward-compatible
SparkSQLEnv.applyOverridedConf(sessionState)

if (sessionState.execString != null) {
System.exit(cli.processLine(sessionState.execString))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package org.apache.spark.sql.hive.thriftserver

import java.io.PrintStream

import scala.collection.JavaConverters._
import org.apache.hadoop.hive.ql.session.SessionState

import org.apache.spark.{SparkConf, SparkContext}
import org.apache.spark.internal.Logging
Expand Down Expand Up @@ -66,6 +66,14 @@ private[hive] object SparkSQLEnv extends Logging {
}
}

def applyOverridedConf(ss: SessionState): Unit = {
val it = ss.getOverriddenConfigurations.entrySet().iterator()
while (it.hasNext) {
val kv = it.next()
SparkSQLEnv.sqlContext.setConf(kv.getKey, kv.getValue)
}
}

/** Cleans up and shuts down the Spark SQL environments. */
def stop() {
logDebug("Shutting down Spark SQL Environment")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ class CliSuite extends SparkFunSuite with BeforeAndAfterAll with Logging {
| --hiveconf ${ConfVars.METASTORECONNECTURLKEY}=$jdbcUrl
| --hiveconf ${ConfVars.METASTOREWAREHOUSE}=$warehousePath
| --hiveconf ${ConfVars.SCRATCHDIR}=$scratchDirPath
| --hiveconf conf1=conftest
| --hiveconf conf2=1
Copy link
Contributor

Choose a reason for hiding this comment

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

@chenghao-intel Does --hiveconf ${ConfVars.METASTORECONNECTURLKEY}=$jdbcUrl work?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, it works, that's intention, right?

But seems the below code in SparkSQLCliDriver will not work as we expected.

      if (key != "javax.jdo.option.ConnectionURL") {
        conf.set(key, value)
        sessionState.getOverriddenConfigurations.put(key, value)
      }

Why do we have to ignore the connection url?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@yhuai any concern for this?

Copy link
Contributor

Choose a reason for hiding this comment

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

Do you know why those work but something like --hiveconf conf1=conftest does not?

""".stripMargin.split("\\s+").toSeq ++ extraArgs
}

Expand Down Expand Up @@ -272,4 +274,13 @@ class CliSuite extends SparkFunSuite with BeforeAndAfterAll with Logging {
s"LIST FILE $dataFilePath;" -> "small_kv.txt"
)
}

test("apply hiveconf from cli command") {
runCliWithin(2.minute)(
"SET conf1;" -> "conftest",
"SET conf2;" -> "1",
"SET conf3=${hiveconf:conf1};" -> "conftest",
"SET conf3;" -> "conftest"
)
}
}