UNPKG

@azure/cosmos

Version:
65 lines 3.29 kB
// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. import { ParallelQueryExecutionContextBase } from "./parallelQueryExecutionContextBase.js"; import { TargetPartitionRangeManager } from "./queryFilteringStrategy/TargetPartitionRangeManager.js"; import { ParallelQueryProcessingStrategy } from "./queryProcessingStrategy/ParallelQueryProcessingStrategy.js"; /** * Provides the ParallelQueryExecutionContext. * This class is capable of handling parallelized queries and derives from ParallelQueryExecutionContextBase. * @hidden */ export class ParallelQueryExecutionContext extends ParallelQueryExecutionContextBase { constructor(clientContext, collectionLink, query, options, partitionedQueryExecutionInfo, correlatedActivityId) { const rangeManager = TargetPartitionRangeManager.createForParallelQuery({ queryInfo: partitionedQueryExecutionInfo, }); // Create parallel query processing strategy const processingStrategy = new ParallelQueryProcessingStrategy(); // Create comparator for document producers const comparator = ParallelQueryExecutionContext.createDocumentProducerComparator(); // Calling on base class constructor super(clientContext, collectionLink, query, options, partitionedQueryExecutionInfo, correlatedActivityId, rangeManager, processingStrategy, comparator); } /** * Fetches all buffered items from producer for parallel processing. */ async fetchFromProducer(producer) { return producer.fetchBufferedItems(); } /** * Determines if buffered producers should continue to be processed for parallel queries. * For parallel queries, we process all buffered producers. * @param _isUnfilledQueueEmpty - Whether the unfilled queue is empty (ignored for parallel queries) * @hidden */ shouldProcessBufferedProducers(_isUnfilledQueueEmpty) { return true; // Process all buffered items in parallel queries } /** * Creates a comparator function for sorting document producers in parallel queries. * Sorts by partition key range minInclusive values, with empty string first, * then lexicographically. Uses EPK ranges as secondary sort when minInclusive values are identical. */ static createDocumentProducerComparator() { return (docProd1, docProd2) => { const aMinInclusive = docProd1.targetPartitionKeyRange.minInclusive; const bMinInclusive = docProd2.targetPartitionKeyRange.minInclusive; // Sort empty string first, then lexicographically (original logic) if (aMinInclusive === bMinInclusive) { // If minInclusive values are the same, check minEPK ranges if they exist const aMinEpk = docProd1.startEpk; const bMinEpk = docProd2.startEpk; if (aMinEpk && bMinEpk) { return aMinEpk < bMinEpk ? -1 : 1; } return 0; } if (aMinInclusive === "") return -1; if (bMinInclusive === "") return 1; return aMinInclusive < bMinInclusive ? -1 : 1; }; } } //# sourceMappingURL=parallelQueryExecutionContext.js.map