@malloydata/render 0.0.261-dev250410224545 → 0.0.261-dev250411164723
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.
package/dist/module/index.mjs
CHANGED
|
@@ -124292,10 +124292,11 @@ FROM ${r}
|
|
|
124292
124292
|
generateSQLFromPipeline(e) {
|
|
124293
124293
|
this.parent.maybeEmitParameterizedSourceUsage(), this.prepare(e);
|
|
124294
124294
|
let r = this.generateSQL(e), i = this.getResultStructDef();
|
|
124295
|
-
|
|
124296
|
-
|
|
124295
|
+
const s = [...this.fieldDef.pipeline];
|
|
124296
|
+
if (s.length > 1) {
|
|
124297
124297
|
let o = {
|
|
124298
124298
|
...i,
|
|
124299
|
+
name: r,
|
|
124299
124300
|
type: "finalize"
|
|
124300
124301
|
};
|
|
124301
124302
|
s.shift();
|
|
@@ -124303,6 +124304,7 @@ FROM ${r}
|
|
|
124303
124304
|
const a = this.parent.parent ? { struct: this.parent.parent } : { model: this.parent.getModel() }, l = new yl(o, void 0, a, this.parent.prepareResultOptions), c = ss.makeQuery({ type: "turtle", name: "~computeLastStage~", pipeline: [u] }, l, e, this.isJoinedSubquery);
|
|
124304
124305
|
c.prepare(e), r = c.generateSQL(e), i = c.getResultStructDef(), o = {
|
|
124305
124306
|
...i,
|
|
124307
|
+
name: r,
|
|
124306
124308
|
type: "finalize"
|
|
124307
124309
|
};
|
|
124308
124310
|
}
|
package/dist/module/index.umd.js
CHANGED
|
@@ -1104,7 +1104,7 @@ FROM ${r}
|
|
|
1104
1104
|
`;const l=this.rootResult.eliminateComputeGroupsSQL();return l.length>0&&(i+=`WHERE ${l}
|
|
1105
1105
|
`),a.length>0&&(i+=`GROUP BY ${a.join(",")}
|
|
1106
1106
|
`),i+=this.genereateSQLOrderBy(this.firstSegment,this.rootResult),!(0,Ie.isRawSegment)(this.firstSegment)&&this.firstSegment.limit&&(i+=`LIMIT ${this.firstSegment.limit}
|
|
1107
|
-
`),this.resultStage=e.addStage(i),this.resultStage=this.generatePipelinedStages(u,this.resultStage,e),this.resultStage}buildDialectFieldList(e){const r=[];for(const[i,s]of e.allFields){const o=this.parent.dialect.sqlMaybeQuoteIdentifier(i);if(e.firstSegment.type==="reduce"&&s instanceof ba){const{structDef:u,repeatedResultType:a}=this.generateTurtlePipelineSQL(s,new Vp(!0,void 0),"<nosource>");if(a==="nested"){const l={...u,type:"array",elementTypeDef:{type:"record_element"},join:"many",name:i};r.push({typeDef:l,sqlExpression:this.parent.dialect.sqlMaybeQuoteIdentifier(`${i}__${e.groupSet}`),rawName:i,sqlOutputName:o})}else{const l={...u,type:"record",join:"one",name:i};r.push({typeDef:l,sqlExpression:this.parent.dialect.sqlMaybeQuoteIdentifier(`${i}__${e.groupSet}`),rawName:i,sqlOutputName:o})}}else e.firstSegment.type==="reduce"&&s instanceof Ui&&s.fieldUsage.type==="result"?Tae(r,{fieldDef:s.f.fieldDef,sqlExpression:this.parent.dialect.sqlMaybeQuoteIdentifier(`${i}__${e.groupSet}`),rawName:i,sqlOutputName:o}):e.firstSegment.type==="project"&&s instanceof Ui&&s.fieldUsage.type==="result"&&Tae(r,{fieldDef:s.f.fieldDef,sqlExpression:s.f.generateExpression(e),rawName:i,sqlOutputName:o})}return r}generateTurtleSQL(e,r,i,s){let o="";const u=(0,Ie.isRawSegment)(e.firstSegment)?void 0:e.firstSegment.limit,a=[];let l;const c=e.firstSegment.orderBy||e.calculateDefaultOrderBy();for(const g of c)typeof g.field=="string"?l={name:g.field,fif:e.getField(g.field)}:l=e.getFieldByNumber(g.field),e.firstSegment.type==="reduce"?a.push(" "+this.parent.dialect.sqlMaybeQuoteIdentifier(`${l.name}__${e.groupSet}`)+` ${g.dir||"ASC"}`):e.firstSegment.type==="project"&&a.push(` ${l.fif.f.generateExpression(e)} ${g.dir||"ASC"}`);a.length>0&&(o=" "+this.parent.dialect.sqlOrderBy(a,"turtle"));const f=this.buildDialectFieldList(e);let x,h;(x=e.getRepeatedResultType())!=="nested"?x==="inline_all_numbers"?h=this.parent.dialect.sqlCoaleseMeasuresInline(e.groupSet,f):h=this.parent.dialect.sqlAnyValueTurtle(e.groupSet,f):h=this.parent.dialect.sqlAggregateTurtle(e.groupSet,f,o,u);const p=new Vp(this.parent.dialect.supportsCTEinCoorelatedSubQueries,r),{structDef:m,pipeOut:y}=this.generateTurtlePipelineSQL(e,p,this.parent.dialect.supportUnnestArrayAgg?h:i);if(y!==void 0){const g=p.generateCoorelatedSubQuery(this.parent.dialect,m);this.parent.dialect.supportUnnestArrayAgg?h=`(${g})`:s.push({sqlFieldName:i,pipelineSQL:`(${g})`})}return h}generateTurtlePipelineSQL(e,r,i){let s=this.getResultStructDef(e,!1);const o=e.getRepeatedResultType(),u=e.turtleDef.pipeline.length>1;let a,l=o;if(u){const c=[...e.turtleDef.pipeline];c.shift();const f={type:"turtle",name:"starthere",pipeline:c},x={type:"nest_source",name:"~pipe~",pipeSQL:this.parent.dialect.sqlUnnestPipelineHead(o==="inline_all_numbers",i,Wp(s)),fields:s.fields,connection:s.connection,dialect:s.dialect},h=new Wl(x,void 0,{model:this.parent.getModel()},this.parent.prepareResultOptions),p=fs.makeQuery(f,h,r,this.isJoinedSubquery);a=p.generateSQLFromPipeline(r),l=p.rootResult.getRepeatedResultType(),s=a.outputStruct}return s.annotation=e.turtleDef.annotation,{structDef:s,pipeOut:a,repeatedResultType:l}}generateComplexSQL(e){let r=this.generateSQLStage0(e);if(this.maxDepth>1){let i=this.maxDepth;for(;i>1;)r=this.generateSQLDepthN(i,e,r),i--}return this.genereateSQLCombineTurtles(e,r)}generateSQL(e){var r;const i=this.rootResult.computeGroups(0,0);return this.maxDepth=i.maxDepth,this.maxGroupSet=i.nextGroupSetNumber-1,this.rootResult.assignFieldsToGroups(),(r=this.rootResult).isComplexQuery||(r.isComplexQuery=this.maxDepth>0||i.isComplex),this.rootResult.isComplexQuery?this.generateComplexSQL(e):this.generateSimpleSQL(e)}generateSQLFromPipeline(e){this.parent.maybeEmitParameterizedSourceUsage(),this.prepare(e);let r=this.generateSQL(e),i=this.getResultStructDef();
|
|
1107
|
+
`),this.resultStage=e.addStage(i),this.resultStage=this.generatePipelinedStages(u,this.resultStage,e),this.resultStage}buildDialectFieldList(e){const r=[];for(const[i,s]of e.allFields){const o=this.parent.dialect.sqlMaybeQuoteIdentifier(i);if(e.firstSegment.type==="reduce"&&s instanceof ba){const{structDef:u,repeatedResultType:a}=this.generateTurtlePipelineSQL(s,new Vp(!0,void 0),"<nosource>");if(a==="nested"){const l={...u,type:"array",elementTypeDef:{type:"record_element"},join:"many",name:i};r.push({typeDef:l,sqlExpression:this.parent.dialect.sqlMaybeQuoteIdentifier(`${i}__${e.groupSet}`),rawName:i,sqlOutputName:o})}else{const l={...u,type:"record",join:"one",name:i};r.push({typeDef:l,sqlExpression:this.parent.dialect.sqlMaybeQuoteIdentifier(`${i}__${e.groupSet}`),rawName:i,sqlOutputName:o})}}else e.firstSegment.type==="reduce"&&s instanceof Ui&&s.fieldUsage.type==="result"?Tae(r,{fieldDef:s.f.fieldDef,sqlExpression:this.parent.dialect.sqlMaybeQuoteIdentifier(`${i}__${e.groupSet}`),rawName:i,sqlOutputName:o}):e.firstSegment.type==="project"&&s instanceof Ui&&s.fieldUsage.type==="result"&&Tae(r,{fieldDef:s.f.fieldDef,sqlExpression:s.f.generateExpression(e),rawName:i,sqlOutputName:o})}return r}generateTurtleSQL(e,r,i,s){let o="";const u=(0,Ie.isRawSegment)(e.firstSegment)?void 0:e.firstSegment.limit,a=[];let l;const c=e.firstSegment.orderBy||e.calculateDefaultOrderBy();for(const g of c)typeof g.field=="string"?l={name:g.field,fif:e.getField(g.field)}:l=e.getFieldByNumber(g.field),e.firstSegment.type==="reduce"?a.push(" "+this.parent.dialect.sqlMaybeQuoteIdentifier(`${l.name}__${e.groupSet}`)+` ${g.dir||"ASC"}`):e.firstSegment.type==="project"&&a.push(` ${l.fif.f.generateExpression(e)} ${g.dir||"ASC"}`);a.length>0&&(o=" "+this.parent.dialect.sqlOrderBy(a,"turtle"));const f=this.buildDialectFieldList(e);let x,h;(x=e.getRepeatedResultType())!=="nested"?x==="inline_all_numbers"?h=this.parent.dialect.sqlCoaleseMeasuresInline(e.groupSet,f):h=this.parent.dialect.sqlAnyValueTurtle(e.groupSet,f):h=this.parent.dialect.sqlAggregateTurtle(e.groupSet,f,o,u);const p=new Vp(this.parent.dialect.supportsCTEinCoorelatedSubQueries,r),{structDef:m,pipeOut:y}=this.generateTurtlePipelineSQL(e,p,this.parent.dialect.supportUnnestArrayAgg?h:i);if(y!==void 0){const g=p.generateCoorelatedSubQuery(this.parent.dialect,m);this.parent.dialect.supportUnnestArrayAgg?h=`(${g})`:s.push({sqlFieldName:i,pipelineSQL:`(${g})`})}return h}generateTurtlePipelineSQL(e,r,i){let s=this.getResultStructDef(e,!1);const o=e.getRepeatedResultType(),u=e.turtleDef.pipeline.length>1;let a,l=o;if(u){const c=[...e.turtleDef.pipeline];c.shift();const f={type:"turtle",name:"starthere",pipeline:c},x={type:"nest_source",name:"~pipe~",pipeSQL:this.parent.dialect.sqlUnnestPipelineHead(o==="inline_all_numbers",i,Wp(s)),fields:s.fields,connection:s.connection,dialect:s.dialect},h=new Wl(x,void 0,{model:this.parent.getModel()},this.parent.prepareResultOptions),p=fs.makeQuery(f,h,r,this.isJoinedSubquery);a=p.generateSQLFromPipeline(r),l=p.rootResult.getRepeatedResultType(),s=a.outputStruct}return s.annotation=e.turtleDef.annotation,{structDef:s,pipeOut:a,repeatedResultType:l}}generateComplexSQL(e){let r=this.generateSQLStage0(e);if(this.maxDepth>1){let i=this.maxDepth;for(;i>1;)r=this.generateSQLDepthN(i,e,r),i--}return this.genereateSQLCombineTurtles(e,r)}generateSQL(e){var r;const i=this.rootResult.computeGroups(0,0);return this.maxDepth=i.maxDepth,this.maxGroupSet=i.nextGroupSetNumber-1,this.rootResult.assignFieldsToGroups(),(r=this.rootResult).isComplexQuery||(r.isComplexQuery=this.maxDepth>0||i.isComplex),this.rootResult.isComplexQuery?this.generateComplexSQL(e):this.generateSimpleSQL(e)}generateSQLFromPipeline(e){this.parent.maybeEmitParameterizedSourceUsage(),this.prepare(e);let r=this.generateSQL(e),i=this.getResultStructDef();const s=[...this.fieldDef.pipeline];if(s.length>1){let o={...i,name:r,type:"finalize"};s.shift();for(const u of s){const a=this.parent.parent?{struct:this.parent.parent}:{model:this.parent.getModel()},l=new Wl(o,void 0,a,this.parent.prepareResultOptions),c=fs.makeQuery({type:"turtle",name:"~computeLastStage~",pipeline:[u]},l,e,this.isJoinedSubquery);c.prepare(e),r=c.generateSQL(e),i=c.getResultStructDef(),o={...i,name:r,type:"finalize"}}}return{lastStageName:r,outputStruct:i}}}class wXe extends fs{}class NXe extends fs{}class LXe extends fs{constructor(e,r,i,s){super(e,r,i,s),this.indexPaths={},this.fieldDef=e}expandField(e){const r=e.path.join("."),i=this.parent.getQueryFieldByName(e.path);return{as:r,field:i}}expandFields(e){let r=1;const i=e.groupSet;this.maxGroupSet=i;for(const o of this.firstSegment.indexFields){const{as:u,field:a}=this.expandField(o);this.indexPaths[u]=o.path,e.addField(u,a,{resultIndex:r,type:"result"}),a instanceof $s&&this.addDependancies(e,a),r++}const s=this.firstSegment.weightMeasure;if(s!==void 0){const o=this.parent.getFieldByName([s]);e.addField(s,o,{resultIndex:r,type:"result"}),this.addDependancies(e,o)}this.expandFilters(e)}generateSQL(e){let r="COUNT(*)";const i=this.parent.dialect,s=i.sqlMaybeQuoteIdentifier("fieldName"),o=i.sqlMaybeQuoteIdentifier("fieldPath"),u=i.sqlMaybeQuoteIdentifier("fieldValue"),a=i.sqlMaybeQuoteIdentifier("fieldType"),l=i.sqlMaybeQuoteIdentifier("fieldRange"),c=i.sqlMaybeQuoteIdentifier("weight"),f=this.firstSegment.weightMeasure;f&&(r=this.rootResult.getField(f).f.generateExpression(this.rootResult));const x=[];for(const[m,y]of this.rootResult.allFields){const g=y;if(g.fieldUsage.type==="result"&&Eo(g.f)){const E=g.f.generateExpression(this.rootResult),A=this.indexPaths[m]||[];x.push({name:m,path:A,type:g.f.fieldDef.type,expression:E})}}let h=`SELECT
|
|
1108
1108
|
group_set,
|
|
1109
1109
|
`;h+=` CASE group_set
|
|
1110
1110
|
`;for(let m=0;m<x.length;m++)h+=` WHEN ${m} THEN '${x[m].name}'
|
|
@@ -128104,10 +128104,11 @@ FROM ${r}
|
|
|
128104
128104
|
generateSQLFromPipeline(e) {
|
|
128105
128105
|
this.parent.maybeEmitParameterizedSourceUsage(), this.prepare(e);
|
|
128106
128106
|
let r = this.generateSQL(e), i = this.getResultStructDef();
|
|
128107
|
-
|
|
128108
|
-
|
|
128107
|
+
const s = [...this.fieldDef.pipeline];
|
|
128108
|
+
if (s.length > 1) {
|
|
128109
128109
|
let o = {
|
|
128110
128110
|
...i,
|
|
128111
|
+
name: r,
|
|
128111
128112
|
type: "finalize"
|
|
128112
128113
|
};
|
|
128113
128114
|
s.shift();
|
|
@@ -128115,6 +128116,7 @@ FROM ${r}
|
|
|
128115
128116
|
const a = this.parent.parent ? { struct: this.parent.parent } : { model: this.parent.getModel() }, l = new kl(o, void 0, a, this.parent.prepareResultOptions), c = ds.makeQuery({ type: "turtle", name: "~computeLastStage~", pipeline: [u] }, l, e, this.isJoinedSubquery);
|
|
128116
128117
|
c.prepare(e), r = c.generateSQL(e), i = c.getResultStructDef(), o = {
|
|
128117
128118
|
...i,
|
|
128119
|
+
name: r,
|
|
128118
128120
|
type: "finalize"
|
|
128119
128121
|
};
|
|
128120
128122
|
}
|
|
@@ -1499,7 +1499,7 @@ FROM ${r}
|
|
|
1499
1499
|
`;const l=this.rootResult.eliminateComputeGroupsSQL();return l.length>0&&(i+=`WHERE ${l}
|
|
1500
1500
|
`),a.length>0&&(i+=`GROUP BY ${a.join(",")}
|
|
1501
1501
|
`),i+=this.genereateSQLOrderBy(this.firstSegment,this.rootResult),!(0,ke.isRawSegment)(this.firstSegment)&&this.firstSegment.limit&&(i+=`LIMIT ${this.firstSegment.limit}
|
|
1502
|
-
`),this.resultStage=e.addStage(i),this.resultStage=this.generatePipelinedStages(u,this.resultStage,e),this.resultStage}buildDialectFieldList(e){const r=[];for(const[i,s]of e.allFields){const o=this.parent.dialect.sqlMaybeQuoteIdentifier(i);if(e.firstSegment.type==="reduce"&&s instanceof Ua){const{structDef:u,repeatedResultType:a}=this.generateTurtlePipelineSQL(s,new b2(!0,void 0),"<nosource>");if(a==="nested"){const l={...u,type:"array",elementTypeDef:{type:"record_element"},join:"many",name:i};r.push({typeDef:l,sqlExpression:this.parent.dialect.sqlMaybeQuoteIdentifier(`${i}__${e.groupSet}`),rawName:i,sqlOutputName:o})}else{const l={...u,type:"record",join:"one",name:i};r.push({typeDef:l,sqlExpression:this.parent.dialect.sqlMaybeQuoteIdentifier(`${i}__${e.groupSet}`),rawName:i,sqlOutputName:o})}}else e.firstSegment.type==="reduce"&&s instanceof Vi&&s.fieldUsage.type==="result"?Rle(r,{fieldDef:s.f.fieldDef,sqlExpression:this.parent.dialect.sqlMaybeQuoteIdentifier(`${i}__${e.groupSet}`),rawName:i,sqlOutputName:o}):e.firstSegment.type==="project"&&s instanceof Vi&&s.fieldUsage.type==="result"&&Rle(r,{fieldDef:s.f.fieldDef,sqlExpression:s.f.generateExpression(e),rawName:i,sqlOutputName:o})}return r}generateTurtleSQL(e,r,i,s){let o="";const u=(0,ke.isRawSegment)(e.firstSegment)?void 0:e.firstSegment.limit,a=[];let l;const c=e.firstSegment.orderBy||e.calculateDefaultOrderBy();for(const g of c)typeof g.field=="string"?l={name:g.field,fif:e.getField(g.field)}:l=e.getFieldByNumber(g.field),e.firstSegment.type==="reduce"?a.push(" "+this.parent.dialect.sqlMaybeQuoteIdentifier(`${l.name}__${e.groupSet}`)+` ${g.dir||"ASC"}`):e.firstSegment.type==="project"&&a.push(` ${l.fif.f.generateExpression(e)} ${g.dir||"ASC"}`);a.length>0&&(o=" "+this.parent.dialect.sqlOrderBy(a,"turtle"));const f=this.buildDialectFieldList(e);let x,h;(x=e.getRepeatedResultType())!=="nested"?x==="inline_all_numbers"?h=this.parent.dialect.sqlCoaleseMeasuresInline(e.groupSet,f):h=this.parent.dialect.sqlAnyValueTurtle(e.groupSet,f):h=this.parent.dialect.sqlAggregateTurtle(e.groupSet,f,o,u);const p=new b2(this.parent.dialect.supportsCTEinCoorelatedSubQueries,r),{structDef:m,pipeOut:y}=this.generateTurtlePipelineSQL(e,p,this.parent.dialect.supportUnnestArrayAgg?h:i);if(y!==void 0){const g=p.generateCoorelatedSubQuery(this.parent.dialect,m);this.parent.dialect.supportUnnestArrayAgg?h=`(${g})`:s.push({sqlFieldName:i,pipelineSQL:`(${g})`})}return h}generateTurtlePipelineSQL(e,r,i){let s=this.getResultStructDef(e,!1);const o=e.getRepeatedResultType(),u=e.turtleDef.pipeline.length>1;let a,l=o;if(u){const c=[...e.turtleDef.pipeline];c.shift();const f={type:"turtle",name:"starthere",pipeline:c},x={type:"nest_source",name:"~pipe~",pipeSQL:this.parent.dialect.sqlUnnestPipelineHead(o==="inline_all_numbers",i,S2(s)),fields:s.fields,connection:s.connection,dialect:s.dialect},h=new p0(x,void 0,{model:this.parent.getModel()},this.parent.prepareResultOptions),p=gs.makeQuery(f,h,r,this.isJoinedSubquery);a=p.generateSQLFromPipeline(r),l=p.rootResult.getRepeatedResultType(),s=a.outputStruct}return s.annotation=e.turtleDef.annotation,{structDef:s,pipeOut:a,repeatedResultType:l}}generateComplexSQL(e){let r=this.generateSQLStage0(e);if(this.maxDepth>1){let i=this.maxDepth;for(;i>1;)r=this.generateSQLDepthN(i,e,r),i--}return this.genereateSQLCombineTurtles(e,r)}generateSQL(e){var r;const i=this.rootResult.computeGroups(0,0);return this.maxDepth=i.maxDepth,this.maxGroupSet=i.nextGroupSetNumber-1,this.rootResult.assignFieldsToGroups(),(r=this.rootResult).isComplexQuery||(r.isComplexQuery=this.maxDepth>0||i.isComplex),this.rootResult.isComplexQuery?this.generateComplexSQL(e):this.generateSimpleSQL(e)}generateSQLFromPipeline(e){this.parent.maybeEmitParameterizedSourceUsage(),this.prepare(e);let r=this.generateSQL(e),i=this.getResultStructDef();
|
|
1502
|
+
`),this.resultStage=e.addStage(i),this.resultStage=this.generatePipelinedStages(u,this.resultStage,e),this.resultStage}buildDialectFieldList(e){const r=[];for(const[i,s]of e.allFields){const o=this.parent.dialect.sqlMaybeQuoteIdentifier(i);if(e.firstSegment.type==="reduce"&&s instanceof Ua){const{structDef:u,repeatedResultType:a}=this.generateTurtlePipelineSQL(s,new b2(!0,void 0),"<nosource>");if(a==="nested"){const l={...u,type:"array",elementTypeDef:{type:"record_element"},join:"many",name:i};r.push({typeDef:l,sqlExpression:this.parent.dialect.sqlMaybeQuoteIdentifier(`${i}__${e.groupSet}`),rawName:i,sqlOutputName:o})}else{const l={...u,type:"record",join:"one",name:i};r.push({typeDef:l,sqlExpression:this.parent.dialect.sqlMaybeQuoteIdentifier(`${i}__${e.groupSet}`),rawName:i,sqlOutputName:o})}}else e.firstSegment.type==="reduce"&&s instanceof Vi&&s.fieldUsage.type==="result"?Rle(r,{fieldDef:s.f.fieldDef,sqlExpression:this.parent.dialect.sqlMaybeQuoteIdentifier(`${i}__${e.groupSet}`),rawName:i,sqlOutputName:o}):e.firstSegment.type==="project"&&s instanceof Vi&&s.fieldUsage.type==="result"&&Rle(r,{fieldDef:s.f.fieldDef,sqlExpression:s.f.generateExpression(e),rawName:i,sqlOutputName:o})}return r}generateTurtleSQL(e,r,i,s){let o="";const u=(0,ke.isRawSegment)(e.firstSegment)?void 0:e.firstSegment.limit,a=[];let l;const c=e.firstSegment.orderBy||e.calculateDefaultOrderBy();for(const g of c)typeof g.field=="string"?l={name:g.field,fif:e.getField(g.field)}:l=e.getFieldByNumber(g.field),e.firstSegment.type==="reduce"?a.push(" "+this.parent.dialect.sqlMaybeQuoteIdentifier(`${l.name}__${e.groupSet}`)+` ${g.dir||"ASC"}`):e.firstSegment.type==="project"&&a.push(` ${l.fif.f.generateExpression(e)} ${g.dir||"ASC"}`);a.length>0&&(o=" "+this.parent.dialect.sqlOrderBy(a,"turtle"));const f=this.buildDialectFieldList(e);let x,h;(x=e.getRepeatedResultType())!=="nested"?x==="inline_all_numbers"?h=this.parent.dialect.sqlCoaleseMeasuresInline(e.groupSet,f):h=this.parent.dialect.sqlAnyValueTurtle(e.groupSet,f):h=this.parent.dialect.sqlAggregateTurtle(e.groupSet,f,o,u);const p=new b2(this.parent.dialect.supportsCTEinCoorelatedSubQueries,r),{structDef:m,pipeOut:y}=this.generateTurtlePipelineSQL(e,p,this.parent.dialect.supportUnnestArrayAgg?h:i);if(y!==void 0){const g=p.generateCoorelatedSubQuery(this.parent.dialect,m);this.parent.dialect.supportUnnestArrayAgg?h=`(${g})`:s.push({sqlFieldName:i,pipelineSQL:`(${g})`})}return h}generateTurtlePipelineSQL(e,r,i){let s=this.getResultStructDef(e,!1);const o=e.getRepeatedResultType(),u=e.turtleDef.pipeline.length>1;let a,l=o;if(u){const c=[...e.turtleDef.pipeline];c.shift();const f={type:"turtle",name:"starthere",pipeline:c},x={type:"nest_source",name:"~pipe~",pipeSQL:this.parent.dialect.sqlUnnestPipelineHead(o==="inline_all_numbers",i,S2(s)),fields:s.fields,connection:s.connection,dialect:s.dialect},h=new p0(x,void 0,{model:this.parent.getModel()},this.parent.prepareResultOptions),p=gs.makeQuery(f,h,r,this.isJoinedSubquery);a=p.generateSQLFromPipeline(r),l=p.rootResult.getRepeatedResultType(),s=a.outputStruct}return s.annotation=e.turtleDef.annotation,{structDef:s,pipeOut:a,repeatedResultType:l}}generateComplexSQL(e){let r=this.generateSQLStage0(e);if(this.maxDepth>1){let i=this.maxDepth;for(;i>1;)r=this.generateSQLDepthN(i,e,r),i--}return this.genereateSQLCombineTurtles(e,r)}generateSQL(e){var r;const i=this.rootResult.computeGroups(0,0);return this.maxDepth=i.maxDepth,this.maxGroupSet=i.nextGroupSetNumber-1,this.rootResult.assignFieldsToGroups(),(r=this.rootResult).isComplexQuery||(r.isComplexQuery=this.maxDepth>0||i.isComplex),this.rootResult.isComplexQuery?this.generateComplexSQL(e):this.generateSimpleSQL(e)}generateSQLFromPipeline(e){this.parent.maybeEmitParameterizedSourceUsage(),this.prepare(e);let r=this.generateSQL(e),i=this.getResultStructDef();const s=[...this.fieldDef.pipeline];if(s.length>1){let o={...i,name:r,type:"finalize"};s.shift();for(const u of s){const a=this.parent.parent?{struct:this.parent.parent}:{model:this.parent.getModel()},l=new p0(o,void 0,a,this.parent.prepareResultOptions),c=gs.makeQuery({type:"turtle",name:"~computeLastStage~",pipeline:[u]},l,e,this.isJoinedSubquery);c.prepare(e),r=c.generateSQL(e),i=c.getResultStructDef(),o={...i,name:r,type:"finalize"}}}return{lastStageName:r,outputStruct:i}}}class btt extends gs{}class Ttt extends gs{}class Rtt extends gs{constructor(e,r,i,s){super(e,r,i,s),this.indexPaths={},this.fieldDef=e}expandField(e){const r=e.path.join("."),i=this.parent.getQueryFieldByName(e.path);return{as:r,field:i}}expandFields(e){let r=1;const i=e.groupSet;this.maxGroupSet=i;for(const o of this.firstSegment.indexFields){const{as:u,field:a}=this.expandField(o);this.indexPaths[u]=o.path,e.addField(u,a,{resultIndex:r,type:"result"}),a instanceof Hs&&this.addDependancies(e,a),r++}const s=this.firstSegment.weightMeasure;if(s!==void 0){const o=this.parent.getFieldByName([s]);e.addField(s,o,{resultIndex:r,type:"result"}),this.addDependancies(e,o)}this.expandFilters(e)}generateSQL(e){let r="COUNT(*)";const i=this.parent.dialect,s=i.sqlMaybeQuoteIdentifier("fieldName"),o=i.sqlMaybeQuoteIdentifier("fieldPath"),u=i.sqlMaybeQuoteIdentifier("fieldValue"),a=i.sqlMaybeQuoteIdentifier("fieldType"),l=i.sqlMaybeQuoteIdentifier("fieldRange"),c=i.sqlMaybeQuoteIdentifier("weight"),f=this.firstSegment.weightMeasure;f&&(r=this.rootResult.getField(f).f.generateExpression(this.rootResult));const x=[];for(const[m,y]of this.rootResult.allFields){const g=y;if(g.fieldUsage.type==="result"&&Ro(g.f)){const E=g.f.generateExpression(this.rootResult),A=this.indexPaths[m]||[];x.push({name:m,path:A,type:g.f.fieldDef.type,expression:E})}}let h=`SELECT
|
|
1503
1503
|
group_set,
|
|
1504
1504
|
`;h+=` CASE group_set
|
|
1505
1505
|
`;for(let m=0;m<x.length;m++)h+=` WHEN ${m} THEN '${x[m].name}'
|
|
@@ -128104,10 +128104,11 @@ FROM ${r}
|
|
|
128104
128104
|
generateSQLFromPipeline(e) {
|
|
128105
128105
|
this.parent.maybeEmitParameterizedSourceUsage(), this.prepare(e);
|
|
128106
128106
|
let r = this.generateSQL(e), i = this.getResultStructDef();
|
|
128107
|
-
|
|
128108
|
-
|
|
128107
|
+
const s = [...this.fieldDef.pipeline];
|
|
128108
|
+
if (s.length > 1) {
|
|
128109
128109
|
let o = {
|
|
128110
128110
|
...i,
|
|
128111
|
+
name: r,
|
|
128111
128112
|
type: "finalize"
|
|
128112
128113
|
};
|
|
128113
128114
|
s.shift();
|
|
@@ -128115,6 +128116,7 @@ FROM ${r}
|
|
|
128115
128116
|
const a = this.parent.parent ? { struct: this.parent.parent } : { model: this.parent.getModel() }, l = new kl(o, void 0, a, this.parent.prepareResultOptions), c = ds.makeQuery({ type: "turtle", name: "~computeLastStage~", pipeline: [u] }, l, e, this.isJoinedSubquery);
|
|
128116
128117
|
c.prepare(e), r = c.generateSQL(e), i = c.getResultStructDef(), o = {
|
|
128117
128118
|
...i,
|
|
128119
|
+
name: r,
|
|
128118
128120
|
type: "finalize"
|
|
128119
128121
|
};
|
|
128120
128122
|
}
|
|
@@ -1499,7 +1499,7 @@ FROM ${r}
|
|
|
1499
1499
|
`;const l=this.rootResult.eliminateComputeGroupsSQL();return l.length>0&&(i+=`WHERE ${l}
|
|
1500
1500
|
`),a.length>0&&(i+=`GROUP BY ${a.join(",")}
|
|
1501
1501
|
`),i+=this.genereateSQLOrderBy(this.firstSegment,this.rootResult),!(0,ke.isRawSegment)(this.firstSegment)&&this.firstSegment.limit&&(i+=`LIMIT ${this.firstSegment.limit}
|
|
1502
|
-
`),this.resultStage=e.addStage(i),this.resultStage=this.generatePipelinedStages(u,this.resultStage,e),this.resultStage}buildDialectFieldList(e){const r=[];for(const[i,s]of e.allFields){const o=this.parent.dialect.sqlMaybeQuoteIdentifier(i);if(e.firstSegment.type==="reduce"&&s instanceof Ua){const{structDef:u,repeatedResultType:a}=this.generateTurtlePipelineSQL(s,new b2(!0,void 0),"<nosource>");if(a==="nested"){const l={...u,type:"array",elementTypeDef:{type:"record_element"},join:"many",name:i};r.push({typeDef:l,sqlExpression:this.parent.dialect.sqlMaybeQuoteIdentifier(`${i}__${e.groupSet}`),rawName:i,sqlOutputName:o})}else{const l={...u,type:"record",join:"one",name:i};r.push({typeDef:l,sqlExpression:this.parent.dialect.sqlMaybeQuoteIdentifier(`${i}__${e.groupSet}`),rawName:i,sqlOutputName:o})}}else e.firstSegment.type==="reduce"&&s instanceof Vi&&s.fieldUsage.type==="result"?Tle(r,{fieldDef:s.f.fieldDef,sqlExpression:this.parent.dialect.sqlMaybeQuoteIdentifier(`${i}__${e.groupSet}`),rawName:i,sqlOutputName:o}):e.firstSegment.type==="project"&&s instanceof Vi&&s.fieldUsage.type==="result"&&Tle(r,{fieldDef:s.f.fieldDef,sqlExpression:s.f.generateExpression(e),rawName:i,sqlOutputName:o})}return r}generateTurtleSQL(e,r,i,s){let o="";const u=(0,ke.isRawSegment)(e.firstSegment)?void 0:e.firstSegment.limit,a=[];let l;const c=e.firstSegment.orderBy||e.calculateDefaultOrderBy();for(const g of c)typeof g.field=="string"?l={name:g.field,fif:e.getField(g.field)}:l=e.getFieldByNumber(g.field),e.firstSegment.type==="reduce"?a.push(" "+this.parent.dialect.sqlMaybeQuoteIdentifier(`${l.name}__${e.groupSet}`)+` ${g.dir||"ASC"}`):e.firstSegment.type==="project"&&a.push(` ${l.fif.f.generateExpression(e)} ${g.dir||"ASC"}`);a.length>0&&(o=" "+this.parent.dialect.sqlOrderBy(a,"turtle"));const f=this.buildDialectFieldList(e);let x,h;(x=e.getRepeatedResultType())!=="nested"?x==="inline_all_numbers"?h=this.parent.dialect.sqlCoaleseMeasuresInline(e.groupSet,f):h=this.parent.dialect.sqlAnyValueTurtle(e.groupSet,f):h=this.parent.dialect.sqlAggregateTurtle(e.groupSet,f,o,u);const p=new b2(this.parent.dialect.supportsCTEinCoorelatedSubQueries,r),{structDef:m,pipeOut:y}=this.generateTurtlePipelineSQL(e,p,this.parent.dialect.supportUnnestArrayAgg?h:i);if(y!==void 0){const g=p.generateCoorelatedSubQuery(this.parent.dialect,m);this.parent.dialect.supportUnnestArrayAgg?h=`(${g})`:s.push({sqlFieldName:i,pipelineSQL:`(${g})`})}return h}generateTurtlePipelineSQL(e,r,i){let s=this.getResultStructDef(e,!1);const o=e.getRepeatedResultType(),u=e.turtleDef.pipeline.length>1;let a,l=o;if(u){const c=[...e.turtleDef.pipeline];c.shift();const f={type:"turtle",name:"starthere",pipeline:c},x={type:"nest_source",name:"~pipe~",pipeSQL:this.parent.dialect.sqlUnnestPipelineHead(o==="inline_all_numbers",i,S2(s)),fields:s.fields,connection:s.connection,dialect:s.dialect},h=new p0(x,void 0,{model:this.parent.getModel()},this.parent.prepareResultOptions),p=gs.makeQuery(f,h,r,this.isJoinedSubquery);a=p.generateSQLFromPipeline(r),l=p.rootResult.getRepeatedResultType(),s=a.outputStruct}return s.annotation=e.turtleDef.annotation,{structDef:s,pipeOut:a,repeatedResultType:l}}generateComplexSQL(e){let r=this.generateSQLStage0(e);if(this.maxDepth>1){let i=this.maxDepth;for(;i>1;)r=this.generateSQLDepthN(i,e,r),i--}return this.genereateSQLCombineTurtles(e,r)}generateSQL(e){var r;const i=this.rootResult.computeGroups(0,0);return this.maxDepth=i.maxDepth,this.maxGroupSet=i.nextGroupSetNumber-1,this.rootResult.assignFieldsToGroups(),(r=this.rootResult).isComplexQuery||(r.isComplexQuery=this.maxDepth>0||i.isComplex),this.rootResult.isComplexQuery?this.generateComplexSQL(e):this.generateSimpleSQL(e)}generateSQLFromPipeline(e){this.parent.maybeEmitParameterizedSourceUsage(),this.prepare(e);let r=this.generateSQL(e),i=this.getResultStructDef();
|
|
1502
|
+
`),this.resultStage=e.addStage(i),this.resultStage=this.generatePipelinedStages(u,this.resultStage,e),this.resultStage}buildDialectFieldList(e){const r=[];for(const[i,s]of e.allFields){const o=this.parent.dialect.sqlMaybeQuoteIdentifier(i);if(e.firstSegment.type==="reduce"&&s instanceof Ua){const{structDef:u,repeatedResultType:a}=this.generateTurtlePipelineSQL(s,new b2(!0,void 0),"<nosource>");if(a==="nested"){const l={...u,type:"array",elementTypeDef:{type:"record_element"},join:"many",name:i};r.push({typeDef:l,sqlExpression:this.parent.dialect.sqlMaybeQuoteIdentifier(`${i}__${e.groupSet}`),rawName:i,sqlOutputName:o})}else{const l={...u,type:"record",join:"one",name:i};r.push({typeDef:l,sqlExpression:this.parent.dialect.sqlMaybeQuoteIdentifier(`${i}__${e.groupSet}`),rawName:i,sqlOutputName:o})}}else e.firstSegment.type==="reduce"&&s instanceof Vi&&s.fieldUsage.type==="result"?Tle(r,{fieldDef:s.f.fieldDef,sqlExpression:this.parent.dialect.sqlMaybeQuoteIdentifier(`${i}__${e.groupSet}`),rawName:i,sqlOutputName:o}):e.firstSegment.type==="project"&&s instanceof Vi&&s.fieldUsage.type==="result"&&Tle(r,{fieldDef:s.f.fieldDef,sqlExpression:s.f.generateExpression(e),rawName:i,sqlOutputName:o})}return r}generateTurtleSQL(e,r,i,s){let o="";const u=(0,ke.isRawSegment)(e.firstSegment)?void 0:e.firstSegment.limit,a=[];let l;const c=e.firstSegment.orderBy||e.calculateDefaultOrderBy();for(const g of c)typeof g.field=="string"?l={name:g.field,fif:e.getField(g.field)}:l=e.getFieldByNumber(g.field),e.firstSegment.type==="reduce"?a.push(" "+this.parent.dialect.sqlMaybeQuoteIdentifier(`${l.name}__${e.groupSet}`)+` ${g.dir||"ASC"}`):e.firstSegment.type==="project"&&a.push(` ${l.fif.f.generateExpression(e)} ${g.dir||"ASC"}`);a.length>0&&(o=" "+this.parent.dialect.sqlOrderBy(a,"turtle"));const f=this.buildDialectFieldList(e);let x,h;(x=e.getRepeatedResultType())!=="nested"?x==="inline_all_numbers"?h=this.parent.dialect.sqlCoaleseMeasuresInline(e.groupSet,f):h=this.parent.dialect.sqlAnyValueTurtle(e.groupSet,f):h=this.parent.dialect.sqlAggregateTurtle(e.groupSet,f,o,u);const p=new b2(this.parent.dialect.supportsCTEinCoorelatedSubQueries,r),{structDef:m,pipeOut:y}=this.generateTurtlePipelineSQL(e,p,this.parent.dialect.supportUnnestArrayAgg?h:i);if(y!==void 0){const g=p.generateCoorelatedSubQuery(this.parent.dialect,m);this.parent.dialect.supportUnnestArrayAgg?h=`(${g})`:s.push({sqlFieldName:i,pipelineSQL:`(${g})`})}return h}generateTurtlePipelineSQL(e,r,i){let s=this.getResultStructDef(e,!1);const o=e.getRepeatedResultType(),u=e.turtleDef.pipeline.length>1;let a,l=o;if(u){const c=[...e.turtleDef.pipeline];c.shift();const f={type:"turtle",name:"starthere",pipeline:c},x={type:"nest_source",name:"~pipe~",pipeSQL:this.parent.dialect.sqlUnnestPipelineHead(o==="inline_all_numbers",i,S2(s)),fields:s.fields,connection:s.connection,dialect:s.dialect},h=new p0(x,void 0,{model:this.parent.getModel()},this.parent.prepareResultOptions),p=gs.makeQuery(f,h,r,this.isJoinedSubquery);a=p.generateSQLFromPipeline(r),l=p.rootResult.getRepeatedResultType(),s=a.outputStruct}return s.annotation=e.turtleDef.annotation,{structDef:s,pipeOut:a,repeatedResultType:l}}generateComplexSQL(e){let r=this.generateSQLStage0(e);if(this.maxDepth>1){let i=this.maxDepth;for(;i>1;)r=this.generateSQLDepthN(i,e,r),i--}return this.genereateSQLCombineTurtles(e,r)}generateSQL(e){var r;const i=this.rootResult.computeGroups(0,0);return this.maxDepth=i.maxDepth,this.maxGroupSet=i.nextGroupSetNumber-1,this.rootResult.assignFieldsToGroups(),(r=this.rootResult).isComplexQuery||(r.isComplexQuery=this.maxDepth>0||i.isComplex),this.rootResult.isComplexQuery?this.generateComplexSQL(e):this.generateSimpleSQL(e)}generateSQLFromPipeline(e){this.parent.maybeEmitParameterizedSourceUsage(),this.prepare(e);let r=this.generateSQL(e),i=this.getResultStructDef();const s=[...this.fieldDef.pipeline];if(s.length>1){let o={...i,name:r,type:"finalize"};s.shift();for(const u of s){const a=this.parent.parent?{struct:this.parent.parent}:{model:this.parent.getModel()},l=new p0(o,void 0,a,this.parent.prepareResultOptions),c=gs.makeQuery({type:"turtle",name:"~computeLastStage~",pipeline:[u]},l,e,this.isJoinedSubquery);c.prepare(e),r=c.generateSQL(e),i=c.getResultStructDef(),o={...i,name:r,type:"finalize"}}}return{lastStageName:r,outputStruct:i}}}class btt extends gs{}class Ttt extends gs{}class Rtt extends gs{constructor(e,r,i,s){super(e,r,i,s),this.indexPaths={},this.fieldDef=e}expandField(e){const r=e.path.join("."),i=this.parent.getQueryFieldByName(e.path);return{as:r,field:i}}expandFields(e){let r=1;const i=e.groupSet;this.maxGroupSet=i;for(const o of this.firstSegment.indexFields){const{as:u,field:a}=this.expandField(o);this.indexPaths[u]=o.path,e.addField(u,a,{resultIndex:r,type:"result"}),a instanceof Hs&&this.addDependancies(e,a),r++}const s=this.firstSegment.weightMeasure;if(s!==void 0){const o=this.parent.getFieldByName([s]);e.addField(s,o,{resultIndex:r,type:"result"}),this.addDependancies(e,o)}this.expandFilters(e)}generateSQL(e){let r="COUNT(*)";const i=this.parent.dialect,s=i.sqlMaybeQuoteIdentifier("fieldName"),o=i.sqlMaybeQuoteIdentifier("fieldPath"),u=i.sqlMaybeQuoteIdentifier("fieldValue"),a=i.sqlMaybeQuoteIdentifier("fieldType"),l=i.sqlMaybeQuoteIdentifier("fieldRange"),c=i.sqlMaybeQuoteIdentifier("weight"),f=this.firstSegment.weightMeasure;f&&(r=this.rootResult.getField(f).f.generateExpression(this.rootResult));const x=[];for(const[m,y]of this.rootResult.allFields){const g=y;if(g.fieldUsage.type==="result"&&Ro(g.f)){const E=g.f.generateExpression(this.rootResult),A=this.indexPaths[m]||[];x.push({name:m,path:A,type:g.f.fieldDef.type,expression:E})}}let h=`SELECT
|
|
1503
1503
|
group_set,
|
|
1504
1504
|
`;h+=` CASE group_set
|
|
1505
1505
|
`;for(let m=0;m<x.length;m++)h+=` WHEN ${m} THEN '${x[m].name}'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@malloydata/render",
|
|
3
|
-
"version": "0.0.261-
|
|
3
|
+
"version": "0.0.261-dev250411164723",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/module/index.umd.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -41,9 +41,9 @@
|
|
|
41
41
|
"generate-flow": "ts-node ../../scripts/gen-flow.ts"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@malloydata/malloy": "^0.0.261-
|
|
45
|
-
"@malloydata/malloy-interfaces": "^0.0.261-
|
|
46
|
-
"@malloydata/malloy-tag": "^0.0.261-
|
|
44
|
+
"@malloydata/malloy": "^0.0.261-dev250411164723",
|
|
45
|
+
"@malloydata/malloy-interfaces": "^0.0.261-dev250411164723",
|
|
46
|
+
"@malloydata/malloy-tag": "^0.0.261-dev250411164723",
|
|
47
47
|
"@tanstack/solid-virtual": "^3.10.4",
|
|
48
48
|
"component-register": "^0.8.6",
|
|
49
49
|
"lodash": "^4.17.20",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"vega-lite": "^5.2.0"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
|
-
"@malloydata/db-duckdb": "^0.0.261-
|
|
59
|
+
"@malloydata/db-duckdb": "^0.0.261-dev250411164723",
|
|
60
60
|
"@storybook/addon-essentials": "^8.5.8",
|
|
61
61
|
"@storybook/addon-interactions": "^8.5.8",
|
|
62
62
|
"@storybook/addon-links": "^8.5.8",
|