@dbsp/adapter-pgsql 7.0.0 → 7.1.0

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.
@@ -26090,7 +26090,7 @@ var PlanCompiler = class _PlanCompiler {
26090
26090
  const targetName = decision.targetTable ?? "";
26091
26091
  const target = resolveRelationTarget(
26092
26092
  queryLocal(targetName),
26093
- this.createHandlerContext(plan)
26093
+ this.relationTargetContext()
26094
26094
  );
26095
26095
  requireRelationTargetColumns(
26096
26096
  target,
@@ -26102,7 +26102,7 @@ var PlanCompiler = class _PlanCompiler {
26102
26102
  queryLocal(decision.alias ?? targetName),
26103
26103
  target
26104
26104
  );
26105
- const sourceAlias = plan.rootTable;
26105
+ const sourceAlias = decision.sourceAlias ?? plan.rootTable;
26106
26106
  const onCondition = buildKeyCorrelation(
26107
26107
  sourceAlias,
26108
26108
  sourceColumn,
@@ -28061,6 +28061,15 @@ function buildBatchValuesRangeFn(bv, startParamIndex, aliasOverride) {
28061
28061
  };
28062
28062
  return { rangeFunction, params };
28063
28063
  }
28064
+ function resolvedJoinsCoverIntents(joins, resolved) {
28065
+ let position = 0;
28066
+ for (const [intentIndex, join] of joins.entries()) {
28067
+ const hops = join.relation !== void 0 ? join.relation.split(".").length : 1;
28068
+ for (let hop = 0; hop < hops; hop++, position++)
28069
+ if (resolved[position]?.intentIndex !== intentIndex) return false;
28070
+ }
28071
+ return position === resolved.length;
28072
+ }
28064
28073
  function compileJoinIntents(joins, execution, schemaName, deps) {
28065
28074
  if (execution.joins.length === 0) return [];
28066
28075
  const rootTable = execution.rootRange.table;
@@ -28123,7 +28132,7 @@ function compileJoinIntents(joins, execution, schemaName, deps) {
28123
28132
  if (alias === rootBinding.qualifier)
28124
28133
  throw new Error(`Query scope already binds qualifier '${alias}'.`);
28125
28134
  if (resolved.kind === "relation" && !resolved.defaultFilter) {
28126
- const pairs = resolved.path.hops[0].pairs;
28135
+ const pairs = resolved.path.hops.at(-1).pairs;
28127
28136
  results.push({
28128
28137
  type: "join",
28129
28138
  targetTable: resolved.range.table,
@@ -28131,7 +28140,10 @@ function compileJoinIntents(joins, execution, schemaName, deps) {
28131
28140
  relationName: resolved.path.logicalSegments.join("."),
28132
28141
  sourceColumn: pairs.map((p) => p.fromColumn),
28133
28142
  targetColumn: pairs.map((p) => p.toColumn),
28134
- joinType: resolved.type
28143
+ joinType: resolved.type,
28144
+ ...resolved.sourceRange.id !== execution.rootRange.id && {
28145
+ sourceAlias: resolved.sourceRange.alias
28146
+ }
28135
28147
  });
28136
28148
  } else if (resolved.kind === "values") {
28137
28149
  const bv = joins[resolved.intentIndex]?.batchValues;
@@ -28169,7 +28181,7 @@ function compileJoinIntents(joins, execution, schemaName, deps) {
28169
28181
  const tableAlias = resolved.range.alias;
28170
28182
  const conditions = [];
28171
28183
  if (resolved.path) {
28172
- for (const pair of resolved.path.hops[0].pairs) {
28184
+ for (const pair of resolved.path.hops.at(-1).pairs) {
28173
28185
  conditions.push(
28174
28186
  compileResolvedCondition(
28175
28187
  {
@@ -28222,6 +28234,10 @@ function compileJoinIntents(joins, execution, schemaName, deps) {
28222
28234
  type: "join",
28223
28235
  targetTable: resolved.range.table,
28224
28236
  alias: tableAlias,
28237
+ // A filtered relation hop still answers to its relation path.
28238
+ ...resolved.path && {
28239
+ relationName: resolved.path.logicalSegments.join(".")
28240
+ },
28225
28241
  joinType: resolved.type,
28226
28242
  joinRarg: joinedRangeVar,
28227
28243
  joinOnNode: onNode,
@@ -28540,10 +28556,12 @@ function assertPlannedReportAuthority(plan) {
28540
28556
  function compileSelectEnvelope(plan, options, deps) {
28541
28557
  const schemaName = deps.schemaName;
28542
28558
  const resolvedModelForCompiler = options?.model ?? deps.model;
28543
- if ([plan.intent, plan.executableIntent].some((intent) => {
28544
- const count = intent?.joins?.length ?? 0;
28545
- return count > 0 && plan.execution?.joins?.length !== count;
28546
- })) {
28559
+ if ([plan.intent, plan.executableIntent].some(
28560
+ (intent) => intent !== void 0 && !resolvedJoinsCoverIntents(
28561
+ intent.joins ?? [],
28562
+ plan.execution?.joins ?? []
28563
+ )
28564
+ )) {
28547
28565
  const error = new Error(
28548
28566
  "Planned joins require matching resolved execution joins"
28549
28567
  );
@@ -59250,4 +59268,4 @@ export {
59250
59268
  planPgTransitionRun,
59251
59269
  applyPgTransitionRun
59252
59270
  };
59253
- //# sourceMappingURL=chunk-5BBN6TPD.js.map
59271
+ //# sourceMappingURL=chunk-GEN6X6M2.js.map