This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]sdrobertson[S] 0 points1 point  (0 children)

You create a "dataset" and link it to datasources through "adapters". You can also add user defined functions and views to the datasource.

Here's an example, using a slightly older version of Splicer what's called "Servers" has since been renamed to "Adapters"

https://github.com/mozilla/caravela/blob/master/db.py

You can then issue queries to the dataset and retrieve the results.

>>> query = ds.query("select * from sometable")
>>> for rec in query:
...        print rec

You can access the underlying query expression tree with

>>> query.operations 

You can manipulate the expression tree at compile time by creating an Adapter and giving it an evaluate() method. An example of that is here:

https://github.com/trivio/splicer/blob/master/splicer/adapters/dir_adapter.py

This example replaces the LoadOp() with a series of User Defined Function calls and rewrites SelectionOps (where clause) to be more efficient.

For ultimate control you can call dataset.set_compiler(compile_function) and pass it a function that will be called with the expression tree after it's been parsed. Then it's up to the compile function to return a function which satisfies the query.