Package com.illumon.iris.db.util
Class IrisDbPythonSession
java.lang.Object
com.illumon.iris.db.util.IrisDbPythonSession
- All Implemented Interfaces:
ScriptSession
A ScriptSession that uses a JPy cpython interpreter internally.
This is used for persistent queries or the DB console; Python code running remotely uses WorkerPythonEnvironment
for it's supporting structures.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionIrisDbPythonSession(com.fishlib.io.logger.Logger log, Database database, boolean runInitScripts) Create a Python ScriptSession.IrisDbPythonSession(PythonScope<?> scope) Creates a Python "ScriptSession", for use where we should only be reading from the scope, such as an IPython kernel session. -
Method Summary
Modifier and TypeMethodDescriptionvoidRemoves the currently configured script path loader from this script.voidEvaluates command in the context of the current ScriptSession.voidEvaluates command in the context of the current ScriptSession.getVariable(String name) Retrieve a variable from the script session's bindings.<T> TgetVariable(String name, T defaultValue) Retrieve a variable from the script session's bindings.Retrieves all of the variable names present in the session's scopeRetrieves all of the variables present in the session's scope (e.g., Groovy binding, Python globals()).booleanhasVariableName(String name) Check if the scope has the given variable namevoidonPersistentQueryInitializationBegin(Supplier<ScriptPathLoader> pathLoader, ScriptPathLoaderState scriptLoaderState) Called before PersistentQuery initialization, should setup sourcing from the controller (as required).voidCalled after PersistentQuery initialization.voidsetScriptPathLoader(Supplier<ScriptPathLoader> scriptPathLoader, boolean caching) Sets the scriptPathLoader that is in use for this session.booleansetUseOriginalScriptLoaderState(boolean useOriginal) Informs the session whether or not we should be using the original ScriptLoaderState for source commands.voidsetVariable(String name, Object value) Inserts a value into the script's scope.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.illumon.iris.db.util.ScriptSession
getWrappedSession, isInteractiveConsoleSession, sanitizeThrowable
-
Field Details
-
SCRIPT_TYPE
-
-
Constructor Details
-
IrisDbPythonSession
public IrisDbPythonSession(com.fishlib.io.logger.Logger log, Database database, boolean runInitScripts) throws IOException Create a Python ScriptSession.- Parameters:
log- the log to use for script session errors, info; as well as the Python interpreter's stdout/stderrdatabase- the database to insert into the script session's bindings.runInitScripts- if init scripts should be executed- Throws:
IOException- if an IO error occurs running initialization scripts
-
IrisDbPythonSession
Creates a Python "ScriptSession", for use where we should only be reading from the scope, such as an IPython kernel session.
-
-
Method Details
-
getVariable
Description copied from interface:ScriptSessionRetrieve a variable from the script session's bindings.- Specified by:
getVariablein interfaceScriptSession- Parameters:
name- the variable to retrieve- Returns:
- the variable
- Throws:
QueryScope.MissingVariableException- if the variable does not exist
-
getVariable
Description copied from interface:ScriptSessionRetrieve a variable from the script session's bindings. If the variable is not present, return defaultValue. If the variable is present, but is not of type (T), a ClassCastException may result.- Specified by:
getVariablein interfaceScriptSession- Type Parameters:
T- the type of the variable- Parameters:
name- the variable to retrievedefaultValue- the value to use when no value is present in the session's scope- Returns:
- the value of the variable, or defaultValue if not present
-
evaluate
Description copied from interface:ScriptSessionEvaluates command in the context of the current ScriptSession.- Specified by:
evaluatein interfaceScriptSession- Parameters:
command- the command to evaluate
-
evaluate
Description copied from interface:ScriptSessionEvaluates command in the context of the current ScriptSession.- Specified by:
evaluatein interfaceScriptSession- Parameters:
command- the command to evaluatescriptName- an optional script name, which may be ignored by the implementation, or used improve error messages or for other internal purposes
-
getVariables
Description copied from interface:ScriptSessionRetrieves all of the variables present in the session's scope (e.g., Groovy binding, Python globals()).- Specified by:
getVariablesin interfaceScriptSession- Returns:
- an unmodifiable map with variable names as the keys, and the Objects as the result
-
getVariableNames
Description copied from interface:ScriptSessionRetrieves all of the variable names present in the session's scope- Specified by:
getVariableNamesin interfaceScriptSession- Returns:
- an unmodifiable set of variable names
-
hasVariableName
Description copied from interface:ScriptSessionCheck if the scope has the given variable name- Specified by:
hasVariableNamein interfaceScriptSession- Parameters:
name- the variable name- Returns:
- True iff the scope has the given variable name
-
setVariable
Description copied from interface:ScriptSessionInserts a value into the script's scope.- Specified by:
setVariablein interfaceScriptSession- Parameters:
name- the variable name to setvalue- the new value of the variable
-
scriptType
- Specified by:
scriptTypein interfaceScriptSession- Returns:
- a textual description of this script session's language for use in messages.
-
onPersistentQueryInitializationBegin
public void onPersistentQueryInitializationBegin(Supplier<ScriptPathLoader> pathLoader, ScriptPathLoaderState scriptLoaderState) Description copied from interface:ScriptSessionCalled before PersistentQuery initialization, should setup sourcing from the controller (as required).- Specified by:
onPersistentQueryInitializationBeginin interfaceScriptSession
-
onPersistentQueryInitializationEnd
public void onPersistentQueryInitializationEnd()Description copied from interface:ScriptSessionCalled after PersistentQuery initialization.- Specified by:
onPersistentQueryInitializationEndin interfaceScriptSession
-
setScriptPathLoader
Description copied from interface:ScriptSessionSets the scriptPathLoader that is in use for this session.- Specified by:
setScriptPathLoaderin interfaceScriptSession- Parameters:
scriptPathLoader- a supplier of a script path loadercaching- whether the source operation should cache results
-
clearScriptPathLoader
public void clearScriptPathLoader()Description copied from interface:ScriptSessionRemoves the currently configured script path loader from this script.- Specified by:
clearScriptPathLoaderin interfaceScriptSession
-
setUseOriginalScriptLoaderState
public boolean setUseOriginalScriptLoaderState(boolean useOriginal) Description copied from interface:ScriptSessionInforms the session whether or not we should be using the original ScriptLoaderState for source commands.- Specified by:
setUseOriginalScriptLoaderStatein interfaceScriptSession- Parameters:
useOriginal- whether to use the script loader state at persistent query initialization
-