Native queries cannot return the concept(s). You need to add all required fields to the SQL and load them from resultset or create a query that returns the id or extID and load the concept(s) with catalog functions Instance.getBy...() or Cluster.DataGrid.getBy...().
The format of a native query is different from an original BQL query.
BQL query:
select <field> from <entityURL> as <alias> where <alias>.<field>=<value> ...
e.g.,
select c@id from /Concepts/DemoConcept as c where c.prop_string="testValue"
Native query:
"native-query: select <field> from be_gen_<entityURLSeparator_underline> where <field>=<value> ...
e.g.,
"native-query: select _id from be_gen_DemoConcept where prop_string="testValue"
Note:
- Add prefix "native-query:" to the BQL query to tag the query as a native query.
- Field name for the ID is "_id"
- Field name for the extID is "_extid"
- Entity URL has a prefix "be_gen_" and the separator "/" replaced with a "_"
- Native queries not work when AS2.x as in-built cache in BE version 6.3.x (AS2.x deprecated)
- For Ignite as in-built cache we recommend to use native queries and add a composite index for the columns in WHERE clause (CDD cluster area -> Overrides section).
Sample BE code:
try{
String sQuery = "native-query: select _EXTID from be_gen_concepts_cpTest cp where cp.p1='t2'";
Object oResultList = Query.Util.executeInDynamicQuerySession(sQuery,null,false);
Object[] oRows = Query.Util.listToArray(oResultList);
Query.Util.clearList(oResultList);
for (int i = 0; i < oRows@length; i++){
String sExtID=oRows[i];
// load concept into Rete
Concepts.cpTest cp=Cluster.DataGrid.CacheLoadConceptByExtIdByUri(sExtID,false,"/Concepts/cpTest");
System.debugOut(Engine.ruleFunctionName() + " loaded concept with extID=" + sExtID);
}
}
catch (Exception ex) {
System.debugOut("### ERROR " + Engine.ruleFunctionName() + ": Stacktrace: " + ex@stackTrace);
}