...
Code Block | ||
---|---|---|
| ||
def tables = api.queryApi().tables() def tProduct = tables.products() def tCosts = tables.productExtension("Costs") def tCountries = tables.companyParameterTable("Countries") |
The Table
interface extends Map<String, SelectableExpression>
interface. Therefore the table objects are used to reference columns.
...
Attribute fields can be used in the QueryAPI only if you configure a name and data type for that attribute field. Attribute fields are accessed as a Map property by the configured label, e.g. px.Cost,
cp.Country
. Therefore it is not recommended to configure attribute labels with spaces, since it makes the code worse readable, however such column names are supported. Attribute fields cannot be accessed by their system field name, e.g. p.attribute3
will not work.
System fields can be accessed as Map properties as well, but also using methods in the given table interface, e.g. p.sku()
, c.customerId()
, p.lastUpdateDate()
. It is recommended to use the provided methods, since it will help you when finding column references in the source code.Columns are instances of SelectableExpression
interface.
If you want to retrieve the column under a different name, you can use an alias method as()
, eg.:
...
The query returns all product records and their cost and currency from the product extension Cost. Or null for cost and currency if the product extension record does not exist.
...
Code Block | ||
---|---|---|
| ||
def qapi = api.queryApi() def t1 = qapi.tables().productExtension("Competition") def exprs = qapi.exprs() return qapi.source(t1, [t1.sku(), t1.jm Price]) .aggregateBy({ cols -> [cols.sku] }, { cols -> [cols.sku, exprs.min(cols.Price).as("MinPrice")] }) .stream().withCloseable { it.collect { it } } |
Returns the sku and it’s lowest competitor’s price for each SKU.
Row limit
The limit of the number of rows being returned is set by .take(maxResults)
method called at the end of the pipeline and just before the stream()
call.
...
Performance, Important Prerequisites
Specify number of columns
Join criteria on all key fields
Fast processing of stream row
Avoid loading big amount of rows to memory
Transactional tables:
Analytical tables:
...