@lde/pipeline 0.6.18 → 0.6.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Groups items from an async iterable into arrays of at most `size` items.
3
+ * Yields partial final batches.
4
+ */
5
+ export declare function batch<T>(iterable: AsyncIterable<T>, size: number): AsyncIterable<T[]>;
6
+ //# sourceMappingURL=batch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"batch.d.ts","sourceRoot":"","sources":["../src/batch.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAuB,KAAK,CAAC,CAAC,EAC5B,QAAQ,EAAE,aAAa,CAAC,CAAC,CAAC,EAC1B,IAAI,EAAE,MAAM,GACX,aAAa,CAAC,CAAC,EAAE,CAAC,CAYpB"}
package/dist/batch.js ADDED
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Groups items from an async iterable into arrays of at most `size` items.
3
+ * Yields partial final batches.
4
+ */
5
+ export async function* batch(iterable, size) {
6
+ let buffer = [];
7
+ for await (const item of iterable) {
8
+ buffer.push(item);
9
+ if (buffer.length === size) {
10
+ yield buffer;
11
+ buffer = [];
12
+ }
13
+ }
14
+ if (buffer.length > 0) {
15
+ yield buffer;
16
+ }
17
+ }
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export * from './batch.js';
1
2
  export * from './pipeline.js';
2
3
  export * from './selector.js';
3
4
  export * from './stage.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,uBAAuB,CAAC;AACtC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,uBAAuB,CAAC;AACtC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC"}
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ export * from './batch.js';
1
2
  export * from './pipeline.js';
2
3
  export * from './selector.js';
3
4
  export * from './stage.js';
package/dist/stage.d.ts CHANGED
@@ -6,14 +6,17 @@ export interface StageOptions {
6
6
  name: string;
7
7
  executors: Executor | Executor[];
8
8
  selector?: StageSelector;
9
+ /** Maximum number of bindings per executor call. @default 10 */
10
+ batchSize?: number;
9
11
  }
10
12
  export declare class Stage {
11
13
  readonly name: string;
12
14
  private readonly executors;
13
15
  private readonly selector?;
16
+ private readonly batchSize;
14
17
  constructor(options: StageOptions);
15
18
  run(dataset: Dataset, distribution: Distribution): Promise<AsyncIterable<Quad> | NotSupported>;
16
- private collectBindings;
19
+ private executeAll;
17
20
  }
18
21
  /** Stage-level selector that yields variable bindings for use in executor queries. Pagination is an implementation detail. */
19
22
  export interface StageSelector extends AsyncIterable<VariableBindings> {
@@ -1 +1 @@
1
- {"version":3,"file":"stage.d.ts","sourceRoot":"","sources":["../src/stage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,KAAK,EACV,QAAQ,EAER,gBAAgB,EACjB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEpD,MAAM,WAAW,YAAY;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CAAS;gBAEvB,OAAO,EAAE,YAAY;IAS3B,GAAG,CACP,OAAO,EAAE,OAAO,EAChB,YAAY,EAAE,YAAY,GACzB,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,GAAG,YAAY,CAAC;YAwBhC,UAAU;CAkBzB;AAUD,8HAA8H;AAE9H,MAAM,WAAW,aAAc,SAAQ,aAAa,CAAC,gBAAgB,CAAC;CAAG"}
package/dist/stage.js CHANGED
@@ -1,23 +1,31 @@
1
1
  import { NotSupported } from './sparql/executor.js';
2
+ import { batch } from './batch.js';
2
3
  export class Stage {
3
4
  name;
4
5
  executors;
5
6
  selector;
7
+ batchSize;
6
8
  constructor(options) {
7
9
  this.name = options.name;
8
10
  this.executors = Array.isArray(options.executors)
9
11
  ? options.executors
10
12
  : [options.executors];
11
13
  this.selector = options.selector;
14
+ this.batchSize = options.batchSize ?? 10;
12
15
  }
13
16
  async run(dataset, distribution) {
14
- const bindings = await this.collectBindings();
15
- const executeOptions = bindings.length > 0 ? { bindings } : undefined;
17
+ if (!this.selector) {
18
+ return this.executeAll(dataset, distribution);
19
+ }
16
20
  const streams = [];
17
- for (const executor of this.executors) {
18
- const result = await executor.execute(dataset, distribution, executeOptions);
19
- if (!(result instanceof NotSupported)) {
20
- streams.push(result);
21
+ for await (const bindings of batch(this.selector, this.batchSize)) {
22
+ for (const executor of this.executors) {
23
+ const result = await executor.execute(dataset, distribution, {
24
+ bindings,
25
+ });
26
+ if (!(result instanceof NotSupported)) {
27
+ streams.push(result);
28
+ }
21
29
  }
22
30
  }
23
31
  if (streams.length === 0) {
@@ -25,15 +33,18 @@ export class Stage {
25
33
  }
26
34
  return mergeStreams(streams);
27
35
  }
28
- async collectBindings() {
29
- if (this.selector === undefined) {
30
- return [];
36
+ async executeAll(dataset, distribution) {
37
+ const streams = [];
38
+ for (const executor of this.executors) {
39
+ const result = await executor.execute(dataset, distribution);
40
+ if (!(result instanceof NotSupported)) {
41
+ streams.push(result);
42
+ }
31
43
  }
32
- const bindings = [];
33
- for await (const row of this.selector) {
34
- bindings.push(row);
44
+ if (streams.length === 0) {
45
+ return new NotSupported('All executors returned NotSupported');
35
46
  }
36
- return bindings;
47
+ return mergeStreams(streams);
37
48
  }
38
49
  }
39
50
  async function* mergeStreams(streams) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lde/pipeline",
3
- "version": "0.6.18",
3
+ "version": "0.6.19",
4
4
  "repository": {
5
5
  "url": "https://github.com/ldengine/lde",
6
6
  "directory": "packages/pipeline"