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;
}
}
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;
}
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)));
}
}
}
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());
}
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);
}
Aggregations