use of org.teiid.query.sql.symbol.Array in project teiid by teiid.
the class TestArrayProcessing method testArrayEquivalence.
@Test
public void testArrayEquivalence() throws Exception {
Array a1 = new Array(new ArrayList<Expression>());
UnitTestUtil.helpTestEquivalence(0, a1, a1);
Array a2 = new Array(Arrays.asList((Expression) new Constant(1)));
UnitTestUtil.helpTestEquivalence(1, a1, a2);
}
use of org.teiid.query.sql.symbol.Array in project teiid by teiid.
the class TempTable method matchesPkColumn.
@Override
public Object matchesPkColumn(int pkIndex, Expression ex) {
if (rowId != null) {
return false;
}
if (ex instanceof Array) {
Array array = (Array) ex;
List<Expression> exprs = array.getExpressions();
int toIndex = Math.min(this.getPkLength(), exprs.size());
int[] indexes = new int[toIndex];
for (int i = pkIndex; i < toIndex; i++) {
int index = exprs.indexOf(this.columns.get(i));
indexes[i] = index;
if (index == -1) {
if (i == pkIndex) {
return false;
}
break;
}
}
return indexes;
}
return columns.get(pkIndex).equals(ex);
}
use of org.teiid.query.sql.symbol.Array in project teiid by teiid.
the class RuleChooseDependent method createDependentSetCriteria.
static DependentSetCriteria createDependentSetCriteria(String id, List<DependentSetCriteria.AttributeComparison> expressions) {
if (expressions.isEmpty()) {
return null;
}
Expression indEx = null;
Expression depEx = null;
float maxNdv = NewCalculateCostUtil.UNKNOWN_VALUE;
float ndv = NewCalculateCostUtil.UNKNOWN_VALUE;
if (expressions.size() == 1) {
AttributeComparison attributeComparison = expressions.get(0);
indEx = attributeComparison.ind;
depEx = attributeComparison.dep;
maxNdv = attributeComparison.maxNdv;
ndv = attributeComparison.ndv;
} else {
List<Expression> indExprs = new ArrayList<Expression>(expressions.size());
List<Expression> depExprs = new ArrayList<Expression>(expressions.size());
boolean unknown = false;
for (DependentSetCriteria.AttributeComparison comp : expressions) {
indExprs.add(comp.ind);
depExprs.add(comp.dep);
if (comp.ndv == NewCalculateCostUtil.UNKNOWN_VALUE) {
ndv = NewCalculateCostUtil.UNKNOWN_VALUE;
maxNdv = NewCalculateCostUtil.UNKNOWN_VALUE;
unknown = true;
} else if (!unknown) {
ndv = Math.max(ndv, comp.ndv);
maxNdv = Math.max(maxNdv, comp.maxNdv);
}
}
// TODO: detect a base type
indEx = new Array(DefaultDataClasses.OBJECT, indExprs);
depEx = new Array(DefaultDataClasses.OBJECT, depExprs);
}
DependentSetCriteria crit = new DependentSetCriteria(depEx, id);
crit.setValueExpression(indEx);
crit.setAttributes(expressions);
crit.setMaxNdv(maxNdv);
crit.setNdv(ndv);
return crit;
}
use of org.teiid.query.sql.symbol.Array in project teiid by teiid.
the class LanguageBridgeFactory method translate.
org.teiid.language.Expression translate(Constant constant) {
if (constant.isMultiValued()) {
Parameter result = new Parameter();
result.setType(constant.getType());
final List<?> values = (List<?>) constant.getValue();
allValues.add(values);
result.setValueIndex(valueIndex++);
return result;
}
if (constant.getValue() instanceof ArrayImpl) {
// TODO: we could check if there is a common base type (also needs to be in the dependent logic)
// and expand binding options in the translators
// we currently support the notion of a mixed type array, since we consider object a common base type
// that will not work for all sources, so instead of treating this as a single array (as commented out below),
// we just turn it into an array of parameters
// Literal result = new Literal(av.getValues(), org.teiid.language.Array.class);
// result.setBindEligible(constant.isBindEligible());
// return result;
ArrayImpl av = (ArrayImpl) constant.getValue();
List<Constant> vals = new ArrayList<Constant>();
Class<?> baseType = null;
for (Object o : av.getValues()) {
Constant c = new Constant(o);
c.setBindEligible(constant.isBindEligible());
vals.add(c);
if (baseType == null) {
baseType = c.getType();
} else if (!baseType.equals(c.getType())) {
baseType = DataTypeManager.DefaultDataClasses.OBJECT;
}
}
return new org.teiid.language.Array(baseType, translateExpressionList(vals));
}
Literal result = new Literal(constant.getValue(), constant.getType());
result.setBindEligible(constant.isBindEligible());
return result;
}
use of org.teiid.query.sql.symbol.Array in project teiid by teiid.
the class DependentCriteriaProcessor method prepareCriteria.
public Criteria prepareCriteria() throws TeiidComponentException, TeiidProcessingException {
if (phase == SORT) {
for (TupleState state : dependentState.values()) {
state.sort();
if (state.dvs.getTupleBuffer().getRowCount() == 0) {
return QueryRewriter.FALSE_CRITERIA;
}
}
// init total predicates and max size
totalPredicates = setStates.size();
if (this.maxPredicates > 0) {
// We have a bin packing problem if totalPredicates < sources - We'll address that case later.
// TODO: better handling for the correlated composite case
totalPredicates = Math.max(totalPredicates, this.maxPredicates);
}
long maxParams = this.maxPredicates * this.maxSetSize;
maxSize = Integer.MAX_VALUE;
if (this.maxSetSize > 0) {
maxSize = this.maxSetSize;
if (this.maxPredicates > 0 && totalPredicates > this.maxPredicates) {
// scale the max based upon the number of predicates - this is not perfect, but sufficient for most situations
maxSize = Math.max(1, maxParams / totalPredicates);
}
}
// determine push down handling
if (pushdown) {
List<Criteria> newCriteria = new ArrayList<Criteria>();
long params = 0;
int sets = 0;
for (Criteria criteria : queryCriteria) {
if (!(criteria instanceof DependentSetCriteria)) {
newCriteria.add(criteria);
continue;
}
sets++;
DependentSetCriteria dsc = (DependentSetCriteria) criteria;
TupleState ts = dependentState.get(dsc.getContextSymbol());
DependentValueSource dvs = ts.dvs;
// check if this has more rows than we want to push
if ((dsc.getMaxNdv() != -1 && dvs.getTupleBuffer().getRowCount() > dsc.getMaxNdv()) || (dsc.getMakeDepOptions() != null && dsc.getMakeDepOptions().getMax() != null && dvs.getTupleBuffer().getRowCount() > dsc.getMakeDepOptions().getMax())) {
// don't try to pushdown
continue;
}
int cols = 1;
if (dsc.getExpression() instanceof Array) {
cols = ((Array) dsc.getExpression()).getExpressions().size();
}
dsc = dsc.clone();
// determine if this will be more than 1 source query
params += cols * dvs.getTupleBuffer().getRowCount();
// TODO: this assumes that if any one of the dependent
// joins are pushed, then they all are
dsc.setDependentValueSource(dvs);
newCriteria.add(dsc);
}
// TODO: see if this should be a source tunable parameter
int maxParamThreshold = 3;
// generally this value accounts for the additional overhead of temp table creation
if (params > maxParams && (sets > 1 || complexQuery || params > maxParams * maxParamThreshold)) {
// and only if the we could produce a cross set or have a complex query
return Criteria.combineCriteria(newCriteria);
}
}
// proceed with set based processing
phase = SET_PROCESSING;
}
replaceDependentValueIterators();
LinkedList<Criteria> crits = new LinkedList<Criteria>();
for (int i = 0; i < queryCriteria.size(); i++) {
SetState state = this.setStates.get(i);
Criteria criteria = queryCriteria.get(i);
if (state == null) {
if (criteria != QueryRewriter.TRUE_CRITERIA) {
crits.add((Criteria) criteria.clone());
}
} else {
Criteria crit = replaceDependentCriteria((AbstractSetCriteria) criteria, state);
if (crit == QueryRewriter.FALSE_CRITERIA) {
return QueryRewriter.FALSE_CRITERIA;
}
if (crit != QueryRewriter.TRUE_CRITERIA) {
crits.add(crit);
}
}
}
if (crits.size() == 1) {
return crits.get(0);
}
return new CompoundCriteria(CompoundCriteria.AND, crits);
}
Aggregations