Search in sources :

Example 6 with GroupSymbol

use of org.teiid.query.sql.symbol.GroupSymbol 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 7 with GroupSymbol

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

the class DocumentNode method build.

public static DocumentNode build(DocumentNode resource, EdmEntityType type, List<UriParameter> keyPredicates, MetadataStore metadata, OData odata, UniqueNameGenerator nameGenerator, boolean useAlias, UriInfo uriInfo, URLParseService parseService) throws TeiidException {
    Table table = findTable(type, metadata);
    GroupSymbol gs = null;
    if (useAlias) {
        gs = new GroupSymbol(nameGenerator.getNextGroup(), table.getFullName());
    } else {
        gs = new GroupSymbol(table.getFullName());
    }
    resource.setTable(table);
    resource.setGroupSymbol(gs);
    resource.setEdmEntityType(type);
    resource.setKeyPredicates(keyPredicates);
    resource.setFromClause(new UnaryFromClause(gs));
    if (keyPredicates != null && !keyPredicates.isEmpty()) {
        Criteria criteria = DocumentNode.buildEntityKeyCriteria(resource, uriInfo, metadata, odata, nameGenerator, parseService);
        resource.setCriteria(criteria);
    }
    return resource;
}
Also used : Table(org.teiid.metadata.Table) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol)

Example 8 with GroupSymbol

use of org.teiid.query.sql.symbol.GroupSymbol 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 9 with GroupSymbol

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

the class ODataExpressionToSQLVisitor method visit.

@Override
public void visit(UriResourceLambdaVariable resource) {
    try {
        if (this.ctxLambda == null) {
            DocumentNode lambda = DocumentNode.build((EdmEntityType) resource.getType(), null, this.metadata, this.odata, this.nameGenerator, false, this.uriInfo, this.parseService);
            lambda.setGroupSymbol(new GroupSymbol(resource.getVariableName(), lambda.getFullName()));
            this.ctxLambda = lambda;
        }
        this.ctxExpression = ctxLambda;
    } catch (TeiidException e) {
        throw new TeiidRuntimeException(e);
    }
}
Also used : GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) TeiidException(org.teiid.core.TeiidException)

Example 10 with GroupSymbol

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

the class ComplexDocumentNode method buildComplexDocumentNode.

public static ComplexDocumentNode buildComplexDocumentNode(EdmOperation edmOperation, MetadataStore metadata, OData odata, UniqueNameGenerator nameGenerator, boolean useAlias, UriInfo uriInfo, URLParseService parseService) throws TeiidProcessingException {
    ComplexDocumentNode resource = new ComplexDocumentNode();
    FullQualifiedName fqn = edmOperation.getFullQualifiedName();
    String withoutVDB = fqn.getNamespace().substring(fqn.getNamespace().lastIndexOf('.') + 1);
    Schema schema = metadata.getSchema(withoutVDB);
    Procedure procedure = schema.getProcedure(edmOperation.getName());
    StoredProcedure storedQuery = new StoredProcedure();
    // $NON-NLS-1$
    storedQuery.setProcedureName(procedure.getFullName());
    for (int i = 0; i < procedure.getParameters().size(); i++) {
        storedQuery.setParameter(new SPParameter(i + 1, new Reference(i)));
    }
    String group = nameGenerator.getNextGroup();
    // $NON-NLS-1$
    SubqueryFromClause sfc = new SubqueryFromClause(group, storedQuery);
    resource.setGroupSymbol(new GroupSymbol(group));
    resource.setFromClause(sfc);
    resource.procedure = procedure;
    return resource;
}
Also used : StoredProcedure(org.teiid.query.sql.lang.StoredProcedure) SPParameter(org.teiid.query.sql.lang.SPParameter) Reference(org.teiid.query.sql.symbol.Reference) FullQualifiedName(org.apache.olingo.commons.api.edm.FullQualifiedName) Schema(org.teiid.metadata.Schema) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) StoredProcedure(org.teiid.query.sql.lang.StoredProcedure) Procedure(org.teiid.metadata.Procedure) SubqueryFromClause(org.teiid.query.sql.lang.SubqueryFromClause)

Aggregations

GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)299 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)146 Test (org.junit.Test)108 ArrayList (java.util.ArrayList)92 MultipleElementSymbol (org.teiid.query.sql.symbol.MultipleElementSymbol)59 Expression (org.teiid.query.sql.symbol.Expression)52 PlanNode (org.teiid.query.optimizer.relational.plantree.PlanNode)50 Constant (org.teiid.query.sql.symbol.Constant)48 List (java.util.List)43 HashSet (java.util.HashSet)32 Query (org.teiid.query.sql.lang.Query)31 From (org.teiid.query.sql.lang.From)29 SymbolMap (org.teiid.query.sql.util.SymbolMap)29 Select (org.teiid.query.sql.lang.Select)26 Criteria (org.teiid.query.sql.lang.Criteria)22 TempMetadataID (org.teiid.query.metadata.TempMetadataID)21 LinkedList (java.util.LinkedList)20 Command (org.teiid.query.sql.lang.Command)20 Set (java.util.Set)17 CompareCriteria (org.teiid.query.sql.lang.CompareCriteria)17