Search in sources :

Example 1 with QueryParserException

use of org.teiid.api.exception.query.QueryParserException in project teiid by teiid.

the class EvaluatorIterator method init.

@Override
public void init(SortedKeyValueIterator<Key, Value> source, Map<String, String> options, IteratorEnvironment env) throws IOException {
    super.init(source, options, env);
    try {
        GroupSymbol gs = null;
        String query = options.get(QUERYSTRING);
        TransformationMetadata tm = createTransformationMetadata(options.get(DDL));
        this.criteria = QueryParser.getQueryParser().parseCriteria(query);
        this.elementsInExpression = ElementCollectorVisitor.getElements(this.criteria, false);
        for (ElementSymbol es : this.elementsInExpression) {
            gs = es.getGroupSymbol();
            ResolverUtil.resolveGroup(gs, tm);
        }
        ResolverVisitor.resolveLanguageObject(this.criteria, tm);
        this.evaluatorUtil = new EvaluatorUtil(gs);
    } catch (QueryParserException e) {
        throw new IOException(e);
    } catch (ClassNotFoundException e) {
        throw new IOException(e);
    } catch (QueryResolverException e) {
        throw new IOException(e);
    } catch (TeiidComponentException e) {
        throw new IOException(e);
    }
    CommandContext cc = new CommandContext();
    this.evaluator = new Evaluator(this.evaluatorUtil.getElementMap(), null, cc);
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) QueryParserException(org.teiid.api.exception.query.QueryParserException) CommandContext(org.teiid.query.util.CommandContext) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) TeiidComponentException(org.teiid.core.TeiidComponentException) IOException(java.io.IOException) Evaluator(org.teiid.query.eval.Evaluator) QueryResolverException(org.teiid.api.exception.query.QueryResolverException)

Example 2 with QueryParserException

use of org.teiid.api.exception.query.QueryParserException in project teiid by teiid.

the class TestPreparedPlanCache method helpPutPreparedPlans.

// ====Help methods====//
private void helpPutPreparedPlans(SessionAwareCache<PreparedPlan> cache, DQPWorkContext session, int start, int count) {
    for (int i = 0; i < count; i++) {
        Command dummy;
        try {
            dummy = QueryParser.getQueryParser().parseCommand(EXAMPLE_QUERY + (start + i));
        } catch (QueryParserException e) {
            throw new RuntimeException(e);
        }
        CacheID id = new CacheID(session, pi, dummy.toString());
        PreparedPlan pPlan = new PreparedPlan();
        cache.put(id, Determinism.SESSION_DETERMINISTIC, pPlan, null);
        pPlan.setCommand(dummy);
        pPlan.setPlan(new RelationalPlan(new ProjectNode(i)), new CommandContext());
        AnalysisRecord analysisRecord = new AnalysisRecord(true, false);
        pPlan.setAnalysisRecord(analysisRecord);
        ArrayList<Reference> refs = new ArrayList<Reference>();
        refs.add(new Reference(1));
        pPlan.setReferences(refs);
    }
}
Also used : QueryParserException(org.teiid.api.exception.query.QueryParserException) AnalysisRecord(org.teiid.query.analysis.AnalysisRecord) CommandContext(org.teiid.query.util.CommandContext) Reference(org.teiid.query.sql.symbol.Reference) ArrayList(java.util.ArrayList) RelationalPlan(org.teiid.query.processor.relational.RelationalPlan) Command(org.teiid.query.sql.lang.Command) CacheID(org.teiid.dqp.internal.process.SessionAwareCache.CacheID) ProjectNode(org.teiid.query.processor.relational.ProjectNode)

Example 3 with QueryParserException

use of org.teiid.api.exception.query.QueryParserException in project teiid by teiid.

the class QueryResolver method parseBindings.

/**
 * Bindings are a poor mans input parameters.  They are represented in legacy metadata
 * by ElementSymbols and placed positionally into the command or by alias symbols
 * and matched by names.
 * @param planNode
 * @return
 * @throws TeiidComponentException
 */
public static List<Expression> parseBindings(QueryNode planNode) throws TeiidComponentException {
    Collection<String> bindingsCol = planNode.getBindings();
    if (bindingsCol == null) {
        return Collections.emptyList();
    }
    List<Expression> parsedBindings = new ArrayList<Expression>(bindingsCol.size());
    for (Iterator<String> bindings = bindingsCol.iterator(); bindings.hasNext(); ) {
        try {
            Expression binding = QueryParser.getQueryParser().parseSelectExpression(bindings.next());
            parsedBindings.add(binding);
        } catch (QueryParserException err) {
            throw new TeiidComponentException(QueryPlugin.Event.TEIID30063, err);
        }
    }
    return parsedBindings;
}
Also used : QueryParserException(org.teiid.api.exception.query.QueryParserException) Expression(org.teiid.query.sql.symbol.Expression) ArrayList(java.util.ArrayList) TeiidComponentException(org.teiid.core.TeiidComponentException)

Example 4 with QueryParserException

use of org.teiid.api.exception.query.QueryParserException in project teiid by teiid.

the class QueryResolver method resolveView.

public static QueryNode resolveView(GroupSymbol virtualGroup, QueryNode qnode, String cacheString, QueryMetadataInterface qmi, boolean logValidation) throws TeiidComponentException, QueryMetadataException, QueryResolverException, QueryValidatorException {
    qmi = qmi.getDesignTimeMetadata();
    // $NON-NLS-1$
    cacheString = "transformation/" + cacheString;
    QueryNode cachedNode = (QueryNode) qmi.getFromMetadataCache(virtualGroup.getMetadataID(), cacheString);
    if (cachedNode == null) {
        Command result = qnode.getCommand();
        List<String> bindings = null;
        if (result == null) {
            try {
                result = QueryParser.getQueryParser().parseCommand(qnode.getQuery());
            } catch (QueryParserException e) {
                throw new QueryResolverException(QueryPlugin.Event.TEIID30065, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30065, virtualGroup));
            }
            bindings = qnode.getBindings();
        } else {
            result = (Command) result.clone();
        }
        if (bindings != null && !bindings.isEmpty()) {
            QueryResolver.resolveWithBindingMetadata(result, qmi, qnode, true);
        } else {
            QueryResolver.resolveCommand(result, qmi, false);
        }
        Request.validateWithVisitor(new ValidationVisitor(), qmi, result);
        validateProjectedSymbols(virtualGroup, qmi, result);
        cachedNode = new QueryNode(qnode.getQuery());
        cachedNode.setCommand(result);
        if (isView(virtualGroup, qmi)) {
            String updatePlan = qmi.getUpdatePlan(virtualGroup.getMetadataID());
            String deletePlan = qmi.getDeletePlan(virtualGroup.getMetadataID());
            String insertPlan = qmi.getInsertPlan(virtualGroup.getMetadataID());
            // the elements must be against the view and not the alias
            if (virtualGroup.getDefinition() != null) {
                GroupSymbol group = new GroupSymbol(virtualGroup.getNonCorrelationName());
                group.setMetadataID(virtualGroup.getMetadataID());
                virtualGroup = group;
            }
            List<ElementSymbol> elements = ResolverUtil.resolveElementsInGroup(virtualGroup, qmi);
            UpdateValidator validator = new UpdateValidator(qmi, determineType(insertPlan), determineType(updatePlan), determineType(deletePlan));
            validator.validate(result, elements);
            UpdateInfo info = validator.getUpdateInfo();
            if (logValidation && qmi.groupSupports(virtualGroup.getMetadataID(), SupportConstants.Group.UPDATE)) {
                if (info.isInherentInsert() && validator.getInsertReport().hasItems()) {
                    LogManager.logDetail(LogConstants.CTX_QUERY_RESOLVER, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31173, validator.getInsertReport().getFailureMessage(), SQLConstants.Reserved.INSERT, qmi.getFullName(virtualGroup.getMetadataID())));
                }
                if (info.isInherentUpdate() && validator.getUpdateReport().hasItems()) {
                    LogManager.logDetail(LogConstants.CTX_QUERY_RESOLVER, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31173, validator.getUpdateReport().getFailureMessage(), SQLConstants.Reserved.UPDATE, qmi.getFullName(virtualGroup.getMetadataID())));
                }
                if (info.isInherentDelete() && validator.getDeleteReport().hasItems()) {
                    LogManager.logDetail(LogConstants.CTX_QUERY_RESOLVER, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31173, validator.getDeleteReport().getFailureMessage(), SQLConstants.Reserved.DELETE, qmi.getFullName(virtualGroup.getMetadataID())));
                }
            }
            cachedNode.setUpdateInfo(info);
        }
        qmi.addToMetadataCache(virtualGroup.getMetadataID(), cacheString, cachedNode);
    }
    return cachedNode;
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) ValidationVisitor(org.teiid.query.validator.ValidationVisitor) QueryParserException(org.teiid.api.exception.query.QueryParserException) Command(org.teiid.query.sql.lang.Command) QueryNode(org.teiid.query.mapping.relational.QueryNode) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) QueryResolverException(org.teiid.api.exception.query.QueryResolverException) UpdateValidator(org.teiid.query.validator.UpdateValidator) UpdateInfo(org.teiid.query.validator.UpdateValidator.UpdateInfo)

Example 5 with QueryParserException

use of org.teiid.api.exception.query.QueryParserException in project teiid by teiid.

the class QueryParser method convertParserException.

private QueryParserException convertParserException(ParseException pe) {
    if (pe.currentToken == null) {
        List<Token> preceeding = findPreceeding(parser.token, 1);
        if (!preceeding.isEmpty()) {
            pe.currentToken = preceeding.get(0);
        } else {
            pe.currentToken = parser.token;
        }
    }
    QueryParserException qpe = new QueryParserException(QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31100, getMessage(pe, 10)));
    qpe.setParseException(pe);
    return qpe;
}
Also used : QueryParserException(org.teiid.api.exception.query.QueryParserException)

Aggregations

QueryParserException (org.teiid.api.exception.query.QueryParserException)10 QueryResolverException (org.teiid.api.exception.query.QueryResolverException)5 TeiidComponentException (org.teiid.core.TeiidComponentException)4 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)4 ArrayList (java.util.ArrayList)3 Command (org.teiid.query.sql.lang.Command)3 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)3 Expression (org.teiid.query.sql.symbol.Expression)3 IOException (java.io.IOException)2 QueryParser (org.teiid.query.parser.QueryParser)2 CreateProcedureCommand (org.teiid.query.sql.proc.CreateProcedureCommand)2 CommandContext (org.teiid.query.util.CommandContext)2 HashMap (java.util.HashMap)1 QueryMetadataException (org.teiid.api.exception.query.QueryMetadataException)1 BlockedException (org.teiid.common.buffer.BlockedException)1 TeiidException (org.teiid.core.TeiidException)1 TeiidProcessingException (org.teiid.core.TeiidProcessingException)1 CacheID (org.teiid.dqp.internal.process.SessionAwareCache.CacheID)1 Column (org.teiid.metadata.Column)1 Trigger (org.teiid.metadata.Trigger)1