"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.computePreAggregateWarnings = exports.PRE_AGGREGATE_ROW_COUNT_WARNING_THRESHOLD = exports.preAggregateMissReasonLabels = exports.PreAggregateMissReason = void 0;
var PreAggregateMissReason;
(function (PreAggregateMissReason) {
    PreAggregateMissReason["NO_PRE_AGGREGATES_DEFINED"] = "no_pre_aggregates_defined";
    PreAggregateMissReason["DIMENSION_NOT_IN_PRE_AGGREGATE"] = "dimension_not_in_pre_aggregate";
    PreAggregateMissReason["METRIC_NOT_IN_PRE_AGGREGATE"] = "metric_not_in_pre_aggregate";
    PreAggregateMissReason["NON_ADDITIVE_METRIC"] = "non_additive_metric";
    PreAggregateMissReason["CUSTOM_SQL_METRIC"] = "custom_sql_metric";
    PreAggregateMissReason["FILTER_DIMENSION_NOT_IN_PRE_AGGREGATE"] = "filter_dimension_not_in_pre_aggregate";
    PreAggregateMissReason["PRE_AGGREGATE_FILTER_NOT_SATISFIED"] = "pre_aggregate_filter_not_satisfied";
    PreAggregateMissReason["GRANULARITY_TOO_FINE"] = "granularity_too_fine";
    PreAggregateMissReason["CUSTOM_DIMENSION_PRESENT"] = "custom_dimension_present";
    PreAggregateMissReason["CUSTOM_METRIC_PRESENT"] = "custom_metric_present";
    PreAggregateMissReason["TABLE_CALCULATION_PRESENT"] = "table_calculation_present";
    PreAggregateMissReason["USER_BYPASS"] = "user_bypass";
    PreAggregateMissReason["EXPLORE_RESOLUTION_ERROR"] = "explore_resolution_error";
    PreAggregateMissReason["NO_ACTIVE_MATERIALIZATION"] = "no_active_materialization";
})(PreAggregateMissReason || (exports.PreAggregateMissReason = PreAggregateMissReason = {}));
exports.preAggregateMissReasonLabels = {
    [PreAggregateMissReason.NO_PRE_AGGREGATES_DEFINED]: 'No pre-aggregates defined',
    [PreAggregateMissReason.DIMENSION_NOT_IN_PRE_AGGREGATE]: 'Dimension not in pre-aggregate',
    [PreAggregateMissReason.METRIC_NOT_IN_PRE_AGGREGATE]: 'Metric not in pre-aggregate',
    [PreAggregateMissReason.NON_ADDITIVE_METRIC]: 'Non-additive metric',
    [PreAggregateMissReason.CUSTOM_SQL_METRIC]: 'Custom SQL metric',
    [PreAggregateMissReason.FILTER_DIMENSION_NOT_IN_PRE_AGGREGATE]: 'Filter dimension not in pre-aggregate',
    [PreAggregateMissReason.PRE_AGGREGATE_FILTER_NOT_SATISFIED]: 'Pre-aggregate filter not satisfied',
    [PreAggregateMissReason.GRANULARITY_TOO_FINE]: 'Granularity too fine',
    [PreAggregateMissReason.CUSTOM_DIMENSION_PRESENT]: 'Custom dimension detected',
    [PreAggregateMissReason.CUSTOM_METRIC_PRESENT]: 'Custom metric detected',
    [PreAggregateMissReason.TABLE_CALCULATION_PRESENT]: 'SQL Table calculation detected',
    [PreAggregateMissReason.USER_BYPASS]: 'Bypassed by user',
    [PreAggregateMissReason.EXPLORE_RESOLUTION_ERROR]: 'Materialized explore not found',
    [PreAggregateMissReason.NO_ACTIVE_MATERIALIZATION]: 'No active materialization',
};
exports.PRE_AGGREGATE_ROW_COUNT_WARNING_THRESHOLD = 1000000;
const computePreAggregateWarnings = (materialization, options = {}) => {
    const { rowCountThreshold = exports.PRE_AGGREGATE_ROW_COUNT_WARNING_THRESHOLD, materializationMaxRows = null, } = options;
    const warnings = [];
    const rowCount = materialization?.rowCount;
    if (materializationMaxRows != null &&
        rowCount != null &&
        rowCount >= materializationMaxRows) {
        warnings.push({
            type: 'max_rows_applied',
            message: `This pre-aggregate was capped at ${materializationMaxRows.toLocaleString()} rows. Results may be incomplete.`,
            maxRows: materializationMaxRows,
        });
    }
    if (rowCount != null && rowCount > rowCountThreshold) {
        warnings.push({
            type: 'row_count_exceeded',
            message: `This pre-aggregate has ${rowCount.toLocaleString()} rows, which exceeds the recommended threshold of ${rowCountThreshold.toLocaleString()} rows. Large pre-aggregates may take longer to build and consume more storage.`,
            rowCount,
            threshold: rowCountThreshold,
        });
    }
    return warnings;
};
exports.computePreAggregateWarnings = computePreAggregateWarnings;
//# sourceMappingURL=preAggregate.js.map