Search in sources :

Example 1 with Reference

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

the class TestPreparedPlanCache method testGet.

@Test
public void testGet() {
    SessionAwareCache<PreparedPlan> cache = new SessionAwareCache<PreparedPlan>("preparedplan", DefaultCacheFactory.INSTANCE, SessionAwareCache.Type.PREPAREDPLAN, 0);
    helpPutPreparedPlans(cache, token, 0, 10);
    helpPutPreparedPlans(cache, token2, 0, 15);
    // read an entry for session2 (token2)
    PreparedPlan pPlan = cache.get(new CacheID(token2, pi, EXAMPLE_QUERY + 12));
    // $NON-NLS-1$
    assertNotNull("Unable to get prepared plan from cache", pPlan);
    // $NON-NLS-1$
    assertEquals("Error getting plan from cache", new RelationalPlan(new ProjectNode(12)).toString(), pPlan.getPlan().toString());
    // $NON-NLS-1$
    assertEquals("Error getting command from cache", EXAMPLE_QUERY + 12, pPlan.getCommand().toString());
    // $NON-NLS-1$
    assertNotNull("Error getting plan description from cache", pPlan.getAnalysisRecord());
    // $NON-NLS-1$
    assertEquals("Error gettting reference from cache", new Reference(1), pPlan.getReferences().get(0));
}
Also used : CacheID(org.teiid.dqp.internal.process.SessionAwareCache.CacheID) Reference(org.teiid.query.sql.symbol.Reference) ProjectNode(org.teiid.query.processor.relational.ProjectNode) RelationalPlan(org.teiid.query.processor.relational.RelationalPlan) Test(org.junit.Test)

Example 2 with Reference

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

the class TestPreparedPlanCache method helpPutPreparedPlans.

// ====Help methods====//
private void helpPutPreparedPlans(SessionAwareCache<PreparedPlan> cache, DQPWorkContext session, int start, int count) {
    for (int i = 0; i < count; i++) {
        Command dummy;
        try {
            dummy = QueryParser.getQueryParser().parseCommand(EXAMPLE_QUERY + (start + i));
        } catch (QueryParserException e) {
            throw new RuntimeException(e);
        }
        CacheID id = new CacheID(session, pi, dummy.toString());
        PreparedPlan pPlan = new PreparedPlan();
        cache.put(id, Determinism.SESSION_DETERMINISTIC, pPlan, null);
        pPlan.setCommand(dummy);
        pPlan.setPlan(new RelationalPlan(new ProjectNode(i)), new CommandContext());
        AnalysisRecord analysisRecord = new AnalysisRecord(true, false);
        pPlan.setAnalysisRecord(analysisRecord);
        ArrayList<Reference> refs = new ArrayList<Reference>();
        refs.add(new Reference(1));
        pPlan.setReferences(refs);
    }
}
Also used : QueryParserException(org.teiid.api.exception.query.QueryParserException) AnalysisRecord(org.teiid.query.analysis.AnalysisRecord) CommandContext(org.teiid.query.util.CommandContext) Reference(org.teiid.query.sql.symbol.Reference) ArrayList(java.util.ArrayList) RelationalPlan(org.teiid.query.processor.relational.RelationalPlan) Command(org.teiid.query.sql.lang.Command) CacheID(org.teiid.dqp.internal.process.SessionAwareCache.CacheID) ProjectNode(org.teiid.query.processor.relational.ProjectNode)

Example 3 with Reference

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

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

the class ODataExpressionToSQLVisitor method visit.

@Override
public void visit(Literal expr) {
    try {
        Object value = null;
        if (expr.getText() != null && !expr.getText().equalsIgnoreCase("null")) {
            String type = expr.getType().getFullQualifiedName().getFullQualifiedNameAsString();
            value = ODataTypeManager.parseLiteral(type, expr.getText());
        }
        if (this.prepared) {
            if (value == null) {
                this.stack.add(new Constant(value));
            } else {
                Function ref = new Function(CONVERT, new org.teiid.query.sql.symbol.Expression[] { new Reference(this.params.size()), new Constant(DataTypeManager.getDataTypeName(value.getClass())) });
                stack.add(ref);
                this.params.add(new SQLParameter(value, JDBCSQLTypeInfo.getSQLTypeFromClass(value.getClass().getName())));
            }
        } else {
            this.stack.add(new Constant(value));
        }
    } catch (TeiidException e) {
        throw new TeiidRuntimeException(e);
    }
}
Also used : Function(org.teiid.query.sql.symbol.Function) Constant(org.teiid.query.sql.symbol.Constant) Reference(org.teiid.query.sql.symbol.Reference) ScalarSubquery(org.teiid.query.sql.symbol.ScalarSubquery) SQLParameter(org.teiid.odata.api.SQLParameter) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) TeiidException(org.teiid.core.TeiidException)

Example 5 with Reference

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

Reference (org.teiid.query.sql.symbol.Reference)42 Test (org.junit.Test)15 Constant (org.teiid.query.sql.symbol.Constant)14 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)14 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)12 Expression (org.teiid.query.sql.symbol.Expression)11 Limit (org.teiid.query.sql.lang.Limit)7 Query (org.teiid.query.sql.lang.Query)7 MultipleElementSymbol (org.teiid.query.sql.symbol.MultipleElementSymbol)7 ArrayList (java.util.ArrayList)6 Criteria (org.teiid.query.sql.lang.Criteria)6 LinkedList (java.util.LinkedList)5 From (org.teiid.query.sql.lang.From)5 Select (org.teiid.query.sql.lang.Select)5 SetQuery (org.teiid.query.sql.lang.SetQuery)5 StoredProcedure (org.teiid.query.sql.lang.StoredProcedure)5 UnaryFromClause (org.teiid.query.sql.lang.UnaryFromClause)5 Column (org.teiid.metadata.Column)4 Command (org.teiid.query.sql.lang.Command)4 SPParameter (org.teiid.query.sql.lang.SPParameter)4