@malloydata/render 0.0.185-dev240918170742 → 0.0.185-dev240919162259

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,4 @@
1
+ import { Explore, Tag } from '@malloydata/malloy';
2
+ import { AreaChartSettings } from './get-area_chart-settings';
3
+ import { RenderResultMetadata, VegaChartProps } from '../types';
4
+ export declare function generateAreaChartVegaLiteSpec(explore: Explore, settings: AreaChartSettings, metadata: RenderResultMetadata, chartTag: Tag): VegaChartProps;
@@ -0,0 +1,15 @@
1
+ import { Explore, Tag } from '@malloydata/malloy';
2
+ import { Channel } from '../plot/plot-spec';
3
+ export type AreaChartSettings = {
4
+ xChannel: Channel;
5
+ yChannel: Channel;
6
+ y2Channel: Channel;
7
+ seriesChannel: Channel;
8
+ zeroBaseline: boolean;
9
+ interpolate?: string;
10
+ isDiffChart: boolean;
11
+ isStreamGraph: boolean;
12
+ isDimensionalSeries: boolean;
13
+ isMeasureSeries: boolean;
14
+ };
15
+ export declare function getAreaChartSettings(explore: Explore, tagOverride?: Tag): AreaChartSettings;
@@ -5817,9 +5817,9 @@ class Fr extends Mz {
5817
5817
  }
5818
5818
  getQueryFieldReference(e, n) {
5819
5819
  const r = this.getQueryFieldByName(e);
5820
- if (n) {
5820
+ if (n !== void 0) {
5821
5821
  const i = { ...r.fieldDef };
5822
- i.annotation = n, r.fieldDef = i;
5822
+ return i.annotation = n, this.makeQueryField(i);
5823
5823
  }
5824
5824
  return r;
5825
5825
  }
@@ -374,7 +374,7 @@ FROM ${n}
374
374
  FROM ${h}
375
375
  `),this.resultStage}}class mce extends As{generateSQL(e){const n=this.parent.fieldDef.structSource;if(n.type!=="sql"||n.method!=="subquery")throw new Error("Invalid struct for QueryQueryRaw, currently only supports SQL");const r=n.sqlBlock.selectStr;return e.addStage(r)}prepare(){}getResultStructDef(){return this.parent.fieldDef}getResultMetadata(e){}}class yce extends As{constructor(e,n,r,i){super(e,n,r,i),this.stages=[],this.fieldDef=e,this.fieldsToStages()}fieldsToStages(){const e=this.firstSegment;if(this.parent.dialect.dontUnionIndex){this.stages=[e.indexFields];return}const n={};for(const r of e.indexFields){if(r.path.length>1){const i=n$(r.path.slice(0,r.path.length-1)),s=n[i];if(s===void 0){const o=this.parent.nameMap.get(r.path[0]);if(o instanceof br&&(o.fieldDef.structRelationship.type==="many"||o.fieldDef.structRelationship.type==="nested")&&o.fieldDef.fields.length>1){const u=[r];n[i]=u,this.stages.push(u);continue}}else{s.push(r);continue}}this.stages[0]===void 0&&(this.stages[0]=[]),this.stages[0].push(r)}}expandFields(e){}generateSQL(e){const n=this.firstSegment,r=[];for(const i of this.stages){const s=new gce({...this.fieldDef,pipeline:[{...n,indexFields:i}]},this.parent,e,this.isJoinedSubquery);s.prepare(e);const o=s.generateSQL(e);r.push(o)}return r.length===1?this.resultStage=r[0]:this.resultStage=e.addStage(r.map(i=>`SELECT * FROM ${i}
376
376
  `).join(` UNION ALL
377
- `)),this.resultStage}getResultStructDef(){const e={type:"struct",name:this.resultStage||"result",dialect:this.parent.fieldDef.dialect,fields:[{type:"string",name:"fieldName"},{type:"string",name:"fieldPath"},{type:"string",name:"fieldValue"},{type:"string",name:"fieldType"},{type:"number",name:"weight",numberType:"integer"}],structRelationship:{type:"basetable",connectionName:this.parent.connectionName},structSource:{type:"query_result"}};return this.parent.fieldDef.modelAnnotation&&(e.modelAnnotation=this.parent.fieldDef.modelAnnotation),e}}class br extends r${constructor(e,n,r){if(super(e),this.sourceArguments=n,this.nameMap=new Map,this._arguments=void 0,this.setParent(r),"model"in r)if(this.model=r.model,this.pathAliasMap=new Map,e.structRelationship.type==="basetable")this.connectionName=e.structRelationship.connectionName;else throw new Error("All root StructDefs should be a baseTable");else this.model=this.getModel(),this.pathAliasMap=this.root().pathAliasMap,this.connectionName=this.root().connectionName;this.fieldDef=e,this.dialect=(0,tce.getDialect)(this.fieldDef.dialect),this.addFieldsFromFieldList(this.fieldDef.fields)}resolveParentParameterReferences(e){return{...e,value:e.value===null?null:(0,an.exprMap)(e.value,n=>{if(n.node==="parameter"){if(this.parent===void 0)throw new Error("No parent from which to retrieve parameter value");const r=this.parent.arguments()[n.path[0]],i=this.parent.resolveParentParameterReferences(r);if(i.value===null)throw new Error("Invalid parameter value");return i.value}return n})}}arguments(){var e;if(this._arguments!==void 0)return this._arguments;this._arguments={};const n=(e=this.fieldDef.parameters)!==null&&e!==void 0?e:{};for(const i in n)this._arguments[i]=n[i];const r={...this.fieldDef.arguments,...this.sourceArguments};for(const i in r){const s=r[i];this._arguments[i]=this.resolveParentParameterReferences(s)}return this._arguments}addFieldsFromFieldList(e){for(const n of e){const r=(0,Ze.getIdentifier)(n);switch(n.type){case"struct":{this.addFieldToNameMap(r,new br(n,void 0,{struct:this}));break}case"turtle":{this.addFieldToNameMap(r,As.makeQuery(n,this,void 0,!1));break}default:this.addFieldToNameMap(r,this.makeQueryField(n))}}this.nameMap.has("__distinct_key")||this.addFieldToNameMap("__distinct_key",new cce({type:"string",name:"__distinct_key"},this))}getAliasIdentifier(){const e=this.getFullOutputName(),n=this.pathAliasMap.get(e);if(n===void 0){const r=Array.from(this.pathAliasMap.values()),i=rce((0,Ze.getIdentifier)(this.fieldDef));let s=`${i}_0`,o=1;for(;r.includes(s)&&o<1e3;)o++,s=`${i}_${o}`;if(o<1e3)return this.pathAliasMap.set(e,s),s;throw new Error("Internal Error: cannot create unique alias name")}else return n}getSQLIdentifier(){return this.unnestWithNumbers()&&this.parent!==void 0?this.parent.getSQLIdentifier()+"."+(0,Ze.getIdentifier)(this.fieldDef)+`[${this.getIdentifier()}.__row_id]`:this.getIdentifier()}getIdentifier(){return this.fieldDef.structRelationship.type==="basetable"?"base":this.fieldDef.structRelationship.type==="inline"&&this.parent?this.parent.getSQLIdentifier()+"."+super.getIdentifier():this.getAliasIdentifier()}getFullOutputName(){return this.parent?this.parent.getFullOutputName()+(0,Ze.getIdentifier)(this.fieldDef)+".":""}needsSymetricCalculation(e){const n=this.getJoinableParent().getIdentifier(),r=e.root().joins.get(n);if(r)return!r.leafiest;throw new Error(`Join ${n} not found in result set`)}unnestWithNumbers(){return this.dialect.unnestWithNumbers&&this.fieldDef.structRelationship.type==="nested"}getJoinableParent(){if(this.fieldDef.structRelationship.type==="inline"){if(this.parent)return this.parent.getJoinableParent();throw new Error("Internal Error: inline struct cannot be root")}return this}addFieldToNameMap(e,n){if(this.nameMap.has(e))throw new Error(`Redefinition of ${e}`);this.nameMap.set(e,n)}getPrimaryKeyField(e){let n;if(n=this.primaryKey())return n;throw new Error(`Missing primary key for ${e}`)}resolveQueryFields(){if(this.fieldDef.structSource.type==="query"){const e=this.model.loadQuery(this.fieldDef.structSource.query,void 0).structs.pop();if(!e)throw new Error("Internal Error, query didn't produce a struct");const n={...this.fieldDef};for(const r of e.fields){let i;this.nameMap.has(i=(0,Ze.getIdentifier)(r))||(n.fields.push(r),this.nameMap.set(i,this.makeQueryField(r)))}this.fieldDef=n,!this.fieldDef.primaryKey&&e.primaryKey&&(this.fieldDef.primaryKey=e.primaryKey)}for(const[,e]of this.nameMap)e instanceof br&&e.resolveQueryFields()}getModel(){if(this.model)return this.model;if(this.parent===void 0)throw new Error("Expected this query struct to have a parent, as no model was present.");return this.parent.getModel()}setParent(e){"struct"in e&&(this.parent=e.struct),"model"in e?this.model=e.model:this.model=this.getModel()}makeQueryField(e){switch(e.type){case"string":return new sce(e,this);case"date":return new sT(e,this);case"timestamp":return new oT(e,this);case"number":return new oce(e,this);case"boolean":return new iT(e,this);case"json":return new uce(e,this);case"sql native":return new ace(e,this);case"turtle":return new u$(e,this);default:throw new Error(`unknown field definition ${JSON.stringify(e)}`)}}structSourceSQL(e){switch(this.fieldDef.structSource.type){case"table":{const n=this.fieldDef.structSource.tablePath;return this.dialect.quoteTablePath(n)}case"sql":if(this.fieldDef.structSource.method==="nested"||this.fieldDef.structSource.method==="lastStage")return this.fieldDef.name;if(this.fieldDef.structSource.method==="subquery")return`(${this.fieldDef.structSource.sqlBlock.selectStr})`;throw new Error("Internal Error: Unknown structSource type 'sql' method");case"nested":return"UNNEST(this.fieldDef.name)";case"inline":return"";case"query":{const n=(0,Ze.getIdentifier)(this.fieldDef);if(n.includes("cache")){const r=new l2(!0,e);return this.model.loadQuery(this.fieldDef.structSource.query,r,!1,!1),r.addPDT(n,this.dialect)}else return this.model.loadQuery(this.fieldDef.structSource.query,e,!1,!0).lastStageName}default:throw new Error(`unknown structSource ${this.fieldDef}`)}}root(){return this.parent===void 0?this:this.parent.root()}primaryKey(){if(this.fieldDef.primaryKey)return this.getDimensionByName([this.fieldDef.primaryKey])}getChildByName(e){return this.nameMap.get(e)}getFieldByName(e){return e.reduce((n,r)=>{const i=n.getChildByName(r);if(i===void 0)throw new Error(e.length===1?`'${r}' not found`:`'${r}' not found in '${e.join(".")}'`);return i},this)}getQueryFieldByName(e){const n=this.getFieldByName(e);if(n instanceof br)throw new Error(`Cannot reference ${e} as a scalar'`);return n}getQueryFieldReference(e,n){const r=this.getQueryFieldByName(e);if(n){const i={...r.fieldDef};i.annotation=n,r.fieldDef=i}return r}getDimensionOrMeasureByName(e){const n=this.getFieldByName(e);if(n instanceof Cr)return n;throw new Error(`${e} is not of type a scalar'`)}getDimensionByName(e){const n=this.getFieldByName(e);if(n instanceof Cr&&cr(n))return n;throw new Error(`${e} is not of type a scalar'`)}getStructByName(e){const n=this.getFieldByName(e);if(n instanceof br)return n;throw new Error(`Error: Path to structure not found '${e.join(".")}'`)}getDistinctKey(){if(this.fieldDef.structRelationship.type!=="inline")return this.getDimensionByName(["__distinct_key"]);if(this.parent)return this.parent.getDistinctKey();throw new Error("Internal Error. inline struct can not be top level")}applyStructFiltersToTurtleDef(e){let n=e.pipeline;const r=e.annotation,i=e.filterList||[];return n=structuredClone(n),n[0].filterList=i.concat(n[0].filterList||[],this.fieldDef.filterList||[]),{type:"turtle",name:e.name,pipeline:n,annotation:r,location:e.location}}}class a${constructor(e){this.dialect=new nce.StandardSQLDialect,this.modelDef=void 0,this.structs=new Map,this.exploreSearchSQLMap=new Map,e&&this.loadModelFromDef(e)}loadModelFromDef(e){this.modelDef=e;for(const n of Object.values(this.modelDef.contents)){let r;if(n.type==="struct")r=new br(n,void 0,{model:this}),this.structs.set((0,Ze.getIdentifier)(n),r),r.resolveQueryFields();else if(n.type!=="query")throw new Error("Internal Error: Unknown structure type")}}getStructByName(e){let n;if(n=this.structs.get(e))return n;throw new Error(`Struct ${e} not found in model.`)}getStructFromRef(e,n){var r;let i;if(typeof e=="string"){const s=this.getStructByName(e);return n!==void 0?new br(s.fieldDef,n,(r=s.parent)!==null&&r!==void 0?r:{model:this}):s}else if(e.type==="struct")i=e;else throw new Error("Broken for now");return new br(i,n,{model:this})}loadQuery(e,n,r=!1,i=!1){const s="";n||(n=new l2(!0,void 0));const o={type:"turtle",name:"ignoreme",pipeline:e.pipeline,filterList:e.filterList},u=As.makeQuery(o,this.getStructFromRef(e.structRef,e.sourceArguments),n,i),a=u.generateSQLFromPipeline(n);if(r&&u.parent.dialect.hasFinalStage){const l=(0,Ze.getPhysicalFields)(a.outputStruct).map(c=>u.parent.dialect.sqlMaybeQuoteIdentifier(c.name));a.lastStageName=n.addStage(u.parent.dialect.sqlFinalStage(a.lastStageName,l))}return{lastStageName:a.lastStageName,malloy:s,stageWriter:n,structs:[a.outputStruct],connectionName:u.parent.connectionName}}compileQuery(e,n=!0){const i=this.loadQuery(e,void 0,n,!1),s=typeof e.structRef=="string"?e.structRef:e.structRef.type==="struct"?e.structRef.as||e.structRef.name:"(need to figure this out)";return n&&this.dialect.hasFinalStage&&(i.lastStageName=i.stageWriter.addStage(this.dialect.sqlFinalStage(i.lastStageName,[]))),{lastStageName:i.lastStageName,malloy:i.malloy,sql:i.stageWriter.generateSQLStages(),structs:i.structs,sourceExplore:s,sourceFilters:e.filterList,queryName:e.name,connectionName:i.connectionName,annotation:e.annotation}}async searchIndex(e,n,r,i=1e3,s=void 0){if(!e.canPersist())return;const o=this.getStructByName(n);let u=[];for(const[y,E]of o.nameMap)E instanceof br||cr(E)&&E.includeInWildcard()&&u.push({type:"fieldref",path:[y]});u=u.sort((y,E)=>y.path[0].localeCompare(E.path[0]));const a={structRef:n,pipeline:[{type:"index",indexFields:u,sample:o.dialect.defaultSampling}]},l=o.dialect.sqlMaybeQuoteIdentifier("fieldName"),c=o.dialect.sqlMaybeQuoteIdentifier("fieldPath"),f=o.dialect.sqlMaybeQuoteIdentifier("fieldValue"),x=o.dialect.sqlMaybeQuoteIdentifier("fieldType"),h=o.dialect.sqlMaybeQuoteIdentifier("weight");let p=this.exploreSearchSQLMap.get(n);p===void 0&&(p=this.compileQuery(a,!1).sql,this.exploreSearchSQLMap.set(n,p));let m=`SELECT
377
+ `)),this.resultStage}getResultStructDef(){const e={type:"struct",name:this.resultStage||"result",dialect:this.parent.fieldDef.dialect,fields:[{type:"string",name:"fieldName"},{type:"string",name:"fieldPath"},{type:"string",name:"fieldValue"},{type:"string",name:"fieldType"},{type:"number",name:"weight",numberType:"integer"}],structRelationship:{type:"basetable",connectionName:this.parent.connectionName},structSource:{type:"query_result"}};return this.parent.fieldDef.modelAnnotation&&(e.modelAnnotation=this.parent.fieldDef.modelAnnotation),e}}class br extends r${constructor(e,n,r){if(super(e),this.sourceArguments=n,this.nameMap=new Map,this._arguments=void 0,this.setParent(r),"model"in r)if(this.model=r.model,this.pathAliasMap=new Map,e.structRelationship.type==="basetable")this.connectionName=e.structRelationship.connectionName;else throw new Error("All root StructDefs should be a baseTable");else this.model=this.getModel(),this.pathAliasMap=this.root().pathAliasMap,this.connectionName=this.root().connectionName;this.fieldDef=e,this.dialect=(0,tce.getDialect)(this.fieldDef.dialect),this.addFieldsFromFieldList(this.fieldDef.fields)}resolveParentParameterReferences(e){return{...e,value:e.value===null?null:(0,an.exprMap)(e.value,n=>{if(n.node==="parameter"){if(this.parent===void 0)throw new Error("No parent from which to retrieve parameter value");const r=this.parent.arguments()[n.path[0]],i=this.parent.resolveParentParameterReferences(r);if(i.value===null)throw new Error("Invalid parameter value");return i.value}return n})}}arguments(){var e;if(this._arguments!==void 0)return this._arguments;this._arguments={};const n=(e=this.fieldDef.parameters)!==null&&e!==void 0?e:{};for(const i in n)this._arguments[i]=n[i];const r={...this.fieldDef.arguments,...this.sourceArguments};for(const i in r){const s=r[i];this._arguments[i]=this.resolveParentParameterReferences(s)}return this._arguments}addFieldsFromFieldList(e){for(const n of e){const r=(0,Ze.getIdentifier)(n);switch(n.type){case"struct":{this.addFieldToNameMap(r,new br(n,void 0,{struct:this}));break}case"turtle":{this.addFieldToNameMap(r,As.makeQuery(n,this,void 0,!1));break}default:this.addFieldToNameMap(r,this.makeQueryField(n))}}this.nameMap.has("__distinct_key")||this.addFieldToNameMap("__distinct_key",new cce({type:"string",name:"__distinct_key"},this))}getAliasIdentifier(){const e=this.getFullOutputName(),n=this.pathAliasMap.get(e);if(n===void 0){const r=Array.from(this.pathAliasMap.values()),i=rce((0,Ze.getIdentifier)(this.fieldDef));let s=`${i}_0`,o=1;for(;r.includes(s)&&o<1e3;)o++,s=`${i}_${o}`;if(o<1e3)return this.pathAliasMap.set(e,s),s;throw new Error("Internal Error: cannot create unique alias name")}else return n}getSQLIdentifier(){return this.unnestWithNumbers()&&this.parent!==void 0?this.parent.getSQLIdentifier()+"."+(0,Ze.getIdentifier)(this.fieldDef)+`[${this.getIdentifier()}.__row_id]`:this.getIdentifier()}getIdentifier(){return this.fieldDef.structRelationship.type==="basetable"?"base":this.fieldDef.structRelationship.type==="inline"&&this.parent?this.parent.getSQLIdentifier()+"."+super.getIdentifier():this.getAliasIdentifier()}getFullOutputName(){return this.parent?this.parent.getFullOutputName()+(0,Ze.getIdentifier)(this.fieldDef)+".":""}needsSymetricCalculation(e){const n=this.getJoinableParent().getIdentifier(),r=e.root().joins.get(n);if(r)return!r.leafiest;throw new Error(`Join ${n} not found in result set`)}unnestWithNumbers(){return this.dialect.unnestWithNumbers&&this.fieldDef.structRelationship.type==="nested"}getJoinableParent(){if(this.fieldDef.structRelationship.type==="inline"){if(this.parent)return this.parent.getJoinableParent();throw new Error("Internal Error: inline struct cannot be root")}return this}addFieldToNameMap(e,n){if(this.nameMap.has(e))throw new Error(`Redefinition of ${e}`);this.nameMap.set(e,n)}getPrimaryKeyField(e){let n;if(n=this.primaryKey())return n;throw new Error(`Missing primary key for ${e}`)}resolveQueryFields(){if(this.fieldDef.structSource.type==="query"){const e=this.model.loadQuery(this.fieldDef.structSource.query,void 0).structs.pop();if(!e)throw new Error("Internal Error, query didn't produce a struct");const n={...this.fieldDef};for(const r of e.fields){let i;this.nameMap.has(i=(0,Ze.getIdentifier)(r))||(n.fields.push(r),this.nameMap.set(i,this.makeQueryField(r)))}this.fieldDef=n,!this.fieldDef.primaryKey&&e.primaryKey&&(this.fieldDef.primaryKey=e.primaryKey)}for(const[,e]of this.nameMap)e instanceof br&&e.resolveQueryFields()}getModel(){if(this.model)return this.model;if(this.parent===void 0)throw new Error("Expected this query struct to have a parent, as no model was present.");return this.parent.getModel()}setParent(e){"struct"in e&&(this.parent=e.struct),"model"in e?this.model=e.model:this.model=this.getModel()}makeQueryField(e){switch(e.type){case"string":return new sce(e,this);case"date":return new sT(e,this);case"timestamp":return new oT(e,this);case"number":return new oce(e,this);case"boolean":return new iT(e,this);case"json":return new uce(e,this);case"sql native":return new ace(e,this);case"turtle":return new u$(e,this);default:throw new Error(`unknown field definition ${JSON.stringify(e)}`)}}structSourceSQL(e){switch(this.fieldDef.structSource.type){case"table":{const n=this.fieldDef.structSource.tablePath;return this.dialect.quoteTablePath(n)}case"sql":if(this.fieldDef.structSource.method==="nested"||this.fieldDef.structSource.method==="lastStage")return this.fieldDef.name;if(this.fieldDef.structSource.method==="subquery")return`(${this.fieldDef.structSource.sqlBlock.selectStr})`;throw new Error("Internal Error: Unknown structSource type 'sql' method");case"nested":return"UNNEST(this.fieldDef.name)";case"inline":return"";case"query":{const n=(0,Ze.getIdentifier)(this.fieldDef);if(n.includes("cache")){const r=new l2(!0,e);return this.model.loadQuery(this.fieldDef.structSource.query,r,!1,!1),r.addPDT(n,this.dialect)}else return this.model.loadQuery(this.fieldDef.structSource.query,e,!1,!0).lastStageName}default:throw new Error(`unknown structSource ${this.fieldDef}`)}}root(){return this.parent===void 0?this:this.parent.root()}primaryKey(){if(this.fieldDef.primaryKey)return this.getDimensionByName([this.fieldDef.primaryKey])}getChildByName(e){return this.nameMap.get(e)}getFieldByName(e){return e.reduce((n,r)=>{const i=n.getChildByName(r);if(i===void 0)throw new Error(e.length===1?`'${r}' not found`:`'${r}' not found in '${e.join(".")}'`);return i},this)}getQueryFieldByName(e){const n=this.getFieldByName(e);if(n instanceof br)throw new Error(`Cannot reference ${e} as a scalar'`);return n}getQueryFieldReference(e,n){const r=this.getQueryFieldByName(e);if(n!==void 0){const i={...r.fieldDef};return i.annotation=n,this.makeQueryField(i)}return r}getDimensionOrMeasureByName(e){const n=this.getFieldByName(e);if(n instanceof Cr)return n;throw new Error(`${e} is not of type a scalar'`)}getDimensionByName(e){const n=this.getFieldByName(e);if(n instanceof Cr&&cr(n))return n;throw new Error(`${e} is not of type a scalar'`)}getStructByName(e){const n=this.getFieldByName(e);if(n instanceof br)return n;throw new Error(`Error: Path to structure not found '${e.join(".")}'`)}getDistinctKey(){if(this.fieldDef.structRelationship.type!=="inline")return this.getDimensionByName(["__distinct_key"]);if(this.parent)return this.parent.getDistinctKey();throw new Error("Internal Error. inline struct can not be top level")}applyStructFiltersToTurtleDef(e){let n=e.pipeline;const r=e.annotation,i=e.filterList||[];return n=structuredClone(n),n[0].filterList=i.concat(n[0].filterList||[],this.fieldDef.filterList||[]),{type:"turtle",name:e.name,pipeline:n,annotation:r,location:e.location}}}class a${constructor(e){this.dialect=new nce.StandardSQLDialect,this.modelDef=void 0,this.structs=new Map,this.exploreSearchSQLMap=new Map,e&&this.loadModelFromDef(e)}loadModelFromDef(e){this.modelDef=e;for(const n of Object.values(this.modelDef.contents)){let r;if(n.type==="struct")r=new br(n,void 0,{model:this}),this.structs.set((0,Ze.getIdentifier)(n),r),r.resolveQueryFields();else if(n.type!=="query")throw new Error("Internal Error: Unknown structure type")}}getStructByName(e){let n;if(n=this.structs.get(e))return n;throw new Error(`Struct ${e} not found in model.`)}getStructFromRef(e,n){var r;let i;if(typeof e=="string"){const s=this.getStructByName(e);return n!==void 0?new br(s.fieldDef,n,(r=s.parent)!==null&&r!==void 0?r:{model:this}):s}else if(e.type==="struct")i=e;else throw new Error("Broken for now");return new br(i,n,{model:this})}loadQuery(e,n,r=!1,i=!1){const s="";n||(n=new l2(!0,void 0));const o={type:"turtle",name:"ignoreme",pipeline:e.pipeline,filterList:e.filterList},u=As.makeQuery(o,this.getStructFromRef(e.structRef,e.sourceArguments),n,i),a=u.generateSQLFromPipeline(n);if(r&&u.parent.dialect.hasFinalStage){const l=(0,Ze.getPhysicalFields)(a.outputStruct).map(c=>u.parent.dialect.sqlMaybeQuoteIdentifier(c.name));a.lastStageName=n.addStage(u.parent.dialect.sqlFinalStage(a.lastStageName,l))}return{lastStageName:a.lastStageName,malloy:s,stageWriter:n,structs:[a.outputStruct],connectionName:u.parent.connectionName}}compileQuery(e,n=!0){const i=this.loadQuery(e,void 0,n,!1),s=typeof e.structRef=="string"?e.structRef:e.structRef.type==="struct"?e.structRef.as||e.structRef.name:"(need to figure this out)";return n&&this.dialect.hasFinalStage&&(i.lastStageName=i.stageWriter.addStage(this.dialect.sqlFinalStage(i.lastStageName,[]))),{lastStageName:i.lastStageName,malloy:i.malloy,sql:i.stageWriter.generateSQLStages(),structs:i.structs,sourceExplore:s,sourceFilters:e.filterList,queryName:e.name,connectionName:i.connectionName,annotation:e.annotation}}async searchIndex(e,n,r,i=1e3,s=void 0){if(!e.canPersist())return;const o=this.getStructByName(n);let u=[];for(const[y,E]of o.nameMap)E instanceof br||cr(E)&&E.includeInWildcard()&&u.push({type:"fieldref",path:[y]});u=u.sort((y,E)=>y.path[0].localeCompare(E.path[0]));const a={structRef:n,pipeline:[{type:"index",indexFields:u,sample:o.dialect.defaultSampling}]},l=o.dialect.sqlMaybeQuoteIdentifier("fieldName"),c=o.dialect.sqlMaybeQuoteIdentifier("fieldPath"),f=o.dialect.sqlMaybeQuoteIdentifier("fieldValue"),x=o.dialect.sqlMaybeQuoteIdentifier("fieldType"),h=o.dialect.sqlMaybeQuoteIdentifier("weight");let p=this.exploreSearchSQLMap.get(n);p===void 0&&(p=this.compileQuery(a,!1).sql,this.exploreSearchSQLMap.set(n,p));let m=`SELECT
378
378
  ${l},
379
379
  ${c},
380
380
  ${f},