Search in sources :

Example 36 with TeiidComponentException

use of org.teiid.core.TeiidComponentException in project teiid by teiid.

the class ResolverVisitor method resolveLanguageObject.

public static void resolveLanguageObject(LanguageObject obj, Collection<GroupSymbol> groups, GroupContext externalContext, QueryMetadataInterface metadata) throws TeiidComponentException, QueryResolverException {
    if (obj == null) {
        return;
    }
    // Resolve elements, deal with errors
    final ResolverVisitor elementsVisitor = new ResolverVisitor(metadata, groups, externalContext);
    // special handling for is distinct - we must resolve as both element and group
    // until we generalize the notion of a scalar group reference as an "elementsymbol"
    PostOrderNavigator nav = new PostOrderNavigator(elementsVisitor) {

        @Override
        public void visit(IsDistinctCriteria obj) {
            obj.setLeftRowValue(resolveAsGroup(obj.getLeftRowValue()));
            obj.setRightRowValue(resolveAsGroup(obj.getRightRowValue()));
            super.visit(obj);
        }

        private LanguageObject resolveAsGroup(LanguageObject rowValue) {
            if (rowValue instanceof ElementSymbol) {
                ElementSymbol es = (ElementSymbol) rowValue;
                if (es.getMetadataID() == null) {
                    try {
                        elementsVisitor.resolveElementSymbol(es);
                    } catch (QueryResolverException | TeiidComponentException e) {
                        GroupSymbol gs = new GroupSymbol(es.getName());
                        try {
                            ResolverUtil.resolveGroup(gs, metadata);
                            rowValue = gs;
                        } catch (QueryResolverException | TeiidComponentException e1) {
                        }
                    }
                }
            }
            return rowValue;
        }
    };
    obj.acceptVisitor(nav);
    elementsVisitor.throwException(true);
}
Also used : PostOrderNavigator(org.teiid.query.sql.navigator.PostOrderNavigator) TeiidComponentException(org.teiid.core.TeiidComponentException) LanguageObject(org.teiid.query.sql.LanguageObject) QueryResolverException(org.teiid.api.exception.query.QueryResolverException)

Example 37 with TeiidComponentException

use of org.teiid.core.TeiidComponentException in project teiid by teiid.

the class QueryRewriter method rewriteSelectInto.

/**
 * This method will alias each of the select into elements to the corresponding column name in the
 * target table.  This ensures that they will all be uniquely named.
 *
 * @param query
 * @throws QueryValidatorException
 */
private Command rewriteSelectInto(Query query) throws TeiidProcessingException {
    Into into = query.getInto();
    try {
        List<ElementSymbol> allIntoElements = Util.deepClone(ResolverUtil.resolveElementsInGroup(into.getGroup(), metadata), ElementSymbol.class);
        Insert insert = new Insert(into.getGroup(), allIntoElements, Collections.emptyList());
        insert.setSourceHint(query.getSourceHint());
        query.setSourceHint(null);
        query.setInto(null);
        insert.setQueryExpression(query);
        return rewriteInsert(correctDatatypes(insert));
    } catch (QueryMetadataException e) {
        throw new QueryValidatorException(e);
    } catch (TeiidComponentException e) {
        throw new QueryValidatorException(e);
    }
}
Also used : QueryValidatorException(org.teiid.api.exception.query.QueryValidatorException) TeiidComponentException(org.teiid.core.TeiidComponentException) QueryMetadataException(org.teiid.api.exception.query.QueryMetadataException)

Example 38 with TeiidComponentException

use of org.teiid.core.TeiidComponentException in project teiid by teiid.

the class TestFunctionPushdown method testSimpleFunctionPushdown.

@Test
public void testSimpleFunctionPushdown() throws Exception {
    TransformationMetadata tm = RealMetadataFactory.fromDDL("create foreign function func (param integer) returns integer; create foreign table g1 (e1 integer)", "x", "y");
    BasicSourceCapabilities bsc = new BasicSourceCapabilities();
    bsc.setCapabilitySupport(Capability.SELECT_WITHOUT_FROM, true);
    bsc.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, false);
    final DefaultCapabilitiesFinder capFinder = new DefaultCapabilitiesFinder(bsc);
    CommandContext cc = TestProcessor.createCommandContext();
    cc.setQueryProcessorFactory(new QueryProcessor.ProcessorFactory() {

        @Override
        public PreparedPlan getPreparedPlan(String query, String recursionGroup, CommandContext commandContext, QueryMetadataInterface metadata) throws TeiidProcessingException, TeiidComponentException {
            return null;
        }

        @Override
        public CapabilitiesFinder getCapabiltiesFinder() {
            return capFinder;
        }

        @Override
        public QueryProcessor createQueryProcessor(String query, String recursionGroup, CommandContext commandContext, Object... params) throws TeiidProcessingException, TeiidComponentException {
            // TODO Auto-generated method stub
            return null;
        }
    });
    cc.setMetadata(tm);
    // $NON-NLS-1$
    String sql = "select func(1)";
    ProcessorPlan plan = helpPlan(sql, tm, null, capFinder, new String[] {}, // $NON-NLS-1$
    ComparisonMode.EXACT_COMMAND_STRING);
    HardcodedDataManager dataManager = new HardcodedDataManager(tm);
    dataManager.addData("SELECT func(1)", new List[] { Arrays.asList(2) });
    TestProcessor.helpProcess(plan, cc, dataManager, new List[] { Arrays.asList(2) });
    // ensure that pseudo-correlation works
    // $NON-NLS-1$
    sql = "select func(0) from g1 where func(e1) = 2";
    plan = helpPlan(sql, tm, null, capFinder, new String[] { "SELECT y.g1.e1 FROM y.g1" }, // $NON-NLS-1$
    ComparisonMode.EXACT_COMMAND_STRING);
    dataManager = new HardcodedDataManager();
    dataManager.addData("SELECT y.g1.e1 FROM y.g1", new List[] { Arrays.asList(1), Arrays.asList(2) });
    dataManager.addData("SELECT func(0)", new List[] { Arrays.asList(1) });
    dataManager.addData("SELECT func(1)", new List[] { Arrays.asList(2) });
    dataManager.addData("SELECT func(2)", new List[] { Arrays.asList(3) });
    TestProcessor.helpProcess(plan, cc, dataManager, new List[] { Arrays.asList(1) });
    bsc.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
    // ensure that pseudo-correlation works
    // $NON-NLS-1$
    sql = "select case when hasrole('x') then func(0) else 2 end from g1";
    plan = helpPlan(sql, tm, null, capFinder, new String[] { "SELECT func(0) FROM y.g1" }, // $NON-NLS-1$
    ComparisonMode.EXACT_COMMAND_STRING);
    dataManager = new HardcodedDataManager(tm);
    dataManager.addData("SELECT func(0) FROM g1", new List[] { Arrays.asList(1), Arrays.asList(1) });
    TestProcessor.helpProcess(plan, cc, dataManager, new List[] { Arrays.asList(1), Arrays.asList(1) });
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) CommandContext(org.teiid.query.util.CommandContext) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) TeiidProcessingException(org.teiid.core.TeiidProcessingException) FakeCapabilitiesFinder(org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder) CapabilitiesFinder(org.teiid.query.optimizer.capabilities.CapabilitiesFinder) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) PreparedPlan(org.teiid.dqp.internal.process.PreparedPlan) TeiidComponentException(org.teiid.core.TeiidComponentException) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) Test(org.junit.Test)

Example 39 with TeiidComponentException

use of org.teiid.core.TeiidComponentException in project teiid by teiid.

the class TestFunctionPushdown method testMustPushdownSubexpressionOverGrouping.

@Test
public void testMustPushdownSubexpressionOverGrouping() throws Exception {
    TransformationMetadata tm = RealMetadataFactory.fromDDL("create foreign function func (param integer) returns integer; create foreign table g1 (e1 integer, e2 integer)", "x", "y");
    BasicSourceCapabilities bsc = new BasicSourceCapabilities();
    bsc.setCapabilitySupport(Capability.SELECT_WITHOUT_FROM, true);
    bsc.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
    final DefaultCapabilitiesFinder capFinder = new DefaultCapabilitiesFinder(bsc);
    CommandContext cc = TestProcessor.createCommandContext();
    cc.setQueryProcessorFactory(new QueryProcessor.ProcessorFactory() {

        @Override
        public PreparedPlan getPreparedPlan(String query, String recursionGroup, CommandContext commandContext, QueryMetadataInterface metadata) throws TeiidProcessingException, TeiidComponentException {
            return null;
        }

        @Override
        public CapabilitiesFinder getCapabiltiesFinder() {
            return capFinder;
        }

        @Override
        public QueryProcessor createQueryProcessor(String query, String recursionGroup, CommandContext commandContext, Object... params) throws TeiidProcessingException, TeiidComponentException {
            // TODO Auto-generated method stub
            return null;
        }
    });
    cc.setMetadata(tm);
    // $NON-NLS-1$
    String sql = "select max(func(e2)) from g1 group by e1";
    ProcessorPlan plan = helpPlan(sql, tm, null, capFinder, new String[] { "SELECT y.g1.e1, func(y.g1.e2) FROM y.g1" }, // $NON-NLS-1$
    ComparisonMode.EXACT_COMMAND_STRING);
    HardcodedDataManager dataManager = new HardcodedDataManager();
    dataManager.addData("SELECT y.g1.e1, func(y.g1.e2) FROM y.g1", new List[] { Arrays.asList(1, 2), Arrays.asList(2, 3) });
    TestProcessor.helpProcess(plan, cc, dataManager, new List[] { Arrays.asList(2), Arrays.asList(3) });
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) CommandContext(org.teiid.query.util.CommandContext) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) TeiidProcessingException(org.teiid.core.TeiidProcessingException) FakeCapabilitiesFinder(org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder) CapabilitiesFinder(org.teiid.query.optimizer.capabilities.CapabilitiesFinder) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) PreparedPlan(org.teiid.dqp.internal.process.PreparedPlan) TeiidComponentException(org.teiid.core.TeiidComponentException) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) Test(org.junit.Test)

Example 40 with TeiidComponentException

use of org.teiid.core.TeiidComponentException in project teiid by teiid.

the class TestFunctionPushdown method testSimpleFunctionPushdown1.

@Test
public void testSimpleFunctionPushdown1() throws Exception {
    TransformationMetadata tm = RealMetadataFactory.createTransformationMetadata(RealMetadataFactory.example1Cached().getMetadataStore(), "example1", new FunctionTree("foo", new FakeFunctionMetadataSource()));
    BasicSourceCapabilities bsc = new BasicSourceCapabilities();
    bsc.setCapabilitySupport(Capability.SELECT_WITHOUT_FROM, true);
    bsc.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, false);
    bsc.setFunctionSupport("parseDate_", true);
    final DefaultCapabilitiesFinder capFinder = new DefaultCapabilitiesFinder(bsc);
    CommandContext cc = TestProcessor.createCommandContext();
    cc.setQueryProcessorFactory(new QueryProcessor.ProcessorFactory() {

        @Override
        public PreparedPlan getPreparedPlan(String query, String recursionGroup, CommandContext commandContext, QueryMetadataInterface metadata) throws TeiidProcessingException, TeiidComponentException {
            return null;
        }

        @Override
        public CapabilitiesFinder getCapabiltiesFinder() {
            return capFinder;
        }

        @Override
        public QueryProcessor createQueryProcessor(String query, String recursionGroup, CommandContext commandContext, Object... params) throws TeiidProcessingException, TeiidComponentException {
            // TODO Auto-generated method stub
            return null;
        }
    });
    cc.setMetadata(tm);
    // $NON-NLS-1$
    String sql = "select parseDate_('2011-11-11')";
    ProcessorPlan plan = helpPlan(sql, tm, null, capFinder, new String[] {}, // $NON-NLS-1$
    ComparisonMode.EXACT_COMMAND_STRING);
    HardcodedDataManager dataManager = new HardcodedDataManager(tm);
    dataManager.addData("SELECT parsedate_('2011-11-11')", new List[] { Arrays.asList(TimestampUtil.createDate(0, 0, 0)) });
    cc.setDQPWorkContext(RealMetadataFactory.buildWorkContext(tm));
    TestProcessor.helpProcess(plan, cc, dataManager, new List[] { Arrays.asList(TimestampUtil.createDate(0, 0, 0)) });
    // $NON-NLS-1$
    sql = "select misc.namespace.func('2011-11-11')";
    plan = helpPlan(sql, tm, null, capFinder, new String[] {}, // $NON-NLS-1$
    ComparisonMode.EXACT_COMMAND_STRING);
    dataManager = new HardcodedDataManager(tm);
    dataManager.addData("SELECT parseDate_('2011-11-11')", new List[] { Arrays.asList(TimestampUtil.createDate(0, 0, 0)) });
    try {
        TestProcessor.helpProcess(plan, cc, dataManager, new List[] { Arrays.asList(TimestampUtil.createDate(0, 0, 0)) });
        fail();
    } catch (TeiidProcessingException e) {
    // not supported by any source
    }
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) FunctionTree(org.teiid.query.function.FunctionTree) CommandContext(org.teiid.query.util.CommandContext) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) TeiidProcessingException(org.teiid.core.TeiidProcessingException) FakeCapabilitiesFinder(org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder) CapabilitiesFinder(org.teiid.query.optimizer.capabilities.CapabilitiesFinder) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) PreparedPlan(org.teiid.dqp.internal.process.PreparedPlan) TeiidComponentException(org.teiid.core.TeiidComponentException) FakeFunctionMetadataSource(org.teiid.query.optimizer.FakeFunctionMetadataSource) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) Test(org.junit.Test)

Aggregations

TeiidComponentException (org.teiid.core.TeiidComponentException)109 TeiidProcessingException (org.teiid.core.TeiidProcessingException)33 QueryMetadataException (org.teiid.api.exception.query.QueryMetadataException)23 TeiidRuntimeException (org.teiid.core.TeiidRuntimeException)23 ArrayList (java.util.ArrayList)18 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)17 BlockedException (org.teiid.common.buffer.BlockedException)16 IOException (java.io.IOException)15 List (java.util.List)14 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)13 Test (org.junit.Test)12 LanguageObject (org.teiid.query.sql.LanguageObject)12 QueryResolverException (org.teiid.api.exception.query.QueryResolverException)11 CommandContext (org.teiid.query.util.CommandContext)11 QueryValidatorException (org.teiid.api.exception.query.QueryValidatorException)10 ExpressionEvaluationException (org.teiid.api.exception.query.ExpressionEvaluationException)9 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)9 HashMap (java.util.HashMap)7 TeiidException (org.teiid.core.TeiidException)7 LogonException (org.teiid.client.security.LogonException)6