You must include a FROM
clause in your statement to specify a record source.
A FROM
clause is mandatory in a statement and specifies the source of records for an EQL statement, such as from a state name or from a previously-defined statement.
The FROM
syntax is:
FROM <recSource> [alias]
where <recSource> can be:
DEFINE
or a RETURN
).FROM
does not directly support collection names, but does in essence because the state includes a collection name and the Dgraph database for the data set.JOIN
or a CROSS JOIN
.If you omit the FROM
clause in your query, the EQL parser returns an error.
Using FROM with a previously-defined statement
DEFINE RepQuarters AS SELECT COUNT(TransId) AS NumTrans FROM SaleState GROUP BY SalesRep, Quarter; RETURN Quarters AS SELECT AVG(NumTrans) AS AvgTransPerRep FROM RepQuarters GROUP BY Quarter
{ SalesRep, Quarter, NumTrans }
. For example:
{ J. Smith, 11Q1, 10 } { J. Smith, 11Q2, 3 } { F. Jackson, 10Q4, 10 } ...
{ Quarter, AvgTransPerRep }
. For example:
{ 10Q4, 10 } { 11Q1, 4.5 } { 11Q2, 6 } ...
State name in FROM clauses
FROM
clauses with this syntax:
FROM <statename>[_FILTERED | _UNFILTERED | _ALL]
EQLQuery
type:
<Request> <Language>en</Language> <State> <Name>WineState</Name> <CollectionName>Wines</CollectionName> <DataSourceFilter Id="DataFltr"> <filterString>WineType <> 'Red'</filterString> </DataSourceFilter> <SelectionFilter Id="SecFltr"> <filterString>Price > 25</filterString> </SelectionFilter> </State> <EQLConfig Id="WineRecs"> <EQLQueryString> RETURN results AS SELECT Price AS prices FROM WineState GROUP BY prices </EQLQueryString> </EQLConfig> </Request>
DataSourceFilter
filter (which is the security filter) first removes any record that has a WineType=Red assignment. In our small data set, only 11 records pass the filter. (Note that WineType must be single-assign or the query will fail.)SelectionFilter
filter then selects any record whose Price assignment is $25 or more. 7 more records are filtered out (from the previous 11 records), leaving 4 records.FROM
clause in the EQL statement references the state named WineState.Thus, because the FROM
clause in the EQL statement references the state named WineState, both filters from the state are applied and the 4 records are returned.