Search in sources :

Example 71 with TranslationUtility

use of org.teiid.cdk.api.TranslationUtility in project teiid by teiid.

the class TestSimpleDBSQLVisitor method testNE.

@Test
public void testNE() throws Exception {
    TransformationMetadata tm = RealMetadataFactory.fromDDL("create foreign table item (\"itemName()\" string, attribute string);", "x", "y");
    TranslationUtility tu = new TranslationUtility(tm);
    Command c = tu.parseCommand("select \"itemname()\" from item where \"itemname()\" <> 'name'");
    SimpleDBSQLVisitor visitor = new SimpleDBSQLVisitor();
    visitor.append(c);
    assertEquals("SELECT itemName() FROM item WHERE itemName() != 'name'", visitor.toString());
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) Command(org.teiid.language.Command) SimpleDBSQLVisitor(org.teiid.translator.simpledb.SimpleDBSQLVisitor) TranslationUtility(org.teiid.cdk.api.TranslationUtility) Test(org.junit.Test)

Example 72 with TranslationUtility

use of org.teiid.cdk.api.TranslationUtility 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 73 with TranslationUtility

use of org.teiid.cdk.api.TranslationUtility in project teiid by teiid.

the class TestSimpleDBSQLVisitor method testSelectCountStar.

@Test
public void testSelectCountStar() throws Exception {
    TransformationMetadata tm = RealMetadataFactory.fromDDL("create foreign table item (\"itemName()\" string, attribute string);", "x", "y");
    TranslationUtility tu = new TranslationUtility(tm);
    Command c = tu.parseCommand("select count(*) from item");
    SimpleDBSQLVisitor visitor = new SimpleDBSQLVisitor();
    visitor.append(c);
    assertEquals("SELECT COUNT(*) FROM item", visitor.toString());
    assertEquals(Arrays.asList("Count"), visitor.getProjectedColumns());
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) Command(org.teiid.language.Command) SimpleDBSQLVisitor(org.teiid.translator.simpledb.SimpleDBSQLVisitor) TranslationUtility(org.teiid.cdk.api.TranslationUtility) Test(org.junit.Test)

Example 74 with TranslationUtility

use of org.teiid.cdk.api.TranslationUtility in project teiid by teiid.

the class TestIckleConversionVisitor method helpUpdate.

private void helpUpdate(MetadataFactory mf, String query, String expected) throws Exception {
    InfinispanExecutionFactory ef = new InfinispanExecutionFactory();
    TransformationMetadata metadata = TestProtobufMetadataProcessor.getTransformationMetadata(mf, ef);
    TranslationUtility utility = new TranslationUtility(metadata);
    Command cmd = utility.parseCommand(query);
    InfinispanUpdateVisitor visitor = new InfinispanUpdateVisitor(new RuntimeMetadataImpl(metadata));
    visitor.append(cmd);
    String actual = null;
    if (cmd instanceof Update) {
        actual = visitor.getUpdateQuery();
    } else {
        actual = visitor.getDeleteQuery();
    }
    assertEquals(expected, actual);
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) Command(org.teiid.language.Command) RuntimeMetadataImpl(org.teiid.dqp.internal.datamgr.RuntimeMetadataImpl) TranslationUtility(org.teiid.cdk.api.TranslationUtility) Update(org.teiid.language.Update)

Example 75 with TranslationUtility

use of org.teiid.cdk.api.TranslationUtility in project teiid by teiid.

the class TestTeiidTableMarsheller method helpExecute.

private IckleConversionVisitor helpExecute(String query) throws Exception {
    MetadataFactory mf = TestProtobufMetadataProcessor.protoMatadata("tables.proto");
    // System.out.println(DDLStringVisitor.getDDLString(mf.getSchema(), null, null));
    InfinispanExecutionFactory ef = new InfinispanExecutionFactory();
    TransformationMetadata metadata = TestProtobufMetadataProcessor.getTransformationMetadata(mf, ef);
    TranslationUtility utility = new TranslationUtility(metadata);
    Select cmd = (Select) utility.parseCommand(query);
    RuntimeMetadata runtimeMetadata = new RuntimeMetadataImpl(metadata);
    IckleConversionVisitor visitor = new IckleConversionVisitor(runtimeMetadata, false);
    visitor.visitNode(cmd);
    visitor.getQuery();
    return visitor;
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) MetadataFactory(org.teiid.metadata.MetadataFactory) RuntimeMetadataImpl(org.teiid.dqp.internal.datamgr.RuntimeMetadataImpl) TranslationUtility(org.teiid.cdk.api.TranslationUtility) Select(org.teiid.language.Select) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata)

Aggregations

TranslationUtility (org.teiid.cdk.api.TranslationUtility)76 Command (org.teiid.language.Command)52 Test (org.junit.Test)45 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)35 ExecutionContext (org.teiid.translator.ExecutionContext)33 RuntimeMetadata (org.teiid.metadata.RuntimeMetadata)26 SimpleDBSQLVisitor (org.teiid.translator.simpledb.SimpleDBSQLVisitor)14 MetadataFactory (org.teiid.metadata.MetadataFactory)13 FunctionTree (org.teiid.query.function.FunctionTree)11 UDFSource (org.teiid.query.function.UDFSource)11 RealMetadataFactory (org.teiid.query.unittest.RealMetadataFactory)11 Before (org.junit.Before)10 LdapContext (javax.naming.ldap.LdapContext)9 ByteArrayInputStream (java.io.ByteArrayInputStream)8 SimpleDBExecutionFactory (org.teiid.translator.simpledb.SimpleDBExecutionFactory)8 List (java.util.List)7 ResultSetExecution (org.teiid.translator.ResultSetExecution)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 DataSource (javax.activation.DataSource)6 WSConnection (org.teiid.translator.WSConnection)6