use of org.teiid.query.sql.symbol.Array in project teiid by teiid.
the class DependentProcedureCriteriaProcessor method prepareNextCommand.
protected boolean prepareNextCommand(VariableContext context) throws BlockedException, TeiidComponentException, TeiidProcessingException {
if (this.critInProgress == null) {
critInProgress = prepareCriteria();
}
for (int j = 0; j < inputReferences.size(); j++) {
Reference ref = (Reference) inputReferences.get(j);
context.remove(ref.getExpression());
}
if (critInProgress == QueryRewriter.FALSE_CRITERIA) {
critInProgress = null;
consumedCriteria();
return false;
}
boolean validRow = true;
for (Iterator<Criteria> i = Criteria.separateCriteriaByAnd(critInProgress).iterator(); i.hasNext() && validRow; ) {
Criteria crit = i.next();
Object value = null;
boolean nullAllowed = false;
Reference parameter = null;
if (crit instanceof IsNullCriteria) {
parameter = (Reference) ((IsNullCriteria) crit).getExpression();
nullAllowed = true;
} else if (crit instanceof CompareCriteria) {
CompareCriteria compare = (CompareCriteria) crit;
value = compare.getRightExpression();
if (compare.getLeftExpression() instanceof Array) {
Array array = (Array) compare.getLeftExpression();
if (value instanceof Expression) {
value = eval.evaluate((Expression) value, null);
}
if (value == null) {
validRow = false;
break;
}
ArrayImpl valueArray = (ArrayImpl) value;
for (int j = 0; j < array.getExpressions().size(); j++) {
validRow = setParam(context, valueArray.getValues()[j], nullAllowed, (Reference) array.getExpressions().get(j));
if (!validRow) {
break;
}
}
continue;
}
parameter = (Reference) compare.getLeftExpression();
} else {
// $NON-NLS-1$
Assertion.failed("Unknown predicate type");
}
validRow = setParam(context, value, nullAllowed, parameter);
}
critInProgress = null;
consumedCriteria();
if (!validRow) {
return false;
}
for (int j = 0; j < inputReferences.size(); j++) {
Object defaultValue = inputDefaults.get(j);
Reference ref = (Reference) inputReferences.get(j);
if (defaultValue != null && !context.containsVariable(ref.getExpression())) {
context.setValue(ref.getExpression(), defaultValue);
}
}
return true;
}
use of org.teiid.query.sql.symbol.Array in project teiid by teiid.
the class DependentValueSource method getValueIterator.
/**
* @throws TeiidComponentException
* @see org.teiid.query.sql.util.ValueIteratorSource#getValueIterator(org.teiid.query.sql.symbol.Expression)
*/
public TupleSourceValueIterator getValueIterator(Expression valueExpression) throws TeiidComponentException {
IndexedTupleSource its = buffer.createIndexedTupleSource();
int index = 0;
if (valueExpression != null) {
if (valueExpression instanceof Array) {
final Array array = (Array) valueExpression;
List<Expression> exprs = array.getExpressions();
final int[] indexes = new int[exprs.size()];
for (int i = 0; i < exprs.size(); i++) {
indexes[i] = getIndex(exprs.get(i));
}
return new TupleSourceValueIterator(its, index) {
@Override
public Object next() throws TeiidComponentException {
List<?> tuple = super.nextTuple();
Object[] a = (Object[]) java.lang.reflect.Array.newInstance(array.getComponentType(), indexes.length);
for (int i = 0; i < indexes.length; i++) {
a[i] = tuple.get(indexes[i]);
if (a[i] == null) {
// TODO: this is a hack
return null;
}
}
return new ArrayImpl(a);
}
};
}
index = getIndex(valueExpression);
}
return new TupleSourceValueIterator(its, index);
}
use of org.teiid.query.sql.symbol.Array in project teiid by teiid.
the class TestArrayProcessing method testArrayParsing.
@Test
public void testArrayParsing() throws Exception {
TestParser.helpTestExpression("()", "()", new Array(new ArrayList<Expression>()));
TestParser.helpTestExpression("(,)", "()", new Array(new ArrayList<Expression>()));
TestParser.helpTestExpression("(1,)", "(1,)", new Array(Arrays.asList((Expression) new Constant(1))));
TestParser.helpTestExpression("(1,2)", "(1, 2)", new Array(Arrays.asList((Expression) new Constant(1), (Expression) new Constant(2))));
TestParser.helpTestExpression("(1,2,)", "(1, 2)", new Array(Arrays.asList((Expression) new Constant(1), (Expression) new Constant(2))));
}
use of org.teiid.query.sql.symbol.Array in project teiid by teiid.
the class TestProcedureResolving method testVarArgs1.
@Test
public void testVarArgs1() throws Exception {
String ddl = "create foreign procedure proc (VARIADIC z integer) returns (x string);\n";
TransformationMetadata tm = createMetadata(ddl);
// $NON-NLS-1$
String sql = "call proc ()";
StoredProcedure sp = (StoredProcedure) TestResolver.helpResolve(sql, tm);
assertEquals("EXEC proc()", sp.toString());
assertEquals(new Array(DataTypeManager.DefaultDataClasses.INTEGER, new ArrayList<Expression>(0)), sp.getParameter(1).getExpression());
sp = (StoredProcedure) QueryRewriter.evaluateAndRewrite(sp, new Evaluator(null, null, null), null, tm);
LanguageBridgeFactory lbf = new LanguageBridgeFactory(tm);
Call call = (Call) lbf.translate(sp);
assertEquals("EXEC proc()", call.toString());
// we pass to the translator level flattened, so no argument
assertEquals(0, call.getArguments().size());
}
Aggregations