<commit_before>/*
// $Id$
// This software is subject to the terms of the Eclipse Public License v1.0
// Agreement, available at the following URL:
// http://www.eclipse.org/legal/epl-v10.html.
// Copyright (C) 2002-2011 <NAME> and others
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
*/
package mondrian.rolap.agg;

import mondrian.rolap.*;
import mondrian.rolap.agg.SegmentHeader.ConstrainedColumn;
import mondrian.olap.*;

import java.io.Serializable;
import java.sql.*;
import java.util.*;
import java.util.concurrent.*;

import mondrian.server.Locus;
import mondrian.util.CombiningGenerator;
import mondrian.util.Pair;
import org.apache.log4j.Logger;

/**
 * <p>The <code>SegmentLoader</code> queries database and loads the data into
 * the given set of segments.</p>
 *
 * <p>It reads a segment of <code>measure</code>, where <code>columns</code>
 * are constrained to <code>values</code>.  Each entry in <code>values</code>
 * can be null, meaning don't constrain, or can have several values. For
 * example, <code>getSegment({Unit_sales}, {Region, State, Year}, {"West"},
 * {"CA", "OR", "WA"}, null})</code> returns sales in states CA, OR and WA
 * in the Western region, for all years.</p>
 *
 * <p>It will also look at the {@link MondrianProperties#SegmentCache} property
 * and make usage of the SegmentCache provided as an SPI.
 *
 * @author Thiyagu, LBoudreau
 * @version $Id$
 * @since 24 May 2007
 */
public class SegmentLoader {

    private final static Logger LOGGER = Logger.getLogger(SegmentLoader.class);

    private final static ExecutorService executor =
        Util.getExecutorService(
            MondrianProperties.instance().RollupAnalyzerNumberThreads.get(),
            "mondrian.rolap.agg.SegmentLoader$ExecutorThread");

    /**
     * Loads data for all the segments of the GroupingSets. If the grouping sets
     * list contains more than one Grouping Set then data is loaded using the
     * GROUP BY GROUPING SETS sql. Else if only one grouping set is passed in
     * the list data is loaded without using GROUP BY GROUPING SETS sql. If the
     * database does not support grouping sets
     * {@link mondrian.spi.Dialect#supportsGroupingSets()} then
     * grouping sets list should always have only one element in it.
     *
     * <p>For example, if list has 2 grouping sets with columns A, B, C and B, C
     * respectively, then the SQL will be
     * "GROUP BY GROUPING SETS ((A, B, C), (B, C))".
     *
     * <p>Else if the list has only one grouping set then sql would be without
     * grouping sets.
     *
     * <p>The <code>groupingSets</code> list should be topological order, with
     * more detailed higher-level grouping sets occuring first. In other words,
     * the first element of the list should always be the detailed grouping
     * set (default grouping set), followed by grouping sets which can be
     * rolled-up on this detailed grouping set.
     * In the example (A, B, C) is the detailed grouping set and (B, C) is
     * rolled-up using the detailed.
     *
     * @param groupingSets   List of grouping sets whose segments are loaded
     * @param pinnedSegments Pinned segments
     */
    public void load(
        List<GroupingSet> groupingSets,
        RolapAggregationManager.PinSet pinnedSegments,
        List<StarPredicate> compoundPredicateList)
    {
        // Simple assertion. Is this Execution instance still valid,
        // or should we get outa here.
//        if (Locus.peek() != null) {
//            Locus.peek().execution.checkCancelOrTimeout();
//        }

        // First check for cached segments.
        // This method will remove all the segments it fetched from
        // the cache from the groupingSets list.
        loadSegmentsFromCache(groupingSets, pinnedSegments);

        // Now try to load the segments from a rollup
        // operation of other segments.
        loadSegmentsFromCacheRollup(groupingSets, pinnedSegments);

        // Now check if there are segments left which were not
        // loaded from the cache.
        boolean segmentsLeft = false;
        for (GroupingSet gs : groupingSets) {
            if (gs.getSegments().size() > 0) {
                segmentsLeft = true;
                break;
            }
        }

        if (segmentsLeft) {
            SqlStatement stmt = null;
            GroupingSetsList groupingSetsList =
                new GroupingSetsList(groupingSets);
            RolapStar.Column[] defaultColumns =
                groupingSetsList.getDefaultColumns();<commit_msg>MONDRIAN: Fixes a woopsie. This code should not have been commented as it fixes MONDRIAN-948.<commit_after>/*
// $Id$
// This software is subject to the terms of the Eclipse Public License v1.0
// Agreement, available at the following URL:
// http://www.eclipse.org/legal/epl-v10.html.
// Copyright (C) 2002-2011 <NAME> and others
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
*/
package mondrian.rolap.agg;

import mondrian.rolap.*;
import mondrian.rolap.agg.SegmentHeader.ConstrainedColumn;
import mondrian.olap.*;

import java.io.Serializable;
import java.sql.*;
import java.util.*;
import java.util.concurrent.*;

import mondrian.server.Locus;
import mondrian.util.CombiningGenerator;
import mondrian.util.Pair;
import org.apache.log4j.Logger;

/**
 * <p>The <code>SegmentLoader</code> queries database and loads the data into
 * the given set of segments.</p>
 *
 * <p>It reads a segment of <code>measure</code>, where <code>columns</code>
 * are constrained to <code>values</code>.  Each entry in <code>values</code>
 * can be null, meaning don't constrain, or can have several values. For
 * example, <code>getSegment({Unit_sales}, {Region, State, Year}, {"West"},
 * {"CA", "OR", "WA"}, null})</code> returns sales in states CA, OR and WA
 * in the Western region, for all years.</p>
 *
 * <p>It will also look at the {@link MondrianProperties#SegmentCache} property
 * and make usage of the SegmentCache provided as an SPI.
 *
 * @author Thiyagu, LBoudreau
 * @version $Id$
 * @since 24 May 2007
 */
public class SegmentLoader {

    private final static Logger LOGGER = Logger.getLogger(SegmentLoader.class);

    private final static ExecutorService executor =
        Util.getExecutorService(
            MondrianProperties.instance().RollupAnalyzerNumberThreads.get(),
            "mondrian.rolap.agg.SegmentLoader$ExecutorThread");

    /**
     * Loads data for all the segments of the GroupingSets. If the grouping sets
     * list contains more than one Grouping Set then data is loaded using the
     * GROUP BY GROUPING SETS sql. Else if only one grouping set is passed in
     * the list data is loaded without using GROUP BY GROUPING SETS sql. If the
     * database does not support grouping sets
     * {@link mondrian.spi.Dialect#supportsGroupingSets()} then
     * grouping sets list should always have only one element in it.
     *
     * <p>For example, if list has 2 grouping sets with columns A, B, C and B, C
     * respectively, then the SQL will be
     * "GROUP BY GROUPING SETS ((A, B, C), (B, C))".
     *
     * <p>Else if the list has only one grouping set then sql would be without
     * grouping sets.
     *
     * <p>The <code>groupingSets</code> list should be topological order, with
     * more detailed higher-level grouping sets occuring first. In other words,
     * the first element of the list should always be the detailed grouping
     * set (default grouping set), followed by grouping sets which can be
     * rolled-up on this detailed grouping set.
     * In the example (A, B, C) is the detailed grouping set and (B, C) is
     * rolled-up using the detailed.
     *
     * @param groupingSets   List of grouping sets whose segments are loaded
     * @param pinnedSegments Pinned segments
     */
    public void load(
        List<GroupingSet> groupingSets,
        RolapAggregationManager.PinSet pinnedSegments,
        List<StarPredicate> compoundPredicateList)
    {
        // Simple assertion. Is this Execution instance still valid,
        // or should we get outa here.
        Locus.peek().execution.checkCancelOrTimeout();

        // First check for cached segments.
        // This method will remove all the segments it fetched from
        // the cache from the groupingSets list.
        loadSegmentsFromCache(groupingSets, pinnedSegments);

        // Now try to load the segments from a rollup
        // operation of other segments.
        loadSegmentsFromCacheRollup(groupingSets, pinnedSegments);

        // Now check if there are segments left which were not
        // loaded from the cache.
        boolean segmentsLeft = false;
        for (GroupingSet gs : groupingSets) {
            if (gs.getSegments().size() > 0) {
                segmentsLeft = true;
                break;
            }
        }

        if (segmentsLeft) {
            SqlStatement stmt = null;
            GroupingSetsList groupingSetsList =
                new GroupingSetsList(groupingSets);
            RolapStar.Column[] defaultColumns =
                groupingSetsList.getDefaultColumns();
{'fraction_non_alphanumeric': 0.09066173269481934, 'fraction_numerical': 0.004897692642577275, 'mean_word_length': 2.820790020790021, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 55, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '926206', 'n_tokens_mistral': 2619, 'n_tokens_neox': 2500, 'n_words': 978}