@malloydata/render 0.0.188-dev240923145123 → 0.0.188-dev240924155145

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.
@@ -5819,9 +5819,9 @@ class Fr extends Mz {
5819
5819
  }
5820
5820
  getQueryFieldReference(e, n) {
5821
5821
  const r = this.getQueryFieldByName(e);
5822
- if (n !== void 0) {
5822
+ if (n) {
5823
5823
  const i = { ...r.fieldDef };
5824
- return i.annotation = n, this.makeQueryField(i);
5824
+ i.annotation = n, r.fieldDef = i;
5825
5825
  }
5826
5826
  return r;
5827
5827
  }
@@ -374,7 +374,7 @@ FROM ${n}
374
374
  FROM ${h}
375
375
  `),this.resultStage}}class gce extends Es{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 mce extends Es{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 pce({...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,ece.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,Es.makeQuery(n,this,void 0,!1));break}default:this.addFieldToNameMap(r,this.makeQueryField(n))}}this.nameMap.has("__distinct_key")||this.addFieldToNameMap("__distinct_key",new lce({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=nce((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 ice(e,this);case"date":return new iT(e,this);case"timestamp":return new sT(e,this);case"number":return new sce(e,this);case"boolean":return new rT(e,this);case"json":return new oce(e,this);case"sql native":return new uce(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 a2(!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 tce.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 a2(!0,void 0));const o={type:"turtle",name:"ignoreme",pipeline:e.pipeline,filterList:e.filterList},u=Es.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,ece.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,Es.makeQuery(n,this,void 0,!1));break}default:this.addFieldToNameMap(r,this.makeQueryField(n))}}this.nameMap.has("__distinct_key")||this.addFieldToNameMap("__distinct_key",new lce({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=nce((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 ice(e,this);case"date":return new iT(e,this);case"timestamp":return new sT(e,this);case"number":return new sce(e,this);case"boolean":return new rT(e,this);case"json":return new oce(e,this);case"sql native":return new uce(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 a2(!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 tce.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 a2(!0,void 0));const o={type:"turtle",name:"ignoreme",pipeline:e.pipeline,filterList:e.filterList},u=Es.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},
@@ -6693,9 +6693,9 @@ class Ir extends NQ {
6693
6693
  }
6694
6694
  getQueryFieldReference(e, n) {
6695
6695
  const r = this.getQueryFieldByName(e);
6696
- if (n !== void 0) {
6696
+ if (n) {
6697
6697
  const i = { ...r.fieldDef };
6698
- return i.annotation = n, this.makeQueryField(i);
6698
+ i.annotation = n, r.fieldDef = i;
6699
6699
  }
6700
6700
  return r;
6701
6701
  }
@@ -92053,8 +92053,8 @@ function RB(t, e, n, r) {
92053
92053
  if (v) {
92054
92054
  const K = L.domain().at(1), ee = L.domain().at(0), Y = WJ(), re = Y.format(",")(ee), se = Y.format(",")(K);
92055
92055
  h = Math.max(
92056
- F6(re, "Inter, sans-serif 12px"),
92057
- F6(se, "Inter, sans-serif 12px")
92056
+ F6(re, "10px Inter, sans-serif") + 4,
92057
+ F6(se, "10px Inter, sans-serif") + 4
92058
92058
  ) + 5 + 31;
92059
92059
  const k = Math.ceil(a / 40), W = L.ticks(k).at(-1);
92060
92060
  if (W < K) {
@@ -92063,9 +92063,9 @@ function RB(t, e, n, r) {
92063
92063
  }
92064
92064
  }
92065
92065
  if (A) {
92066
- const K = fu(i), ee = e.fields[K].maxString, Y = F6(ee, "Inter, sans-serif 12px"), re = 0.3;
92066
+ const K = fu(i), ee = e.fields[K].maxString, Y = F6(ee, "10px Inter, sans-serif") + 4, re = 1;
92067
92067
  E = 26, x = Math.min(Y, re * a), y = x;
92068
- const se = e.fields[K].values.size, D = se <= 20 ? se : _.maxRecordCt, k = (u - h) / D;
92068
+ const se = e.fields[K].values.size, D = se <= 20 ? se : _.maxRecordCt, k = u / D;
92069
92069
  (k > x || k > Y) && (p = 0, y = k, m = void 0, g = "top", E = 22, x = 14);
92070
92070
  }
92071
92071
  const H = a + x + E, G = Math.ceil(H / RE) * RE;