@malloydata/render 0.0.240-dev250305213425 → 0.0.240-dev250308020308

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.
@@ -25416,11 +25416,12 @@ ${(0, yn.indent)(h)}) AS ${n.alias}
25416
25416
  const o = [];
25417
25417
  let u = s;
25418
25418
  for (; u; ) {
25419
- for (const a of u.fieldNames((l) => yr(l.f)))
25420
- o.push(this.parent.dialect.sqlMaybeQuoteIdentifier(`${a}__${u.groupSet}`));
25419
+ for (const l of u.fieldNames((c) => yr(c.f)))
25420
+ o.push(this.parent.dialect.sqlMaybeQuoteIdentifier(`${l}__${u.groupSet}`));
25421
25421
  u = u.parent;
25422
25422
  }
25423
- r.push(`MAX(CASE WHEN group_set IN (${s.childGroups.join(",")}) THEN __delete__${s.groupSet} END) OVER(partition by ${o.map(this.parent.dialect.castToString).join(",")}) as __shaving__${s.groupSet}`);
25423
+ let a = "";
25424
+ o.length > 0 && (a = "partition by ", a += o.map(this.parent.dialect.castToString).join(",")), r.push(`MAX(CASE WHEN group_set IN (${s.childGroups.join(",")}) THEN __delete__${s.groupSet} END) OVER(${a}) as __shaving__${s.groupSet}`);
25424
25425
  }
25425
25426
  if (i.length > 0) {
25426
25427
  n = e.addStage(`SELECT
@@ -894,7 +894,7 @@ ${(0,mn.indent)(h)}) AS ${n.alias}
894
894
  `),this.resultStage=e.addStage(n),this.resultStage}generatePipelinedStages(e,n,r){if(e.length===0)return n;let i;if(this.parent.dialect.supportsSelectReplace)i=`SELECT * replace (${e.map(o=>`${o.pipelineSQL} as ${o.sqlFieldName}`).join(`,
895
895
  `)}) FROM ${n}
896
896
  `;else{const s=e.map(l=>`${l.pipelineSQL} as ${l.sqlFieldName}`).join(`,
897
- `),o=e.map(l=>l.sqlFieldName),a=Array.from(this.rootResult.allFields.keys()).map(l=>this.parent.dialect.sqlMaybeQuoteIdentifier(l)).filter(l=>o.indexOf(l)===-1);i=`SELECT ${a.length>0?a.join(", ")+",":""} ${s} FROM ${n}`}return r.addStage(i)}generateStage0Fields(e,n,r){const i=[],s=[];for(const[a,l]of e.allFields)l instanceof oi&&_r(l.f)?i.push([a,l]):s.push([a,l]);const o=[...i,...s];for(const[a,l]of o){const c=this.parent.dialect.sqlMaybeQuoteIdentifier(`${a}__${e.groupSet}`);if(l instanceof oi){if(l.fieldUsage.type==="result"){const f=l.getSQL();if(_r(l.f)){if(this.parent.dialect.cantPartitionWindowFunctionsOnExpressions&&this.rootResult.queryUsesPartitioning){const d=`__lateral_join_bag.${c}`;if(l.analyticalSQL=d,n.lateralJoinSQLExpressions.push(`${f} as ${c}`),n.sql.push(d),l.f.fieldDef.type==="number"){const h=this.parent.dialect.sqlMaybeQuoteIdentifier(`${a}__${e.groupSet}_string`),p=`__lateral_join_bag.${h}`;n.sql.push(p),n.dimensionIndexes.push(n.fieldIndex++),n.lateralJoinSQLExpressions.push(`CAST(${f} as STRING) as ${h}`),l.partitionSQL=p}}else n.sql.push(`${f} as ${c}`);n.dimensionIndexes.push(n.fieldIndex++)}else VA(l.f)&&(n.sql.push(`${f} as ${c}`),n.fieldIndex++)}}else if(l instanceof _u){if(l.firstSegment.type==="reduce")this.generateStage0Fields(l,n,r);else if(l.firstSegment.type==="project"){const f=this.generateTurtleSQL(l,r,c,n.outputPipelinedSQL);n.sql.push(`${f} as ${c}`),n.fieldIndex++}}}const u=this.generateSQLFilters(e,"having");u.empty()||(e.childGroups.length===1?e.root().havings.add(`(group_set<>${e.groupSet} OR (group_set=${e.groupSet} AND ${u.sql()}))`):(e.hasHaving=!0,n.sql.push(`CASE WHEN group_set=${e.groupSet} THEN CASE WHEN ${u.sql()} THEN 0 ELSE 1 END END as __delete__${e.groupSet}`),n.fieldIndex++))}generateSQLWhereChildren(e){const n=new mn.AndChain;for(const[,r]of e.allFields)if(r.type==="query"){const i=r,s=this.generateSQLFilters(i,"where");if(s.present()){const o=i.childGroups.join(",");n.add(`(group_set NOT IN (${o}) OR (group_set IN (${o}) AND ${s.sql()}))`)}n.addChain(this.generateSQLWhereChildren(i))}return n}generateSQLWhereTurtled(){const e=this.generateSQLFilters(this.rootResult,"where");return e.addChain(this.generateSQLWhereChildren(this.rootResult)),e.sql("where")}generateSQLHavingLimit(e,n){const r=[],i=this.rootResult.selectStructs([],s=>s.hasHaving);if(i.length>0)for(const s of i){const o=[];let u=s;for(;u;){for(const a of u.fieldNames(l=>_r(l.f)))o.push(this.parent.dialect.sqlMaybeQuoteIdentifier(`${a}__${u.groupSet}`));u=u.parent}r.push(`MAX(CASE WHEN group_set IN (${s.childGroups.join(",")}) THEN __delete__${s.groupSet} END) OVER(partition by ${o.map(this.parent.dialect.castToString).join(",")}) as __shaving__${s.groupSet}`)}if(i.length>0){n=e.addStage(`SELECT
897
+ `),o=e.map(l=>l.sqlFieldName),a=Array.from(this.rootResult.allFields.keys()).map(l=>this.parent.dialect.sqlMaybeQuoteIdentifier(l)).filter(l=>o.indexOf(l)===-1);i=`SELECT ${a.length>0?a.join(", ")+",":""} ${s} FROM ${n}`}return r.addStage(i)}generateStage0Fields(e,n,r){const i=[],s=[];for(const[a,l]of e.allFields)l instanceof oi&&_r(l.f)?i.push([a,l]):s.push([a,l]);const o=[...i,...s];for(const[a,l]of o){const c=this.parent.dialect.sqlMaybeQuoteIdentifier(`${a}__${e.groupSet}`);if(l instanceof oi){if(l.fieldUsage.type==="result"){const f=l.getSQL();if(_r(l.f)){if(this.parent.dialect.cantPartitionWindowFunctionsOnExpressions&&this.rootResult.queryUsesPartitioning){const d=`__lateral_join_bag.${c}`;if(l.analyticalSQL=d,n.lateralJoinSQLExpressions.push(`${f} as ${c}`),n.sql.push(d),l.f.fieldDef.type==="number"){const h=this.parent.dialect.sqlMaybeQuoteIdentifier(`${a}__${e.groupSet}_string`),p=`__lateral_join_bag.${h}`;n.sql.push(p),n.dimensionIndexes.push(n.fieldIndex++),n.lateralJoinSQLExpressions.push(`CAST(${f} as STRING) as ${h}`),l.partitionSQL=p}}else n.sql.push(`${f} as ${c}`);n.dimensionIndexes.push(n.fieldIndex++)}else VA(l.f)&&(n.sql.push(`${f} as ${c}`),n.fieldIndex++)}}else if(l instanceof _u){if(l.firstSegment.type==="reduce")this.generateStage0Fields(l,n,r);else if(l.firstSegment.type==="project"){const f=this.generateTurtleSQL(l,r,c,n.outputPipelinedSQL);n.sql.push(`${f} as ${c}`),n.fieldIndex++}}}const u=this.generateSQLFilters(e,"having");u.empty()||(e.childGroups.length===1?e.root().havings.add(`(group_set<>${e.groupSet} OR (group_set=${e.groupSet} AND ${u.sql()}))`):(e.hasHaving=!0,n.sql.push(`CASE WHEN group_set=${e.groupSet} THEN CASE WHEN ${u.sql()} THEN 0 ELSE 1 END END as __delete__${e.groupSet}`),n.fieldIndex++))}generateSQLWhereChildren(e){const n=new mn.AndChain;for(const[,r]of e.allFields)if(r.type==="query"){const i=r,s=this.generateSQLFilters(i,"where");if(s.present()){const o=i.childGroups.join(",");n.add(`(group_set NOT IN (${o}) OR (group_set IN (${o}) AND ${s.sql()}))`)}n.addChain(this.generateSQLWhereChildren(i))}return n}generateSQLWhereTurtled(){const e=this.generateSQLFilters(this.rootResult,"where");return e.addChain(this.generateSQLWhereChildren(this.rootResult)),e.sql("where")}generateSQLHavingLimit(e,n){const r=[],i=this.rootResult.selectStructs([],s=>s.hasHaving);if(i.length>0)for(const s of i){const o=[];let u=s;for(;u;){for(const l of u.fieldNames(c=>_r(c.f)))o.push(this.parent.dialect.sqlMaybeQuoteIdentifier(`${l}__${u.groupSet}`));u=u.parent}let a="";o.length>0&&(a="partition by ",a+=o.map(this.parent.dialect.castToString).join(",")),r.push(`MAX(CASE WHEN group_set IN (${s.childGroups.join(",")}) THEN __delete__${s.groupSet} END) OVER(${a}) as __shaving__${s.groupSet}`)}if(i.length>0){n=e.addStage(`SELECT
898
898
  *,
899
899
  ${r.join(`,
900
900
  `)}
@@ -26314,11 +26314,12 @@ ${(0, vn.indent)(h)}) AS ${n.alias}
26314
26314
  const o = [];
26315
26315
  let u = s;
26316
26316
  for (; u; ) {
26317
- for (const a of u.fieldNames((l) => Cr(l.f)))
26318
- o.push(this.parent.dialect.sqlMaybeQuoteIdentifier(`${a}__${u.groupSet}`));
26317
+ for (const l of u.fieldNames((c) => Cr(c.f)))
26318
+ o.push(this.parent.dialect.sqlMaybeQuoteIdentifier(`${l}__${u.groupSet}`));
26319
26319
  u = u.parent;
26320
26320
  }
26321
- r.push(`MAX(CASE WHEN group_set IN (${s.childGroups.join(",")}) THEN __delete__${s.groupSet} END) OVER(partition by ${o.map(this.parent.dialect.castToString).join(",")}) as __shaving__${s.groupSet}`);
26321
+ let a = "";
26322
+ o.length > 0 && (a = "partition by ", a += o.map(this.parent.dialect.castToString).join(",")), r.push(`MAX(CASE WHEN group_set IN (${s.childGroups.join(",")}) THEN __delete__${s.groupSet} END) OVER(${a}) as __shaving__${s.groupSet}`);
26322
26323
  }
26323
26324
  if (i.length > 0) {
26324
26325
  n = e.addStage(`SELECT
@@ -894,7 +894,7 @@ ${(0,En.indent)(h)}) AS ${n.alias}
894
894
  `),this.resultStage=e.addStage(n),this.resultStage}generatePipelinedStages(e,n,r){if(e.length===0)return n;let i;if(this.parent.dialect.supportsSelectReplace)i=`SELECT * replace (${e.map(o=>`${o.pipelineSQL} as ${o.sqlFieldName}`).join(`,
895
895
  `)}) FROM ${n}
896
896
  `;else{const s=e.map(l=>`${l.pipelineSQL} as ${l.sqlFieldName}`).join(`,
897
- `),o=e.map(l=>l.sqlFieldName),a=Array.from(this.rootResult.allFields.keys()).map(l=>this.parent.dialect.sqlMaybeQuoteIdentifier(l)).filter(l=>o.indexOf(l)===-1);i=`SELECT ${a.length>0?a.join(", ")+",":""} ${s} FROM ${n}`}return r.addStage(i)}generateStage0Fields(e,n,r){const i=[],s=[];for(const[a,l]of e.allFields)l instanceof di&&Rr(l.f)?i.push([a,l]):s.push([a,l]);const o=[...i,...s];for(const[a,l]of o){const c=this.parent.dialect.sqlMaybeQuoteIdentifier(`${a}__${e.groupSet}`);if(l instanceof di){if(l.fieldUsage.type==="result"){const f=l.getSQL();if(Rr(l.f)){if(this.parent.dialect.cantPartitionWindowFunctionsOnExpressions&&this.rootResult.queryUsesPartitioning){const d=`__lateral_join_bag.${c}`;if(l.analyticalSQL=d,n.lateralJoinSQLExpressions.push(`${f} as ${c}`),n.sql.push(d),l.f.fieldDef.type==="number"){const h=this.parent.dialect.sqlMaybeQuoteIdentifier(`${a}__${e.groupSet}_string`),p=`__lateral_join_bag.${h}`;n.sql.push(p),n.dimensionIndexes.push(n.fieldIndex++),n.lateralJoinSQLExpressions.push(`CAST(${f} as STRING) as ${h}`),l.partitionSQL=p}}else n.sql.push(`${f} as ${c}`);n.dimensionIndexes.push(n.fieldIndex++)}else Qv(l.f)&&(n.sql.push(`${f} as ${c}`),n.fieldIndex++)}}else if(l instanceof ku){if(l.firstSegment.type==="reduce")this.generateStage0Fields(l,n,r);else if(l.firstSegment.type==="project"){const f=this.generateTurtleSQL(l,r,c,n.outputPipelinedSQL);n.sql.push(`${f} as ${c}`),n.fieldIndex++}}}const u=this.generateSQLFilters(e,"having");u.empty()||(e.childGroups.length===1?e.root().havings.add(`(group_set<>${e.groupSet} OR (group_set=${e.groupSet} AND ${u.sql()}))`):(e.hasHaving=!0,n.sql.push(`CASE WHEN group_set=${e.groupSet} THEN CASE WHEN ${u.sql()} THEN 0 ELSE 1 END END as __delete__${e.groupSet}`),n.fieldIndex++))}generateSQLWhereChildren(e){const n=new En.AndChain;for(const[,r]of e.allFields)if(r.type==="query"){const i=r,s=this.generateSQLFilters(i,"where");if(s.present()){const o=i.childGroups.join(",");n.add(`(group_set NOT IN (${o}) OR (group_set IN (${o}) AND ${s.sql()}))`)}n.addChain(this.generateSQLWhereChildren(i))}return n}generateSQLWhereTurtled(){const e=this.generateSQLFilters(this.rootResult,"where");return e.addChain(this.generateSQLWhereChildren(this.rootResult)),e.sql("where")}generateSQLHavingLimit(e,n){const r=[],i=this.rootResult.selectStructs([],s=>s.hasHaving);if(i.length>0)for(const s of i){const o=[];let u=s;for(;u;){for(const a of u.fieldNames(l=>Rr(l.f)))o.push(this.parent.dialect.sqlMaybeQuoteIdentifier(`${a}__${u.groupSet}`));u=u.parent}r.push(`MAX(CASE WHEN group_set IN (${s.childGroups.join(",")}) THEN __delete__${s.groupSet} END) OVER(partition by ${o.map(this.parent.dialect.castToString).join(",")}) as __shaving__${s.groupSet}`)}if(i.length>0){n=e.addStage(`SELECT
897
+ `),o=e.map(l=>l.sqlFieldName),a=Array.from(this.rootResult.allFields.keys()).map(l=>this.parent.dialect.sqlMaybeQuoteIdentifier(l)).filter(l=>o.indexOf(l)===-1);i=`SELECT ${a.length>0?a.join(", ")+",":""} ${s} FROM ${n}`}return r.addStage(i)}generateStage0Fields(e,n,r){const i=[],s=[];for(const[a,l]of e.allFields)l instanceof di&&Rr(l.f)?i.push([a,l]):s.push([a,l]);const o=[...i,...s];for(const[a,l]of o){const c=this.parent.dialect.sqlMaybeQuoteIdentifier(`${a}__${e.groupSet}`);if(l instanceof di){if(l.fieldUsage.type==="result"){const f=l.getSQL();if(Rr(l.f)){if(this.parent.dialect.cantPartitionWindowFunctionsOnExpressions&&this.rootResult.queryUsesPartitioning){const d=`__lateral_join_bag.${c}`;if(l.analyticalSQL=d,n.lateralJoinSQLExpressions.push(`${f} as ${c}`),n.sql.push(d),l.f.fieldDef.type==="number"){const h=this.parent.dialect.sqlMaybeQuoteIdentifier(`${a}__${e.groupSet}_string`),p=`__lateral_join_bag.${h}`;n.sql.push(p),n.dimensionIndexes.push(n.fieldIndex++),n.lateralJoinSQLExpressions.push(`CAST(${f} as STRING) as ${h}`),l.partitionSQL=p}}else n.sql.push(`${f} as ${c}`);n.dimensionIndexes.push(n.fieldIndex++)}else Qv(l.f)&&(n.sql.push(`${f} as ${c}`),n.fieldIndex++)}}else if(l instanceof ku){if(l.firstSegment.type==="reduce")this.generateStage0Fields(l,n,r);else if(l.firstSegment.type==="project"){const f=this.generateTurtleSQL(l,r,c,n.outputPipelinedSQL);n.sql.push(`${f} as ${c}`),n.fieldIndex++}}}const u=this.generateSQLFilters(e,"having");u.empty()||(e.childGroups.length===1?e.root().havings.add(`(group_set<>${e.groupSet} OR (group_set=${e.groupSet} AND ${u.sql()}))`):(e.hasHaving=!0,n.sql.push(`CASE WHEN group_set=${e.groupSet} THEN CASE WHEN ${u.sql()} THEN 0 ELSE 1 END END as __delete__${e.groupSet}`),n.fieldIndex++))}generateSQLWhereChildren(e){const n=new En.AndChain;for(const[,r]of e.allFields)if(r.type==="query"){const i=r,s=this.generateSQLFilters(i,"where");if(s.present()){const o=i.childGroups.join(",");n.add(`(group_set NOT IN (${o}) OR (group_set IN (${o}) AND ${s.sql()}))`)}n.addChain(this.generateSQLWhereChildren(i))}return n}generateSQLWhereTurtled(){const e=this.generateSQLFilters(this.rootResult,"where");return e.addChain(this.generateSQLWhereChildren(this.rootResult)),e.sql("where")}generateSQLHavingLimit(e,n){const r=[],i=this.rootResult.selectStructs([],s=>s.hasHaving);if(i.length>0)for(const s of i){const o=[];let u=s;for(;u;){for(const l of u.fieldNames(c=>Rr(c.f)))o.push(this.parent.dialect.sqlMaybeQuoteIdentifier(`${l}__${u.groupSet}`));u=u.parent}let a="";o.length>0&&(a="partition by ",a+=o.map(this.parent.dialect.castToString).join(",")),r.push(`MAX(CASE WHEN group_set IN (${s.childGroups.join(",")}) THEN __delete__${s.groupSet} END) OVER(${a}) as __shaving__${s.groupSet}`)}if(i.length>0){n=e.addStage(`SELECT
898
898
  *,
899
899
  ${r.join(`,
900
900
  `)}
@@ -26314,11 +26314,12 @@ ${(0, vn.indent)(h)}) AS ${n.alias}
26314
26314
  const o = [];
26315
26315
  let u = s;
26316
26316
  for (; u; ) {
26317
- for (const a of u.fieldNames((l) => Cr(l.f)))
26318
- o.push(this.parent.dialect.sqlMaybeQuoteIdentifier(`${a}__${u.groupSet}`));
26317
+ for (const l of u.fieldNames((c) => Cr(c.f)))
26318
+ o.push(this.parent.dialect.sqlMaybeQuoteIdentifier(`${l}__${u.groupSet}`));
26319
26319
  u = u.parent;
26320
26320
  }
26321
- r.push(`MAX(CASE WHEN group_set IN (${s.childGroups.join(",")}) THEN __delete__${s.groupSet} END) OVER(partition by ${o.map(this.parent.dialect.castToString).join(",")}) as __shaving__${s.groupSet}`);
26321
+ let a = "";
26322
+ o.length > 0 && (a = "partition by ", a += o.map(this.parent.dialect.castToString).join(",")), r.push(`MAX(CASE WHEN group_set IN (${s.childGroups.join(",")}) THEN __delete__${s.groupSet} END) OVER(${a}) as __shaving__${s.groupSet}`);
26322
26323
  }
26323
26324
  if (i.length > 0) {
26324
26325
  n = e.addStage(`SELECT
@@ -894,7 +894,7 @@ ${(0,En.indent)(h)}) AS ${n.alias}
894
894
  `),this.resultStage=e.addStage(n),this.resultStage}generatePipelinedStages(e,n,r){if(e.length===0)return n;let i;if(this.parent.dialect.supportsSelectReplace)i=`SELECT * replace (${e.map(o=>`${o.pipelineSQL} as ${o.sqlFieldName}`).join(`,
895
895
  `)}) FROM ${n}
896
896
  `;else{const s=e.map(l=>`${l.pipelineSQL} as ${l.sqlFieldName}`).join(`,
897
- `),o=e.map(l=>l.sqlFieldName),a=Array.from(this.rootResult.allFields.keys()).map(l=>this.parent.dialect.sqlMaybeQuoteIdentifier(l)).filter(l=>o.indexOf(l)===-1);i=`SELECT ${a.length>0?a.join(", ")+",":""} ${s} FROM ${n}`}return r.addStage(i)}generateStage0Fields(e,n,r){const i=[],s=[];for(const[a,l]of e.allFields)l instanceof di&&Rr(l.f)?i.push([a,l]):s.push([a,l]);const o=[...i,...s];for(const[a,l]of o){const c=this.parent.dialect.sqlMaybeQuoteIdentifier(`${a}__${e.groupSet}`);if(l instanceof di){if(l.fieldUsage.type==="result"){const f=l.getSQL();if(Rr(l.f)){if(this.parent.dialect.cantPartitionWindowFunctionsOnExpressions&&this.rootResult.queryUsesPartitioning){const d=`__lateral_join_bag.${c}`;if(l.analyticalSQL=d,n.lateralJoinSQLExpressions.push(`${f} as ${c}`),n.sql.push(d),l.f.fieldDef.type==="number"){const h=this.parent.dialect.sqlMaybeQuoteIdentifier(`${a}__${e.groupSet}_string`),p=`__lateral_join_bag.${h}`;n.sql.push(p),n.dimensionIndexes.push(n.fieldIndex++),n.lateralJoinSQLExpressions.push(`CAST(${f} as STRING) as ${h}`),l.partitionSQL=p}}else n.sql.push(`${f} as ${c}`);n.dimensionIndexes.push(n.fieldIndex++)}else zv(l.f)&&(n.sql.push(`${f} as ${c}`),n.fieldIndex++)}}else if(l instanceof ku){if(l.firstSegment.type==="reduce")this.generateStage0Fields(l,n,r);else if(l.firstSegment.type==="project"){const f=this.generateTurtleSQL(l,r,c,n.outputPipelinedSQL);n.sql.push(`${f} as ${c}`),n.fieldIndex++}}}const u=this.generateSQLFilters(e,"having");u.empty()||(e.childGroups.length===1?e.root().havings.add(`(group_set<>${e.groupSet} OR (group_set=${e.groupSet} AND ${u.sql()}))`):(e.hasHaving=!0,n.sql.push(`CASE WHEN group_set=${e.groupSet} THEN CASE WHEN ${u.sql()} THEN 0 ELSE 1 END END as __delete__${e.groupSet}`),n.fieldIndex++))}generateSQLWhereChildren(e){const n=new En.AndChain;for(const[,r]of e.allFields)if(r.type==="query"){const i=r,s=this.generateSQLFilters(i,"where");if(s.present()){const o=i.childGroups.join(",");n.add(`(group_set NOT IN (${o}) OR (group_set IN (${o}) AND ${s.sql()}))`)}n.addChain(this.generateSQLWhereChildren(i))}return n}generateSQLWhereTurtled(){const e=this.generateSQLFilters(this.rootResult,"where");return e.addChain(this.generateSQLWhereChildren(this.rootResult)),e.sql("where")}generateSQLHavingLimit(e,n){const r=[],i=this.rootResult.selectStructs([],s=>s.hasHaving);if(i.length>0)for(const s of i){const o=[];let u=s;for(;u;){for(const a of u.fieldNames(l=>Rr(l.f)))o.push(this.parent.dialect.sqlMaybeQuoteIdentifier(`${a}__${u.groupSet}`));u=u.parent}r.push(`MAX(CASE WHEN group_set IN (${s.childGroups.join(",")}) THEN __delete__${s.groupSet} END) OVER(partition by ${o.map(this.parent.dialect.castToString).join(",")}) as __shaving__${s.groupSet}`)}if(i.length>0){n=e.addStage(`SELECT
897
+ `),o=e.map(l=>l.sqlFieldName),a=Array.from(this.rootResult.allFields.keys()).map(l=>this.parent.dialect.sqlMaybeQuoteIdentifier(l)).filter(l=>o.indexOf(l)===-1);i=`SELECT ${a.length>0?a.join(", ")+",":""} ${s} FROM ${n}`}return r.addStage(i)}generateStage0Fields(e,n,r){const i=[],s=[];for(const[a,l]of e.allFields)l instanceof di&&Rr(l.f)?i.push([a,l]):s.push([a,l]);const o=[...i,...s];for(const[a,l]of o){const c=this.parent.dialect.sqlMaybeQuoteIdentifier(`${a}__${e.groupSet}`);if(l instanceof di){if(l.fieldUsage.type==="result"){const f=l.getSQL();if(Rr(l.f)){if(this.parent.dialect.cantPartitionWindowFunctionsOnExpressions&&this.rootResult.queryUsesPartitioning){const d=`__lateral_join_bag.${c}`;if(l.analyticalSQL=d,n.lateralJoinSQLExpressions.push(`${f} as ${c}`),n.sql.push(d),l.f.fieldDef.type==="number"){const h=this.parent.dialect.sqlMaybeQuoteIdentifier(`${a}__${e.groupSet}_string`),p=`__lateral_join_bag.${h}`;n.sql.push(p),n.dimensionIndexes.push(n.fieldIndex++),n.lateralJoinSQLExpressions.push(`CAST(${f} as STRING) as ${h}`),l.partitionSQL=p}}else n.sql.push(`${f} as ${c}`);n.dimensionIndexes.push(n.fieldIndex++)}else zv(l.f)&&(n.sql.push(`${f} as ${c}`),n.fieldIndex++)}}else if(l instanceof ku){if(l.firstSegment.type==="reduce")this.generateStage0Fields(l,n,r);else if(l.firstSegment.type==="project"){const f=this.generateTurtleSQL(l,r,c,n.outputPipelinedSQL);n.sql.push(`${f} as ${c}`),n.fieldIndex++}}}const u=this.generateSQLFilters(e,"having");u.empty()||(e.childGroups.length===1?e.root().havings.add(`(group_set<>${e.groupSet} OR (group_set=${e.groupSet} AND ${u.sql()}))`):(e.hasHaving=!0,n.sql.push(`CASE WHEN group_set=${e.groupSet} THEN CASE WHEN ${u.sql()} THEN 0 ELSE 1 END END as __delete__${e.groupSet}`),n.fieldIndex++))}generateSQLWhereChildren(e){const n=new En.AndChain;for(const[,r]of e.allFields)if(r.type==="query"){const i=r,s=this.generateSQLFilters(i,"where");if(s.present()){const o=i.childGroups.join(",");n.add(`(group_set NOT IN (${o}) OR (group_set IN (${o}) AND ${s.sql()}))`)}n.addChain(this.generateSQLWhereChildren(i))}return n}generateSQLWhereTurtled(){const e=this.generateSQLFilters(this.rootResult,"where");return e.addChain(this.generateSQLWhereChildren(this.rootResult)),e.sql("where")}generateSQLHavingLimit(e,n){const r=[],i=this.rootResult.selectStructs([],s=>s.hasHaving);if(i.length>0)for(const s of i){const o=[];let u=s;for(;u;){for(const l of u.fieldNames(c=>Rr(c.f)))o.push(this.parent.dialect.sqlMaybeQuoteIdentifier(`${l}__${u.groupSet}`));u=u.parent}let a="";o.length>0&&(a="partition by ",a+=o.map(this.parent.dialect.castToString).join(",")),r.push(`MAX(CASE WHEN group_set IN (${s.childGroups.join(",")}) THEN __delete__${s.groupSet} END) OVER(${a}) as __shaving__${s.groupSet}`)}if(i.length>0){n=e.addStage(`SELECT
898
898
  *,
899
899
  ${r.join(`,
900
900
  `)}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@malloydata/render",
3
- "version": "0.0.240-dev250305213425",
3
+ "version": "0.0.240-dev250308020308",
4
4
  "license": "MIT",
5
5
  "main": "dist/module/index.umd.js",
6
6
  "types": "dist/index.d.ts",
@@ -31,8 +31,8 @@
31
31
  "build-types": "tsc --build --declaration --emitDeclarationOnly"
32
32
  },
33
33
  "dependencies": {
34
- "@malloydata/malloy": "^0.0.240-dev250305213425",
35
- "@malloydata/malloy-tag": "^0.0.240-dev250305213425",
34
+ "@malloydata/malloy": "^0.0.240-dev250308020308",
35
+ "@malloydata/malloy-tag": "^0.0.240-dev250308020308",
36
36
  "@tanstack/solid-virtual": "^3.10.4",
37
37
  "component-register": "^0.8.6",
38
38
  "lodash": "^4.17.20",