Search in sources :

Example 11 with QueryResolverException

use of org.teiid.api.exception.query.QueryResolverException 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 12 with QueryResolverException

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

the class TestValidator method testDefect9917.

@Test
public void testDefect9917() throws Exception {
    QueryMetadataInterface metadata = RealMetadataFactory.example1Cached();
    // $NON-NLS-1$
    String sql = "SELECT lookup('pm1.g1', 'e1a', 'e2', e2) AS x, lookup('pm1.g1', 'e4', 'e3', e3) AS y FROM pm1.g1";
    Command command = new QueryParser().parseCommand(sql);
    try {
        QueryResolver.resolveCommand(command, metadata);
        // $NON-NLS-1$
        fail("Did not get exception");
    } catch (QueryResolverException e) {
    // expected
    }
    // $NON-NLS-1$
    sql = "SELECT lookup('pm1.g1a', 'e1', 'e2', e2) AS x, lookup('pm1.g1', 'e4', 'e3', e3) AS y FROM pm1.g1";
    command = new QueryParser().parseCommand(sql);
    try {
        QueryResolver.resolveCommand(command, metadata);
        // $NON-NLS-1$
        fail("Did not get exception");
    } catch (QueryResolverException e) {
    // expected
    }
}
Also used : QueryParser(org.teiid.query.parser.QueryParser) Command(org.teiid.query.sql.lang.Command) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) QueryResolverException(org.teiid.api.exception.query.QueryResolverException) Test(org.junit.Test)

Example 13 with QueryResolverException

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

the class TestResolver method testLookupFunctionFailBadKeyElement.

@Test
public void testLookupFunctionFailBadKeyElement() throws Exception {
    // $NON-NLS-1$
    String sql = "SELECT lookup('pm1.g1', 'e1', 'x', e2) AS x, lookup('pm1.g1', 'e4', 'e3', e3) AS y FROM pm1.g1";
    Command command = QueryParser.getQueryParser().parseCommand(sql);
    try {
        QueryResolver.resolveCommand(command, metadata);
        // $NON-NLS-1$
        fail("exception expected");
    } catch (QueryResolverException e) {
    }
}
Also used : CreateProcedureCommand(org.teiid.query.sql.proc.CreateProcedureCommand) QueryResolverException(org.teiid.api.exception.query.QueryResolverException) Test(org.junit.Test)

Example 14 with QueryResolverException

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

the class TestFunctionResolving method testAmbiguousUDF.

@Test
public void testAmbiguousUDF() throws Exception {
    TransformationMetadata tm = RealMetadataFactory.fromDDL("x", new DDLHolder("y", "create foreign function f () returns string"), new DDLHolder("z", "create foreign function f () returns string"));
    String sql = "f()";
    Function func = (Function) QueryParser.getQueryParser().parseExpression(sql);
    try {
        ResolverVisitor.resolveLanguageObject(func, tm);
        fail();
    } catch (QueryResolverException e) {
    }
    sql = "z.f()";
    func = (Function) QueryParser.getQueryParser().parseExpression(sql);
    ResolverVisitor.resolveLanguageObject(func, tm);
}
Also used : Function(org.teiid.query.sql.symbol.Function) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) DDLHolder(org.teiid.query.unittest.RealMetadataFactory.DDLHolder) QueryResolverException(org.teiid.api.exception.query.QueryResolverException) Test(org.junit.Test)

Example 15 with QueryResolverException

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

the class TestResolver method testStoredQueryTransformationWithVariable4.

@Test
public void testStoredQueryTransformationWithVariable4() throws Exception {
    // $NON-NLS-1$
    Command command = QueryParser.getQueryParser().parseCommand("EXEC pm1.sq2(pm1.sq2.in)");
    // resolve
    try {
        // Construct command metadata
        // $NON-NLS-1$
        GroupSymbol sqGroup = new GroupSymbol("pm1.sq5");
        ArrayList sqParams = new ArrayList();
        // $NON-NLS-1$
        ElementSymbol in = new ElementSymbol("pm1.sq5.in1");
        in.setType(DataTypeManager.DefaultDataClasses.STRING);
        sqParams.add(in);
        Map externalMetadata = new HashMap();
        externalMetadata.put(sqGroup, sqParams);
        QueryResolver.resolveCommand(command, metadata);
        // $NON-NLS-1$
        fail("Expected exception on invalid variable pm1.sq2.in");
    } catch (QueryResolverException e) {
        // $NON-NLS-1$
        assertEquals("TEIID31119 Symbol pm1.sq2.\"in\" is specified with an unknown group context", e.getMessage());
    }
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) CreateProcedureCommand(org.teiid.query.sql.proc.CreateProcedureCommand) HashMap(java.util.HashMap) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) SymbolMap(org.teiid.query.sql.util.SymbolMap) QueryResolverException(org.teiid.api.exception.query.QueryResolverException) Test(org.junit.Test)

Aggregations

QueryResolverException (org.teiid.api.exception.query.QueryResolverException)62 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)13 TempMetadataID (org.teiid.query.metadata.TempMetadataID)11 ExceptionExpression (org.teiid.query.sql.proc.ExceptionExpression)11 ArrayList (java.util.ArrayList)10 Test (org.junit.Test)10 TeiidComponentException (org.teiid.core.TeiidComponentException)10 Expression (org.teiid.query.sql.symbol.Expression)10 QueryMetadataException (org.teiid.api.exception.query.QueryMetadataException)8 CreateProcedureCommand (org.teiid.query.sql.proc.CreateProcedureCommand)7 Command (org.teiid.query.sql.lang.Command)6 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)6 QueryParserException (org.teiid.api.exception.query.QueryParserException)5 TempMetadataStore (org.teiid.query.metadata.TempMetadataStore)5 LanguageObject (org.teiid.query.sql.LanguageObject)5 List (java.util.List)4 UnresolvedSymbolDescription (org.teiid.api.exception.query.UnresolvedSymbolDescription)4 TempMetadataAdapter (org.teiid.query.metadata.TempMetadataAdapter)4 StoredProcedure (org.teiid.query.sql.lang.StoredProcedure)4 HashSet (java.util.HashSet)3