use of org.teiid.translator.ResultSetExecution 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();
}
use of org.teiid.translator.ResultSetExecution in project teiid by teiid.
the class TestODataQueryExecution method testSimplePKWhere.
@Test
public void testSimplePKWhere() throws Exception {
String query = "SELECT * FROM Categories Where CategoryId = 3";
String expectedURL = "Categories(3)?$select=CategoryID,CategoryName,Description,Picture";
FileReader reader = new FileReader(UnitTestUtil.getTestDataFile("categories.xml"));
ResultSetExecution excution = helpExecute(query, ObjectConverterUtil.convertToString(reader), expectedURL);
reader.close();
}
use of org.teiid.translator.ResultSetExecution in project teiid by teiid.
the class TestODataQueryExecution method testSimpleWhere.
@Test
public void testSimpleWhere() throws Exception {
String query = "SELECT * FROM Categories Where CategoryName = 'Beverages'";
String expectedURL = "Categories?$filter=CategoryName eq 'Beverages'&$select=CategoryID,CategoryName,Description,Picture";
FileReader reader = new FileReader(UnitTestUtil.getTestDataFile("categories.xml"));
ResultSetExecution excution = helpExecute(query, ObjectConverterUtil.convertToString(reader), expectedURL);
reader.close();
}
use of org.teiid.translator.ResultSetExecution in project teiid by teiid.
the class TestODataQueryExecution method testSimpleSelectStar.
@Test
public void testSimpleSelectStar() throws Exception {
String query = "SELECT * FROM Categories";
String expectedURL = "Categories?$select=CategoryID,CategoryName,Description,Picture";
FileReader reader = new FileReader(UnitTestUtil.getTestDataFile("categories.xml"));
ResultSetExecution excution = helpExecute(query, ObjectConverterUtil.convertToString(reader), expectedURL);
reader.close();
}
use of org.teiid.translator.ResultSetExecution in project teiid by teiid.
the class TestODataQueryExecution method testArrayType.
@Test
public void testArrayType() throws Exception {
ModelMetaData model = new ModelMetaData();
model.setName("nw");
model.setModelType(Type.PHYSICAL);
MetadataFactory mf = new MetadataFactory("northwind", 1, SystemMetadata.getInstance().getRuntimeTypeMap(), model);
EdmDataServices edm = new EdmxFormatParser().parseMetadata(StaxUtil.newXMLEventReader(new FileReader(UnitTestUtil.getTestDataFile("arraytest.xml"))));
ODataMetadataProcessor metadataProcessor = new ODataMetadataProcessor();
// $NON-NLS-1$
PropertiesUtils.setBeanProperties(metadataProcessor, mf.getModelProperties(), "importer");
metadataProcessor.getMetadata(mf, edm);
Column c = mf.getSchema().getTable("G2").getColumnByName("e3");
assertEquals("integer[]", c.getRuntimeType());
Procedure p = mf.getSchema().getProcedure("ARRAYITERATE");
assertEquals("varbinary[]", p.getParameters().get(0).getRuntimeType());
assertEquals("varbinary", p.getResultSet().getColumns().get(0).getRuntimeType());
String ddl = DDLStringVisitor.getDDLString(mf.getSchema(), null, null);
TransformationMetadata metadata = RealMetadataFactory.fromDDL(ddl, "northwind", "nw");
String query = "SELECT * FROM G2";
String expectedURL = "G2?$select=e1,e3";
String result = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<feed xmlns=\"http://www.w3.org/2005/Atom\" xmlns:d=\"http://schemas.microsoft.com/ado/2007/08/dataservices\" xmlns:m=\"http://schemas.microsoft.com/ado/2007/08/dataservices/metadata\" xml:base=\"http://localhost:8080/odata/loopy/\">\n" + " <title type=\"text\">VM1.x</title>\n" + " <id>http://localhost:8080/odata/loopy/VM1.x</id>\n" + " <updated>2015-10-14T19:36:58Z</updated>\n" + " <link rel=\"self\" title=\"VM1.x\" href=\"VM1.x\" />\n" + " <entry>\n" + " <id>http://localhost:8080/odata/loopy/VM1.x('x')</id>\n" + " <title type=\"text\" />\n" + " <updated>2015-10-14T19:36:58Z</updated>\n" + " <author>\n" + " <name />\n" + " </author>\n" + " <link rel=\"edit\" title=\"x\" href=\"VM1.x('x')\" />\n" + " <category term=\"PM1.G2\" scheme=\"http://schemas.microsoft.com/ado/2007/08/dataservices/scheme\" />\n" + " <content type=\"application/xml\">\n" + " <m:properties>\n" + " <d:e1>32</d:e1>\n" + " <d:e3 m:type=\"Collection(Edm.Int32)\">\n" + " <d:element>1</d:element>\n" + " <d:element>2</d:element>\n" + " <d:element>3</d:element>\n" + " </d:e3>\n" + " </m:properties>\n" + " </content>\n" + " </entry>\n" + "</feed>";
ResultSetExecution excution = helpExecute(query, result, expectedURL, 200, metadata);
assertArrayEquals(new Object[] { 32, new Integer[] { 1, 2, 3 } }, excution.next().toArray(new Object[2]));
}
Aggregations