Search in sources :

Example 16 with TransformationMetadata

use of org.teiid.query.metadata.TransformationMetadata 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 17 with TransformationMetadata

use of org.teiid.query.metadata.TransformationMetadata in project teiid by teiid.

the class TestDataEntitySchemaBuilder method testEntityTypeName.

@Test
public void testEntityTypeName() throws Exception {
    String ddl = "CREATE FOREIGN TABLE BookingCollection (\n" + "	carrid bigdecimal NOT NULL,\n" + "	connid string(5) NOT NULL,\n" + "	bookid bigdecimal NOT NULL,\n" + "	LOCCURKEY string(5) NOT NULL,\n" + "	fldate timestamp NOT NULL,\n" + "	PRIMARY KEY(carrid, connid, fldate, bookid)\n" + ") OPTIONS (UPDATABLE TRUE, " + " \"teiid_odata:EntityType\" 'RMTSAMPLEFLIGHT.Booking');";
    TransformationMetadata metadata = RealMetadataFactory.fromDDL(ddl, "northwind", "nw");
    EdmDataServices edm = ODataEntitySchemaBuilder.buildMetadata(metadata.getMetadataStore());
    assertTrue(edm.findEdmEntitySet("nw.BookingCollection") != null);
    assertTrue(edm.findEdmEntityType("nw.RMTSAMPLEFLIGHT.Booking") != null);
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) Test(org.junit.Test)

Example 18 with TransformationMetadata

use of org.teiid.query.metadata.TransformationMetadata in project teiid by teiid.

the class TestDataEntitySchemaBuilder method getNorthwindMetadataFromODataXML.

static TransformationMetadata getNorthwindMetadataFromODataXML() 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("northwind.xml"))));
    ODataMetadataProcessor metadataProcessor = new ODataMetadataProcessor();
    // $NON-NLS-1$
    PropertiesUtils.setBeanProperties(metadataProcessor, mf.getModelProperties(), "importer");
    metadataProcessor.getMetadata(mf, edm);
    String ddl = DDLStringVisitor.getDDLString(mf.getSchema(), null, null);
    TransformationMetadata metadata = RealMetadataFactory.fromDDL(ddl, "northwind", "nw");
    ValidatorReport report = new MetadataValidator().validate(metadata.getVdbMetaData(), metadata.getMetadataStore());
    if (report.hasItems()) {
        throw new RuntimeException(report.getFailureMessage());
    }
    return metadata;
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) EdmxFormatParser(org.odata4j.format.xml.EdmxFormatParser) FileReader(java.io.FileReader) MetadataValidator(org.teiid.query.metadata.MetadataValidator) ValidatorReport(org.teiid.query.validator.ValidatorReport) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData)

Example 19 with TransformationMetadata

use of org.teiid.query.metadata.TransformationMetadata in project teiid by teiid.

the class TestDataEntitySchemaBuilder method testMetadataWithSelfJoin.

@Test
public void testMetadataWithSelfJoin() throws Exception {
    TransformationMetadata metadata = RealMetadataFactory.fromDDL(ObjectConverterUtil.convertFileToString(UnitTestUtil.getTestDataFile("categories.ddl")), "northwind", "nw");
    StringWriter sw = new StringWriter();
    EdmDataServices eds = ODataEntitySchemaBuilder.buildMetadata(metadata.getMetadataStore());
    EdmxFormatWriter.write(eds, sw);
    String expectedXML = "<?xml version=\"1.0\" encoding=\"utf-8\"?><edmx:Edmx Version=\"1.0\" xmlns:edmx=\"http://schemas.microsoft.com/ado/2007/06/edmx\"><edmx:DataServices m:DataServiceVersion=\"2.0\" xmlns:m=\"http://schemas.microsoft.com/ado/2007/08/dataservices/metadata\"><Schema Namespace=\"nw\" xmlns=\"http://schemas.microsoft.com/ado/2008/09/edm\"><EntityType Name=\"Category\"><Key><PropertyRef Name=\"CategoryID\"></PropertyRef></Key><Property Name=\"CategoryID\" Type=\"Edm.Int32\" Nullable=\"false\"></Property><Property Name=\"Name\" Type=\"Edm.String\" Nullable=\"false\" MaxLength=\"25\" FixedLength=\"false\" Unicode=\"true\"></Property><Property Name=\"ParentCategoryID\" Type=\"Edm.Int32\" Nullable=\"false\"></Property><NavigationProperty Name=\"Category\" Relationship=\"nw.Category_FK_CATEGORY_ID\" FromRole=\"Category\" ToRole=\"Category\"></NavigationProperty></EntityType><Association Name=\"Category_FK_CATEGORY_ID\"><End Type=\"nw.Category\" Multiplicity=\"*\" Role=\"Category\"></End><End Type=\"nw.Category\" Multiplicity=\"0..1\" Role=\"Category\"></End><ReferentialConstraint><Principal Role=\"Category\"><PropertyRef Name=\"CategoryID\"></PropertyRef></Principal><Dependent Role=\"Category\"><PropertyRef Name=\"ParentCategoryID\"></PropertyRef></Dependent></ReferentialConstraint></Association><EntityContainer Name=\"nw\" m:IsDefaultEntityContainer=\"false\"><EntitySet Name=\"Category\" EntityType=\"nw.Category\"></EntitySet><AssociationSet Name=\"Category_FK_CATEGORY_ID\" Association=\"nw.Category_FK_CATEGORY_ID\"><End EntitySet=\"Category\" Role=\"Category\"></End><End EntitySet=\"Category\" Role=\"Category\"></End></AssociationSet></EntityContainer></Schema></edmx:DataServices></edmx:Edmx>\n";
    EdmDataServices pds = new EdmxFormatParser().parseMetadata(StaxUtil.newXMLEventReader(new StringReader(expectedXML)));
    assertEquals(eds.getSchemas().size(), pds.getSchemas().size());
    for (int i = 0; i < eds.getSchemas().size(); i++) {
        EdmSchema expected = eds.getSchemas().get(i);
        EdmSchema actual = pds.getSchemas().get(i);
        assertEdmSchema(expected, actual);
    }
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) StringWriter(java.io.StringWriter) StringReader(java.io.StringReader) EdmxFormatParser(org.odata4j.format.xml.EdmxFormatParser) Test(org.junit.Test)

Example 20 with TransformationMetadata

use of org.teiid.query.metadata.TransformationMetadata in project teiid by teiid.

the class TestDataEntitySchemaBuilder method testMetadata.

@Test
public void testMetadata() throws Exception {
    TransformationMetadata metadata = RealMetadataFactory.fromDDL(ObjectConverterUtil.convertFileToString(UnitTestUtil.getTestDataFile("northwind.ddl")), "northwind", "nw");
    StringWriter sw = new StringWriter();
    EdmDataServices eds = ODataEntitySchemaBuilder.buildMetadata(metadata.getMetadataStore());
    EdmxFormatWriter.write(eds, sw);
    // System.out.println(sw.toString());
    EdmDataServices pds = new EdmxFormatParser().parseMetadata(StaxUtil.newXMLEventReader(new StringReader(sw.toString())));
    assertEquals(eds.getSchemas().size(), pds.getSchemas().size());
    for (int i = 0; i < eds.getSchemas().size(); i++) {
        EdmSchema expected = eds.getSchemas().get(i);
        EdmSchema actual = pds.getSchemas().get(i);
        assertEdmSchema(expected, actual);
    }
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) StringWriter(java.io.StringWriter) StringReader(java.io.StringReader) EdmxFormatParser(org.odata4j.format.xml.EdmxFormatParser) Test(org.junit.Test)

Aggregations

TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)427 Test (org.junit.Test)352 BasicSourceCapabilities (org.teiid.query.optimizer.capabilities.BasicSourceCapabilities)163 ProcessorPlan (org.teiid.query.processor.ProcessorPlan)108 FakeCapabilitiesFinder (org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder)97 DefaultCapabilitiesFinder (org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder)89 List (java.util.List)83 CommandContext (org.teiid.query.util.CommandContext)64 HardcodedDataManager (org.teiid.query.processor.HardcodedDataManager)63 ArrayList (java.util.ArrayList)56 TranslationUtility (org.teiid.cdk.api.TranslationUtility)35 MetadataFactory (org.teiid.metadata.MetadataFactory)35 FakeDataManager (org.teiid.query.processor.FakeDataManager)35 RealMetadataFactory (org.teiid.query.unittest.RealMetadataFactory)35 Schema (org.teiid.metadata.Schema)33 Table (org.teiid.metadata.Table)27 FunctionTree (org.teiid.query.function.FunctionTree)22 Column (org.teiid.metadata.Column)21 Command (org.teiid.language.Command)20 UDFSource (org.teiid.query.function.UDFSource)20