Search in sources :

Example 6 with TranslationUtility

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

the class TestSimpleDBSQLVisitor method testOrderByAllow.

@Test
public void testOrderByAllow() 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 * from item where \"itemName()\" = 'name' order by \"itemName()\"");
    SimpleDBSQLVisitor visitor = new SimpleDBSQLVisitor();
    visitor.append(c);
    visitor.checkExceptions();
    assertEquals("SELECT attribute FROM item WHERE itemName() = 'name' ORDER BY itemName()", 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 7 with TranslationUtility

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

the class TestSimpleDBSQLVisitor method testArrayCompare.

@Test
public void testArrayCompare() 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 attribute = ('1','2')");
    SimpleDBSQLVisitor visitor = new SimpleDBSQLVisitor();
    visitor.append(c);
    assertEquals("SELECT attribute FROM item WHERE attribute = '1' OR attribute = '2'", 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 8 with TranslationUtility

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

the class TestSimpleDBSQLVisitor method testEvery.

@Test
public void testEvery() 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'");
    SimpleDBSQLVisitor visitor = new SimpleDBSQLVisitor();
    visitor.append(c);
    assertEquals("SELECT attribute FROM item WHERE SIMPLEDB.EVERY(attribute) = '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 9 with TranslationUtility

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

the class TestMongoDBQueryExecution method setUp.

@Before
public void setUp() throws Exception {
    this.translator = new MongoDBExecutionFactory();
    this.translator.setDatabaseVersion("2.6");
    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)

Example 10 with TranslationUtility

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

the class TestMongoDBQueryExecution method testNextWithGroupAndOrder.

@Test
public void testNextWithGroupAndOrder() throws Exception {
    String query = "select \"FirstName\" from \"TeiidArray\" group by \"FirstName\" order by \"FirstName\" limit 1000";
    String[] expectedCollection = new String[] { "TeiidArray" };
    TransformationMetadata metadata = RealMetadataFactory.fromDDL("CREATE FOREIGN TABLE TeiidArray (ID String PRIMARY KEY, FirstName varchar(25), LastName varchar(25), Score object[]) OPTIONS(UPDATABLE 'TRUE');", "x", "y");
    TranslationUtility util = new TranslationUtility(metadata);
    Command cmd = util.parseCommand(query);
    ExecutionContext context = Mockito.mock(ExecutionContext.class);
    Mockito.stub(context.getBatchSize()).toReturn(256);
    MongoDBConnection connection = Mockito.mock(MongoDBConnection.class);
    DB db = Mockito.mock(DB.class);
    DBCollection dbCollection = Mockito.mock(DBCollection.class);
    for (String collection : expectedCollection) {
        Mockito.stub(db.getCollection(collection)).toReturn(dbCollection);
    }
    Cursor c = Mockito.mock(Cursor.class);
    Mockito.stub(c.hasNext()).toAnswer(new Answer<Boolean>() {

        boolean next = true;

        @Override
        public Boolean answer(InvocationOnMock invocation) throws Throwable {
            if (next) {
                next = false;
                return true;
            }
            return false;
        }
    });
    DBObject dbo = Mockito.mock(DBObject.class);
    Mockito.stub(c.next()).toReturn(dbo);
    Mockito.stub(dbCollection.aggregate((List<DBObject>) Mockito.anyList(), (AggregationOptions) Mockito.anyObject())).toReturn(c);
    Mockito.stub(db.collectionExists(Mockito.anyString())).toReturn(true);
    Mockito.stub(connection.getDatabase()).toReturn(db);
    Mockito.stub(db.getCollectionFromString(Mockito.anyString())).toReturn(dbCollection);
    ResultSetExecution execution = this.translator.createResultSetExecution((QueryExpression) cmd, context, util.createRuntimeMetadata(), connection);
    execution.execute();
    execution.next();
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) TranslationUtility(org.teiid.cdk.api.TranslationUtility) ResultSetExecution(org.teiid.translator.ResultSetExecution) ExecutionContext(org.teiid.translator.ExecutionContext) Command(org.teiid.language.Command) MongoDBConnection(org.teiid.mongodb.MongoDBConnection) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Test(org.junit.Test)

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