Package adipe.translate.ra

Examples of adipe.translate.ra.Relation


     * TODO update
     */
    protected State2 registerTableByName(String primaryName, String knownAs, List<String> derivedColumnList)
            throws IndexOutOfBoundsException, TranslationException
    {
        Relation r;
        ColumnNamesImpl[] colNamesWr = new ColumnNamesImpl[1];
        try {
            r = schema.instantiateTable(primaryName, knownAs, derivedColumnList, colNamesWr);
        } catch (IllegalStateException exc) {
            throw new TranslationException(exc.getMessage(), exc);
        }
        registerRelation(r.alias(), colNamesWr[0]);
        return makeState2(r, colNamesWr[0].asColumnIndexesLookup(), addQualifiedColumnNames(knownAs == null?primaryName:knownAs, colNamesWr[0]));
    }
View Full Code Here


        ColumnNamesImpl[] colNamesWr = new ColumnNamesImpl[1];

        alias             = correlationSpecificationCtx.correlationName().getText();
        derivedColumnList = visitDerivedColumnList(correlationSpecificationCtx.derivedColumnList());
        subqueryCtx       = derivedTable.tableSubquery().subquery();
        Relation subquery = translates.translate(subqueryCtx, alias, derivedColumnList, colNamesWr);

        registerRelation(subquery.alias(), colNamesWr[0]);

        return makeState2(subquery, colNamesWr[0].asColumnIndexesLookup(), addQualifiedColumnNames(subquery.alias(), colNamesWr[0]));
    }
View Full Code Here

        if (checkContainsSubquery(p)) {
            throw new RuntimeException("not implemented (EXISTS in JOIN condition)");
        }

        Relation rel;
        if (! isInnerJoin) {
            if (joinType.UNION() != null) {
                throw new RuntimeException("UNION JOIN is not supported");// TODO
            } else {
                checkNotNull(joinType.outerJoinType());
                if (joinType.outerJoinType().LEFT() != null) {
                    rel = r1.relation().leftOuterJoin(r2.relation(), pcode, pIsEq);
                } else if (joinType.outerJoinType().RIGHT() != null) {
                    rel = r1.relation().rightOuterJoin(r2.relation(), pcode, pIsEq);
                } else {
                    checkNotNull(joinType.outerJoinType().FULL());
                    rel = r1.relation().fullOuterJoin(r2.relation(), pcode, pIsEq);
                }
            }
        } else {
            rel = r1.relation().join(r2.relation(), pcode, pIsEq);
        }

        return makeState2(rel, rel.columns(), named);
    }
View Full Code Here

    * TODO update
    */
    Relation visitSelectStatement(SelectStatementContext ctx)
            throws IndexOutOfBoundsException, RuntimeException, WrappedException, TranslationException
    {
        Relation unordered = visitQueryExpression(ctx.queryExpression());
        if (ctx.orderByClause() == null) {
            return unordered;
        }
        SortSpecificationListContext sslc = ctx.orderByClause().sortSpecificationList();
        //TODO support ORDER BY multiple columns
        checkState(sslc.COMMA().isEmpty());
        SortSpecificationContext ssc = sslc.sortSpecification(0);

        boolean asc = ssc.orderingSpecification() == null || ssc.orderingSpecification().ASC() != null;

        if (ssc.sortKey().columnName() != null) {
            SimpleColumn sc = scopeIncludingAliases.getColumnIcShdWrapNambNind(ssc.sortKey().columnName().getText());
            return unordered.orderBy(sc, asc);
        } else {
            int columnNo = visitUnsignedInteger(ssc.sortKey().unsignedInteger());
            return unordered.orderBy(columnNo, asc);
        }
    }
View Full Code Here

            @Override
            public Relation translate(SubqueryContext ctx, String newName, List<String> derivedColumnList, ColumnNamesImpl[] colNamesWr)
                throws TranslationException, IndexOutOfBoundsException, RuntimeException, WrappedException
            {
                TranslationVisitor tv;
                Relation formula;

                tv      = subqueryTranslationVisitorWithOuterScope();
                formula = tv.visitQueryExpression(ctx.queryExpression());

                if (derivedColumnList != null) {
                    colNamesWr[0] = formula.renameColumns(derivedColumnList);
                } else {
                    colNamesWr[0] = new ColumnNamesImpl(formula.columns());
                }
                return formula.withAlias(newName);
            }

        };
    }
View Full Code Here

            lt.checkCanSetOperations(rt);
        }

        boolean removeDuplicates = ! all;

        Relation rightFormula = rightTranslator.state.rela;
        if (union_notExcept) {
            state.rela = state.rela.union(rightFormula, removeDuplicates);
        } else {
            state.rela = state.rela.except(rightFormula, removeDuplicates);
        }
View Full Code Here

     * TODO update
     */
    void processCondition(Proposition condition, ColumnNamesLookup columnNamesLookup, ColumnIndexes interprets)
        throws TranslationException
    {
        Relation newRela = state.rela.makeEmpty("nameInSchema", "newName");
        if (checkContainsSubquery(condition)) {
            /* the tree contains a subquery */
            for (Proposition clause : condition.clauses()) {
                /*
                 * {@link condition} is of form <clause> OR <clause> [OR ...]
                 * we need to normalize all subtrees of {@link condition} which contain the subquery
                 */
                /* At this point, {@link state.formula} contains only the representation of the FROM clause.
                 * It may include 'rel' term introductions of tables; thus, {@link state.formula} should not
                 * turn up twice in the combined formula. Instead, the second and subsequent operands
                 * to {@link Utils.union} will be {@link #tablesFormula}: a 'ref' reference to {@link state.formula}.
                 */
                Relation formulaBase = newRela.isEmpty() ? state.rela : tablesRelation.get();
                Relation component = processSubqueryInCondition(formulaBase, clause, interprets);
                checkNotNull(component);
                /* each clause of the disjunction is treated separately, then unioned
                 * for example ..WHERE EXISTS subquery1 OR EXISTS subquery2
                 * translates into union(translation-of(..WHERE EXISTS subquery1), translation-of(..WHERE EXISTS subquery2))
                 */
                checkState(component.expandedColumns().size() == state.attributeCount());
                newRela = newRela.union(component, false); // TODO removeDuplicates?
            }
        } else {
            /* a condition that does not contain a subquery is copied verbatim */
            newRela = state.rela.filter(condition, interprets);
View Full Code Here

     */
    private Relation processSubqueryInCondition(Relation formula, Proposition p, ColumnIndexes interprets)
        throws TranslationException
    {
        List<Proposition> subqueryFreeLiterals = new ArrayList<>();
        Relation newFormula = formula;
        for (Proposition literal : p.literals())
        {
            if (checkContainsSubquery(literal)) {
                boolean positive = true;

                if (literal instanceof DnfExcludable) {
                    literal = ((DnfExcludable)literal).delegate();
                }

                if (literal instanceof PropositionalLogic.Not) {
                    positive = false;
                    literal = ((PropositionalLogic.Not)literal).operand();
                }

                checkState(literal instanceof ExistsLiteral);

                Relation nextTablesFormula = newFormula;
                if (!positive) {
                    /* {@code !positive} means it's a WHERE NOT EXISTS condition. We will emit
                     * diffSet(<current value of {@code newFormula}>, subquery) thus
                     * subquery should not use {@code newFormula}'s value as tablesFormula,
                     * but its alias instead*/
                    Term[] ref = new Term[1];
                    nextTablesFormula = newFormula.makeRef(ref);
                }

                /* translate the subquery */
                ExistsLiteral existsLiteral = (ExistsLiteral) literal;
                TableSubqueryContext ctx = existsLiteral.ctx();
                QueryExpressionContext queryExpressionContext = ctx.subquery().queryExpression();
                TranslationVisitor subqueryTranslator = subqueryTranslationVisitor.apply(nextTablesFormula);

                Relation subqueryFormula = subqueryTranslator.visitQueryExpression(queryExpressionContext);

                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) {
                    newFormula = prevNewFormula.except(newFormula, false); // TODO removeDuplicates?
                }
            } else {
                subqueryFreeLiterals.add(literal);
            }
        }
View Full Code Here

TOP

Related Classes of adipe.translate.ra.Relation

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.