Search in sources :

Example 6 with ResultSetExecution

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

Example 7 with ResultSetExecution

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();
}
Also used : ResultSetExecution(org.teiid.translator.ResultSetExecution) FileReader(java.io.FileReader) Test(org.junit.Test)

Example 8 with ResultSetExecution

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();
}
Also used : ResultSetExecution(org.teiid.translator.ResultSetExecution) FileReader(java.io.FileReader) Test(org.junit.Test)

Example 9 with ResultSetExecution

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();
}
Also used : ResultSetExecution(org.teiid.translator.ResultSetExecution) FileReader(java.io.FileReader) Test(org.junit.Test)

Example 10 with ResultSetExecution

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]));
}
Also used : ResultSetExecution(org.teiid.translator.ResultSetExecution) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) Column(org.teiid.metadata.Column) EdmxFormatParser(org.odata4j.format.xml.EdmxFormatParser) Procedure(org.teiid.metadata.Procedure) EdmDataServices(org.odata4j.edm.EdmDataServices) FileReader(java.io.FileReader) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) Test(org.junit.Test)

Aggregations

ResultSetExecution (org.teiid.translator.ResultSetExecution)50 Test (org.junit.Test)41 ExecutionContext (org.teiid.translator.ExecutionContext)22 FileReader (java.io.FileReader)19 Command (org.teiid.language.Command)17 RuntimeMetadata (org.teiid.metadata.RuntimeMetadata)15 QueryExpression (org.teiid.language.QueryExpression)12 List (java.util.List)11 ArrayList (java.util.ArrayList)10 TranslatorException (org.teiid.translator.TranslatorException)10 ExecutionFactory (org.teiid.translator.ExecutionFactory)8 TranslationUtility (org.teiid.cdk.api.TranslationUtility)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 Connection (java.sql.Connection)4 ResultSet (java.sql.ResultSet)4 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)4 MongoDBConnection (org.teiid.mongodb.MongoDBConnection)4 DataNotAvailableException (org.teiid.translator.DataNotAvailableException)4 UpdateExecution (org.teiid.translator.UpdateExecution)4 DatabaseMetaData (java.sql.DatabaseMetaData)3