Make sure expressions are printed when no plots are shown

This commit is contained in:
Alex Goodman 2016-11-03 19:21:46 -07:00
parent 22b6fe4178
commit bdb584e02b
2 changed files with 23 additions and 5 deletions

View file

@ -286,6 +286,17 @@ while True :
stmts = req.statements().split("\n")
jobGroup = req.jobGroup()
final_code = []
# Get post-execute hooks
try:
global_hook = intp.getHook('post_exec_dev')
except:
global_hook = None
user_hook = z.getHook('post_exec')
nhooks = 0
for hook in (global_hook, user_hook):
if hook:
nhooks += 1
for s in stmts:
if s == None:
@ -303,7 +314,9 @@ while True :
# so that the last statement's evaluation will be printed to stdout
sc.setJobGroup(jobGroup, "Zeppelin")
code = compile('\n'.join(final_code), '<stdin>', 'exec', ast.PyCF_ONLY_AST, 1)
to_run_exec, to_run_single = code.body[:-1], code.body[-1:]
to_run_hooks = code.body[-nhooks:]
to_run_exec, to_run_single = (code.body[:-(nhooks + 1)],
[code.body[-(nhooks + 1)]])
try:
for node in to_run_exec:
@ -315,6 +328,11 @@ while True :
mod = ast.Interactive([node])
code = compile(mod, '<stdin>', 'single')
exec(code)
for node in to_run_hooks:
mod = ast.Module([node])
code = compile(mod, '<stdin>', 'exec')
exec(code)
except:
raise Exception(traceback.format_exc())

View file

@ -214,7 +214,7 @@ public class ZeppelinSparkClusterTest extends AbstractTestRestApi {
p.setConfig(config);
p.setText("%pyspark from pyspark.sql import Row\n" +
"df=sqlContext.createDataFrame([Row(id=1, age=20)])\n" +
"print(df.collect())");
"df.collect()");
p.setAuthenticationInfo(anonymous);
note.run(p.getId());
waitForFinish(p);
@ -243,7 +243,7 @@ public class ZeppelinSparkClusterTest extends AbstractTestRestApi {
config.put("enabled", true);
p.setConfig(config);
p.setText("%pyspark sqlContext.udf.register(\"f1\", lambda x: len(x))\n" +
"print(sqlContext.sql(\"select f1(\\\"abc\\\") as len\").collect())");
"sqlContext.sql(\"select f1(\\\"abc\\\") as len\").collect()");
p.setAuthenticationInfo(anonymous);
note.run(p.getId());
waitForFinish(p);
@ -258,7 +258,7 @@ public class ZeppelinSparkClusterTest extends AbstractTestRestApi {
p.setConfig(config);
p.setText("%pyspark from pyspark.sql import Row\n" +
"df=sqlContext.createDataFrame([Row(id=1, age=20)])\n" +
"print(df.collect())");
"df.collect()");
p.setAuthenticationInfo(anonymous);
note.run(p.getId());
waitForFinish(p);
@ -272,7 +272,7 @@ public class ZeppelinSparkClusterTest extends AbstractTestRestApi {
p.setConfig(config);
// use SQLContext to register UDF but use this UDF through SparkSession
p.setText("%pyspark sqlContext.udf.register(\"f1\", lambda x: len(x))\n" +
"print(spark.sql(\"select f1(\\\"abc\\\") as len\").collect())");
"spark.sql(\"select f1(\\\"abc\\\") as len\").collect()");
p.setAuthenticationInfo(anonymous);
note.run(p.getId());
waitForFinish(p);