<commit_before>/*
// $Id$
// Firewater is a scaleout column store DBMS.
// Copyright (C) 2011 Dynamo Business Intelligence Corporation

// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 2 of the License, or (at your option)
// any later version approved by Dynamo Business Intelligence Corporation.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

package net.sf.firewater;

import java.util.*;

import net.sf.farrago.fennel.rel.*;
import org.luciddb.lcs.*;
import org.eigenbase.reltype.*;

import net.sf.farrago.catalog.*;
import net.sf.farrago.namespace.jdbc.*;
import net.sf.farrago.query.*;
import net.sf.farrago.fem.med.*;

import org.eigenbase.rel.*;
import org.eigenbase.relopt.*;

import java.util.logging.*;
import net.sf.farrago.trace.*;

/**
 * FirewaterPushDistinctRule removes a top-level LhxAggRel step on the single
 * Firewater instance so that only each partition must do a DISTINCT check.
 *
 * @author <NAME>
 * @version $Id$
 */
public class FirewaterPushDistinctRule extends RelOptRule {

    private static final Logger tracer
        = FarragoTrace.getClassTracer(FirewaterPushDistinctRule.class);

    public static final FirewaterPushDistinctRule instance =
        new FirewaterPushDistinctRule();

    /**
     * Creates a FirewaterPushDistinctRule
     */
    private FirewaterPushDistinctRule()
    {
        super(new RelOptRuleOperand(AggregateRel.class, ANY));
    }

    // implement RelOptRule
    public void onMatch(RelOptRuleCall call)
    {
        AggregateRel agg = (AggregateRel) call.rels[0];
        if (agg.getGroupCount() < 1)
            return;

        tracer.info("ONMATCH CALLED\n\n");
        String count_key = agg.getChild().getRowType().getFields()[0].getName();

        boolean is_partition_column = false;
        // TODO: figure out how to get partition column from node, either by
        // getting a column set, server, or table props, and comparing
        // it to count_key
        // commented code below to help me remember later.
        /*MedJdbcQueryRel otherRel =
            (MedJdbcQueryRel) call.rels[2];
        MedJdbcColumnSet columnSet = otherRel.getColumnSet();
        // here we'd get columnSet.partition_column;
        MedJdbcDataServer server = columnSet.getDirectory().getServer();
        FarragoRepos repos =
            FarragoRelUtil.getPreparingStmt(tableRel).getRepos();
            */
        // this needs a femlocaltable
        //Properties tableProps =
        //    FarragoCatalogUtil.getStorageOptionsAsProperties(repos, (FemLocalTable)table);

        if (!is_partition_column)
            return;

        /*
        for (AggregateCall aggCall : agg.getAggCallList()) {
            tracer.info("AGG LIST\n\n");
            tracer.info(aggCall.toString());
            tracer.info(aggCall.getName());
            for (Integer i : aggCall.getArgList())
                tracer.info(i.toString() + ",");
            RelDataType r = aggCall.getType();
            tracer.info(":\n");
            tracer.info(r.toString());
            for (RelDataTypeField f : r.getFieldList())
                tracer.info(f.getName() + ";" + f.getIndex() + ";");
        }
        */

        RelNode fennelInput = mergeTraitsAndConvert(agg.getTraits(),
                FennelRel.FENNEL_EXEC_CONVENTION,
                agg.getChild());
        if (fennelInput == null)
            return;

        FennelAggRel fenn = new FennelAggRel(
                agg.getCluster(),
                fennelInput,
                agg.getGroupCount(),
                agg.getAggCallList());
        call.transformTo(fenn);
    }
}

<commit_msg>FIREWATER: (FW-11) Further work on this issue. TODO: working table from catalog to grab stored options.<commit_after>/*
// $Id$
// Firewater is a scaleout column store DBMS.
// Copyright (C) 2011 Dynamo Business Intelligence Corporation

// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 2 of the License, or (at your option)
// any later version approved by Dynamo Business Intelligence Corporation.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

package net.sf.firewater;

import java.util.*;

import net.sf.farrago.fennel.rel.*;
import org.luciddb.lcs.*;
import org.eigenbase.reltype.*;

import net.sf.farrago.catalog.*;
import net.sf.farrago.namespace.jdbc.*;
import net.sf.farrago.query.*;
import net.sf.farrago.fem.med.*;

import org.eigenbase.rel.*;
import org.eigenbase.relopt.*;

import java.util.logging.*;
import net.sf.farrago.trace.*;

import org.eigenbase.relopt.hep.*;

/**
 * FirewaterPushDistinctRule removes a top-level LhxAggRel step on the single
 * Firewater instance so that only each partition must do a DISTINCT check.
 *
 * @author <NAME>
 * @version $Id$
 */
public class FirewaterPushDistinctRule extends RelOptRule {

    private static final Logger tracer
        = FarragoTrace.getClassTracer(FirewaterPushDistinctRule.class);

    public static final FirewaterPushDistinctRule instance =
        new FirewaterPushDistinctRule();

    /**
     * Creates a FirewaterPushDistinctRule
     */
    private FirewaterPushDistinctRule()
    {
        super(new RelOptRuleOperand(
                    AggregateRel.class,
                    new RelOptRuleOperand(
                        AggregateRel.class,
                        new RelOptRuleOperand(
                            UnionRel.class, ANY))));
    }

    public void onMatch(RelOptRuleCall call)
    {
        AggregateRel agg = (AggregateRel) call.rels[0];
        AggregateRel child = (AggregateRel) call.rels[1];
        UnionRel uni = (UnionRel) call.rels[2];

        //tracer.info("OHYEAH CALLED\n\n");
        // Assert that the top node is groupless and child is grouping for
        // distinct.
        if (child.getGroupCount() != 1)
            return;
        // Assert that the aggs have been pushed through the union
        if (!(((HepRelVertex)uni.getInput(0)).getCurrentRel() instanceof AggregateRel))
            return;


        // Assert that the key we're grouping by (count_key) is the
        // PARTITION_COLUMN stored in the table.
        String count_key = agg.getChild().getRowType().getFields()[0].getName();

        boolean is_partition_column = false;
        // Grab the FemLocalTable from the catalog.
        // (Commented out w.i.p. since it wasn't working right and haven't
        // fixed it yet.)
        FarragoRepos repos =
            FarragoRelUtil.getPreparingStmt(call.rels[0]).getRepos();
        RelOptTable tab = agg.getTable();
        //CwmCatalog catalog = repos.getSelfAsCatalog();
        /*for (CwmModelElement element : catalog.getOwnedElement()) {
            if (element instanceof FemLocalTable) {
                Properties tableProps =
                    FarragoCatalogUtil.getStorageOptionsAsProperties(repos, (FemLocalTable)table);
                    */

        is_partition_column = true;
        if (!is_partition_column)
            return;

        FennelAggRel newtop = new FennelAggRel(
            agg.getCluster(),
            child.getChild(),
            agg.getGroupCount(),
            agg.getAggCallList());

        call.transformTo(newtop);
    }
}


{'fraction_non_alphanumeric': 0.09804398007532499, 'fraction_numerical': 0.00619608796015065, 'mean_word_length': 2.551337359792925, 'pattern_counts': {'":': 1, '<': 6, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5525804', 'n_tokens_mistral': 2392, 'n_tokens_neox': 2268, 'n_words': 698}