Преглед на файлове

[livy] Hack python session to allow the last line of a cell to be a magic fn

Erick Tryzelaar преди 10 години
родител
ревизия
a7d6a5b
променени са 1 файла, в които са добавени 12 реда и са изтрити 2 реда
  1. 12 2
      apps/spark/java/livy-repl/src/main/resources/fake_shell.py

+ 12 - 2
apps/spark/java/livy-repl/src/main/resources/fake_shell.py

@@ -94,8 +94,18 @@ def execute_request(content):
         exc_type, exc_value, tb = sys.exc_info()
         return execute_reply_error(exc_type, exc_value, [])
 
-    if code.startswith('%'):
-        parts = code[1:].split(' ', 1)
+    lines = code.split('\n')
+
+    if lines and lines[-1].startswith('%'):
+        code, magic = lines[:-1], lines[-1]
+
+        # Make sure to execute the other lines first.
+        if code:
+            result = execute('\n'.join(code))
+            if result['content']['status'] != 'ok':
+                return result
+
+        parts = magic[1:].split(' ', 1)
         if len(parts) == 1:
             magic, rest = parts[0], ()
         else: