UNPKG

@azure/cosmos

Version:
110 lines (109 loc) 4.04 kB
var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var TargetPartitionRangeManager_exports = {}; __export(TargetPartitionRangeManager_exports, { QueryExecutionContextType: () => QueryExecutionContextType, TargetPartitionRangeManager: () => TargetPartitionRangeManager }); module.exports = __toCommonJS(TargetPartitionRangeManager_exports); var import_ParallelQueryRangeStrategy = require("./ParallelQueryRangeStrategy.js"); var import_OrderByQueryRangeStrategy = require("./OrderByQueryRangeStrategy.js"); var QueryExecutionContextType = /* @__PURE__ */ ((QueryExecutionContextType2) => { QueryExecutionContextType2["Parallel"] = "Parallel"; QueryExecutionContextType2["OrderBy"] = "OrderBy"; return QueryExecutionContextType2; })(QueryExecutionContextType || {}); class TargetPartitionRangeManager { strategy; config; constructor(config) { this.config = config; this.strategy = this.createStrategy(config); } /** * Creates the appropriate strategy based on configuration */ createStrategy(config) { if (config.customStrategy) { return config.customStrategy; } switch (config.queryType) { case "Parallel" /* Parallel */: return new import_ParallelQueryRangeStrategy.ParallelQueryRangeStrategy(); case "OrderBy" /* OrderBy */: return new import_OrderByQueryRangeStrategy.OrderByQueryRangeStrategy(); default: throw new Error(`Unsupported query execution context type: ${config.queryType}`); } } /** * Filters target partition ranges based on range-token pairs from partition split/merge detection * @param targetRanges - All available target partition ranges (fallback if no range-token pairs) * @param rangeTokenPairs - Pre-processed range-token pairs after split/merge detection * @param additionalQueryInfo - Additional query information to merge with existing queryInfo * @returns Filtered partition ranges and metadata */ filterPartitionRanges(targetRanges, rangeTokenPairs, additionalQueryInfo) { if (!targetRanges || targetRanges.length === 0) { return { rangeTokenPairs: [] }; } const mergedQueryInfo = { ...this.config.queryInfo, ...additionalQueryInfo }; const result = this.strategy.filterPartitionRanges( targetRanges, rangeTokenPairs, mergedQueryInfo ); return result; } /** * Gets the current strategy type */ getStrategyType() { return this.strategy.getStrategyType(); } /** * Updates the strategy (useful for switching between query types) */ updateStrategy(newConfig) { this.config = newConfig; this.strategy = this.createStrategy(newConfig); } /** * Static factory method to create a manager for parallel queries */ static createForParallelQuery(queryInfo) { return new TargetPartitionRangeManager({ queryType: "Parallel" /* Parallel */, queryInfo }); } /** * Static factory method to create a manager for ORDER BY queries */ static createForOrderByQuery(queryInfo) { return new TargetPartitionRangeManager({ queryType: "OrderBy" /* OrderBy */, queryInfo }); } } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { QueryExecutionContextType, TargetPartitionRangeManager });