use of org.teiid.query.sql.symbol.Expression in project teiid by teiid.
the class LanguageBridgeFactory method translate.
org.teiid.language.Comparison translate(DependentSetCriteria criteria) {
Operator operator = Operator.EQ;
org.teiid.language.Expression arg = null;
final TupleBuffer tb = criteria.getDependentValueSource().getTupleBuffer();
if (criteria.getValueExpression() instanceof Array) {
Array array = (Array) criteria.getValueExpression();
List<org.teiid.language.Expression> params = new ArrayList<org.teiid.language.Expression>();
Class<?> baseType = null;
for (Expression ex : array.getExpressions()) {
if (baseType == null) {
baseType = ex.getType();
} else if (!baseType.equals(ex.getType())) {
baseType = DataTypeManager.DefaultDataClasses.OBJECT;
}
params.add(createParameter(criteria, tb, ex));
}
arg = new org.teiid.language.Array(baseType, params);
} else {
Expression ex = criteria.getValueExpression();
arg = createParameter(criteria, tb, ex);
}
if (this.dependentSets == null) {
this.dependentSets = new HashMap<String, List<? extends List<?>>>();
}
this.dependentSets.put(criteria.getContextSymbol(), new TupleBufferList(tb));
Comparison result = new org.teiid.language.Comparison(translate(criteria.getExpression()), arg, operator);
return result;
}
use of org.teiid.query.sql.symbol.Expression in project teiid by teiid.
the class LanguageBridgeFactory method translate.
AggregateFunction translate(AggregateSymbol symbol) {
List<org.teiid.language.Expression> params = new ArrayList<org.teiid.language.Expression>(symbol.getArgs().length);
for (Expression expression : symbol.getArgs()) {
params.add(translate(expression));
}
String name = symbol.getAggregateFunction().name();
if (symbol.getAggregateFunction() == AggregateSymbol.Type.USER_DEFINED) {
name = symbol.getName();
}
AggregateFunction af = new AggregateFunction(name, symbol.isDistinct(), params, symbol.getType());
af.setCondition(translate(symbol.getCondition()));
af.setOrderBy(translate(symbol.getOrderBy(), false));
return af;
}
use of org.teiid.query.sql.symbol.Expression in project teiid by teiid.
the class BufferManagerImpl method getTypeClasses.
private static Class<?>[] getTypeClasses(final List<? extends Expression> elements) {
Class<?>[] types = new Class[elements.size()];
for (ListIterator<? extends Expression> i = elements.listIterator(); i.hasNext(); ) {
Expression expr = i.next();
Class<?> type = expr.getType();
Assertion.isNotNull(type);
types[i.previousIndex()] = type;
}
return types;
}
use of org.teiid.query.sql.symbol.Expression in project teiid by teiid.
the class TestResolver method testUser.
/**
* test jdbc USER method
*/
@Test
public void testUser() {
// String sql = "select intkey from SmallA where user() = 'bqt2'";
// Expected left expression
FunctionLibrary library = RealMetadataFactory.SFM.getSystemFunctionLibrary();
FunctionDescriptor fd = library.findFunction(FunctionLibrary.USER, new Class[] {});
Function user = new Function(fd.getName(), new Expression[] {});
user.setFunctionDescriptor(fd);
// Expected criteria
CompareCriteria expected = new CompareCriteria();
// Expected right expression
// $NON-NLS-1$
Expression e1 = new Constant("bqt2", String.class);
// Expected left expression
expected.setLeftExpression(user);
expected.setOperator(CompareCriteria.EQ);
expected.setRightExpression(e1);
// Resolve the query and check against expected objects
// $NON-NLS-1$
CompareCriteria actual = (CompareCriteria) helpResolveCriteria("user()='bqt2'");
// $NON-NLS-1$
assertEquals("Did not match expected criteria", expected, actual);
}
use of org.teiid.query.sql.symbol.Expression in project teiid by teiid.
the class TestResolver method testStringConversion2.
@Test
public void testStringConversion2() {
// Expected left expression
// $NON-NLS-1$
ElementSymbol e1 = new ElementSymbol("pm3.g1.e2");
e1.setType(DataTypeManager.DefaultDataClasses.DATE);
// Expected right expression
Class srcType = DataTypeManager.DefaultDataClasses.STRING;
String tgtTypeName = DataTypeManager.DefaultDataTypes.DATE;
// $NON-NLS-1$
Expression expression = new Constant("2003-02-27");
FunctionLibrary library = RealMetadataFactory.SFM.getSystemFunctionLibrary();
FunctionDescriptor fd = library.findFunction(FunctionLibrary.CONVERT, new Class[] { srcType, DataTypeManager.DefaultDataClasses.STRING });
Function conversion = new Function(fd.getName(), new Expression[] { expression, new Constant(tgtTypeName) });
conversion.setType(DataTypeManager.getDataTypeClass(tgtTypeName));
conversion.setFunctionDescriptor(fd);
conversion.makeImplicit();
// Expected criteria
CompareCriteria expected = new CompareCriteria();
expected.setLeftExpression(conversion);
expected.setOperator(CompareCriteria.EQ);
expected.setRightExpression(e1);
// Resolve the query and check against expected objects
// $NON-NLS-1$
CompareCriteria actual = (CompareCriteria) helpResolveCriteria("'2003-02-27'=pm3.g1.e2");
// if (! actual.getLeftExpression().equals(expected.getLeftExpression())) {
// fail("Left expressions not equal");
// } else if (!actual.getRightExpression().equals(expected.getRightExpression())) {
// fail("Right expressions not equal");
// }
// $NON-NLS-1$
assertEquals("Did not match expected criteria", expected, actual);
}
Aggregations