}
public List<Object> runJoSqlQuery(String josql, Map<String, Object> bindVariables,
List<Object> additionalFunctionHandlers) throws QueryParseException, QueryExecutionException
{
Query josqlQuery = prepareQuery(bindVariables, additionalFunctionHandlers);
// Per JoSql, select FROM <target> the target must be a object class that
// corresponds to a "table row",
// while the table (list of Objects) are put in the query by
// query.execute(List<Object>). In the input,
// In out case, the row is always a ZNRecord. But in SQL, the from target is
// a "table name".
String fromTargetString = parseFromTarget(josql);
List fromTargetList = null;
Object fromTarget = null;
if (fromTargetString.equalsIgnoreCase(PARTITIONS))
{
fromTarget = josqlQuery.getVariable(PARTITIONS.toString());
} else if (fromTargetString.equalsIgnoreCase(PropertyType.LIVEINSTANCES.toString()))
{
fromTarget = josqlQuery.getVariable(PropertyType.LIVEINSTANCES.toString());
} else if (fromTargetString.equalsIgnoreCase(PropertyType.CONFIGS.toString() + "/"
+ ConfigScopeProperty.PARTICIPANT.toString()))
{
fromTarget = josqlQuery.getVariable(PropertyType.CONFIGS.toString() + "/"
+ ConfigScopeProperty.PARTICIPANT.toString());
} else if (fromTargetString.equalsIgnoreCase(PropertyType.STATEMODELDEFS.toString()))
{
fromTarget = josqlQuery.getVariable(PropertyType.STATEMODELDEFS.toString());
} else if (fromTargetString.equalsIgnoreCase(PropertyType.EXTERNALVIEW.toString()))
{
fromTarget = josqlQuery.getVariable(PropertyType.EXTERNALVIEW.toString());
}
else if (fromTargetString.equalsIgnoreCase(PropertyType.IDEALSTATES.toString()))
{
fromTarget = josqlQuery.getVariable(PropertyType.IDEALSTATES.toString());
}
else if (fromTargetString.equalsIgnoreCase(PARTITIONS + FLATTABLE))
{
fromTarget = josqlQuery.getVariable(PARTITIONS.toString() + FLATTABLE);
} else if (fromTargetString.equalsIgnoreCase(PropertyType.LIVEINSTANCES.toString() + FLATTABLE))
{
fromTarget = josqlQuery.getVariable(PropertyType.LIVEINSTANCES.toString() + FLATTABLE);
} else if (fromTargetString.equalsIgnoreCase(PropertyType.CONFIGS.toString() + "/"
+ ConfigScopeProperty.PARTICIPANT.toString()
+ FLATTABLE))
{
fromTarget = josqlQuery.getVariable(PropertyType.CONFIGS.toString() + "/"
+ ConfigScopeProperty.PARTICIPANT.toString() + FLATTABLE);
} else if (fromTargetString
.equalsIgnoreCase(PropertyType.STATEMODELDEFS.toString() + FLATTABLE))
{
fromTarget = josqlQuery.getVariable(PropertyType.STATEMODELDEFS.toString() + FLATTABLE);
} else if (fromTargetString.equalsIgnoreCase(PropertyType.EXTERNALVIEW.toString() + FLATTABLE))
{
fromTarget = josqlQuery.getVariable(PropertyType.EXTERNALVIEW.toString() + FLATTABLE);
}
else if (fromTargetString.equalsIgnoreCase(PropertyType.IDEALSTATES.toString() + FLATTABLE))
{
fromTarget = josqlQuery.getVariable(PropertyType.IDEALSTATES.toString() + FLATTABLE);
}
else
{
throw new HelixException(
"Unknown query target "
+ fromTargetString
+ ". Target should be PARTITIONS, LIVEINSTANCES, CONFIGS, STATEMODELDEFS, IDEALSTATES, EXTERNALVIEW, and corresponding flat Tables");
}
fromTargetList = fromTargetString.endsWith(FLATTABLE) ? ((List<ZNRecordRow>) fromTarget)
: ((List<ZNRecord>) fromTarget);
// Per JoSql, select FROM <target> the target must be a object class that
// corresponds to a "table row"
// In out case, the row is always a ZNRecord
josql = josql.replaceFirst(
fromTargetString,
fromTargetString.endsWith(FLATTABLE) ? ZNRecordRow.class.getName() : ZNRecord.class
.getName());
josqlQuery.parse(josql);
QueryResults qr = josqlQuery.execute(fromTargetList);
return qr.getResults();
}