use of org.teiid.metadata.Column in project teiid by teiid.
the class DocumentNode method addProjectedColumn.
protected void addProjectedColumn(final String columnName, final Expression expr) {
EdmPropertyImpl edmProperty = (EdmPropertyImpl) this.edmEntityType.getProperty(columnName);
Column c = getColumnByName(columnName);
ProjectedColumn pc = addProjectedColumn(expr, edmProperty.getType(), edmProperty, edmProperty.isCollection());
pc.setOrdinal(c.getPosition());
}
use of org.teiid.metadata.Column in project teiid by teiid.
the class ODataExpressionToSQLVisitor method visit.
// ///////////////////////////////////////////////////////////////////////
// RequestURLHierarchyVisitor specific methods
// ///////////////////////////////////////////////////////////////////////
@Override
public void visit(UriResourcePrimitiveProperty info) {
if (this.root) {
this.stack.add(new ScalarSubquery(buildRootSubQuery(info.getProperty().getName(), this.ctxExpression)));
root = false;
} else {
this.stack.add(new ElementSymbol(info.getProperty().getName(), this.ctxExpression.getGroupSymbol()));
}
// hack to resolve the property type.
Column c = this.ctxExpression.getColumnByName(info.getProperty().getName());
this.lastPropertyType = c.getRuntimeType();
// revert back to the query context
this.ctxExpression = this.ctxQuery;
}
use of org.teiid.metadata.Column in project teiid by teiid.
the class ComplexDocumentNode method addAllColumns.
@Override
protected void addAllColumns(boolean onlyPK) {
for (final Column column : procedure.getResultSet().getColumns()) {
if (column.isSelectable()) {
EdmReturnType returnType = procedureReturn.getReturnType();
EdmComplexType complexType = (EdmComplexType) returnType.getType();
EdmPropertyImpl edmProperty = (EdmPropertyImpl) complexType.getProperty(column.getName());
addProjectedColumn(new ElementSymbol(column.getName(), getGroupSymbol()), edmProperty.getType(), edmProperty, edmProperty.isCollection());
}
}
}
use of org.teiid.metadata.Column in project teiid by teiid.
the class ODataMetadataProcessor method addEntitySetAsTable.
protected Table addEntitySetAsTable(MetadataFactory mf, EdmEntitySet entitySet) throws TranslatorException {
Table table = buildTable(mf, entitySet);
table.setProperty(ENTITY_TYPE, entitySet.getType().getFullyQualifiedTypeName());
// add columns
for (EdmProperty ep : entitySet.getType().getProperties().toList()) {
if (ep.getType().isSimple() || (ep.getType() instanceof EdmCollectionType && ((EdmCollectionType) ep.getType()).getItemType().isSimple())) {
addPropertyAsColumn(mf, table, ep, entitySet);
} else {
// this is complex type, i.e treat them as embeddable in the same table add all columns.
// Have tried adding this as separate table with 1 to 1 mapping to parent table, however
// that model fails when there are two instances of single complex type as column. This
// creates verbose columns but safe.
EdmComplexType embedded = (EdmComplexType) ep.getType();
for (EdmProperty property : embedded.getProperties().toList()) {
if (property.getType().isSimple() || (property.getType() instanceof EdmCollectionType && ((EdmCollectionType) property.getType()).getItemType().isSimple())) {
Column column = addPropertyAsColumn(mf, table, property, entitySet, ep.getName());
// complex type
column.setProperty(COMPLEX_TYPE, embedded.getFullyQualifiedTypeName());
// name of parent column
column.setProperty(COLUMN_GROUP, ep.getName());
} else {
throw new TranslatorException(ODataPlugin.Util.gs(ODataPlugin.Event.TEIID17002, entitySet.getName(), ep.getName()));
}
}
}
}
// add PK
// $NON-NLS-1$
mf.addPrimaryKey("PK", entitySet.getType().getKeys(), table);
return table;
}
use of org.teiid.metadata.Column 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