Search in sources :

Example 6 with Array

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);
}
Also used : Array(org.teiid.query.sql.symbol.Array) Expression(org.teiid.query.sql.symbol.Expression) Constant(org.teiid.query.sql.symbol.Constant) Test(org.junit.Test)

Example 7 with Array

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);
}
Also used : Array(org.teiid.query.sql.symbol.Array) Expression(org.teiid.query.sql.symbol.Expression) CacheHint(org.teiid.query.sql.lang.CacheHint)

Example 8 with Array

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;
}
Also used : DependentSetCriteria(org.teiid.query.sql.lang.DependentSetCriteria) Array(org.teiid.query.sql.symbol.Array) AttributeComparison(org.teiid.query.sql.lang.DependentSetCriteria.AttributeComparison) Expression(org.teiid.query.sql.symbol.Expression) ArrayList(java.util.ArrayList) AttributeComparison(org.teiid.query.sql.lang.DependentSetCriteria.AttributeComparison)

Example 9 with Array

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;
}
Also used : Array(org.teiid.query.sql.symbol.Array) Constant(org.teiid.query.sql.symbol.Constant) ArrayImpl(org.teiid.core.types.ArrayImpl) ProcedureParameter(org.teiid.metadata.ProcedureParameter)

Example 10 with Array

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);
}
Also used : CompoundCriteria(org.teiid.query.sql.lang.CompoundCriteria) Criteria(org.teiid.query.sql.lang.Criteria) DependentSetCriteria(org.teiid.query.sql.lang.DependentSetCriteria) AbstractSetCriteria(org.teiid.query.sql.lang.AbstractSetCriteria) CompareCriteria(org.teiid.query.sql.lang.CompareCriteria) SetCriteria(org.teiid.query.sql.lang.SetCriteria) DependentSetCriteria(org.teiid.query.sql.lang.DependentSetCriteria) Array(org.teiid.query.sql.symbol.Array) CompoundCriteria(org.teiid.query.sql.lang.CompoundCriteria)

Aggregations

Array (org.teiid.query.sql.symbol.Array)14 Expression (org.teiid.query.sql.symbol.Expression)9 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)5 Constant (org.teiid.query.sql.symbol.Constant)5 StoredProcedure (org.teiid.query.sql.lang.StoredProcedure)4 ArrayImpl (org.teiid.core.types.ArrayImpl)3 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)3 LanguageBridgeFactory (org.teiid.dqp.internal.datamgr.LanguageBridgeFactory)2 Call (org.teiid.language.Call)2 Evaluator (org.teiid.query.eval.Evaluator)2 CompareCriteria (org.teiid.query.sql.lang.CompareCriteria)2 Criteria (org.teiid.query.sql.lang.Criteria)2 DependentSetCriteria (org.teiid.query.sql.lang.DependentSetCriteria)2 Reference (org.teiid.query.sql.symbol.Reference)2 HashSet (java.util.HashSet)1 List (java.util.List)1 TreeMap (java.util.TreeMap)1 QueryMetadataException (org.teiid.api.exception.query.QueryMetadataException)1 QueryResolverException (org.teiid.api.exception.query.QueryResolverException)1