forked from mc2-project/opaque-sql
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PySpark integration with client (mc2-project#261)
This PR includes the necessary changes to make our PySpark listener actually work with the full end-to-end workflow.
- Loading branch information
1 parent
1744b8a
commit 6f6edd7
Showing
2 changed files
with
21 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,24 @@ | ||
import code | ||
import io | ||
from code import InteractiveInterpreter | ||
from contextlib import redirect_stdout, redirect_stderr | ||
from io import StringIO | ||
from traceback import print_exc | ||
|
||
from opaque_sql import * | ||
|
||
from pyspark.shell import * | ||
|
||
class IntpHandler: | ||
def __init__(self): | ||
init_opaque_sql() | ||
self.initialized = False | ||
|
||
def run(self, source): | ||
out = io.StringIO() | ||
err = io.StringIO() | ||
with redirect_stdout(out) and redirect_stderr(err): | ||
compiled = compile(source) | ||
exec(compiled) | ||
out.getvalue(), err.getvalue() | ||
|
||
with StringIO() as out, redirect_stdout(out), \ | ||
StringIO() as err, redirect_stderr(err): | ||
try: | ||
if not self.initialized: | ||
exec("init_opaque_sql()") | ||
self.initialized = True | ||
exec(source) | ||
except Exception as e: | ||
print_exc() # This goes to stderr | ||
finally: | ||
return out.getvalue(), err.getvalue() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters