use of org.teiid.query.sql.symbol.Function in project teiid by teiid.
the class TestFunction method testFunction2.
public void testFunction2() {
// $NON-NLS-1$ //$NON-NLS-2$
Function f1 = new Function("f1", new Expression[] { new Constant("xyz") });
// $NON-NLS-1$ //$NON-NLS-2$
Function f2 = new Function("F1", new Expression[] { new Constant("xyz") });
UnitTestUtil.helpTestEquivalence(0, f1, f2);
}
use of org.teiid.query.sql.symbol.Function in project teiid by teiid.
the class TestFunction method testFunction4.
public void testFunction4() {
// $NON-NLS-1$
Function f1 = new Function("f1", new Expression[] { null });
// $NON-NLS-1$
Function f2 = new Function("f1", new Expression[] { null });
UnitTestUtil.helpTestEquivalence(0, f1, f2);
}
use of org.teiid.query.sql.symbol.Function in project teiid by teiid.
the class ODataExpressionToSQLVisitor method addOne.
private org.teiid.query.sql.symbol.Expression addOne(org.teiid.query.sql.symbol.Expression expr) {
org.teiid.query.sql.symbol.Expression when = new CompareCriteria(expr, CompareCriteria.LT, new Constant(0));
SearchedCaseExpression caseExpr = new SearchedCaseExpression(Arrays.asList(when), Arrays.asList(expr));
caseExpr.setElseExpression(new Function("+", new org.teiid.query.sql.symbol.Expression[] { expr, new Constant(1) }));
return caseExpr;
}
use of org.teiid.query.sql.symbol.Function in project teiid by teiid.
the class ODataExpressionToSQLVisitor method visit.
@Override
public void visit(Method expr) {
List<org.teiid.query.sql.symbol.Expression> teiidExprs = new ArrayList<org.teiid.query.sql.symbol.Expression>();
for (Expression exp : expr.getParameters()) {
accept(exp);
teiidExprs.add(this.stack.pop());
}
switch(expr.getMethod()) {
case CONTAINS:
CompareCriteria criteria = new CompareCriteria(new Function("LOCATE", new org.teiid.query.sql.symbol.Expression[] { teiidExprs.get(1), teiidExprs.get(0), new Constant(1) }), CompareCriteria.GE, // $NON-NLS-1$
new Constant(1));
this.stack.push(criteria);
break;
case STARTSWITH:
criteria = new CompareCriteria(new Function("LOCATE", new org.teiid.query.sql.symbol.Expression[] { teiidExprs.get(1), teiidExprs.get(0), new Constant(1) }), CompareCriteria.EQ, // $NON-NLS-1$
new Constant(1));
this.stack.push(criteria);
break;
case ENDSWITH:
criteria = new CompareCriteria(new Function("ENDSWITH", new org.teiid.query.sql.symbol.Expression[] { teiidExprs.get(1), teiidExprs.get(0) }), CompareCriteria.EQ, // $NON-NLS-1$
new Constant(Boolean.TRUE));
this.stack.push(criteria);
break;
case LENGTH:
this.stack.push(new Function("LENGTH", // $NON-NLS-1$
new org.teiid.query.sql.symbol.Expression[] { teiidExprs.get(0) }));
break;
case INDEXOF:
stack.push(minusOne(new Function("LOCATE", new org.teiid.query.sql.symbol.Expression[] // $NON-NLS-1$
{ teiidExprs.get(1), teiidExprs.get(0) })));
break;
case SUBSTRING:
org.teiid.query.sql.symbol.Expression[] exprs = teiidExprs.toArray(new org.teiid.query.sql.symbol.Expression[teiidExprs.size()]);
exprs[1] = addOne(exprs[1]);
// $NON-NLS-1$
this.stack.push(new Function("SUBSTRING", exprs));
break;
case TOLOWER:
this.stack.push(new Function("LCASE", // $NON-NLS-1$
new org.teiid.query.sql.symbol.Expression[] { teiidExprs.get(0) }));
break;
case TOUPPER:
this.stack.push(new Function("UCASE", // $NON-NLS-1$
new org.teiid.query.sql.symbol.Expression[] { teiidExprs.get(0) }));
break;
case TRIM:
this.stack.push(new Function("TRIM", new org.teiid.query.sql.symbol.Expression[] { new Constant("BOTH"), new Constant(' '), // $NON-NLS-1$ //$NON-NLS-2$
teiidExprs.get(0) }));
break;
case CONCAT:
this.stack.push(new Function("CONCAT", new org.teiid.query.sql.symbol.Expression[] // $NON-NLS-1$
{ teiidExprs.get(0), teiidExprs.get(1) }));
break;
case YEAR:
this.stack.push(new Function("YEAR", new org.teiid.query.sql.symbol.Expression[] // $NON-NLS-1$
{ teiidExprs.get(0) }));
break;
case MONTH:
this.stack.push(new Function("MONTH", new org.teiid.query.sql.symbol.Expression[] // $NON-NLS-1$
{ teiidExprs.get(0) }));
break;
case DAY:
this.stack.push(new Function("DAYOFMONTH", new org.teiid.query.sql.symbol.Expression[] // $NON-NLS-1$
{ teiidExprs.get(0) }));
break;
case HOUR:
this.stack.push(new Function("HOUR", new org.teiid.query.sql.symbol.Expression[] // $NON-NLS-1$
{ teiidExprs.get(0) }));
break;
case MINUTE:
this.stack.push(new Function("MINUTE", new org.teiid.query.sql.symbol.Expression[] // $NON-NLS-1$
{ teiidExprs.get(0) }));
break;
case SECOND:
this.stack.push(new Function("SECOND", new org.teiid.query.sql.symbol.Expression[] // $NON-NLS-1$
{ teiidExprs.get(0) }));
break;
case NOW:
// $NON-NLS-1$
this.stack.push(new Function("NOW", new org.teiid.query.sql.symbol.Expression[] {}));
break;
case ROUND:
stack.push(new Function("ROUND", new org.teiid.query.sql.symbol.Expression[] // $NON-NLS-1$
{ teiidExprs.get(0), new Constant(0) }));
break;
case FLOOR:
this.stack.push(new Function("FLOOR", new org.teiid.query.sql.symbol.Expression[] // $NON-NLS-1$
{ teiidExprs.get(0) }));
break;
case CEILING:
this.stack.push(new Function("CEILING", new org.teiid.query.sql.symbol.Expression[] // $NON-NLS-1$
{ teiidExprs.get(0) }));
break;
case CAST:
this.stack.push(new Function(CONVERT, new org.teiid.query.sql.symbol.Expression[] { teiidExprs.get(0), teiidExprs.get(1) }));
break;
case DATE:
this.stack.push(new Function(CONVERT, new org.teiid.query.sql.symbol.Expression[] { teiidExprs.get(0), new Constant(DataTypeManager.DefaultDataTypes.DATE) }));
break;
case TIME:
this.stack.push(new Function(CONVERT, new org.teiid.query.sql.symbol.Expression[] { teiidExprs.get(0), new Constant(DataTypeManager.DefaultDataTypes.TIME) }));
break;
case FRACTIONALSECONDS:
case TOTALSECONDS:
case TOTALOFFSETMINUTES:
case MINDATETIME:
case MAXDATETIME:
case GEODISTANCE:
case GEOLENGTH:
case GEOINTERSECTS:
case ISOF:
default:
throw new TeiidRuntimeException(new TeiidNotImplementedException(ODataPlugin.Event.TEIID16027, ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16027, expr.getMethod())));
}
}
use of org.teiid.query.sql.symbol.Function in project teiid by teiid.
the class ODataExpressionToSQLVisitor method visit.
@Override
public void visit(Binary expr) {
accept(expr.getLeftOperand());
org.teiid.query.sql.symbol.Expression lhs = this.stack.pop();
accept(expr.getRightOperand());
org.teiid.query.sql.symbol.Expression rhs = this.stack.pop();
org.teiid.query.sql.symbol.Expression binaryExpr = null;
switch(expr.getOperator()) {
case HAS:
// TODO: not supported. What would be SQL equivalent?
throw new TeiidRuntimeException(new TeiidNotImplementedException(ODataPlugin.Event.TEIID16036, ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16036)));
case MUL:
// $NON-NLS-1$
binaryExpr = new Function("*", new org.teiid.query.sql.symbol.Expression[] { lhs, rhs });
break;
case DIV:
// $NON-NLS-1$
binaryExpr = new Function("/", new org.teiid.query.sql.symbol.Expression[] { lhs, rhs });
break;
case MOD:
// $NON-NLS-1$
binaryExpr = new Function("MOD", new org.teiid.query.sql.symbol.Expression[] { lhs, rhs });
break;
case ADD:
// $NON-NLS-1$
binaryExpr = new Function("+", new org.teiid.query.sql.symbol.Expression[] { lhs, rhs });
break;
case SUB:
// $NON-NLS-1$
binaryExpr = new Function("-", new org.teiid.query.sql.symbol.Expression[] { lhs, rhs });
break;
case GT:
binaryExpr = new CompareCriteria(lhs, CompareCriteria.GT, rhs);
break;
case GE:
binaryExpr = new CompareCriteria(lhs, CompareCriteria.GE, rhs);
break;
case LT:
binaryExpr = new CompareCriteria(lhs, CompareCriteria.LT, rhs);
break;
case LE:
binaryExpr = new CompareCriteria(lhs, CompareCriteria.LE, rhs);
break;
case EQ:
if (rhs instanceof Constant && ((Constant) rhs).getType() == DataTypeManager.DefaultDataClasses.NULL) {
binaryExpr = new IsNullCriteria(lhs);
} else {
binaryExpr = new CompareCriteria(lhs, CompareCriteria.EQ, rhs);
}
break;
case NE:
if (rhs instanceof Constant && ((Constant) rhs).getType() == DataTypeManager.DefaultDataClasses.NULL) {
IsNullCriteria crit = new IsNullCriteria(lhs);
crit.setNegated(true);
binaryExpr = crit;
} else {
binaryExpr = new CompareCriteria(lhs, CompareCriteria.NE, rhs);
}
break;
case AND:
binaryExpr = new CompoundCriteria(CompoundCriteria.AND, (Criteria) lhs, (Criteria) rhs);
break;
case OR:
binaryExpr = new CompoundCriteria(CompoundCriteria.OR, (Criteria) lhs, (Criteria) rhs);
break;
}
this.stack.push(binaryExpr);
}
Aggregations