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());
}
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());
}
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());
}
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);
}
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();
}
Aggregations