Search in sources :

Example 11 with Constant

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

the class ODataExpressionToSQLVisitor method visit.

@Override
public void visit(Unary expr) {
    accept(expr.getOperand());
    org.teiid.query.sql.symbol.Expression teiidExpr = this.stack.pop();
    switch(expr.getOperator()) {
        case MINUS:
            this.stack.push(new Function(SourceSystemFunctions.MULTIPLY_OP, new org.teiid.query.sql.symbol.Expression[] { new Constant(-1), teiidExpr }));
            break;
        case NOT:
            this.stack.push(new NotCriteria(new ExpressionCriteria(teiidExpr)));
            break;
    }
}
Also used : Function(org.teiid.query.sql.symbol.Function) SearchedCaseExpression(org.teiid.query.sql.symbol.SearchedCaseExpression) Constant(org.teiid.query.sql.symbol.Constant) ScalarSubquery(org.teiid.query.sql.symbol.ScalarSubquery)

Example 12 with Constant

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

the class ODataExpressionToSQLVisitor method visit.

@Override
public void visit(UriResourceLambdaAny any) {
    accept(any.getExpression());
    if (this.ctxLambda != null) {
        org.teiid.query.sql.symbol.Expression predicate = this.stack.pop();
        Query q = buildSubquery(this.ctxLambda, new Constant(1));
        Criteria crit = null;
        if (predicate instanceof Criteria) {
            crit = (Criteria) predicate;
        } else {
            crit = new ExpressionCriteria(predicate);
        }
        q.setCriteria(Criteria.combineCriteria(q.getCriteria(), crit));
        predicate = new ExistsCriteria(q);
        this.stack.push(predicate);
    }
    this.ctxLambda = null;
}
Also used : Constant(org.teiid.query.sql.symbol.Constant) ScalarSubquery(org.teiid.query.sql.symbol.ScalarSubquery)

Example 13 with Constant

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

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

the class TestFunction method helpTestParseTimestamp.

public static void helpTestParseTimestamp(String tsStr, String format, String expected) throws FunctionExecutionException {
    Object actual = FunctionMethods.parseTimestamp(new CommandContext(), tsStr, format);
    assertEquals(// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    "parseTimestamp(" + tsStr + ", " + format + ") failed", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    expected.toString(), new Constant(actual).toString());
}
Also used : CommandContext(org.teiid.query.util.CommandContext) Constant(org.teiid.query.sql.symbol.Constant)

Example 15 with Constant

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

the class TestFunctionTree method testMultiPartNameSystemConflict.

@Test
public void testMultiPartNameSystemConflict() throws Exception {
    FunctionMethod method = new FunctionMethod("x.concat", null, null, PushDown.MUST_PUSHDOWN, null, null, // $NON-NLS-1$
    Arrays.asList(new FunctionParameter("in", DataTypeManager.DefaultDataTypes.STRING), new FunctionParameter("in", DataTypeManager.DefaultDataTypes.STRING)), // $NON-NLS-1$
    new FunctionParameter("output", DataTypeManager.DefaultDataTypes.STRING), true, Determinism.DETERMINISTIC);
    FunctionTree sys = RealMetadataFactory.SFM.getSystemFunctions();
    FunctionLibrary fl = new FunctionLibrary(sys, new FunctionTree("foo", new UDFSource(Arrays.asList(method)), true));
    fl.determineNecessaryConversions("concat", DataTypeManager.DefaultDataClasses.STRING, new Expression[] { new Constant(1), new Constant(2) }, new Class[] { DataTypeManager.DefaultDataClasses.INTEGER, DataTypeManager.DefaultDataClasses.INTEGER }, false);
}
Also used : Constant(org.teiid.query.sql.symbol.Constant) FunctionMethod(org.teiid.metadata.FunctionMethod) FunctionParameter(org.teiid.metadata.FunctionParameter) Test(org.junit.Test)

Aggregations

Constant (org.teiid.query.sql.symbol.Constant)203 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)94 Test (org.junit.Test)88 ArrayList (java.util.ArrayList)61 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)48 List (java.util.List)38 Expression (org.teiid.query.sql.symbol.Expression)38 Function (org.teiid.query.sql.symbol.Function)31 CompareCriteria (org.teiid.query.sql.lang.CompareCriteria)25 Query (org.teiid.query.sql.lang.Query)22 Select (org.teiid.query.sql.lang.Select)15 Reference (org.teiid.query.sql.symbol.Reference)14 From (org.teiid.query.sql.lang.From)12 HashMap (java.util.HashMap)11 FunctionDescriptor (org.teiid.query.function.FunctionDescriptor)11 Criteria (org.teiid.query.sql.lang.Criteria)11 SetQuery (org.teiid.query.sql.lang.SetQuery)11 LinkedList (java.util.LinkedList)10 Limit (org.teiid.query.sql.lang.Limit)10 StoredProcedure (org.teiid.query.sql.lang.StoredProcedure)9