/
Can I query a Data Source directly?
Can I query a Data Source directly?
Question
Does anyone know of a way to query data straight out of a Data Source from a calculation logic instead of setting up a Datamart + Data Load for it?
I found that I can use the search API to find the DS, but it contains no actual data, only the structure:
api.find("DMDS", Filter.equal("uniqueName", "DSNAME"))
Answer
You need to use DatamartContext.getDataSource(String name)
.
def dmCtx = api.getDatamartContext()
def salesDS = dmCtx.getDataSource("SalesHistory2")
def dsQuery = dmCtx.newQuery(salesDS)
def filters = [
Filter.equal("Sku", api.product("sku")),
]
dsQuery.select("SUM(Revenue)", "revenue")
dsQuery.select("SUM(UnitsSold)", "unitsSold")
dsQuery.select("YearMonth", "month")
dsQuery.where(filters)
def result = dmCtx.executeQuery(dsQuery)
, multiple selections available,
Related content
Query a Datamart
Query a Datamart
Read with this
Advanced Data Source Queries
Advanced Data Source Queries
More like this
General Data Queries
General Data Queries
Read with this
Use Complex Queries
Use Complex Queries
More like this
Calculation Data Loads
Calculation Data Loads
Read with this
Model Logic Key Methods
Model Logic Key Methods
More like this
Found an issue in documentation? Write to us.