address comments

This commit is contained in:
Jeff Zhang 2017-07-17 13:26:15 +08:00
parent 151e991427
commit f57d7bbf61
2 changed files with 13 additions and 4 deletions

View file

@ -341,9 +341,7 @@ public class SparkInterpreter extends Interpreter {
*/
public Object createSparkSession() {
// use local mode for embedded spark mode when spark.master is not found
if (!conf.contains("spark.master")) {
conf.setMaster("local");
}
conf.setIfMissing("spark.master", "local");
logger.info("------ Create new SparkSession {} -------", conf.get("spark.master"));
String execUri = System.getenv("SPARK_EXECUTOR_URI");
if (outputDir != null) {

View file

@ -151,13 +151,24 @@ public class RemoteInterpreter extends Interpreter {
sparkConfBuilder.append(" --master " + property.getProperty("master"));
}
if (isSparkConf(key, property.getProperty(key))) {
sparkConfBuilder.append(" --conf " + key + "=" + property.getProperty(key));
sparkConfBuilder.append(" --conf " + key + "=\"" +
toShellFormat(property.getProperty(key)) + "\"");
}
}
env.put("ZEPPELIN_SPARK_CONF", sparkConfBuilder.toString());
return env;
}
private String toShellFormat(String value) {
if (value.contains("\'") && value.contains("\"")) {
throw new RuntimeException("Spark property value could not contain both \" and '");
} else if (value.contains("\'")) {
return "\"" + value + "\"";
} else {
return "\'" + value + "\'";
}
}
static boolean isSparkConf(String key, String value) {
return !StringUtils.isEmpty(key) && key.startsWith("spark.") && !StringUtils.isEmpty(value);
}