@malloy-publisher/server 0.0.245 → 0.0.246

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.
Files changed (2) hide show
  1. package/dist/server.mjs +63 -46
  2. package/package.json +1 -1
package/dist/server.mjs CHANGED
@@ -156292,15 +156292,6 @@ var BUNDLED_DEFAULT_CONFIG_PATH, PER_MODE_COLOR_KEYS, DEFAULT_HIGH_WATER_FRACTIO
156292
156292
  return value;
156293
156293
  }
156294
156294
  throw new Error(`PERSIST_STORAGE_MODE must be one of ${PERSIST_STORAGE_MODES.join(" | ")} (got ${JSON.stringify(raw)})`);
156295
- }, PREAGGREGATE_MODES, getPreaggregateMode = () => {
156296
- const raw = process.env.PREAGGREGATE_MODE;
156297
- if (raw === undefined || raw.trim() === "")
156298
- return "off";
156299
- const value = raw.trim().toLowerCase();
156300
- if (PREAGGREGATE_MODES.includes(value)) {
156301
- return value;
156302
- }
156303
- throw new Error(`PREAGGREGATE_MODE must be one of ${PREAGGREGATE_MODES.join(" | ")} (got ${JSON.stringify(raw)})`);
156304
156295
  }, getPersistCollisionEnforce = () => parseBoolEnv("PERSIST_COLLISION_ENFORCE") ?? false, getQueryMetadataMode = () => {
156305
156296
  const raw = process.env.PUBLISHER_QUERY_METADATA;
156306
156297
  if (raw === undefined || raw.trim() === "")
@@ -156493,11 +156484,6 @@ var init_config = __esm(() => {
156493
156484
  "write-only",
156494
156485
  "on"
156495
156486
  ];
156496
- PREAGGREGATE_MODES = [
156497
- "off",
156498
- "build-only",
156499
- "on"
156500
- ];
156501
156487
  });
156502
156488
 
156503
156489
  // src/errors.ts
@@ -249681,6 +249667,7 @@ var init_model = __esm(() => {
249681
249667
  discoveryCurationEnabled = false;
249682
249668
  queryBoundary = { mode: "all", exploresDeclared: false, isQueryEntryPoint: true };
249683
249669
  freshnessResolver;
249670
+ preaggregateEntityIdResolver;
249684
249671
  entryPointGatesBySource = new Map;
249685
249672
  meter = publisherMeter();
249686
249673
  queryExecutionHistogram = this.meter.createHistogram("malloy_model_query_duration", {
@@ -250135,6 +250122,18 @@ var init_model = __esm(() => {
250135
250122
  const entries = this.freshnessResolver?.();
250136
250123
  return entries ? { entries, strict: false } : undefined;
250137
250124
  }
250125
+ setPreaggregateEntityIdResolver(resolver) {
250126
+ this.preaggregateEntityIdResolver = resolver;
250127
+ }
250128
+ withoutPreaggregateEntries(manifest) {
250129
+ if (!manifest)
250130
+ return;
250131
+ const preaggregateIds = this.preaggregateEntityIdResolver?.();
250132
+ if (!preaggregateIds || preaggregateIds.size === 0)
250133
+ return manifest;
250134
+ const entries = Object.fromEntries(Object.entries(manifest.entries).filter(([sourceEntityId]) => !preaggregateIds.has(sourceEntityId)));
250135
+ return Object.keys(entries).length > 0 ? { ...manifest, entries } : undefined;
250136
+ }
250138
250137
  getSources() {
250139
250138
  return this.curateForDiscovery(this.sources);
250140
250139
  }
@@ -250475,8 +250474,12 @@ var init_model = __esm(() => {
250475
250474
  let serveVirtualMap;
250476
250475
  let serveShapeBindings = [];
250477
250476
  let servedFrom;
250477
+ let preaggRouted = false;
250478
250478
  if (!this.modelMaterializer || !this.modelDef || !this.modelInfo)
250479
250479
  throw new BadRequestError("Model has no queryable entities.");
250480
+ const buildManifest = this.resolveFreshBuildManifest();
250481
+ const liveBuildManifest = this.withoutPreaggregateEntries(buildManifest);
250482
+ const querySurfaceGivens = this.filterGivensToModelSurface(givens);
250480
250483
  const boundary = this.assertQueryBoundaryEarly(sourceName, queryName, query);
250481
250484
  const surfaceName = extractRunTargetSourceName(query);
250482
250485
  const earlySource = sourceName || (queryName ? this.queries?.find((q) => q.name === queryName)?.sourceName : undefined) || (surfaceName && !this.sources?.some((s) => s.name === surfaceName) ? this.queries?.find((q) => q.name === surfaceName)?.sourceName : undefined) || surfaceName;
@@ -250549,9 +250552,15 @@ run: ${sourceName ? `${quoteMalloyIdentifier(sourceName)} -> ` : ""}${quoteMallo
250549
250552
  });
250550
250553
  }
250551
250554
  }
250552
- if (getPreaggregateMode() === "on" && this.preaggregateServeMaterializer && !serveVirtualMap) {
250555
+ if (this.preaggregateServeMaterializer && !serveVirtualMap) {
250553
250556
  try {
250554
- runnable = this.preaggregateServeMaterializer.loadRestrictedQuery(queryString);
250557
+ const candidate = this.preaggregateServeMaterializer.loadRestrictedQuery(queryString);
250558
+ await candidate.getSQL({
250559
+ givens: querySurfaceGivens,
250560
+ buildManifest
250561
+ });
250562
+ runnable = candidate;
250563
+ preaggRouted = true;
250555
250564
  } catch (preaggErr) {
250556
250565
  logger.debug("query does not compile against the pre-aggregation model; serving live", {
250557
250566
  modelPath: this.modelPath,
@@ -250588,14 +250597,12 @@ run: ${sourceName ? `${quoteMalloyIdentifier(sourceName)} -> ` : ""}${quoteMallo
250588
250597
  await this.assertAuthorizedForAllSources(runnable, givens ?? {}, bypassAuthorize);
250589
250598
  const maxRows = getMaxQueryRows();
250590
250599
  const maxBytes = getMaxResponseBytes();
250591
- const buildManifest = this.resolveFreshBuildManifest();
250592
- const effectiveBuildManifest = serveVirtualMap ? undefined : buildManifest;
250600
+ const effectiveBuildManifest = serveVirtualMap ? undefined : preaggRouted ? buildManifest : liveBuildManifest;
250593
250601
  let rowLimit = 0;
250594
250602
  let rowLimitSource = "server_default";
250595
250603
  let executionTime = 0;
250596
250604
  let queryResults;
250597
250605
  let appliedQueryMetadata;
250598
- const querySurfaceGivens = this.filterGivensToModelSurface(givens);
250599
250606
  const effectiveGivens = serveVirtualMap ? undefined : querySurfaceGivens;
250600
250607
  try {
250601
250608
  const preparedResult = await runnable.getPreparedResult({
@@ -250665,7 +250672,7 @@ run: ${sourceName ? `${quoteMalloyIdentifier(sourceName)} -> ` : ""}${quoteMallo
250665
250672
  try {
250666
250673
  const livePrepared = await liveRunnable.getPreparedResult({
250667
250674
  givens: querySurfaceGivens,
250668
- buildManifest
250675
+ buildManifest: liveBuildManifest
250669
250676
  });
250670
250677
  const livePreparedLimit = livePrepared.resultExplore.limit;
250671
250678
  rowLimitSource = queryRowLimitSource(livePreparedLimit);
@@ -250678,7 +250685,7 @@ run: ${sourceName ? `${quoteMalloyIdentifier(sourceName)} -> ` : ""}${quoteMallo
250678
250685
  rowLimit,
250679
250686
  givens: querySurfaceGivens,
250680
250687
  abortSignal,
250681
- buildManifest,
250688
+ buildManifest: liveBuildManifest,
250682
250689
  queryMetadata: appliedQueryMetadata
250683
250690
  });
250684
250691
  } catch (retryError) {
@@ -250843,7 +250850,7 @@ run: ${sourceName ? `${quoteMalloyIdentifier(sourceName)} -> ` : ""}${quoteMallo
250843
250850
  }
250844
250851
  const cellMaxRows = getMaxQueryRows();
250845
250852
  const cellMaxBytes = getMaxResponseBytes();
250846
- const buildManifest = this.resolveFreshBuildManifest();
250853
+ const buildManifest = this.withoutPreaggregateEntries(this.resolveFreshBuildManifest());
250847
250854
  const cellSurfaceGivens = this.filterGivensToModelSurface(givens);
250848
250855
  const preparedCell = await runnableToExecute.getPreparedResult({
250849
250856
  givens: cellSurfaceGivens,
@@ -280746,7 +280753,6 @@ init_config();
280746
280753
  init_materialization_serve_transform();
280747
280754
 
280748
280755
  // src/service/build_plan.ts
280749
- init_config();
280750
280756
  init_errors();
280751
280757
  init_constants();
280752
280758
  init_logger();
@@ -281274,27 +281280,25 @@ async function compilePackageBuildPlan(pkg, signal) {
281274
281280
  throw new Error("Build cancelled");
281275
281281
  const { runtime, modelURL, importBaseURL } = await Model.getModelRuntime(pkg.getPackagePath(), modelPath, pkg.getMalloyConfig());
281276
281282
  const malloyModel = await runtime.loadModel(modelURL, { importBaseURL }).getModel();
281277
- if (getPreaggregateMode() !== "off") {
281278
- const synthesized = await tryCompileSynthesizedPreaggregation({
281279
- packagePath: pkg.getPackagePath(),
281280
- modelPath,
281281
- malloyConfig: pkg.getMalloyConfig(),
281282
- contents: malloyModel._modelDef?.contents ?? {}
281283
- });
281284
- if (synthesized) {
281285
- const rollupPlan = synthesized.model.getBuildPlan();
281286
- const rollupNames = new Set(synthesized.plans.map((p) => p.rollupSourceName));
281287
- allGraphs.push(...rollupPlan.graphs);
281288
- const planByName = new Map(synthesized.plans.map((p) => [p.rollupSourceName, p]));
281289
- for (const [sourceID, source] of Object.entries(rollupPlan.sources)) {
281290
- if (!rollupNames.has(source.name))
281291
- continue;
281292
- allSources[sourceID] = source;
281293
- sourceModelPaths[sourceID] = modelPath;
281294
- const rollup = planByName.get(source.name);
281295
- if (rollup)
281296
- preaggregatePlans[sourceID] = rollup;
281297
- }
281283
+ const synthesized = await tryCompileSynthesizedPreaggregation({
281284
+ packagePath: pkg.getPackagePath(),
281285
+ modelPath,
281286
+ malloyConfig: pkg.getMalloyConfig(),
281287
+ contents: malloyModel._modelDef?.contents ?? {}
281288
+ });
281289
+ if (synthesized) {
281290
+ const rollupPlan = synthesized.model.getBuildPlan();
281291
+ const rollupNames = new Set(synthesized.plans.map((p) => p.rollupSourceName));
281292
+ allGraphs.push(...rollupPlan.graphs);
281293
+ const planByName = new Map(synthesized.plans.map((p) => [p.rollupSourceName, p]));
281294
+ for (const [sourceID, source] of Object.entries(rollupPlan.sources)) {
281295
+ if (!rollupNames.has(source.name))
281296
+ continue;
281297
+ allSources[sourceID] = source;
281298
+ sourceModelPaths[sourceID] = modelPath;
281299
+ const rollup = planByName.get(source.name);
281300
+ if (rollup)
281301
+ preaggregatePlans[sourceID] = rollup;
281298
281302
  }
281299
281303
  }
281300
281304
  const modelTag = malloyModel.modelAnnotations.parseAsTag("!").tag;
@@ -282186,6 +282190,7 @@ class Package {
282186
282190
  manifestEntryCount = 0;
282187
282191
  boundManifestUri = null;
282188
282192
  buildPlan = null;
282193
+ preaggregateEntityIdCache;
282189
282194
  droppedPersistSources = [];
282190
282195
  sourceEligibility = undefined;
282191
282196
  incrementalPolicySources = [];
@@ -282537,8 +282542,22 @@ class Package {
282537
282542
  wireFreshnessResolvers() {
282538
282543
  for (const model of this.models.values()) {
282539
282544
  model.setFreshnessResolver(() => this.getFreshBuildManifest());
282545
+ model.setPreaggregateEntityIdResolver(() => this.getPreaggregateEntityIds());
282540
282546
  }
282541
282547
  }
282548
+ getPreaggregateEntityIds() {
282549
+ if (this.preaggregateEntityIdCache?.plan === this.buildPlan) {
282550
+ return this.preaggregateEntityIdCache.ids;
282551
+ }
282552
+ const ids = new Set;
282553
+ for (const source of Object.values(this.buildPlan?.sources ?? {})) {
282554
+ if (source.origin === "preaggregate" && source.sourceEntityId) {
282555
+ ids.add(source.sourceEntityId);
282556
+ }
282557
+ }
282558
+ this.preaggregateEntityIdCache = { plan: this.buildPlan, ids };
282559
+ return ids;
282560
+ }
282542
282561
  setBoundManifestUri(uri) {
282543
282562
  this.boundManifestUri = uri;
282544
282563
  }
@@ -282578,8 +282597,6 @@ class Package {
282578
282597
  this.pushStorageServeBindingsToModels();
282579
282598
  }
282580
282599
  async pushPreaggregateServeModels() {
282581
- if (getPreaggregateMode() !== "on")
282582
- return;
282583
282600
  for (const model of this.models.values()) {
282584
282601
  await model.buildPreaggregateServeModel(this.packagePath, this.malloyConfig, this.buildManifestEntries);
282585
282602
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@malloy-publisher/server",
3
3
  "description": "Malloy Publisher Server",
4
- "version": "0.0.245",
4
+ "version": "0.0.246",
5
5
  "main": "dist/server.mjs",
6
6
  "bin": {
7
7
  "malloy-publisher": "dist/server.mjs"