Package adipe.translate.sql

Examples of adipe.translate.sql.ColumnIndexesImpl


     */
    private QueryExpressionTranslation(State state, Schema schema) {
        this.state = state;
        this.tablesRelation = new TablesRelation(this.state.rela);
        this.schema = schema;
        this.state2 = new State2(this.tablesRelation.value, new ColumnIndexesImpl(), this.state.scope.columnScope().asColumnNames(), state.scope.tableScope());
    }
View Full Code Here


        if (! built) {
            built = true;

            conjureAttributes();
            if (needGroupByOperator()) {
                ColumnIndexesImpl attributesBeforeGroupBy = intermediate.columns();
                useGroupByOperator();
                applyAggregations(attributesBeforeGroupBy);
                applyHavingCondition();
            }
            applySelectionOperator();
View Full Code Here

            formula = Relation.refTableFormula(nameInSchemaCaseSensitive);
        } else {
            formula = Relation.relTableFormula(nameInSchemaCaseSensitive, table.size());
            instantiatedTables.add(nameInSchemaIc);
        }
        ColumnIndexesImpl c = table.asColumnIndexesLookup();
        return new Relation(namesRelations, newName, formula, c, c);
    }
View Full Code Here

                Relation prevNewFormula = newFormula;
                newFormula = subqueryFormula;

                /* project the results on the outer query, ie. drop the subquery's attributes */
                ColumnIndexesImpl ec = new ColumnIndexesImpl();
                for (int i = 0; i < state.rela.expandedColumns().size(); ++i) {
                    ec.add(newFormula.expandedColumns().get(i));
                }
                newFormula = newFormula.select(tablesRelation.value.columns(), false);
                newFormula = newFormula.withExpandedColumns(ec);

                if (!positive) {
View Full Code Here

    /**
     * @param indexes as numbered in {@link columns}, not {@link expandedColumns}
     * @return the result's {@link expandedColumns} are the projected-on columns
     */
    public Relation project(int[] indexes) {
        ColumnIndexesImpl c = new ColumnIndexesImpl(this.columns());
        c = c.select(indexes);
        return makeNew(Terms.project(this.formula(), indexes), c, c);
    }
View Full Code Here

            return makeNew(Utils.sortDesc(this.formula(), columnNo), this.columns(), this.expandedColumns());
        }
    }

    public Relation multiply(Relation that) {
        ColumnIndexesImpl c = new ColumnIndexesImpl(this.columns());
        c.addAll(that.columns());
        ColumnIndexesImpl ec = new ColumnIndexesImpl(this.expandedColumns());
        ec.addAll(that.expandedColumns());
        return makeNew(Utils.cartProd(this.formula, that.formula), c, ec);
    }
View Full Code Here

    public Relation select(Iterable<? extends Expression> selectElems, boolean allowOmit) {
        List<String> selectedStrs = Lists.newArrayList();
        List<Integer> projectionInts = Lists.newArrayList();
        boolean canUseProject = true;
        boolean canOmitProjectSelect = true;
        ColumnIndexesImpl attributesAfterSelection = new ColumnIndexesImpl();
        ChainedColumnIndexes attr =
                new ChainedColumnIndexes(new ChainedColumnIndexes(null, this.columns()));

        int i = 0;

        for (Expression expr : selectElems) {
            ++ i;
            if (expr.codeRefersToConjuredColumn()) {
                try {
                    // TODO fix this - do not even attempt to add a second time here
                    attr.find(expr.conjure().column());
                } catch (IndexOutOfBoundsException ex) {
                    attr.add(expr.conjure().column());
                }
            }
            if (! expr.isSuitableForProject()) {
                canUseProject = false;
            }
            projectionInts.add(expr.conjure().conjuredIndex(attr.columnIndexes()));
            attributesAfterSelection.add(expr.conjure().column());
            if (i > columns().size() || expr.conjure().column() != columns().get(i-1)) {
                canOmitProjectSelect = false;
            }
            selectedStrs.add(expr.code(attr.columnIndexes()));
        }

        if (attributesAfterSelection.size() != columns().size()) {
            canOmitProjectSelect = false;
        }

        if (canOmitProjectSelect && allowOmit) {
            return this;
View Full Code Here

        List<Integer> colIdxs = Lists.newArrayList();
        for (NonAggregated nc : exprs) {
            colIdxs.add(1 + columns.find(nc.conjure().column()));
        }
        int[] colsArr = Ints.toArray(colIdxs);
        ColumnIndexesImpl c = this.columns().select(exprs);
        if (colsArr.length == 0) {
          return makeNew(Utils.groupBy(this.formula()), c, c);
        } else {
          return makeNew(Utils.groupBy(this.formula(), colsArr), c, c);
        }
View Full Code Here


    private final static Pattern EQ_PATTERN = Pattern.compile("#(\\d+)=#(\\d+)");

    public Relation join(Relation that, String pred, boolean conditionIsEq) {
        ColumnIndexesImpl attributesOrder = new ColumnIndexesImpl()// the columns that comprise the result of the join

        ColumnIndexesImpl attributesOrderInExpanded = new ColumnIndexesImpl();
        attributesOrderInExpanded.addAll(this.expandedColumns());
        attributesOrderInExpanded.addAll(that.expandedColumns());

        Term t1 = formula;
        Term t2 = that.formula();
        Term joined;

        if (! conditionIsEq) {
            joined = Utils.genJoin(t1, t2, pred);
            attributesOrder.addAll(this.columns());
            attributesOrder.addAll(that.columns());
        } else {
            // TODO pass index1, index2 from caller instead of reading it from the string
            Matcher eqMatcher = EQ_PATTERN.matcher(pred);
            checkState(eqMatcher.matches());
            int index1 = Integer.parseInt(eqMatcher.group(1));
            int index2 = Integer.parseInt(eqMatcher.group(2));

            if (index1 > index2) {
                int index;
                index = index2;
                index2 = index1;
                index1 = index;
            }

            index2 = index2 - this.columns().size();

            joined = Utils.eqJoin(t1, t2, index1, index2);

            attributesOrder.add(this.columns().get(index1-1));
            for (int i = 0; i < this.columns().size(); ++i) {
                if (i + 1 != index1) {
                    attributesOrder.add(this.columns().get(i));
                }
            }
            for (int i = 0; i < that.columns().size(); ++i) {
                if (i + 1 != index2) {
                    attributesOrder.add(that.columns().get(i));
                }
            }

            SimpleColumn replacedColumn = that.columns.get(index2-1);
            SimpleColumn replacedBy = this.columns.get(index1-1);
            attributesOrderInExpanded.replace(replacedColumn, replacedBy);
        }

        return new Relation(namesRelations, null, joined, attributesOrder, attributesOrderInExpanded);
    }
View Full Code Here

    public Relation applyAggregation(Aggregated ag, int columnIndex) {
        checkState(this.isExpanded()); // TODO
        checkState(this.formula() instanceof AggregT);

        ColumnIndexesImpl c = new ColumnIndexesImpl(this.columns());
        c.add(ag.conjure().column());

        return makeNew(ag.apply((AggregT) this.formula(), columnIndex), c, c);
    }
View Full Code Here

TOP

Related Classes of adipe.translate.sql.ColumnIndexesImpl

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.