Package core

Examples of core.Relation


        dummyRelation = caf.getEmptyRelation();

        //sort the first input
        SortingAscendingOperator sortAscOper1before = new SortingAscendingOperator(caf, inputRelation1, index1);
        formulas.putAll(sortAscOper1before.getFormulas());
        Relation sortedInput1 = sortAscOper1before.getResultRelation();
        dummyRelation = extend(dummyRelation, sortAscOper1before.getDummyRelation());
        dummyRelation = extend(dummyRelation, sortedInput1);
        labels.putAll(sortAscOper1before.getLabels());

        //sort the second input
        SortingAscendingOperator sortAscOper2before = new SortingAscendingOperator(caf, inputRelation2, index2);
        formulas.putAll(sortAscOper2before.getFormulas());
        Relation sortedInput2 = sortAscOper2before.getResultRelation();
        dummyRelation = extend(dummyRelation, sortAscOper2before.getDummyRelation());
        dummyRelation = extend(dummyRelation, sortedInput2);
        labels.putAll(sortAscOper2before.getLabels());


        //semijoin to filter the first input
        SemiJoinOperator semiJoinOper1 = new SemiJoinOperator(caf, sortedInput1, index1, sortedInput2, index2);
        formulas.putAll(semiJoinOper1.getFormulas());
        Relation semiJoinResult1 = semiJoinOper1.getResultRelation();
        dummyRelation = extend(dummyRelation, semiJoinOper1.getDummyRelation());
        dummyRelation = extend(dummyRelation, semiJoinResult1);
        labels.putAll(semiJoinOper1.getLabels());

        //semijoin to filter the second input
        SemiJoinOperator semiJoinOper2 = new SemiJoinOperator(caf, sortedInput2, index2, sortedInput1, index1);
        formulas.putAll(semiJoinOper2.getFormulas());
        Relation semiJoinResult2 = semiJoinOper2.getResultRelation();
        dummyRelation = extend(dummyRelation, semiJoinOper2.getDummyRelation());
        dummyRelation = extend(dummyRelation, semiJoinResult2);
        labels.putAll(semiJoinOper2.getLabels());


        //select (C,count(D)) from (C,D) group by D for the first relation
        int[] indexesWithoutThefirst1 = new int[semiJoinResult1.getCardinality() - 1];
        int dummy = 0;
        for (int c = 2; c <= semiJoinResult1.getCardinality(); c++) {
            indexesWithoutThefirst1[dummy++] = c;
        }

        AggregationOperator agregOper1 = new AggregationOperator(caf, semiJoinResult1, new int[]{1}, new CountExtender(caf, new int[][]{indexesWithoutThefirst1}));
        formulas.putAll(agregOper1.getFormulas());
        Relation groupBy1 = agregOper1.getResultRelation();
        dummyRelation = extend(dummyRelation, agregOper1.getDummyRelation());
        dummyRelation = extend(dummyRelation, groupBy1);
        labels.putAll(agregOper1.getLabels());


        //select (C,count(D)) from (C,D) group by D for the second relation
        int[] indexesWithoutTheFirst2 = new int[semiJoinResult2.getCardinality() - 1];
        dummy = 0;
        for (int c = 2; c <= semiJoinResult2.getCardinality(); c++) {
            indexesWithoutTheFirst2[dummy++] = c;
        }

        AggregationOperator agregOper2 = new AggregationOperator(caf, semiJoinResult2, new int[]{1}, new CountExtender(caf, new int[][]{indexesWithoutTheFirst2}));
        formulas.putAll(agregOper2.getFormulas());
        Relation groupBy2 = agregOper2.getResultRelation();
        dummyRelation = extend(dummyRelation, agregOper2.getDummyRelation());
        dummyRelation = extend(dummyRelation, groupBy2);
        labels.putAll(agregOper2.getLabels());


        //standarization after groupBy1
        StandarizationOperator standOper1 = new StandarizationOperator(caf, groupBy1);
        formulas.putAll(standOper1.getFormulas());
        Relation standarizationResult1 = standOper1.getResultRelation();
        dummyRelation = extend(dummyRelation, standOper1.getDummyRelation());
        dummyRelation = extend(dummyRelation, standarizationResult1);
        labels.putAll(standOper1.getLabels());

        //standarization after groupBy2
        StandarizationOperator standOper2 = new StandarizationOperator(caf, groupBy2);
        formulas.putAll(standOper2.getFormulas());
        Relation standarizationResult2 = standOper2.getResultRelation();
        dummyRelation = extend(dummyRelation, standOper2.getDummyRelation());
        dummyRelation = extend(dummyRelation, standarizationResult2);
        labels.putAll(standOper2.getLabels());


        Relation furtherDummyRelation = caf.getSpaceForNewRelation(7);
        dummyRelation = extend(dummyRelation, furtherDummyRelation);

        //finding row numbers in the input relation that correspond to the group by keys
        Column h = furtherDummyRelation.getFirstCol();
        Column a = sortedInput1.getCol(index1);
        Column e = standarizationResult1.getFirstCol();
        for (int row = 1; row <= 2; row++) {
            formulas.put(h.getCell(row), fillMatch(e.getCell(row), a));
        }
View Full Code Here


        FilterOperator filterOper = new FilterOperator(caf, cartProdOper.getResultRelation(), predicate);
        formulas.putAll(filterOper.getFormulas());
        labels.putAll(filterOper.getLabels());

        dummyRelation = new Relation(cartProdOper.getDummyRelation().getFirstCol(), filterOper.getDummyRelation().getLastCol());
        labelDummy(dummyRelation, "General Join of "+inputRelation1.toString(caf)+" and "+inputRelation2.toString(caf));
        resultRelation = filterOper.getResultRelation();
        labelResult(resultRelation, "General Join of "+inputRelation1.toString(caf)+" and "+inputRelation2.toString(caf));
    }
View Full Code Here

    @Override
    public Object fromString(String string) {
        String[] t = string.split("-");
        int size = Column.fromString(t[1], Utils.getCaf()).getNumber() - Column.fromString(t[0], Utils.getCaf()).getNumber() + 1;
        return new Relation(Utils.getCaf().getSpaceForNewRelation(size));
    }
View Full Code Here

        return new Relation(Utils.getCaf().getSpaceForNewRelation(size));
    }

    @Override
    public String toString(Object obj) {
        Relation r = (Relation) obj;
        return r.getFirstCol().toString(Utils.getCaf()) + "-" + r.getLastCol().toString(Utils.getCaf());
    }
View Full Code Here

        super(caf);

        inputRelation.failOnEmpty();

        dummyRelation = caf.getSpaceForNewRelation(1);
        Relation resultRelationToStandarize = caf.getSpaceForNewRelation(inputRelation.getCardinality());

        for (int row = 1; row <= 2; row++) {
            String pred = predicate;
            //replace relative column references in the predicate with real names
            pred = caf.replaceAll(inputRelation, predicate, row);
//            for (int i = 1; i <= inputRelation.getCardinality(); i++) {
//                pred = pred.replaceAll(ESCAPE_SEQ + i, inputRelation.getCol(i).toString(caf)+row);
//            }

            Cell dummyCell = dummyRelation.getFirstCol().getCell(row);
            formulas.put(dummyCell, pred);

            String strDummyCell = dummyCell.toString(caf);
            Cell in = inputRelation.getFirstCol().getCell(row);
            Cell out = resultRelationToStandarize.getFirstCol().getCell(row);
            for (int i = 1; i <= inputRelation.getCardinality(); i++) {
                String strInputCell = inputRelation.getCol(i).getCell(row).toString(caf);
                formulas.put(out, fillIf(strInputCell, strDummyCell, in));
                out = out.nextInRow();
                in = in.nextInRow();
            }
        }

        StandarizationOperator standOper = new StandarizationOperator(caf, resultRelationToStandarize);
        formulas.putAll(standOper.getFormulas());
        labels.putAll(standOper.getLabels());
        dummyRelation = new Relation(dummyRelation.getFirstCol(), standOper.getDummyRelation().getLastCol());

        labelDummy(dummyRelation, "Filter of " + inputRelation.toString(caf));
        resultRelation = standOper.resultRelation;
        labelResult(resultRelation, "Filter of " + inputRelation.toString(caf));
    }
View Full Code Here

            sourceComment = sourceComment.replace("\n", "\n|   ");
            for (Term formula : formulas) {
                // TODO refactor this and move to QuietSpreadsheetLayout
                Result result = formula.execute();
                ColumnLabels labels = result.getLabels();
                Relation resultRelation = result.getResultRelation();
                for (Column col : resultRelation) {
                    labels.put(col, sourceComment);
                }
                results.add(result);
            }
View Full Code Here

TOP

Related Classes of core.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.