<commit_before>package com.splicemachine.derby.impl.sql.compile;

import com.splicemachine.db.iapi.sql.compile.CostEstimate;
import com.splicemachine.db.iapi.sql.compile.RowOrdering;
import com.splicemachine.db.iapi.store.access.SortCostController;
import com.splicemachine.db.iapi.store.access.StoreCostController;

import java.text.DecimalFormat;

/**
 * @author <NAME>
 *         Date: 3/13/15
 */
public class SimpleCostEstimate implements CostEstimate{
    private double localCost = Double.MAX_VALUE;
    private double remoteCost;
    private int numPartitions;
    private double numRows = Double.MAX_VALUE;

    private double singleScanRowCount = Double.MAX_VALUE;
    private RowOrdering rowOrdering;

    private CostEstimate baseCost;
    private boolean isRealCost=true;
    private StoreCostController storeCost;
    private SortCostController sortCost;
    private long estimatedHeapSize;

    private double openCost;
    private double closeCost;

    public SimpleCostEstimate(){ }

    public SimpleCostEstimate(double theCost,double theRowCount,double theSingleScanRowCount){
        this(theCost,0d,theRowCount,theSingleScanRowCount,1);
    }

    public SimpleCostEstimate(double localCost,double remoteCost,double numRows,double singleScanRowCount,int numPartitions){
        this.localCost=localCost;
        this.remoteCost=remoteCost;
        this.numRows=numRows;
        this.singleScanRowCount=singleScanRowCount;
        this.numPartitions=numPartitions;
    }

    public SimpleCostEstimate(double localCost,
                              double remoteCost,
                              double numRows,
                              double singleScanRowCount,
                              int numPartitions,
                              CostEstimate base){
        this(localCost, remoteCost, numRows, singleScanRowCount, numPartitions);
        this.baseCost = base;
    }

    public void setStoreCost(StoreCostController storeCost){
        this.storeCost = storeCost;
    }

    public StoreCostController getStoreCost(){
        return storeCost;
    }

    @Override public double getOpenCost(){ return openCost; }
    @Override public double getCloseCost(){ return closeCost; }

    @Override public void setOpenCost(double openCost){ this.openCost = openCost;}
    @Override public void setCloseCost(double closeCost){ this.closeCost = closeCost;}

    @Override
    public void setCost(double cost,double rowCount,double singleScanRowCount){
        setCost(cost,rowCount,singleScanRowCount,1);
    }

    @Override
    public void setCost(double cost,double rowCount,double singleScanRowCount,int numPartitions){
        this.localCost = cost;
        this.numRows = rowCount;
        this.singleScanRowCount = singleScanRowCount;
        this.numPartitions = numPartitions;
    }

    @Override
    public void setCost(CostEstimate other){
        this.localCost = other.localCost();
        this.remoteCost = other.remoteCost();
        this.numPartitions =other.partitionCount();
        this.numRows = other.rowCount();
        this.singleScanRowCount = other.singleScanRowCount();
        this.estimatedHeapSize = other.getEstimatedHeapSize();
        this.openCost = other.getOpenCost();
        this.closeCost = other.getCloseCost();
        RowOrdering rowOrdering=other.getRowOrdering();
        if(rowOrdering!=null)
            this.rowOrdering = rowOrdering.getClone();
        else
            this.rowOrdering = null;

        CostEstimate base=other.getBase();
        if(base!=null && base != other)
            this.baseCost = base.cloneMe();
    }


    @Override
    public String prettyString(){
        DecimalFormat df = new DecimalFormat();
        df.setMaximumFractionDigits(3);
        df.setGroupingUsed(false);

        return "(overallCost="+df.format(getEstimatedCost())
                +",localCost="+df.format(localCost())
                +",remoteCost="+df.format(remoteCost())
                +",outputRows="+getEstimatedRowCount()
                +",outputHeapSize="+getEstimatedHeapSize()+
                ",partitions="+partitionCount()+")";
    }

    @Override
    public String toString(){
        return "(overallCost="+getEstimatedCost()
                +",localCost="+localCost()
                +",remoteCost="+remoteCost()
                +",outputRows="+getEstimatedRowCount()
                +",outputHeapSize="+getEstimatedHeapSize()+
                ",partitions="+partitionCount()+")";
    }

    @Override public void setRowCount(double outerRows){ this.numRows = outerRows;  }
    @Override public void setRemoteCost(double remoteCost){ this.remoteCost = remoteCost; }
    @Override public void setSingleScanRowCount(double singleRowScanCount){this.singleScanRowCount = singleRowScanCount;}
    @Override public void setNumPartitions(int numPartitions){ this.numPartitions = numPartitions; }
    @Override public double rowCount(){ return numRows; }
    @Override public double singleScanRowCount(){ return singleScanRowCount; }
    @Override public int partitionCount(){ return numPartitions; }
    @Override public double remoteCost(){ return remoteCost; }
    @Override public double localCost(){ return localCost; }
    @Override public RowOrdering getRowOrdering(){ return rowOrdering; }
    @Override public void setRowOrdering(RowOrdering rowOrdering){ this.rowOrdering = rowOrdering; }
    @Override public CostEstimate getBase(){ return baseCost==null?this:baseCost; }<commit_msg>Changing explain cost info for better readability.<commit_after>package com.splicemachine.derby.impl.sql.compile;

import com.splicemachine.db.iapi.sql.compile.CostEstimate;
import com.splicemachine.db.iapi.sql.compile.RowOrdering;
import com.splicemachine.db.iapi.store.access.SortCostController;
import com.splicemachine.db.iapi.store.access.StoreCostController;

import java.text.DecimalFormat;

/**
 * @author <NAME>
 *         Date: 3/13/15
 */
public class SimpleCostEstimate implements CostEstimate{
    private double localCost = Double.MAX_VALUE;
    private double remoteCost;
    private int numPartitions;
    private double numRows = Double.MAX_VALUE;

    private double singleScanRowCount = Double.MAX_VALUE;
    private RowOrdering rowOrdering;

    private CostEstimate baseCost;
    private boolean isRealCost=true;
    private StoreCostController storeCost;
    private SortCostController sortCost;
    private long estimatedHeapSize;

    private double openCost;
    private double closeCost;

    public SimpleCostEstimate(){ }

    public SimpleCostEstimate(double theCost,double theRowCount,double theSingleScanRowCount){
        this(theCost,0d,theRowCount,theSingleScanRowCount,1);
    }

    public SimpleCostEstimate(double localCost,double remoteCost,double numRows,double singleScanRowCount,int numPartitions){
        this.localCost=localCost;
        this.remoteCost=remoteCost;
        this.numRows=numRows;
        this.singleScanRowCount=singleScanRowCount;
        this.numPartitions=numPartitions;
    }

    public SimpleCostEstimate(double localCost,
                              double remoteCost,
                              double numRows,
                              double singleScanRowCount,
                              int numPartitions,
                              CostEstimate base){
        this(localCost, remoteCost, numRows, singleScanRowCount, numPartitions);
        this.baseCost = base;
    }

    public void setStoreCost(StoreCostController storeCost){
        this.storeCost = storeCost;
    }

    public StoreCostController getStoreCost(){
        return storeCost;
    }

    @Override public double getOpenCost(){ return openCost; }
    @Override public double getCloseCost(){ return closeCost; }

    @Override public void setOpenCost(double openCost){ this.openCost = openCost;}
    @Override public void setCloseCost(double closeCost){ this.closeCost = closeCost;}

    @Override
    public void setCost(double cost,double rowCount,double singleScanRowCount){
        setCost(cost,rowCount,singleScanRowCount,1);
    }

    @Override
    public void setCost(double cost,double rowCount,double singleScanRowCount,int numPartitions){
        this.localCost = cost;
        this.numRows = rowCount;
        this.singleScanRowCount = singleScanRowCount;
        this.numPartitions = numPartitions;
    }

    @Override
    public void setCost(CostEstimate other){
        this.localCost = other.localCost();
        this.remoteCost = other.remoteCost();
        this.numPartitions =other.partitionCount();
        this.numRows = other.rowCount();
        this.singleScanRowCount = other.singleScanRowCount();
        this.estimatedHeapSize = other.getEstimatedHeapSize();
        this.openCost = other.getOpenCost();
        this.closeCost = other.getCloseCost();
        RowOrdering rowOrdering=other.getRowOrdering();
        if(rowOrdering!=null)
            this.rowOrdering = rowOrdering.getClone();
        else
            this.rowOrdering = null;

        CostEstimate base=other.getBase();
        if(base!=null && base != other)
            this.baseCost = base.cloneMe();
    }


    @Override
    public String prettyString(){
        DecimalFormat df = new DecimalFormat();
        df.setMaximumFractionDigits(3);
        df.setGroupingUsed(false);

        return "(overallCost="+df.format(getEstimatedCost())
                +",processingCost="+df.format(localCost())
                +",networkCost="+df.format(remoteCost())
                +",outputRows="+getEstimatedRowCount()
                +",outputHeapSize="+getEstimatedHeapSize()+
                ",partitions="+partitionCount()+")";
    }

    @Override
    public String toString(){
        return "(overallCost="+getEstimatedCost()
                +",processingCost="+localCost()
                +",networkCost="+remoteCost()
                +",outputRows="+getEstimatedRowCount()
                +",outputHeapSize="+getEstimatedHeapSize()+
                ",partitions="+partitionCount()+")";
    }

    @Override public void setRowCount(double outerRows){ this.numRows = outerRows;  }
    @Override public void setRemoteCost(double remoteCost){ this.remoteCost = remoteCost; }
    @Override public void setSingleScanRowCount(double singleRowScanCount){this.singleScanRowCount = singleRowScanCount;}
    @Override public void setNumPartitions(int numPartitions){ this.numPartitions = numPartitions; }
    @Override public double rowCount(){ return numRows; }
    @Override public double singleScanRowCount(){ return singleScanRowCount; }
    @Override public int partitionCount(){ return numPartitions; }
    @Override public double remoteCost(){ return remoteCost; }
    @Override public double localCost(){ return localCost; }
    @Override public RowOrdering getRowOrdering(){ return rowOrdering; }
    @Override public void setRowOrdering(RowOrdering rowOrdering){ this.rowOrdering = rowOrdering; }
    @Override public CostEstimate getBase(){ return baseCost==null?this:baseCost; }
{'fraction_non_alphanumeric': 0.09391162326467653, 'fraction_numerical': 0.0016332456219943744, 'mean_word_length': 3.1972581873571975, 'pattern_counts': {'":': 0, '<': 5, '<?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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '381498', 'n_tokens_mistral': 2967, 'n_tokens_neox': 2938, 'n_words': 614}