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