@azure/cosmos
Version:
Microsoft Azure Cosmos DB Service Node.js SDK for NOSQL API
87 lines (86 loc) • 3.74 kB
JavaScript
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 parallelQueryExecutionContext_exports = {};
__export(parallelQueryExecutionContext_exports, {
ParallelQueryExecutionContext: () => ParallelQueryExecutionContext
});
module.exports = __toCommonJS(parallelQueryExecutionContext_exports);
var import_parallelQueryExecutionContextBase = require("./parallelQueryExecutionContextBase.js");
var import_TargetPartitionRangeManager = require("./queryFilteringStrategy/TargetPartitionRangeManager.js");
var import_ParallelQueryProcessingStrategy = require("./queryProcessingStrategy/ParallelQueryProcessingStrategy.js");
class ParallelQueryExecutionContext extends import_parallelQueryExecutionContextBase.ParallelQueryExecutionContextBase {
constructor(clientContext, collectionLink, query, options, partitionedQueryExecutionInfo, correlatedActivityId) {
const rangeManager = import_TargetPartitionRangeManager.TargetPartitionRangeManager.createForParallelQuery({
queryInfo: partitionedQueryExecutionInfo
});
const processingStrategy = new import_ParallelQueryProcessingStrategy.ParallelQueryProcessingStrategy();
const comparator = ParallelQueryExecutionContext.createDocumentProducerComparator();
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;
}
/**
* 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;
if (aMinInclusive === bMinInclusive) {
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;
};
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
ParallelQueryExecutionContext
});