The Session Object


source

Session

 Session (register_stdlib=True)

A Session object is the main interface to the spannerlog engine. It is used to parse, check semantics, plan and execute queries. It allows importing data and callbacks to the Spannerlog engine and exporting data from the engine back to python.

Type Default Details
register_stdlib bool True if True, registers the standard library of IEs and AGGs

source

Session.clear

 Session.clear (register_stdlib=True)

Resets the engine and clears all relations, functions and rules.

Type Default Details
register_stdlib bool True if True, registers the standard library of IEs and AGGs

Importing information to spannerlog


source

Session.register

 Session.register (name, func, in_schema, out_schema)

Registers an IE function with the spannerlog engine.

Details
name name of the IE function in spannerlog
func the python function that implements the IE
in_schema the schema of the input relation
out_schema the schema of the output relation

source

Session.register_agg

 Session.register_agg (name, func, in_schema, out_schema)

Registers an AGG function with the spannerlog engine.

Details
name name of the AGG function in spannerlog
func the python function that implements the AGG
in_schema the schema of the input relation, can be of arity 1 only
out_schema the schema of the output relation, can be of arity 1 only

source

Session.import_rel

 Session.import_rel (name:str,
                     data:Union[str,pathlib.Path,pandas.core.frame.DataFra
                     me], delim:str=None, header=None)

Imports a relation into the current session, either from a dataframe or from a csv file.

Type Default Details
name str name of the relation in spannerlog
data Union either a pandas dataframe or a path to a csv file
delim str None the delimiter of the csv file
header NoneType None the header of the csv file

source

Session.import_var

 Session.import_var (name, value)

Imports a variable into the current session.

Details
name name of the variable in spannerlog
value the value of the variable

Exporting data from spannerlog to python


source

Session.export

 Session.export (code:str, display_results=False, draw_query=False,
                 plan_query=False, return_statements_meta=False)

Takes a string of spannerlog code, and executes it, returning the value of the last statement in the code string. All statements that are not queries, return None.

Type Default Details
code str the spannerlog code to execute
display_results bool False if True, displays the results of the query to screen
draw_query bool False if True, draws the query graph of queries to screen
plan_query bool False if True, if last statement is a query, plans the query and returns the query graph and root node.
return_statements_meta bool False if True, returns both the return value and the statements meta data, used internally.

source

Session.get_all_functions

 Session.get_all_functions ()

Returns all the IEs and AGGs in the engine, as a nested dictionary of the form: { ‘ie’:{name:IEFunction}, ‘agg’:{name:AGGFunction} }


source

Session.print_rules

 Session.print_rules ()

Prints all the rules in the engine. and returns them as a list

Removing information

These functions are mostly used when debugging spannerlog code, to remove rules and relations we want to redefine.


source

Session.remove_rule

 Session.remove_rule (rule:str)

removes a rule from the engine, rule string must be identical to the rule defined previously

Type Details
rule str the rule string to remove

source

Session.remove_head

 Session.remove_head (head:str)

removes all rules of a given head relation


source

Session.remove_all_rules

 Session.remove_all_rules ()

removes all rules from the engine


source

Session.remove_relation

 Session.remove_relation (relation:str)

removes a relation from the engine, either a extrinsic or intrinsic relation

Examples

sess = Session()
df1 = pd.DataFrame([['John Doe', 35],['Jane Smith', 28]],columns=['X','Y'])
df2 = pd.DataFrame([['John Doe', 30]],columns=['X','Y'])

sess.import_rel("AgeOfKids",df1)
display.display(sess.export("?AgeOfKids(X,Y)"))
sess.import_rel("AgeOfKids",df2)
display.display(sess.export("?AgeOfKids(X,Y)"))
X Y
0 Jane Smith 28
1 John Doe 35
X Y
0 Jane Smith 28
1 John Doe 30
2 John Doe 35
# basic export with metadata
sess = Session()

res = sess.export("""
new A(int)
""")
display.display(res)
None
sess.engine.Relation_defs
{'A': RelationDefinition(name='A', scheme=[<class 'int'>])}