Seek Context
The power of the Insight Cloud is it's ability to magically execute generically defined app code against a user's specific environment and request. This run context includes things like mapped user data source tables, parameter values, and other run specific settings.
Runtime Magic ✨
All app models defined by SBT developers are passed a parameter called seek
. This is an instance of a SeekRunContext
object that is instantiated during the user's app run request.
class SeekRunContext:
model_name: str # name of currently running model
target_name: str # schema.table name of output object
current_db: str # db name of output object
params: dict # dic
sources: dict
models: dict
Now that we understand what the SeekRunContext object is, let's dive into using it in a model definition.
SQL Models
In the below SQL model definition, we can see how to correctly reference the seek
object to access the user's run context. Although you are defining the model using sql, we use a python-like syntax to access the seek
object. That's because ultimately even your sql models are being run through a Python runtime in order to inteprolate the run context as needed.
select
*
from
{seek.sources['known_source_name']} as source
join
{seek.models['upstream_model']} as model
on
source.id = model.id
where
date >= {seek.params['lookback_date']}
Python Models
In the below Python model definition, we can see how to correctly reference the seek
object to access the user's run context. Now we are in Python natively so it's a little more obvious that you are accessing a Python object.
def model(session, seek):
source = seek.sources['known_source_name']
model = seek.models['upstream_model']
lookback_date = seek.params['lookback_date']
# do some python magic
return result