Search in sources :

Example 16 with FunctionTree

use of org.teiid.query.function.FunctionTree in project teiid by teiid.

the class TestFunctionPushdown method testMustPushdownOverMultipleSourcesWithView.

@Test
public void testMustPushdownOverMultipleSourcesWithView() throws Exception {
    QueryMetadataInterface metadata = RealMetadataFactory.createTransformationMetadata(RealMetadataFactory.example1Cached().getMetadataStore(), "example1", new FunctionTree("foo", new FakeFunctionMetadataSource()));
    FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
    BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
    caps.setFunctionSupport("misc.namespace.func", true);
    // $NON-NLS-1$
    capFinder.addCapabilities("pm1", caps);
    // $NON-NLS-1$
    capFinder.addCapabilities("pm2", caps);
    // $NON-NLS-1$
    String sql = "select func(x.e1) from (select x.* from pm1.g1 as x, pm2.g1 as y where x.e2 = y.e2 order by e1 limit 10) as x";
    ProcessorPlan plan = helpPlan(sql, metadata, null, capFinder, new String[] { "SELECT g_0.e2 AS c_0 FROM pm2.g1 AS g_0 ORDER BY c_0", "SELECT g_0.e2 AS c_0, func(g_0.e1) AS c_1, g_0.e1 AS c_2 FROM pm1.g1 AS g_0 ORDER BY c_0" }, // $NON-NLS-1$
    ComparisonMode.EXACT_COMMAND_STRING);
    HardcodedDataManager dataManager = new HardcodedDataManager();
    dataManager.addData("SELECT g_0.e2 AS c_0 FROM pm2.g1 AS g_0 ORDER BY c_0", new List[] { Arrays.asList(1) });
    dataManager.addData("SELECT g_0.e2 AS c_0, func(g_0.e1) AS c_1, g_0.e1 AS c_2 FROM pm1.g1 AS g_0 ORDER BY c_0", new List[] { Arrays.asList(1, "aa", "a"), Arrays.asList(2, "bb", "b") });
    CommandContext cc = TestProcessor.createCommandContext();
    cc.setMetadata(metadata);
    TestProcessor.helpProcess(plan, cc, dataManager, new List[] { Arrays.asList("aa") });
}
Also used : FakeCapabilitiesFinder(org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder) FunctionTree(org.teiid.query.function.FunctionTree) CommandContext(org.teiid.query.util.CommandContext) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) FakeFunctionMetadataSource(org.teiid.query.optimizer.FakeFunctionMetadataSource) Test(org.junit.Test)

Example 17 with FunctionTree

use of org.teiid.query.function.FunctionTree in project teiid by teiid.

the class TestFunctionPushdown method testMustPushdownOverMultipleSourcesWithoutSupport.

@Test
public void testMustPushdownOverMultipleSourcesWithoutSupport() throws Exception {
    QueryMetadataInterface metadata = RealMetadataFactory.createTransformationMetadata(RealMetadataFactory.example1Cached().getMetadataStore(), "example1", new FunctionTree("foo", new FakeFunctionMetadataSource()));
    FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
    BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
    // $NON-NLS-1$
    capFinder.addCapabilities("pm1", caps);
    // $NON-NLS-1$
    capFinder.addCapabilities("pm2", caps);
    // $NON-NLS-1$
    String sql = "select func(x.e1) from pm1.g1 as x, pm2.g1 as y where x.e2 = y.e2";
    helpPlan(sql, metadata, null, capFinder, new String[] {}, // $NON-NLS-1$
    ComparisonMode.FAILED_PLANNING);
}
Also used : FakeCapabilitiesFinder(org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder) FunctionTree(org.teiid.query.function.FunctionTree) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) FakeFunctionMetadataSource(org.teiid.query.optimizer.FakeFunctionMetadataSource) Test(org.junit.Test)

Example 18 with FunctionTree

use of org.teiid.query.function.FunctionTree 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)

Example 19 with FunctionTree

use of org.teiid.query.function.FunctionTree in project teiid by teiid.

the class TestODataMetadataProcessor method getTransformationMetadata.

public static TransformationMetadata getTransformationMetadata(MetadataFactory mf, ODataExecutionFactory ef) throws Exception {
    TransformationMetadata metadata = RealMetadataFactory.createTransformationMetadata(mf.asMetadataStore(), "trippin", new FunctionTree("foo", new UDFSource(ef.getPushDownFunctions())));
    ValidatorReport report = new MetadataValidator().validate(metadata.getVdbMetaData(), metadata.getMetadataStore());
    if (report.hasItems()) {
        throw new RuntimeException(report.getFailureMessage());
    }
    return metadata;
}
Also used : UDFSource(org.teiid.query.function.UDFSource) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) FunctionTree(org.teiid.query.function.FunctionTree) MetadataValidator(org.teiid.query.metadata.MetadataValidator) ValidatorReport(org.teiid.query.validator.ValidatorReport)

Example 20 with FunctionTree

use of org.teiid.query.function.FunctionTree in project teiid by teiid.

the class TestMongoDBSelectVisitor method setUp.

@Before
public void setUp() throws Exception {
    this.translator = new MongoDBExecutionFactory();
    this.translator.start();
    MetadataFactory mf = TestDDLParser.helpParse(ObjectConverterUtil.convertFileToString(UnitTestUtil.getTestDataFile("northwind.ddl")), "northwind");
    TransformationMetadata metadata = RealMetadataFactory.createTransformationMetadata(mf.asMetadataStore(), "sakila", new FunctionTree("mongo", new UDFSource(translator.getPushDownFunctions())));
    ValidatorReport report = new MetadataValidator().validate(metadata.getVdbMetaData(), metadata.getMetadataStore());
    if (report.hasItems()) {
        throw new RuntimeException(report.getFailureMessage());
    }
    this.utility = new TranslationUtility(metadata);
}
Also used : UDFSource(org.teiid.query.function.UDFSource) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) FunctionTree(org.teiid.query.function.FunctionTree) RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) TranslationUtility(org.teiid.cdk.api.TranslationUtility) MetadataValidator(org.teiid.query.metadata.MetadataValidator) ValidatorReport(org.teiid.query.validator.ValidatorReport) Before(org.junit.Before)

Aggregations

FunctionTree (org.teiid.query.function.FunctionTree)33 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)22 UDFSource (org.teiid.query.function.UDFSource)21 Test (org.junit.Test)19 MetadataFactory (org.teiid.metadata.MetadataFactory)15 RealMetadataFactory (org.teiid.query.unittest.RealMetadataFactory)14 TranslationUtility (org.teiid.cdk.api.TranslationUtility)11 MetadataValidator (org.teiid.query.metadata.MetadataValidator)10 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)10 ValidatorReport (org.teiid.query.validator.ValidatorReport)10 FakeFunctionMetadataSource (org.teiid.query.optimizer.FakeFunctionMetadataSource)9 BasicSourceCapabilities (org.teiid.query.optimizer.capabilities.BasicSourceCapabilities)8 FakeCapabilitiesFinder (org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder)8 SimpleDBExecutionFactory (org.teiid.translator.simpledb.SimpleDBExecutionFactory)8 Command (org.teiid.language.Command)7 SimpleDBSQLVisitor (org.teiid.translator.simpledb.SimpleDBSQLVisitor)7 Properties (java.util.Properties)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 InputStreamReader (java.io.InputStreamReader)3 ArrayList (java.util.ArrayList)3