Search in sources :

Example 21 with ElementSymbol

use of org.teiid.query.sql.symbol.ElementSymbol in project teiid by teiid.

the class ODataSQLBuilder method update.

public Update update(EdmEntityType entityType, Entity entity, boolean prepared) throws TeiidException {
    Update update = new Update();
    update.setGroup(this.context.getGroupSymbol());
    int i = 0;
    for (Property property : entity.getProperties()) {
        EdmProperty edmProperty = (EdmProperty) entityType.getProperty(property.getName());
        Column column = this.context.getColumnByName(edmProperty.getName());
        ElementSymbol symbol = new ElementSymbol(column.getName(), this.context.getGroupSymbol());
        boolean add = true;
        for (String c : this.context.getKeyColumnNames()) {
            if (c.equals(column.getName())) {
                add = false;
                break;
            }
        }
        if (add) {
            if (prepared) {
                update.addChange(symbol, new Reference(i++));
                this.params.add(asParam(edmProperty, property.getValue()));
            } else {
                update.addChange(symbol, new Constant(asParam(edmProperty, property.getValue()).getValue()));
            }
        }
    }
    update.setCriteria(this.context.getCriteria());
    return update;
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) Column(org.teiid.metadata.Column) Reference(org.teiid.query.sql.symbol.Reference) Constant(org.teiid.query.sql.symbol.Constant) EdmProperty(org.apache.olingo.commons.api.edm.EdmProperty) Property(org.apache.olingo.commons.api.data.Property) EdmNavigationProperty(org.apache.olingo.commons.api.edm.EdmNavigationProperty) EdmProperty(org.apache.olingo.commons.api.edm.EdmProperty) SubqueryHint(org.teiid.query.sql.lang.ExistsCriteria.SubqueryHint)

Example 22 with ElementSymbol

use of org.teiid.query.sql.symbol.ElementSymbol in project teiid by teiid.

the class ODataSQLBuilder method selectWithEntityKey.

// TODO: allow the generated key building.
public Query selectWithEntityKey(EdmEntityType entityType, Entity entity, Map<String, Object> generatedKeys, List<ExpandNode> expand) throws TeiidException {
    Table table = findTable(entityType.getName(), this.metadata);
    DocumentNode resource = new DocumentNode(table, new GroupSymbol(table.getFullName()), entityType);
    resource.setFromClause(new UnaryFromClause(new GroupSymbol(table.getFullName())));
    resource.addAllColumns(false);
    this.context = resource;
    Query query = this.context.buildQuery();
    processExpand(expand, resource, query, 1);
    Criteria criteria = null;
    KeyRecord pk = ODataSchemaBuilder.getIdentifier(table);
    for (Column c : pk.getColumns()) {
        Property prop = entity.getProperty(c.getName());
        Constant right = null;
        if (prop != null) {
            right = new Constant(ODataTypeManager.convertToTeiidRuntimeType(c.getJavaType(), prop.getValue(), null));
        } else {
            Object value = generatedKeys.get(c.getName());
            if (value == null) {
                throw new TeiidProcessingException(ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16016, entityType.getName()));
            }
            right = new Constant(value);
        }
        ElementSymbol left = new ElementSymbol(c.getName(), this.context.getGroupSymbol());
        if (criteria == null) {
            criteria = new CompareCriteria(left, AbstractCompareCriteria.EQ, right);
        } else {
            CompareCriteria rightCC = new CompareCriteria(left, AbstractCompareCriteria.EQ, right);
            criteria = new CompoundCriteria(CompoundCriteria.AND, criteria, rightCC);
        }
    }
    query.setCriteria(criteria);
    return query;
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) Table(org.teiid.metadata.Table) Constant(org.teiid.query.sql.symbol.Constant) TeiidProcessingException(org.teiid.core.TeiidProcessingException) KeyRecord(org.teiid.metadata.KeyRecord) Column(org.teiid.metadata.Column) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) Property(org.apache.olingo.commons.api.data.Property) EdmNavigationProperty(org.apache.olingo.commons.api.edm.EdmNavigationProperty) EdmProperty(org.apache.olingo.commons.api.edm.EdmProperty)

Example 23 with ElementSymbol

use of org.teiid.query.sql.symbol.ElementSymbol in project teiid by teiid.

the class ODataExpressionToSQLVisitor method visit.

@Override
public void visit(UriResourceIt info) {
    if (info.getType() instanceof SingletonPrimitiveType) {
        org.teiid.query.sql.symbol.Expression ex = null;
        if (this.ctxQuery.getIterator() == null) {
            String group = this.nameGenerator.getNextGroup();
            GroupSymbol groupSymbol = new GroupSymbol(group);
            StoredProcedure procedure = new StoredProcedure();
            procedure.setProcedureName("arrayiterate");
            // the projected should only be the collection property at this point
            // we may need more checks here to ensure that is valid
            Collection<ProjectedColumn> values = this.ctxQuery.getProjectedColumns().values();
            Assertion.assertTrue(values.size() == 1);
            ProjectedColumn projectedColumn = values.iterator().next();
            ElementSymbol projectedEs = (ElementSymbol) projectedColumn.getExpression();
            List<SPParameter> params = new ArrayList<SPParameter>();
            SPParameter param = new SPParameter(1, SPParameter.IN, "val");
            param.setExpression(projectedEs);
            params.add(param);
            procedure.setParameter(param);
            SubqueryFromClause fromClause = new SubqueryFromClause(group, procedure);
            fromClause.setLateral(true);
            ElementSymbol es = new ElementSymbol("col", groupSymbol);
            String type = ODataTypeManager.teiidType((SingletonPrimitiveType) info.getType(), false);
            Function castFunction = new Function(CAST, new org.teiid.query.sql.symbol.Expression[] { es, new Constant(type) });
            DocumentNode itResource = new DocumentNode();
            org.teiid.query.sql.symbol.Expression clone = (org.teiid.query.sql.symbol.Expression) castFunction.clone();
            AggregateSymbol symbol = new AggregateSymbol(AggregateSymbol.Type.ARRAY_AGG.name(), false, clone);
            AliasSymbol expression = new AliasSymbol(projectedEs.getShortName(), symbol);
            itResource.setFromClause(fromClause);
            itResource.setGroupSymbol(groupSymbol);
            itResource.addProjectedColumn(expression, info.getType(), projectedColumn.getProperty(), true);
            this.ctxQuery.getProjectedColumns().remove(projectedColumn.getExpression());
            this.ctxQuery.setIterator(itResource);
            ex = castFunction;
        } else {
            GroupSymbol groupSymbol = this.ctxQuery.getIterator().getGroupSymbol();
            ElementSymbol es = new ElementSymbol("col", groupSymbol);
            String type = ODataTypeManager.teiidType((SingletonPrimitiveType) info.getType(), false);
            ex = new Function(CAST, new org.teiid.query.sql.symbol.Expression[] { es, new Constant(type) });
        }
        this.stack.push(ex);
    } else {
        boolean ex = true;
        if (this.ctxQuery instanceof ExpandDocumentNode) {
            ExpandDocumentNode node = (ExpandDocumentNode) this.ctxQuery;
            DocumentNode parent = node.getCollectionContext();
            if (parent != null) {
                this.ctxExpression = parent;
                ex = false;
            }
        }
        if (ex) {
            throw new TeiidRuntimeException(new TeiidNotImplementedException(ODataPlugin.Event.TEIID16010, ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16010)));
        }
    }
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) AggregateSymbol(org.teiid.query.sql.symbol.AggregateSymbol) Constant(org.teiid.query.sql.symbol.Constant) ArrayList(java.util.ArrayList) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) ProjectedColumn(org.teiid.olingo.ProjectedColumn) Function(org.teiid.query.sql.symbol.Function) SingletonPrimitiveType(org.apache.olingo.commons.core.edm.primitivetype.SingletonPrimitiveType) ScalarSubquery(org.teiid.query.sql.symbol.ScalarSubquery) AliasSymbol(org.teiid.query.sql.symbol.AliasSymbol) SearchedCaseExpression(org.teiid.query.sql.symbol.SearchedCaseExpression) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol)

Example 24 with ElementSymbol

use of org.teiid.query.sql.symbol.ElementSymbol 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;
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) ScalarSubquery(org.teiid.query.sql.symbol.ScalarSubquery) ProjectedColumn(org.teiid.olingo.ProjectedColumn) Column(org.teiid.metadata.Column)

Example 25 with ElementSymbol

use of org.teiid.query.sql.symbol.ElementSymbol 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());
        }
    }
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) EdmReturnType(org.apache.olingo.commons.api.edm.EdmReturnType) Column(org.teiid.metadata.Column) EdmComplexType(org.apache.olingo.commons.api.edm.EdmComplexType) EdmPropertyImpl(org.apache.olingo.commons.core.edm.EdmPropertyImpl)

Aggregations

ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)417 ArrayList (java.util.ArrayList)165 Test (org.junit.Test)157 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)148 Expression (org.teiid.query.sql.symbol.Expression)104 List (java.util.List)103 Constant (org.teiid.query.sql.symbol.Constant)94 MultipleElementSymbol (org.teiid.query.sql.symbol.MultipleElementSymbol)41 SymbolMap (org.teiid.query.sql.util.SymbolMap)40 PlanNode (org.teiid.query.optimizer.relational.plantree.PlanNode)36 CompareCriteria (org.teiid.query.sql.lang.CompareCriteria)29 Map (java.util.Map)28 AggregateSymbol (org.teiid.query.sql.symbol.AggregateSymbol)28 Query (org.teiid.query.sql.lang.Query)26 HashMap (java.util.HashMap)25 Select (org.teiid.query.sql.lang.Select)24 BufferManager (org.teiid.common.buffer.BufferManager)22 Criteria (org.teiid.query.sql.lang.Criteria)22 LinkedList (java.util.LinkedList)20 TupleBuffer (org.teiid.common.buffer.TupleBuffer)19