Search in sources :

Example 26 with FunctionTree

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

the class TestSimpleDBSQLVisitor method testEvery2.

@Test
public void testEvery2() throws Exception {
    SimpleDBExecutionFactory translator = new SimpleDBExecutionFactory();
    translator.start();
    MetadataFactory mf = TestDDLParser.helpParse("create foreign table item (\"itemName()\" integer, attribute string[]);", "y");
    TransformationMetadata metadata = RealMetadataFactory.createTransformationMetadata(mf.asMetadataStore(), "x", new FunctionTree("foo", new UDFSource(translator.getPushDownFunctions())));
    TranslationUtility tu = new TranslationUtility(metadata);
    Command c = tu.parseCommand("select * from item where simpledb.every(attribute) = '1' or  simpledb.every(attribute) = '2'");
    SimpleDBSQLVisitor visitor = new SimpleDBSQLVisitor();
    visitor.append(c);
    assertEquals("SELECT attribute FROM item WHERE SIMPLEDB.EVERY(attribute) IN ('2', '1')", visitor.toString());
}
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) Command(org.teiid.language.Command) SimpleDBSQLVisitor(org.teiid.translator.simpledb.SimpleDBSQLVisitor) TranslationUtility(org.teiid.cdk.api.TranslationUtility) SimpleDBExecutionFactory(org.teiid.translator.simpledb.SimpleDBExecutionFactory) Test(org.junit.Test)

Example 27 with FunctionTree

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

the class TestSimpleDBSQLVisitor method testEveryLike.

@Test
public void testEveryLike() throws Exception {
    SimpleDBExecutionFactory translator = new SimpleDBExecutionFactory();
    translator.start();
    MetadataFactory mf = TestDDLParser.helpParse("create foreign table item (\"itemName()\" integer, attribute string[]);", "y");
    TransformationMetadata metadata = RealMetadataFactory.createTransformationMetadata(mf.asMetadataStore(), "x", new FunctionTree("foo", new UDFSource(translator.getPushDownFunctions())));
    TranslationUtility tu = new TranslationUtility(metadata);
    Command c = tu.parseCommand("select * from item where simpledb.every(attribute) like '1%'");
    SimpleDBSQLVisitor visitor = new SimpleDBSQLVisitor();
    visitor.append(c);
    assertEquals("SELECT attribute FROM item WHERE SIMPLEDB.EVERY(attribute) LIKE '1%'", visitor.toString());
}
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) Command(org.teiid.language.Command) SimpleDBSQLVisitor(org.teiid.translator.simpledb.SimpleDBSQLVisitor) TranslationUtility(org.teiid.cdk.api.TranslationUtility) SimpleDBExecutionFactory(org.teiid.translator.simpledb.SimpleDBExecutionFactory) Test(org.junit.Test)

Example 28 with FunctionTree

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

the class TestProtobufMetadataProcessor method getTransformationMetadata.

public static TransformationMetadata getTransformationMetadata(MetadataFactory mf, InfinispanExecutionFactory ef) throws Exception {
    TransformationMetadata metadata = RealMetadataFactory.createTransformationMetadata(mf.asMetadataStore(), "proto", 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 29 with FunctionTree

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

the class TestFunctionPushdown method testMustPushdownOverMultipleSources.

@Test
public void testMustPushdownOverMultipleSources() 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 pm1.g1 as x, pm2.g1 as y where x.e2 = y.e2";
    ProcessorPlan plan = helpPlan(sql, metadata, null, capFinder, new String[] { "SELECT g_0.e2 AS c_0, func(g_0.e1) AS c_1 FROM pm1.g1 AS g_0 ORDER BY c_0", "SELECT g_0.e2 AS c_0 FROM pm2.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, func(g_0.e1) AS c_1 FROM pm1.g1 AS g_0 ORDER BY c_0", new List[] { Arrays.asList(1, "a") });
    dataManager.addData("SELECT g_0.e2 AS c_0 FROM pm2.g1 AS g_0 ORDER BY c_0", new List[] { Arrays.asList(1), Arrays.asList(2) });
    CommandContext cc = TestProcessor.createCommandContext();
    cc.setMetadata(metadata);
    TestProcessor.helpProcess(plan, cc, dataManager, new List[] { Arrays.asList("a") });
}
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 30 with FunctionTree

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

the class TestQueryRewriter method testUDFParse.

@Test
public void testUDFParse() throws Exception {
    QueryMetadataInterface metadata = RealMetadataFactory.createTransformationMetadata(RealMetadataFactory.example1Cached().getMetadataStore(), "example1", new FunctionTree("foo", new FakeFunctionMetadataSource()));
    String sql = "parsedate_(pm1.g1.e1) = {d'2001-01-01'}";
    helpTestRewriteCriteria(sql, parseCriteria(sql, metadata), metadata);
}
Also used : FunctionTree(org.teiid.query.function.FunctionTree) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) FakeFunctionMetadataSource(org.teiid.query.optimizer.FakeFunctionMetadataSource) Test(org.junit.Test)

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