Search in sources :

Example 1 with StoreQueryCreationException

use of org.wso2.siddhi.core.exception.StoreQueryCreationException in project siddhi by wso2.

the class StoreQueryParser method parse.

/**
 * Parse a storeQuery and return corresponding StoreQueryRuntime.
 *
 * @param storeQuery       storeQuery to be parsed.
 * @param siddhiAppContext associated Siddhi app context.
 * @param tableMap         keyvalue containing tables.
 * @param windowMap        keyvalue containing windows.
 * @param aggregationMap   keyvalue containing aggregation runtimes.
 * @return StoreQueryRuntime
 */
public static StoreQueryRuntime parse(StoreQuery storeQuery, SiddhiAppContext siddhiAppContext, Map<String, Table> tableMap, Map<String, Window> windowMap, Map<String, AggregationRuntime> aggregationMap) {
    String queryName = "store_query_" + storeQuery.getInputStore().getStoreId();
    InputStore inputStore = storeQuery.getInputStore();
    int metaPosition = SiddhiConstants.UNKNOWN_STATE;
    Within within = null;
    Expression per = null;
    try {
        SnapshotService.getSkipSnapshotableThreadLocal().set(true);
        Expression onCondition = Expression.value(true);
        MetaStreamEvent metaStreamEvent = new MetaStreamEvent();
        metaStreamEvent.setInputReferenceId(inputStore.getStoreReferenceId());
        if (inputStore instanceof AggregationInputStore) {
            AggregationInputStore aggregationInputStore = (AggregationInputStore) inputStore;
            if (aggregationMap.get(inputStore.getStoreId()) == null) {
                throw new StoreQueryCreationException("Aggregation \"" + inputStore.getStoreId() + "\" has not been defined");
            }
            if (aggregationInputStore.getPer() != null && aggregationInputStore.getWithin() != null) {
                within = aggregationInputStore.getWithin();
                per = aggregationInputStore.getPer();
            } else if (aggregationInputStore.getPer() != null || aggregationInputStore.getWithin() != null) {
                throw new StoreQueryCreationException(inputStore.getStoreId() + " should either have both 'within' and 'per' defined or none.");
            }
            if (((AggregationInputStore) inputStore).getOnCondition() != null) {
                onCondition = ((AggregationInputStore) inputStore).getOnCondition();
            }
        } else if (inputStore instanceof ConditionInputStore) {
            if (((ConditionInputStore) inputStore).getOnCondition() != null) {
                onCondition = ((ConditionInputStore) inputStore).getOnCondition();
            }
        }
        List<VariableExpressionExecutor> variableExpressionExecutors = new ArrayList<>();
        Table table = tableMap.get(inputStore.getStoreId());
        if (table != null) {
            return constructStoreQueryRuntime(table, storeQuery, siddhiAppContext, tableMap, queryName, metaPosition, onCondition, metaStreamEvent, variableExpressionExecutors);
        } else {
            AggregationRuntime aggregation = aggregationMap.get(inputStore.getStoreId());
            if (aggregation != null) {
                return constructStoreQueryRuntime(aggregation, storeQuery, siddhiAppContext, tableMap, queryName, within, per, onCondition, metaStreamEvent, variableExpressionExecutors);
            } else {
                Window window = windowMap.get(inputStore.getStoreId());
                if (window != null) {
                    return constructStoreQueryRuntime(window, storeQuery, siddhiAppContext, tableMap, queryName, metaPosition, onCondition, metaStreamEvent, variableExpressionExecutors);
                } else {
                    throw new StoreQueryCreationException(inputStore.getStoreId() + " is neither a table, aggregation or window");
                }
            }
        }
    } finally {
        SnapshotService.getSkipSnapshotableThreadLocal().set(null);
    }
}
Also used : Window(org.wso2.siddhi.core.window.Window) Table(org.wso2.siddhi.core.table.Table) VariableExpressionExecutor(org.wso2.siddhi.core.executor.VariableExpressionExecutor) ArrayList(java.util.ArrayList) AggregationInputStore(org.wso2.siddhi.query.api.execution.query.input.store.AggregationInputStore) Expression(org.wso2.siddhi.query.api.expression.Expression) ConditionInputStore(org.wso2.siddhi.query.api.execution.query.input.store.ConditionInputStore) AggregationInputStore(org.wso2.siddhi.query.api.execution.query.input.store.AggregationInputStore) InputStore(org.wso2.siddhi.query.api.execution.query.input.store.InputStore) ConditionInputStore(org.wso2.siddhi.query.api.execution.query.input.store.ConditionInputStore) Within(org.wso2.siddhi.query.api.aggregation.Within) StoreQueryCreationException(org.wso2.siddhi.core.exception.StoreQueryCreationException) MetaStreamEvent(org.wso2.siddhi.core.event.stream.MetaStreamEvent) AggregationRuntime(org.wso2.siddhi.core.aggregation.AggregationRuntime)

Example 2 with StoreQueryCreationException

use of org.wso2.siddhi.core.exception.StoreQueryCreationException in project siddhi by wso2.

the class SiddhiAppRuntime method getStoreQueryOutputAttributes.

/**
 * This method get the storeQuery and return the corresponding output and its types.
 *
 * @param storeQuery       this storeQuery is processed and get the output attributes.
 * @param storeQueryString this passed to report errors with context if there are any.
 * @return List of output attributes
 */
private Attribute[] getStoreQueryOutputAttributes(StoreQuery storeQuery, String storeQueryString) {
    try {
        StoreQueryRuntime storeQueryRuntime = storeQueryRuntimeMap.get(storeQuery);
        if (storeQueryRuntime == null) {
            storeQueryRuntime = StoreQueryParser.parse(storeQuery, siddhiAppContext, tableMap, windowMap, aggregationMap);
            storeQueryRuntimeMap.put(storeQuery, storeQueryRuntime);
        }
        return storeQueryRuntime.getStoreQueryOutputAttributes();
    } catch (RuntimeException e) {
        if (e instanceof SiddhiAppContextException) {
            throw new StoreQueryCreationException(((SiddhiAppContextException) e).getMessageWithOutContext(), e, ((SiddhiAppContextException) e).getQueryContextStartIndex(), ((SiddhiAppContextException) e).getQueryContextEndIndex(), null, siddhiAppContext.getSiddhiAppString());
        }
        throw new StoreQueryCreationException(e.getMessage(), e);
    }
}
Also used : SiddhiAppContextException(org.wso2.siddhi.query.api.exception.SiddhiAppContextException) StoreQueryRuntime(org.wso2.siddhi.core.query.StoreQueryRuntime) StoreQueryCreationException(org.wso2.siddhi.core.exception.StoreQueryCreationException)

Example 3 with StoreQueryCreationException

use of org.wso2.siddhi.core.exception.StoreQueryCreationException in project siddhi by wso2.

the class SiddhiAppRuntime method query.

private Event[] query(StoreQuery storeQuery, String storeQueryString) {
    try {
        if (siddhiAppContext.isStatsEnabled() && storeQueryLatencyTracker != null) {
            storeQueryLatencyTracker.markIn();
        }
        StoreQueryRuntime storeQueryRuntime = storeQueryRuntimeMap.get(storeQuery);
        if (storeQueryRuntime == null) {
            storeQueryRuntime = StoreQueryParser.parse(storeQuery, siddhiAppContext, tableMap, windowMap, aggregationMap);
            storeQueryRuntimeMap.put(storeQuery, storeQueryRuntime);
        } else {
            storeQueryRuntime.reset();
        }
        return storeQueryRuntime.execute();
    } catch (RuntimeException e) {
        if (e instanceof SiddhiAppContextException) {
            throw new StoreQueryCreationException(((SiddhiAppContextException) e).getMessageWithOutContext(), e, ((SiddhiAppContextException) e).getQueryContextStartIndex(), ((SiddhiAppContextException) e).getQueryContextEndIndex(), null, storeQueryString);
        }
        throw new StoreQueryCreationException(e.getMessage(), e);
    } finally {
        if (siddhiAppContext.isStatsEnabled() && storeQueryLatencyTracker != null) {
            storeQueryLatencyTracker.markOut();
        }
    }
}
Also used : SiddhiAppContextException(org.wso2.siddhi.query.api.exception.SiddhiAppContextException) StoreQueryRuntime(org.wso2.siddhi.core.query.StoreQueryRuntime) StoreQueryCreationException(org.wso2.siddhi.core.exception.StoreQueryCreationException)

Aggregations

StoreQueryCreationException (org.wso2.siddhi.core.exception.StoreQueryCreationException)3 StoreQueryRuntime (org.wso2.siddhi.core.query.StoreQueryRuntime)2 SiddhiAppContextException (org.wso2.siddhi.query.api.exception.SiddhiAppContextException)2 ArrayList (java.util.ArrayList)1 AggregationRuntime (org.wso2.siddhi.core.aggregation.AggregationRuntime)1 MetaStreamEvent (org.wso2.siddhi.core.event.stream.MetaStreamEvent)1 VariableExpressionExecutor (org.wso2.siddhi.core.executor.VariableExpressionExecutor)1 Table (org.wso2.siddhi.core.table.Table)1 Window (org.wso2.siddhi.core.window.Window)1 Within (org.wso2.siddhi.query.api.aggregation.Within)1 AggregationInputStore (org.wso2.siddhi.query.api.execution.query.input.store.AggregationInputStore)1 ConditionInputStore (org.wso2.siddhi.query.api.execution.query.input.store.ConditionInputStore)1 InputStore (org.wso2.siddhi.query.api.execution.query.input.store.InputStore)1 Expression (org.wso2.siddhi.query.api.expression.Expression)1