@malloydata/render 0.0.265-dev250416204239 → 0.0.265-dev250417022335
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 +10151 -9910
- package/dist/module/index.umd.js +241 -241
- package/dist/register/register.mjs +3687 -3687
- package/dist/register/register.umd.js +24 -24
- package/dist/webcomponent/malloy-render.mjs +3687 -3687
- package/dist/webcomponent/malloy-render.umd.js +24 -24
- package/package.json +5 -5
|
@@ -1437,15 +1437,15 @@ Use (?: … ) instead`);if(!ee.lineBreaks&&j.test(`
|
|
|
1437
1437
|
`))throw new Error("Rule should declare lineBreaks: "+j);de.push(l(w))}}var z=U&&U.fallback,L=i&&!z?"ym":"gm",P=i||z?"":"|";X===!0&&(L+="u");var q=new RegExp(c(de)+P,L);return{regexp:q,groups:xe,fast:V,error:U||E}}function _(D){var $=A(y(D));return new b({start:$},"start")}function v(D,$,U){var V=D&&(D.push||D.next);if(V&&!U[V])throw new Error("Missing state '"+V+"' (in token '"+D.defaultType+"' of state '"+$+"')");if(D&&D.pop&&+D.pop!=1)throw new Error("pop must be 1 (in token '"+D.defaultType+"' of state '"+$+"')")}function C(D,$){var U=D.$all?y(D.$all):[];delete D.$all;var V=Object.getOwnPropertyNames(D);$||($=V[0]);for(var Q=Object.create(null),X=0;X<V.length;X++){var xe=V[X];Q[xe]=y(D[xe]).concat(U)}for(var X=0;X<V.length;X++)for(var xe=V[X],de=Q[xe],ie=Object.create(null),ee=0;ee<de.length;ee++){var J=de[ee];if(J.include){var ce=[ee,1];if(J.include!==xe&&!ie[J.include]){ie[J.include]=!0;var N=Q[J.include];if(!N)throw new Error("Cannot include nonexistent state '"+J.include+"' (in state '"+xe+"')");for(var F=0;F<N.length;F++){var w=N[F];de.indexOf(w)===-1&&ce.push(w)}}de.splice.apply(de,ce),ee--}}for(var j=Object.create(null),X=0;X<V.length;X++){var xe=V[X];j[xe]=A(Q[xe],!0)}for(var X=0;X<V.length;X++){for(var Y=V[X],z=j[Y],L=z.groups,ee=0;ee<L.length;ee++)v(L[ee],Y,j);for(var P=Object.getOwnPropertyNames(z.fast),ee=0;ee<P.length;ee++)v(z.fast[P[ee]],Y,j)}return new b(j,$)}function S(D){for(var $=typeof Map<"u",U=$?new Map:Object.create(null),V=Object.getOwnPropertyNames(D),Q=0;Q<V.length;Q++){var X=V[Q],xe=D[X],de=Array.isArray(xe)?xe:[xe];de.forEach(function(ie){if(typeof ie!="string")throw new Error("keyword must be string (in keyword '"+X+"')");$?U.set(ie,X):U[ie]=X})}return function(ie){return $?U.get(ie):U[ie]}}var b=function(D,$){this.startState=$,this.states=D,this.buffer="",this.stack=[],this.reset()};b.prototype.reset=function(D,$){return this.buffer=D||"",this.index=0,this.line=$?$.line:1,this.col=$?$.col:1,this.queuedToken=$?$.queuedToken:null,this.queuedText=$?$.queuedText:"",this.queuedThrow=$?$.queuedThrow:null,this.setState($?$.state:this.startState),this.stack=$&&$.stack?$.stack.slice():[],this},b.prototype.save=function(){return{line:this.line,col:this.col,state:this.state,stack:this.stack.slice(),queuedToken:this.queuedToken,queuedText:this.queuedText,queuedThrow:this.queuedThrow}},b.prototype.setState=function(D){if(!(!D||this.state===D)){this.state=D;var $=this.states[D];this.groups=$.groups,this.error=$.error,this.re=$.regexp,this.fast=$.fast}},b.prototype.popState=function(){this.setState(this.stack.pop())},b.prototype.pushState=function(D){this.stack.push(this.state),this.setState(D)};var R=i?function(D,$){return D.exec($)}:function(D,$){var U=D.exec($);return U[0].length===0?null:U};b.prototype._getGroup=function(D){for(var $=this.groups.length,U=0;U<$;U++)if(D[U+1]!==void 0)return this.groups[U];throw new Error("Cannot find token type for matched text")};function O(){return this.value}if(b.prototype.next=function(){var D=this.index;if(this.queuedGroup){var $=this._token(this.queuedGroup,this.queuedText,D);return this.queuedGroup=null,this.queuedText="",$}var U=this.buffer;if(D!==U.length){var xe=this.fast[U.charCodeAt(D)];if(xe)return this._token(xe,U.charAt(D),D);var V=this.re;V.lastIndex=D;var Q=R(V,U),X=this.error;if(Q==null)return this._token(X,U.slice(D,U.length),D);var xe=this._getGroup(Q),de=Q[0];return X.fallback&&Q.index!==D?(this.queuedGroup=xe,this.queuedText=de,this._token(X,U.slice(D,Q.index),D)):this._token(xe,de,D)}},b.prototype._token=function(D,$,U){var V=0;if(D.lineBreaks){var Q=/\n/g,X=1;if($===`
|
|
1438
1438
|
`)V=1;else for(;Q.exec($);)V++,X=Q.lastIndex}var xe={type:typeof D.type=="function"&&D.type($)||D.defaultType,value:typeof D.value=="function"?D.value($):$,text:$,toString:O,offset:U,lineBreaks:V,line:this.line,col:this.col},de=$.length;if(this.index+=de,this.line+=V,V!==0?this.col=de-X+1:this.col+=de,D.shouldThrow){var ie=new Error(this.formatError(xe,"invalid syntax"));throw ie}return D.pop?this.popState():D.push?this.pushState(D.push):D.next&&this.setState(D.next),xe},typeof Symbol<"u"&&Symbol.iterator){var B=function(D){this.lexer=D};B.prototype.next=function(){var D=this.lexer.next();return{value:D,done:!D}},B.prototype[Symbol.iterator]=function(){return this},b.prototype[Symbol.iterator]=function(){return new B(this)}}return b.prototype.formatError=function(D,$){if(D==null)var U=this.buffer.slice(this.index),D={text:U,offset:this.index,lineBreaks:U.indexOf(`
|
|
1439
1439
|
`)===-1?0:1,line:this.line,col:this.col};var V=2,Q=Math.max(D.line-V,1),X=D.line+V,xe=String(X).length,de=h(this.buffer,this.line-D.line+V+1).slice(0,5),ie=[];ie.push($+" at line "+D.line+" col "+D.col+":"),ie.push("");for(var ee=0;ee<de.length;ee++){var J=de[ee],ce=Q+ee;ie.push(x(String(ce),xe)+" "+J),ce===D.line&&ie.push(x("",xe+D.col+1)+"^")}return ie.join(`
|
|
1440
|
-
`)},b.prototype.clone=function(){return new b(this.states,this.state)},b.prototype.has=function(D){return!0},{compile:_,states:C,error:Object.freeze({error:!0}),fallback:Object.freeze({fallback:!0}),keywords:S}})})(dle);var yB=dle.exports,Qt={};Object.defineProperty(Qt,"__esModule",{value:!0}),Qt.mkUnits=Qt.timeLiteral=Qt.joinTemporal=Qt.temporalNot=Qt.numNot=Qt.mkValues=Qt.mkRange=Qt.joinNumbers=Qt.conjoin=Qt.matchOp=Qt.escape=Qt.unescape=Qt.maybeNot=void 0;const Ma=On;function Ret(t){const[e,r]=t;return e&&r&&(0,Ma.isStringFilter)(r)?{...r,not:!0}:r}Qt.maybeNot=Ret;function rE(t){return t.replace(/\\(.)/g,"$1")}Qt.unescape=rE;function Det(t){const e=t.toLowerCase();return e==="null"||e==="empty"?"\\"+t:t.replace(/([,; |()\\%_-])/g,"\\$1")}Qt.escape=Det;function L4(t){let e=!1,r=!1,i=0,s=!1;const o=t.length;for(let u=0;u<o;u+=1){const a=t[u];if(a===" "||a===" "){i+=1;continue}i=0,a==="%"?(s=!0,u===0&&(e=!0),r=!0):(r=!1,a==="\\"?u+=1:a==="_"&&(s=!0))}return{hasLike:s,percentEnd:r&&o>1,percentStart:e&&o>1,endSpace:i}}function Oet(t){let e=t.trimStart();const{hasLike:r,percentEnd:i,percentStart:s,endSpace:o}=L4(e);if(o>0&&(e=e.slice(0,-o)),r){if(s&&i){const u=e.slice(1,-1);if(!L4(u).hasLike&&u.length>0)return{operator:"contains",values:[rE(u)]}}else if(i){const u=e.slice(0,-1);if(!L4(u).hasLike)return{operator:"starts",values:[rE(u)]}}else if(s){const u=e.slice(1);if(!L4(u).hasLike)return{operator:"ends",values:[rE(u)]}}return{operator:"~",escaped_values:[e]}}return e.toLowerCase()==="null"||e==="NULL"?{operator:"null"}:e==="empty"||e==="EMPTY"?{operator:"empty"}:{operator:"=",values:[rE(e)]}}Qt.matchOp=Oet;function EB(t,e){var r,i;return t.operator===e.operator&&((r=t.not)!==null&&r!==void 0?r:!1)===((i=e.not)!==null&&i!==void 0?i:!1)}function Fet(t,e,r){if((0,Ma.isStringFilter)(t)&&(0,Ma.isStringFilter)(r)){if(e===","){if(t.operator==="~"&&EB(t,r))return{...t,escaped_values:[...t.escaped_values,...r.escaped_values]};if((0,Ma.isStringCondition)(t)&&EB(t,r))return{...t,values:[...t.values,...r.values]}}const i=e===","?",":e==="|"?"or":e===";"?"and":void 0;if(i)return t.operator===i?{...t,members:[...t.members,r]}:{operator:i,members:[t,r]}}return null}Qt.conjoin=Fet;function wet(t,e,r){if((0,Ma.isNumberFilter)(t)&&(0,Ma.isNumberFilter)(r)){if(e==="or"&&t.operator==="="&&EB(t,r)){const i={operator:"=",values:[...t.values,...r.values]};return t.not&&(i.not=!0),i}if(e==="and"||e==="or")return t.operator===e?{...t,members:[...t.members,r]}:{operator:e,members:[t,r]}}return null}Qt.joinNumbers=wet;function Net(t,e,r,i){return{operator:"range",startValue:e,startOperator:t==="("?">":">=",endValue:r,endOperator:i===")"?"<":"<="}}Qt.mkRange=Net;function Let(t,e){return{values:[t,...e]}}Qt.mkValues=Let;function Iet(t,e){return(0,Ma.isNumberFilter)(t)&&e?t.operator==="="?{operator:"!=",values:t.values}:t.operator==="!="?{operator:"=",values:t.values}:{...t,not:!0}:t}Qt.numNot=Iet;function $et(t,e){return(0,Ma.isTemporalFilter)(t)&&e?{...t,not:!0}:t}Qt.temporalNot=$et;function Bet(t,e,r){return(0,Ma.isTemporalFilter)(t)&&(0,Ma.isTemporalFilter)(r)&&(e==="and"||e==="or")?t.operator===e?{...t,members:[...t.members,r]}:{operator:e,members:[t,r]}:null}Qt.joinTemporal=Bet;function ket(t,e){const r={moment:"literal",literal:t};return e&&(r.units=e),r}Qt.timeLiteral=ket;function Met(t){switch(t.toLowerCase()){case"second":case"seconds":return"second";case"minute":case"minutes":return"minute";case"hour":case"hours":return"hour";case"day":case"days":return"day";case"week":case"weeks":return"week";case"month":case"months":return"month";case"quarter":case"quarters":return"quarter";case"year":case"years":return"year"}}Qt.mkUnits=Met;var Pet=T&&T.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(gB,"__esModule",{value:!0});function Uet(t){return t[0]}const hle=Pet(yB),A2=Qt,kn=hle.default.compile({WS:/[ \t]+/,id:{match:/[a-zA-Z]+/,type:hle.default.keywords({AND:"and",OR:"or",NOT:"not",NULL_KW:"null",TO:"to"})},oparen:"(",cparen:")",obrack:"[",cbrack:"]",comma:",",op:/<=|>=|<|>/,ne:"!=",eq:"=",float:/-?(?:\d+)?\.\d+(?:[Ee][+-]?\d+)?/,numberE:/-?\d+[Ee][+-]?\d+/,integer:/-?\d+/}),jet=kn.next;kn.next=(t=>()=>{for(;;){const e=t.call(kn);if(e===void 0||e.type!=="WS")return e}})(jet);const qet={Lexer:kn,ParserRules:[{name:"numberFilter",symbols:["numberFilter","conjunction","numberUnary"],postprocess:([t,e,r])=>(0,A2.joinNumbers)(t,e[0].text,r)},{name:"numberFilter",symbols:["numberUnary"],postprocess:t=>t[0]},{name:"numberUnary$ebnf$1",symbols:[kn.has("NOT")?{type:"NOT"}:NOT],postprocess:Uet},{name:"numberUnary$ebnf$1",symbols:[],postprocess:()=>null},{name:"numberUnary",symbols:["numberUnary$ebnf$1","clause"],postprocess:([t,e])=>(0,A2.numNot)(e,t)},{name:"clause",symbols:[kn.has("NULL_KW")?{type:"NULL_KW"}:NULL_KW],postprocess:()=>({operator:"null"})},{name:"clause$ebnf$1",symbols:[]},{name:"clause$ebnf$1",symbols:["clause$ebnf$1","numberList"],postprocess:t=>t[0].concat([t[1]])},{name:"clause",symbols:["N","clause$ebnf$1"],postprocess:([t,e])=>({operator:"=",...(0,A2.mkValues)(t,e)})},{name:"clause$ebnf$2",symbols:[]},{name:"clause$ebnf$2",symbols:["clause$ebnf$2","numberList"],postprocess:t=>t[0].concat([t[1]])},{name:"clause",symbols:[kn.has("eq")?{type:"eq"}:eq,"N","clause$ebnf$2"],postprocess:([t,e,r])=>({operator:"=",...(0,A2.mkValues)(e,r)})},{name:"clause$ebnf$3",symbols:[]},{name:"clause$ebnf$3",symbols:["clause$ebnf$3","numberList"],postprocess:t=>t[0].concat([t[1]])},{name:"clause",symbols:[kn.has("ne")?{type:"ne"}:ne,"N","clause$ebnf$3"],postprocess:([t,e,r])=>({operator:"!=",...(0,A2.mkValues)(e,r)})},{name:"clause",symbols:[kn.has("op")?{type:"op"}:op,"N"],postprocess:([t,e])=>({operator:t.text,values:[e]})},{name:"clause",symbols:[kn.has("oparen")?{type:"oparen"}:oparen,"numberFilter",kn.has("cparen")?{type:"cparen"}:cparen],postprocess:([t,e,r])=>({operator:"()",expr:e})},{name:"clause",symbols:["openInterval","N",kn.has("TO")?{type:"TO"}:TO,"N","closeInterval"],postprocess:([t,e,r,i,s])=>(0,A2.mkRange)(t[0].text,e,i,s[0].text)},{name:"numberList",symbols:[kn.has("comma")?{type:"comma"}:comma,"N"],postprocess:([t,e])=>e},{name:"closeInterval",symbols:[kn.has("cbrack")?{type:"cbrack"}:cbrack]},{name:"closeInterval",symbols:[kn.has("cparen")?{type:"cparen"}:cparen]},{name:"openInterval",symbols:[kn.has("obrack")?{type:"obrack"}:obrack]},{name:"openInterval",symbols:[kn.has("oparen")?{type:"oparen"}:oparen]},{name:"N$subexpression$1",symbols:[kn.has("float")?{type:"float"}:float]},{name:"N$subexpression$1",symbols:[kn.has("numberE")?{type:"numberE"}:numberE]},{name:"N$subexpression$1",symbols:[kn.has("integer")?{type:"integer"}:integer]},{name:"N",symbols:["N$subexpression$1"],postprocess:([t])=>t[0].text},{name:"conjunction",symbols:[kn.has("OR")?{type:"OR"}:OR]},{name:"conjunction",symbols:[kn.has("AND")?{type:"AND"}:AND]}],ParserStart:"numberFilter"};gB.default=qet;var _2={};Object.defineProperty(_2,"__esModule",{value:!0}),_2.run_parser=void 0;const Het=On;function Qet(t,e){try{e.feed(t);const i=e.finish()[0];return(0,Het.isFilterExpression)(i)?{parsed:i,log:[]}:{parsed:null,log:[]}}catch(r){let i=r.message,s=1,o=t.length;if(r.token){const u=r.token;s=u.col,o=u.text.length;const l=r.message.match(new RegExp("(?<=A ).*(?= based on:)","g")).map(c=>c.replace(/\s+token/i,""));i=`Unexpected ${u.type} token "${u.value}"`,l&&l.length&&(i+=` Tokens expected: ${[...new Set(l)]}`)}return{parsed:null,log:[{message:i,startIndex:s-1,endIndex:s-1+o-1,severity:"error"}]}}}_2.run_parser=Qet,function(t){var e=T&&T.__createBinding||(Object.create?function(c,f,x,h){h===void 0&&(h=x);var p=Object.getOwnPropertyDescriptor(f,x);(!p||("get"in p?!f.__esModule:p.writable||p.configurable))&&(p={enumerable:!0,get:function(){return f[x]}}),Object.defineProperty(c,h,p)}:function(c,f,x,h){h===void 0&&(h=x),c[h]=f[x]}),r=T&&T.__setModuleDefault||(Object.create?function(c,f){Object.defineProperty(c,"default",{enumerable:!0,value:f})}:function(c,f){c.default=f}),i=T&&T.__importStar||function(c){if(c&&c.__esModule)return c;var f={};if(c!=null)for(var x in c)x!=="default"&&Object.prototype.hasOwnProperty.call(c,x)&&e(f,c,x);return r(f,c),f},s=T&&T.__importDefault||function(c){return c&&c.__esModule?c:{default:c}};Object.defineProperty(t,"__esModule",{value:!0}),t.NumberFilterExpression=void 0;const o=On,u=i(mB),a=s(gB),l=_2;t.NumberFilterExpression={parse(c){if(c.match(/^\s*$/))return{parsed:null,log:[]};const f=new u.Parser(u.Grammar.fromCompiled(a.default)),x=(0,l.run_parser)(c,f);return x.parsed&&(0,o.isNumberFilter)(x.parsed)?{parsed:x.parsed,log:[]}:{parsed:null,log:x.log}},unparse(c){if(c===null)return"";switch(c.operator){case"=":return c.values.join(", ");case"!=":return"!= "+c.values.join(", ");case">":case"<":case"<=":case">=":return c.not?c.values.map(f=>c.operator==="="?`not ${f}`:`not ${c.operator} ${f}`).join(", "):c.values.map(f=>`${c.operator} ${f}`).join(", ");case"range":{const f=c.startOperator===">"?"(":"[",x=c.endOperator==="<"?")":"]",h=`${f}${c.startValue} to ${c.endValue}${x}`;return c.not?`not ${h}`:h}case"null":return c.not?"not null":"null";case"and":case"or":return c.members.map(f=>t.NumberFilterExpression.unparse(f)).join(` ${c.operator} `);case"()":{const f="("+t.NumberFilterExpression.unparse(c.expr)+")";return c.not?"not "+f:f}}return`no unparse for ${JSON.stringify(c)}`}}}(fle);var ple={},AB={},zet=T&&T.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(AB,"__esModule",{value:!0});function Wet(t){return t[0]}const Get=zet(yB),_B=Qt,Cu=Get.default.compile({WS:/[ \t]+/,comma:",",semi:";",or:"|",open:"(",close:")",minus:"-",matchStr:/(?:\\[^\n]|[^\n,;()|])+/}),Vet=Cu.next;Cu.next=(t=>()=>{for(;;){const e=t.call(Cu);if(e==null||e.type!=="WS")return e}})(Vet);const Yet={Lexer:Cu,ParserRules:[{name:"stringFilter",symbols:["stringFilter","conjunction","sfUnary"],postprocess:([t,e,r])=>(0,_B.conjoin)(t,e[0].text,r)},{name:"stringFilter",symbols:["sfUnary"],postprocess:t=>t[0]},{name:"sfUnary$ebnf$1",symbols:[Cu.has("minus")?{type:"minus"}:minus],postprocess:Wet},{name:"sfUnary$ebnf$1",symbols:[],postprocess:()=>null},{name:"sfUnary",symbols:["sfUnary$ebnf$1","clause"],postprocess:t=>(0,_B.maybeNot)(t)},{name:"parens",symbols:[Cu.has("open")?{type:"open"}:open,"stringFilter",Cu.has("close")?{type:"close"}:close],postprocess:([t,e,r])=>({operator:"()",expr:e})},{name:"clause",symbols:[Cu.has("matchStr")?{type:"matchStr"}:matchStr],postprocess:([t])=>(0,_B.matchOp)(t.text)},{name:"clause",symbols:["parens"],postprocess:t=>t[0]},{name:"conjunction",symbols:[Cu.has("comma")?{type:"comma"}:comma]},{name:"conjunction",symbols:[Cu.has("semi")?{type:"semi"}:semi]},{name:"conjunction",symbols:[Cu.has("or")?{type:"or"}:or]}],ParserStart:"stringFilter"};AB.default=Yet,function(t){var e=T&&T.__createBinding||(Object.create?function(f,x,h,p){p===void 0&&(p=h);var m=Object.getOwnPropertyDescriptor(x,h);(!m||("get"in m?!x.__esModule:m.writable||m.configurable))&&(m={enumerable:!0,get:function(){return x[h]}}),Object.defineProperty(f,p,m)}:function(f,x,h,p){p===void 0&&(p=h),f[p]=x[h]}),r=T&&T.__setModuleDefault||(Object.create?function(f,x){Object.defineProperty(f,"default",{enumerable:!0,value:x})}:function(f,x){f.default=x}),i=T&&T.__importStar||function(f){if(f&&f.__esModule)return f;var x={};if(f!=null)for(var h in f)h!=="default"&&Object.prototype.hasOwnProperty.call(f,h)&&e(x,f,h);return r(x,f),x},s=T&&T.__importDefault||function(f){return f&&f.__esModule?f:{default:f}};Object.defineProperty(t,"__esModule",{value:!0}),t.StringFilterExpression=void 0;const o=On,u=i(mB),a=s(AB),l=Qt,c=_2;t.StringFilterExpression={parse(f){if(f.match(/^\s*$/))return{parsed:null,log:[]};const x=new u.Parser(u.Grammar.fromCompiled(a.default)),h=(0,c.run_parser)(f,x);return h.parsed&&(0,o.isStringFilter)(h.parsed)?{parsed:h.parsed,log:[]}:{parsed:null,log:h.log}},unparse(f){if(f===null)return"";switch(f.operator){case"=":return f.not?f.values.map(x=>"-"+(0,l.escape)(x)).join(", "):f.values.map(x=>(0,l.escape)(x)).join(", ");case"~":return f.not?f.escaped_values.map(x=>"-"+x).join(", "):f.escaped_values.join(", ");case"starts":return f.not?f.values.map(x=>"-"+(0,l.escape)(x)+"%").join(", "):f.values.map(x=>(0,l.escape)(x)+"%").join(", ");case"ends":return f.not?f.values.map(x=>"-%"+(0,l.escape)(x)).join(", "):f.values.map(x=>"%"+(0,l.escape)(x)).join(", ");case"contains":return f.not?f.values.map(x=>"-%"+(0,l.escape)(x)+"%").join(", "):f.values.map(x=>"%"+(0,l.escape)(x)+"%").join(", ");case"or":return f.members.map(x=>t.StringFilterExpression.unparse(x)).join(" | ");case"and":return f.members.map(x=>t.StringFilterExpression.unparse(x)).join("; ");case",":return f.members.map(x=>t.StringFilterExpression.unparse(x)).join(", ");case"()":{const x="("+t.StringFilterExpression.unparse(f.expr)+")";return f.not?"-"+x:x}case"null":return f.not?"-null":"null";case"empty":return f.not?"-empty":"empty"}}}}(ple);var mle={},vB={},Ket=T&&T.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(vB,"__esModule",{value:!0});function Jet(t){return t[0]}const gle=Ket(yB),Su=Qt,Xe=gle.default.compile({WS:/[ \t]+/,id:{match:/[a-zA-Z]+/,type:gle.default.keywords({AND:"and",OR:"or",NOT:"not",NULL_KW:"null",TO:"to",NOW:"now",LAST:"last",THIS:"this",NEXT:"next",AGO:"ago",FROM:"from",BEFORE:"before",AFTER:"after",FOR:"for",TODAY:"today",YESTERDAY:"yesterday",TOMORROW:"tomorrow",SECOND:"second",MINUTE:"minute",HOUR:"hour",DAY:"day",WEEK:"week",MONTH:"month",QUARTER:"quarter",YEAR:"year",SECONDS:"seconds",MINUTES:"minutes",HOURS:"hours",DAYS:"days",WEEKS:"weeks",MONTHS:"months",QUARTERS:"quarters",YEARS:"years",MONDAY:"monday",TUESDAY:"tuesday",WEDNESDAY:"wednesday",THURSDAY:"thursday",FRIDAY:"friday",SATURDAY:"saturday",SUNDAY:"sunday"})},oparen:"(",cparen:")",comma:",",literal:/\d\d\d\d-\d\d-\d\d[ Tt]\d\d:\d\d(?::\d\d(?:[.,]\d*)?)/,lit_week:/\d\d\d\d-\d\d-\d\d-[Ww][Kk]/,lit_quarter:/\d\d\d\d-[qQ][1234]/,lit_min:/\d\d\d\d-\d\d-\d\d[ Tt]\d\d:\d\d/,lit_hour:/\d\d\d\d-\d\d-\d\d[ Tt]\d\d/,lit_day:/\d\d\d\d-\d\d-\d\d/,lit_month:/\d\d\d\d-\d\d/,lit_year:/\d\d\d\d/,n:/\d+/}),Xet=Xe.next;Xe.next=(t=>()=>{for(;;){const e=t.call(Xe);if(e===void 0||e.type!=="WS")return e}})(Xet);const Zet={Lexer:Xe,ParserRules:[{name:"temporalFilter",symbols:["temporalFilter","conjunction","temporalUnary"],postprocess:([t,e,r])=>(0,Su.joinTemporal)(t,e[0].text,r)},{name:"temporalFilter",symbols:["temporalUnary"],postprocess:t=>t[0]},{name:"temporalUnary$ebnf$1",symbols:[Xe.has("NOT")?{type:"NOT"}:NOT],postprocess:Jet},{name:"temporalUnary$ebnf$1",symbols:[],postprocess:()=>null},{name:"temporalUnary",symbols:["temporalUnary$ebnf$1","clause"],postprocess:([t,e])=>(0,Su.temporalNot)(e,t)},{name:"duration",symbols:["number","unit"],postprocess:([t,e])=>({units:e,n:t})},{name:"number",symbols:[Xe.has("n")?{type:"n"}:n],postprocess:([t])=>t.text},{name:"number",symbols:[Xe.has("lityear")?{type:"lityear"}:lityear],postprocess:([t])=>t.text},{name:"unit$subexpression$1",symbols:[Xe.has("SECOND")?{type:"SECOND"}:SECOND]},{name:"unit$subexpression$1",symbols:[Xe.has("MINUTE")?{type:"MINUTE"}:MINUTE]},{name:"unit$subexpression$1",symbols:[Xe.has("HOUR")?{type:"HOUR"}:HOUR]},{name:"unit$subexpression$1",symbols:[Xe.has("DAY")?{type:"DAY"}:DAY]},{name:"unit$subexpression$1",symbols:[Xe.has("WEEK")?{type:"WEEK"}:WEEK]},{name:"unit$subexpression$1",symbols:[Xe.has("MONTH")?{type:"MONTH"}:MONTH]},{name:"unit$subexpression$1",symbols:[Xe.has("QUARTER")?{type:"QUARTER"}:QUARTER]},{name:"unit$subexpression$1",symbols:[Xe.has("YEAR")?{type:"YEAR"}:YEAR]},{name:"unit$subexpression$1",symbols:[Xe.has("SECONDS")?{type:"SECONDS"}:SECONDS]},{name:"unit$subexpression$1",symbols:[Xe.has("MINUTES")?{type:"MINUTES"}:MINUTES]},{name:"unit$subexpression$1",symbols:[Xe.has("HOURS")?{type:"HOURS"}:HOURS]},{name:"unit$subexpression$1",symbols:[Xe.has("DAYS")?{type:"DAYS"}:DAYS]},{name:"unit$subexpression$1",symbols:[Xe.has("WEEKS")?{type:"WEEKS"}:WEEKS]},{name:"unit$subexpression$1",symbols:[Xe.has("MONTHS")?{type:"MONTHS"}:MONTHS]},{name:"unit$subexpression$1",symbols:[Xe.has("QUARTERS")?{type:"QUARTERS"}:QUARTERS]},{name:"unit$subexpression$1",symbols:[Xe.has("YEARS")?{type:"YEARS"}:YEARS]},{name:"unit",symbols:["unit$subexpression$1"],postprocess:([t])=>(0,Su.mkUnits)(t[0].text)},{name:"clause",symbols:[Xe.has("NULL_KW")?{type:"NULL_KW"}:NULL_KW],postprocess:()=>({operator:"null"})},{name:"clause",symbols:["parens"],postprocess:t=>t[0]},{name:"clause",symbols:["duration"],postprocess:([t])=>({operator:"in_last",...t})},{name:"clause",symbols:[Xe.has("BEFORE")?{type:"BEFORE"}:BEFORE,"moment"],postprocess:([t,e])=>({operator:"before",before:e})},{name:"clause",symbols:[Xe.has("AFTER")?{type:"AFTER"}:AFTER,"moment"],postprocess:([t,e])=>({operator:"after",after:e})},{name:"clause",symbols:["moment",Xe.has("TO")?{type:"TO"}:TO,"moment"],postprocess:([t,e,r])=>({operator:"to",fromMoment:t,toMoment:r})},{name:"clause",symbols:["moment",Xe.has("FOR")?{type:"FOR"}:FOR,"duration"],postprocess:([t,e,r])=>({...r,operator:"for",begin:t})},{name:"clause$subexpression$1",symbols:[Xe.has("LAST")?{type:"LAST"}:LAST]},{name:"clause$subexpression$1",symbols:[Xe.has("NEXT")?{type:"NEXT"}:NEXT]},{name:"clause",symbols:["clause$subexpression$1","duration"],postprocess:([t,e])=>({operator:t[0].text,...e})},{name:"clause",symbols:["moment"],postprocess:([t])=>({operator:"in",in:t})},{name:"lastNextThis",symbols:[Xe.has("THIS")?{type:"THIS"}:THIS],postprocess:([t])=>t.text.toLowerCase()},{name:"lastNextThis",symbols:[Xe.has("NEXT")?{type:"NEXT"}:NEXT],postprocess:([t])=>t.text.toLowerCase()},{name:"lastNextThis",symbols:[Xe.has("LAST")?{type:"LAST"}:LAST],postprocess:([t])=>t.text.toLowerCase()},{name:"moment",symbols:[Xe.has("NOW")?{type:"NOW"}:NOW],postprocess:()=>({moment:"now"})},{name:"moment",symbols:["lastNextThis","unit"],postprocess:([t,e])=>({moment:t,units:e})},{name:"moment",symbols:[Xe.has("TODAY")?{type:"TODAY"}:TODAY],postprocess:()=>({moment:"today"})},{name:"moment",symbols:[Xe.has("YESTERDAY")?{type:"YESTERDAY"}:YESTERDAY],postprocess:()=>({moment:"yesterday"})},{name:"moment",symbols:[Xe.has("TOMORROW")?{type:"TOMORROW"}:TOMORROW],postprocess:()=>({moment:"tomorrow"})},{name:"moment",symbols:["duration",Xe.has("AGO")?{type:"AGO"}:AGO],postprocess:([t,e])=>({moment:"ago",...t})},{name:"moment",symbols:["duration",Xe.has("FROM")?{type:"FROM"}:FROM,Xe.has("NOW")?{type:"NOW"}:NOW],postprocess:([t,e])=>({moment:"from_now",...t})},{name:"moment",symbols:[Xe.has("NEXT")?{type:"NEXT"}:NEXT,"weekday"],postprocess:([t,e])=>({moment:e.toLowerCase(),which:"next"})},{name:"moment",symbols:[Xe.has("LAST")?{type:"LAST"}:LAST,"weekday"],postprocess:([t,e])=>({moment:e.toLowerCase(),which:"last"})},{name:"moment",symbols:["weekday"],postprocess:([t])=>({moment:t.toLowerCase(),which:"last"})},{name:"moment",symbols:["timeLiteral"],postprocess:t=>t[0]},{name:"timeLiteral",symbols:[Xe.has("literal")?{type:"literal"}:literal],postprocess:([t])=>(0,Su.timeLiteral)(t.text)},{name:"timeLiteral",symbols:[Xe.has("lit_day")?{type:"lit_day"}:lit_day],postprocess:([t])=>(0,Su.timeLiteral)(t.text,"day")},{name:"timeLiteral",symbols:[Xe.has("lit_min")?{type:"lit_min"}:lit_min],postprocess:([t])=>(0,Su.timeLiteral)(t.text,"minute")},{name:"timeLiteral",symbols:[Xe.has("lit_hour")?{type:"lit_hour"}:lit_hour],postprocess:([t])=>(0,Su.timeLiteral)(t.text,"hour")},{name:"timeLiteral",symbols:[Xe.has("lit_month")?{type:"lit_month"}:lit_month],postprocess:([t])=>(0,Su.timeLiteral)(t.text,"month")},{name:"timeLiteral",symbols:[Xe.has("lit_quarter")?{type:"lit_quarter"}:lit_quarter],postprocess:([t])=>(0,Su.timeLiteral)(t.text,"quarter")},{name:"timeLiteral",symbols:[Xe.has("lit_week")?{type:"lit_week"}:lit_week],postprocess:([t])=>(0,Su.timeLiteral)(t.text,"week")},{name:"timeLiteral",symbols:[Xe.has("lit_year")?{type:"lit_year"}:lit_year],postprocess:([t])=>(0,Su.timeLiteral)(t.text,"year")},{name:"weekday$subexpression$1",symbols:[Xe.has("MONDAY")?{type:"MONDAY"}:MONDAY]},{name:"weekday$subexpression$1",symbols:[Xe.has("TUESDAY")?{type:"TUESDAY"}:TUESDAY]},{name:"weekday$subexpression$1",symbols:[Xe.has("WEDNESDAY")?{type:"WEDNESDAY"}:WEDNESDAY]},{name:"weekday$subexpression$1",symbols:[Xe.has("THURSDAY")?{type:"THURSDAY"}:THURSDAY]},{name:"weekday$subexpression$1",symbols:[Xe.has("FRIDAY")?{type:"FRIDAY"}:FRIDAY]},{name:"weekday$subexpression$1",symbols:[Xe.has("SATURDAY")?{type:"SATURDAY"}:SATURDAY]},{name:"weekday$subexpression$1",symbols:[Xe.has("SUNDAY")?{type:"SUNDAY"}:SUNDAY]},{name:"weekday",symbols:["weekday$subexpression$1"],postprocess:([t])=>t[0].text},{name:"parens",symbols:[Xe.has("oparen")?{type:"oparen"}:oparen,"temporalFilter",Xe.has("cparen")?{type:"cparen"}:cparen],postprocess:([t,e,r])=>({operator:"()",expr:e})},{name:"conjunction",symbols:[Xe.has("OR")?{type:"OR"}:OR]},{name:"conjunction",symbols:[Xe.has("AND")?{type:"AND"}:AND]}],ParserStart:"temporalFilter"};vB.default=Zet,function(t){var e=T&&T.__createBinding||(Object.create?function(h,p,m,g){g===void 0&&(g=m);var y=Object.getOwnPropertyDescriptor(p,m);(!y||("get"in y?!p.__esModule:y.writable||y.configurable))&&(y={enumerable:!0,get:function(){return p[m]}}),Object.defineProperty(h,g,y)}:function(h,p,m,g){g===void 0&&(g=m),h[g]=p[m]}),r=T&&T.__setModuleDefault||(Object.create?function(h,p){Object.defineProperty(h,"default",{enumerable:!0,value:p})}:function(h,p){h.default=p}),i=T&&T.__importStar||function(h){if(h&&h.__esModule)return h;var p={};if(h!=null)for(var m in h)m!=="default"&&Object.prototype.hasOwnProperty.call(h,m)&&e(p,h,m);return r(p,h),p},s=T&&T.__importDefault||function(h){return h&&h.__esModule?h:{default:h}};Object.defineProperty(t,"__esModule",{value:!0}),t.TemporalFilterExpression=void 0;const o=On,u=s(vB),a=i(mB),l=_2;t.TemporalFilterExpression={parse(h){if(h.match(/^\s*$/))return{parsed:null,log:[]};const p=new a.Parser(a.Grammar.fromCompiled(u.default)),m=(0,l.run_parser)(h,p);return m.parsed&&(0,o.isTemporalFilter)(m.parsed)?{parsed:m.parsed,log:[]}:{parsed:null,log:m.log}},unparse(h){if(h===null)return"";switch(h.operator){case"null":return c(h,"null");case"in":return c(h,x(h.in));case"()":return"("+t.TemporalFilterExpression.unparse(h.expr)+")";case"in_last":return c(h,f(h));case"last":case"next":return c(h,`${h.operator} ${f(h)}`);case"before":return c(h,`before ${x(h.before)}`);case"after":return c(h,`after ${x(h.after)}`);case"to":return c(h,`${x(h.fromMoment)} to ${x(h.toMoment)}`);case"for":return c(h,`${x(h.begin)} for ${f(h)}`);case"or":return h.members.map(p=>t.TemporalFilterExpression.unparse(p)).join(" or ");case"and":return h.members.map(p=>t.TemporalFilterExpression.unparse(p)).join(" and ")}}};function c(h,p){return"not"in h&&h.not?"not "+p:p}function f(h){return h.n==="1"?`1 ${h.units}`:`${h.n} ${h.units}s`}function x(h){switch(h.moment){case"literal":return h.literal;case"now":case"today":case"yesterday":case"tomorrow":return h.moment;case"monday":case"tuesday":case"wednesday":case"thursday":case"friday":case"saturday":case"sunday":return h.which==="next"?"next "+h.moment:h.moment;case"this":case"next":case"last":return`${h.moment} ${h.units}`;case"ago":return`${f(h)} ago`;case"from_now":return`${f(h)} from now`}}}(mle),function(t){var e=T&&T.__createBinding||(Object.create?function(a,l,c,f){f===void 0&&(f=c);var x=Object.getOwnPropertyDescriptor(l,c);(!x||("get"in x?!l.__esModule:x.writable||x.configurable))&&(x={enumerable:!0,get:function(){return l[c]}}),Object.defineProperty(a,f,x)}:function(a,l,c,f){f===void 0&&(f=c),a[f]=l[c]}),r=T&&T.__exportStar||function(a,l){for(var c in a)c!=="default"&&!Object.prototype.hasOwnProperty.call(l,c)&&e(l,a,c)};Object.defineProperty(t,"__esModule",{value:!0}),t.TemporalFilterExpression=t.StringFilterExpression=t.NumberFilterExpression=t.BooleanFilterExpression=void 0,r(On,t);var i=N4;Object.defineProperty(t,"BooleanFilterExpression",{enumerable:!0,get:function(){return i.BooleanFilterExpression}});var s=fle;Object.defineProperty(t,"NumberFilterExpression",{enumerable:!0,get:function(){return s.NumberFilterExpression}});var o=ple;Object.defineProperty(t,"StringFilterExpression",{enumerable:!0,get:function(){return o.StringFilterExpression}});var u=mle;Object.defineProperty(t,"TemporalFilterExpression",{enumerable:!0,get:function(){return u.TemporalFilterExpression}})}(nE),function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.TemporalFilterCompiler=t.FilterCompilers=void 0;const e=nE,r=et,i=qr;function s(m){return m.replace(/([%_\\])/g,"\\$1")}function o(m){return m===">"?"<=":m==="<"?">=":m===">="?"<":">"}function u(m,g){const y=` OR ${g} IS NULL`;return m.length===1?`${m[0]}${y}`:`(${m.join(" AND ")})${y}`}t.FilterCompilers={compile(m,g,y,E){if(g===null)return"true";if(m==="string"&&(0,e.isStringFilter)(g))return t.FilterCompilers.stringCompile(g,y,E);if(m==="number"&&(0,e.isNumberFilter)(g))return t.FilterCompilers.numberCompile(g,y,E);if(m==="boolean"&&(0,e.isBooleanFilter)(g))return t.FilterCompilers.booleanCompile(g,y,E);if((m==="date"||m==="timestamp")&&(0,e.isTemporalFilter)(g))return t.FilterCompilers.temporalCompile(g,y,E,m);throw new Error("INTERNAL ERROR: No filter compiler for "+m)},numberCompile(m,g,y){switch(m.operator){case"!=":case"=":{const E=m.operator==="="&&m.not||m.operator==="!="&&!m.not,A=m.values.join(", ");return m.values.length===1?E?`${g} != ${A} OR ${g} IS NULL`:`${g} = ${A}`:E?`${g} NOT IN (${A}) OR ${g} IS NULL`:`${g} IN (${A})`}case">":case"<":case">=":case"<=":return m.values.map(E=>`${g} ${m.operator} ${E}`).join(m.not?" AND ":" OR ");case"range":{let E=m.startOperator,A=m.endOperator,_=" AND ";return m.not&&(E=o(E),A=o(A),_=" OR "),`${g} ${E} ${m.startValue} ${_} ${g} ${A} ${m.endValue}`}case"null":return m.not?`${g} IS NOT NULL`:`${g} IS NULL`;case"()":{const E="("+t.FilterCompilers.numberCompile(m.expr,g,y)+")";return m.not?`NOT ${E}`:E}case"and":case"or":return m.members.map(E=>t.FilterCompilers.numberCompile(E,g,y)).join(` ${m.operator.toUpperCase()} `)}},booleanCompile(m,g,y){switch(m.operator){case"false":return`${g} = false`;case"false_or_null":return`${g} IS NULL OR ${g} = false`;case"null":return m.not?`${g} IS NOT NULL`:`${g} IS NULL`;case"true":return g}},stringCompile(m,g,y){switch(m.operator){case"null":return m.not?`${g} IS NOT NULL`:`${g} IS NULL`;case"empty":return m.not?`COALESCE(${g},'') != ''`:`COALESCE(${g},'') = ''`;case"=":{if(m.values.length===1){const A=m.not?"!=":"=",_=`${g} ${A} ${y.sqlLiteralString(m.values[0])}`;return m.not?`(${_} OR ${g} IS NULL)`:_}const E="("+m.values.map(A=>y.sqlLiteralString(A)).join(", ")+")";return m.not?`(${g} NOT IN ${E} OR ${g} IS NULL)`:`${g} IN ${E}`}case"()":{const E="("+t.FilterCompilers.stringCompile(m.expr,g,y)+")";return m.not?`not ${E}`:E}case"contains":{const E=m.values.map(A=>"%"+s(A)+"%");return m.not?u(E.map(A=>y.sqlLike("NOT LIKE",g,A)),g):E.map(A=>y.sqlLike("LIKE",g,A)).join(" OR ")}case"starts":{const E=m.values.map(A=>s(A)+"%");return m.not?u(E.map(A=>y.sqlLike("NOT LIKE",g,A)),g):E.map(A=>y.sqlLike("LIKE",g,A)).join(" OR ")}case"ends":{const E=m.values.map(A=>"%"+s(A));return m.not?u(E.map(A=>y.sqlLike("NOT LIKE",g,A)),g):E.map(A=>y.sqlLike("LIKE",g,A)).join(" OR ")}case"~":return m.not?u(m.escaped_values.map(E=>y.sqlLike("NOT LIKE",g,E)),g):m.escaped_values.map(E=>y.sqlLike("LIKE",g,E)).join(" OR ");case"and":return m.members.map(A=>t.FilterCompilers.stringCompile(A,g,y)).join(" AND ");case"or":return m.members.map(A=>t.FilterCompilers.stringCompile(A,g,y)).join(" AND ");case",":{const E=[],A=[];let _=!1,v=!1,C=!1,S=!1;for(const O of m.members)switch(O.operator){case"or":case"and":case",":E.push(O);break;case"null":O.not?v=!0:_=!0;break;case"empty":O.not?(S=!0,v=!0):(C=!0,_=!0);break;default:(O.not?A:E).push(O)}if(C&&S||_&&v)return"false";let b="";if(E.length>0||_||C){S=!1,v=!1;const O=E.map(B=>t.FilterCompilers.stringCompile(B,g,y));C&&O.push(`${g} = ''`),_&&O.push(`${g} IS NULL`),b=O.join(" OR ")}let R="";if(A.length>0||S||v){const O=A.map(B=>t.FilterCompilers.stringCompile(B,g,y));S&&O.push(`${g} != ''`),v&&O.push(`${g} IS NOT NULL`),R=O.join(" AND ")}return b?R!==""?`(${b}) AND (${R})`:b:R!==""?R:"true"}}},temporalCompile(m,g,y,E){return new p(g,y,E).compile(m)}};const a="yyyy",l=`${a}-LL`,c=`${l}-dd`,f=`${c} HH`,x=`${f}:mm`,h=`${x}:ss`;class p{constructor(g,y,E="timestamp"){this.expr=g,this.timetype=E,this.d=y}time(g){return this.timetype==="timestamp"?g:this.d.sqlCast({},{node:"cast",e:{node:"genericSQLExpr",src:["",g],kids:{args:[]},sql:g},srcType:{type:"timestamp"},dstType:{type:"date"},safe:!1})}compile(g){const y=this.expr;switch(g.operator){case"after":return`${y} ${g.not?"<":">="} ${this.time(this.moment(g.after).end)}`;case"before":return`${y} ${g.not?">=":"<"} ${this.time(this.moment(g.before).begin.sql)}`;case"in":{const E=this.moment(g.in);return E.begin.sql===E.end?g.not?`${y} != ${this.time(E.end)} OR ${y} IS NULL`:`${y} = ${this.time(E.end)}`:this.isIn(g.not,E.begin.sql,E.end)}case"for":{const E=this.moment(g.begin),A=this.delta(E.begin,"+",g.n,g.units);return this.isIn(g.not,E.begin.sql,A.sql)}case"in_last":{const E=Number(g.n)-1,A=this.nowDot(g.units),_=E>0?this.delta(A,"-",E.toString(),g.units):A,v=this.delta(A,"+","1",g.units);return this.isIn(g.not,_.sql,v.sql)}case"to":{const E=this.moment(g.fromMoment),A=this.moment(g.toMoment);return this.isIn(g.not,E.begin.sql,A.begin.sql)}case"last":{const E=this.nowDot(g.units),A=this.delta(E,"-",g.n,g.units);return this.isIn(g.not,A.sql,E.sql)}case"next":{const E=this.nowDot(g.units),A=this.delta(E,"+","1",g.units),_=this.delta(E,"+",(Number(g.n)+1).toString(),g.units);return this.isIn(g.not,A.sql,_.sql)}case"null":return g.not?`${y} IS NOT NULL`:`${y} IS NULL`;case"()":{const E="("+this.compile(g.expr)+")";return g.not?`NOT ${E}`:E}case"and":case"or":return g.members.map(E=>this.compile(E)).join(` ${g.operator.toUpperCase()} `)}}expandLiteral(g){let y=g.literal;switch(g.units){case"year":{const E=i.DateTime.fromFormat(y,a),A=this.literalNode(E.toFormat(h)),_=E.plus({year:1});return{begin:A,end:this.literalNode(_.toFormat(h)).sql}}case"month":{const E=i.DateTime.fromFormat(y,l),A=this.literalNode(E.toFormat(h)),_=E.plus({month:1});return{begin:A,end:this.literalNode(_.toFormat(h)).sql}}case"day":{const E=i.DateTime.fromFormat(y,c),A=this.literalNode(E.toFormat(h)),_=E.plus({day:1});return{begin:A,end:this.literalNode(_.toFormat(h)).sql}}case"hour":{const E=i.DateTime.fromFormat(y,f),A=this.literalNode(E.toFormat(h)),_=E.plus({hour:1});return{begin:A,end:this.literalNode(_.toFormat(h)).sql}}case"minute":{const E=i.DateTime.fromFormat(y,x),A=this.literalNode(E.toFormat(h)),_=E.plus({minute:1});return{begin:A,end:this.literalNode(_.toFormat(h)).sql}}case"week":{const _=i.DateTime.fromFormat(y.slice(0,10),c).plus({day:1}).startOf("week").minus({day:1}),v=this.literalNode(_.toFormat(h)),C=_.plus({days:7});return{begin:v,end:this.literalNode(C.toFormat(h)).sql}}case"quarter":{const E=y.slice(0,4),A=y.slice(6);A==="1"?y=`${E}-01-01 00:00:00`:A==="2"?y=`${E}-03-01 00:00:00`:A==="3"?y=`${E}-06-01 00:00:00`:y=`${E}-09-01 00:00:00`;const _=this.literalNode(y),C=i.DateTime.fromFormat(y,h).plus({months:3});return{begin:_,end:this.literalNode(C.toFormat(h)).sql}}case void 0:case"second":{const E=this.literalNode(y);return{begin:E,end:E.sql}}}}literalNode(g){const y={node:"timeLiteral",typeDef:{type:"timestamp"},literal:g};return{...y,sql:this.d.sqlLiteralTime({},y)}}nowExpr(){return{node:"now",typeDef:{type:"timestamp"},sql:this.d.sqlNowExpr()}}n(g){return{node:"numberLiteral",literal:g,sql:g}}delta(g,y,E,A){const _={node:"delta",op:y,units:A,kids:{base:(0,r.mkTemporal)(g,"timestamp"),delta:this.n(E)}};return{..._,sql:this.d.sqlAlterTimeExpr(_)}}dayofWeek(g){const y={node:"extract",e:(0,r.mkTemporal)(g,"timestamp"),units:"day_of_week"};return{...y,sql:this.d.sqlTimeExtractExpr({},y)}}nowDot(g){const y={node:"trunc",e:this.nowExpr(),units:g};return{...y,sql:this.d.sqlTruncExpr({},y)}}thisUnit(g){const y=this.nowDot(g),E=this.delta(y,"+","1",g);return{begin:y,end:E.sql}}lastUnit(g){const y=this.nowDot(g);return{begin:this.delta(y,"-","1",g),end:y.sql}}nextUnit(g){const y=this.nowDot(g),E=this.delta(y,"+","1",g),A=this.delta(y,"+","2",g);return{begin:E,end:A.sql}}mod7(g){return this.d.hasModOperator?`(${g})%7`:`MOD(${g},7)`}moment(g){switch(g.moment){case"now":{const y=this.nowExpr();return{begin:y,end:y.sql}}case"literal":return this.expandLiteral(g);case"ago":case"from_now":{const y=this.nowDot(g.units),E=(0,r.mkTemporal)(y,"timestamp"),A=this.delta(E,g.moment==="ago"?"-":"+",g.n,g.units);if(g.moment==="ago"&&g.n==="1")return{begin:A,end:y.sql};const _=Number(g.n)+(g.moment==="ago"?-1:1),v={...A,kids:{base:E,delta:this.n(_.toString())}};return{begin:A,end:this.d.sqlAlterTimeExpr(v)}}case"today":return this.thisUnit("day");case"yesterday":return this.lastUnit("day");case"tomorrow":return this.nextUnit("day");case"this":return this.thisUnit(g.units);case"last":return this.lastUnit(g.units);case"next":return this.nextUnit(g.units);case"monday":case"tuesday":case"wednesday":case"thursday":case"friday":case"saturday":case"sunday":{const y=["sunday","monday","tuesday","wednesday","thursday","friday","saturday"].indexOf(g.moment),E=this.dayofWeek(this.nowExpr()).sql;if(g.which==="next"){const C=`${this.mod7(`${y}-(${E}-1)+6`)}+1`,S=this.delta(this.thisUnit("day").begin,"+",C,"day"),b=this.delta(this.thisUnit("day").begin,"+",`${C}+1`,"day");return{begin:S,end:b.sql}}const A=`${this.mod7(`(${E}-1)-${y}+6`)}+1`,_=this.delta(this.thisUnit("day").begin,"-",A,"day"),v=this.delta(this.thisUnit("day").begin,"-",`(${A})-1`,"day");return{begin:_,end:v.sql}}}}isIn(g,y,E){let A=">=",_="<",v="AND";return g&&(v="OR",A="<",_=">="),y=this.time(y),E=this.time(E),`${this.expr} ${A} ${y} ${v} ${this.expr} ${_} ${E}`}}t.TemporalFilterCompiler=p}(cle),Object.defineProperty(js,"__esModule",{value:!0}),js.QueryModel=js.getResultStructDefForQuery=js.getResultStructDefForView=js.Segment=void 0;const ett=m2,ttt=h2,ntt=Zy,Me=et,Fn=kt,I4=E2,rtt=mi,itt=cle,$4=nE;function yle(t){return t.map(e=>encodeURIComponent(e)).join("/")}function CB(t){return`'${t}'`}function stt(t){return t.replace(/[^a-zA-Z0-9_]/g,"_o_")}function v2(t){const e=[];for(const r of t.fields.filter(Me.fieldIsIntrinsic))e.push({typeDef:r,sqlExpression:(0,Me.getIdentifier)(r),rawName:(0,Me.getIdentifier)(r),sqlOutputName:(0,Me.getIdentifier)(r)});return e}function Ele(t,e){const{sqlExpression:r,sqlOutputName:i,rawName:s}=e;(0,Me.isAtomic)(e.fieldDef)&&t.push({typeDef:e.fieldDef,sqlExpression:r,sqlOutputName:i,rawName:s})}class ott extends Set{add_use(e){if(e!==void 0)return this.add(e)}hasAsymetricFunctions(){return this.has("sum")||this.has("avg")||this.has("count")||this.has("generic_asymmetric_aggregate")}}class C2{constructor(e=!0,r){this.parent=r,this.withs=[],this.udfs=[],this.pdts=[],this.dependenciesToMaterialize={},this.stagePrefix="__stage",this.useCTE=e}getName(e){return`${this.stagePrefix}${e}`}root(){return this.parent===void 0?this:this.parent.root()}addStage(e){return this.useCTE?(this.withs.push(e),this.getName(this.withs.length-1)):(this.withs[0]=e,(0,Fn.indent)(`
|
|
1440
|
+
`)},b.prototype.clone=function(){return new b(this.states,this.state)},b.prototype.has=function(D){return!0},{compile:_,states:C,error:Object.freeze({error:!0}),fallback:Object.freeze({fallback:!0}),keywords:S}})})(dle);var yB=dle.exports,Qt={};Object.defineProperty(Qt,"__esModule",{value:!0}),Qt.mkUnits=Qt.timeLiteral=Qt.joinTemporal=Qt.temporalNot=Qt.numNot=Qt.mkValues=Qt.mkRange=Qt.joinNumbers=Qt.conjoin=Qt.matchOp=Qt.escape=Qt.unescape=Qt.maybeNot=void 0;const Ma=On;function Ret(t){const[e,r]=t;return e&&r&&(0,Ma.isStringFilter)(r)?{...r,not:!0}:r}Qt.maybeNot=Ret;function rE(t){return t.replace(/\\(.)/g,"$1")}Qt.unescape=rE;function Det(t){const e=t.toLowerCase();return e==="null"||e==="empty"?"\\"+t:t.replace(/([,; |()\\%_-])/g,"\\$1")}Qt.escape=Det;function L4(t){let e=!1,r=!1,i=0,s=!1;const o=t.length;for(let u=0;u<o;u+=1){const a=t[u];if(a===" "||a===" "){i+=1;continue}i=0,a==="%"?(s=!0,u===0&&(e=!0),r=!0):(r=!1,a==="\\"?u+=1:a==="_"&&(s=!0))}return{hasLike:s,percentEnd:r&&o>1,percentStart:e&&o>1,endSpace:i}}function Oet(t){let e=t.trimStart();const{hasLike:r,percentEnd:i,percentStart:s,endSpace:o}=L4(e);if(o>0&&(e=e.slice(0,-o)),r){if(s&&i){const u=e.slice(1,-1);if(!L4(u).hasLike&&u.length>0)return{operator:"contains",values:[rE(u)]}}else if(i){const u=e.slice(0,-1);if(!L4(u).hasLike)return{operator:"starts",values:[rE(u)]}}else if(s){const u=e.slice(1);if(!L4(u).hasLike)return{operator:"ends",values:[rE(u)]}}return{operator:"~",escaped_values:[e]}}return e.toLowerCase()==="null"?{operator:"null"}:e.toLowerCase()==="empty"?{operator:"empty"}:{operator:"=",values:[rE(e)]}}Qt.matchOp=Oet;function EB(t,e){var r,i;return t.operator===e.operator&&((r=t.not)!==null&&r!==void 0?r:!1)===((i=e.not)!==null&&i!==void 0?i:!1)}function Fet(t,e,r){if(e=e.toLowerCase(),(0,Ma.isStringFilter)(t)&&(0,Ma.isStringFilter)(r)){if(e===","){if(t.operator==="~"&&EB(t,r))return{...t,escaped_values:[...t.escaped_values,...r.escaped_values]};if((0,Ma.isStringCondition)(t)&&EB(t,r))return{...t,values:[...t.values,...r.values]}}const i=e===","?",":e==="|"?"or":e===";"?"and":void 0;if(i)return t.operator===i?{...t,members:[...t.members,r]}:{operator:i,members:[t,r]}}return null}Qt.conjoin=Fet;function wet(t,e,r){if(e=e.toLowerCase(),(0,Ma.isNumberFilter)(t)&&(0,Ma.isNumberFilter)(r)){if(e==="or"&&t.operator==="="&&EB(t,r)){const i={operator:"=",values:[...t.values,...r.values]};return t.not&&(i.not=!0),i}if(e==="and"||e==="or")return t.operator===e?{...t,members:[...t.members,r]}:{operator:e,members:[t,r]}}return null}Qt.joinNumbers=wet;function Net(t,e,r,i){return{operator:"range",startValue:e,startOperator:t==="("?">":">=",endValue:r,endOperator:i===")"?"<":"<="}}Qt.mkRange=Net;function Let(t,e){return{values:[t,...e]}}Qt.mkValues=Let;function Iet(t,e){return(0,Ma.isNumberFilter)(t)&&e?t.operator==="="?{operator:"!=",values:t.values}:t.operator==="!="?{operator:"=",values:t.values}:{...t,not:!0}:t}Qt.numNot=Iet;function $et(t,e){return(0,Ma.isTemporalFilter)(t)&&e?{...t,not:!0}:t}Qt.temporalNot=$et;function Bet(t,e,r){return e=e.toLowerCase(),(0,Ma.isTemporalFilter)(t)&&(0,Ma.isTemporalFilter)(r)&&(e==="and"||e==="or")?t.operator===e?{...t,members:[...t.members,r]}:{operator:e,members:[t,r]}:null}Qt.joinTemporal=Bet;function ket(t,e){const r={moment:"literal",literal:t};return e&&(r.units=e),r}Qt.timeLiteral=ket;function Met(t){switch(t.toLowerCase()){case"second":case"seconds":return"second";case"minute":case"minutes":return"minute";case"hour":case"hours":return"hour";case"day":case"days":return"day";case"week":case"weeks":return"week";case"month":case"months":return"month";case"quarter":case"quarters":return"quarter";case"year":case"years":return"year"}}Qt.mkUnits=Met;var Pet=T&&T.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(gB,"__esModule",{value:!0});function Uet(t){return t[0]}const hle=Pet(yB),A2=Qt,jet=hle.default.keywords({AND:"and",OR:"or",NOT:"not",NULL_KW:"null",TO:"to"}),kn=hle.default.compile({WS:/[ \t]+/,id:{match:/[a-zA-Z]+/,type:t=>jet(t.toLowerCase())},oparen:"(",cparen:")",obrack:"[",cbrack:"]",comma:",",op:/<=|>=|<|>/,ne:"!=",eq:"=",float:/-?(?:\d+)?\.\d+(?:[Ee][+-]?\d+)?/,numberE:/-?\d+[Ee][+-]?\d+/,integer:/-?\d+/}),qet=kn.next;kn.next=(t=>()=>{for(;;){const e=t.call(kn);if(e===void 0||e.type!=="WS")return e}})(qet);const Het={Lexer:kn,ParserRules:[{name:"numberFilter",symbols:["numberFilter","conjunction","numberUnary"],postprocess:([t,e,r])=>(0,A2.joinNumbers)(t,e[0].text,r)},{name:"numberFilter",symbols:["numberUnary"],postprocess:t=>t[0]},{name:"numberUnary$ebnf$1",symbols:[kn.has("NOT")?{type:"NOT"}:NOT],postprocess:Uet},{name:"numberUnary$ebnf$1",symbols:[],postprocess:()=>null},{name:"numberUnary",symbols:["numberUnary$ebnf$1","clause"],postprocess:([t,e])=>(0,A2.numNot)(e,t)},{name:"clause",symbols:[kn.has("NULL_KW")?{type:"NULL_KW"}:NULL_KW],postprocess:()=>({operator:"null"})},{name:"clause$ebnf$1",symbols:[]},{name:"clause$ebnf$1",symbols:["clause$ebnf$1","numberList"],postprocess:t=>t[0].concat([t[1]])},{name:"clause",symbols:["N","clause$ebnf$1"],postprocess:([t,e])=>({operator:"=",...(0,A2.mkValues)(t,e)})},{name:"clause$ebnf$2",symbols:[]},{name:"clause$ebnf$2",symbols:["clause$ebnf$2","numberList"],postprocess:t=>t[0].concat([t[1]])},{name:"clause",symbols:[kn.has("eq")?{type:"eq"}:eq,"N","clause$ebnf$2"],postprocess:([t,e,r])=>({operator:"=",...(0,A2.mkValues)(e,r)})},{name:"clause$ebnf$3",symbols:[]},{name:"clause$ebnf$3",symbols:["clause$ebnf$3","numberList"],postprocess:t=>t[0].concat([t[1]])},{name:"clause",symbols:[kn.has("ne")?{type:"ne"}:ne,"N","clause$ebnf$3"],postprocess:([t,e,r])=>({operator:"!=",...(0,A2.mkValues)(e,r)})},{name:"clause",symbols:[kn.has("op")?{type:"op"}:op,"N"],postprocess:([t,e])=>({operator:t.text,values:[e]})},{name:"clause",symbols:[kn.has("oparen")?{type:"oparen"}:oparen,"numberFilter",kn.has("cparen")?{type:"cparen"}:cparen],postprocess:([t,e,r])=>({operator:"()",expr:e})},{name:"clause",symbols:["openInterval","N",kn.has("TO")?{type:"TO"}:TO,"N","closeInterval"],postprocess:([t,e,r,i,s])=>(0,A2.mkRange)(t[0].text,e,i,s[0].text)},{name:"numberList",symbols:[kn.has("comma")?{type:"comma"}:comma,"N"],postprocess:([t,e])=>e},{name:"closeInterval",symbols:[kn.has("cbrack")?{type:"cbrack"}:cbrack]},{name:"closeInterval",symbols:[kn.has("cparen")?{type:"cparen"}:cparen]},{name:"openInterval",symbols:[kn.has("obrack")?{type:"obrack"}:obrack]},{name:"openInterval",symbols:[kn.has("oparen")?{type:"oparen"}:oparen]},{name:"N$subexpression$1",symbols:[kn.has("float")?{type:"float"}:float]},{name:"N$subexpression$1",symbols:[kn.has("numberE")?{type:"numberE"}:numberE]},{name:"N$subexpression$1",symbols:[kn.has("integer")?{type:"integer"}:integer]},{name:"N",symbols:["N$subexpression$1"],postprocess:([t])=>t[0].text},{name:"conjunction",symbols:[kn.has("OR")?{type:"OR"}:OR]},{name:"conjunction",symbols:[kn.has("AND")?{type:"AND"}:AND]}],ParserStart:"numberFilter"};gB.default=Het;var _2={};Object.defineProperty(_2,"__esModule",{value:!0}),_2.run_parser=void 0;const Qet=On;function zet(t,e){try{e.feed(t);const i=e.finish()[0];return(0,Qet.isFilterExpression)(i)?{parsed:i,log:[]}:{parsed:null,log:[]}}catch(r){let i=r.message,s=1,o=t.length;if(r.token){const u=r.token;s=u.col,o=u.text.length;const l=r.message.match(new RegExp("(?<=A ).*(?= based on:)","g")).map(c=>c.replace(/\s+token/i,""));i=`Unexpected ${u.type} token "${u.value}"`,l&&l.length&&(i+=` Tokens expected: ${[...new Set(l)]}`)}return{parsed:null,log:[{message:i,startIndex:s-1,endIndex:s-1+o-1,severity:"error"}]}}}_2.run_parser=zet,function(t){var e=T&&T.__createBinding||(Object.create?function(c,f,x,h){h===void 0&&(h=x);var p=Object.getOwnPropertyDescriptor(f,x);(!p||("get"in p?!f.__esModule:p.writable||p.configurable))&&(p={enumerable:!0,get:function(){return f[x]}}),Object.defineProperty(c,h,p)}:function(c,f,x,h){h===void 0&&(h=x),c[h]=f[x]}),r=T&&T.__setModuleDefault||(Object.create?function(c,f){Object.defineProperty(c,"default",{enumerable:!0,value:f})}:function(c,f){c.default=f}),i=T&&T.__importStar||function(c){if(c&&c.__esModule)return c;var f={};if(c!=null)for(var x in c)x!=="default"&&Object.prototype.hasOwnProperty.call(c,x)&&e(f,c,x);return r(f,c),f},s=T&&T.__importDefault||function(c){return c&&c.__esModule?c:{default:c}};Object.defineProperty(t,"__esModule",{value:!0}),t.NumberFilterExpression=void 0;const o=On,u=i(mB),a=s(gB),l=_2;t.NumberFilterExpression={parse(c){if(c.match(/^\s*$/))return{parsed:null,log:[]};const f=new u.Parser(u.Grammar.fromCompiled(a.default)),x=(0,l.run_parser)(c,f);return x.parsed&&(0,o.isNumberFilter)(x.parsed)?{parsed:x.parsed,log:[]}:{parsed:null,log:x.log}},unparse(c){if(c===null)return"";switch(c.operator){case"=":return c.values.join(", ");case"!=":return"!= "+c.values.join(", ");case">":case"<":case"<=":case">=":return c.not?c.values.map(f=>c.operator==="="?`not ${f}`:`not ${c.operator} ${f}`).join(", "):c.values.map(f=>`${c.operator} ${f}`).join(", ");case"range":{const f=c.startOperator===">"?"(":"[",x=c.endOperator==="<"?")":"]",h=`${f}${c.startValue} to ${c.endValue}${x}`;return c.not?`not ${h}`:h}case"null":return c.not?"not null":"null";case"and":case"or":return c.members.map(f=>t.NumberFilterExpression.unparse(f)).join(` ${c.operator} `);case"()":{const f="("+t.NumberFilterExpression.unparse(c.expr)+")";return c.not?"not "+f:f}}return`no unparse for ${JSON.stringify(c)}`}}}(fle);var ple={},AB={},Wet=T&&T.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(AB,"__esModule",{value:!0});function Get(t){return t[0]}const Vet=Wet(yB),_B=Qt,Cu=Vet.default.compile({WS:/[ \t]+/,comma:",",semi:";",or:"|",open:"(",close:")",minus:"-",matchStr:/(?:\\[^\n]|[^\n,;()|])+/}),Yet=Cu.next;Cu.next=(t=>()=>{for(;;){const e=t.call(Cu);if(e==null||e.type!=="WS")return e}})(Yet);const Ket={Lexer:Cu,ParserRules:[{name:"stringFilter",symbols:["stringFilter","conjunction","sfUnary"],postprocess:([t,e,r])=>(0,_B.conjoin)(t,e[0].text,r)},{name:"stringFilter",symbols:["sfUnary"],postprocess:t=>t[0]},{name:"sfUnary$ebnf$1",symbols:[Cu.has("minus")?{type:"minus"}:minus],postprocess:Get},{name:"sfUnary$ebnf$1",symbols:[],postprocess:()=>null},{name:"sfUnary",symbols:["sfUnary$ebnf$1","clause"],postprocess:t=>(0,_B.maybeNot)(t)},{name:"parens",symbols:[Cu.has("open")?{type:"open"}:open,"stringFilter",Cu.has("close")?{type:"close"}:close],postprocess:([t,e,r])=>({operator:"()",expr:e})},{name:"clause",symbols:[Cu.has("matchStr")?{type:"matchStr"}:matchStr],postprocess:([t])=>(0,_B.matchOp)(t.text)},{name:"clause",symbols:["parens"],postprocess:t=>t[0]},{name:"conjunction",symbols:[Cu.has("comma")?{type:"comma"}:comma]},{name:"conjunction",symbols:[Cu.has("semi")?{type:"semi"}:semi]},{name:"conjunction",symbols:[Cu.has("or")?{type:"or"}:or]}],ParserStart:"stringFilter"};AB.default=Ket,function(t){var e=T&&T.__createBinding||(Object.create?function(f,x,h,p){p===void 0&&(p=h);var m=Object.getOwnPropertyDescriptor(x,h);(!m||("get"in m?!x.__esModule:m.writable||m.configurable))&&(m={enumerable:!0,get:function(){return x[h]}}),Object.defineProperty(f,p,m)}:function(f,x,h,p){p===void 0&&(p=h),f[p]=x[h]}),r=T&&T.__setModuleDefault||(Object.create?function(f,x){Object.defineProperty(f,"default",{enumerable:!0,value:x})}:function(f,x){f.default=x}),i=T&&T.__importStar||function(f){if(f&&f.__esModule)return f;var x={};if(f!=null)for(var h in f)h!=="default"&&Object.prototype.hasOwnProperty.call(f,h)&&e(x,f,h);return r(x,f),x},s=T&&T.__importDefault||function(f){return f&&f.__esModule?f:{default:f}};Object.defineProperty(t,"__esModule",{value:!0}),t.StringFilterExpression=void 0;const o=On,u=i(mB),a=s(AB),l=Qt,c=_2;t.StringFilterExpression={parse(f){if(f.match(/^\s*$/))return{parsed:null,log:[]};const x=new u.Parser(u.Grammar.fromCompiled(a.default)),h=(0,c.run_parser)(f,x);return h.parsed&&(0,o.isStringFilter)(h.parsed)?{parsed:h.parsed,log:[]}:{parsed:null,log:h.log}},unparse(f){if(f===null)return"";switch(f.operator){case"=":return f.not?f.values.map(x=>"-"+(0,l.escape)(x)).join(", "):f.values.map(x=>(0,l.escape)(x)).join(", ");case"~":return f.not?f.escaped_values.map(x=>"-"+x).join(", "):f.escaped_values.join(", ");case"starts":return f.not?f.values.map(x=>"-"+(0,l.escape)(x)+"%").join(", "):f.values.map(x=>(0,l.escape)(x)+"%").join(", ");case"ends":return f.not?f.values.map(x=>"-%"+(0,l.escape)(x)).join(", "):f.values.map(x=>"%"+(0,l.escape)(x)).join(", ");case"contains":return f.not?f.values.map(x=>"-%"+(0,l.escape)(x)+"%").join(", "):f.values.map(x=>"%"+(0,l.escape)(x)+"%").join(", ");case"or":return f.members.map(x=>t.StringFilterExpression.unparse(x)).join(" | ");case"and":return f.members.map(x=>t.StringFilterExpression.unparse(x)).join("; ");case",":return f.members.map(x=>t.StringFilterExpression.unparse(x)).join(", ");case"()":{const x="("+t.StringFilterExpression.unparse(f.expr)+")";return f.not?"-"+x:x}case"null":return f.not?"-null":"null";case"empty":return f.not?"-empty":"empty"}}}}(ple);var mle={},vB={},Jet=T&&T.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(vB,"__esModule",{value:!0});function Xet(t){return t[0]}const gle=Jet(yB),Su=Qt,Zet=gle.default.keywords({AND:"and",OR:"or",NOT:"not",NULL_KW:"null",TO:"to",NOW:"now",LAST:"last",THIS:"this",NEXT:"next",AGO:"ago",FROM:"from",BEFORE:"before",AFTER:"after",FOR:"for",TODAY:"today",YESTERDAY:"yesterday",TOMORROW:"tomorrow",SECOND:"second",MINUTE:"minute",HOUR:"hour",DAY:"day",WEEK:"week",MONTH:"month",QUARTER:"quarter",YEAR:"year",SECONDS:"seconds",MINUTES:"minutes",HOURS:"hours",DAYS:"days",WEEKS:"weeks",MONTHS:"months",QUARTERS:"quarters",YEARS:"years",MONDAY:"monday",TUESDAY:"tuesday",WEDNESDAY:"wednesday",THURSDAY:"thursday",FRIDAY:"friday",SATURDAY:"saturday",SUNDAY:"sunday"}),Xe=gle.default.compile({WS:/[ \t]+/,id:{match:/[a-zA-Z]+/,type:t=>Zet(t.toLowerCase())},oparen:"(",cparen:")",comma:",",literal:/\d\d\d\d-\d\d-\d\d[ Tt]\d\d:\d\d(?::\d\d(?:[.,]\d*)?)/,lit_week:/\d\d\d\d-\d\d-\d\d-[Ww][Kk]/,lit_quarter:/\d\d\d\d-[qQ][1234]/,lit_min:/\d\d\d\d-\d\d-\d\d[ Tt]\d\d:\d\d/,lit_hour:/\d\d\d\d-\d\d-\d\d[ Tt]\d\d/,lit_day:/\d\d\d\d-\d\d-\d\d/,lit_month:/\d\d\d\d-\d\d/,lit_year:/\d\d\d\d/,n:/\d+/}),ett=Xe.next;Xe.next=(t=>()=>{for(;;){const e=t.call(Xe);if(e===void 0||e.type!=="WS")return e}})(ett);const ttt={Lexer:Xe,ParserRules:[{name:"temporalFilter",symbols:["temporalFilter","conjunction","temporalUnary"],postprocess:([t,e,r])=>(0,Su.joinTemporal)(t,e[0].text,r)},{name:"temporalFilter",symbols:["temporalUnary"],postprocess:t=>t[0]},{name:"temporalUnary$ebnf$1",symbols:[Xe.has("NOT")?{type:"NOT"}:NOT],postprocess:Xet},{name:"temporalUnary$ebnf$1",symbols:[],postprocess:()=>null},{name:"temporalUnary",symbols:["temporalUnary$ebnf$1","clause"],postprocess:([t,e])=>(0,Su.temporalNot)(e,t)},{name:"duration",symbols:["number","unit"],postprocess:([t,e])=>({units:e,n:t})},{name:"number",symbols:[Xe.has("n")?{type:"n"}:n],postprocess:([t])=>t.text},{name:"number",symbols:[Xe.has("lityear")?{type:"lityear"}:lityear],postprocess:([t])=>t.text},{name:"unit$subexpression$1",symbols:[Xe.has("SECOND")?{type:"SECOND"}:SECOND]},{name:"unit$subexpression$1",symbols:[Xe.has("MINUTE")?{type:"MINUTE"}:MINUTE]},{name:"unit$subexpression$1",symbols:[Xe.has("HOUR")?{type:"HOUR"}:HOUR]},{name:"unit$subexpression$1",symbols:[Xe.has("DAY")?{type:"DAY"}:DAY]},{name:"unit$subexpression$1",symbols:[Xe.has("WEEK")?{type:"WEEK"}:WEEK]},{name:"unit$subexpression$1",symbols:[Xe.has("MONTH")?{type:"MONTH"}:MONTH]},{name:"unit$subexpression$1",symbols:[Xe.has("QUARTER")?{type:"QUARTER"}:QUARTER]},{name:"unit$subexpression$1",symbols:[Xe.has("YEAR")?{type:"YEAR"}:YEAR]},{name:"unit$subexpression$1",symbols:[Xe.has("SECONDS")?{type:"SECONDS"}:SECONDS]},{name:"unit$subexpression$1",symbols:[Xe.has("MINUTES")?{type:"MINUTES"}:MINUTES]},{name:"unit$subexpression$1",symbols:[Xe.has("HOURS")?{type:"HOURS"}:HOURS]},{name:"unit$subexpression$1",symbols:[Xe.has("DAYS")?{type:"DAYS"}:DAYS]},{name:"unit$subexpression$1",symbols:[Xe.has("WEEKS")?{type:"WEEKS"}:WEEKS]},{name:"unit$subexpression$1",symbols:[Xe.has("MONTHS")?{type:"MONTHS"}:MONTHS]},{name:"unit$subexpression$1",symbols:[Xe.has("QUARTERS")?{type:"QUARTERS"}:QUARTERS]},{name:"unit$subexpression$1",symbols:[Xe.has("YEARS")?{type:"YEARS"}:YEARS]},{name:"unit",symbols:["unit$subexpression$1"],postprocess:([t])=>(0,Su.mkUnits)(t[0].text)},{name:"clause",symbols:[Xe.has("NULL_KW")?{type:"NULL_KW"}:NULL_KW],postprocess:()=>({operator:"null"})},{name:"clause",symbols:["parens"],postprocess:t=>t[0]},{name:"clause",symbols:["duration"],postprocess:([t])=>({operator:"in_last",...t})},{name:"clause",symbols:[Xe.has("BEFORE")?{type:"BEFORE"}:BEFORE,"moment"],postprocess:([t,e])=>({operator:"before",before:e})},{name:"clause",symbols:[Xe.has("AFTER")?{type:"AFTER"}:AFTER,"moment"],postprocess:([t,e])=>({operator:"after",after:e})},{name:"clause",symbols:["moment",Xe.has("TO")?{type:"TO"}:TO,"moment"],postprocess:([t,e,r])=>({operator:"to",fromMoment:t,toMoment:r})},{name:"clause",symbols:["moment",Xe.has("FOR")?{type:"FOR"}:FOR,"duration"],postprocess:([t,e,r])=>({...r,operator:"for",begin:t})},{name:"clause$subexpression$1",symbols:[Xe.has("LAST")?{type:"LAST"}:LAST]},{name:"clause$subexpression$1",symbols:[Xe.has("NEXT")?{type:"NEXT"}:NEXT]},{name:"clause",symbols:["clause$subexpression$1","duration"],postprocess:([t,e])=>({operator:t[0].text,...e})},{name:"clause",symbols:["moment"],postprocess:([t])=>({operator:"in",in:t})},{name:"lastNextThis",symbols:[Xe.has("THIS")?{type:"THIS"}:THIS],postprocess:([t])=>t.text.toLowerCase()},{name:"lastNextThis",symbols:[Xe.has("NEXT")?{type:"NEXT"}:NEXT],postprocess:([t])=>t.text.toLowerCase()},{name:"lastNextThis",symbols:[Xe.has("LAST")?{type:"LAST"}:LAST],postprocess:([t])=>t.text.toLowerCase()},{name:"moment",symbols:[Xe.has("NOW")?{type:"NOW"}:NOW],postprocess:()=>({moment:"now"})},{name:"moment",symbols:["lastNextThis","unit"],postprocess:([t,e])=>({moment:t,units:e})},{name:"moment",symbols:[Xe.has("TODAY")?{type:"TODAY"}:TODAY],postprocess:()=>({moment:"today"})},{name:"moment",symbols:[Xe.has("YESTERDAY")?{type:"YESTERDAY"}:YESTERDAY],postprocess:()=>({moment:"yesterday"})},{name:"moment",symbols:[Xe.has("TOMORROW")?{type:"TOMORROW"}:TOMORROW],postprocess:()=>({moment:"tomorrow"})},{name:"moment",symbols:["duration",Xe.has("AGO")?{type:"AGO"}:AGO],postprocess:([t,e])=>({moment:"ago",...t})},{name:"moment",symbols:["duration",Xe.has("FROM")?{type:"FROM"}:FROM,Xe.has("NOW")?{type:"NOW"}:NOW],postprocess:([t,e])=>({moment:"from_now",...t})},{name:"moment",symbols:[Xe.has("NEXT")?{type:"NEXT"}:NEXT,"weekday"],postprocess:([t,e])=>({moment:e.toLowerCase(),which:"next"})},{name:"moment",symbols:[Xe.has("LAST")?{type:"LAST"}:LAST,"weekday"],postprocess:([t,e])=>({moment:e.toLowerCase(),which:"last"})},{name:"moment",symbols:["weekday"],postprocess:([t])=>({moment:t.toLowerCase(),which:"last"})},{name:"moment",symbols:["timeLiteral"],postprocess:t=>t[0]},{name:"timeLiteral",symbols:[Xe.has("literal")?{type:"literal"}:literal],postprocess:([t])=>(0,Su.timeLiteral)(t.text)},{name:"timeLiteral",symbols:[Xe.has("lit_day")?{type:"lit_day"}:lit_day],postprocess:([t])=>(0,Su.timeLiteral)(t.text,"day")},{name:"timeLiteral",symbols:[Xe.has("lit_min")?{type:"lit_min"}:lit_min],postprocess:([t])=>(0,Su.timeLiteral)(t.text,"minute")},{name:"timeLiteral",symbols:[Xe.has("lit_hour")?{type:"lit_hour"}:lit_hour],postprocess:([t])=>(0,Su.timeLiteral)(t.text,"hour")},{name:"timeLiteral",symbols:[Xe.has("lit_month")?{type:"lit_month"}:lit_month],postprocess:([t])=>(0,Su.timeLiteral)(t.text,"month")},{name:"timeLiteral",symbols:[Xe.has("lit_quarter")?{type:"lit_quarter"}:lit_quarter],postprocess:([t])=>(0,Su.timeLiteral)(t.text,"quarter")},{name:"timeLiteral",symbols:[Xe.has("lit_week")?{type:"lit_week"}:lit_week],postprocess:([t])=>(0,Su.timeLiteral)(t.text,"week")},{name:"timeLiteral",symbols:[Xe.has("lit_year")?{type:"lit_year"}:lit_year],postprocess:([t])=>(0,Su.timeLiteral)(t.text,"year")},{name:"weekday$subexpression$1",symbols:[Xe.has("MONDAY")?{type:"MONDAY"}:MONDAY]},{name:"weekday$subexpression$1",symbols:[Xe.has("TUESDAY")?{type:"TUESDAY"}:TUESDAY]},{name:"weekday$subexpression$1",symbols:[Xe.has("WEDNESDAY")?{type:"WEDNESDAY"}:WEDNESDAY]},{name:"weekday$subexpression$1",symbols:[Xe.has("THURSDAY")?{type:"THURSDAY"}:THURSDAY]},{name:"weekday$subexpression$1",symbols:[Xe.has("FRIDAY")?{type:"FRIDAY"}:FRIDAY]},{name:"weekday$subexpression$1",symbols:[Xe.has("SATURDAY")?{type:"SATURDAY"}:SATURDAY]},{name:"weekday$subexpression$1",symbols:[Xe.has("SUNDAY")?{type:"SUNDAY"}:SUNDAY]},{name:"weekday",symbols:["weekday$subexpression$1"],postprocess:([t])=>t[0].text},{name:"parens",symbols:[Xe.has("oparen")?{type:"oparen"}:oparen,"temporalFilter",Xe.has("cparen")?{type:"cparen"}:cparen],postprocess:([t,e,r])=>({operator:"()",expr:e})},{name:"conjunction",symbols:[Xe.has("OR")?{type:"OR"}:OR]},{name:"conjunction",symbols:[Xe.has("AND")?{type:"AND"}:AND]}],ParserStart:"temporalFilter"};vB.default=ttt,function(t){var e=T&&T.__createBinding||(Object.create?function(h,p,m,g){g===void 0&&(g=m);var y=Object.getOwnPropertyDescriptor(p,m);(!y||("get"in y?!p.__esModule:y.writable||y.configurable))&&(y={enumerable:!0,get:function(){return p[m]}}),Object.defineProperty(h,g,y)}:function(h,p,m,g){g===void 0&&(g=m),h[g]=p[m]}),r=T&&T.__setModuleDefault||(Object.create?function(h,p){Object.defineProperty(h,"default",{enumerable:!0,value:p})}:function(h,p){h.default=p}),i=T&&T.__importStar||function(h){if(h&&h.__esModule)return h;var p={};if(h!=null)for(var m in h)m!=="default"&&Object.prototype.hasOwnProperty.call(h,m)&&e(p,h,m);return r(p,h),p},s=T&&T.__importDefault||function(h){return h&&h.__esModule?h:{default:h}};Object.defineProperty(t,"__esModule",{value:!0}),t.TemporalFilterExpression=void 0;const o=On,u=s(vB),a=i(mB),l=_2;t.TemporalFilterExpression={parse(h){if(h.match(/^\s*$/))return{parsed:null,log:[]};const p=new a.Parser(a.Grammar.fromCompiled(u.default)),m=(0,l.run_parser)(h,p);return m.parsed&&(0,o.isTemporalFilter)(m.parsed)?{parsed:m.parsed,log:[]}:{parsed:null,log:m.log}},unparse(h){if(h===null)return"";switch(h.operator){case"null":return c(h,"null");case"in":return c(h,x(h.in));case"()":return"("+t.TemporalFilterExpression.unparse(h.expr)+")";case"in_last":return c(h,f(h));case"last":case"next":return c(h,`${h.operator} ${f(h)}`);case"before":return c(h,`before ${x(h.before)}`);case"after":return c(h,`after ${x(h.after)}`);case"to":return c(h,`${x(h.fromMoment)} to ${x(h.toMoment)}`);case"for":return c(h,`${x(h.begin)} for ${f(h)}`);case"or":return h.members.map(p=>t.TemporalFilterExpression.unparse(p)).join(" or ");case"and":return h.members.map(p=>t.TemporalFilterExpression.unparse(p)).join(" and ")}}};function c(h,p){return"not"in h&&h.not?"not "+p:p}function f(h){return h.n==="1"?`1 ${h.units}`:`${h.n} ${h.units}s`}function x(h){switch(h.moment){case"literal":return h.literal;case"now":case"today":case"yesterday":case"tomorrow":return h.moment;case"monday":case"tuesday":case"wednesday":case"thursday":case"friday":case"saturday":case"sunday":return h.which==="next"?"next "+h.moment:h.moment;case"this":case"next":case"last":return`${h.moment} ${h.units}`;case"ago":return`${f(h)} ago`;case"from_now":return`${f(h)} from now`}}}(mle),function(t){var e=T&&T.__createBinding||(Object.create?function(a,l,c,f){f===void 0&&(f=c);var x=Object.getOwnPropertyDescriptor(l,c);(!x||("get"in x?!l.__esModule:x.writable||x.configurable))&&(x={enumerable:!0,get:function(){return l[c]}}),Object.defineProperty(a,f,x)}:function(a,l,c,f){f===void 0&&(f=c),a[f]=l[c]}),r=T&&T.__exportStar||function(a,l){for(var c in a)c!=="default"&&!Object.prototype.hasOwnProperty.call(l,c)&&e(l,a,c)};Object.defineProperty(t,"__esModule",{value:!0}),t.TemporalFilterExpression=t.StringFilterExpression=t.NumberFilterExpression=t.BooleanFilterExpression=void 0,r(On,t);var i=N4;Object.defineProperty(t,"BooleanFilterExpression",{enumerable:!0,get:function(){return i.BooleanFilterExpression}});var s=fle;Object.defineProperty(t,"NumberFilterExpression",{enumerable:!0,get:function(){return s.NumberFilterExpression}});var o=ple;Object.defineProperty(t,"StringFilterExpression",{enumerable:!0,get:function(){return o.StringFilterExpression}});var u=mle;Object.defineProperty(t,"TemporalFilterExpression",{enumerable:!0,get:function(){return u.TemporalFilterExpression}})}(nE),function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.TemporalFilterCompiler=t.FilterCompilers=void 0;const e=nE,r=et,i=qr;function s(m){return m.replace(/([%_\\])/g,"\\$1")}function o(m){return m===">"?"<=":m==="<"?">=":m===">="?"<":">"}function u(m,g){const y=` OR ${g} IS NULL`;return m.length===1?`${m[0]}${y}`:`(${m.join(" AND ")})${y}`}t.FilterCompilers={compile(m,g,y,E){if(g===null)return"true";if(m==="string"&&(0,e.isStringFilter)(g))return t.FilterCompilers.stringCompile(g,y,E);if(m==="number"&&(0,e.isNumberFilter)(g))return t.FilterCompilers.numberCompile(g,y,E);if(m==="boolean"&&(0,e.isBooleanFilter)(g))return t.FilterCompilers.booleanCompile(g,y,E);if((m==="date"||m==="timestamp")&&(0,e.isTemporalFilter)(g))return t.FilterCompilers.temporalCompile(g,y,E,m);throw new Error("INTERNAL ERROR: No filter compiler for "+m)},numberCompile(m,g,y){switch(m.operator){case"!=":case"=":{const E=m.operator==="="&&m.not||m.operator==="!="&&!m.not,A=m.values.join(", ");return m.values.length===1?E?`${g} != ${A} OR ${g} IS NULL`:`${g} = ${A}`:E?`${g} NOT IN (${A}) OR ${g} IS NULL`:`${g} IN (${A})`}case">":case"<":case">=":case"<=":return m.values.map(E=>`${g} ${m.operator} ${E}`).join(m.not?" AND ":" OR ");case"range":{let E=m.startOperator,A=m.endOperator,_=" AND ";return m.not&&(E=o(E),A=o(A),_=" OR "),`${g} ${E} ${m.startValue} ${_} ${g} ${A} ${m.endValue}`}case"null":return m.not?`${g} IS NOT NULL`:`${g} IS NULL`;case"()":{const E="("+t.FilterCompilers.numberCompile(m.expr,g,y)+")";return m.not?`NOT ${E}`:E}case"and":case"or":return m.members.map(E=>t.FilterCompilers.numberCompile(E,g,y)).join(` ${m.operator.toUpperCase()} `)}},booleanCompile(m,g,y){switch(m.operator){case"false":return`${g} = false`;case"false_or_null":return`${g} IS NULL OR ${g} = false`;case"null":return m.not?`${g} IS NOT NULL`:`${g} IS NULL`;case"true":return g}},stringCompile(m,g,y){switch(m.operator){case"null":return m.not?`${g} IS NOT NULL`:`${g} IS NULL`;case"empty":return m.not?`COALESCE(${g},'') != ''`:`COALESCE(${g},'') = ''`;case"=":{if(m.values.length===1){const A=m.not?"!=":"=",_=`${g} ${A} ${y.sqlLiteralString(m.values[0])}`;return m.not?`(${_} OR ${g} IS NULL)`:_}const E="("+m.values.map(A=>y.sqlLiteralString(A)).join(", ")+")";return m.not?`(${g} NOT IN ${E} OR ${g} IS NULL)`:`${g} IN ${E}`}case"()":{const E="("+t.FilterCompilers.stringCompile(m.expr,g,y)+")";return m.not?`not ${E}`:E}case"contains":{const E=m.values.map(A=>"%"+s(A)+"%");return m.not?u(E.map(A=>y.sqlLike("NOT LIKE",g,A)),g):E.map(A=>y.sqlLike("LIKE",g,A)).join(" OR ")}case"starts":{const E=m.values.map(A=>s(A)+"%");return m.not?u(E.map(A=>y.sqlLike("NOT LIKE",g,A)),g):E.map(A=>y.sqlLike("LIKE",g,A)).join(" OR ")}case"ends":{const E=m.values.map(A=>"%"+s(A));return m.not?u(E.map(A=>y.sqlLike("NOT LIKE",g,A)),g):E.map(A=>y.sqlLike("LIKE",g,A)).join(" OR ")}case"~":return m.not?u(m.escaped_values.map(E=>y.sqlLike("NOT LIKE",g,E)),g):m.escaped_values.map(E=>y.sqlLike("LIKE",g,E)).join(" OR ");case"and":return m.members.map(A=>t.FilterCompilers.stringCompile(A,g,y)).join(" AND ");case"or":return m.members.map(A=>t.FilterCompilers.stringCompile(A,g,y)).join(" AND ");case",":{const E=[],A=[];let _=!1,v=!1,C=!1,S=!1;for(const O of m.members)switch(O.operator){case"or":case"and":case",":E.push(O);break;case"null":O.not?v=!0:_=!0;break;case"empty":O.not?(S=!0,v=!0):(C=!0,_=!0);break;default:(O.not?A:E).push(O)}if(C&&S||_&&v)return"false";let b="";if(E.length>0||_||C){S=!1,v=!1;const O=E.map(B=>t.FilterCompilers.stringCompile(B,g,y));C&&O.push(`${g} = ''`),_&&O.push(`${g} IS NULL`),b=O.join(" OR ")}let R="";if(A.length>0||S||v){const O=A.map(B=>t.FilterCompilers.stringCompile(B,g,y));S&&O.push(`${g} != ''`),v&&O.push(`${g} IS NOT NULL`),R=O.join(" AND ")}return b?R!==""?`(${b}) AND (${R})`:b:R!==""?R:"true"}}},temporalCompile(m,g,y,E){return new p(g,y,E).compile(m)}};const a="yyyy",l=`${a}-LL`,c=`${l}-dd`,f=`${c} HH`,x=`${f}:mm`,h=`${x}:ss`;class p{constructor(g,y,E="timestamp"){this.expr=g,this.timetype=E,this.d=y}time(g){return this.timetype==="timestamp"?g:this.d.sqlCast({},{node:"cast",e:{node:"genericSQLExpr",src:["",g],kids:{args:[]},sql:g},srcType:{type:"timestamp"},dstType:{type:"date"},safe:!1})}compile(g){const y=this.expr;switch(g.operator){case"after":return`${y} ${g.not?"<":">="} ${this.time(this.moment(g.after).end)}`;case"before":return`${y} ${g.not?">=":"<"} ${this.time(this.moment(g.before).begin.sql)}`;case"in":{const E=this.moment(g.in);return E.begin.sql===E.end?g.not?`${y} != ${this.time(E.end)} OR ${y} IS NULL`:`${y} = ${this.time(E.end)}`:this.isIn(g.not,E.begin.sql,E.end)}case"for":{const E=this.moment(g.begin),A=this.delta(E.begin,"+",g.n,g.units);return this.isIn(g.not,E.begin.sql,A.sql)}case"in_last":{const E=Number(g.n)-1,A=this.nowDot(g.units),_=E>0?this.delta(A,"-",E.toString(),g.units):A,v=this.delta(A,"+","1",g.units);return this.isIn(g.not,_.sql,v.sql)}case"to":{const E=this.moment(g.fromMoment),A=this.moment(g.toMoment);return this.isIn(g.not,E.begin.sql,A.begin.sql)}case"last":{const E=this.nowDot(g.units),A=this.delta(E,"-",g.n,g.units);return this.isIn(g.not,A.sql,E.sql)}case"next":{const E=this.nowDot(g.units),A=this.delta(E,"+","1",g.units),_=this.delta(E,"+",(Number(g.n)+1).toString(),g.units);return this.isIn(g.not,A.sql,_.sql)}case"null":return g.not?`${y} IS NOT NULL`:`${y} IS NULL`;case"()":{const E="("+this.compile(g.expr)+")";return g.not?`NOT ${E}`:E}case"and":case"or":return g.members.map(E=>this.compile(E)).join(` ${g.operator.toUpperCase()} `)}}expandLiteral(g){let y=g.literal;switch(g.units){case"year":{const E=i.DateTime.fromFormat(y,a),A=this.literalNode(E.toFormat(h)),_=E.plus({year:1});return{begin:A,end:this.literalNode(_.toFormat(h)).sql}}case"month":{const E=i.DateTime.fromFormat(y,l),A=this.literalNode(E.toFormat(h)),_=E.plus({month:1});return{begin:A,end:this.literalNode(_.toFormat(h)).sql}}case"day":{const E=i.DateTime.fromFormat(y,c),A=this.literalNode(E.toFormat(h)),_=E.plus({day:1});return{begin:A,end:this.literalNode(_.toFormat(h)).sql}}case"hour":{const E=i.DateTime.fromFormat(y,f),A=this.literalNode(E.toFormat(h)),_=E.plus({hour:1});return{begin:A,end:this.literalNode(_.toFormat(h)).sql}}case"minute":{const E=i.DateTime.fromFormat(y,x),A=this.literalNode(E.toFormat(h)),_=E.plus({minute:1});return{begin:A,end:this.literalNode(_.toFormat(h)).sql}}case"week":{const _=i.DateTime.fromFormat(y.slice(0,10),c).plus({day:1}).startOf("week").minus({day:1}),v=this.literalNode(_.toFormat(h)),C=_.plus({days:7});return{begin:v,end:this.literalNode(C.toFormat(h)).sql}}case"quarter":{const E=y.slice(0,4),A=y.slice(6);A==="1"?y=`${E}-01-01 00:00:00`:A==="2"?y=`${E}-03-01 00:00:00`:A==="3"?y=`${E}-06-01 00:00:00`:y=`${E}-09-01 00:00:00`;const _=this.literalNode(y),C=i.DateTime.fromFormat(y,h).plus({months:3});return{begin:_,end:this.literalNode(C.toFormat(h)).sql}}case void 0:case"second":{const E=this.literalNode(y);return{begin:E,end:E.sql}}}}literalNode(g){const y={node:"timeLiteral",typeDef:{type:"timestamp"},literal:g};return{...y,sql:this.d.sqlLiteralTime({},y)}}nowExpr(){return{node:"now",typeDef:{type:"timestamp"},sql:this.d.sqlNowExpr()}}n(g){return{node:"numberLiteral",literal:g,sql:g}}delta(g,y,E,A){const _={node:"delta",op:y,units:A,kids:{base:(0,r.mkTemporal)(g,"timestamp"),delta:this.n(E)}};return{..._,sql:this.d.sqlAlterTimeExpr(_)}}dayofWeek(g){const y={node:"extract",e:(0,r.mkTemporal)(g,"timestamp"),units:"day_of_week"};return{...y,sql:this.d.sqlTimeExtractExpr({},y)}}nowDot(g){const y={node:"trunc",e:this.nowExpr(),units:g};return{...y,sql:this.d.sqlTruncExpr({},y)}}thisUnit(g){const y=this.nowDot(g),E=this.delta(y,"+","1",g);return{begin:y,end:E.sql}}lastUnit(g){const y=this.nowDot(g);return{begin:this.delta(y,"-","1",g),end:y.sql}}nextUnit(g){const y=this.nowDot(g),E=this.delta(y,"+","1",g),A=this.delta(y,"+","2",g);return{begin:E,end:A.sql}}mod7(g){return this.d.hasModOperator?`(${g})%7`:`MOD(${g},7)`}moment(g){switch(g.moment){case"now":{const y=this.nowExpr();return{begin:y,end:y.sql}}case"literal":return this.expandLiteral(g);case"ago":case"from_now":{const y=this.nowDot(g.units),E=(0,r.mkTemporal)(y,"timestamp"),A=this.delta(E,g.moment==="ago"?"-":"+",g.n,g.units);if(g.moment==="ago"&&g.n==="1")return{begin:A,end:y.sql};const _=Number(g.n)+(g.moment==="ago"?-1:1),v={...A,kids:{base:E,delta:this.n(_.toString())}};return{begin:A,end:this.d.sqlAlterTimeExpr(v)}}case"today":return this.thisUnit("day");case"yesterday":return this.lastUnit("day");case"tomorrow":return this.nextUnit("day");case"this":return this.thisUnit(g.units);case"last":return this.lastUnit(g.units);case"next":return this.nextUnit(g.units);case"monday":case"tuesday":case"wednesday":case"thursday":case"friday":case"saturday":case"sunday":{const y=["sunday","monday","tuesday","wednesday","thursday","friday","saturday"].indexOf(g.moment),E=this.dayofWeek(this.nowExpr()).sql;if(g.which==="next"){const C=`${this.mod7(`${y}-(${E}-1)+6`)}+1`,S=this.delta(this.thisUnit("day").begin,"+",C,"day"),b=this.delta(this.thisUnit("day").begin,"+",`${C}+1`,"day");return{begin:S,end:b.sql}}const A=`${this.mod7(`(${E}-1)-${y}+6`)}+1`,_=this.delta(this.thisUnit("day").begin,"-",A,"day"),v=this.delta(this.thisUnit("day").begin,"-",`(${A})-1`,"day");return{begin:_,end:v.sql}}}}isIn(g,y,E){let A=">=",_="<",v="AND";return g&&(v="OR",A="<",_=">="),y=this.time(y),E=this.time(E),`${this.expr} ${A} ${y} ${v} ${this.expr} ${_} ${E}`}}t.TemporalFilterCompiler=p}(cle),Object.defineProperty(js,"__esModule",{value:!0}),js.QueryModel=js.getResultStructDefForQuery=js.getResultStructDefForView=js.Segment=void 0;const ntt=m2,rtt=h2,itt=Zy,Me=et,Fn=kt,I4=E2,stt=mi,ott=cle,$4=nE;function yle(t){return t.map(e=>encodeURIComponent(e)).join("/")}function CB(t){return`'${t}'`}function utt(t){return t.replace(/[^a-zA-Z0-9_]/g,"_o_")}function v2(t){const e=[];for(const r of t.fields.filter(Me.fieldIsIntrinsic))e.push({typeDef:r,sqlExpression:(0,Me.getIdentifier)(r),rawName:(0,Me.getIdentifier)(r),sqlOutputName:(0,Me.getIdentifier)(r)});return e}function Ele(t,e){const{sqlExpression:r,sqlOutputName:i,rawName:s}=e;(0,Me.isAtomic)(e.fieldDef)&&t.push({typeDef:e.fieldDef,sqlExpression:r,sqlOutputName:i,rawName:s})}class att extends Set{add_use(e){if(e!==void 0)return this.add(e)}hasAsymetricFunctions(){return this.has("sum")||this.has("avg")||this.has("count")||this.has("generic_asymmetric_aggregate")}}class C2{constructor(e=!0,r){this.parent=r,this.withs=[],this.udfs=[],this.pdts=[],this.dependenciesToMaterialize={},this.stagePrefix="__stage",this.useCTE=e}getName(e){return`${this.stagePrefix}${e}`}root(){return this.parent===void 0?this:this.parent.root()}addStage(e){return this.useCTE?(this.withs.push(e),this.getName(this.withs.length-1)):(this.withs[0]=e,(0,Fn.indent)(`
|
|
1441
1441
|
(${e})
|
|
1442
1442
|
`))}addUDF(e,r,i){var s;let{sql:o,lastStageName:u}=e.combineStages(!0);if(u===void 0)throw new Error("Internal Error: no stage to combine");o+=r.sqlCreateFunctionCombineLastStage(u,v2(i),(s=i.resultMetadata)===null||s===void 0?void 0:s.orderBy);const a=`${r.udfPrefix}${this.root().udfs.length}`;return o=r.sqlCreateFunction(a,o),this.root().udfs.push(o),a}addMaterializedQuery(e,r,i){var s;const o=r.name;if(!o)throw new Error(`Source ${e} on a unnamed query that is tagged as materialize, only named queries can be materialized.`);const u=(s=r.location)===null||s===void 0?void 0:s.url;if(!u)throw new Error(`Trying to materialize query ${o}, but its path is not set.`);const a=(0,I4.buildQueryMaterializationSpec)(u,o,i);return this.root().dependenciesToMaterialize[a.id]=a,a.id}addPDT(e,r){const i=this.combineStages(!1).sql+this.withs[this.withs.length-1],o=`scratch.${e+(0,Fn.generateHash)(i)}`;return this.root().pdts.push(r.sqlCreateTableAsSelect(o,i)),o}combineStages(e){if(!this.useCTE)return{sql:this.withs[0],lastStageName:this.withs[0]};let r=this.getName(0),i="WITH ",s="";for(let o=0;o<this.withs.length-(e?0:1);o++){const u=this.withs[o];if(r=this.getName(o),u===void 0)throw new Error(`Expected sql WITH to be present for stage ${r}.`);s+=`${i}${r} AS (
|
|
1443
1443
|
${(0,Fn.indent)(u)})
|
|
1444
1444
|
`,i=", "}return{sql:s,lastStageName:r}}generateSQLStages(){const e=this.withs.length-1;if(e<0)throw new Error("No SQL generated");const r=this.udfs.join(`
|
|
1445
1445
|
`),i=this.pdts.join(`
|
|
1446
|
-
`),s=this.combineStages(!1).sql;return r+i+s+this.withs[e]}generateCoorelatedSubQuery(e,r){var i,s;return this.useCTE?this.combineStages(!0).sql+e.sqlCreateFunctionCombineLastStage(this.getName(this.withs.length-1),v2(r),(s=r.resultMetadata)===null||s===void 0?void 0:s.orderBy):e.sqlCreateFunctionCombineLastStage(`(${this.withs[0]})`,v2(r),(i=r.resultMetadata)===null||i===void 0?void 0:i.orderBy)}}class iE{constructor(){this.totalGroupSet=-1}withWhere(e){const r=new iE;return r.whereSQL=e,r.applyValue=this.applyValue,r.totalGroupSet=this.totalGroupSet,r}withApply(e){const r=new iE;return r.whereSQL=this.whereSQL,r.applyValue=e,r.totalGroupSet=this.totalGroupSet,r}withTotal(e){const r=new iE;return r.whereSQL=this.whereSQL,r.applyValue=this.applyValue,r.totalGroupSet=e,r}}class
|
|
1446
|
+
`),s=this.combineStages(!1).sql;return r+i+s+this.withs[e]}generateCoorelatedSubQuery(e,r){var i,s;return this.useCTE?this.combineStages(!0).sql+e.sqlCreateFunctionCombineLastStage(this.getName(this.withs.length-1),v2(r),(s=r.resultMetadata)===null||s===void 0?void 0:s.orderBy):e.sqlCreateFunctionCombineLastStage(`(${this.withs[0]})`,v2(r),(i=r.resultMetadata)===null||i===void 0?void 0:i.orderBy)}}class iE{constructor(){this.totalGroupSet=-1}withWhere(e){const r=new iE;return r.whereSQL=e,r.applyValue=this.applyValue,r.totalGroupSet=this.totalGroupSet,r}withApply(e){const r=new iE;return r.whereSQL=this.whereSQL,r.applyValue=e,r.totalGroupSet=this.totalGroupSet,r}withTotal(e){const r=new iE;return r.whereSQL=this.whereSQL,r.applyValue=this.applyValue,r.totalGroupSet=e,r}}class ltt{constructor(e){this.referenceId=e??(0,ntt.v4)()}getChildByName(e){}}let SB=class extends ltt{constructor(e,r,i){super(i),this.fieldDef=e,this.parent=r,this.fieldDef=e}getIdentifier(){return(0,Me.getIdentifier)(this.fieldDef)}uniqueKeyPossibleUse(){}getJoinableParent(){const e=this.parent;return e.structDef.type==="record"?e.getJoinableParent():e}isAtomic(){return(0,Me.isAtomic)(this.fieldDef)}caseGroup(e,r){return e.length===0?r:`CASE WHEN group_set${e.length===1?`=${e[0]}`:` IN (${e.join(",")})`} THEN
|
|
1447
1447
|
${r}
|
|
1448
|
-
END`}getFullOutputName(){return this.parent.getFullOutputName()+this.getIdentifier()}generateFieldFragment(e,r,i,s){const o=r.getFieldByName(i.path);return(0,Me.hasExpression)(o.fieldDef)?`(${this.exprToSQL(e,o.parent,o.fieldDef.e,s)})`:o.generateExpression(e)}generateOutputFieldFragment(e,r,i,s){return`(${e.getField(i.name).getAnalyticalSQL(!1)})`}*stringsFromSQLExpression(e,r,i,s){const o=[...i.kids.args];for(const u of i.src){yield u;const a=o.shift();a&&(yield this.exprToSQL(e,r,a,s))}}getParameterMap(e,r){return new Map(e.params.map((i,s)=>{const o=i.isVariadic?(0,Fn.range)(s,r):[s];return[i.name,{param:i,argIndexes:o}]}))}expandFunctionCall(e,r,i,s,o){function u(c){const f=[];for(let x=0;x<c.length;)f.push(c[x]),x+=1,x<c.length&&f.push(",");return f}const a=this.getParameterMap(r,i.length);if(r.dialect[e]===void 0)throw new Error(`Function is not defined for '${e}' dialect`);return(0,Fn.exprMap)(r.dialect[e].e,c=>{var f,x;if(c.node==="spread"){const h=c.e;if(h.node!=="function_parameter")throw new Error("Invalid function definition. Argument to spread must be a function parameter.");const p=a.get(h.name);if(p===void 0)return c;const m=p.argIndexes.map(g=>i[g]);return(0,Fn.composeSQLExpr)(u(m))}else if(c.node==="function_parameter"){const h=a.get(c.name);if(h===void 0)return c;if(h.param.isVariadic){const p=h.argIndexes.map(m=>i[m]);return(0,Fn.composeSQLExpr)(u(p))}else return i[h.argIndexes[0]]}else{if(c.node==="aggregate_order_by")return s?(0,Fn.composeSQLExpr)([` ${(f=c.prefix)!==null&&f!==void 0?f:""}${s}${(x=c.suffix)!==null&&x!==void 0?x:""}`]):{node:""};if(c.node==="aggregate_limit")return o?(0,Fn.composeSQLExpr)([` ${o}`]):{node:""}}return c})}getFunctionOrderBy(e,r,i,s,o,u){if(s.length!==0)return"ORDER BY "+s.map(a=>{var l;const c=(l=u.dialect[r.dialect.name].defaultOrderByArgIndex)!==null&&l!==void 0?l:0,f=a.node==="functionOrderBy"?a.e:o[c],x=this.generateDimFragment(e,r,f,i),h=a.dir==="asc"?" ASC":a.dir==="desc"?" DESC":"";return`${x}${h}`}).join(", ")}generateAsymmetricStringAggExpression(e,r,i,s,o,u,a,l){if(u)throw new Error(`Function \`string_agg\` does not support fanning out with an order by in ${a}`);const c=this.generateDimFragment(e,r,i,l),f=s?this.generateDimFragment(e,r,s,l):"";return this.parent.dialect.sqlStringAggDistinct(o,c,f)}getParamForArgIndex(e,r){const i=e.slice(0,r).find(s=>s.isVariadic);return i??e[r]}generateFunctionCallExpression(e,r,i,s){var o,u,a;const l=i.overload,c=i.kids.args,f=(o=i.overload.isSymmetric)!==null&&o!==void 0?o:!1,x=(0,Me.expressionIsAggregate)(l.returnType.expressionType)&&!f&&this.generateDistinctKeyIfNecessary(e,r,i.structPath),h=i.limit?`LIMIT ${i.limit}`:void 0;if(i.name==="string_agg"&&x&&!r.dialect.supportsAggDistinct&&r.dialect.name!=="snowflake")return this.generateAsymmetricStringAggExpression(e,r,c[0],c[1],x,i.kids.orderBy,r.dialect.name,s);if(x){if(!r.dialect.supportsAggDistinct)throw new Error(`Function \`${i.name}\` does not support fanning out in ${r.dialect.name}`);const p=c.map(y=>this.generateDimFragment(e,r,y,s)),m=(u=i.kids.orderBy)!==null&&u!==void 0?u:[],g=m.map(y=>{var E;const A=(E=l.dialect[r.dialect.name].defaultOrderByArgIndex)!==null&&E!==void 0?E:0,_=y.node==="functionOrderBy"?y.e:c[A];return this.generateDimFragment(e,r,_,s)});return r.dialect.sqlAggDistinct(x,[...p,...g],y=>{const E=y.map((S,b)=>b<c.length&&this.getParamForArgIndex(l.params,b).allowedTypes.every(O=>(0,Me.isLiteral)(O.evalSpace))?c[b]:(0,Fn.composeSQLExpr)([S])),A=E.slice(0,p.length),_=E.slice(p.length).map((S,b)=>({node:"functionOrderBy",e:S,dir:m[b].dir})),v=this.getFunctionOrderBy(e,r,s,_,A,l),C=this.expandFunctionCall(r.dialect.name,l,A,v,h);return this.exprToSQL(e,r,C,s)})}else{const p=(0,Me.expressionIsAggregate)(l.returnType.expressionType)?c.map((y,E)=>this.getParamForArgIndex(l.params,E).allowedTypes.every(_=>(0,Me.isLiteral)(_.evalSpace))?y:(0,Fn.composeSQLExpr)([this.generateDimFragment(e,r,y,s)])):c,m=i.kids.orderBy?this.getFunctionOrderBy(e,r,s,i.kids.orderBy,c,l):"",g=this.expandFunctionCall(r.dialect.name,l,p,m,h);if((0,Me.expressionIsAnalytic)(l.returnType.expressionType)){const y=((a=i.partitionBy)!==null&&a!==void 0?a:[]).map(E=>`(${e.getField(E).getAnalyticalSQL(!1)})`);return this.generateAnalyticFragment(r.dialect.name,e,r,g,l,s,c,y,m)}return this.exprToSQL(e,r,g,s)}}generateSpread(e,r,i,s){throw new Error("Unexpanded spread encountered during SQL generation")}generateParameterFragment(e,r,i,s){var o;const u=i.path[0];(o=r.eventStream)===null||o===void 0||o.emit("source-argument-compiled",{name:u});const a=r.arguments()[u];if(a.value)return this.exprToSQL(e,r,a.value,s);throw new Error(`Can't generate SQL, no value for ${i.path}`)}generateFilterFragment(e,r,i,s){const o=new Fn.AndChain(s.whereSQL);for(const u of i.kids.filterList)o.add(this.exprToSQL(e,r,u.e,s.withWhere()));return this.exprToSQL(e,r,i.kids.e,s.withWhere(o.sql()))}generateDimFragment(e,r,i,s){let o=this.exprToSQL(e,r,i,s);return s.whereSQL&&(o=`CASE WHEN ${s.whereSQL} THEN ${o} END`),o}generateUngroupedFragment(e,r,i,s){if(s.totalGroupSet!==-1)throw new Error("Already in ALL. Cannot nest within an all calcuation.");let o,u;if(i.fields&&i.fields.length>0){const x=i.fields.sort().join("|")+i.node;if(u=e.ungroupedSets.get(x),u===void 0)throw new Error(`Internal Error, cannot find groupset with key ${x}`);o=u.groupSet}else o=e.parent?e.parent.groupSet:0;const a=this.exprToSQL(e,r,i.e,s.withTotal(o)),l=e.getUngroupPartitions(u);let c="";const f=l.map(x=>x.getAnalyticalSQL(!0)).join(", ");return f.length>0&&(c=`PARTITION BY ${f}`),`MAX(${a}) OVER (${c})`}generateDistinctKeyIfNecessary(e,r,i){let s=r;if(i&&(s=this.parent.root().getStructByName(i)),s.needsSymetricCalculation(e))return s.getDistinctKey().generateExpression(e)}generateSumFragment(e,r,i,s){const o=this.generateDimFragment(e,r,i.e,s),u=this.generateDistinctKeyIfNecessary(e,r,i.structPath);let a;return u?this.parent.dialect.supportsSumDistinctFunction?a=this.parent.dialect.sqlSumDistinct(u,o,"SUM"):a=vle(this.parent.dialect,o,u):a=`SUM(${o})`,`COALESCE(${a},0)`}generateSymmetricFragment(e,r,i,s){const o=this.generateDimFragment(e,r,i.e,s);return`${i.function==="distinct"?"count(distinct ":i.function+"("}${o})`}generateAvgFragment(e,r,i,s){const o=this.generateDimFragment(e,r,i.e,s),u=this.generateDistinctKeyIfNecessary(e,r,i.structPath);if(u){let a=u;s.whereSQL&&(a=`CASE WHEN ${s.whereSQL} THEN ${u} END`);let l,c;return this.parent.dialect.supportsSumDistinctFunction?c=this.parent.dialect.sqlSumDistinct(u,o,"AVG"):(l=vle(this.parent.dialect,o,u),c=`(${l})/NULLIF(COUNT(DISTINCT CASE WHEN ${o} IS NOT NULL THEN ${a} END),0)`),c}else return`AVG(${o})`}generateCountFragment(e,r,i,s){let o="COUNT(",u="1",a=r;i.structPath&&(a=this.parent.root().getStructByName(i.structPath));const l=a.getJoinableParent().getIdentifier(),c=e.root().joins.get(l);if(!c)throw new Error(`Join ${l} not found in result set`);return(!c.leafiest||c.makeUniqueKey)&&(o="COUNT(DISTINCT ",u=a.getDistinctKey().generateExpression(e)),s.whereSQL?`${o}CASE WHEN ${s.whereSQL} THEN ${u} END)`:`${o}${u})`}generateSourceReference(e,r,i){return i.path===void 0?r.getSQLIdentifier():r.getFieldByName(i.path).getIdentifier()}getAnalyticPartitions(e,r){const i=[];let s=e.parent;for(;s!==void 0;){const u=s.fields(a=>S2(a.f)&&a.fieldUsage.type==="result").map(a=>a.getAnalyticalSQL(!0));i.push(...u),s=s.parent}return r&&i.push(...r),i}generateAnalyticFragment(e,r,i,s,o,u,a,l,c){const f=r.root().isComplexQuery,x=this.getAnalyticPartitions(r,l),h=[...f?["group_set"]:[],...x],p=h.length>0?`PARTITION BY ${h.join(", ")}`:"";let m=c??"";const g=o.dialect[e];if(!c&&g.needsWindowOrderBy){const _=[];let v;const C=r.firstSegment.orderBy||r.calculateDefaultOrderBy();for(const S of C){typeof S.field=="string"?v={name:S.field,fif:r.getField(S.field)}:v=r.getFieldByNumber(S.field);const b=v.fif.f.fieldDef.expressionType;if(!(0,Me.expressionIsAnalytic)(b))if(r.firstSegment.type==="reduce"){const R=v.fif.getAnalyticalSQL(!1);_.push(` ${R} ${S.dir||"ASC"}`)}else r.firstSegment.type==="project"&&_.push(` ${v.fif.f.generateExpression(r)} ${S.dir||"ASC"}`)}_.length>0&&(m=" "+this.parent.dialect.sqlOrderBy(_,"analytical"))}let y="";if(g.between){const[_,v]=[g.between.preceding,g.between.following].map(C=>{if(C===-1)return"UNBOUNDED";if(typeof C=="number")return C;const S=o.params.findIndex(R=>R.name===C),b=a[S];if(b.node!=="numberLiteral")throw new Error("Invalid number of rows for window spec");return b.literal});y=`ROWS BETWEEN ${_} PRECEDING AND ${v} FOLLOWING`}let A=`${this.exprToSQL(r,i,s,u)} OVER(${p} ${m} ${y})`;return f&&(A=`CASE WHEN group_set=${r.groupSet} THEN ${A} END`),A}generateCaseSQL(e){const r=["CASE"];e.kids.caseValue!==void 0&&r.push(`${e.kids.caseValue.sql}`);for(let i=0;i<e.kids.caseWhen.length;i+=1)r.push(`WHEN ${e.kids.caseWhen[i].sql} THEN ${e.kids.caseThen[i].sql}`);return e.kids.caseElse!==void 0&&r.push(`ELSE ${e.kids.caseElse.sql}`),r.push("END"),r.join(" ")}exprToSQL(e,r,i,s=new iE){var o;const u=function(f,x){const h=f.exprToSQL(e,r,x,s);return(0,Me.exprHasKids)(x)?`(${h})`:h};let a=i;if((0,Me.exprHasE)(i)){a={...i};const f=u(this,a.e);a.e={...a.e,sql:f}}else if((0,Me.exprHasKids)(i)){a={...i};const f=i.kids;for(const[x,h]of Object.entries(f))h!==null&&(Array.isArray(h)?a.kids[x]=h.map(p=>({...p,sql:u(this,p)})):a.kids[x]={...f[x],sql:u(this,h)})}const l=e.getQueryInfo(),c=this.parent.dialect.exprToSQL(l,a);if(c)return c;switch(a.node){case"field":return this.generateFieldFragment(e,r,a,s);case"parameter":return this.generateParameterFragment(e,r,a,s);case"filteredExpr":return this.generateFilterFragment(e,r,a,s);case"all":case"exclude":return this.generateUngroupedFragment(e,r,a,s);case"genericSQLExpr":return Array.from(this.stringsFromSQLExpression(e,r,a,s)).join("");case"aggregate":{let f="";if(a.function==="sum")f=this.generateSumFragment(e,r,a,s);else if(a.function==="avg")f=this.generateAvgFragment(e,r,a,s);else if(a.function==="count")f=this.generateCountFragment(e,r,a,s);else if(a.function==="min"||a.function==="max"||a.function==="distinct")f=this.generateSymmetricFragment(e,r,a,s);else throw new Error(`Internal Error: Unknown aggregate function ${a.function}`);if(e.root().isComplexQuery){let x=e.groupSet;return s.totalGroupSet!==-1&&(x=s.totalGroupSet),this.caseGroup([x],f)}return f}case"function_parameter":throw new Error("Internal Error: Function parameter fragment remaining during SQL generation");case"outputField":return this.generateOutputFieldFragment(e,r,a,s);case"function_call":return this.generateFunctionCallExpression(e,r,a,s);case"spread":return this.generateSpread(e,r,a,s);case"source-reference":return this.generateSourceReference(e,r,a);case"+":case"-":case"*":case"%":case"/":case">":case"<":case">=":case"<=":case"=":return`${a.kids.left.sql}${a.node}${a.kids.right.sql}`;case"!=":return`COALESCE(${`${a.kids.left.sql}!=${a.kids.right.sql}`},true)`;case"and":case"or":return`${a.kids.left.sql} ${a.node} ${a.kids.right.sql}`;case"coalesce":return`COALESCE(${a.kids.left.sql},${a.kids.right.sql})`;case"in":{const f=a.kids.oneOf.map(x=>x.sql).join(",");return`${a.kids.e.sql} ${a.not?"NOT IN":"IN"} (${f})`}case"like":case"!like":{const f=a.node==="like"?"LIKE":"NOT LIKE",x=a.kids.right.node==="stringLiteral"?this.parent.dialect.sqlLike(f,(o=a.kids.left.sql)!==null&&o!==void 0?o:"",a.kids.right.literal):`${a.kids.left.sql} ${f} ${a.kids.right.sql}`;return a.node==="like"?x:`COALESCE(${x},true)`}case"()":return`(${a.e.sql})`;case"not":return`COALESCE(NOT ${a.e.sql},TRUE)`;case"unary-":return`-${a.e.sql}`;case"is-null":return`${a.e.sql} IS NULL`;case"is-not-null":return`${a.e.sql} IS NOT NULL`;case"true":case"false":return a.node;case"null":return"NULL";case"case":return this.generateCaseSQL(a);case"":return"";case"filterCondition":return a.e.sql?(a.sql=a.e.sql,a.sql):"";case"functionDefaultOrderBy":case"functionOrderBy":return"";case"compositeField":return"{COMPOSITE_FIELD}";case"filterMatch":return this.generateAppliedFilter(r,a);case"filterLiteral":return"INTERNAL ERROR FILTER EXPRESSION VALUE SHOULD NOT BE USED";default:throw new Error(`Internal Error: Unknown expression node '${a.node}' ${JSON.stringify(a,void 0,2)}`)}}generateAppliedFilter(e,r){var i;let s=r.kids.filterExpr;for(;s.node==="()";)s=s.e;if(s.node==="parameter"){const a=s.path[0];(i=e.eventStream)===null||i===void 0||i.emit("source-argument-compiled",{name:a});const l=e.arguments()[a];if(l.value)s=l.value;else throw new Error(`Parameter ${a} was expected to be a filter expression`)}if(s.node!=="filterLiteral")throw new Error("Can only use filter expression literals or parameters as filter expressions");const o=s.filterSrc;let u;switch(r.dataType){case"string":u=$4.StringFilterExpression.parse(o);break;case"number":u=$4.NumberFilterExpression.parse(o);break;case"boolean":u=$4.BooleanFilterExpression.parse(o);break;case"date":case"timestamp":u=$4.TemporalFilterExpression.parse(o);break}if(u.log.length>0)throw new Error(`Filter expression parse error: ${u.log[0]}`);return itt.FilterCompilers.compile(r.dataType,u.parsed,r.kids.expr.sql||"",e.dialect)}isNestedInParent(e){switch(e.type){case"record":case"array":return!0;default:return!1}}isArrayElement(e){return e.type==="array"&&e.elementTypeDef.type!=="record_element"}generateExpression(e){if((0,Me.hasExpression)(this.fieldDef))return this.exprToSQL(e,this.parent,this.fieldDef.e);for(let r=this.parent;r!==void 0;r=r.parent)if(r.structDef.type==="record"&&(0,Me.hasExpression)(r.structDef)&&r.recordAlias===void 0){if(!r.parent)throw new Error("Inconcievable record ancestor with expression but no parent");const i=this.exprToSQL(e,r.parent,r.structDef.e);r.informOfAliasValue(i)}return this.parent.sqlChildReference(this.fieldDef.name,this.parent.structDef.type==="record"?{result:e,field:this}:void 0)}includeInWildcard(){return!1}};function B4(t){return t instanceof qs&&att(t)}function Ale(t){return t instanceof qs&<t(t)}function S2(t){return t instanceof qs&&To(t)}function To(t){if(t.isAtomic()){if((0,Me.hasExpression)(t.fieldDef)){const e=t.fieldDef.expressionType;if((0,Me.expressionIsCalculation)(e)||(0,Me.expressionIsAggregate)(e))return!1}return!0}return!1}function att(t){return t.isAtomic()&&(0,Me.hasExpression)(t.fieldDef)?(0,Me.expressionIsCalculation)(t.fieldDef.expressionType):!1}function ltt(t){return t.isAtomic()&&(0,Me.hasExpression)(t.fieldDef)?(0,Me.expressionIsAggregate)(t.fieldDef.expressionType):!1}class qs extends SB{constructor(e,r,i){super(e,r,i),this.fieldDef=e}includeInWildcard(){return!0}getFilterList(){return[]}}class ctt extends qs{}class ftt extends qs{}class bB extends qs{}class xtt extends qs{}class dtt extends qs{}class TB extends qs{generateExpression(e){const r=this.fieldDef,i=super.generateExpression(e);if(r.timeframe){const s={node:"trunc",e:(0,Me.mkTemporal)({node:"genericSQLExpr",src:[i],kids:{args:[]}},"date"),units:r.timeframe};return this.exprToSQL(e,this.parent,s)}else return i}getChildByName(e){const r={...this.fieldDef,as:`${this.getIdentifier()}_${e}`,timeframe:e};return new TB(r,this.parent)}}class RB extends qs{getChildByName(e){const r={...this.fieldDef,as:`${this.getIdentifier()}_${e}`,timeframe:e};return new RB(r,this.parent)}}class htt extends qs{generateExpression(e){var r;if(this.parent.primaryKey())return this.parent.getPrimaryKeyField(this.fieldDef).generateExpression(e);if(this.parent.structDef.type==="array"){const i=(r=this.parent.parent)===null||r===void 0?void 0:r.getDistinctKey().generateExpression(e);return this.parent.dialect.sqlMakeUnnestKey(i||"",this.parent.dialect.sqlFieldReference(this.parent.getIdentifier(),"table","__row_id","string"))}else return this.parent.dialect.sqlFieldReference(this.parent.getIdentifier(),"table","__distinct_key","string")}includeInWildcard(){return!1}}const _le=9;function vle(t,e,r){const s=t.sqlSumDistinctHashedKey(r),o=10**(9-_le);let a=`(${`
|
|
1448
|
+
END`}getFullOutputName(){return this.parent.getFullOutputName()+this.getIdentifier()}generateFieldFragment(e,r,i,s){const o=r.getFieldByName(i.path);return(0,Me.hasExpression)(o.fieldDef)?`(${this.exprToSQL(e,o.parent,o.fieldDef.e,s)})`:o.generateExpression(e)}generateOutputFieldFragment(e,r,i,s){return`(${e.getField(i.name).getAnalyticalSQL(!1)})`}*stringsFromSQLExpression(e,r,i,s){const o=[...i.kids.args];for(const u of i.src){yield u;const a=o.shift();a&&(yield this.exprToSQL(e,r,a,s))}}getParameterMap(e,r){return new Map(e.params.map((i,s)=>{const o=i.isVariadic?(0,Fn.range)(s,r):[s];return[i.name,{param:i,argIndexes:o}]}))}expandFunctionCall(e,r,i,s,o){function u(c){const f=[];for(let x=0;x<c.length;)f.push(c[x]),x+=1,x<c.length&&f.push(",");return f}const a=this.getParameterMap(r,i.length);if(r.dialect[e]===void 0)throw new Error(`Function is not defined for '${e}' dialect`);return(0,Fn.exprMap)(r.dialect[e].e,c=>{var f,x;if(c.node==="spread"){const h=c.e;if(h.node!=="function_parameter")throw new Error("Invalid function definition. Argument to spread must be a function parameter.");const p=a.get(h.name);if(p===void 0)return c;const m=p.argIndexes.map(g=>i[g]);return(0,Fn.composeSQLExpr)(u(m))}else if(c.node==="function_parameter"){const h=a.get(c.name);if(h===void 0)return c;if(h.param.isVariadic){const p=h.argIndexes.map(m=>i[m]);return(0,Fn.composeSQLExpr)(u(p))}else return i[h.argIndexes[0]]}else{if(c.node==="aggregate_order_by")return s?(0,Fn.composeSQLExpr)([` ${(f=c.prefix)!==null&&f!==void 0?f:""}${s}${(x=c.suffix)!==null&&x!==void 0?x:""}`]):{node:""};if(c.node==="aggregate_limit")return o?(0,Fn.composeSQLExpr)([` ${o}`]):{node:""}}return c})}getFunctionOrderBy(e,r,i,s,o,u){if(s.length!==0)return"ORDER BY "+s.map(a=>{var l;const c=(l=u.dialect[r.dialect.name].defaultOrderByArgIndex)!==null&&l!==void 0?l:0,f=a.node==="functionOrderBy"?a.e:o[c],x=this.generateDimFragment(e,r,f,i),h=a.dir==="asc"?" ASC":a.dir==="desc"?" DESC":"";return`${x}${h}`}).join(", ")}generateAsymmetricStringAggExpression(e,r,i,s,o,u,a,l){if(u)throw new Error(`Function \`string_agg\` does not support fanning out with an order by in ${a}`);const c=this.generateDimFragment(e,r,i,l),f=s?this.generateDimFragment(e,r,s,l):"";return this.parent.dialect.sqlStringAggDistinct(o,c,f)}getParamForArgIndex(e,r){const i=e.slice(0,r).find(s=>s.isVariadic);return i??e[r]}generateFunctionCallExpression(e,r,i,s){var o,u,a;const l=i.overload,c=i.kids.args,f=(o=i.overload.isSymmetric)!==null&&o!==void 0?o:!1,x=(0,Me.expressionIsAggregate)(l.returnType.expressionType)&&!f&&this.generateDistinctKeyIfNecessary(e,r,i.structPath),h=i.limit?`LIMIT ${i.limit}`:void 0;if(i.name==="string_agg"&&x&&!r.dialect.supportsAggDistinct&&r.dialect.name!=="snowflake")return this.generateAsymmetricStringAggExpression(e,r,c[0],c[1],x,i.kids.orderBy,r.dialect.name,s);if(x){if(!r.dialect.supportsAggDistinct)throw new Error(`Function \`${i.name}\` does not support fanning out in ${r.dialect.name}`);const p=c.map(y=>this.generateDimFragment(e,r,y,s)),m=(u=i.kids.orderBy)!==null&&u!==void 0?u:[],g=m.map(y=>{var E;const A=(E=l.dialect[r.dialect.name].defaultOrderByArgIndex)!==null&&E!==void 0?E:0,_=y.node==="functionOrderBy"?y.e:c[A];return this.generateDimFragment(e,r,_,s)});return r.dialect.sqlAggDistinct(x,[...p,...g],y=>{const E=y.map((S,b)=>b<c.length&&this.getParamForArgIndex(l.params,b).allowedTypes.every(O=>(0,Me.isLiteral)(O.evalSpace))?c[b]:(0,Fn.composeSQLExpr)([S])),A=E.slice(0,p.length),_=E.slice(p.length).map((S,b)=>({node:"functionOrderBy",e:S,dir:m[b].dir})),v=this.getFunctionOrderBy(e,r,s,_,A,l),C=this.expandFunctionCall(r.dialect.name,l,A,v,h);return this.exprToSQL(e,r,C,s)})}else{const p=(0,Me.expressionIsAggregate)(l.returnType.expressionType)?c.map((y,E)=>this.getParamForArgIndex(l.params,E).allowedTypes.every(_=>(0,Me.isLiteral)(_.evalSpace))?y:(0,Fn.composeSQLExpr)([this.generateDimFragment(e,r,y,s)])):c,m=i.kids.orderBy?this.getFunctionOrderBy(e,r,s,i.kids.orderBy,c,l):"",g=this.expandFunctionCall(r.dialect.name,l,p,m,h);if((0,Me.expressionIsAnalytic)(l.returnType.expressionType)){const y=((a=i.partitionBy)!==null&&a!==void 0?a:[]).map(E=>`(${e.getField(E).getAnalyticalSQL(!1)})`);return this.generateAnalyticFragment(r.dialect.name,e,r,g,l,s,c,y,m)}return this.exprToSQL(e,r,g,s)}}generateSpread(e,r,i,s){throw new Error("Unexpanded spread encountered during SQL generation")}generateParameterFragment(e,r,i,s){var o;const u=i.path[0];(o=r.eventStream)===null||o===void 0||o.emit("source-argument-compiled",{name:u});const a=r.arguments()[u];if(a.value)return this.exprToSQL(e,r,a.value,s);throw new Error(`Can't generate SQL, no value for ${i.path}`)}generateFilterFragment(e,r,i,s){const o=new Fn.AndChain(s.whereSQL);for(const u of i.kids.filterList)o.add(this.exprToSQL(e,r,u.e,s.withWhere()));return this.exprToSQL(e,r,i.kids.e,s.withWhere(o.sql()))}generateDimFragment(e,r,i,s){let o=this.exprToSQL(e,r,i,s);return s.whereSQL&&(o=`CASE WHEN ${s.whereSQL} THEN ${o} END`),o}generateUngroupedFragment(e,r,i,s){if(s.totalGroupSet!==-1)throw new Error("Already in ALL. Cannot nest within an all calcuation.");let o,u;if(i.fields&&i.fields.length>0){const x=i.fields.sort().join("|")+i.node;if(u=e.ungroupedSets.get(x),u===void 0)throw new Error(`Internal Error, cannot find groupset with key ${x}`);o=u.groupSet}else o=e.parent?e.parent.groupSet:0;const a=this.exprToSQL(e,r,i.e,s.withTotal(o)),l=e.getUngroupPartitions(u);let c="";const f=l.map(x=>x.getAnalyticalSQL(!0)).join(", ");return f.length>0&&(c=`PARTITION BY ${f}`),`MAX(${a}) OVER (${c})`}generateDistinctKeyIfNecessary(e,r,i){let s=r;if(i&&(s=this.parent.root().getStructByName(i)),s.needsSymetricCalculation(e))return s.getDistinctKey().generateExpression(e)}generateSumFragment(e,r,i,s){const o=this.generateDimFragment(e,r,i.e,s),u=this.generateDistinctKeyIfNecessary(e,r,i.structPath);let a;return u?this.parent.dialect.supportsSumDistinctFunction?a=this.parent.dialect.sqlSumDistinct(u,o,"SUM"):a=vle(this.parent.dialect,o,u):a=`SUM(${o})`,`COALESCE(${a},0)`}generateSymmetricFragment(e,r,i,s){const o=this.generateDimFragment(e,r,i.e,s);return`${i.function==="distinct"?"count(distinct ":i.function+"("}${o})`}generateAvgFragment(e,r,i,s){const o=this.generateDimFragment(e,r,i.e,s),u=this.generateDistinctKeyIfNecessary(e,r,i.structPath);if(u){let a=u;s.whereSQL&&(a=`CASE WHEN ${s.whereSQL} THEN ${u} END`);let l,c;return this.parent.dialect.supportsSumDistinctFunction?c=this.parent.dialect.sqlSumDistinct(u,o,"AVG"):(l=vle(this.parent.dialect,o,u),c=`(${l})/NULLIF(COUNT(DISTINCT CASE WHEN ${o} IS NOT NULL THEN ${a} END),0)`),c}else return`AVG(${o})`}generateCountFragment(e,r,i,s){let o="COUNT(",u="1",a=r;i.structPath&&(a=this.parent.root().getStructByName(i.structPath));const l=a.getJoinableParent().getIdentifier(),c=e.root().joins.get(l);if(!c)throw new Error(`Join ${l} not found in result set`);return(!c.leafiest||c.makeUniqueKey)&&(o="COUNT(DISTINCT ",u=a.getDistinctKey().generateExpression(e)),s.whereSQL?`${o}CASE WHEN ${s.whereSQL} THEN ${u} END)`:`${o}${u})`}generateSourceReference(e,r,i){return i.path===void 0?r.getSQLIdentifier():r.getFieldByName(i.path).getIdentifier()}getAnalyticPartitions(e,r){const i=[];let s=e.parent;for(;s!==void 0;){const u=s.fields(a=>S2(a.f)&&a.fieldUsage.type==="result").map(a=>a.getAnalyticalSQL(!0));i.push(...u),s=s.parent}return r&&i.push(...r),i}generateAnalyticFragment(e,r,i,s,o,u,a,l,c){const f=r.root().isComplexQuery,x=this.getAnalyticPartitions(r,l),h=[...f?["group_set"]:[],...x],p=h.length>0?`PARTITION BY ${h.join(", ")}`:"";let m=c??"";const g=o.dialect[e];if(!c&&g.needsWindowOrderBy){const _=[];let v;const C=r.firstSegment.orderBy||r.calculateDefaultOrderBy();for(const S of C){typeof S.field=="string"?v={name:S.field,fif:r.getField(S.field)}:v=r.getFieldByNumber(S.field);const b=v.fif.f.fieldDef.expressionType;if(!(0,Me.expressionIsAnalytic)(b))if(r.firstSegment.type==="reduce"){const R=v.fif.getAnalyticalSQL(!1);_.push(` ${R} ${S.dir||"ASC"}`)}else r.firstSegment.type==="project"&&_.push(` ${v.fif.f.generateExpression(r)} ${S.dir||"ASC"}`)}_.length>0&&(m=" "+this.parent.dialect.sqlOrderBy(_,"analytical"))}let y="";if(g.between){const[_,v]=[g.between.preceding,g.between.following].map(C=>{if(C===-1)return"UNBOUNDED";if(typeof C=="number")return C;const S=o.params.findIndex(R=>R.name===C),b=a[S];if(b.node!=="numberLiteral")throw new Error("Invalid number of rows for window spec");return b.literal});y=`ROWS BETWEEN ${_} PRECEDING AND ${v} FOLLOWING`}let A=`${this.exprToSQL(r,i,s,u)} OVER(${p} ${m} ${y})`;return f&&(A=`CASE WHEN group_set=${r.groupSet} THEN ${A} END`),A}generateCaseSQL(e){const r=["CASE"];e.kids.caseValue!==void 0&&r.push(`${e.kids.caseValue.sql}`);for(let i=0;i<e.kids.caseWhen.length;i+=1)r.push(`WHEN ${e.kids.caseWhen[i].sql} THEN ${e.kids.caseThen[i].sql}`);return e.kids.caseElse!==void 0&&r.push(`ELSE ${e.kids.caseElse.sql}`),r.push("END"),r.join(" ")}exprToSQL(e,r,i,s=new iE){var o;const u=function(f,x){const h=f.exprToSQL(e,r,x,s);return(0,Me.exprHasKids)(x)?`(${h})`:h};let a=i;if((0,Me.exprHasE)(i)){a={...i};const f=u(this,a.e);a.e={...a.e,sql:f}}else if((0,Me.exprHasKids)(i)){a={...i};const f=i.kids;for(const[x,h]of Object.entries(f))h!==null&&(Array.isArray(h)?a.kids[x]=h.map(p=>({...p,sql:u(this,p)})):a.kids[x]={...f[x],sql:u(this,h)})}const l=e.getQueryInfo(),c=this.parent.dialect.exprToSQL(l,a);if(c)return c;switch(a.node){case"field":return this.generateFieldFragment(e,r,a,s);case"parameter":return this.generateParameterFragment(e,r,a,s);case"filteredExpr":return this.generateFilterFragment(e,r,a,s);case"all":case"exclude":return this.generateUngroupedFragment(e,r,a,s);case"genericSQLExpr":return Array.from(this.stringsFromSQLExpression(e,r,a,s)).join("");case"aggregate":{let f="";if(a.function==="sum")f=this.generateSumFragment(e,r,a,s);else if(a.function==="avg")f=this.generateAvgFragment(e,r,a,s);else if(a.function==="count")f=this.generateCountFragment(e,r,a,s);else if(a.function==="min"||a.function==="max"||a.function==="distinct")f=this.generateSymmetricFragment(e,r,a,s);else throw new Error(`Internal Error: Unknown aggregate function ${a.function}`);if(e.root().isComplexQuery){let x=e.groupSet;return s.totalGroupSet!==-1&&(x=s.totalGroupSet),this.caseGroup([x],f)}return f}case"function_parameter":throw new Error("Internal Error: Function parameter fragment remaining during SQL generation");case"outputField":return this.generateOutputFieldFragment(e,r,a,s);case"function_call":return this.generateFunctionCallExpression(e,r,a,s);case"spread":return this.generateSpread(e,r,a,s);case"source-reference":return this.generateSourceReference(e,r,a);case"+":case"-":case"*":case"%":case"/":case">":case"<":case">=":case"<=":case"=":return`${a.kids.left.sql}${a.node}${a.kids.right.sql}`;case"!=":return`COALESCE(${`${a.kids.left.sql}!=${a.kids.right.sql}`},true)`;case"and":case"or":return`${a.kids.left.sql} ${a.node} ${a.kids.right.sql}`;case"coalesce":return`COALESCE(${a.kids.left.sql},${a.kids.right.sql})`;case"in":{const f=a.kids.oneOf.map(x=>x.sql).join(",");return`${a.kids.e.sql} ${a.not?"NOT IN":"IN"} (${f})`}case"like":case"!like":{const f=a.node==="like"?"LIKE":"NOT LIKE",x=a.kids.right.node==="stringLiteral"?this.parent.dialect.sqlLike(f,(o=a.kids.left.sql)!==null&&o!==void 0?o:"",a.kids.right.literal):`${a.kids.left.sql} ${f} ${a.kids.right.sql}`;return a.node==="like"?x:`COALESCE(${x},true)`}case"()":return`(${a.e.sql})`;case"not":return`COALESCE(NOT ${a.e.sql},TRUE)`;case"unary-":return`-${a.e.sql}`;case"is-null":return`${a.e.sql} IS NULL`;case"is-not-null":return`${a.e.sql} IS NOT NULL`;case"true":case"false":return a.node;case"null":return"NULL";case"case":return this.generateCaseSQL(a);case"":return"";case"filterCondition":return a.e.sql?(a.sql=a.e.sql,a.sql):"";case"functionDefaultOrderBy":case"functionOrderBy":return"";case"compositeField":return"{COMPOSITE_FIELD}";case"filterMatch":return this.generateAppliedFilter(r,a);case"filterLiteral":return"INTERNAL ERROR FILTER EXPRESSION VALUE SHOULD NOT BE USED";default:throw new Error(`Internal Error: Unknown expression node '${a.node}' ${JSON.stringify(a,void 0,2)}`)}}generateAppliedFilter(e,r){var i;let s=r.kids.filterExpr;for(;s.node==="()";)s=s.e;if(s.node==="parameter"){const a=s.path[0];(i=e.eventStream)===null||i===void 0||i.emit("source-argument-compiled",{name:a});const l=e.arguments()[a];if(l.value)s=l.value;else throw new Error(`Parameter ${a} was expected to be a filter expression`)}if(s.node!=="filterLiteral")throw new Error("Can only use filter expression literals or parameters as filter expressions");const o=s.filterSrc;let u;switch(r.dataType){case"string":u=$4.StringFilterExpression.parse(o);break;case"number":u=$4.NumberFilterExpression.parse(o);break;case"boolean":u=$4.BooleanFilterExpression.parse(o);break;case"date":case"timestamp":u=$4.TemporalFilterExpression.parse(o);break}if(u.log.length>0)throw new Error(`Filter expression parse error: ${u.log[0]}`);return ott.FilterCompilers.compile(r.dataType,u.parsed,r.kids.expr.sql||"",e.dialect)}isNestedInParent(e){switch(e.type){case"record":case"array":return!0;default:return!1}}isArrayElement(e){return e.type==="array"&&e.elementTypeDef.type!=="record_element"}generateExpression(e){if((0,Me.hasExpression)(this.fieldDef))return this.exprToSQL(e,this.parent,this.fieldDef.e);for(let r=this.parent;r!==void 0;r=r.parent)if(r.structDef.type==="record"&&(0,Me.hasExpression)(r.structDef)&&r.recordAlias===void 0){if(!r.parent)throw new Error("Inconcievable record ancestor with expression but no parent");const i=this.exprToSQL(e,r.parent,r.structDef.e);r.informOfAliasValue(i)}return this.parent.sqlChildReference(this.fieldDef.name,this.parent.structDef.type==="record"?{result:e,field:this}:void 0)}includeInWildcard(){return!1}};function B4(t){return t instanceof qs&&ctt(t)}function Ale(t){return t instanceof qs&&ftt(t)}function S2(t){return t instanceof qs&&To(t)}function To(t){if(t.isAtomic()){if((0,Me.hasExpression)(t.fieldDef)){const e=t.fieldDef.expressionType;if((0,Me.expressionIsCalculation)(e)||(0,Me.expressionIsAggregate)(e))return!1}return!0}return!1}function ctt(t){return t.isAtomic()&&(0,Me.hasExpression)(t.fieldDef)?(0,Me.expressionIsCalculation)(t.fieldDef.expressionType):!1}function ftt(t){return t.isAtomic()&&(0,Me.hasExpression)(t.fieldDef)?(0,Me.expressionIsAggregate)(t.fieldDef.expressionType):!1}class qs extends SB{constructor(e,r,i){super(e,r,i),this.fieldDef=e}includeInWildcard(){return!0}getFilterList(){return[]}}class xtt extends qs{}class dtt extends qs{}class bB extends qs{}class htt extends qs{}class ptt extends qs{}class TB extends qs{generateExpression(e){const r=this.fieldDef,i=super.generateExpression(e);if(r.timeframe){const s={node:"trunc",e:(0,Me.mkTemporal)({node:"genericSQLExpr",src:[i],kids:{args:[]}},"date"),units:r.timeframe};return this.exprToSQL(e,this.parent,s)}else return i}getChildByName(e){const r={...this.fieldDef,as:`${this.getIdentifier()}_${e}`,timeframe:e};return new TB(r,this.parent)}}class RB extends qs{getChildByName(e){const r={...this.fieldDef,as:`${this.getIdentifier()}_${e}`,timeframe:e};return new RB(r,this.parent)}}class mtt extends qs{generateExpression(e){var r;if(this.parent.primaryKey())return this.parent.getPrimaryKeyField(this.fieldDef).generateExpression(e);if(this.parent.structDef.type==="array"){const i=(r=this.parent.parent)===null||r===void 0?void 0:r.getDistinctKey().generateExpression(e);return this.parent.dialect.sqlMakeUnnestKey(i||"",this.parent.dialect.sqlFieldReference(this.parent.getIdentifier(),"table","__row_id","string"))}else return this.parent.dialect.sqlFieldReference(this.parent.getIdentifier(),"table","__distinct_key","string")}includeInWildcard(){return!1}}const _le=9;function vle(t,e,r){const s=t.sqlSumDistinctHashedKey(r),o=10**(9-_le);let a=`(${`
|
|
1449
1449
|
(
|
|
1450
1450
|
SUM(DISTINCT
|
|
1451
1451
|
(CAST(ROUND(COALESCE(${e},0)*(${o}*1.0), ${_le}) AS ${t.defaultDecimalType}) +
|
|
@@ -1453,7 +1453,7 @@ ${(0,Fn.indent)(u)})
|
|
|
1453
1453
|
))
|
|
1454
1454
|
-
|
|
1455
1455
|
SUM(DISTINCT ${s})
|
|
1456
|
-
)`}/(${o}*1.0))`;return a=`CAST(${a} AS ${t.defaultNumberType})`,a}class Vi{constructor(e,r,i){this.f=e,this.fieldUsage=r,this.parent=i,this.type="field",this.additionalGroupSets=[]}root(){return this.parent.root()}getSQL(){let e=this.f.generateExpression(this.parent);return To(this.f)&&(e=this.f.caseGroup(this.parent.groupSet>0?this.parent.childGroups.concat(this.additionalGroupSets):[],e)),e}getAnalyticalSQL(e){return this.analyticalSQL===void 0?this.getSQL():e&&this.partitionSQL?this.partitionSQL:this.analyticalSQL}}class Pa{constructor(e,r){this.turtleDef=e,this.parent=r,this.type="query",this.allFields=new Map,this.groupSet=0,this.depth=0,this.childGroups=[],this.hasHaving=!1,this.ungroupedSets=new Map,this.resultUsesUngrouped=!1,this.firstSegment=e.pipeline[0]}getQueryInfo(){if(!(0,Me.isIndexSegment)(this.firstSegment)&&!(0,Me.isRawSegment)(this.firstSegment)){const{queryTimezone:e}=this.firstSegment;if(e)return{queryTimezone:e}}return{}}addField(e,r,i){const s=this.allFields.get(e);if(s){if(s.type==="query")throw new Error(`Redefinition of field ${r.fieldDef.name} as struct`);if(s.fieldUsage.type==="result"){if(i.type!=="result")return;throw new Error(`Ambiguous output field name '${r.fieldDef.name}'.`)}}this.add(e,new Vi(r,i,this))}parentGroupSet(){return this.parent?this.parent.groupSet:0}add(e,r){this.allFields.set(e,r)}hasField(e){const r=this.allFields.get(e);return r!==void 0&&r instanceof Vi}getField(e){const r=this.allFields.get(e);if(r===void 0)throw new Error(`Internal Error, field Not defined ${e}`);if(r instanceof Vi)return r;throw new Error(`can't use a query here ${e}`)}getFieldByNumber(e){for(const[r,i]of this.allFields)if(i instanceof Vi&&i.fieldUsage.type==="result"&&i.fieldUsage.resultIndex===e)return{name:r,fif:i};throw new Error(`Invalid Order By index '${e}`)}computeGroups(e,r){e===0&&this.resultUsesUngrouped&&this.root().computeOnlyGroups.push(e++);for(const[u,a]of this.ungroupedSets){const l=e++;a.groupSet=l,this.root().computeOnlyGroups.push(l)}this.groupSet=e++,this.depth=r;let i=r,s=!1,o=[this.groupSet];for(const[u,a]of this.allFields)if(a.type==="query"){const l=a;if(s=!0,l.firstSegment.type==="reduce"){const c=l.computeGroups(e,r+1);o=o.concat(c.children),e=c.nextGroupSetNumber,c.maxDepth>i&&(i=c.maxDepth)}}return this.childGroups=o,{nextGroupSetNumber:e,maxDepth:i,children:o,isComplex:s}}fields(e=void 0){const r=[];for(const i of this.allFields.values())i instanceof Vi&&(e===void 0||e(i))&&r.push(i);return r}fieldNames(e){const r=[];for(const[i,s]of this.allFields)s instanceof Vi&&(e===void 0||e(s))&&r.push(i);return r}getRepeatedResultType(){let e="inline_all_numbers";for(const r of this.fields())if(r.fieldUsage.type==="result"){if(S2(r.f))return"nested";r.f instanceof gs&&(e="inline")}return e}structs(){const e=[];for(const r of this.allFields.values())r instanceof Pa&&e.push(r);return e}selectStructs(e,r){r(this)&&e.push(this);for(const i of this.structs())i.selectStructs(e,r);return e}calculateDefaultOrderBy(){let e;for(const[r,i]of this.allFields)if(i instanceof Vi&&i.fieldUsage.type==="result"){if(i.f.fieldDef.type==="turtle"||(0,Me.isJoined)(i.f.fieldDef)||(0,Me.expressionIsAnalytic)(i.f.fieldDef.expressionType))continue;if(e||(e=i.fieldUsage.resultIndex),["date","timestamp"].indexOf(i.f.fieldDef.type)>-1)return[{dir:"desc",field:i.fieldUsage.resultIndex}];if(Ale(i.f))return[{dir:"desc",field:i.fieldUsage.resultIndex}]}return e?[{dir:"asc",field:e}]:[]}addStructToJoin(e,r,i,s){var o;const u=e.getIdentifier();if(s.indexOf(u)!==-1)return;let a;if(a=this.root().joins.get(u)){a.uniqueKeyPossibleUses.add_use(i);return}let l;const c=(o=e.parent)===null||o===void 0?void 0:o.getJoinableParent();c&&(this.addStructToJoin(c,r,void 0,s),l=this.root().joins.get(c.getIdentifier()));const f=e.structDef;(0,Me.isJoinedSource)(f)&&e.parent&&f.onExpression&&s.indexOf(u)===-1&&r.addDependantExpr(this,e.parent,f.onExpression,[...s,u]),(a=this.root().joins.get(u))||(a=new mtt(e,u,l),this.root().joins.set(u,a)),a.uniqueKeyPossibleUses.add_use(i)}findJoins(e){for(const r of this.fields())r.f instanceof gs||this.addStructToJoin(r.f.getJoinableParent(),e,r.f.uniqueKeyPossibleUse(),[]);for(const r of this.structs())r.findJoins(e)}root(){if(this.parent)return this.parent.root();throw new Error("Internal Error, Null parent FieldInstanceResult")}getUngroupPartitions(e){let r=[],i=this,s=[],o=[];if(e===void 0||e.type==="all"){const a=(e==null?void 0:e.fields)||[];s=this.fields(l=>S2(l.f)&&l.fieldUsage.type==="result"&&a.indexOf(l.f.getIdentifier())===-1).map(l=>l.f.getIdentifier())}else s=e.fields;let u=!0;for(;i!==void 0;)(u||(e==null?void 0:e.type)==="exclude")&&(o=o.concat(i.fields(a=>To(a.f)&&a.fieldUsage.type==="result").map(a=>a.f.getIdentifier()))),r=r.concat(i.fields(a=>To(a.f)&&a.fieldUsage.type==="result"&&s.indexOf(a.f.getIdentifier())===-1)),i=i.parent,u=!1;for(const a of(e==null?void 0:e.fields)||[])if(o.indexOf(a)===-1)throw new Error(`${e==null?void 0:e.type}(): unknown field name "${a}" or name not in scope.`);return r}assignFieldsToGroups(){for(const[e,r]of this.ungroupedSets)for(const i of this.getUngroupPartitions(r))i.additionalGroupSets.push(r.groupSet);for(const e of this.structs())e.assignFieldsToGroups()}}class ptt extends Pa{constructor(e){super(e,void 0),this.joins=new Map,this.havings=new Fn.AndChain,this.isComplexQuery=!1,this.queryUsesPartitioning=!1,this.computeOnlyGroups=[],this.elimatedComputeGroups=!1}root(){return this}eliminateComputeGroupsSQL(){return this.elimatedComputeGroups||this.computeOnlyGroups.length===0?"":(this.elimatedComputeGroups=!0,`group_set NOT IN (${this.computeOnlyGroups.join(",")})`)}calculateSymmetricAggregates(){let e;for(const[r,i]of this.joins)if(i.parentRelationship()==="many_to_many"||i.forceAllSymmetricCalculations())e="0never";else if(e===void 0)e=r;else if(i.parentRelationship()==="one_to_many"){const o=i.queryStruct;o.parent&&o.parent.getIdentifier()===e?e=r:e="0never"}for(const[r,i]of this.joins)i.leafiest=r===e;for(const[r,i]of this.joins)if(i.leafiest&&i.parent!==void 0&&i.uniqueKeyPossibleUses.has("count")||!i.leafiest&&i.uniqueKeyPossibleUses.hasAsymetricFunctions()){let s=i;for(;s;)s.queryStruct.primaryKey()||(s.makeUniqueKey=!0),s.queryStruct.structDef.type==="array"?s=s.parent:s=void 0}}}class mtt{constructor(e,r,i){this.queryStruct=e,this.alias=r,this.parent=i,this.uniqueKeyPossibleUses=new ott,this.makeUniqueKey=!1,this.leafiest=!1,this.children=[],i&&i.children.push(this);const s=this.queryStruct.structDef;(0,Me.isSourceDef)(s)&&s.filterList&&(this.joinFilterConditions=s.filterList.map(o=>new bB({type:"boolean",name:"ignoreme",e:o.e},this.queryStruct)))}parentRelationship(){if(this.queryStruct.parent===void 0)return"root";const e=this.queryStruct.structDef;if((0,Me.isJoined)(e))switch(e.join){case"one":return"many_to_one";case"cross":return"many_to_many";case"many":return"one_to_many"}throw new Error(`Internal error unknown relationship type to parent for ${this.queryStruct.structDef.name}`)}forceAllSymmetricCalculations(){if(this.queryStruct.parent===void 0)return!1;const e=this.queryStruct.structDef;return(0,Me.isJoined)(e)?e.matrixOperation==="right"||e.matrixOperation==="full":!1}getDialectFieldList(){return v2(this.queryStruct.structDef)}}class gtt{static nextStructDef(e,r){const i=new p0(e,void 0,{model:new k4(void 0)},{}),s={type:"turtle",name:"ignoreme",pipeline:[r]};return ms.makeQuery(s,i,new C2(!0,void 0),!1).getResultStructDef()}}js.Segment=gtt;function ytt(t,e){const r=new p0(t,void 0,{model:new k4(void 0)},{});return ms.makeQuery(e,r,new C2(!0,void 0),!1).getResultStructDef()}js.getResultStructDefForView=ytt;function Ett(t,e){const i=new k4(t).compileQuery(e);return i.structs[i.structs.length-1]}js.getResultStructDefForQuery=Ett;class ms extends SB{constructor(e,r,i,s){super(e,r),this.prepared=!1,this.maxDepth=0,this.maxGroupSet=0,this.fieldDef=e,this.rootResult=new ptt(e),this.stageWriter=i,this.firstSegment=e.pipeline[0],this.isJoinedSubquery=s}static makeQuery(e,r,i=void 0,s){let o=r,u=r.applyStructFiltersToTurtleDef(e);const a=u.pipeline[0],l=r.structDef;switch(i!==void 0&&(0,Me.isQuerySegment)(a)&&a.extendSource!==void 0&&(o=new p0({...l,fields:[...l.fields,...a.extendSource]},r.sourceArguments,o.parent?{struct:o}:{model:o.model},o.prepareResultOptions),u={...u,pipeline:[{...a,extendSource:void 0},...u.pipeline.slice(1)]}),(0,Me.isSourceDef)(l)&&l.queryTimezone&&(0,Me.isQuerySegment)(a)&&a.queryTimezone===void 0&&(a.queryTimezone=l.queryTimezone),a.type){case"reduce":return new Att(u,o,i,s);case"project":return new _tt(u,o,i,s);case"index":return new Stt(u,o,i,s);case"raw":return new Ctt(u,o,i,s);case"partial":throw new Error("Attempt to make query out of partial stage")}}inNestedPipeline(){return this.parent.structDef.type==="nest_source"}expandField(e){const r=e.type==="fieldref"?this.parent.getQueryFieldReference(e.path,e.annotation):this.parent.makeQueryField(e);return{as:r.getIdentifier(),field:r}}addDependantPath(e,r,i,s,o){if(i.length===0)return;const u=r.getFieldByName(i),a=u instanceof gs?u.queryStruct.getJoinableParent():u.parent.getJoinableParent();e.root().addStructToJoin(a,this,s,o)}findRecordAliases(e,r){for(const i of r){const s=e.getFieldByName([i]);if(s instanceof gs){const o=s.queryStruct;o.structDef.type==="record"&&(0,Me.hasExpression)(o.structDef)&&o.parent&&o.informOfAliasValue(this.exprToSQL(this.rootResult,o.parent,o.structDef.e)),e=o}}}addDependantExpr(e,r,i,s){var o;for(const u of(0,Fn.exprWalk)(i)){if(u.node==="function_call"){(0,Me.expressionIsAnalytic)(u.overload.returnType.expressionType)&&this.parent.dialect.cantPartitionWindowFunctionsOnExpressions&&(e.root().isComplexQuery=!0,e.root().queryUsesPartitioning=!0);const a=(o=u.overload.isSymmetric)!==null&&o!==void 0?o:!1,c=(0,Me.expressionIsAggregate)(u.overload.returnType.expressionType)&&!a,f=c?"generic_asymmetric_aggregate":void 0;u.structPath?this.addDependantPath(e,r,u.structPath,f,s):c&&e.addStructToJoin(r,this,f,s),(0,Me.expressionIsAnalytic)(u.overload.returnType.expressionType)&&(e.root().queryUsesPartitioning=!0)}else if((u.node==="all"||u.node==="exclude")&&(e.resultUsesUngrouped=!0,e.root().isComplexQuery=!0,e.root().queryUsesPartitioning=!0,u.fields&&u.fields.length>0)){const a=u.fields.sort().join("|")+u.node;e.ungroupedSets.get(a)===void 0&&e.ungroupedSets.set(a,{type:u.node,fields:u.fields,groupSet:-1})}if(u.node==="field"){this.findRecordAliases(r,u.path);const a=r.getDimensionOrMeasureByName(u.path);(0,Me.hasExpression)(a.fieldDef)?this.addDependantExpr(e,a.parent,a.fieldDef.e,s):e.root().addStructToJoin(a.parent.getJoinableParent(),this,void 0,s)}else u.node==="aggregate"&&(0,Me.isAsymmetricExpr)(u)&&(u.structPath?(this.findRecordAliases(r,u.structPath),this.addDependantPath(e,r,u.structPath,u.function,s)):e.addStructToJoin(r,this,u.function,s))}}addDependancies(e,r){(0,Me.hasExpression)(r.fieldDef)&&this.addDependantExpr(e,r.parent,r.fieldDef.e,[])}getSegmentFields(e){const r=e.firstSegment;return r.type==="index"?r.indexFields:(0,Me.isQuerySegment)(r)?r.queryFields:[]}expandFields(e){let r=1;for(const i of this.getSegmentFields(e)){const{as:s,field:o}=this.expandField(i);if(o instanceof ms){if(this.firstSegment.type==="project")throw new Error(`Nested views cannot be used in select - '${o.fieldDef.name}'`);const u=new Pa(o.fieldDef,e);this.expandFields(u),e.add(s,u)}else if(o instanceof qs){if(e.addField(s,o,{resultIndex:r,type:"result"}),this.addDependancies(e,o),Ale(o)&&this.firstSegment.type==="project")throw new Error(`Aggregate Fields cannot be used in select - '${o.fieldDef.name}'`)}else o instanceof gs&&(o.isAtomic()&&this.addDependancies(e,o),e.addField(s,o,{resultIndex:r,type:"result"}));r++}this.expandFilters(e)}expandFilters(e){if(e.firstSegment.filterList!==void 0){for(const r of e.firstSegment.filterList||[]){const i=this.parent;this.addDependantExpr(e,i,r.e,[])}for(const r of e.root().joins.values()||[])for(const i of r.joinFilterConditions||[])i.fieldDef.type==="boolean"&&i.fieldDef.e&&this.addDependantExpr(e,i.parent,i.fieldDef.e,[])}}generateSQLFilters(e,r){const i=new Fn.AndChain,s=e.firstSegment.filterList;if(s===void 0)return i;for(const o of s||[]){const u=this.parent;if(r==="having"&&(0,Me.expressionIsCalculation)(o.expressionType)||r==="where"&&(0,Me.expressionIsScalar)(o.expressionType)){const a=this.exprToSQL(e,u,o.e,void 0);i.add(a)}}return i}prepare(e){this.prepared||(this.expandFields(this.rootResult),this.rootResult.addStructToJoin(this.parent,this,void 0,[]),this.rootResult.findJoins(this),this.addAlwaysJoins(this.rootResult),this.rootResult.calculateSymmetricAggregates(),this.prepared=!0)}addAlwaysJoins(e){var r;const i=this.fieldDef.pipeline[0];if(i.type!=="raw"){const s=(r=i.alwaysJoins)!==null&&r!==void 0?r:[];for(const o of s){const u=this.parent.getChildByName(o);u instanceof gs&&e.addStructToJoin(u.queryStruct,this,void 0,[])}}}getResultMetadata(e){if(e instanceof Vi){if(e.fieldUsage.type==="result"){const r=e.f.fieldDef;let i;const s=e.f.parent.getFullOutputName()+(r.name||r.as||"undefined"),o=(0,Me.hasExpression)(r)?r.code:void 0,u=[s],a=e.f.referenceId,l={sourceField:s,sourceExpression:o,sourceClasses:u,referenceId:a};return B4(e.f)?(i=e.f.getFilterList(),{...l,filterList:i,fieldKind:"measure"}):S2(e.f)?{...l,filterList:i,fieldKind:"dimension"}:void 0}return}else if(e instanceof Pa){const r=e.turtleDef.name||e.turtleDef.as,i=r?[r]:[],s=e.firstSegment.filterList,o=e.turtleDef.pipeline[e.turtleDef.pipeline.length-1],u=(0,Me.isRawSegment)(o)?void 0:o.limit;let a;if((0,Me.isQuerySegment)(o)&&(a=o.orderBy),r)return{sourceField:r,filterList:s,sourceClasses:i,fieldKind:"struct",limit:u,orderBy:a}}}getResultStructDef(e=this.rootResult,r=!0){const i=[];let s;this.prepare(void 0);let o=0;for(const[a,l]of e.allFields){const c=this.getResultMetadata(l);if(l instanceof Pa){const{structDef:f,repeatedResultType:x}=this.generateTurtlePipelineSQL(l,new C2(!0,void 0),"<nosource>");if(x==="nested"){const h={...f,type:"array",elementTypeDef:{type:"record_element"},join:"many",name:a,resultMetadata:c};i.push(h)}else{const h={...f,type:"record",join:"one",name:a,resultMetadata:c};i.push(h)}}else if(l instanceof Vi&&l.fieldUsage.type==="result"){S2(l.f)&&(o===0&&r?s=a:s=void 0,o++);let f=l.f.fieldDef;(0,Me.hasExpression)(f)&&(f={...f},delete f.e,delete f.code,delete f.expressionType);const x=f.location,h=f.annotation;switch(f.type){case"boolean":case"json":case"string":i.push({name:a,type:f.type,resultMetadata:c,location:x,annotation:h});break;case"date":case"timestamp":{const p=f.timeframe,m={type:f.type};p&&(m.timeframe=p),i.push({name:a,...m,resultMetadata:c,location:x,annotation:h});break}case"number":i.push({name:a,numberType:f.numberType,type:"number",resultMetadata:c,location:x,annotation:h});break;case"sql native":case"record":case"array":{i.push({...f,resultMetadata:c});break}default:throw new Error(`unknown Field Type in query ${JSON.stringify(f)}`)}}}const u={type:"query_result",name:this.resultStage||"result",fields:i,dialect:this.parent.dialect.name,primaryKey:s,connection:this.parent.connectionName,resultMetadata:this.getResultMetadata(this.rootResult),queryTimezone:e.getQueryInfo().queryTimezone};return this.parent.structDef.modelAnnotation&&(u.modelAnnotation=this.parent.structDef.modelAnnotation),u}generateSQLJoinBlock(e,r,i){var s;let o="";const u=r.queryStruct,a=u.structDef;if((s=u.eventStream)===null||s===void 0||s.emit("join-used",{name:(0,Me.getIdentifier)(a)}),u.maybeEmitParameterizedSourceUsage(),(0,Me.isJoinedSource)(a)){let l=u.structSourceSQL(e);const c=(a.matrixOperation||"left").toUpperCase();if(!this.parent.dialect.supportsFullJoin&&c==="FULL")throw new Error("FULL JOIN not supported");if(r.makeUniqueKey){const p=this.generateSQLPassthroughKeys(u);l=`(SELECT ${u.dialect.sqlGenerateUUID()} as ${u.dialect.sqlMaybeQuoteIdentifier("__distinct_key")}, x.* ${p} FROM ${l} as x)`}let f="";if(u.parent===void 0)throw new Error("Expected joined struct to have a parent.");a.onExpression?f=new bB({type:"boolean",name:"ignoreme",e:a.onExpression},u.parent).generateExpression(this.rootResult):f="1=1";let x="",h;if(r.joinFilterConditions&&(h=r.joinFilterConditions.map(p=>p.generateExpression(this.rootResult))),r.children.length===0||h===void 0||!this.parent.dialect.supportsComplexFilteredSources)h!==void 0&&h.length>=1&&(x=` AND (${h.join(" AND ")})`),o+=` ${c} JOIN ${l} AS ${r.alias}
|
|
1456
|
+
)`}/(${o}*1.0))`;return a=`CAST(${a} AS ${t.defaultNumberType})`,a}class Vi{constructor(e,r,i){this.f=e,this.fieldUsage=r,this.parent=i,this.type="field",this.additionalGroupSets=[]}root(){return this.parent.root()}getSQL(){let e=this.f.generateExpression(this.parent);return To(this.f)&&(e=this.f.caseGroup(this.parent.groupSet>0?this.parent.childGroups.concat(this.additionalGroupSets):[],e)),e}getAnalyticalSQL(e){return this.analyticalSQL===void 0?this.getSQL():e&&this.partitionSQL?this.partitionSQL:this.analyticalSQL}}class Pa{constructor(e,r){this.turtleDef=e,this.parent=r,this.type="query",this.allFields=new Map,this.groupSet=0,this.depth=0,this.childGroups=[],this.hasHaving=!1,this.ungroupedSets=new Map,this.resultUsesUngrouped=!1,this.firstSegment=e.pipeline[0]}getQueryInfo(){if(!(0,Me.isIndexSegment)(this.firstSegment)&&!(0,Me.isRawSegment)(this.firstSegment)){const{queryTimezone:e}=this.firstSegment;if(e)return{queryTimezone:e}}return{}}addField(e,r,i){const s=this.allFields.get(e);if(s){if(s.type==="query")throw new Error(`Redefinition of field ${r.fieldDef.name} as struct`);if(s.fieldUsage.type==="result"){if(i.type!=="result")return;throw new Error(`Ambiguous output field name '${r.fieldDef.name}'.`)}}this.add(e,new Vi(r,i,this))}parentGroupSet(){return this.parent?this.parent.groupSet:0}add(e,r){this.allFields.set(e,r)}hasField(e){const r=this.allFields.get(e);return r!==void 0&&r instanceof Vi}getField(e){const r=this.allFields.get(e);if(r===void 0)throw new Error(`Internal Error, field Not defined ${e}`);if(r instanceof Vi)return r;throw new Error(`can't use a query here ${e}`)}getFieldByNumber(e){for(const[r,i]of this.allFields)if(i instanceof Vi&&i.fieldUsage.type==="result"&&i.fieldUsage.resultIndex===e)return{name:r,fif:i};throw new Error(`Invalid Order By index '${e}`)}computeGroups(e,r){e===0&&this.resultUsesUngrouped&&this.root().computeOnlyGroups.push(e++);for(const[u,a]of this.ungroupedSets){const l=e++;a.groupSet=l,this.root().computeOnlyGroups.push(l)}this.groupSet=e++,this.depth=r;let i=r,s=!1,o=[this.groupSet];for(const[u,a]of this.allFields)if(a.type==="query"){const l=a;if(s=!0,l.firstSegment.type==="reduce"){const c=l.computeGroups(e,r+1);o=o.concat(c.children),e=c.nextGroupSetNumber,c.maxDepth>i&&(i=c.maxDepth)}}return this.childGroups=o,{nextGroupSetNumber:e,maxDepth:i,children:o,isComplex:s}}fields(e=void 0){const r=[];for(const i of this.allFields.values())i instanceof Vi&&(e===void 0||e(i))&&r.push(i);return r}fieldNames(e){const r=[];for(const[i,s]of this.allFields)s instanceof Vi&&(e===void 0||e(s))&&r.push(i);return r}getRepeatedResultType(){let e="inline_all_numbers";for(const r of this.fields())if(r.fieldUsage.type==="result"){if(S2(r.f))return"nested";r.f instanceof gs&&(e="inline")}return e}structs(){const e=[];for(const r of this.allFields.values())r instanceof Pa&&e.push(r);return e}selectStructs(e,r){r(this)&&e.push(this);for(const i of this.structs())i.selectStructs(e,r);return e}calculateDefaultOrderBy(){let e;for(const[r,i]of this.allFields)if(i instanceof Vi&&i.fieldUsage.type==="result"){if(i.f.fieldDef.type==="turtle"||(0,Me.isJoined)(i.f.fieldDef)||(0,Me.expressionIsAnalytic)(i.f.fieldDef.expressionType))continue;if(e||(e=i.fieldUsage.resultIndex),["date","timestamp"].indexOf(i.f.fieldDef.type)>-1)return[{dir:"desc",field:i.fieldUsage.resultIndex}];if(Ale(i.f))return[{dir:"desc",field:i.fieldUsage.resultIndex}]}return e?[{dir:"asc",field:e}]:[]}addStructToJoin(e,r,i,s){var o;const u=e.getIdentifier();if(s.indexOf(u)!==-1)return;let a;if(a=this.root().joins.get(u)){a.uniqueKeyPossibleUses.add_use(i);return}let l;const c=(o=e.parent)===null||o===void 0?void 0:o.getJoinableParent();c&&(this.addStructToJoin(c,r,void 0,s),l=this.root().joins.get(c.getIdentifier()));const f=e.structDef;(0,Me.isJoinedSource)(f)&&e.parent&&f.onExpression&&s.indexOf(u)===-1&&r.addDependantExpr(this,e.parent,f.onExpression,[...s,u]),(a=this.root().joins.get(u))||(a=new ytt(e,u,l),this.root().joins.set(u,a)),a.uniqueKeyPossibleUses.add_use(i)}findJoins(e){for(const r of this.fields())r.f instanceof gs||this.addStructToJoin(r.f.getJoinableParent(),e,r.f.uniqueKeyPossibleUse(),[]);for(const r of this.structs())r.findJoins(e)}root(){if(this.parent)return this.parent.root();throw new Error("Internal Error, Null parent FieldInstanceResult")}getUngroupPartitions(e){let r=[],i=this,s=[],o=[];if(e===void 0||e.type==="all"){const a=(e==null?void 0:e.fields)||[];s=this.fields(l=>S2(l.f)&&l.fieldUsage.type==="result"&&a.indexOf(l.f.getIdentifier())===-1).map(l=>l.f.getIdentifier())}else s=e.fields;let u=!0;for(;i!==void 0;)(u||(e==null?void 0:e.type)==="exclude")&&(o=o.concat(i.fields(a=>To(a.f)&&a.fieldUsage.type==="result").map(a=>a.f.getIdentifier()))),r=r.concat(i.fields(a=>To(a.f)&&a.fieldUsage.type==="result"&&s.indexOf(a.f.getIdentifier())===-1)),i=i.parent,u=!1;for(const a of(e==null?void 0:e.fields)||[])if(o.indexOf(a)===-1)throw new Error(`${e==null?void 0:e.type}(): unknown field name "${a}" or name not in scope.`);return r}assignFieldsToGroups(){for(const[e,r]of this.ungroupedSets)for(const i of this.getUngroupPartitions(r))i.additionalGroupSets.push(r.groupSet);for(const e of this.structs())e.assignFieldsToGroups()}}class gtt extends Pa{constructor(e){super(e,void 0),this.joins=new Map,this.havings=new Fn.AndChain,this.isComplexQuery=!1,this.queryUsesPartitioning=!1,this.computeOnlyGroups=[],this.elimatedComputeGroups=!1}root(){return this}eliminateComputeGroupsSQL(){return this.elimatedComputeGroups||this.computeOnlyGroups.length===0?"":(this.elimatedComputeGroups=!0,`group_set NOT IN (${this.computeOnlyGroups.join(",")})`)}calculateSymmetricAggregates(){let e;for(const[r,i]of this.joins)if(i.parentRelationship()==="many_to_many"||i.forceAllSymmetricCalculations())e="0never";else if(e===void 0)e=r;else if(i.parentRelationship()==="one_to_many"){const o=i.queryStruct;o.parent&&o.parent.getIdentifier()===e?e=r:e="0never"}for(const[r,i]of this.joins)i.leafiest=r===e;for(const[r,i]of this.joins)if(i.leafiest&&i.parent!==void 0&&i.uniqueKeyPossibleUses.has("count")||!i.leafiest&&i.uniqueKeyPossibleUses.hasAsymetricFunctions()){let s=i;for(;s;)s.queryStruct.primaryKey()||(s.makeUniqueKey=!0),s.queryStruct.structDef.type==="array"?s=s.parent:s=void 0}}}class ytt{constructor(e,r,i){this.queryStruct=e,this.alias=r,this.parent=i,this.uniqueKeyPossibleUses=new att,this.makeUniqueKey=!1,this.leafiest=!1,this.children=[],i&&i.children.push(this);const s=this.queryStruct.structDef;(0,Me.isSourceDef)(s)&&s.filterList&&(this.joinFilterConditions=s.filterList.map(o=>new bB({type:"boolean",name:"ignoreme",e:o.e},this.queryStruct)))}parentRelationship(){if(this.queryStruct.parent===void 0)return"root";const e=this.queryStruct.structDef;if((0,Me.isJoined)(e))switch(e.join){case"one":return"many_to_one";case"cross":return"many_to_many";case"many":return"one_to_many"}throw new Error(`Internal error unknown relationship type to parent for ${this.queryStruct.structDef.name}`)}forceAllSymmetricCalculations(){if(this.queryStruct.parent===void 0)return!1;const e=this.queryStruct.structDef;return(0,Me.isJoined)(e)?e.matrixOperation==="right"||e.matrixOperation==="full":!1}getDialectFieldList(){return v2(this.queryStruct.structDef)}}class Ett{static nextStructDef(e,r){const i=new p0(e,void 0,{model:new k4(void 0)},{}),s={type:"turtle",name:"ignoreme",pipeline:[r]};return ms.makeQuery(s,i,new C2(!0,void 0),!1).getResultStructDef()}}js.Segment=Ett;function Att(t,e){const r=new p0(t,void 0,{model:new k4(void 0)},{});return ms.makeQuery(e,r,new C2(!0,void 0),!1).getResultStructDef()}js.getResultStructDefForView=Att;function _tt(t,e){const i=new k4(t).compileQuery(e);return i.structs[i.structs.length-1]}js.getResultStructDefForQuery=_tt;class ms extends SB{constructor(e,r,i,s){super(e,r),this.prepared=!1,this.maxDepth=0,this.maxGroupSet=0,this.fieldDef=e,this.rootResult=new gtt(e),this.stageWriter=i,this.firstSegment=e.pipeline[0],this.isJoinedSubquery=s}static makeQuery(e,r,i=void 0,s){let o=r,u=r.applyStructFiltersToTurtleDef(e);const a=u.pipeline[0],l=r.structDef;switch(i!==void 0&&(0,Me.isQuerySegment)(a)&&a.extendSource!==void 0&&(o=new p0({...l,fields:[...l.fields,...a.extendSource]},r.sourceArguments,o.parent?{struct:o}:{model:o.model},o.prepareResultOptions),u={...u,pipeline:[{...a,extendSource:void 0},...u.pipeline.slice(1)]}),(0,Me.isSourceDef)(l)&&l.queryTimezone&&(0,Me.isQuerySegment)(a)&&a.queryTimezone===void 0&&(a.queryTimezone=l.queryTimezone),a.type){case"reduce":return new vtt(u,o,i,s);case"project":return new Ctt(u,o,i,s);case"index":return new Ttt(u,o,i,s);case"raw":return new btt(u,o,i,s);case"partial":throw new Error("Attempt to make query out of partial stage")}}inNestedPipeline(){return this.parent.structDef.type==="nest_source"}expandField(e){const r=e.type==="fieldref"?this.parent.getQueryFieldReference(e.path,e.annotation):this.parent.makeQueryField(e);return{as:r.getIdentifier(),field:r}}addDependantPath(e,r,i,s,o){if(i.length===0)return;const u=r.getFieldByName(i),a=u instanceof gs?u.queryStruct.getJoinableParent():u.parent.getJoinableParent();e.root().addStructToJoin(a,this,s,o)}findRecordAliases(e,r){for(const i of r){const s=e.getFieldByName([i]);if(s instanceof gs){const o=s.queryStruct;o.structDef.type==="record"&&(0,Me.hasExpression)(o.structDef)&&o.parent&&o.informOfAliasValue(this.exprToSQL(this.rootResult,o.parent,o.structDef.e)),e=o}}}addDependantExpr(e,r,i,s){var o;for(const u of(0,Fn.exprWalk)(i)){if(u.node==="function_call"){(0,Me.expressionIsAnalytic)(u.overload.returnType.expressionType)&&this.parent.dialect.cantPartitionWindowFunctionsOnExpressions&&(e.root().isComplexQuery=!0,e.root().queryUsesPartitioning=!0);const a=(o=u.overload.isSymmetric)!==null&&o!==void 0?o:!1,c=(0,Me.expressionIsAggregate)(u.overload.returnType.expressionType)&&!a,f=c?"generic_asymmetric_aggregate":void 0;u.structPath?this.addDependantPath(e,r,u.structPath,f,s):c&&e.addStructToJoin(r,this,f,s),(0,Me.expressionIsAnalytic)(u.overload.returnType.expressionType)&&(e.root().queryUsesPartitioning=!0)}else if((u.node==="all"||u.node==="exclude")&&(e.resultUsesUngrouped=!0,e.root().isComplexQuery=!0,e.root().queryUsesPartitioning=!0,u.fields&&u.fields.length>0)){const a=u.fields.sort().join("|")+u.node;e.ungroupedSets.get(a)===void 0&&e.ungroupedSets.set(a,{type:u.node,fields:u.fields,groupSet:-1})}if(u.node==="field"){this.findRecordAliases(r,u.path);const a=r.getDimensionOrMeasureByName(u.path);(0,Me.hasExpression)(a.fieldDef)?this.addDependantExpr(e,a.parent,a.fieldDef.e,s):e.root().addStructToJoin(a.parent.getJoinableParent(),this,void 0,s)}else u.node==="aggregate"&&(0,Me.isAsymmetricExpr)(u)&&(u.structPath?(this.findRecordAliases(r,u.structPath),this.addDependantPath(e,r,u.structPath,u.function,s)):e.addStructToJoin(r,this,u.function,s))}}addDependancies(e,r){(0,Me.hasExpression)(r.fieldDef)&&this.addDependantExpr(e,r.parent,r.fieldDef.e,[])}getSegmentFields(e){const r=e.firstSegment;return r.type==="index"?r.indexFields:(0,Me.isQuerySegment)(r)?r.queryFields:[]}expandFields(e){let r=1;for(const i of this.getSegmentFields(e)){const{as:s,field:o}=this.expandField(i);if(o instanceof ms){if(this.firstSegment.type==="project")throw new Error(`Nested views cannot be used in select - '${o.fieldDef.name}'`);const u=new Pa(o.fieldDef,e);this.expandFields(u),e.add(s,u)}else if(o instanceof qs){if(e.addField(s,o,{resultIndex:r,type:"result"}),this.addDependancies(e,o),Ale(o)&&this.firstSegment.type==="project")throw new Error(`Aggregate Fields cannot be used in select - '${o.fieldDef.name}'`)}else o instanceof gs&&(o.isAtomic()&&this.addDependancies(e,o),e.addField(s,o,{resultIndex:r,type:"result"}));r++}this.expandFilters(e)}expandFilters(e){if(e.firstSegment.filterList!==void 0){for(const r of e.firstSegment.filterList||[]){const i=this.parent;this.addDependantExpr(e,i,r.e,[])}for(const r of e.root().joins.values()||[])for(const i of r.joinFilterConditions||[])i.fieldDef.type==="boolean"&&i.fieldDef.e&&this.addDependantExpr(e,i.parent,i.fieldDef.e,[])}}generateSQLFilters(e,r){const i=new Fn.AndChain,s=e.firstSegment.filterList;if(s===void 0)return i;for(const o of s||[]){const u=this.parent;if(r==="having"&&(0,Me.expressionIsCalculation)(o.expressionType)||r==="where"&&(0,Me.expressionIsScalar)(o.expressionType)){const a=this.exprToSQL(e,u,o.e,void 0);i.add(a)}}return i}prepare(e){this.prepared||(this.expandFields(this.rootResult),this.rootResult.addStructToJoin(this.parent,this,void 0,[]),this.rootResult.findJoins(this),this.addAlwaysJoins(this.rootResult),this.rootResult.calculateSymmetricAggregates(),this.prepared=!0)}addAlwaysJoins(e){var r;const i=this.fieldDef.pipeline[0];if(i.type!=="raw"){const s=(r=i.alwaysJoins)!==null&&r!==void 0?r:[];for(const o of s){const u=this.parent.getChildByName(o);u instanceof gs&&e.addStructToJoin(u.queryStruct,this,void 0,[])}}}getResultMetadata(e){if(e instanceof Vi){if(e.fieldUsage.type==="result"){const r=e.f.fieldDef;let i;const s=e.f.parent.getFullOutputName()+(r.name||r.as||"undefined"),o=(0,Me.hasExpression)(r)?r.code:void 0,u=[s],a=e.f.referenceId,l={sourceField:s,sourceExpression:o,sourceClasses:u,referenceId:a};return B4(e.f)?(i=e.f.getFilterList(),{...l,filterList:i,fieldKind:"measure"}):S2(e.f)?{...l,filterList:i,fieldKind:"dimension"}:void 0}return}else if(e instanceof Pa){const r=e.turtleDef.name||e.turtleDef.as,i=r?[r]:[],s=e.firstSegment.filterList,o=e.turtleDef.pipeline[e.turtleDef.pipeline.length-1],u=(0,Me.isRawSegment)(o)?void 0:o.limit;let a;if((0,Me.isQuerySegment)(o)&&(a=o.orderBy),r)return{sourceField:r,filterList:s,sourceClasses:i,fieldKind:"struct",limit:u,orderBy:a}}}getResultStructDef(e=this.rootResult,r=!0){const i=[];let s;this.prepare(void 0);let o=0;for(const[a,l]of e.allFields){const c=this.getResultMetadata(l);if(l instanceof Pa){const{structDef:f,repeatedResultType:x}=this.generateTurtlePipelineSQL(l,new C2(!0,void 0),"<nosource>");if(x==="nested"){const h={...f,type:"array",elementTypeDef:{type:"record_element"},join:"many",name:a,resultMetadata:c};i.push(h)}else{const h={...f,type:"record",join:"one",name:a,resultMetadata:c};i.push(h)}}else if(l instanceof Vi&&l.fieldUsage.type==="result"){S2(l.f)&&(o===0&&r?s=a:s=void 0,o++);let f=l.f.fieldDef;(0,Me.hasExpression)(f)&&(f={...f},delete f.e,delete f.code,delete f.expressionType);const x=f.location,h=f.annotation;switch(f.type){case"boolean":case"json":case"string":i.push({name:a,type:f.type,resultMetadata:c,location:x,annotation:h});break;case"date":case"timestamp":{const p=f.timeframe,m={type:f.type};p&&(m.timeframe=p),i.push({name:a,...m,resultMetadata:c,location:x,annotation:h});break}case"number":i.push({name:a,numberType:f.numberType,type:"number",resultMetadata:c,location:x,annotation:h});break;case"sql native":case"record":case"array":{i.push({...f,resultMetadata:c});break}default:throw new Error(`unknown Field Type in query ${JSON.stringify(f)}`)}}}const u={type:"query_result",name:this.resultStage||"result",fields:i,dialect:this.parent.dialect.name,primaryKey:s,connection:this.parent.connectionName,resultMetadata:this.getResultMetadata(this.rootResult),queryTimezone:e.getQueryInfo().queryTimezone};return this.parent.structDef.modelAnnotation&&(u.modelAnnotation=this.parent.structDef.modelAnnotation),u}generateSQLJoinBlock(e,r,i){var s;let o="";const u=r.queryStruct,a=u.structDef;if((s=u.eventStream)===null||s===void 0||s.emit("join-used",{name:(0,Me.getIdentifier)(a)}),u.maybeEmitParameterizedSourceUsage(),(0,Me.isJoinedSource)(a)){let l=u.structSourceSQL(e);const c=(a.matrixOperation||"left").toUpperCase();if(!this.parent.dialect.supportsFullJoin&&c==="FULL")throw new Error("FULL JOIN not supported");if(r.makeUniqueKey){const p=this.generateSQLPassthroughKeys(u);l=`(SELECT ${u.dialect.sqlGenerateUUID()} as ${u.dialect.sqlMaybeQuoteIdentifier("__distinct_key")}, x.* ${p} FROM ${l} as x)`}let f="";if(u.parent===void 0)throw new Error("Expected joined struct to have a parent.");a.onExpression?f=new bB({type:"boolean",name:"ignoreme",e:a.onExpression},u.parent).generateExpression(this.rootResult):f="1=1";let x="",h;if(r.joinFilterConditions&&(h=r.joinFilterConditions.map(p=>p.generateExpression(this.rootResult))),r.children.length===0||h===void 0||!this.parent.dialect.supportsComplexFilteredSources)h!==void 0&&h.length>=1&&(x=` AND (${h.join(" AND ")})`),o+=` ${c} JOIN ${l} AS ${r.alias}
|
|
1457
1457
|
ON ${f}${x}
|
|
1458
1458
|
`;else{let p=`SELECT ${r.alias}.*`,m="";for(const g of r.children)m+=this.generateSQLJoinBlock(e,g,i+1),p+=`, ${this.parent.dialect.sqlSelectAliasAsStruct(g.alias,v2(g.queryStruct.structDef))} AS ${g.alias}`;return p+=`
|
|
1459
1459
|
FROM ${l} AS ${r.alias}
|
|
@@ -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,Me.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 Pa){const{structDef:u,repeatedResultType:a}=this.generateTurtlePipelineSQL(s,new C2(!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"?Ele(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"&&Ele(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,Me.isRawSegment)(e.firstSegment)?void 0:e.firstSegment.limit,a=[];let l;const c=e.firstSegment.orderBy||e.calculateDefaultOrderBy();for(const y of c)typeof y.field=="string"?l={name:y.field,fif:e.getField(y.field)}:l=e.getFieldByNumber(y.field),e.firstSegment.type==="reduce"?a.push(" "+this.parent.dialect.sqlMaybeQuoteIdentifier(`${l.name}__${e.groupSet}`)+` ${y.dir||"ASC"}`):e.firstSegment.type==="project"&&a.push(` ${l.fif.f.generateExpression(e)} ${y.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 C2(this.parent.dialect.supportsCTEinCoorelatedSubQueries,r),{structDef:m,pipeOut:g}=this.generateTurtlePipelineSQL(e,p,this.parent.dialect.supportUnnestArrayAgg?h:i);if(g!==void 0){const y=p.generateCoorelatedSubQuery(this.parent.dialect,m);this.parent.dialect.supportUnnestArrayAgg?h=`(${y})`:s.push({sqlFieldName:i,pipelineSQL:`(${y})`})}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,v2(s)),fields:s.fields,connection:s.connection,dialect:s.dialect},h=new p0(x,void 0,{model:this.parent.getModel()},this.parent.prepareResultOptions),p=ms.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=ms.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
|
|
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 Pa){const{structDef:u,repeatedResultType:a}=this.generateTurtlePipelineSQL(s,new C2(!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"?Ele(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"&&Ele(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,Me.isRawSegment)(e.firstSegment)?void 0:e.firstSegment.limit,a=[];let l;const c=e.firstSegment.orderBy||e.calculateDefaultOrderBy();for(const y of c)typeof y.field=="string"?l={name:y.field,fif:e.getField(y.field)}:l=e.getFieldByNumber(y.field),e.firstSegment.type==="reduce"?a.push(" "+this.parent.dialect.sqlMaybeQuoteIdentifier(`${l.name}__${e.groupSet}`)+` ${y.dir||"ASC"}`):e.firstSegment.type==="project"&&a.push(` ${l.fif.f.generateExpression(e)} ${y.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 C2(this.parent.dialect.supportsCTEinCoorelatedSubQueries,r),{structDef:m,pipeOut:g}=this.generateTurtlePipelineSQL(e,p,this.parent.dialect.supportUnnestArrayAgg?h:i);if(g!==void 0){const y=p.generateCoorelatedSubQuery(this.parent.dialect,m);this.parent.dialect.supportUnnestArrayAgg?h=`(${y})`:s.push({sqlFieldName:i,pipelineSQL:`(${y})`})}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,v2(s)),fields:s.fields,connection:s.connection,dialect:s.dialect},h=new p0(x,void 0,{model:this.parent.getModel()},this.parent.prepareResultOptions),p=ms.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=ms.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 vtt extends ms{}class Ctt extends ms{}class Stt extends ms{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 qs&&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,g]of this.rootResult.allFields){const y=g;if(y.fieldUsage.type==="result"&&To(y.f)){const E=y.f.generateExpression(this.rootResult),A=this.indexPaths[m]||[];x.push({name:m,path:A,type:y.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}'
|
|
@@ -1527,9 +1527,9 @@ FROM ${r}
|
|
|
1527
1527
|
COALESCE(${u}, ${l}) as ${u},
|
|
1528
1528
|
${c}
|
|
1529
1529
|
FROM ${p}
|
|
1530
|
-
`),this.resultStage}}class
|
|
1530
|
+
`),this.resultStage}}class btt extends ms{generateSQL(e){if(this.parent.structDef.type!=="sql_select")throw new Error("Invalid struct for QueryQueryRaw, currently only supports SQL");return e.addStage(this.parent.structDef.selectStr)}prepare(){}getResultStructDef(){if(!(0,Me.isSourceDef)(this.parent.structDef))throw new Error(`Result cannot be type ${this.parent.structDef.type}`);return{...this.parent.structDef,type:"query_result"}}getResultMetadata(e){}}class Ttt extends ms{constructor(e,r,i,s){super(e,r,i,s),this.stages=[],this.fieldDef=e,this.fieldsToStages()}fieldsToStages(){const e=this.firstSegment;if(this.parent.dialect.dontUnionIndex){this.stages=[e.indexFields];return}const r={};for(const i of e.indexFields){if(i.path.length>1){const s=yle(i.path.slice(0,i.path.length-1)),o=r[s];if(o===void 0){const u=this.parent.nameMap.get(i.path[0]);if(u instanceof gs&&u.fieldDef.join==="many"&&u.fieldDef.fields.length>1){const a=[i];r[s]=a,this.stages.push(a);continue}}else{o.push(i);continue}}this.stages[0]===void 0&&(this.stages[0]=[]),this.stages[0].push(i)}}expandFields(e){}generateSQL(e){const r=this.firstSegment,i=[];for(const s of this.stages){const o=new Stt({...this.fieldDef,pipeline:[{...r,indexFields:s}]},this.parent,e,this.isJoinedSubquery);o.prepare(e);const u=o.generateSQL(e);i.push(u)}return i.length===1?this.resultStage=i[0]:this.resultStage=e.addStage(i.map(s=>`SELECT * FROM ${s}
|
|
1531
1531
|
`).join(` UNION ALL
|
|
1532
|
-
`)),this.resultStage}getResultStructDef(){const e={type:"query_result",name:this.resultStage||"result",dialect:this.parent.dialect.name,fields:[{type:"string",name:"fieldName"},{type:"string",name:"fieldPath"},{type:"string",name:"fieldValue"},{type:"string",name:"fieldType"},{type:"number",name:"weight",numberType:"integer"}],connection:this.parent.connectionName};return this.parent.structDef.modelAnnotation&&(e.modelAnnotation=this.parent.structDef.modelAnnotation),e}}class gs extends SB{constructor(e,r,i,s,o){super(e,i,o),this.fieldDef=e,this.queryStruct=new p0(e,r,{struct:i},s)}getJoinableParent(){return this.queryStruct.getJoinableParent()}getFullOutputName(){return this.queryStruct.getFullOutputName()}includeInWildcard(){return this.isAtomic()}}class p0{constructor(e,r,i,s){if(this.structDef=e,this.sourceArguments=r,this.prepareResultOptions=s,this.nameMap=new Map,this._modelTag=void 0,this._arguments=void 0,this.setParent(i),"model"in i)if(this.model=i.model,this.pathAliasMap=new Map,(0,Me.isSourceDef)(e))this.connectionName=e.connection;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.dialect=(0,ttt.getDialect)(this.findFirstDialect()),this.addFieldsFromFieldList(e.fields)}modelCompilerFlags(){if(this._modelTag===void 0){const e=this.structDef.modelAnnotation,{tag:r}=(0,rtt.annotationToTag)(e,{prefix:/^##!\s*/});this._modelTag=r}return this._modelTag}findFirstDialect(){if((0,Me.isSourceDef)(this.structDef))return this.structDef.dialect;if(this.parent)return this.parent.findFirstDialect();throw new Error("Cannot create QueryStruct from record with model parent")}informOfAliasValue(e){this.recordAlias=e}maybeEmitParameterizedSourceUsage(){var e;if((0,Me.isSourceDef)(this.structDef)){const r={...this.structDef.parameters,...this.structDef.arguments};if(Object.values(r).length===0)return;(e=this.eventStream)===null||e===void 0||e.emit("parameterized-source-compiled",{parameters:r})}}resolveParentParameterReferences(e){return{...e,value:e.value===null?null:(0,Fn.exprMap)(e.value,r=>{if(r.node==="parameter"){if(this.parent===void 0)throw new Error("No parent from which to retrieve parameter value");const i=this.parent.arguments()[r.path[0]],s=this.parent.resolveParentParameterReferences(i);if(s.value===null)throw new Error("Invalid parameter value");return s.value}return r})}}arguments(){var e;if(this._arguments!==void 0)return this._arguments;if(this._arguments={},(0,Me.isSourceDef)(this.structDef)){const r=(e=this.structDef.parameters)!==null&&e!==void 0?e:{};for(const s in r)this._arguments[s]=r[s];const i={...this.structDef.arguments,...this.sourceArguments};for(const s in i){const o=i[s];this._arguments[s]=this.resolveParentParameterReferences(o)}}return this._arguments}addFieldsFromFieldList(e){for(const r of e){const i=(0,Me.getIdentifier)(r);if(r.type==="turtle")this.addFieldToNameMap(i,ms.makeQuery(r,this,void 0,!1));else if((0,Me.isAtomic)(r)||(0,Me.isJoinedSource)(r))this.addFieldToNameMap(i,this.makeQueryField(r));else throw new Error("mtoy did nit add field")}this.nameMap.has("__distinct_key")||this.addFieldToNameMap("__distinct_key",new htt({type:"string",name:"__distinct_key"},this))}getAliasIdentifier(){const e=this.getFullOutputName(),r=this.pathAliasMap.get(e);if(r===void 0){const i=Array.from(this.pathAliasMap.values()),s=stt((0,Me.getIdentifier)(this.structDef));let o=`${s}_0`,u=1;for(;i.includes(o)&&u<1e3;)u++,o=`${s}_${u}`;if(u<1e3)return this.pathAliasMap.set(e,o),o;throw new Error("Internal Error: cannot create unique alias name")}else return r}getSQLIdentifier(){return this.unnestWithNumbers()&&this.parent!==void 0?this.parent.getSQLIdentifier()+"."+(0,Me.getIdentifier)(this.structDef)+`[${this.getIdentifier()}.__row_id]`:this.getIdentifier()}sqlChildReference(e,r){let i=this.getSQLIdentifier();r&&(0,Me.isAtomic)(this.structDef)&&(0,Me.hasExpression)(this.structDef)&&(i=r.field.exprToSQL(r.result,this,this.structDef.e));let s="table";this.structDef.type==="record"?s="record":this.structDef.type==="array"?s=this.structDef.elementTypeDef.type==="record_element"?"array[record]":"array[scalar]":this.structDef.type==="nest_source"&&(s="nest source");const o=this.getChildByName(e),u=(o==null?void 0:o.fieldDef.type)||"unknown";return this.dialect.sqlFieldReference(i,s,e,u)}getIdentifier(){if((0,Me.isBaseTable)(this.structDef))return"base";if(this.structDef.type==="record"&&(0,Me.hasExpression)(this.structDef)){if(this.recordAlias)return this.recordAlias;throw new Error("INTERNAL ERROR, record field alias not pre-computed")}return this.structDef.type==="record"&&this.parent?this.parent.sqlChildReference((0,Me.getIdentifier)(this.structDef),void 0):this.getAliasIdentifier()}getFullOutputName(){return this.parent?this.parent.getFullOutputName()+(0,Me.getIdentifier)(this.structDef)+".":""}needsSymetricCalculation(e){const r=this.getJoinableParent().getIdentifier(),i=e.root().joins.get(r);if(i)return!i.leafiest;throw new Error(`Join ${r} not found in result set`)}unnestWithNumbers(){return this.dialect.unnestWithNumbers&&this.structDef.type==="array"}getJoinableParent(){if(this.structDef.type==="record"){if(this.parent)return this.parent.getJoinableParent();throw new Error("Internal Error: inline struct cannot be root")}return this}addFieldToNameMap(e,r){if(this.nameMap.has(e))throw new Error(`Redefinition of ${e}`);this.nameMap.set(e,r)}getPrimaryKeyField(e){let r;if(r=this.primaryKey())return r;throw new Error(`Missing primary key for ${e}`)}resolveQueryFields(){if(this.structDef.type==="query_source"){const e=this.model.loadQuery(this.structDef.query,void 0,this.prepareResultOptions).structs.pop();if(!e)throw new Error("Internal Error, query didn't produce a struct");const r={...this.structDef};for(const i of e.fields){const s=(0,Me.getIdentifier)(i);this.nameMap.has(s)||(r.fields.push(i),this.nameMap.set(s,this.makeQueryField(i)))}this.structDef=r,!this.structDef.primaryKey&&e.primaryKey&&(this.structDef.primaryKey=e.primaryKey)}for(const[,e]of this.nameMap)e instanceof gs&&e.queryStruct.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()}get eventStream(){return this.getModel().eventStream}setParent(e){"struct"in e&&(this.parent=e.struct),"model"in e?this.model=e.model:this.model=this.getModel()}makeQueryField(e,r){switch(e.type){case"array":case"record":case"query_source":case"table":case"sql_select":case"composite":return new gs(e,void 0,this,this.prepareResultOptions);case"string":return new ctt(e,this,r);case"date":return new TB(e,this,r);case"timestamp":return new RB(e,this,r);case"number":return new ftt(e,this,r);case"boolean":return new bB(e,this,r);case"json":return new xtt(e,this,r);case"sql native":return new dtt(e,this,r);case"turtle":return ms.makeQuery(e,this,void 0,!1);default:throw new Error(`unknown field definition ${JSON.stringify(e),2}`)}}structSourceSQL(e){var r,i;switch(this.structDef.type){case"table":return this.dialect.quoteTablePath(this.structDef.tablePath);case"composite":return"{COMPOSITE SOURCE}";case"finalize":return this.structDef.name;case"sql_select":return`(${this.structDef.selectStr})`;case"nest_source":return this.structDef.pipeSQL;case"query_source":return!((r=this.prepareResultOptions)===null||r===void 0)&&r.replaceMaterializedReferences&&(0,I4.shouldMaterialize)(this.structDef.query.annotation)?e.addMaterializedQuery((0,Me.getIdentifier)(this.structDef),this.structDef.query,(i=this.prepareResultOptions)===null||i===void 0?void 0:i.materializedTablePrefix):this.model.loadQuery(this.structDef.query,e,this.prepareResultOptions,!1,!0).lastStageName;default:throw new Error(`Cannot create SQL StageWriter from '${(0,Me.getIdentifier)(this.structDef)}' type '${this.structDef.type}`)}}root(){return this.parent?this.parent.root():this}primaryKey(){if((0,Me.isSourceDef)(this.structDef)&&this.structDef.primaryKey)return this.getDimensionByName([this.structDef.primaryKey])}getChildByName(e){return this.nameMap.get(e)}getFieldByName(e){let r,i=this,s=e[0];for(const o of e){if(r=i==null?void 0:i.getChildByName(o),!r){s=o;break}i=r instanceof gs?r.queryStruct:void 0}if(r===void 0){const o=e.length>1?` in ${e.join(".")}`:"";throw new Error(`${s} not found${o}`)}return r}getQueryFieldByName(e){const r=this.getFieldByName(e);if(r instanceof gs)throw new Error(`Cannot reference ${e.join(".")} as a scalar'`);return r}getQueryFieldReference(e,r){const i=this.getFieldByName(e);if(r){if(i.parent===void 0)throw new Error("Inconcievable, field reference to orphaned query field");if(i instanceof gs){const s={...i.fieldDef,annotation:r};return new gs(s,void 0,i.parent,{},i.referenceId)}else{const s={...i.fieldDef,annotation:r};return i.parent.makeQueryField(s,i.referenceId)}}return i}getDimensionOrMeasureByName(e){const r=this.getFieldByName(e);if(!r.isAtomic())throw new Error(`${e} is not an atomic field? Inconceivable!`);return r}getDimensionByName(e){const r=this.getFieldByName(e);if(S2(r))return r;throw new Error(`${e} is not an atomic scalar field? Inconceivable!`)}getStructByName(e){if(e.length===0)return this;const r=this.getFieldByName(e);if(r instanceof gs)return r.queryStruct;throw new Error(`Error: Path to structure not found '${e.join(".")}'`)}getDistinctKey(){if(this.structDef.type!=="record")return this.getDimensionByName(["__distinct_key"]);if(this.parent)return this.parent.getDistinctKey();throw new Error("Asking a record for a primary key? Inconceivable!")}applyStructFiltersToTurtleDef(e){let r=e.pipeline;const i=e.annotation,s=e.filterList||[];return r=structuredClone(r),r[0].filterList=s.concat(r[0].filterList||[],(0,Me.isSourceDef)(this.structDef)?this.structDef.filterList||[]:[]),{type:"turtle",name:e.name,pipeline:r,annotation:i,location:e.location}}}class k4{constructor(e,r){this.eventStream=r,this.dialect=new ntt.StandardSQLDialect,this.modelDef=void 0,this.structs=new Map,this.exploreSearchSQLMap=new Map,e&&this.loadModelFromDef(e)}loadModelFromDef(e){this.modelDef=e;for(const r of Object.values(this.modelDef.contents)){let i;if((0,Me.isSourceDef)(r))i=new p0(r,void 0,{model:this},{}),this.structs.set((0,Me.getIdentifier)(r),i),i.resolveQueryFields();else if(r.type!=="query")throw new Error("Internal Error: Unknown structure type")}}getStructByName(e){const r=this.structs.get(e);if(r)return r;throw new Error(`Struct ${e} not found in model.`)}getStructFromRef(e,r,i){var s;if(i??(i={}),typeof e=="string"){const o=this.getStructByName(e);return r!==void 0?new p0(o.structDef,r,(s=o.parent)!==null&&s!==void 0?s:{model:this},i):o}return new p0(e,r,{model:this},i)}loadQuery(e,r,i,s=!1,o=!1){var u;const a="";r||(r=new C2(!0,void 0));const l={type:"turtle",name:"ignoreme",pipeline:e.pipeline,filterList:e.filterList},c=(u=e.compositeResolvedSourceDef)!==null&&u!==void 0?u:e.structRef,f=ms.makeQuery(l,this.getStructFromRef(c,e.sourceArguments,i),r,o),x=f.generateSQLFromPipeline(r);if(s&&f.parent.dialect.hasFinalStage){const h=[];for(const p of x.outputStruct.fields)if((0,Me.isAtomic)(p)){const m=f.parent.dialect.sqlMaybeQuoteIdentifier(p.name);h.push(m)}x.lastStageName=r.addStage(f.parent.dialect.sqlFinalStage(x.lastStageName,h))}return{lastStageName:x.lastStageName,malloy:a,stageWriter:r,structs:[x.outputStruct],connectionName:f.parent.connectionName}}addDefaultRowLimit(e,r){const i={query:e,addedDefaultRowLimit:void 0};if(r===void 0)return i;const s=e.pipeline[e.pipeline.length-1];return s.type==="raw"||s.limit!==void 0?i:{query:{...e,pipeline:[...e.pipeline.slice(0,-1),{...s,limit:r}]},addedDefaultRowLimit:r}}compileQuery(e,r,i=!0){var s,o;const u=this.addDefaultRowLimit(e,r==null?void 0:r.defaultRowLimit);e=u.query;const a=u.addedDefaultRowLimit,c=this.loadQuery(e,void 0,r,i,!1),f=(s=e.compositeResolvedSourceDef)!==null&&s!==void 0?s:e.structRef,x=typeof f=="string"?f:f.as||f.name;return i&&this.dialect.hasFinalStage&&(c.lastStageName=c.stageWriter.addStage(this.dialect.sqlFinalStage(c.lastStageName,[]))),{lastStageName:c.lastStageName,malloy:c.malloy,sql:c.stageWriter.generateSQLStages(),dependenciesToMaterialize:c.stageWriter.dependenciesToMaterialize,materialization:(0,I4.shouldMaterialize)(e.annotation)?(0,I4.buildQueryMaterializationSpec)((o=e.location)===null||o===void 0?void 0:o.url,e.name,r==null?void 0:r.materializedTablePrefix):void 0,structs:c.structs,sourceExplore:x,sourceFilters:e.filterList,queryName:e.name,connectionName:c.connectionName,annotation:e.annotation,queryTimezone:c.structs[0].queryTimezone,defaultRowLimitAdded:a}}async searchIndex(e,r,i,s=1e3,o=void 0){if(!e.canPersist())return;const u=this.getStructByName(r);let a=[];for(const[E,A]of u.nameMap)To(A)&&A.includeInWildcard()&&a.push({type:"fieldref",path:[E]});a=a.sort((E,A)=>E.path[0].localeCompare(A.path[0]));const l={structRef:r,pipeline:[{type:"index",indexFields:a,sample:u.dialect.defaultSampling}]},c=u.dialect.sqlMaybeQuoteIdentifier("fieldName"),f=u.dialect.sqlMaybeQuoteIdentifier("fieldPath"),x=u.dialect.sqlMaybeQuoteIdentifier("fieldValue"),h=u.dialect.sqlMaybeQuoteIdentifier("fieldType"),p=u.dialect.sqlMaybeQuoteIdentifier("weight");let m=this.exploreSearchSQLMap.get(r);m===void 0&&(m=this.compileQuery(l,void 0,!1).sql,this.exploreSearchSQLMap.set(r,m));let g=`SELECT
|
|
1532
|
+
`)),this.resultStage}getResultStructDef(){const e={type:"query_result",name:this.resultStage||"result",dialect:this.parent.dialect.name,fields:[{type:"string",name:"fieldName"},{type:"string",name:"fieldPath"},{type:"string",name:"fieldValue"},{type:"string",name:"fieldType"},{type:"number",name:"weight",numberType:"integer"}],connection:this.parent.connectionName};return this.parent.structDef.modelAnnotation&&(e.modelAnnotation=this.parent.structDef.modelAnnotation),e}}class gs extends SB{constructor(e,r,i,s,o){super(e,i,o),this.fieldDef=e,this.queryStruct=new p0(e,r,{struct:i},s)}getJoinableParent(){return this.queryStruct.getJoinableParent()}getFullOutputName(){return this.queryStruct.getFullOutputName()}includeInWildcard(){return this.isAtomic()}}class p0{constructor(e,r,i,s){if(this.structDef=e,this.sourceArguments=r,this.prepareResultOptions=s,this.nameMap=new Map,this._modelTag=void 0,this._arguments=void 0,this.setParent(i),"model"in i)if(this.model=i.model,this.pathAliasMap=new Map,(0,Me.isSourceDef)(e))this.connectionName=e.connection;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.dialect=(0,rtt.getDialect)(this.findFirstDialect()),this.addFieldsFromFieldList(e.fields)}modelCompilerFlags(){if(this._modelTag===void 0){const e=this.structDef.modelAnnotation,{tag:r}=(0,stt.annotationToTag)(e,{prefix:/^##!\s*/});this._modelTag=r}return this._modelTag}findFirstDialect(){if((0,Me.isSourceDef)(this.structDef))return this.structDef.dialect;if(this.parent)return this.parent.findFirstDialect();throw new Error("Cannot create QueryStruct from record with model parent")}informOfAliasValue(e){this.recordAlias=e}maybeEmitParameterizedSourceUsage(){var e;if((0,Me.isSourceDef)(this.structDef)){const r={...this.structDef.parameters,...this.structDef.arguments};if(Object.values(r).length===0)return;(e=this.eventStream)===null||e===void 0||e.emit("parameterized-source-compiled",{parameters:r})}}resolveParentParameterReferences(e){return{...e,value:e.value===null?null:(0,Fn.exprMap)(e.value,r=>{if(r.node==="parameter"){if(this.parent===void 0)throw new Error("No parent from which to retrieve parameter value");const i=this.parent.arguments()[r.path[0]],s=this.parent.resolveParentParameterReferences(i);if(s.value===null)throw new Error("Invalid parameter value");return s.value}return r})}}arguments(){var e;if(this._arguments!==void 0)return this._arguments;if(this._arguments={},(0,Me.isSourceDef)(this.structDef)){const r=(e=this.structDef.parameters)!==null&&e!==void 0?e:{};for(const s in r)this._arguments[s]=r[s];const i={...this.structDef.arguments,...this.sourceArguments};for(const s in i){const o=i[s];this._arguments[s]=this.resolveParentParameterReferences(o)}}return this._arguments}addFieldsFromFieldList(e){for(const r of e){const i=(0,Me.getIdentifier)(r);if(r.type==="turtle")this.addFieldToNameMap(i,ms.makeQuery(r,this,void 0,!1));else if((0,Me.isAtomic)(r)||(0,Me.isJoinedSource)(r))this.addFieldToNameMap(i,this.makeQueryField(r));else throw new Error("mtoy did nit add field")}this.nameMap.has("__distinct_key")||this.addFieldToNameMap("__distinct_key",new mtt({type:"string",name:"__distinct_key"},this))}getAliasIdentifier(){const e=this.getFullOutputName(),r=this.pathAliasMap.get(e);if(r===void 0){const i=Array.from(this.pathAliasMap.values()),s=utt((0,Me.getIdentifier)(this.structDef));let o=`${s}_0`,u=1;for(;i.includes(o)&&u<1e3;)u++,o=`${s}_${u}`;if(u<1e3)return this.pathAliasMap.set(e,o),o;throw new Error("Internal Error: cannot create unique alias name")}else return r}getSQLIdentifier(){return this.unnestWithNumbers()&&this.parent!==void 0?this.parent.getSQLIdentifier()+"."+(0,Me.getIdentifier)(this.structDef)+`[${this.getIdentifier()}.__row_id]`:this.getIdentifier()}sqlChildReference(e,r){let i=this.getSQLIdentifier();r&&(0,Me.isAtomic)(this.structDef)&&(0,Me.hasExpression)(this.structDef)&&(i=r.field.exprToSQL(r.result,this,this.structDef.e));let s="table";this.structDef.type==="record"?s="record":this.structDef.type==="array"?s=this.structDef.elementTypeDef.type==="record_element"?"array[record]":"array[scalar]":this.structDef.type==="nest_source"&&(s="nest source");const o=this.getChildByName(e),u=(o==null?void 0:o.fieldDef.type)||"unknown";return this.dialect.sqlFieldReference(i,s,e,u)}getIdentifier(){if((0,Me.isBaseTable)(this.structDef))return"base";if(this.structDef.type==="record"&&(0,Me.hasExpression)(this.structDef)){if(this.recordAlias)return this.recordAlias;throw new Error("INTERNAL ERROR, record field alias not pre-computed")}return this.structDef.type==="record"&&this.parent?this.parent.sqlChildReference((0,Me.getIdentifier)(this.structDef),void 0):this.getAliasIdentifier()}getFullOutputName(){return this.parent?this.parent.getFullOutputName()+(0,Me.getIdentifier)(this.structDef)+".":""}needsSymetricCalculation(e){const r=this.getJoinableParent().getIdentifier(),i=e.root().joins.get(r);if(i)return!i.leafiest;throw new Error(`Join ${r} not found in result set`)}unnestWithNumbers(){return this.dialect.unnestWithNumbers&&this.structDef.type==="array"}getJoinableParent(){if(this.structDef.type==="record"){if(this.parent)return this.parent.getJoinableParent();throw new Error("Internal Error: inline struct cannot be root")}return this}addFieldToNameMap(e,r){if(this.nameMap.has(e))throw new Error(`Redefinition of ${e}`);this.nameMap.set(e,r)}getPrimaryKeyField(e){let r;if(r=this.primaryKey())return r;throw new Error(`Missing primary key for ${e}`)}resolveQueryFields(){if(this.structDef.type==="query_source"){const e=this.model.loadQuery(this.structDef.query,void 0,this.prepareResultOptions).structs.pop();if(!e)throw new Error("Internal Error, query didn't produce a struct");const r={...this.structDef};for(const i of e.fields){const s=(0,Me.getIdentifier)(i);this.nameMap.has(s)||(r.fields.push(i),this.nameMap.set(s,this.makeQueryField(i)))}this.structDef=r,!this.structDef.primaryKey&&e.primaryKey&&(this.structDef.primaryKey=e.primaryKey)}for(const[,e]of this.nameMap)e instanceof gs&&e.queryStruct.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()}get eventStream(){return this.getModel().eventStream}setParent(e){"struct"in e&&(this.parent=e.struct),"model"in e?this.model=e.model:this.model=this.getModel()}makeQueryField(e,r){switch(e.type){case"array":case"record":case"query_source":case"table":case"sql_select":case"composite":return new gs(e,void 0,this,this.prepareResultOptions);case"string":return new xtt(e,this,r);case"date":return new TB(e,this,r);case"timestamp":return new RB(e,this,r);case"number":return new dtt(e,this,r);case"boolean":return new bB(e,this,r);case"json":return new htt(e,this,r);case"sql native":return new ptt(e,this,r);case"turtle":return ms.makeQuery(e,this,void 0,!1);default:throw new Error(`unknown field definition ${JSON.stringify(e),2}`)}}structSourceSQL(e){var r,i;switch(this.structDef.type){case"table":return this.dialect.quoteTablePath(this.structDef.tablePath);case"composite":return"{COMPOSITE SOURCE}";case"finalize":return this.structDef.name;case"sql_select":return`(${this.structDef.selectStr})`;case"nest_source":return this.structDef.pipeSQL;case"query_source":return!((r=this.prepareResultOptions)===null||r===void 0)&&r.replaceMaterializedReferences&&(0,I4.shouldMaterialize)(this.structDef.query.annotation)?e.addMaterializedQuery((0,Me.getIdentifier)(this.structDef),this.structDef.query,(i=this.prepareResultOptions)===null||i===void 0?void 0:i.materializedTablePrefix):this.model.loadQuery(this.structDef.query,e,this.prepareResultOptions,!1,!0).lastStageName;default:throw new Error(`Cannot create SQL StageWriter from '${(0,Me.getIdentifier)(this.structDef)}' type '${this.structDef.type}`)}}root(){return this.parent?this.parent.root():this}primaryKey(){if((0,Me.isSourceDef)(this.structDef)&&this.structDef.primaryKey)return this.getDimensionByName([this.structDef.primaryKey])}getChildByName(e){return this.nameMap.get(e)}getFieldByName(e){let r,i=this,s=e[0];for(const o of e){if(r=i==null?void 0:i.getChildByName(o),!r){s=o;break}i=r instanceof gs?r.queryStruct:void 0}if(r===void 0){const o=e.length>1?` in ${e.join(".")}`:"";throw new Error(`${s} not found${o}`)}return r}getQueryFieldByName(e){const r=this.getFieldByName(e);if(r instanceof gs)throw new Error(`Cannot reference ${e.join(".")} as a scalar'`);return r}getQueryFieldReference(e,r){const i=this.getFieldByName(e);if(r){if(i.parent===void 0)throw new Error("Inconcievable, field reference to orphaned query field");if(i instanceof gs){const s={...i.fieldDef,annotation:r};return new gs(s,void 0,i.parent,{},i.referenceId)}else{const s={...i.fieldDef,annotation:r};return i.parent.makeQueryField(s,i.referenceId)}}return i}getDimensionOrMeasureByName(e){const r=this.getFieldByName(e);if(!r.isAtomic())throw new Error(`${e} is not an atomic field? Inconceivable!`);return r}getDimensionByName(e){const r=this.getFieldByName(e);if(S2(r))return r;throw new Error(`${e} is not an atomic scalar field? Inconceivable!`)}getStructByName(e){if(e.length===0)return this;const r=this.getFieldByName(e);if(r instanceof gs)return r.queryStruct;throw new Error(`Error: Path to structure not found '${e.join(".")}'`)}getDistinctKey(){if(this.structDef.type!=="record")return this.getDimensionByName(["__distinct_key"]);if(this.parent)return this.parent.getDistinctKey();throw new Error("Asking a record for a primary key? Inconceivable!")}applyStructFiltersToTurtleDef(e){let r=e.pipeline;const i=e.annotation,s=e.filterList||[];return r=structuredClone(r),r[0].filterList=s.concat(r[0].filterList||[],(0,Me.isSourceDef)(this.structDef)?this.structDef.filterList||[]:[]),{type:"turtle",name:e.name,pipeline:r,annotation:i,location:e.location}}}class k4{constructor(e,r){this.eventStream=r,this.dialect=new itt.StandardSQLDialect,this.modelDef=void 0,this.structs=new Map,this.exploreSearchSQLMap=new Map,e&&this.loadModelFromDef(e)}loadModelFromDef(e){this.modelDef=e;for(const r of Object.values(this.modelDef.contents)){let i;if((0,Me.isSourceDef)(r))i=new p0(r,void 0,{model:this},{}),this.structs.set((0,Me.getIdentifier)(r),i),i.resolveQueryFields();else if(r.type!=="query")throw new Error("Internal Error: Unknown structure type")}}getStructByName(e){const r=this.structs.get(e);if(r)return r;throw new Error(`Struct ${e} not found in model.`)}getStructFromRef(e,r,i){var s;if(i??(i={}),typeof e=="string"){const o=this.getStructByName(e);return r!==void 0?new p0(o.structDef,r,(s=o.parent)!==null&&s!==void 0?s:{model:this},i):o}return new p0(e,r,{model:this},i)}loadQuery(e,r,i,s=!1,o=!1){var u;const a="";r||(r=new C2(!0,void 0));const l={type:"turtle",name:"ignoreme",pipeline:e.pipeline,filterList:e.filterList},c=(u=e.compositeResolvedSourceDef)!==null&&u!==void 0?u:e.structRef,f=ms.makeQuery(l,this.getStructFromRef(c,e.sourceArguments,i),r,o),x=f.generateSQLFromPipeline(r);if(s&&f.parent.dialect.hasFinalStage){const h=[];for(const p of x.outputStruct.fields)if((0,Me.isAtomic)(p)){const m=f.parent.dialect.sqlMaybeQuoteIdentifier(p.name);h.push(m)}x.lastStageName=r.addStage(f.parent.dialect.sqlFinalStage(x.lastStageName,h))}return{lastStageName:x.lastStageName,malloy:a,stageWriter:r,structs:[x.outputStruct],connectionName:f.parent.connectionName}}addDefaultRowLimit(e,r){const i={query:e,addedDefaultRowLimit:void 0};if(r===void 0)return i;const s=e.pipeline[e.pipeline.length-1];return s.type==="raw"||s.limit!==void 0?i:{query:{...e,pipeline:[...e.pipeline.slice(0,-1),{...s,limit:r}]},addedDefaultRowLimit:r}}compileQuery(e,r,i=!0){var s,o;const u=this.addDefaultRowLimit(e,r==null?void 0:r.defaultRowLimit);e=u.query;const a=u.addedDefaultRowLimit,c=this.loadQuery(e,void 0,r,i,!1),f=(s=e.compositeResolvedSourceDef)!==null&&s!==void 0?s:e.structRef,x=typeof f=="string"?f:f.as||f.name;return i&&this.dialect.hasFinalStage&&(c.lastStageName=c.stageWriter.addStage(this.dialect.sqlFinalStage(c.lastStageName,[]))),{lastStageName:c.lastStageName,malloy:c.malloy,sql:c.stageWriter.generateSQLStages(),dependenciesToMaterialize:c.stageWriter.dependenciesToMaterialize,materialization:(0,I4.shouldMaterialize)(e.annotation)?(0,I4.buildQueryMaterializationSpec)((o=e.location)===null||o===void 0?void 0:o.url,e.name,r==null?void 0:r.materializedTablePrefix):void 0,structs:c.structs,sourceExplore:x,sourceFilters:e.filterList,queryName:e.name,connectionName:c.connectionName,annotation:e.annotation,queryTimezone:c.structs[0].queryTimezone,defaultRowLimitAdded:a}}async searchIndex(e,r,i,s=1e3,o=void 0){if(!e.canPersist())return;const u=this.getStructByName(r);let a=[];for(const[E,A]of u.nameMap)To(A)&&A.includeInWildcard()&&a.push({type:"fieldref",path:[E]});a=a.sort((E,A)=>E.path[0].localeCompare(A.path[0]));const l={structRef:r,pipeline:[{type:"index",indexFields:a,sample:u.dialect.defaultSampling}]},c=u.dialect.sqlMaybeQuoteIdentifier("fieldName"),f=u.dialect.sqlMaybeQuoteIdentifier("fieldPath"),x=u.dialect.sqlMaybeQuoteIdentifier("fieldValue"),h=u.dialect.sqlMaybeQuoteIdentifier("fieldType"),p=u.dialect.sqlMaybeQuoteIdentifier("weight");let m=this.exploreSearchSQLMap.get(r);m===void 0&&(m=this.compileQuery(l,void 0,!1).sql,this.exploreSearchSQLMap.set(r,m));let g=`SELECT
|
|
1533
1533
|
${c},
|
|
1534
1534
|
${f},
|
|
1535
1535
|
${x},
|
|
@@ -1544,17 +1544,17 @@ FROM ${p}
|
|
|
1544
1544
|
`;return u.dialect.hasFinalStage&&(g=`WITH __stage0 AS(
|
|
1545
1545
|
${g}
|
|
1546
1546
|
)
|
|
1547
|
-
${u.dialect.sqlFinalStage("__stage0",[c,f,x,h,p,"match_first"])}`),(await e.runSQL(g,{rowLimit:1e3})).rows}}js.QueryModel=k4,function(t){var e=T&&T.__createBinding||(Object.create?function(o,u,a,l){l===void 0&&(l=a);var c=Object.getOwnPropertyDescriptor(u,a);(!c||("get"in c?!u.__esModule:c.writable||c.configurable))&&(c={enumerable:!0,get:function(){return u[a]}}),Object.defineProperty(o,l,c)}:function(o,u,a,l){l===void 0&&(l=a),o[l]=u[a]}),r=T&&T.__exportStar||function(o,u){for(var a in o)a!=="default"&&!Object.prototype.hasOwnProperty.call(u,a)&&e(u,o,a)};Object.defineProperty(t,"__esModule",{value:!0}),t.composeSQLExpr=t.indent=t.QueryModel=t.Segment=void 0,r(et,t);var i=js;Object.defineProperty(t,"Segment",{enumerable:!0,get:function(){return i.Segment}}),Object.defineProperty(t,"QueryModel",{enumerable:!0,get:function(){return i.QueryModel}});var s=kt;Object.defineProperty(t,"indent",{enumerable:!0,get:function(){return s.indent}}),Object.defineProperty(t,"composeSQLExpr",{enumerable:!0,get:function(){return s.composeSQLExpr}})}(Gi);var M4={},Wc={},P4={},sE={},b2={};Object.defineProperty(b2,"__esModule",{value:!0}),b2.detectAndRemovePartialStages=void 0;const btt=Gi;function Ttt(t,e){const r=[];let i=!1;for(const s of t)(0,btt.isPartialSegment)(s)?(r.push({...s,type:"reduce"}),i=!0):r.push(s);return i&&e.logError("ambiguous-view-type",{}),r}b2.detectAndRemovePartialStages=Ttt;var oE={},Ze={},T2={},dt={},Jn={};Object.defineProperty(Jn,"__esModule",{value:!0}),Jn.getSourceInfo=Jn.rangeFromContext=Jn.rangeFromToken=Jn.rangeFromTokens=Jn.isNotUndefined=Jn.locationContainsPosition=void 0;function Rtt(t,e){return t.range.start.line<=e.line&&t.range.end.line>=e.line&&(e.line!==t.range.start.line||e.character>=t.range.start.character)&&(e.line!==t.range.end.line||e.character<=t.range.end.character)}Jn.locationContainsPosition=Rtt;function Dtt(t){return t!==void 0}Jn.isNotUndefined=Dtt;function DB(t,e,r){const i={line:e.line-1,character:e.charPositionInLine};if(t&&r.stopIndex!==-1){const s=t.lines.length-1;for(let o=e.line-1;o<=s;o++){const u=t.at[o];if(r.stopIndex>=u.begin&&r.stopIndex<u.end)return{start:i,end:{line:o,character:r.stopIndex-u.begin+1}}}return{start:i,end:{line:s,character:t.lines[s].length}}}return{start:i,end:i}}Jn.rangeFromTokens=DB;function Ott(t,e){return DB(t,e,e)}Jn.rangeFromToken=Ott;function Ftt(t,e){return DB(t,e.start,e.stop||e.start)}Jn.rangeFromContext=Ftt;function wtt(t){const e=/\r?\n/,r={at:[],lines:[],length:t.length};let i=t,s=0;for(;i!=="";){const o=i.match(e);if(o&&o.index!==void 0){r.lines.push(i.slice(0,o.index));const u=o.index+o[0].length;r.at.push({begin:s,end:s+u}),s+=u,i=i.slice(u)}else{r.lines.push(i),r.at.push({begin:s,end:s+i.length});break}}return r}Jn.getSourceInfo=wtt,Object.defineProperty(dt,"__esModule",{value:!0}),dt.compositeFieldUsageJoinPaths=dt.joinedCompositeFieldUsage=dt.compositeFieldUsageDifference=dt.emptyCompositeFieldUsage=dt.mergeCompositeFieldUsage=dt.unique=dt.formatCompositeFieldUsage=dt.compositeFieldUsageIsPlural=dt.isEmptyCompositeFieldUsage=dt.formatCompositeFieldUsages=dt.compositeFieldUsagePaths=dt.resolveCompositeSources=dt.narrowCompositeFieldResolution=dt.emptyNarrowedCompositeFieldResolution=void 0;const Cle=Jn,OB=et;function U4(t,e,r,i=void 0){var s,o,u,a,l,c,f;let x={...e},h;const p=Utt(e);if(r.fields.length>0||e.type==="composite")if(e.type==="composite"){let y=!1;h=(s=i==null?void 0:i.source)!==null&&s!==void 0?s:e.sources.map(A=>({source:A,nested:void 0}));const E=[...h];e:for(const{source:A,nested:_}of h){const v=new Set;for(const C of A.fields)C.accessModifier!=="private"&&v.add((o=C.as)!==null&&o!==void 0?o:C.name);for(const C of r.fields)if(!v.has(C)){E.shift();continue e}if(A.type==="composite"){const C=U4(t,A,jtt(r,A),{source:_??A.sources.map(S=>({source:S,nested:[]})),joined:{}});if("error"in C){E.shift();continue e}x={...C.success},E[0]={source:A,nested:C.narrowedCompositeFieldResolution.source}}else x={...A};y=!0,x={...x,fields:[...p,...x.fields],filterList:[...(u=e.filterList)!==null&&u!==void 0?u:[],...(a=x.filterList)!==null&&a!==void 0?a:[]]};break}if(!y)return{error:{code:"no_suitable_composite_source_input",data:{fields:r.fields,path:t}}};h=E}else return{error:{code:"not_a_composite_source",data:{path:t}}};x.arguments=e.arguments;const m={},g=(l=i==null?void 0:i.joined)!==null&&l!==void 0?l:{};for(const y of x.fields)m[(c=y.as)!==null&&c!==void 0?c:y.name]=y;for(const[y,E]of Object.entries(r.joinedUsage)){const A=m[y],_=[...t,y];if(A===void 0)return{error:{code:"composite_source_not_defined",data:{path:_}}};if((0,OB.isJoined)(A)){if(!(0,OB.isSourceDef)(A))continue}else return{error:{code:"composite_source_not_a_join",data:{path:_}}};const v=U4(_,A,E,g[y]);if("error"in v)return v;if(!(0,OB.isJoinable)(v.success))return{error:{code:"composite_source_is_not_joinable",data:{path:_}}};m[y]={...v.success,join:A.join,as:(f=A.as)!==null&&f!==void 0?f:A.name,onExpression:A.onExpression},g[y]=v.narrowedCompositeFieldResolution}return{success:{...x,fields:Object.values(m)},narrowedCompositeFieldResolution:{source:h,joined:g}}}function Ntt(){return{source:void 0,joined:{}}}dt.emptyNarrowedCompositeFieldResolution=Ntt;function Ltt(t,e,r){const i=U4([],t,e,r);return"success"in i?{narrowedCompositeFieldResolution:i.narrowedCompositeFieldResolution,error:void 0}:{narrowedCompositeFieldResolution:void 0,error:i.error}}dt.narrowCompositeFieldResolution=Ltt;function Itt(t,e){const r=U4([],t,e);return"success"in r?{sourceDef:r.success,error:void 0}:{sourceDef:void 0,error:r.error}}dt.resolveCompositeSources=Itt;function FB(t){return[...t.fields.map(e=>[e]),...Object.entries(t.joinedUsage).map(([e,r])=>FB(r).map(i=>[e,...i])).flat()]}dt.compositeFieldUsagePaths=FB;function $tt(t){return FB(t).map(e=>Sle(e)).join(", ")}dt.formatCompositeFieldUsages=$tt;function wB(t){return Object.values(t.joinedUsage).reduce((e,r)=>e+wB(r),t.fields.length)}function Btt(t){return wB(t)===0}dt.isEmptyCompositeFieldUsage=Btt;function ktt(t){return wB(t)>1}dt.compositeFieldUsageIsPlural=ktt;function Sle(t){return`\`${t.join(".")}\``}dt.formatCompositeFieldUsage=Sle;function ble(t){return Array.from(new Set(t))}dt.unique=ble;function Tle(...t){const e=t.filter(Cle.isNotUndefined),r=new Set(e.map(s=>Object.keys(s.joinedUsage)).flat()),i={};for(const s of r)i[s]=Tle(...e.map(o=>o==null?void 0:o.joinedUsage[s]).filter(Cle.isNotUndefined));return{fields:ble(e.map(s=>s.fields).flat()),joinedUsage:i}}dt.mergeCompositeFieldUsage=Tle;function Mtt(){return{fields:[],joinedUsage:{}}}dt.emptyCompositeFieldUsage=Mtt;function Ptt(t,e){const r=new Set(e),i=[];for(const s of t)r.has(s)||i.push(s);return i}function Rle(t,e){return{fields:Ptt(t.fields,e.fields),joinedUsage:Object.fromEntries(Object.entries(t.joinedUsage).map(([r,i])=>[r,r in e.joinedUsage?Rle(i,e.joinedUsage[r]):i]))}}dt.compositeFieldUsageDifference=Rle;function Dle(t,e){return t.length===0?e:Dle(t.slice(0,-1),{fields:[],joinedUsage:{[t[t.length-1]]:e}})}dt.joinedCompositeFieldUsage=Dle;function Ole(t){const e=Object.keys(t.joinedUsage);return[...e.map(r=>[r]),...e.map(r=>Ole(t.joinedUsage[r]).map(i=>[r,...i])).flat()]}dt.compositeFieldUsageJoinPaths=Ole;function Fle(t){var e;return"e"in t&&((e=t.e)===null||e===void 0?void 0:e.node)==="compositeField"}function Utt(t){return t.fields.filter(e=>!Fle(e))}function jtt(t,e){var r;const i={};for(const s of e.fields)i[(r=s.as)!==null&&r!==void 0?r:s.name]=s;return{fields:t.fields.filter(s=>Fle(i[s])),joinedUsage:{}}}(function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.makeLogMessage=t.MESSAGE_FORMATTERS=t.BaseMessageLogger=void 0;const e=dt;class r{constructor(o){this.eventStream=o,this.rawLog=[]}getLog(){return this.rawLog}log(o){var u;this.rawLog.push(o),(u=this.eventStream)===null||u===void 0||u.emit(`translation-${o.severity}`,{code:o.code,data:o.data,message:o.message})}reset(){this.rawLog.length=0}noErrors(){return!this.hasErrors()}hasErrors(){return this.rawLog.find(u=>u.severity!=="warn")!==void 0}empty(){return this.rawLog.length===0}}t.BaseMessageLogger=r,t.MESSAGE_FORMATTERS={"pick-type-does-not-match":s=>({message:`pick type \`${s.pickType}\` does not match return type \`${s.returnType}\``,tag:"pick-values-must-match"}),"pick-else-type-does-not-match":s=>({message:`else type \`${s.elseType}\` does not match return type \`${s.returnType}\``,tag:"pick-values-must-match"}),"pick-default-type-does-not-match":s=>({message:`default type \`${s.defaultType}\` does not match return type \`${s.returnType}\``,tag:"pick-values-must-match"}),"experimental-dialect-not-enabled":s=>`Requires compiler flag '##! experimental.dialect.${s.dialect}'`,"pick-missing-else":"pick incomplete, missing 'else'","pick-missing-value":"pick with no value can only be used with apply","pick-illegal-partial":"pick with partial when can only be used with apply","pick-when-must-be-boolean":s=>`when expression must be boolean, not ${s.whenType}`,"sql-native-not-allowed-in-expression":s=>({message:`Unsupported SQL native type '${s.rawType}' not allowed in expression`,tag:"unsupported-sql-native-type-not-allowed-in-expression"}),"experiment-not-enabled":s=>`Experimental flag \`${s.experimentId}\` is not set, feature not available`,"ambiguous-view-type":"Can't determine view type (`group_by` / `aggregate` / `nest`, `project`, `index`)","import-error":s=>s.message.includes(s.url)?`import error: ${s.message}`:`import '${s.url}' error: ${s.message}`,"parsed-non-malloy-document":s=>`'${s.url}' did not parse to malloy document`,"parse-exception":s=>`Malloy internal parser exception [${s.message}]`,"syntax-error":s=>s.message,"internal-translator-error":s=>`Internal Translator Error: ${s.message}`,"invalid-timezone":s=>`Invalid timezone: ${s.timezone}`,"case-then-type-does-not-match":s=>`Case then type ${s.thenType} does not match return type ${s.returnType}`,"case-else-type-does-not-match":s=>`Case else type ${s.elseType} does not match return type ${s.returnType}`,"case-when-must-be-boolean":s=>`Case when expression must be boolean, not ${s.whenType}`,"case-when-type-does-not-match":s=>`Case when type ${s.whenType} does not match value type ${s.valueType}`,"invalid-composite-field-usage":s=>{const o=(0,e.formatCompositeFieldUsages)(s.newUsage),u=(0,e.formatCompositeFieldUsages)(s.allUsage);return`This operation uses composite field${(0,e.compositeFieldUsageIsPlural)(s.newUsage)?"s":""} ${o}, resulting in invalid usage of the composite source, as there is no composite input source which defines all of ${u}`}};function i(s,o,u){var a,l,c,f,x;const h=t.MESSAGE_FORMATTERS[s],p=h?h instanceof Function?h(o):h:typeof o=="string"?o:void 0;if(p===void 0)throw new Error(`No message formatter for error code \`${s}\`.`);const m=typeof p=="string"?{message:p}:p,g=((a=m.data)!==null&&a!==void 0?a:typeof o=="string")?null:o;return{code:s,data:g,message:m.message,severity:(c=(l=u==null?void 0:u.severity)!==null&&l!==void 0?l:m.severity)!==null&&c!==void 0?c:"error",errorTag:(f=u==null?void 0:u.tag)!==null&&f!==void 0?f:m.tag,replacement:(x=u==null?void 0:u.replacement)!==null&&x!==void 0?x:m.replacement,at:u==null?void 0:u.at}}t.makeLogMessage=i})(T2);var Hs={};Object.defineProperty(Hs,"__esModule",{value:!0}),Hs.errorFor=void 0;const qtt=dt;function Htt(t){return{type:"error",expressionType:"scalar",value:{node:"error",message:t},evalSpace:"constant",compositeFieldUsage:(0,qtt.emptyCompositeFieldUsage)()}}Hs.errorFor=Htt;var j4={};Object.defineProperty(j4,"__esModule",{value:!0}),j4.DialectNameSpace=void 0;class Qtt{constructor(e){this.entries=new Map;const r=e.getDialectFunctions();for(const i in r){const s=r[i];this.entries.set(i,{type:"function",name:i,overloads:s.map(o=>({returnType:o.returnType,params:o.params,supportsOrderBy:o.supportsOrderBy,supportsLimit:o.supportsLimit,isSymmetric:o.isSymmetric,genericTypes:o.genericTypes,dialect:{[e.name]:{e:o.e,defaultOrderByArgIndex:o.defaultOrderByArgIndex,between:o.between,needsWindowOrderBy:o.needsWindowOrderBy}}}))})}}getEntry(e){const r=this.entries.get(e);if(r!==void 0)return{entry:r,exported:!1}}setEntry(e,r,i){throw new Error("The dialect namespace is immutable!")}}j4.DialectNameSpace=Qtt;var R2={};Object.defineProperty(R2,"__esModule",{value:!0}),R2.getDialectFunctions=R2.GlobalNameSpace=void 0;const ztt=h2,Wtt=ka,Gtt=Gi;class Vtt{constructor(){this.entries=wle()}getEntry(e){const r=this.entries.get(e);if(r!==void 0)return{entry:r,exported:!1}}setEntry(e,r,i){throw new Error("The global namespace is immutable!")}}R2.GlobalNameSpace=Vtt;function Ytt(t,e){return t.params.length===e.params.length&&t.params.every((r,i)=>{const s=e.params[i];return r.isVariadic===s.isVariadic&&r.name===s.name&&r.allowedTypes.length===s.allowedTypes.length&&r.allowedTypes.every(o=>s.allowedTypes.some(u=>Gtt.TD.eq(o,u)&&o.expressionType===u.expressionType))})}function wle(){var t,e;const r=(0,ztt.getMalloyStandardFunctions)(),i={},s=(0,Wtt.getDialects)();for(const u of s)i[u.name]=u.getDialectFunctionOverrides();const o=new Map;for(const u in r){const a=r[u],l={type:"function",name:u,overloads:[]};for(const c of a){const f={returnType:c.returnType,params:c.params,dialect:{},supportsOrderBy:c.supportsOrderBy,supportsLimit:c.supportsLimit,genericTypes:c.genericTypes,isSymmetric:c.isSymmetric};for(const x of s){const p=(e=((t=i[x.name][u])!==null&&t!==void 0?t:[]).find(m=>Ytt(m,f)))!==null&&e!==void 0?e:c;f.dialect[x.name]={e:p.e,needsWindowOrderBy:p.needsWindowOrderBy,between:p.between,defaultOrderByArgIndex:p.defaultOrderByArgIndex}}l.overloads.push(f)}o.set(u,l)}return o}R2.getDialectFunctions=wle;var Qr={};Object.defineProperty(Qr,"__esModule",{value:!0}),Qr.extendNoteHelper=Qr.extendNoteMethod=Qr.isNoteable=void 0;function Ktt(t){return t.isNoteableObj}Qr.isNoteable=Ktt;function Jtt(t){Nle(this,t)}Qr.extendNoteMethod=Jtt;function Nle(t,e){(e.notes&&e.notes.length>0||e.blockNotes&&e.blockNotes.length>0||e.inherits!==void 0)&&(t.note={...t.note,...e})}Qr.extendNoteHelper=Nle,Object.defineProperty(Ze,"__esModule",{value:!0}),Ze.Document=Ze.DocStatementList=Ze.ListOf=Ze.isDocStatementOrDocStatementList=Ze.isDocStatement=Ze.ExperimentalExperiment=Ze.ModelEntryReference=Ze.Unimplemented=Ze.MalloyElement=void 0;const Lle=h2,q4=et,Xtt=$o,Ztt=T2,ent=Hs,tnt=j4,nnt=R2,Ile=Qr,rnt=m2;class Ua{constructor(e){this.children={},this.parent=null,this.logged=new Set,e&&this.has(e)}has(e){for(const r in e){const i=e[r];if(i!==void 0)if(this.children[r]=i,i instanceof Ua)i.parent=this;else for(const s of i)s.parent=this}}get location(){return this.codeLocation?this.codeLocation:this.parent?this.parent.location:{url:this.sourceURL,range:{start:{line:0,character:0},end:{line:0,character:0}}}}set location(e){this.codeLocation=e}get code(){var e,r;return(r=(e=this.translator())===null||e===void 0?void 0:e.codeAtLocation(this.location))!==null&&r!==void 0?r:""}document(){var e;return this instanceof LB?this:(e=this.parent)===null||e===void 0?void 0:e.document()}namespace(){if(this instanceof LB)return this;if(this.parent)return this.parent.namespace();throw new Error("INTERNAL ERROR: Translation without document scope")}getDialectNamespace(e){var r;return(r=this.document())===null||r===void 0?void 0:r.getDialectNamespace(e)}modelEntry(e){var r;const i=e instanceof NB?e.name:e,s=(r=this.namespace())===null||r===void 0?void 0:r.getEntry(i);return e instanceof NB&&((s==null?void 0:s.entry.type)==="query"?this.addReference({type:"queryReference",text:i,definition:s.entry,location:e.location}):s&&(0,q4.isSourceDef)(s.entry)&&this.addReference({type:"exploreReference",text:i,definition:s.entry,location:e.location})),s}kupuna(){var e;return((e=this.parent)===null||e===void 0?void 0:e.kupuna())||this}translator(){if(this.xlate)return this.xlate;if(this.parent)return this.parent.translator()}setTranslator(e){this.xlate=e}addReference(e){var r;(r=this.translator())===null||r===void 0||r.addReference(e)}get sourceURL(){const e=this.translator();return(e==null?void 0:e.sourceURL)||"(missing)"}log(e,r,i){const s=(0,Ztt.makeLogMessage)(e,r,{at:this.location,...i});if(this.codeLocation){if(this.logged.has(s.message))return e;this.logged.add(s.message)}return this.logger.log(s),e}logError(e,r,i){return this.log(e,r,{severity:"error",...i})}logWarning(e,r,i){return this.log(e,r,{severity:"warn",...i})}loggedErrorExpr(e,r,i){return(0,ent.errorFor)(this.logError(e,r,i))}get logger(){var e;const r=(e=this.translator())===null||e===void 0?void 0:e.root.logger;if(r===void 0)throw new Error("Attempted to access logger without a translator");return r}toString(){return this.stringify("",0)}stringify(e,r){const i=" ".repeat(r);let s=`${i}${e}<${this.elementType}>${this.varInfo()}`;for(const o of Object.keys(this.children)){const u=this.children[o];u instanceof Ua?s+=`
|
|
1547
|
+
${u.dialect.sqlFinalStage("__stage0",[c,f,x,h,p,"match_first"])}`),(await e.runSQL(g,{rowLimit:1e3})).rows}}js.QueryModel=k4,function(t){var e=T&&T.__createBinding||(Object.create?function(o,u,a,l){l===void 0&&(l=a);var c=Object.getOwnPropertyDescriptor(u,a);(!c||("get"in c?!u.__esModule:c.writable||c.configurable))&&(c={enumerable:!0,get:function(){return u[a]}}),Object.defineProperty(o,l,c)}:function(o,u,a,l){l===void 0&&(l=a),o[l]=u[a]}),r=T&&T.__exportStar||function(o,u){for(var a in o)a!=="default"&&!Object.prototype.hasOwnProperty.call(u,a)&&e(u,o,a)};Object.defineProperty(t,"__esModule",{value:!0}),t.composeSQLExpr=t.indent=t.QueryModel=t.Segment=void 0,r(et,t);var i=js;Object.defineProperty(t,"Segment",{enumerable:!0,get:function(){return i.Segment}}),Object.defineProperty(t,"QueryModel",{enumerable:!0,get:function(){return i.QueryModel}});var s=kt;Object.defineProperty(t,"indent",{enumerable:!0,get:function(){return s.indent}}),Object.defineProperty(t,"composeSQLExpr",{enumerable:!0,get:function(){return s.composeSQLExpr}})}(Gi);var M4={},Wc={},P4={},sE={},b2={};Object.defineProperty(b2,"__esModule",{value:!0}),b2.detectAndRemovePartialStages=void 0;const Rtt=Gi;function Dtt(t,e){const r=[];let i=!1;for(const s of t)(0,Rtt.isPartialSegment)(s)?(r.push({...s,type:"reduce"}),i=!0):r.push(s);return i&&e.logError("ambiguous-view-type",{}),r}b2.detectAndRemovePartialStages=Dtt;var oE={},Ze={},T2={},dt={},Jn={};Object.defineProperty(Jn,"__esModule",{value:!0}),Jn.getSourceInfo=Jn.rangeFromContext=Jn.rangeFromToken=Jn.rangeFromTokens=Jn.isNotUndefined=Jn.locationContainsPosition=void 0;function Ott(t,e){return t.range.start.line<=e.line&&t.range.end.line>=e.line&&(e.line!==t.range.start.line||e.character>=t.range.start.character)&&(e.line!==t.range.end.line||e.character<=t.range.end.character)}Jn.locationContainsPosition=Ott;function Ftt(t){return t!==void 0}Jn.isNotUndefined=Ftt;function DB(t,e,r){const i={line:e.line-1,character:e.charPositionInLine};if(t&&r.stopIndex!==-1){const s=t.lines.length-1;for(let o=e.line-1;o<=s;o++){const u=t.at[o];if(r.stopIndex>=u.begin&&r.stopIndex<u.end)return{start:i,end:{line:o,character:r.stopIndex-u.begin+1}}}return{start:i,end:{line:s,character:t.lines[s].length}}}return{start:i,end:i}}Jn.rangeFromTokens=DB;function wtt(t,e){return DB(t,e,e)}Jn.rangeFromToken=wtt;function Ntt(t,e){return DB(t,e.start,e.stop||e.start)}Jn.rangeFromContext=Ntt;function Ltt(t){const e=/\r?\n/,r={at:[],lines:[],length:t.length};let i=t,s=0;for(;i!=="";){const o=i.match(e);if(o&&o.index!==void 0){r.lines.push(i.slice(0,o.index));const u=o.index+o[0].length;r.at.push({begin:s,end:s+u}),s+=u,i=i.slice(u)}else{r.lines.push(i),r.at.push({begin:s,end:s+i.length});break}}return r}Jn.getSourceInfo=Ltt,Object.defineProperty(dt,"__esModule",{value:!0}),dt.compositeFieldUsageJoinPaths=dt.joinedCompositeFieldUsage=dt.compositeFieldUsageDifference=dt.emptyCompositeFieldUsage=dt.mergeCompositeFieldUsage=dt.unique=dt.formatCompositeFieldUsage=dt.compositeFieldUsageIsPlural=dt.isEmptyCompositeFieldUsage=dt.formatCompositeFieldUsages=dt.compositeFieldUsagePaths=dt.resolveCompositeSources=dt.narrowCompositeFieldResolution=dt.emptyNarrowedCompositeFieldResolution=void 0;const Cle=Jn,OB=et;function U4(t,e,r,i=void 0){var s,o,u,a,l,c,f;let x={...e},h;const p=qtt(e);if(r.fields.length>0||e.type==="composite")if(e.type==="composite"){let y=!1;h=(s=i==null?void 0:i.source)!==null&&s!==void 0?s:e.sources.map(A=>({source:A,nested:void 0}));const E=[...h];e:for(const{source:A,nested:_}of h){const v=new Set;for(const C of A.fields)C.accessModifier!=="private"&&v.add((o=C.as)!==null&&o!==void 0?o:C.name);for(const C of r.fields)if(!v.has(C)){E.shift();continue e}if(A.type==="composite"){const C=U4(t,A,Htt(r,A),{source:_??A.sources.map(S=>({source:S,nested:[]})),joined:{}});if("error"in C){E.shift();continue e}x={...C.success},E[0]={source:A,nested:C.narrowedCompositeFieldResolution.source}}else x={...A};y=!0,x={...x,fields:[...p,...x.fields],filterList:[...(u=e.filterList)!==null&&u!==void 0?u:[],...(a=x.filterList)!==null&&a!==void 0?a:[]]};break}if(!y)return{error:{code:"no_suitable_composite_source_input",data:{fields:r.fields,path:t}}};h=E}else return{error:{code:"not_a_composite_source",data:{path:t}}};x.arguments=e.arguments;const m={},g=(l=i==null?void 0:i.joined)!==null&&l!==void 0?l:{};for(const y of x.fields)m[(c=y.as)!==null&&c!==void 0?c:y.name]=y;for(const[y,E]of Object.entries(r.joinedUsage)){const A=m[y],_=[...t,y];if(A===void 0)return{error:{code:"composite_source_not_defined",data:{path:_}}};if((0,OB.isJoined)(A)){if(!(0,OB.isSourceDef)(A))continue}else return{error:{code:"composite_source_not_a_join",data:{path:_}}};const v=U4(_,A,E,g[y]);if("error"in v)return v;if(!(0,OB.isJoinable)(v.success))return{error:{code:"composite_source_is_not_joinable",data:{path:_}}};m[y]={...v.success,join:A.join,as:(f=A.as)!==null&&f!==void 0?f:A.name,onExpression:A.onExpression},g[y]=v.narrowedCompositeFieldResolution}return{success:{...x,fields:Object.values(m)},narrowedCompositeFieldResolution:{source:h,joined:g}}}function Itt(){return{source:void 0,joined:{}}}dt.emptyNarrowedCompositeFieldResolution=Itt;function $tt(t,e,r){const i=U4([],t,e,r);return"success"in i?{narrowedCompositeFieldResolution:i.narrowedCompositeFieldResolution,error:void 0}:{narrowedCompositeFieldResolution:void 0,error:i.error}}dt.narrowCompositeFieldResolution=$tt;function Btt(t,e){const r=U4([],t,e);return"success"in r?{sourceDef:r.success,error:void 0}:{sourceDef:void 0,error:r.error}}dt.resolveCompositeSources=Btt;function FB(t){return[...t.fields.map(e=>[e]),...Object.entries(t.joinedUsage).map(([e,r])=>FB(r).map(i=>[e,...i])).flat()]}dt.compositeFieldUsagePaths=FB;function ktt(t){return FB(t).map(e=>Sle(e)).join(", ")}dt.formatCompositeFieldUsages=ktt;function wB(t){return Object.values(t.joinedUsage).reduce((e,r)=>e+wB(r),t.fields.length)}function Mtt(t){return wB(t)===0}dt.isEmptyCompositeFieldUsage=Mtt;function Ptt(t){return wB(t)>1}dt.compositeFieldUsageIsPlural=Ptt;function Sle(t){return`\`${t.join(".")}\``}dt.formatCompositeFieldUsage=Sle;function ble(t){return Array.from(new Set(t))}dt.unique=ble;function Tle(...t){const e=t.filter(Cle.isNotUndefined),r=new Set(e.map(s=>Object.keys(s.joinedUsage)).flat()),i={};for(const s of r)i[s]=Tle(...e.map(o=>o==null?void 0:o.joinedUsage[s]).filter(Cle.isNotUndefined));return{fields:ble(e.map(s=>s.fields).flat()),joinedUsage:i}}dt.mergeCompositeFieldUsage=Tle;function Utt(){return{fields:[],joinedUsage:{}}}dt.emptyCompositeFieldUsage=Utt;function jtt(t,e){const r=new Set(e),i=[];for(const s of t)r.has(s)||i.push(s);return i}function Rle(t,e){return{fields:jtt(t.fields,e.fields),joinedUsage:Object.fromEntries(Object.entries(t.joinedUsage).map(([r,i])=>[r,r in e.joinedUsage?Rle(i,e.joinedUsage[r]):i]))}}dt.compositeFieldUsageDifference=Rle;function Dle(t,e){return t.length===0?e:Dle(t.slice(0,-1),{fields:[],joinedUsage:{[t[t.length-1]]:e}})}dt.joinedCompositeFieldUsage=Dle;function Ole(t){const e=Object.keys(t.joinedUsage);return[...e.map(r=>[r]),...e.map(r=>Ole(t.joinedUsage[r]).map(i=>[r,...i])).flat()]}dt.compositeFieldUsageJoinPaths=Ole;function Fle(t){var e;return"e"in t&&((e=t.e)===null||e===void 0?void 0:e.node)==="compositeField"}function qtt(t){return t.fields.filter(e=>!Fle(e))}function Htt(t,e){var r;const i={};for(const s of e.fields)i[(r=s.as)!==null&&r!==void 0?r:s.name]=s;return{fields:t.fields.filter(s=>Fle(i[s])),joinedUsage:{}}}(function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.makeLogMessage=t.MESSAGE_FORMATTERS=t.BaseMessageLogger=void 0;const e=dt;class r{constructor(o){this.eventStream=o,this.rawLog=[]}getLog(){return this.rawLog}log(o){var u;this.rawLog.push(o),(u=this.eventStream)===null||u===void 0||u.emit(`translation-${o.severity}`,{code:o.code,data:o.data,message:o.message})}reset(){this.rawLog.length=0}noErrors(){return!this.hasErrors()}hasErrors(){return this.rawLog.find(u=>u.severity!=="warn")!==void 0}empty(){return this.rawLog.length===0}}t.BaseMessageLogger=r,t.MESSAGE_FORMATTERS={"pick-type-does-not-match":s=>({message:`pick type \`${s.pickType}\` does not match return type \`${s.returnType}\``,tag:"pick-values-must-match"}),"pick-else-type-does-not-match":s=>({message:`else type \`${s.elseType}\` does not match return type \`${s.returnType}\``,tag:"pick-values-must-match"}),"pick-default-type-does-not-match":s=>({message:`default type \`${s.defaultType}\` does not match return type \`${s.returnType}\``,tag:"pick-values-must-match"}),"experimental-dialect-not-enabled":s=>`Requires compiler flag '##! experimental.dialect.${s.dialect}'`,"pick-missing-else":"pick incomplete, missing 'else'","pick-missing-value":"pick with no value can only be used with apply","pick-illegal-partial":"pick with partial when can only be used with apply","pick-when-must-be-boolean":s=>`when expression must be boolean, not ${s.whenType}`,"sql-native-not-allowed-in-expression":s=>({message:`Unsupported SQL native type '${s.rawType}' not allowed in expression`,tag:"unsupported-sql-native-type-not-allowed-in-expression"}),"experiment-not-enabled":s=>`Experimental flag \`${s.experimentId}\` is not set, feature not available`,"ambiguous-view-type":"Can't determine view type (`group_by` / `aggregate` / `nest`, `project`, `index`)","import-error":s=>s.message.includes(s.url)?`import error: ${s.message}`:`import '${s.url}' error: ${s.message}`,"parsed-non-malloy-document":s=>`'${s.url}' did not parse to malloy document`,"parse-exception":s=>`Malloy internal parser exception [${s.message}]`,"syntax-error":s=>s.message,"internal-translator-error":s=>`Internal Translator Error: ${s.message}`,"invalid-timezone":s=>`Invalid timezone: ${s.timezone}`,"case-then-type-does-not-match":s=>`Case then type ${s.thenType} does not match return type ${s.returnType}`,"case-else-type-does-not-match":s=>`Case else type ${s.elseType} does not match return type ${s.returnType}`,"case-when-must-be-boolean":s=>`Case when expression must be boolean, not ${s.whenType}`,"case-when-type-does-not-match":s=>`Case when type ${s.whenType} does not match value type ${s.valueType}`,"invalid-composite-field-usage":s=>{const o=(0,e.formatCompositeFieldUsages)(s.newUsage),u=(0,e.formatCompositeFieldUsages)(s.allUsage);return`This operation uses composite field${(0,e.compositeFieldUsageIsPlural)(s.newUsage)?"s":""} ${o}, resulting in invalid usage of the composite source, as there is no composite input source which defines all of ${u}`}};function i(s,o,u){var a,l,c,f,x;const h=t.MESSAGE_FORMATTERS[s],p=h?h instanceof Function?h(o):h:typeof o=="string"?o:void 0;if(p===void 0)throw new Error(`No message formatter for error code \`${s}\`.`);const m=typeof p=="string"?{message:p}:p,g=((a=m.data)!==null&&a!==void 0?a:typeof o=="string")?null:o;return{code:s,data:g,message:m.message,severity:(c=(l=u==null?void 0:u.severity)!==null&&l!==void 0?l:m.severity)!==null&&c!==void 0?c:"error",errorTag:(f=u==null?void 0:u.tag)!==null&&f!==void 0?f:m.tag,replacement:(x=u==null?void 0:u.replacement)!==null&&x!==void 0?x:m.replacement,at:u==null?void 0:u.at}}t.makeLogMessage=i})(T2);var Hs={};Object.defineProperty(Hs,"__esModule",{value:!0}),Hs.errorFor=void 0;const Qtt=dt;function ztt(t){return{type:"error",expressionType:"scalar",value:{node:"error",message:t},evalSpace:"constant",compositeFieldUsage:(0,Qtt.emptyCompositeFieldUsage)()}}Hs.errorFor=ztt;var j4={};Object.defineProperty(j4,"__esModule",{value:!0}),j4.DialectNameSpace=void 0;class Wtt{constructor(e){this.entries=new Map;const r=e.getDialectFunctions();for(const i in r){const s=r[i];this.entries.set(i,{type:"function",name:i,overloads:s.map(o=>({returnType:o.returnType,params:o.params,supportsOrderBy:o.supportsOrderBy,supportsLimit:o.supportsLimit,isSymmetric:o.isSymmetric,genericTypes:o.genericTypes,dialect:{[e.name]:{e:o.e,defaultOrderByArgIndex:o.defaultOrderByArgIndex,between:o.between,needsWindowOrderBy:o.needsWindowOrderBy}}}))})}}getEntry(e){const r=this.entries.get(e);if(r!==void 0)return{entry:r,exported:!1}}setEntry(e,r,i){throw new Error("The dialect namespace is immutable!")}}j4.DialectNameSpace=Wtt;var R2={};Object.defineProperty(R2,"__esModule",{value:!0}),R2.getDialectFunctions=R2.GlobalNameSpace=void 0;const Gtt=h2,Vtt=ka,Ytt=Gi;class Ktt{constructor(){this.entries=wle()}getEntry(e){const r=this.entries.get(e);if(r!==void 0)return{entry:r,exported:!1}}setEntry(e,r,i){throw new Error("The global namespace is immutable!")}}R2.GlobalNameSpace=Ktt;function Jtt(t,e){return t.params.length===e.params.length&&t.params.every((r,i)=>{const s=e.params[i];return r.isVariadic===s.isVariadic&&r.name===s.name&&r.allowedTypes.length===s.allowedTypes.length&&r.allowedTypes.every(o=>s.allowedTypes.some(u=>Ytt.TD.eq(o,u)&&o.expressionType===u.expressionType))})}function wle(){var t,e;const r=(0,Gtt.getMalloyStandardFunctions)(),i={},s=(0,Vtt.getDialects)();for(const u of s)i[u.name]=u.getDialectFunctionOverrides();const o=new Map;for(const u in r){const a=r[u],l={type:"function",name:u,overloads:[]};for(const c of a){const f={returnType:c.returnType,params:c.params,dialect:{},supportsOrderBy:c.supportsOrderBy,supportsLimit:c.supportsLimit,genericTypes:c.genericTypes,isSymmetric:c.isSymmetric};for(const x of s){const p=(e=((t=i[x.name][u])!==null&&t!==void 0?t:[]).find(m=>Jtt(m,f)))!==null&&e!==void 0?e:c;f.dialect[x.name]={e:p.e,needsWindowOrderBy:p.needsWindowOrderBy,between:p.between,defaultOrderByArgIndex:p.defaultOrderByArgIndex}}l.overloads.push(f)}o.set(u,l)}return o}R2.getDialectFunctions=wle;var Qr={};Object.defineProperty(Qr,"__esModule",{value:!0}),Qr.extendNoteHelper=Qr.extendNoteMethod=Qr.isNoteable=void 0;function Xtt(t){return t.isNoteableObj}Qr.isNoteable=Xtt;function Ztt(t){Nle(this,t)}Qr.extendNoteMethod=Ztt;function Nle(t,e){(e.notes&&e.notes.length>0||e.blockNotes&&e.blockNotes.length>0||e.inherits!==void 0)&&(t.note={...t.note,...e})}Qr.extendNoteHelper=Nle,Object.defineProperty(Ze,"__esModule",{value:!0}),Ze.Document=Ze.DocStatementList=Ze.ListOf=Ze.isDocStatementOrDocStatementList=Ze.isDocStatement=Ze.ExperimentalExperiment=Ze.ModelEntryReference=Ze.Unimplemented=Ze.MalloyElement=void 0;const Lle=h2,q4=et,ent=$o,tnt=T2,nnt=Hs,rnt=j4,int=R2,Ile=Qr,snt=m2;class Ua{constructor(e){this.children={},this.parent=null,this.logged=new Set,e&&this.has(e)}has(e){for(const r in e){const i=e[r];if(i!==void 0)if(this.children[r]=i,i instanceof Ua)i.parent=this;else for(const s of i)s.parent=this}}get location(){return this.codeLocation?this.codeLocation:this.parent?this.parent.location:{url:this.sourceURL,range:{start:{line:0,character:0},end:{line:0,character:0}}}}set location(e){this.codeLocation=e}get code(){var e,r;return(r=(e=this.translator())===null||e===void 0?void 0:e.codeAtLocation(this.location))!==null&&r!==void 0?r:""}document(){var e;return this instanceof LB?this:(e=this.parent)===null||e===void 0?void 0:e.document()}namespace(){if(this instanceof LB)return this;if(this.parent)return this.parent.namespace();throw new Error("INTERNAL ERROR: Translation without document scope")}getDialectNamespace(e){var r;return(r=this.document())===null||r===void 0?void 0:r.getDialectNamespace(e)}modelEntry(e){var r;const i=e instanceof NB?e.name:e,s=(r=this.namespace())===null||r===void 0?void 0:r.getEntry(i);return e instanceof NB&&((s==null?void 0:s.entry.type)==="query"?this.addReference({type:"queryReference",text:i,definition:s.entry,location:e.location}):s&&(0,q4.isSourceDef)(s.entry)&&this.addReference({type:"exploreReference",text:i,definition:s.entry,location:e.location})),s}kupuna(){var e;return((e=this.parent)===null||e===void 0?void 0:e.kupuna())||this}translator(){if(this.xlate)return this.xlate;if(this.parent)return this.parent.translator()}setTranslator(e){this.xlate=e}addReference(e){var r;(r=this.translator())===null||r===void 0||r.addReference(e)}get sourceURL(){const e=this.translator();return(e==null?void 0:e.sourceURL)||"(missing)"}log(e,r,i){const s=(0,tnt.makeLogMessage)(e,r,{at:this.location,...i});if(this.codeLocation){if(this.logged.has(s.message))return e;this.logged.add(s.message)}return this.logger.log(s),e}logError(e,r,i){return this.log(e,r,{severity:"error",...i})}logWarning(e,r,i){return this.log(e,r,{severity:"warn",...i})}loggedErrorExpr(e,r,i){return(0,nnt.errorFor)(this.logError(e,r,i))}get logger(){var e;const r=(e=this.translator())===null||e===void 0?void 0:e.root.logger;if(r===void 0)throw new Error("Attempted to access logger without a translator");return r}toString(){return this.stringify("",0)}stringify(e,r){const i=" ".repeat(r);let s=`${i}${e}<${this.elementType}>${this.varInfo()}`;for(const o of Object.keys(this.children)){const u=this.children[o];u instanceof Ua?s+=`
|
|
1548
1548
|
`+u.stringify(`${o}: `,r+2):(s+=`
|
|
1549
1549
|
${i} ${o}: [`,u.length>0&&(s+=`
|
|
1550
1550
|
`+u.map(a=>a.stringify("",r+4)).join(`
|
|
1551
1551
|
`)+`
|
|
1552
|
-
${i} `),s+="]")}return s}*walk(){for(const e of Object.keys(this.children)){const r=this.children[e];if(r instanceof Ua)yield r;else for(const i of r)yield i}}varInfo(){let e="";for(const[r,i]of Object.entries(this))r!=="elementType"&&(typeof i=="boolean"?e+=i?` ${r}`:` !${r}`:(typeof i=="string"||typeof i=="number")&&(e+=` ${r}=${i}`));return e}internalError(e){return new Error(`INTERNAL ERROR IN TRANSLATION: ${e}`)}needs(e){for(const r of this.walk()){const i=r.needs(e);if(i)return i}}inExperiment(e,r=!1){var i;const s=(i=this.translator())===null||i===void 0?void 0:i.compilerFlags.tag("experimental");return s&&(s.bare()||s.has(e))?!0:(r||this.logError("experiment-not-enabled",{experimentId:e}),!1)}}Ze.MalloyElement=Ua;class int extends Ua{constructor(){super(...arguments),this.elementType="unimplemented",this.reported=!1}}Ze.Unimplemented=int;class NB extends Ua{constructor(e){super(),this.name=e,this.elementType="modelEntryReference"}get refString(){return this.name}toString(){return this.refString}getNamed(){var e;return(e=this.modelEntry(this))===null||e===void 0?void 0:e.entry}}Ze.ModelEntryReference=NB;class snt extends Ua{constructor(e){super(),this.id=e,this.elementType="experimentalExperiment"}execute(e){this.inExperiment(this.id)}}Ze.ExperimentalExperiment=snt;function $le(t){return t.execute!==void 0}Ze.isDocStatement=$le;function ont(t){return t instanceof uE||$le(t)}Ze.isDocStatementOrDocStatementList=ont;class Ble extends Ua{constructor(e){super(),this.elements=e,this.newContents()}newContents(){this.has({listOf:this.elements})}get list(){return this.elements}empty(){return this.elements.length===0}notEmpty(){return this.elements.length>0}push(...e){return this.elements.push(...e),this.newContents(),this.elements}needs(e){for(const r of this.elements){const i=r.needs(e);if(i)return i}}}Ze.ListOf=Ble;class uE extends Ble{constructor(){super(...arguments),this.elementType="topLevelStatements",this.execCursor=0,this.isNoteableObj=!0,this.extendNote=Ile.extendNoteMethod,this.noteCursor=0}executeList(e){for(;this.execCursor<this.elements.length;){const r=this.elements[this.execCursor];if(this.noteCursor===this.execCursor&&(this.note&&(0,Ile.isNoteable)(r)&&r.extendNote(this.note),this.noteCursor+=1),r instanceof uE){const i=r.executeList(e);if(i)return i}else{const i=r.needs(e);if(i)return i;r.execute(e)}this.execCursor+=1}}}Ze.DocStatementList=uE;const unt="5a79a191-06bc-43cf-9b12-58741cd82970";function kle(t){const e=t.inherits?kle(t.inherits):[];return t.blockNotes&&e.push(...t.blockNotes.map(r=>r.text)),t.notes&&e.push(...t.notes.map(r=>r.text)),e}function ant(t){const e=kle(t).join("");return(0,rnt.v5)(e,unt)}class LB extends Ua{constructor(e){super(),this.elementType="document",this.globalNameSpace=new nnt.GlobalNameSpace,this.documentModel={},this.queryList=[],this.didInitModel=!1,this.annotation={},this.experiments=new Xtt.Tag({}),this.modelAnnotationTodoList=[],this.dialectNameSpaces=new Map,this.statements=new uE(e),this.has({statements:e})}initModelDef(e){if(!this.didInitModel){if(this.documentModel={},this.queryList=[],e){e.annotation&&(this.annotation.inherits=e.annotation);for(const[r,i]of Object.entries(e.contents)){const s=structuredClone(i);if((0,q4.isSourceDef)(s)||s.type==="query"||s.type==="function"){const o=e.exports.includes(r);this.setEntry(r,{entry:s,exported:o})}}}this.didInitModel=!0}}compile(){const e=this.statements.executeList(this),r=this.modelDef();if(e===void 0)for(const s of this.queryList)s.modelAnnotation===void 0&&r.annotation&&(s.modelAnnotation=r.annotation);if(r.annotation)for(const s of this.modelAnnotationTodoList)s.modelAnnotation||(s.modelAnnotation=r.annotation);return{modelDef:{...r,queryList:this.queryList},needs:e}}rememberToAddModelAnnotations(e){this.modelAnnotationTodoList.push(e)}hasAnnotation(){return this.annotation.notes&&this.annotation.notes.length>0||this.annotation.inherits!==void 0}currentModelAnnotation(){if(this.hasAnnotation()){const e={...this.annotation,id:""};return e.id=ant(e),e}}modelDef(){const e={name:"",exports:[],contents:{},queryList:[],dependencies:{}};this.hasAnnotation()&&(e.annotation=this.currentModelAnnotation());for(const r in this.documentModel){const i=this.documentModel[r].entry;if((0,q4.isSourceDef)(i)||i.type==="query"){this.documentModel[r].exported&&e.exports.push(r);const s=structuredClone(i);s.modelAnnotation===void 0&&e.annotation&&(s.modelAnnotation=e.annotation),e.contents[r]=s}}return e}getEntry(e){var r;return(r=this.globalNameSpace.getEntry(e))!==null&&r!==void 0?r:this.documentModel[e]}setEntry(e,r){this.globalNameSpace.getEntry(e)!==void 0&&this.logError("name-conflict-with-global",`Cannot redefine '${e}', which is in global namespace`),(0,q4.isSourceDef)(r.entry)&&this.checkExperimentalDialect(this,r.entry.dialect),this.documentModel[e]=r}checkExperimentalDialect(e,r){const i=this.translator();i&&i.firstReferenceToDialect(r)&&(0,Lle.getDialect)(r).experimental&&!i.experimentalDialectEnabled(r)&&e.logError("experimental-dialect-not-enabled",{dialect:r})}getDialectNamespace(e){if(this.dialectNameSpaces.has(e))return this.dialectNameSpaces.get(e);const r=(0,Lle.getDialect)(e),i=new tnt.DialectNameSpace(r);return this.dialectNameSpaces.set(e,i),i}}Ze.Document=LB;var H4={},D2={},nn={};(function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.atomicDef=t.inspect=t.typeEq=t.typeIn=t.eq=t.any=t.anyAtomicT=t.aggregateBoolT=t.viewT=t.errorT=t.boolT=t.timestampT=t.dateT=t.stringT=t.numberT=t.nullT=void 0;const e=Gi,r=dt;function i(f,x="scalar",h="constant"){return{type:f,expressionType:x,evalSpace:h,compositeFieldUsage:(0,r.emptyCompositeFieldUsage)()}}t.nullT=i("null"),t.numberT=i("number"),t.stringT=i("string"),t.dateT=i("date"),t.timestampT=i("timestamp"),t.boolT=i("boolean"),t.errorT=i("error"),t.viewT=i("turtle"),t.aggregateBoolT=i("boolean","aggregate"),t.anyAtomicT=[t.numberT,t.stringT,t.dateT,t.timestampT,t.boolT];function s(f,x){return f?x.find(p=>o(p,f))!==void 0:!1}t.any=s;function o(f,x){return x!==void 0&&e.TD.eq(f,x)&&f.expressionType===x.expressionType}t.eq=o;function u(f,x){return f?x.find(p=>a(p,f))!==void 0:!1}t.typeIn=u;function a(f,x,h=!1,p=!0){const m=e.TD.eq(f,x),g=h&&(f.type==="null"||x.type==="null"),y=p&&(f.type==="error"||x.type==="error");return m||g||y}t.typeEq=a;function l(...f){return f.map(h=>{if(h){let p=h.type;return(0,e.expressionIsScalar)(h.expressionType)||(p=`${h.expressionType} ${p}`),p}return"undefined"}).join(",")}t.inspect=l;function c(f){if(e.TD.isAtomic(f))switch(f.type){case"array":return(0,e.isRepeatedRecord)(f)?{type:"array",elementTypeDef:f.elementTypeDef,fields:f.fields}:{type:"array",elementTypeDef:f.elementTypeDef};case"record":return{type:"record",fields:f.fields};case"number":return f.numberType?{type:"number",numberType:f.numberType}:{type:"number"};case"sql native":return f.rawType?{type:"sql native",rawType:f.rawType}:{type:"sql native"};default:return{type:f.type}}return{type:"error"}}t.atomicDef=c})(nn);var zr={},Gc={};Object.defineProperty(Gc,"__esModule",{value:!0}),Gc.canMakeEntry=Gc.SpaceEntry=void 0;class lnt{}Gc.SpaceEntry=lnt;function cnt(t){return"makeEntry"in t}Gc.canMakeEntry=cnt,Object.defineProperty(zr,"__esModule",{value:!0}),zr.SpaceField=void 0;const fnt=Gc,xnt=dt;class dnt extends fnt.SpaceEntry{constructor(){super(...arguments),this.refType="field"}fieldTypeFromFieldDef(e){var r,i,s;const o=e.expressionType||"scalar";return{...e,expressionType:o,evalSpace:"input",compositeFieldUsage:(r=e.compositeFieldUsage)!==null&&r!==void 0?r:((i=e.e)===null||i===void 0?void 0:i.node)==="compositeField"?{fields:[(s=e.as)!==null&&s!==void 0?s:e.name],joinedUsage:{}}:(0,xnt.emptyCompositeFieldUsage)()}}getQueryFieldDef(e){}fieldDef(){}constructorFieldDef(){}}zr.SpaceField=dnt;var hnt=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),pnt=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),mnt=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&hnt(e,t,r);return pnt(e,t),e};Object.defineProperty(D2,"__esModule",{value:!0}),D2.ViewField=void 0;const gnt=dt,ynt=mnt(nn),Ent=zr;class Ant extends Ent.SpaceField{constructor(e){super(),this.inSpace=e}typeDesc(){var e;const r=this.fieldDef();return{...ynt.viewT,compositeFieldUsage:(e=r.compositeFieldUsage)!==null&&e!==void 0?e:(0,gnt.emptyCompositeFieldUsage)()}}}D2.ViewField=Ant,Object.defineProperty(H4,"__esModule",{value:!0}),H4.ASTViewField=void 0;const _nt=D2;class vnt extends _nt.ViewField{constructor(e,r,i){super(e),this.view=r,this.name=i,this.turtleDef=void 0}getQueryFieldDef(e){return this.view.getFieldDef(e)}fieldDef(){return this.turtleDef===void 0&&(this.turtleDef=this.view.getFieldDef(this.inSpace)),this.turtleDef}}H4.ASTViewField=vnt,Object.defineProperty(oE,"__esModule",{value:!0}),oE.ViewFieldDeclaration=void 0;const Cnt=Ze,Snt=Qr,bnt=b2,Tnt=H4;class Rnt extends Cnt.MalloyElement{constructor(e,r){super({view:r}),this.name=e,this.view=r,this.elementType="view-field-declaration",this.isNoteableObj=!0,this.extendNote=Snt.extendNoteMethod}makeEntry(e){const r=new Tnt.ASTViewField(e,this,this.name);e.newEntry(this.name,this,r)}getName(){return this.name}getFieldDef(e){const{pipeline:r,annotation:i}=this.view.pipelineComp(e),s=(0,bnt.detectAndRemovePartialStages)(r,this);return{type:"turtle",name:this.name,pipeline:s,annotation:{...this.note,inherits:i},location:this.location}}}oE.ViewFieldDeclaration=Rnt;var zn={};Object.defineProperty(zn,"__esModule",{value:!0}),zn.LegalRefinementStage=zn.QueryClass=void 0;var Mle;(function(t){t.Index="index",t.Project="project",t.Grouping="grouping"})(Mle||(zn.QueryClass=Mle={}));var Ple;(function(t){t[t.Single=0]="Single",t[t.Head=1]="Head",t[t.Tail=2]="Tail"})(Ple||(zn.LegalRefinementStage=Ple={}));var Dnt=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),Ont=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),Fnt=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&Dnt(e,t,r);return Ont(e,t),e};Object.defineProperty(sE,"__esModule",{value:!0}),sE.NestFieldDeclaration=void 0;const wnt=Fnt(et),Nnt=b2,Lnt=oE,Ule=zn;class Int extends Lnt.ViewFieldDeclaration{constructor(){super(...arguments),this.elementType="nest-field-declaration",this.queryRefinementStage=Ule.LegalRefinementStage.Single,this.forceQueryClass=Ule.QueryClass.Grouping,this.turtleDef=void 0}queryExecute(e){e.resultFS.pushFields(this)}getFieldDef(e){if(this.turtleDef)return this.turtleDef;if(e.isQueryFieldSpace()){const{pipeline:r,annotation:i}=this.view.pipelineComp(e,e.outputSpace()),s=r[0]&&wnt.isQuerySegment(r[0])?r[0].compositeFieldUsage:void 0,o=(0,Nnt.detectAndRemovePartialStages)(r,this);return this.turtleDef={type:"turtle",name:this.name,pipeline:o,annotation:{...this.note,inherits:i},location:this.location,compositeFieldUsage:s},this.turtleDef}throw this.internalError("Unexpected namespace for nest")}}sE.NestFieldDeclaration=Int;var O2={},gi={};Object.defineProperty(gi,"__esModule",{value:!0}),gi.ErrorFactory=void 0;const jle="~malformed~";class IB{static get structDef(){return{type:"table",name:jle,dialect:"~malformed~",connection:"~unknown~",tablePath:"//undefined_error_table_path",fields:[],errorFactory:!0}}static get joinDef(){return{type:"table",name:jle,dialect:"~malformed~",connection:"~unknown~",tablePath:"//undefined_error_table_path",fields:[],join:"one",matrixOperation:"left",errorFactory:!0}}static didCreate(e){return e.type==="table"&&"errorFactory"in e}static get query(){return{structRef:IB.structDef,pipeline:[]}}static get reduceSegment(){return{type:"reduce",queryFields:[]}}static get projectSegment(){return{type:"project",queryFields:[]}}static get indexSegment(){return{type:"index",indexFields:[]}}}gi.ErrorFactory=IB,Object.defineProperty(O2,"__esModule",{value:!0}),O2.DefineSourceList=O2.DefineSource=void 0;const $nt=gi,qle=Ze,Bnt=Qr;class knt extends qle.MalloyElement{constructor(e,r,i,s){super(),this.name=e,this.sourceExpr=r,this.exported=i,this.parameters=s,this.elementType="defineSource",this.isNoteableObj=!0,this.extendNote=Bnt.extendNoteMethod,r&&this.has({sourceExpr:r}),s&&this.has({parameters:s})}execute(e){var r;if(e.modelEntry(this.name))this.logError("source-definition-name-conflict",`Cannot redefine '${this.name}'`);else{const i=(r=this.sourceExpr)===null||r===void 0?void 0:r.getSource();if(i===void 0)return;const s=this.deduplicatedParameters(),o=i.withParameters(void 0,this.parameters);if(this.validateParameterShadowing(s,o),$nt.ErrorFactory.didCreate(o))return;const u={...o,as:this.name,location:this.location};this.note&&(u.annotation=o.annotation?{...this.note,inherits:o.annotation}:this.note),e.setEntry(this.name,{entry:u,exported:this.exported})}}deduplicatedParameters(){if(this.parameters===void 0)return[];const e={},r=[];for(const i of this.parameters)i.name in e&&i.logError("parameter-name-conflict",`Cannot redefine parameter \`${i.name}\``),e[i.name]=!0,r.push(i);return r}validateParameterShadowing(e,r){for(const i of e)r.fields.find(s=>{var o;return((o=s.as)!==null&&o!==void 0?o:s.name)===i.name})&&i.logError("parameter-shadowing-field",`Illegal shadowing of field \`${i.name}\` by parameter with the same name`)}}O2.DefineSource=knt;class Mnt extends qle.DocStatementList{constructor(e){super(e),this.elementType="defineSources"}}O2.DefineSourceList=Mnt;var F2={};Object.defineProperty(F2,"__esModule",{value:!0}),F2.DefineQueryList=F2.DefineQuery=void 0;const Hle=Ze,Pnt=Qr;class Unt extends Hle.MalloyElement{constructor(e,r){super({queryExpr:r}),this.name=e,this.queryExpr=r,this.elementType="defineQuery",this.isNoteableObj=!0,this.extendNote=Pnt.extendNoteMethod}execute(e){if(e.getEntry(this.name)){this.logError("query-definition-name-conflict",`'${this.name}' is already defined, cannot redefine`);return}const i=this.queryExpr.getQuery();if(!i){this.queryExpr.sqLog("query-definition-from-non-query","Cannot define a query from this expression");return}const s={...i.query(),type:"query",name:this.name,location:this.location};this.note&&(s.annotation=s.annotation?{...this.note,inherits:s.annotation}:this.note),e.setEntry(this.name,{entry:s,exported:!0})}}F2.DefineQuery=Unt;class jnt extends Hle.DocStatementList{constructor(e){super(e),this.elementType="defineQueries"}}F2.DefineQueryList=jnt;var Ro={};Object.defineProperty(Ro,"__esModule",{value:!0}),Ro.Source=void 0;const qnt=Ze;class Hnt extends qnt.MalloyElement{structRef(e){return{structRef:this.getSourceDef(e)}}packParameters(e){if(e===void 0)return;const r={};for(const i of e){const s=i.parameter();r[s.name]=s}return r}withParameters(e,r){return{...this.getSourceDef(e),parameters:this.packParameters(r)}}}Ro.Source=Hnt;var aE={},w2={},Q4={},Vc={};Object.defineProperty(Vc,"__esModule",{value:!0}),Vc.mergeFields=Vc.nameFromDef=void 0;function $B(t){var e;return t.type==="fieldref"?t.path[t.path.length-1]:(e=t.as)!==null&&e!==void 0?e:t.name}Vc.nameFromDef=$B;function Qnt(t,e){if(t===void 0)return e;const r=new Set(e.map(s=>$B(s))),i=t.filter(s=>!r.has($B(s)));return i.push(...e),i}Vc.mergeFields=Qnt;var lE={},Wr={},ja={},znt=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),Wnt=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),Gnt=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&znt(e,t,r);return Wnt(e,t),e};Object.defineProperty(ja,"__esModule",{value:!0}),ja.DefinedParameter=ja.AbstractParameter=ja.SpaceParam=void 0;const Vnt=Gc,Qle=Gnt(nn),zle=dt;class BB extends Vnt.SpaceEntry{constructor(){super(...arguments),this.refType="parameter"}}ja.SpaceParam=BB;class Ynt extends BB{constructor(e){super(),this.astParam=e,this._parameter=void 0}parameter(){return this._parameter!==void 0?this._parameter:(this._parameter=this.astParam.parameter(),this._parameter)}typeDesc(){const e=this.parameter(),r=e.type;return{...r==="filter expression"?{type:r}:Qle.atomicDef(e),expressionType:"scalar",evalSpace:"constant",compositeFieldUsage:(0,zle.emptyCompositeFieldUsage)()}}}ja.AbstractParameter=Ynt;class Knt extends BB{constructor(e){super(),this.paramDef=e}parameter(){return this.paramDef}typeDesc(){const e=this.parameter(),r=e.type;return{...r==="filter expression"?{type:r}:Qle.atomicDef(e),expressionType:"scalar",evalSpace:"input",compositeFieldUsage:(0,zle.emptyCompositeFieldUsage)()}}}ja.DefinedParameter=Knt;var Cd={},Jnt=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),Xnt=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),Znt=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&Jnt(e,t,r);return Xnt(e,t),e};Object.defineProperty(Cd,"__esModule",{value:!0}),Cd.StructSpaceFieldBase=void 0;const Wle=dt,ert=et,trt=Znt(nn),nrt=zr;class rrt extends nrt.SpaceField{constructor(e){super(),this.structDef=e}fieldDef(){return this.structDef}get joinPathElement(){return{name:this.structDef.as||this.structDef.name,joinType:this.structDef.join,joinElementType:this.structDef.type}}typeDesc(){var e,r;return(0,ert.isSourceDef)(this.structDef)?{type:this.structDef.type,evalSpace:"input",expressionType:"scalar",compositeFieldUsage:(e=this.structDef.onCompositeFieldUsage)!==null&&e!==void 0?e:(0,Wle.emptyCompositeFieldUsage)()}:{...trt.atomicDef(this.structDef),evalSpace:"input",expressionType:"scalar",compositeFieldUsage:(r=this.structDef.onCompositeFieldUsage)!==null&&r!==void 0?r:(0,Wle.emptyCompositeFieldUsage)()}}}Cd.StructSpaceFieldBase=rrt;var cE={};Object.defineProperty(cE,"__esModule",{value:!0}),cE.ColumnSpaceField=void 0;const irt=zr;class srt extends irt.SpaceField{constructor(e){super(),this.sourceFieldDef=e}fieldDef(){return this.sourceFieldDef}typeDesc(){return this.fieldTypeFromFieldDef(this.sourceFieldDef)}constructorFieldDef(){return this.sourceFieldDef}}cE.ColumnSpaceField=srt;var z4={};Object.defineProperty(z4,"__esModule",{value:!0}),z4.IRViewField=void 0;const ort=D2;class urt extends ort.ViewField{constructor(e,r){super(e),this.turtleDef=r}rename(e){this.turtleDef={...this.turtleDef,as:e}}fieldDef(){return this.turtleDef}constructorFieldDef(){return this.turtleDef}getQueryFieldDef(e){return this.fieldDef()}}z4.IRViewField=urt,Object.defineProperty(Wr,"__esModule",{value:!0}),Wr.StaticSourceSpace=Wr.StructSpaceField=Wr.StaticSpace=void 0;const art=ka,N2=et,lrt=ja,crt=zr,fE=Cd,frt=cE,xrt=z4;class kB{constructor(e,r){this.type="fieldSpace",this.fromStruct=e,this.structDialect=r}dialectName(){return this.structDialect}dialectObj(){try{return(0,art.getDialect)(this.structDialect)}catch{return}}defToSpaceField(e){return(0,N2.isJoined)(e)?new MB(e,this.structDialect):(0,N2.isTurtle)(e)?new xrt.IRViewField(this,e):new frt.ColumnSpaceField(e)}get map(){if(this.memoMap===void 0){this.memoMap={};for(const e of this.fromStruct.fields){const r=e.as||e.name;this.memoMap[r]=this.defToSpaceField(e)}if((0,N2.isSourceDef)(this.fromStruct)&&this.fromStruct.parameters)for(const[e,r]of Object.entries(this.fromStruct.parameters))e in this.memoMap||(this.memoMap[e]=new lrt.DefinedParameter(r))}return this.memoMap}isProtectedAccessSpace(){return!1}dropEntries(){this.memoMap={}}dropEntry(e){delete this.map[e]}entry(e){return this.map[e]}setEntry(e,r){this.map[e]=r}entries(){return Object.entries(this.map)}structDef(){return this.fromStruct}emptyStructDef(){const e={...this.fromStruct};return(0,N2.isSourceDef)(e)&&(e.parameters={}),e.fields=[],e}lookup(e){const r=e[0],i=e.slice(1);let s=this.entry(r.refString);if(!s)return{error:{message:`'${r}' is not defined`,code:"field-not-found"},found:s};if(s instanceof crt.SpaceField){const u=s.fieldDef();if(u&&(!(s instanceof fE.StructSpaceFieldBase)&&(0,N2.isJoined)(u)&&(s=new MB(u,this.structDialect)),r.addReference({type:s instanceof fE.StructSpaceFieldBase?"joinReference":"fieldReference",definition:u,location:r.location,text:r.refString})),u!=null&&u.accessModifier&&!(this.isProtectedAccessSpace()&&u.accessModifier==="internal"&&e.length===1))return{error:{message:`'${r}' is ${u==null?void 0:u.accessModifier}`,code:"field-not-accessible"},found:void 0}}const o=s instanceof fE.StructSpaceFieldBase?[{...s.joinPathElement,name:r.refString}]:[];if(i.length){if(s instanceof fE.StructSpaceFieldBase){const u=s.fieldSpace.lookup(i);return u.found?{...u,joinPath:[...o,...u.joinPath]}:u}return{error:{message:`'${r}' cannot contain a '${i[0]}'`,code:"invalid-property-access-in-field-reference"},found:void 0}}return{found:s,error:void 0,joinPath:o,isOutputField:!1}}isQueryFieldSpace(){return!1}}Wr.StaticSpace=kB;class MB extends fE.StructSpaceFieldBase{constructor(e,r){super(e),this.forDialect=r}get fieldSpace(){return(0,N2.isSourceDef)(this.structDef)?new Gle(this.structDef):new kB(this.structDef,this.forDialect)}}Wr.StructSpaceField=MB;class Gle extends kB{constructor(e){super(e,e.dialect),this.source=e}structDef(){return this.source}emptyStructDef(){const e={...this.source};return e.parameters={},e.fields=[],e}}Wr.StaticSourceSpace=Gle,Object.defineProperty(lE,"__esModule",{value:!0}),lE.JoinSpaceField=void 0;const drt=Wr;class hrt extends drt.StructSpaceField{constructor(e,r,i){super(r.getStructDef(e),i),this.parameterSpace=e,this.join=r}}lE.JoinSpaceField=hrt;var L2={};Object.defineProperty(L2,"__esModule",{value:!0}),L2.ParameterSpace=void 0;const prt=ja;class mrt{constructor(e){this.type="fieldSpace",this._map={};for(const r of e)this._map[r.name]=new prt.AbstractParameter(r)}structDef(){throw new Error("Parameter space does not have a structDef")}emptyStructDef(){throw new Error("Parameter space does not have an emptyStructDef")}entry(e){return this._map[e]}lookup(e){const r=e[0];if(r===void 0)return{error:{message:"Invalid reference",code:"invalid-parameter-reference"},found:void 0};const i=this.entry(r.refString);return i===void 0?{error:{message:`\`${r}\` is not defined`,code:"parameter-not-found"},found:void 0}:e.length>1?{error:{message:`\`${r}\` cannot contain a \`${e.slice(1).join(".")}\``,code:"invalid-parameter-reference"},found:void 0}:{found:i,error:void 0,joinPath:[],isOutputField:!1}}entries(){return Object.entries(this._map)}dialectName(){return"~parameter-space-unknown-dialect~"}dialectObj(){}isQueryFieldSpace(){return!1}isProtectedAccessSpace(){return!1}}L2.ParameterSpace=mrt;var grt=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),yrt=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),Ert=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&grt(e,t,r);return yrt(e,t),e};Object.defineProperty(Q4,"__esModule",{value:!0}),Q4.DynamicSpace=void 0;const Art=Ert(et),_rt=Vc,vrt=gi,Crt=zr,Srt=lE,brt=D2,Vle=ja,Trt=Wr,Rrt=Cd,Drt=L2;class Ort extends Trt.StaticSpace{constructor(e){super(structuredClone(e),e.dialect),this.complete=!1,this.parameters=[],this.newAccessModifiers=new Map,this.newNotes=new Map,this.fromSource=e,this.sourceDef=void 0}setEntry(e,r){if(this.complete)throw new Error("Space already final");super.setEntry(e,r)}addParameters(e){for(const r of e)this.entry(r.name)===void 0&&(this.parameters.push(r),this.setEntry(r.name,new Vle.AbstractParameter(r)));return this}parameterSpace(){return new Drt.ParameterSpace(this.parameters)}newEntry(e,r,i){if(this.entry(e)){r.logError("definition-name-conflict",`Cannot redefine '${e}'`);return}this.setEntry(e,i)}renameEntry(e,r,i){this.dropEntry(e),this.setEntry(r,i)}addFieldDef(e){this.setEntry((0,_rt.nameFromDef)(e),this.defToSpaceField(e))}setTimezone(e){this.newTimezone=e}structDef(){if(this.complete=!0,this.sourceDef===void 0){const e={};for(const[l,c]of this.entries())c instanceof Vle.SpaceParam&&(e[l]=c.parameter());this.sourceDef={...this.fromSource,fields:[]},this.sourceDef.parameters=e;const r=new Map,i=[],s=[],o=[];for(const[l,c]of this.entries())c instanceof Rrt.StructSpaceFieldBase?s.push([l,c]):c instanceof brt.ViewField?o.push([l,c]):c instanceof Crt.SpaceField&&i.push([l,c]);const u=[...i,...s,...o],a=this.parameterSpace();for(const[l,c]of u)if(c instanceof Srt.JoinSpaceField){const f=c.join.getStructDef(a);vrt.ErrorFactory.didCreate(f)||(r.set(l,this.sourceDef.fields.length),this.sourceDef.fields.push(f),c.join.fixupJoinOn(this,f))}else{const f=c.fieldDef();f&&(r.set(l,this.sourceDef.fields.length),this.sourceDef.fields.push(f))}for(const[l,c]of this.newAccessModifiers){const f=this.sourceDef.fields.findIndex(x=>{var h;return(h=x.as)!==null&&h!==void 0?h:x.name===l});if(f===-1)throw new Error(`Can't find field '${l}' to set access modifier`);c==="public"?delete this.sourceDef.fields[f].accessModifier:this.sourceDef.fields[f]={...this.sourceDef.fields[f],accessModifier:c}}for(const[l,c]of this.newNotes){const f=this.sourceDef.fields.findIndex(h=>{var p;return(p=h.as)!==null&&p!==void 0?p:h.name===l});if(f===-1)throw new Error(`Can't find field '${l}' to set access modifier`);const x=this.sourceDef.fields[f];this.sourceDef.fields[f]={...x,annotation:{...c,inherits:x.annotation}}}}return this.newTimezone&&Art.isSourceDef(this.sourceDef)&&(this.sourceDef.queryTimezone=this.newTimezone),this.sourceDef}emptyStructDef(){const e={...this.fromSource};return e.fields=[],e}}Q4.DynamicSpace=Ort;var xE={};Object.defineProperty(xE,"__esModule",{value:!0}),xE.RenameSpaceField=void 0;const Frt=zr;class wrt extends Frt.SpaceField{constructor(e,r,i){super(),this.otherField=e,this.newName=r,this.location=i}fieldDef(){const e=this.otherField.fieldDef();if(e!==void 0)return{...e,as:this.newName,location:this.location}}typeDesc(){return this.otherField.typeDesc()}}xE.RenameSpaceField=wrt,Object.defineProperty(w2,"__esModule",{value:!0}),w2.RefinedSpace=void 0;const Nrt=Q4,Lrt=Gc,Irt=xE,$rt=zr;class PB extends Nrt.DynamicSpace{static filteredFrom(e,r,i,s,o){const u=new PB(e),a=new Map;for(const l of s??[])a.has(l.name.refString)?l.name.logError("already-renamed",`${l.name.refString} already renamed to ${l.as}`):a.set(l.name.refString,{as:l.as,location:l.location,logTo:l.name});if(i!==void 0){const l=u.entries();u.dropEntries();for(const[c,f]of l)if(i.has(c)){const x=a.get(c);x?f instanceof $rt.SpaceField?u.setEntry(x.as,new Irt.RenameSpaceField(f,x.as,x.location)):x.logTo.logError("cannot-rename-non-field",`Cannot rename \`${c}\` which is not a field`):u.setEntry(c,f)}r!==void 0&&r.logError("accept-except-not-compatible-with-include","Can't use `accept:` or `except:` with `include`")}else if(r){const l=r.refs.list,c=u.entries();for(const f of l)c.find(([h])=>h===f.refString)===void 0&&(o!=null&&o.entry(f.refString)?f.logError(`${r.edit}-parameter`,`Illegal \`${r.edit}:\` of parameter`):f.logError("field-list-edit-not-found",`\`${f.refString}\` is not defined`));u.dropEntries();for(const[f,x]of c){const h=!!l.find(m=>m.refString===f),p=r.edit==="accept";h===p&&u.setEntry(f,x)}}return u}pushFields(...e){for(const r of e)this.addField(r)}addField(e){(0,Lrt.canMakeEntry)(e)?e.makeEntry(this):e.logError("unexpected-element-type",`Internal error, ${e.elementType} not expected in this context`)}addAccessModifiers(e){for(const[r,i]of e)this.newAccessModifiers.set(r,i)}addNotes(e){for(const[r,i]of e)this.newNotes.set(r,i)}isProtectedAccessSpace(){return!0}}w2.RefinedSpace=PB;var Yc={},Qs={};Object.defineProperty(Qs,"__esModule",{value:!0}),Qs.DefinitionList=void 0;const Brt=Ze,Yle=Qr;class krt extends Brt.ListOf{constructor(){super(...arguments),this.isNoteableObj=!0}extendNote(e){(0,Yle.extendNoteHelper)(this,e),this.distributeAnnotation()}distributeAnnotation(){if(this.note)for(const e of this.elements)(0,Yle.isNoteable)(e)&&e.extendNote(this.note)}newContents(){super.newContents(),this.distributeAnnotation()}}Qs.DefinitionList=krt,Object.defineProperty(Yc,"__esModule",{value:!0}),Yc.DeclareFields=void 0;const Mrt=Qs,Prt=zn;class Urt extends Mrt.DefinitionList{constructor(e,r){super(e),this.accessModifier=r,this.elementType="declareFields",this.queryRefinementStage=Prt.LegalRefinementStage.Single,this.forceQueryClass=void 0}queryExecute(e){for(const r of this.list)e.inputFS.extendSource(r)}get delarationNames(){return this.list.map(e=>e.defineName)}}Yc.DeclareFields=Urt;var qa={};Object.defineProperty(qa,"__esModule",{value:!0}),qa.Filter=qa.FilterElement=void 0;const Kle=et,jrt=Jn,Jle=Ze,UB=zn;class qrt extends Jle.MalloyElement{constructor(e,r){super({expr:e}),this.expr=e,this.exprSrc=r,this.elementType="filterElement"}filterCondition(e){const r=this.expr.getExpression(e);return r.type!=="boolean"?(this.expr.logError("non-boolean-filter","Filter expression must have boolean value"),{node:"filterCondition",code:this.exprSrc,e:{node:"false"},expressionType:"scalar",compositeFieldUsage:r.compositeFieldUsage}):{node:"filterCondition",code:this.exprSrc,e:r.value,expressionType:r.expressionType,compositeFieldUsage:r.compositeFieldUsage}}}qa.FilterElement=qrt;class Hrt extends Jle.ListOf{constructor(){super(...arguments),this.elementType="filter",this.forceQueryClass=void 0,this.queryRefinementStage=UB.LegalRefinementStage.Head}set having(e){this.elementType=e?"having":"where",this.havingClause=e,this.queryRefinementStage=e?UB.LegalRefinementStage.Tail:UB.LegalRefinementStage.Head}checkedFilterCondition(e,r){const i=r.filterCondition(e);if(this.havingClause!==void 0){const s=(0,Kle.expressionIsAggregate)(i.expressionType),o=(0,Kle.expressionIsAnalytic)(i.expressionType);if(this.havingClause){if(o){r.logError("analytic-in-having","Analytic expressions are not allowed in `having:`");return}}else if(o){r.logError("analytic-in-where","Analytic expressions are not allowed in `where:`");return}else s&&r.logError("aggregate-in-where","Aggregate expressions are not allowed in `where:`; use `having:`")}return i}getFilterList(e){return this.list.map(r=>this.checkedFilterCondition(e,r)).filter(jrt.isNotUndefined)}queryExecute(e){const r=this.havingClause?e.resultFS:e.inputFS;for(const i of this.list){const s=this.checkedFilterCondition(r,i);s!==void 0&&(e.filters.push(s),e.resultFS.addCompositeFieldUserFromFilter(s,i))}}}qa.Filter=Hrt;var I2={};Object.defineProperty(I2,"__esModule",{value:!0}),I2.FieldListEdit=void 0;const Qrt=Ze;class zrt extends Qrt.MalloyElement{constructor(e,r){super({refs:r}),this.edit=e,this.refs=r,this.elementType="fieldListEdit"}}I2.FieldListEdit=zrt;var $2={};Object.defineProperty($2,"__esModule",{value:!0}),$2.PrimaryKey=void 0;const Wrt=Ze;class Grt extends Wrt.MalloyElement{constructor(e){super({field:e}),this.field=e,this.elementType="primary key"}}$2.PrimaryKey=Grt;var B2={};Object.defineProperty(B2,"__esModule",{value:!0}),B2.Views=void 0;const Vrt=Qs;class Yrt extends Vrt.DefinitionList{constructor(e,r){super(e),this.accessModifier=r,this.elementType="turtleDefList"}get delarationNames(){return this.list.map(e=>e.name)}}B2.Views=Yrt;var k2={};Object.defineProperty(k2,"__esModule",{value:!0}),k2.TimezoneStatement=void 0;const Krt=Ze,Jrt=qr;class Xrt extends Krt.MalloyElement{constructor(e){super(),this.tz=e,this.elementType="timezone",this.forceQueryClass=void 0,this.queryRefinementStage=void 0}get isValid(){try{return Jrt.DateTime.fromISO("2020-02-19T00:00:00",{zone:this.tz}),!0}catch{return!1}}queryExecute(e){e.resultFS.setTimezone(this.tz)}}k2.TimezoneStatement=Xrt;var Kc={};Object.defineProperty(Kc,"__esModule",{value:!0}),Kc.ModelAnnotation=Kc.ObjectAnnotation=void 0;const Zrt=Ze,eit=mi;class Xle extends Zrt.MalloyElement{constructor(e){super(),this.notes=e,this.elementType="annotation",this.forceQueryClass=void 0,this.queryRefinementStage=void 0}queryExecute(){}}Kc.ObjectAnnotation=Xle;class tit extends Xle{constructor(){super(...arguments),this.elementType="modelAnnotation"}getCompilerFlags(e,r){const i=(0,eit.annotationToTag)({notes:this.notes},{prefix:/^##! /,extending:e});return i.log.forEach(s=>r.log(s)),i.tag}execute(e){e.annotation.notes===void 0&&(e.annotation.notes=[]),e.annotation.notes.push(...this.notes)}}Kc.ModelAnnotation=tit;var Jc={};Object.defineProperty(Jc,"__esModule",{value:!0}),Jc.Renames=Jc.RenameField=void 0;const nit=xE,Zle=Ze,rit=zr;class iit extends Zle.MalloyElement{constructor(e,r){super(),this.newName=e,this.oldName=r,this.elementType="renameField",this.has({oldName:r})}makeEntry(e){if(this.oldName.refString===this.newName){this.logError("invalid-rename-with-same-name","Can't rename field to itself");return}const r=this.oldName.getField(e);r.found?r.found instanceof rit.SpaceField?e.renameEntry(this.oldName.refString,this.newName,new nit.RenameSpaceField(r.found,this.newName,this.location)):this.logError("failed-rename",`'${this.oldName}' cannot be renamed`):this.logError("rename-field-not-found",`Can't rename '${this.oldName}', no such field`)}getName(){return this.newName}}Jc.RenameField=iit;class sit extends Zle.ListOf{constructor(e,r){super(e),this.accessModifier=r,this.elementType="renameFields"}get delarationNames(){return this.list.map(e=>e.getName())}}Jc.Renames=sit;var ys={};Object.defineProperty(ys,"__esModule",{value:!0}),ys.JoinStatement=ys.ExpressionJoin=ys.KeyJoin=ys.Join=void 0;const jB=et,oit=lE,uit=Qs,ait=Ze,lit=Qr,e0e=gi,cit=zn;class qB extends ait.MalloyElement{constructor(){super(...arguments),this.isNoteableObj=!0,this.extendNote=lit.extendNoteMethod}makeEntry(e){e.newEntry(this.name.refString,this,new oit.JoinSpaceField(e.parameterSpace(),this,e.dialectName()))}getName(){return this.name.refString}getStructDefFromExpr(e){const r=this.sourceExpr.getSource();return r?r.getSourceDef(e):(this.sourceExpr.sqLog("invalid-join-source","Cannot create a source to join from"),e0e.ErrorFactory.structDef)}}ys.Join=qB;class fit extends qB{constructor(e,r,i){super({name:e,sourceExpr:r,keyExpr:i}),this.name=e,this.sourceExpr=r,this.keyExpr=i,this.elementType="joinOnKey"}getStructDef(e){var r;const i=this.getStructDefFromExpr(e);if(!(0,jB.isJoinable)(i))throw this.internalError(`Cannot join struct type '${i.type}'`);const s={...i,name:this.name.refString,join:"one",matrixOperation:"left",onExpression:{node:"error",message:"('join fixup'='not done yet')"},location:this.location};return delete s.as,this.note&&(s.annotation=this.note),(r=this.document())===null||r===void 0||r.rememberToAddModelAnnotations(s),s}fixupJoinOn(e,r){const i=this.keyExpr.getExpression(e);if((0,jB.isSourceDef)(r)&&r.primaryKey){const s=r.fields.find(o=>(o.as||o.name)===r.primaryKey);if(s)if(s.type===i.type){r.join="one",r.onExpression={node:"=",kids:{left:{node:"field",path:[this.name.refString,r.primaryKey]},right:i.value}},r.onCompositeFieldUsage=i.compositeFieldUsage;return}else this.logError("join-on-primary-key-type-mismatch",`join_one: with type mismatch with primary key: ${i.type}/${s.type}`);else this.logError("join-primary-key-not-found",`join_one: Primary key '${s}' not found in source`)}else this.logError("join-with-without-primary-key","join_one: Cannot use with unless source has a primary key")}}ys.KeyJoin=fit;class xit extends qB{constructor(e,r){super({name:e,sourceExpr:r}),this.name=e,this.sourceExpr=r,this.elementType="joinOnExpr",this.joinType="one",this.matrixOperation="left"}set joinOn(e){this.expr=e,this.has({on:e})}get joinOn(){return this.expr}fixupJoinOn(e,r){if(this.expr===void 0)return;const i=this.expr.getExpression(e);if(i.type!=="boolean"){this.logError("non-boolean-join-on","join conditions must be boolean expressions");return}r.onExpression=i.value,r.onCompositeFieldUsage=i.compositeFieldUsage}getStructDef(e){var r;const i=this.sourceExpr.getSource();if(!i)return this.sourceExpr.sqLog("invalid-join-source","Cannot create a source to join from"),e0e.ErrorFactory.joinDef;const s=i.getSourceDef(e);let o="left";if(this.inExperiment("join_types",!0)&&(o=this.matrixOperation),!(0,jB.isJoinable)(s))throw this.internalError(`Can't join struct type ${s.type}`);const u={...s,name:this.name.refString,join:this.joinType,matrixOperation:o,location:this.location};return delete u.as,this.note&&(u.annotation=this.note),(r=this.document())===null||r===void 0||r.rememberToAddModelAnnotations(u),u}}ys.ExpressionJoin=xit;class dit extends uit.DefinitionList{constructor(e,r){super(e),this.accessModifier=r,this.elementType="joinStatement",this.forceQueryClass=void 0,this.queryRefinementStage=cit.LegalRefinementStage.Single}queryExecute(e){for(const r of this.list)e.inputFS.extendSource(r),e.alwaysJoins.push(r.name.refString)}get delarationNames(){return this.list.map(e=>e.name.refString)}}ys.JoinStatement=dit;var bu={};Object.defineProperty(bu,"__esModule",{value:!0}),bu.IncludeListItem=bu.IncludeExceptItem=bu.IncludeAccessItem=bu.IncludeItem=void 0;const t0e=Ze,n0e=Qr;class HB extends t0e.MalloyElement{}bu.IncludeItem=HB;class hit extends HB{constructor(e,r){super(),this.kind=e,this.fields=r,this.elementType="include-access-item",this.isNoteableObj=!0,this.extendNote=n0e.extendNoteMethod,this.has({fields:r})}}bu.IncludeAccessItem=hit;class pit extends HB{constructor(e){super(),this.fields=e,this.elementType="include-except-item",this.kind="except",this.has({fields:e})}}bu.IncludeExceptItem=pit;class mit extends t0e.MalloyElement{constructor(e,r){super({name:e}),this.name=e,this.as=r,this.elementType="include-list-item",this.isNoteableObj=!0,this.extendNote=n0e.extendNoteMethod}}bu.IncludeListItem=mit;var _t={},dE={},git=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),yit=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),Eit=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&git(e,t,r);return yit(e,t),e};Object.defineProperty(dE,"__esModule",{value:!0}),dE.ReferenceField=void 0;const r0e=et,i0e=Eit(nn),s0e=zr,Ait=dt;class _it extends s0e.SpaceField{constructor(e,r){super(),this.fieldRef=e,this.inFS=r,this.didLookup=!1}get referenceTo(){return this.didLookup||(this.memoReference=this.inFS.lookup(this.fieldRef.list).found,this.didLookup=!0),this.memoReference}getQueryFieldDef(e){if(!this.queryFieldDef){const r=this.fieldRef.getField(e);r.error&&this.fieldRef.logError(r.error.code,r.error.message);const i=this.fieldRef.path;if(r.found&&r.found.refType==="parameter"){const o=r.found.typeDesc();if(r0e.TD.isAtomic(o))this.queryFieldDef={...(0,r0e.mkFieldDef)(i0e.atomicDef(o),i[0]),e:{node:"parameter",path:i}};else throw new Error("impossible turtle/join parameter")}else this.queryFieldDef={type:"fieldref",path:i};const s=this.referenceTo;if(s instanceof s0e.SpaceField){const o=s.constructorFieldDef();if(o){const u=this.fieldRef.note;if(o.annotation||u){const a=u||{};o.annotation&&(a.inherits=o.annotation),this.queryFieldDef.annotation=a}}}}return this.queryFieldDef}typeDesc(){if(this.memoTypeDesc)return this.memoTypeDesc;const e=this.referenceTo;if(e){const r=this.fieldRef.list.slice(0,-1).map(s=>s.refString),i=e.typeDesc();return this.memoTypeDesc={...i,compositeFieldUsage:(0,Ait.joinedCompositeFieldUsage)(r,i.compositeFieldUsage)},this.memoTypeDesc}return i0e.errorT}}dE.ReferenceField=_it;var lr={};Object.defineProperty(lr,"__esModule",{value:!0}),lr.typecheckGroupBy=lr.typecheckAggregate=lr.typecheckCalculate=lr.typecheckDeclare=lr.typecheckMeasure=lr.typecheckDimension=lr.typecheckIndex=lr.typecheckProject=void 0;const Mn=Gi;function vit(t,e){if(t.type==="turtle"||!(0,Mn.expressionIsScalar)(t.expressionType)){let r,i,s;if(t.type==="turtle")r="a nest",i="a view",s="select-of-view";else if((0,Mn.expressionIsAnalytic)(t.expressionType))r="a calculate",i="an analytic",s="select-of-analytic";else if((0,Mn.expressionIsAggregate)(t.expressionType))r="an aggregate",i="an aggregate",s="select-of-aggregate";else throw new Error(`Unexpected expression type ${t.expressionType} not handled here`);e.logError(s,`Cannot use ${i} field in a select operation, did you mean to use ${r} operation instead?`)}}lr.typecheckProject=vit;function Cit(t,e){if(t.type==="turtle"||!(0,Mn.expressionIsScalar)(t.expressionType)){let r,i;if(t.type==="turtle")r="a view",i="index-of-view";else if((0,Mn.expressionIsAnalytic)(t.expressionType))r="an analytic",i="index-of-analytic";else if((0,Mn.expressionIsAggregate)(t.expressionType))r="an aggregate",i="index-of-aggregate";else throw new Error(`Unexpected expression type ${t.expressionType} not handled here`);e.logError(i,`Cannot use ${r} field in an index operation`)}}lr.typecheckIndex=Cit;function Sit(t,e){if(!(0,Mn.expressionIsScalar)(t.expressionType))if((0,Mn.expressionIsAggregate)(t.expressionType))e.logError("aggregate-in-dimension","Cannot use an aggregate field in a dimension declaration, did you mean to use a measure declaration instead?");else if((0,Mn.expressionIsAnalytic)(t.expressionType))e.logError("analytic-in-dimension","Cannot use an analytic field in a dimension declaration");else throw new Error(`Unexpected expression type ${t.expressionType} not handled here`)}lr.typecheckDimension=Sit;function bit(t,e){if(!(0,Mn.expressionIsAggregate)(t.expressionType))if((0,Mn.expressionIsScalar)(t.expressionType))e.logError("scalar-in-measure","Cannot use a scalar field in a measure declaration, did you mean to use a dimension declaration instead?");else if((0,Mn.expressionIsAnalytic)(t.expressionType))e.logError("analytic-in-measure","Cannot use an analytic field in a measure declaration");else throw new Error(`Unexpected expression type ${t.expressionType} not handled here`)}lr.typecheckMeasure=bit;function Tit(t,e){t.type==="turtle"?e.logError("view-in-declare","Views cannot be used in a declare block"):(0,Mn.expressionIsAnalytic)(t.expressionType)&&e.logError("analytic-in-declare","Analytic expressions can not be used in a declare block")}lr.typecheckDeclare=Tit;function Rit(t,e){if(t.type==="turtle"||!(0,Mn.expressionIsAnalytic)(t.expressionType)){let r,i,s;if(t.type==="turtle")r="a nest",i="a view",s="calculate-of-view";else if((0,Mn.expressionIsAggregate)(t.expressionType))r="an aggregate",i="an aggregate",s="calculate-of-aggregate";else if((0,Mn.expressionIsScalar)(t.expressionType))r="a group_by or select",i="a scalar",s="calculate-of-scalar";else throw new Error(`Unexpected expression type ${t.expressionType} not handled here`);e.logError(s,`Cannot use ${i} field in a calculate operation, did you mean to use ${r} operation instead?`)}}lr.typecheckCalculate=Rit;function Dit(t,e){if(t.type==="turtle"||!(0,Mn.expressionIsAggregate)(t.expressionType)){let r,i,s;if(t.type==="turtle")r="a nest",i="a view",s="aggregate-of-view";else if((0,Mn.expressionIsAnalytic)(t.expressionType))r="a calculate",i="an analytic",s="aggregate-of-analytic";else if((0,Mn.expressionIsScalar)(t.expressionType))r="a group_by or select",i="a scalar",s="aggregate-of-scalar";else throw new Error(`Unexpected expression type ${t} not handled here`);e.logError(s,`Cannot use ${i} field in an aggregate operation, did you mean to use ${r} operation instead?`)}}lr.typecheckAggregate=Dit;function Oit(t,e){if(t.type==="turtle"||!(0,Mn.expressionIsScalar)(t.expressionType)){let r,i,s;if(t.type==="turtle")r="a nest",i="a view",s="group-by-view";else if((0,Mn.expressionIsAnalytic)(t.expressionType))r="a calculate",i="an analytic",s="group-by-analytic";else if((0,Mn.expressionIsAggregate)(t.expressionType))r="an aggregate",i="an aggregate",s="group-by-aggregate";else throw new Error(`Unexpected expression type ${t.expressionType} not handled here`);e.logError(s,`Cannot use ${i} field in a group_by operation, did you mean to use ${r} operation instead?`)}}lr.typecheckGroupBy=Oit,Object.defineProperty(_t,"__esModule",{value:!0}),_t.FieldReferences=_t.WildcardFieldReference=_t.ViewOrScalarFieldReference=_t.DimensionFieldReference=_t.MeasureFieldReference=_t.DeclareFieldReference=_t.ProjectFieldReference=_t.GroupByFieldReference=_t.AggregateFieldReference=_t.IndexFieldReference=_t.CalculateFieldReference=_t.ParameterFieldReference=_t.PartitionByFieldReference=_t.ExpressionFieldReference=_t.AccessModifierFieldReference=_t.AcceptExceptFieldReference=_t.FieldReference=void 0;const Fit=dE,wit=Qs,o0e=Ze,u0e=Qr,Xc=lr;class Yi extends o0e.ListOf{constructor(e){super(e),this.isNoteableObj=!0,this.extendNote=u0e.extendNoteMethod}makeEntry(e){const r=this.outputName;if(e.entry(r))this.logError("output-name-conflict",`Output already has a field named '${r}'`);else{const i=e.isQueryFieldSpace()?e.inputSpace():e;e.newEntry(r,this,new Fit.ReferenceField(this,i))}}getName(){return this.nameString}get refToField(){return{type:"fieldref",path:this.list.map(e=>e.refString)}}get refString(){return this.path.join(".")}get path(){return this.list.map(e=>e.refString)}get outputName(){return this.list[this.list.length-1].refString}get sourceString(){if(this.list.length>1)return this.list.slice(0,-1).map(e=>e.refString).join(".")}get nameString(){return this.list[this.list.length-1].refString}getField(e){const r=e.lookup(this.list);if(r.found){const i=r.found.typeDesc();this.typecheck(i)}return r}}_t.FieldReference=Yi;class Nit extends Yi{constructor(){super(...arguments),this.elementType="acceptExceptFieldReference"}typecheck(){}}_t.AcceptExceptFieldReference=Nit;class Lit extends Yi{constructor(){super(...arguments),this.elementType="accessModifierFieldReference"}typecheck(){}}_t.AccessModifierFieldReference=Lit;class Iit extends Yi{constructor(){super(...arguments),this.elementType="expressionFieldReference"}typecheck(){}}_t.ExpressionFieldReference=Iit;class $it extends Yi{constructor(){super(...arguments),this.elementType="partitionByFieldReference"}typecheck(){}}_t.PartitionByFieldReference=$it;class Bit extends Yi{constructor(){super(...arguments),this.elementType="parameterFieldReference"}typecheck(){}}_t.ParameterFieldReference=Bit;class kit extends Yi{constructor(){super(...arguments),this.elementType="calculateFieldReference"}typecheck(e){(0,Xc.typecheckCalculate)(e,this)}}_t.CalculateFieldReference=kit;class QB extends Yi{constructor(){super(...arguments),this.elementType="indexFieldReference"}typecheck(e){(0,Xc.typecheckIndex)(e,this)}static indexOutputName(e){return e.map(r=>encodeURIComponent(r)).join("/")}get outputName(){return QB.indexOutputName(this.path)}}_t.IndexFieldReference=QB;class Mit extends Yi{constructor(){super(...arguments),this.elementType="aggregateFieldReference"}typecheck(e){(0,Xc.typecheckAggregate)(e,this)}}_t.AggregateFieldReference=Mit;class Pit extends Yi{constructor(){super(...arguments),this.elementType="groupByFieldReference"}typecheck(e){(0,Xc.typecheckGroupBy)(e,this)}}_t.GroupByFieldReference=Pit;class Uit extends Yi{constructor(){super(...arguments),this.elementType="projectFieldReference"}typecheck(e){(0,Xc.typecheckProject)(e,this)}}_t.ProjectFieldReference=Uit;class jit extends Yi{constructor(){super(...arguments),this.elementType="declareFieldReference"}typecheck(e){(0,Xc.typecheckDeclare)(e,this)}}_t.DeclareFieldReference=jit;class qit extends Yi{constructor(){super(...arguments),this.elementType="measureFieldReference"}typecheck(e){(0,Xc.typecheckMeasure)(e,this)}}_t.MeasureFieldReference=qit;class Hit extends Yi{constructor(){super(...arguments),this.elementType="dimensionFieldReference"}typecheck(e){(0,Xc.typecheckDimension)(e,this)}}_t.DimensionFieldReference=Hit;class Qit extends Yi{constructor(){super(...arguments),this.elementType="viewOrScalarFieldReference"}typecheck(e){}}_t.ViewOrScalarFieldReference=Qit;class zit extends o0e.MalloyElement{constructor(e){super(),this.joinPath=e,this.elementType="wildcardFieldReference",this.isNoteableObj=!0,this.extendNote=u0e.extendNoteMethod,this.except=new Set,this.has({joinPath:e})}getFieldDef(){throw this.internalError("fielddef request from wildcard reference")}get refString(){return this.joinPath?`${this.joinPath.refString}.*`:"*"}}_t.WildcardFieldReference=zit;class Wit extends wit.DefinitionList{constructor(e){super(e),this.elementType="fieldReferenceList"}}_t.FieldReferences=Wit,Object.defineProperty(aE,"__esModule",{value:!0}),aE.RefinedSource=void 0;const Git=et,Vit=w2,Yit=Yc,Kit=qa,Jit=I2,Xit=$2,Zit=B2,est=Ro,tst=k2,nst=Kc,rst=Jc,ist=L2,sst=ys,a0e=bu,zB=_t;class ost extends est.Source{constructor(e,r,i){super({source:e,refinement:r}),this.source=e,this.refinement=r,this.includeList=i,this.elementType="refinedSource",i&&this.has({includeList:i})}getSourceDef(e){return this.withParameters(e,[])}withParameters(e,r){var i;let s,o;const u=[],a=[];let l;const c=[];for(const v of this.refinement.list){if(v instanceof nst.ObjectAnnotation)continue;const C=v;if(v instanceof Xit.PrimaryKey){if(s){const S="multiple-primary-keys";s.logError(S,"Primary key already defined"),v.logError(S,"Primary key redefined")}s=v}else if(v instanceof Jit.FieldListEdit){if(o){const S="multiple-field-list-edits";o.logError(S,"Too many accept/except statements"),v.logError(S,"Too many accept/except statements")}o=v}else v instanceof Yit.DeclareFields||v instanceof sst.JoinStatement||v instanceof Zit.Views||v instanceof rst.Renames?(u.push(...v.list),v.accessModifier&&c.push({fields:v.delarationNames,access:v.accessModifier})):v instanceof Kit.Filter?a.push(v):v instanceof tst.TimezoneStatement?l=v.tz:C.logError("unexpected-source-property",`Unexpected source property: '${C.elementType}'`)}const f=r?new ist.ParameterSpace(r):void 0,x=structuredClone(this.source.getSourceDef(f)),{fieldsToInclude:h,modifiers:p,renames:m,notes:g}=ust(this.includeList,x);for(const v of c)for(const C of v.fields)p.set(C,v.access);s&&(x.primaryKey=s.field.name);const y=Vit.RefinedSpace.filteredFrom(x,o,h,m,f);if(l&&y.setTimezone(l),r&&y.addParameters(r),y.pushFields(...u),s){const v=s.field.getField(y);v.error&&s.logError(v.error.code,v.error.message)}y.addAccessModifiers(p),y.addNotes(g);const E=y.structDef(),A=E.filterList||[];let _=!1;for(const v of a)for(const C of v.list){const S=C.filterCondition(y);(0,Git.expressionIsCalculation)(S.expressionType)?C.logError("aggregate-in-source-filter","Can't use aggregate computations in top level filters"):(A.push(S),_=!0)}return _?{...E,filterList:A}:((i=this.document())===null||i===void 0||i.rememberToAddModelAnnotations(E),E)}}aE.RefinedSource=ost;function ust(t,e){var r,i,s,o,u,a,l,c,f;const x=new Set(e.fields.map(S=>S.name)),h=new Set(e.fields.filter(S=>S.accessModifier==="private").map(S=>S.name));let p;const m=new Set;let g,y;const E=new Map,A=[],_=new Map;if(t===void 0)return{fieldsToInclude:void 0,modifiers:E,renames:A,notes:_};for(const S of t)if(S instanceof a0e.IncludeAccessItem)for(const b of S.fields)if(b.name instanceof zB.WildcardFieldReference)b.name.joinPath&&b.logError("unsupported-path-in-include","Wildcards with paths are not supported in `include` blocks"),g!==void 0?S.logError("already-used-star-in-include","Wildcard already used in this include block"):(g=(r=S.kind)!==null&&r!==void 0?r:"inherit",y={notes:(s=(i=b.note)===null||i===void 0?void 0:i.notes)!==null&&s!==void 0?s:[],blockNotes:(u=(o=S.note)===null||o===void 0?void 0:o.blockNotes)!==null&&u!==void 0?u:[]});else{if(p==="exclude"){S.logError("include-after-exclude","Cannot include specific fields if specific fields are already excluded");continue}p="include";const R=b.name.refString;h.has(R)&&b.logError("cannot-expand-access",`Cannot expand access of \`${R}\` from private to ${S.kind}`),E.has(R)?b.logError("duplicate-include",`Field \`${R}\` already referenced in include list`):(S.kind!==void 0&&E.set(R,S.kind),m.add(R),(b.note||S.note)&&_.set(R,{notes:(l=(a=b.note)===null||a===void 0?void 0:a.notes)!==null&&l!==void 0?l:[],blockNotes:(f=(c=S.note)===null||c===void 0?void 0:c.blockNotes)!==null&&f!==void 0?f:[]})),b.as&&(b.name instanceof zB.WildcardFieldReference?b.logError("wildcard-include-rename","Cannot rename a wildcard field in an `include` block"):A.push({name:b.name,as:b.as,location:b.location}))}else if(S instanceof a0e.IncludeExceptItem)for(const b of S.fields)b instanceof zB.WildcardFieldReference?b.joinPath?b.logError("unsupported-path-in-include","Wildcards with paths are not supported in `include` blocks"):b.logWarning("wildcard-except-redundant","`except: *` is implied, unless another clause uses *"):p==="include"?S.logError("exclude-after-include","Cannot exclude specific fields if specific fields are already included"):(p="exclude",g="inherit",m.add(b.refString));const v=new Set(x);m.forEach(S=>v.delete(S)),h.forEach(S=>v.delete(S));let C;if(g!==void 0)for(const S of v)g!=="inherit"&&E.set(S,g),y&&_.set(S,{...y});return p!=="exclude"?g!==void 0?C=x:C=m:C=v,{fieldsToInclude:C,modifiers:E,renames:A,notes:_}}var Tu={};Object.defineProperty(Tu,"__esModule",{value:!0}),Tu.SourceQueryElement=void 0;const ast=Ze;class WB extends ast.MalloyElement{constructor(){super(...arguments),this.errored=!1}getSource(){}getQuery(){}isSource(){return!1}sqLog(e,r,i){return this.isErrorFree()&&this.logError(e,r,i),this.errored=!0,e}isErrorFree(){if(this.errored)return!1;let e=!0;for(const r of this.walk())if(r instanceof WB&&r.errored){e=!1;break}return e}}Tu.SourceQueryElement=WB;var W4={},Sd={};Object.defineProperty(Sd,"__esModule",{value:!0}),Sd.QuerySource=void 0;const lst=Ro,cst=m2;class fst extends lst.Source{constructor(e){super({query:e}),this.query=e,this.elementType="querySource"}getSourceDef(e){return this.withParameters(e,void 0)}withParameters(e,r){var i;const s=this.query.queryComp(!1),o={...s.outputStruct,name:`QuerySource-${(0,cst.v4)()}`,type:"query_source",query:s.query};return(i=this.document())===null||i===void 0||i.rememberToAddModelAnnotations(o),{...o,parameters:this.packParameters(r)}}}Sd.QuerySource=fst;var M2={},hE={};Object.defineProperty(hE,"__esModule",{value:!0}),hE.QueryBase=void 0;const GB=dt,l0e=et,xst=b2,dst=Ze;class hst extends dst.MalloyElement{resolveCompositeSource(e,r){var i;const s=r.pipeline[0];if(s&&((0,l0e.isQuerySegment)(s)||(0,l0e.isIndexSegment)(s))){const o=(i=s.compositeFieldUsage)!==null&&i!==void 0?i:(0,GB.emptyCompositeFieldUsage)();if(!(0,GB.isEmptyCompositeFieldUsage)(o)||e.type==="composite")return(0,GB.resolveCompositeSources)(e,o).sourceDef}}query(){const{query:e}=this.queryComp(!0);return{...e,pipeline:(0,xst.detectAndRemovePartialStages)(e.pipeline,this)}}}hE.QueryBase=hst,Object.defineProperty(M2,"__esModule",{value:!0}),M2.QueryArrow=void 0;const pst=et,mst=Ro,c0e=Wr,gst=hE;class yst extends gst.QueryBase{constructor(e,r){super({source:e,view:r}),this.source=e,this.view=r,this.elementType="arrow"}queryComp(e){var r;let i,s,o;if(this.source instanceof mst.Source){const h=e?this.source.structRef(void 0):{structRef:this.source.getSourceDef(void 0)};s={type:"query",...h,pipeline:[],location:this.location},i=(0,pst.refIsStructDef)(h.structRef)?h.structRef:this.source.getSourceDef(void 0),o=new c0e.StaticSourceSpace(i)}else{const h=this.source.queryComp(e);s=h.query,i=h.outputStruct,o=new c0e.StaticSourceSpace(h.outputStruct)}const{pipeline:u,annotation:a,outputStruct:l,name:c}=this.view.pipelineComp(o),f={...s,name:c,annotation:a,pipeline:[...s.pipeline,...u]},x=(r=f.compositeResolvedSourceDef)!==null&&r!==void 0?r:this.resolveCompositeSource(i,f);return{query:{...f,compositeResolvedSourceDef:x},outputStruct:l,inputStruct:i}}}M2.QueryArrow=yst,Object.defineProperty(W4,"__esModule",{value:!0}),W4.SQArrow=void 0;const Est=Tu,Ast=Sd,_st=M2;class vst extends Est.SourceQueryElement{constructor(e,r){super({applyTo:e,operation:r}),this.applyTo=e,this.operation=r,this.elementType="sq-arrow"}getQuery(){const e=this.applyTo.isSource()?this.applyTo.getSource():this.applyTo.getQuery();if(e===void 0){this.sqLog("failed-to-compute-arrow-source","Could not get LHS of arrow operation");return}const r=new _st.QueryArrow(e,this.operation);return this.has({query:r}),r}getSource(){const e=this.getQuery();if(!e){this.sqLog("failed-to-compute-source-from-query","Couldn't comprehend query well enough to make a source");return}const r=new Ast.QuerySource(e);return this.has({asSource:r}),r}}W4.SQArrow=vst;var G4={},P2={},zs={};Object.defineProperty(zs,"__esModule",{value:!0}),zs.getStructFieldDef=zs.getFinalStruct=zs.opOutputStruct=void 0;const f0e=D0,Cst=js,V4=et,x0e=gi;function d0e(t,e,r){const i=x0e.ErrorFactory.didCreate(e)||(0,V4.structHasErrors)(e);(0,V4.isPartialSegment)(r)&&(r={...r,type:"reduce"});const s=(0,V4.segmentHasErrors)(r);if(!i&&!s)try{const o=Cst.Segment.nextStructDef(e,r);if((0,V4.isSourceDef)(o))return o;t.logError("failed-to-compute-output-schema",`INTERNAL ERROR model/Segment.nextStructDef: RETURNED A NON SOURCE
|
|
1552
|
+
${i} `),s+="]")}return s}*walk(){for(const e of Object.keys(this.children)){const r=this.children[e];if(r instanceof Ua)yield r;else for(const i of r)yield i}}varInfo(){let e="";for(const[r,i]of Object.entries(this))r!=="elementType"&&(typeof i=="boolean"?e+=i?` ${r}`:` !${r}`:(typeof i=="string"||typeof i=="number")&&(e+=` ${r}=${i}`));return e}internalError(e){return new Error(`INTERNAL ERROR IN TRANSLATION: ${e}`)}needs(e){for(const r of this.walk()){const i=r.needs(e);if(i)return i}}inExperiment(e,r=!1){var i;const s=(i=this.translator())===null||i===void 0?void 0:i.compilerFlags.tag("experimental");return s&&(s.bare()||s.has(e))?!0:(r||this.logError("experiment-not-enabled",{experimentId:e}),!1)}}Ze.MalloyElement=Ua;class ont extends Ua{constructor(){super(...arguments),this.elementType="unimplemented",this.reported=!1}}Ze.Unimplemented=ont;class NB extends Ua{constructor(e){super(),this.name=e,this.elementType="modelEntryReference"}get refString(){return this.name}toString(){return this.refString}getNamed(){var e;return(e=this.modelEntry(this))===null||e===void 0?void 0:e.entry}}Ze.ModelEntryReference=NB;class unt extends Ua{constructor(e){super(),this.id=e,this.elementType="experimentalExperiment"}execute(e){this.inExperiment(this.id)}}Ze.ExperimentalExperiment=unt;function $le(t){return t.execute!==void 0}Ze.isDocStatement=$le;function ant(t){return t instanceof uE||$le(t)}Ze.isDocStatementOrDocStatementList=ant;class Ble extends Ua{constructor(e){super(),this.elements=e,this.newContents()}newContents(){this.has({listOf:this.elements})}get list(){return this.elements}empty(){return this.elements.length===0}notEmpty(){return this.elements.length>0}push(...e){return this.elements.push(...e),this.newContents(),this.elements}needs(e){for(const r of this.elements){const i=r.needs(e);if(i)return i}}}Ze.ListOf=Ble;class uE extends Ble{constructor(){super(...arguments),this.elementType="topLevelStatements",this.execCursor=0,this.isNoteableObj=!0,this.extendNote=Ile.extendNoteMethod,this.noteCursor=0}executeList(e){for(;this.execCursor<this.elements.length;){const r=this.elements[this.execCursor];if(this.noteCursor===this.execCursor&&(this.note&&(0,Ile.isNoteable)(r)&&r.extendNote(this.note),this.noteCursor+=1),r instanceof uE){const i=r.executeList(e);if(i)return i}else{const i=r.needs(e);if(i)return i;r.execute(e)}this.execCursor+=1}}}Ze.DocStatementList=uE;const lnt="5a79a191-06bc-43cf-9b12-58741cd82970";function kle(t){const e=t.inherits?kle(t.inherits):[];return t.blockNotes&&e.push(...t.blockNotes.map(r=>r.text)),t.notes&&e.push(...t.notes.map(r=>r.text)),e}function cnt(t){const e=kle(t).join("");return(0,snt.v5)(e,lnt)}class LB extends Ua{constructor(e){super(),this.elementType="document",this.globalNameSpace=new int.GlobalNameSpace,this.documentModel={},this.queryList=[],this.didInitModel=!1,this.annotation={},this.experiments=new ent.Tag({}),this.modelAnnotationTodoList=[],this.dialectNameSpaces=new Map,this.statements=new uE(e),this.has({statements:e})}initModelDef(e){if(!this.didInitModel){if(this.documentModel={},this.queryList=[],e){e.annotation&&(this.annotation.inherits=e.annotation);for(const[r,i]of Object.entries(e.contents)){const s=structuredClone(i);if((0,q4.isSourceDef)(s)||s.type==="query"||s.type==="function"){const o=e.exports.includes(r);this.setEntry(r,{entry:s,exported:o})}}}this.didInitModel=!0}}compile(){const e=this.statements.executeList(this),r=this.modelDef();if(e===void 0)for(const s of this.queryList)s.modelAnnotation===void 0&&r.annotation&&(s.modelAnnotation=r.annotation);if(r.annotation)for(const s of this.modelAnnotationTodoList)s.modelAnnotation||(s.modelAnnotation=r.annotation);return{modelDef:{...r,queryList:this.queryList},needs:e}}rememberToAddModelAnnotations(e){this.modelAnnotationTodoList.push(e)}hasAnnotation(){return this.annotation.notes&&this.annotation.notes.length>0||this.annotation.inherits!==void 0}currentModelAnnotation(){if(this.hasAnnotation()){const e={...this.annotation,id:""};return e.id=cnt(e),e}}modelDef(){const e={name:"",exports:[],contents:{},queryList:[],dependencies:{}};this.hasAnnotation()&&(e.annotation=this.currentModelAnnotation());for(const r in this.documentModel){const i=this.documentModel[r].entry;if((0,q4.isSourceDef)(i)||i.type==="query"){this.documentModel[r].exported&&e.exports.push(r);const s=structuredClone(i);s.modelAnnotation===void 0&&e.annotation&&(s.modelAnnotation=e.annotation),e.contents[r]=s}}return e}getEntry(e){var r;return(r=this.globalNameSpace.getEntry(e))!==null&&r!==void 0?r:this.documentModel[e]}setEntry(e,r){this.globalNameSpace.getEntry(e)!==void 0&&this.logError("name-conflict-with-global",`Cannot redefine '${e}', which is in global namespace`),(0,q4.isSourceDef)(r.entry)&&this.checkExperimentalDialect(this,r.entry.dialect),this.documentModel[e]=r}checkExperimentalDialect(e,r){const i=this.translator();i&&i.firstReferenceToDialect(r)&&(0,Lle.getDialect)(r).experimental&&!i.experimentalDialectEnabled(r)&&e.logError("experimental-dialect-not-enabled",{dialect:r})}getDialectNamespace(e){if(this.dialectNameSpaces.has(e))return this.dialectNameSpaces.get(e);const r=(0,Lle.getDialect)(e),i=new rnt.DialectNameSpace(r);return this.dialectNameSpaces.set(e,i),i}}Ze.Document=LB;var H4={},D2={},nn={};(function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.atomicDef=t.inspect=t.typeEq=t.typeIn=t.eq=t.any=t.anyAtomicT=t.aggregateBoolT=t.viewT=t.errorT=t.boolT=t.timestampT=t.dateT=t.stringT=t.numberT=t.nullT=void 0;const e=Gi,r=dt;function i(f,x="scalar",h="constant"){return{type:f,expressionType:x,evalSpace:h,compositeFieldUsage:(0,r.emptyCompositeFieldUsage)()}}t.nullT=i("null"),t.numberT=i("number"),t.stringT=i("string"),t.dateT=i("date"),t.timestampT=i("timestamp"),t.boolT=i("boolean"),t.errorT=i("error"),t.viewT=i("turtle"),t.aggregateBoolT=i("boolean","aggregate"),t.anyAtomicT=[t.numberT,t.stringT,t.dateT,t.timestampT,t.boolT];function s(f,x){return f?x.find(p=>o(p,f))!==void 0:!1}t.any=s;function o(f,x){return x!==void 0&&e.TD.eq(f,x)&&f.expressionType===x.expressionType}t.eq=o;function u(f,x){return f?x.find(p=>a(p,f))!==void 0:!1}t.typeIn=u;function a(f,x,h=!1,p=!0){const m=e.TD.eq(f,x),g=h&&(f.type==="null"||x.type==="null"),y=p&&(f.type==="error"||x.type==="error");return m||g||y}t.typeEq=a;function l(...f){return f.map(h=>{if(h){let p=h.type;return(0,e.expressionIsScalar)(h.expressionType)||(p=`${h.expressionType} ${p}`),p}return"undefined"}).join(",")}t.inspect=l;function c(f){if(e.TD.isAtomic(f))switch(f.type){case"array":return(0,e.isRepeatedRecord)(f)?{type:"array",elementTypeDef:f.elementTypeDef,fields:f.fields}:{type:"array",elementTypeDef:f.elementTypeDef};case"record":return{type:"record",fields:f.fields};case"number":return f.numberType?{type:"number",numberType:f.numberType}:{type:"number"};case"sql native":return f.rawType?{type:"sql native",rawType:f.rawType}:{type:"sql native"};default:return{type:f.type}}return{type:"error"}}t.atomicDef=c})(nn);var zr={},Gc={};Object.defineProperty(Gc,"__esModule",{value:!0}),Gc.canMakeEntry=Gc.SpaceEntry=void 0;class fnt{}Gc.SpaceEntry=fnt;function xnt(t){return"makeEntry"in t}Gc.canMakeEntry=xnt,Object.defineProperty(zr,"__esModule",{value:!0}),zr.SpaceField=void 0;const dnt=Gc,hnt=dt;class pnt extends dnt.SpaceEntry{constructor(){super(...arguments),this.refType="field"}fieldTypeFromFieldDef(e){var r,i,s;const o=e.expressionType||"scalar";return{...e,expressionType:o,evalSpace:"input",compositeFieldUsage:(r=e.compositeFieldUsage)!==null&&r!==void 0?r:((i=e.e)===null||i===void 0?void 0:i.node)==="compositeField"?{fields:[(s=e.as)!==null&&s!==void 0?s:e.name],joinedUsage:{}}:(0,hnt.emptyCompositeFieldUsage)()}}getQueryFieldDef(e){}fieldDef(){}constructorFieldDef(){}}zr.SpaceField=pnt;var mnt=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),gnt=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),ynt=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&mnt(e,t,r);return gnt(e,t),e};Object.defineProperty(D2,"__esModule",{value:!0}),D2.ViewField=void 0;const Ent=dt,Ant=ynt(nn),_nt=zr;class vnt extends _nt.SpaceField{constructor(e){super(),this.inSpace=e}typeDesc(){var e;const r=this.fieldDef();return{...Ant.viewT,compositeFieldUsage:(e=r.compositeFieldUsage)!==null&&e!==void 0?e:(0,Ent.emptyCompositeFieldUsage)()}}}D2.ViewField=vnt,Object.defineProperty(H4,"__esModule",{value:!0}),H4.ASTViewField=void 0;const Cnt=D2;class Snt extends Cnt.ViewField{constructor(e,r,i){super(e),this.view=r,this.name=i,this.turtleDef=void 0}getQueryFieldDef(e){return this.view.getFieldDef(e)}fieldDef(){return this.turtleDef===void 0&&(this.turtleDef=this.view.getFieldDef(this.inSpace)),this.turtleDef}}H4.ASTViewField=Snt,Object.defineProperty(oE,"__esModule",{value:!0}),oE.ViewFieldDeclaration=void 0;const bnt=Ze,Tnt=Qr,Rnt=b2,Dnt=H4;class Ont extends bnt.MalloyElement{constructor(e,r){super({view:r}),this.name=e,this.view=r,this.elementType="view-field-declaration",this.isNoteableObj=!0,this.extendNote=Tnt.extendNoteMethod}makeEntry(e){const r=new Dnt.ASTViewField(e,this,this.name);e.newEntry(this.name,this,r)}getName(){return this.name}getFieldDef(e){const{pipeline:r,annotation:i}=this.view.pipelineComp(e),s=(0,Rnt.detectAndRemovePartialStages)(r,this);return{type:"turtle",name:this.name,pipeline:s,annotation:{...this.note,inherits:i},location:this.location}}}oE.ViewFieldDeclaration=Ont;var zn={};Object.defineProperty(zn,"__esModule",{value:!0}),zn.LegalRefinementStage=zn.QueryClass=void 0;var Mle;(function(t){t.Index="index",t.Project="project",t.Grouping="grouping"})(Mle||(zn.QueryClass=Mle={}));var Ple;(function(t){t[t.Single=0]="Single",t[t.Head=1]="Head",t[t.Tail=2]="Tail"})(Ple||(zn.LegalRefinementStage=Ple={}));var Fnt=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),wnt=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),Nnt=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&Fnt(e,t,r);return wnt(e,t),e};Object.defineProperty(sE,"__esModule",{value:!0}),sE.NestFieldDeclaration=void 0;const Lnt=Nnt(et),Int=b2,$nt=oE,Ule=zn;class Bnt extends $nt.ViewFieldDeclaration{constructor(){super(...arguments),this.elementType="nest-field-declaration",this.queryRefinementStage=Ule.LegalRefinementStage.Single,this.forceQueryClass=Ule.QueryClass.Grouping,this.turtleDef=void 0}queryExecute(e){e.resultFS.pushFields(this)}getFieldDef(e){if(this.turtleDef)return this.turtleDef;if(e.isQueryFieldSpace()){const{pipeline:r,annotation:i}=this.view.pipelineComp(e,e.outputSpace()),s=r[0]&&Lnt.isQuerySegment(r[0])?r[0].compositeFieldUsage:void 0,o=(0,Int.detectAndRemovePartialStages)(r,this);return this.turtleDef={type:"turtle",name:this.name,pipeline:o,annotation:{...this.note,inherits:i},location:this.location,compositeFieldUsage:s},this.turtleDef}throw this.internalError("Unexpected namespace for nest")}}sE.NestFieldDeclaration=Bnt;var O2={},gi={};Object.defineProperty(gi,"__esModule",{value:!0}),gi.ErrorFactory=void 0;const jle="~malformed~";class IB{static get structDef(){return{type:"table",name:jle,dialect:"~malformed~",connection:"~unknown~",tablePath:"//undefined_error_table_path",fields:[],errorFactory:!0}}static get joinDef(){return{type:"table",name:jle,dialect:"~malformed~",connection:"~unknown~",tablePath:"//undefined_error_table_path",fields:[],join:"one",matrixOperation:"left",errorFactory:!0}}static didCreate(e){return e.type==="table"&&"errorFactory"in e}static get query(){return{structRef:IB.structDef,pipeline:[]}}static get reduceSegment(){return{type:"reduce",queryFields:[]}}static get projectSegment(){return{type:"project",queryFields:[]}}static get indexSegment(){return{type:"index",indexFields:[]}}}gi.ErrorFactory=IB,Object.defineProperty(O2,"__esModule",{value:!0}),O2.DefineSourceList=O2.DefineSource=void 0;const knt=gi,qle=Ze,Mnt=Qr;class Pnt extends qle.MalloyElement{constructor(e,r,i,s){super(),this.name=e,this.sourceExpr=r,this.exported=i,this.parameters=s,this.elementType="defineSource",this.isNoteableObj=!0,this.extendNote=Mnt.extendNoteMethod,r&&this.has({sourceExpr:r}),s&&this.has({parameters:s})}execute(e){var r;if(e.modelEntry(this.name))this.logError("source-definition-name-conflict",`Cannot redefine '${this.name}'`);else{const i=(r=this.sourceExpr)===null||r===void 0?void 0:r.getSource();if(i===void 0)return;const s=this.deduplicatedParameters(),o=i.withParameters(void 0,this.parameters);if(this.validateParameterShadowing(s,o),knt.ErrorFactory.didCreate(o))return;const u={...o,as:this.name,location:this.location};this.note&&(u.annotation=o.annotation?{...this.note,inherits:o.annotation}:this.note),e.setEntry(this.name,{entry:u,exported:this.exported})}}deduplicatedParameters(){if(this.parameters===void 0)return[];const e={},r=[];for(const i of this.parameters)i.name in e&&i.logError("parameter-name-conflict",`Cannot redefine parameter \`${i.name}\``),e[i.name]=!0,r.push(i);return r}validateParameterShadowing(e,r){for(const i of e)r.fields.find(s=>{var o;return((o=s.as)!==null&&o!==void 0?o:s.name)===i.name})&&i.logError("parameter-shadowing-field",`Illegal shadowing of field \`${i.name}\` by parameter with the same name`)}}O2.DefineSource=Pnt;class Unt extends qle.DocStatementList{constructor(e){super(e),this.elementType="defineSources"}}O2.DefineSourceList=Unt;var F2={};Object.defineProperty(F2,"__esModule",{value:!0}),F2.DefineQueryList=F2.DefineQuery=void 0;const Hle=Ze,jnt=Qr;class qnt extends Hle.MalloyElement{constructor(e,r){super({queryExpr:r}),this.name=e,this.queryExpr=r,this.elementType="defineQuery",this.isNoteableObj=!0,this.extendNote=jnt.extendNoteMethod}execute(e){if(e.getEntry(this.name)){this.logError("query-definition-name-conflict",`'${this.name}' is already defined, cannot redefine`);return}const i=this.queryExpr.getQuery();if(!i){this.queryExpr.sqLog("query-definition-from-non-query","Cannot define a query from this expression");return}const s={...i.query(),type:"query",name:this.name,location:this.location};this.note&&(s.annotation=s.annotation?{...this.note,inherits:s.annotation}:this.note),e.setEntry(this.name,{entry:s,exported:!0})}}F2.DefineQuery=qnt;class Hnt extends Hle.DocStatementList{constructor(e){super(e),this.elementType="defineQueries"}}F2.DefineQueryList=Hnt;var Ro={};Object.defineProperty(Ro,"__esModule",{value:!0}),Ro.Source=void 0;const Qnt=Ze;class znt extends Qnt.MalloyElement{structRef(e){return{structRef:this.getSourceDef(e)}}packParameters(e){if(e===void 0)return;const r={};for(const i of e){const s=i.parameter();r[s.name]=s}return r}withParameters(e,r){return{...this.getSourceDef(e),parameters:this.packParameters(r)}}}Ro.Source=znt;var aE={},w2={},Q4={},Vc={};Object.defineProperty(Vc,"__esModule",{value:!0}),Vc.mergeFields=Vc.nameFromDef=void 0;function $B(t){var e;return t.type==="fieldref"?t.path[t.path.length-1]:(e=t.as)!==null&&e!==void 0?e:t.name}Vc.nameFromDef=$B;function Wnt(t,e){if(t===void 0)return e;const r=new Set(e.map(s=>$B(s))),i=t.filter(s=>!r.has($B(s)));return i.push(...e),i}Vc.mergeFields=Wnt;var lE={},Wr={},ja={},Gnt=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),Vnt=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),Ynt=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&Gnt(e,t,r);return Vnt(e,t),e};Object.defineProperty(ja,"__esModule",{value:!0}),ja.DefinedParameter=ja.AbstractParameter=ja.SpaceParam=void 0;const Knt=Gc,Qle=Ynt(nn),zle=dt;class BB extends Knt.SpaceEntry{constructor(){super(...arguments),this.refType="parameter"}}ja.SpaceParam=BB;class Jnt extends BB{constructor(e){super(),this.astParam=e,this._parameter=void 0}parameter(){return this._parameter!==void 0?this._parameter:(this._parameter=this.astParam.parameter(),this._parameter)}typeDesc(){const e=this.parameter(),r=e.type;return{...r==="filter expression"?{type:r}:Qle.atomicDef(e),expressionType:"scalar",evalSpace:"constant",compositeFieldUsage:(0,zle.emptyCompositeFieldUsage)()}}}ja.AbstractParameter=Jnt;class Xnt extends BB{constructor(e){super(),this.paramDef=e}parameter(){return this.paramDef}typeDesc(){const e=this.parameter(),r=e.type;return{...r==="filter expression"?{type:r}:Qle.atomicDef(e),expressionType:"scalar",evalSpace:"input",compositeFieldUsage:(0,zle.emptyCompositeFieldUsage)()}}}ja.DefinedParameter=Xnt;var Cd={},Znt=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),ert=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),trt=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&Znt(e,t,r);return ert(e,t),e};Object.defineProperty(Cd,"__esModule",{value:!0}),Cd.StructSpaceFieldBase=void 0;const Wle=dt,nrt=et,rrt=trt(nn),irt=zr;class srt extends irt.SpaceField{constructor(e){super(),this.structDef=e}fieldDef(){return this.structDef}get joinPathElement(){return{name:this.structDef.as||this.structDef.name,joinType:this.structDef.join,joinElementType:this.structDef.type}}typeDesc(){var e,r;return(0,nrt.isSourceDef)(this.structDef)?{type:this.structDef.type,evalSpace:"input",expressionType:"scalar",compositeFieldUsage:(e=this.structDef.onCompositeFieldUsage)!==null&&e!==void 0?e:(0,Wle.emptyCompositeFieldUsage)()}:{...rrt.atomicDef(this.structDef),evalSpace:"input",expressionType:"scalar",compositeFieldUsage:(r=this.structDef.onCompositeFieldUsage)!==null&&r!==void 0?r:(0,Wle.emptyCompositeFieldUsage)()}}}Cd.StructSpaceFieldBase=srt;var cE={};Object.defineProperty(cE,"__esModule",{value:!0}),cE.ColumnSpaceField=void 0;const ort=zr;class urt extends ort.SpaceField{constructor(e){super(),this.sourceFieldDef=e}fieldDef(){return this.sourceFieldDef}typeDesc(){return this.fieldTypeFromFieldDef(this.sourceFieldDef)}constructorFieldDef(){return this.sourceFieldDef}}cE.ColumnSpaceField=urt;var z4={};Object.defineProperty(z4,"__esModule",{value:!0}),z4.IRViewField=void 0;const art=D2;class lrt extends art.ViewField{constructor(e,r){super(e),this.turtleDef=r}rename(e){this.turtleDef={...this.turtleDef,as:e}}fieldDef(){return this.turtleDef}constructorFieldDef(){return this.turtleDef}getQueryFieldDef(e){return this.fieldDef()}}z4.IRViewField=lrt,Object.defineProperty(Wr,"__esModule",{value:!0}),Wr.StaticSourceSpace=Wr.StructSpaceField=Wr.StaticSpace=void 0;const crt=ka,N2=et,frt=ja,xrt=zr,fE=Cd,drt=cE,hrt=z4;class kB{constructor(e,r){this.type="fieldSpace",this.fromStruct=e,this.structDialect=r}dialectName(){return this.structDialect}dialectObj(){try{return(0,crt.getDialect)(this.structDialect)}catch{return}}defToSpaceField(e){return(0,N2.isJoined)(e)?new MB(e,this.structDialect):(0,N2.isTurtle)(e)?new hrt.IRViewField(this,e):new drt.ColumnSpaceField(e)}get map(){if(this.memoMap===void 0){this.memoMap={};for(const e of this.fromStruct.fields){const r=e.as||e.name;this.memoMap[r]=this.defToSpaceField(e)}if((0,N2.isSourceDef)(this.fromStruct)&&this.fromStruct.parameters)for(const[e,r]of Object.entries(this.fromStruct.parameters))e in this.memoMap||(this.memoMap[e]=new frt.DefinedParameter(r))}return this.memoMap}isProtectedAccessSpace(){return!1}dropEntries(){this.memoMap={}}dropEntry(e){delete this.map[e]}entry(e){return this.map[e]}setEntry(e,r){this.map[e]=r}entries(){return Object.entries(this.map)}structDef(){return this.fromStruct}emptyStructDef(){const e={...this.fromStruct};return(0,N2.isSourceDef)(e)&&(e.parameters={}),e.fields=[],e}lookup(e){const r=e[0],i=e.slice(1);let s=this.entry(r.refString);if(!s)return{error:{message:`'${r}' is not defined`,code:"field-not-found"},found:s};if(s instanceof xrt.SpaceField){const u=s.fieldDef();if(u&&(!(s instanceof fE.StructSpaceFieldBase)&&(0,N2.isJoined)(u)&&(s=new MB(u,this.structDialect)),r.addReference({type:s instanceof fE.StructSpaceFieldBase?"joinReference":"fieldReference",definition:u,location:r.location,text:r.refString})),u!=null&&u.accessModifier&&!(this.isProtectedAccessSpace()&&u.accessModifier==="internal"&&e.length===1))return{error:{message:`'${r}' is ${u==null?void 0:u.accessModifier}`,code:"field-not-accessible"},found:void 0}}const o=s instanceof fE.StructSpaceFieldBase?[{...s.joinPathElement,name:r.refString}]:[];if(i.length){if(s instanceof fE.StructSpaceFieldBase){const u=s.fieldSpace.lookup(i);return u.found?{...u,joinPath:[...o,...u.joinPath]}:u}return{error:{message:`'${r}' cannot contain a '${i[0]}'`,code:"invalid-property-access-in-field-reference"},found:void 0}}return{found:s,error:void 0,joinPath:o,isOutputField:!1}}isQueryFieldSpace(){return!1}}Wr.StaticSpace=kB;class MB extends fE.StructSpaceFieldBase{constructor(e,r){super(e),this.forDialect=r}get fieldSpace(){return(0,N2.isSourceDef)(this.structDef)?new Gle(this.structDef):new kB(this.structDef,this.forDialect)}}Wr.StructSpaceField=MB;class Gle extends kB{constructor(e){super(e,e.dialect),this.source=e}structDef(){return this.source}emptyStructDef(){const e={...this.source};return e.parameters={},e.fields=[],e}}Wr.StaticSourceSpace=Gle,Object.defineProperty(lE,"__esModule",{value:!0}),lE.JoinSpaceField=void 0;const prt=Wr;class mrt extends prt.StructSpaceField{constructor(e,r,i){super(r.getStructDef(e),i),this.parameterSpace=e,this.join=r}}lE.JoinSpaceField=mrt;var L2={};Object.defineProperty(L2,"__esModule",{value:!0}),L2.ParameterSpace=void 0;const grt=ja;class yrt{constructor(e){this.type="fieldSpace",this._map={};for(const r of e)this._map[r.name]=new grt.AbstractParameter(r)}structDef(){throw new Error("Parameter space does not have a structDef")}emptyStructDef(){throw new Error("Parameter space does not have an emptyStructDef")}entry(e){return this._map[e]}lookup(e){const r=e[0];if(r===void 0)return{error:{message:"Invalid reference",code:"invalid-parameter-reference"},found:void 0};const i=this.entry(r.refString);return i===void 0?{error:{message:`\`${r}\` is not defined`,code:"parameter-not-found"},found:void 0}:e.length>1?{error:{message:`\`${r}\` cannot contain a \`${e.slice(1).join(".")}\``,code:"invalid-parameter-reference"},found:void 0}:{found:i,error:void 0,joinPath:[],isOutputField:!1}}entries(){return Object.entries(this._map)}dialectName(){return"~parameter-space-unknown-dialect~"}dialectObj(){}isQueryFieldSpace(){return!1}isProtectedAccessSpace(){return!1}}L2.ParameterSpace=yrt;var Ert=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),Art=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),_rt=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&Ert(e,t,r);return Art(e,t),e};Object.defineProperty(Q4,"__esModule",{value:!0}),Q4.DynamicSpace=void 0;const vrt=_rt(et),Crt=Vc,Srt=gi,brt=zr,Trt=lE,Rrt=D2,Vle=ja,Drt=Wr,Ort=Cd,Frt=L2;class wrt extends Drt.StaticSpace{constructor(e){super(structuredClone(e),e.dialect),this.complete=!1,this.parameters=[],this.newAccessModifiers=new Map,this.newNotes=new Map,this.fromSource=e,this.sourceDef=void 0}setEntry(e,r){if(this.complete)throw new Error("Space already final");super.setEntry(e,r)}addParameters(e){for(const r of e)this.entry(r.name)===void 0&&(this.parameters.push(r),this.setEntry(r.name,new Vle.AbstractParameter(r)));return this}parameterSpace(){return new Frt.ParameterSpace(this.parameters)}newEntry(e,r,i){if(this.entry(e)){r.logError("definition-name-conflict",`Cannot redefine '${e}'`);return}this.setEntry(e,i)}renameEntry(e,r,i){this.dropEntry(e),this.setEntry(r,i)}addFieldDef(e){this.setEntry((0,Crt.nameFromDef)(e),this.defToSpaceField(e))}setTimezone(e){this.newTimezone=e}structDef(){if(this.complete=!0,this.sourceDef===void 0){const e={};for(const[l,c]of this.entries())c instanceof Vle.SpaceParam&&(e[l]=c.parameter());this.sourceDef={...this.fromSource,fields:[]},this.sourceDef.parameters=e;const r=new Map,i=[],s=[],o=[];for(const[l,c]of this.entries())c instanceof Ort.StructSpaceFieldBase?s.push([l,c]):c instanceof Rrt.ViewField?o.push([l,c]):c instanceof brt.SpaceField&&i.push([l,c]);const u=[...i,...s,...o],a=this.parameterSpace();for(const[l,c]of u)if(c instanceof Trt.JoinSpaceField){const f=c.join.getStructDef(a);Srt.ErrorFactory.didCreate(f)||(r.set(l,this.sourceDef.fields.length),this.sourceDef.fields.push(f),c.join.fixupJoinOn(this,f))}else{const f=c.fieldDef();f&&(r.set(l,this.sourceDef.fields.length),this.sourceDef.fields.push(f))}for(const[l,c]of this.newAccessModifiers){const f=this.sourceDef.fields.findIndex(x=>{var h;return(h=x.as)!==null&&h!==void 0?h:x.name===l});if(f===-1)throw new Error(`Can't find field '${l}' to set access modifier`);c==="public"?delete this.sourceDef.fields[f].accessModifier:this.sourceDef.fields[f]={...this.sourceDef.fields[f],accessModifier:c}}for(const[l,c]of this.newNotes){const f=this.sourceDef.fields.findIndex(h=>{var p;return(p=h.as)!==null&&p!==void 0?p:h.name===l});if(f===-1)throw new Error(`Can't find field '${l}' to set access modifier`);const x=this.sourceDef.fields[f];this.sourceDef.fields[f]={...x,annotation:{...c,inherits:x.annotation}}}}return this.newTimezone&&vrt.isSourceDef(this.sourceDef)&&(this.sourceDef.queryTimezone=this.newTimezone),this.sourceDef}emptyStructDef(){const e={...this.fromSource};return e.fields=[],e}}Q4.DynamicSpace=wrt;var xE={};Object.defineProperty(xE,"__esModule",{value:!0}),xE.RenameSpaceField=void 0;const Nrt=zr;class Lrt extends Nrt.SpaceField{constructor(e,r,i){super(),this.otherField=e,this.newName=r,this.location=i}fieldDef(){const e=this.otherField.fieldDef();if(e!==void 0)return{...e,as:this.newName,location:this.location}}typeDesc(){return this.otherField.typeDesc()}}xE.RenameSpaceField=Lrt,Object.defineProperty(w2,"__esModule",{value:!0}),w2.RefinedSpace=void 0;const Irt=Q4,$rt=Gc,Brt=xE,krt=zr;class PB extends Irt.DynamicSpace{static filteredFrom(e,r,i,s,o){const u=new PB(e),a=new Map;for(const l of s??[])a.has(l.name.refString)?l.name.logError("already-renamed",`${l.name.refString} already renamed to ${l.as}`):a.set(l.name.refString,{as:l.as,location:l.location,logTo:l.name});if(i!==void 0){const l=u.entries();u.dropEntries();for(const[c,f]of l)if(i.has(c)){const x=a.get(c);x?f instanceof krt.SpaceField?u.setEntry(x.as,new Brt.RenameSpaceField(f,x.as,x.location)):x.logTo.logError("cannot-rename-non-field",`Cannot rename \`${c}\` which is not a field`):u.setEntry(c,f)}r!==void 0&&r.logError("accept-except-not-compatible-with-include","Can't use `accept:` or `except:` with `include`")}else if(r){const l=r.refs.list,c=u.entries();for(const f of l)c.find(([h])=>h===f.refString)===void 0&&(o!=null&&o.entry(f.refString)?f.logError(`${r.edit}-parameter`,`Illegal \`${r.edit}:\` of parameter`):f.logError("field-list-edit-not-found",`\`${f.refString}\` is not defined`));u.dropEntries();for(const[f,x]of c){const h=!!l.find(m=>m.refString===f),p=r.edit==="accept";h===p&&u.setEntry(f,x)}}return u}pushFields(...e){for(const r of e)this.addField(r)}addField(e){(0,$rt.canMakeEntry)(e)?e.makeEntry(this):e.logError("unexpected-element-type",`Internal error, ${e.elementType} not expected in this context`)}addAccessModifiers(e){for(const[r,i]of e)this.newAccessModifiers.set(r,i)}addNotes(e){for(const[r,i]of e)this.newNotes.set(r,i)}isProtectedAccessSpace(){return!0}}w2.RefinedSpace=PB;var Yc={},Qs={};Object.defineProperty(Qs,"__esModule",{value:!0}),Qs.DefinitionList=void 0;const Mrt=Ze,Yle=Qr;class Prt extends Mrt.ListOf{constructor(){super(...arguments),this.isNoteableObj=!0}extendNote(e){(0,Yle.extendNoteHelper)(this,e),this.distributeAnnotation()}distributeAnnotation(){if(this.note)for(const e of this.elements)(0,Yle.isNoteable)(e)&&e.extendNote(this.note)}newContents(){super.newContents(),this.distributeAnnotation()}}Qs.DefinitionList=Prt,Object.defineProperty(Yc,"__esModule",{value:!0}),Yc.DeclareFields=void 0;const Urt=Qs,jrt=zn;class qrt extends Urt.DefinitionList{constructor(e,r){super(e),this.accessModifier=r,this.elementType="declareFields",this.queryRefinementStage=jrt.LegalRefinementStage.Single,this.forceQueryClass=void 0}queryExecute(e){for(const r of this.list)e.inputFS.extendSource(r)}get delarationNames(){return this.list.map(e=>e.defineName)}}Yc.DeclareFields=qrt;var qa={};Object.defineProperty(qa,"__esModule",{value:!0}),qa.Filter=qa.FilterElement=void 0;const Kle=et,Hrt=Jn,Jle=Ze,UB=zn;class Qrt extends Jle.MalloyElement{constructor(e,r){super({expr:e}),this.expr=e,this.exprSrc=r,this.elementType="filterElement"}filterCondition(e){const r=this.expr.getExpression(e);return r.type!=="boolean"?(this.expr.logError("non-boolean-filter","Filter expression must have boolean value"),{node:"filterCondition",code:this.exprSrc,e:{node:"false"},expressionType:"scalar",compositeFieldUsage:r.compositeFieldUsage}):{node:"filterCondition",code:this.exprSrc,e:r.value,expressionType:r.expressionType,compositeFieldUsage:r.compositeFieldUsage}}}qa.FilterElement=Qrt;class zrt extends Jle.ListOf{constructor(){super(...arguments),this.elementType="filter",this.forceQueryClass=void 0,this.queryRefinementStage=UB.LegalRefinementStage.Head}set having(e){this.elementType=e?"having":"where",this.havingClause=e,this.queryRefinementStage=e?UB.LegalRefinementStage.Tail:UB.LegalRefinementStage.Head}checkedFilterCondition(e,r){const i=r.filterCondition(e);if(this.havingClause!==void 0){const s=(0,Kle.expressionIsAggregate)(i.expressionType),o=(0,Kle.expressionIsAnalytic)(i.expressionType);if(this.havingClause){if(o){r.logError("analytic-in-having","Analytic expressions are not allowed in `having:`");return}}else if(o){r.logError("analytic-in-where","Analytic expressions are not allowed in `where:`");return}else s&&r.logError("aggregate-in-where","Aggregate expressions are not allowed in `where:`; use `having:`")}return i}getFilterList(e){return this.list.map(r=>this.checkedFilterCondition(e,r)).filter(Hrt.isNotUndefined)}queryExecute(e){const r=this.havingClause?e.resultFS:e.inputFS;for(const i of this.list){const s=this.checkedFilterCondition(r,i);s!==void 0&&(e.filters.push(s),e.resultFS.addCompositeFieldUserFromFilter(s,i))}}}qa.Filter=zrt;var I2={};Object.defineProperty(I2,"__esModule",{value:!0}),I2.FieldListEdit=void 0;const Wrt=Ze;class Grt extends Wrt.MalloyElement{constructor(e,r){super({refs:r}),this.edit=e,this.refs=r,this.elementType="fieldListEdit"}}I2.FieldListEdit=Grt;var $2={};Object.defineProperty($2,"__esModule",{value:!0}),$2.PrimaryKey=void 0;const Vrt=Ze;class Yrt extends Vrt.MalloyElement{constructor(e){super({field:e}),this.field=e,this.elementType="primary key"}}$2.PrimaryKey=Yrt;var B2={};Object.defineProperty(B2,"__esModule",{value:!0}),B2.Views=void 0;const Krt=Qs;class Jrt extends Krt.DefinitionList{constructor(e,r){super(e),this.accessModifier=r,this.elementType="turtleDefList"}get delarationNames(){return this.list.map(e=>e.name)}}B2.Views=Jrt;var k2={};Object.defineProperty(k2,"__esModule",{value:!0}),k2.TimezoneStatement=void 0;const Xrt=Ze,Zrt=qr;class eit extends Xrt.MalloyElement{constructor(e){super(),this.tz=e,this.elementType="timezone",this.forceQueryClass=void 0,this.queryRefinementStage=void 0}get isValid(){try{return Zrt.DateTime.fromISO("2020-02-19T00:00:00",{zone:this.tz}),!0}catch{return!1}}queryExecute(e){e.resultFS.setTimezone(this.tz)}}k2.TimezoneStatement=eit;var Kc={};Object.defineProperty(Kc,"__esModule",{value:!0}),Kc.ModelAnnotation=Kc.ObjectAnnotation=void 0;const tit=Ze,nit=mi;class Xle extends tit.MalloyElement{constructor(e){super(),this.notes=e,this.elementType="annotation",this.forceQueryClass=void 0,this.queryRefinementStage=void 0}queryExecute(){}}Kc.ObjectAnnotation=Xle;class rit extends Xle{constructor(){super(...arguments),this.elementType="modelAnnotation"}getCompilerFlags(e,r){const i=(0,nit.annotationToTag)({notes:this.notes},{prefix:/^##! /,extending:e});return i.log.forEach(s=>r.log(s)),i.tag}execute(e){e.annotation.notes===void 0&&(e.annotation.notes=[]),e.annotation.notes.push(...this.notes)}}Kc.ModelAnnotation=rit;var Jc={};Object.defineProperty(Jc,"__esModule",{value:!0}),Jc.Renames=Jc.RenameField=void 0;const iit=xE,Zle=Ze,sit=zr;class oit extends Zle.MalloyElement{constructor(e,r){super(),this.newName=e,this.oldName=r,this.elementType="renameField",this.has({oldName:r})}makeEntry(e){if(this.oldName.refString===this.newName){this.logError("invalid-rename-with-same-name","Can't rename field to itself");return}const r=this.oldName.getField(e);r.found?r.found instanceof sit.SpaceField?e.renameEntry(this.oldName.refString,this.newName,new iit.RenameSpaceField(r.found,this.newName,this.location)):this.logError("failed-rename",`'${this.oldName}' cannot be renamed`):this.logError("rename-field-not-found",`Can't rename '${this.oldName}', no such field`)}getName(){return this.newName}}Jc.RenameField=oit;class uit extends Zle.ListOf{constructor(e,r){super(e),this.accessModifier=r,this.elementType="renameFields"}get delarationNames(){return this.list.map(e=>e.getName())}}Jc.Renames=uit;var ys={};Object.defineProperty(ys,"__esModule",{value:!0}),ys.JoinStatement=ys.ExpressionJoin=ys.KeyJoin=ys.Join=void 0;const jB=et,ait=lE,lit=Qs,cit=Ze,fit=Qr,e0e=gi,xit=zn;class qB extends cit.MalloyElement{constructor(){super(...arguments),this.isNoteableObj=!0,this.extendNote=fit.extendNoteMethod}makeEntry(e){e.newEntry(this.name.refString,this,new ait.JoinSpaceField(e.parameterSpace(),this,e.dialectName()))}getName(){return this.name.refString}getStructDefFromExpr(e){const r=this.sourceExpr.getSource();return r?r.getSourceDef(e):(this.sourceExpr.sqLog("invalid-join-source","Cannot create a source to join from"),e0e.ErrorFactory.structDef)}}ys.Join=qB;class dit extends qB{constructor(e,r,i){super({name:e,sourceExpr:r,keyExpr:i}),this.name=e,this.sourceExpr=r,this.keyExpr=i,this.elementType="joinOnKey"}getStructDef(e){var r;const i=this.getStructDefFromExpr(e);if(!(0,jB.isJoinable)(i))throw this.internalError(`Cannot join struct type '${i.type}'`);const s={...i,name:this.name.refString,join:"one",matrixOperation:"left",onExpression:{node:"error",message:"('join fixup'='not done yet')"},location:this.location};return delete s.as,this.note&&(s.annotation=this.note),(r=this.document())===null||r===void 0||r.rememberToAddModelAnnotations(s),s}fixupJoinOn(e,r){const i=this.keyExpr.getExpression(e);if((0,jB.isSourceDef)(r)&&r.primaryKey){const s=r.fields.find(o=>(o.as||o.name)===r.primaryKey);if(s)if(s.type===i.type){r.join="one",r.onExpression={node:"=",kids:{left:{node:"field",path:[this.name.refString,r.primaryKey]},right:i.value}},r.onCompositeFieldUsage=i.compositeFieldUsage;return}else this.logError("join-on-primary-key-type-mismatch",`join_one: with type mismatch with primary key: ${i.type}/${s.type}`);else this.logError("join-primary-key-not-found",`join_one: Primary key '${s}' not found in source`)}else this.logError("join-with-without-primary-key","join_one: Cannot use with unless source has a primary key")}}ys.KeyJoin=dit;class hit extends qB{constructor(e,r){super({name:e,sourceExpr:r}),this.name=e,this.sourceExpr=r,this.elementType="joinOnExpr",this.joinType="one",this.matrixOperation="left"}set joinOn(e){this.expr=e,this.has({on:e})}get joinOn(){return this.expr}fixupJoinOn(e,r){if(this.expr===void 0)return;const i=this.expr.getExpression(e);if(i.type!=="boolean"){this.logError("non-boolean-join-on","join conditions must be boolean expressions");return}r.onExpression=i.value,r.onCompositeFieldUsage=i.compositeFieldUsage}getStructDef(e){var r;const i=this.sourceExpr.getSource();if(!i)return this.sourceExpr.sqLog("invalid-join-source","Cannot create a source to join from"),e0e.ErrorFactory.joinDef;const s=i.getSourceDef(e);let o="left";if(this.inExperiment("join_types",!0)&&(o=this.matrixOperation),!(0,jB.isJoinable)(s))throw this.internalError(`Can't join struct type ${s.type}`);const u={...s,name:this.name.refString,join:this.joinType,matrixOperation:o,location:this.location};return delete u.as,this.note&&(u.annotation=this.note),(r=this.document())===null||r===void 0||r.rememberToAddModelAnnotations(u),u}}ys.ExpressionJoin=hit;class pit extends lit.DefinitionList{constructor(e,r){super(e),this.accessModifier=r,this.elementType="joinStatement",this.forceQueryClass=void 0,this.queryRefinementStage=xit.LegalRefinementStage.Single}queryExecute(e){for(const r of this.list)e.inputFS.extendSource(r),e.alwaysJoins.push(r.name.refString)}get delarationNames(){return this.list.map(e=>e.name.refString)}}ys.JoinStatement=pit;var bu={};Object.defineProperty(bu,"__esModule",{value:!0}),bu.IncludeListItem=bu.IncludeExceptItem=bu.IncludeAccessItem=bu.IncludeItem=void 0;const t0e=Ze,n0e=Qr;class HB extends t0e.MalloyElement{}bu.IncludeItem=HB;class mit extends HB{constructor(e,r){super(),this.kind=e,this.fields=r,this.elementType="include-access-item",this.isNoteableObj=!0,this.extendNote=n0e.extendNoteMethod,this.has({fields:r})}}bu.IncludeAccessItem=mit;class git extends HB{constructor(e){super(),this.fields=e,this.elementType="include-except-item",this.kind="except",this.has({fields:e})}}bu.IncludeExceptItem=git;class yit extends t0e.MalloyElement{constructor(e,r){super({name:e}),this.name=e,this.as=r,this.elementType="include-list-item",this.isNoteableObj=!0,this.extendNote=n0e.extendNoteMethod}}bu.IncludeListItem=yit;var _t={},dE={},Eit=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),Ait=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),_it=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&Eit(e,t,r);return Ait(e,t),e};Object.defineProperty(dE,"__esModule",{value:!0}),dE.ReferenceField=void 0;const r0e=et,i0e=_it(nn),s0e=zr,vit=dt;class Cit extends s0e.SpaceField{constructor(e,r){super(),this.fieldRef=e,this.inFS=r,this.didLookup=!1}get referenceTo(){return this.didLookup||(this.memoReference=this.inFS.lookup(this.fieldRef.list).found,this.didLookup=!0),this.memoReference}getQueryFieldDef(e){if(!this.queryFieldDef){const r=this.fieldRef.getField(e);r.error&&this.fieldRef.logError(r.error.code,r.error.message);const i=this.fieldRef.path;if(r.found&&r.found.refType==="parameter"){const o=r.found.typeDesc();if(r0e.TD.isAtomic(o))this.queryFieldDef={...(0,r0e.mkFieldDef)(i0e.atomicDef(o),i[0]),e:{node:"parameter",path:i}};else throw new Error("impossible turtle/join parameter")}else this.queryFieldDef={type:"fieldref",path:i};const s=this.referenceTo;if(s instanceof s0e.SpaceField){const o=s.constructorFieldDef();if(o){const u=this.fieldRef.note;if(o.annotation||u){const a=u||{};o.annotation&&(a.inherits=o.annotation),this.queryFieldDef.annotation=a}}}}return this.queryFieldDef}typeDesc(){if(this.memoTypeDesc)return this.memoTypeDesc;const e=this.referenceTo;if(e){const r=this.fieldRef.list.slice(0,-1).map(s=>s.refString),i=e.typeDesc();return this.memoTypeDesc={...i,compositeFieldUsage:(0,vit.joinedCompositeFieldUsage)(r,i.compositeFieldUsage)},this.memoTypeDesc}return i0e.errorT}}dE.ReferenceField=Cit;var lr={};Object.defineProperty(lr,"__esModule",{value:!0}),lr.typecheckGroupBy=lr.typecheckAggregate=lr.typecheckCalculate=lr.typecheckDeclare=lr.typecheckMeasure=lr.typecheckDimension=lr.typecheckIndex=lr.typecheckProject=void 0;const Mn=Gi;function Sit(t,e){if(t.type==="turtle"||!(0,Mn.expressionIsScalar)(t.expressionType)){let r,i,s;if(t.type==="turtle")r="a nest",i="a view",s="select-of-view";else if((0,Mn.expressionIsAnalytic)(t.expressionType))r="a calculate",i="an analytic",s="select-of-analytic";else if((0,Mn.expressionIsAggregate)(t.expressionType))r="an aggregate",i="an aggregate",s="select-of-aggregate";else throw new Error(`Unexpected expression type ${t.expressionType} not handled here`);e.logError(s,`Cannot use ${i} field in a select operation, did you mean to use ${r} operation instead?`)}}lr.typecheckProject=Sit;function bit(t,e){if(t.type==="turtle"||!(0,Mn.expressionIsScalar)(t.expressionType)){let r,i;if(t.type==="turtle")r="a view",i="index-of-view";else if((0,Mn.expressionIsAnalytic)(t.expressionType))r="an analytic",i="index-of-analytic";else if((0,Mn.expressionIsAggregate)(t.expressionType))r="an aggregate",i="index-of-aggregate";else throw new Error(`Unexpected expression type ${t.expressionType} not handled here`);e.logError(i,`Cannot use ${r} field in an index operation`)}}lr.typecheckIndex=bit;function Tit(t,e){if(!(0,Mn.expressionIsScalar)(t.expressionType))if((0,Mn.expressionIsAggregate)(t.expressionType))e.logError("aggregate-in-dimension","Cannot use an aggregate field in a dimension declaration, did you mean to use a measure declaration instead?");else if((0,Mn.expressionIsAnalytic)(t.expressionType))e.logError("analytic-in-dimension","Cannot use an analytic field in a dimension declaration");else throw new Error(`Unexpected expression type ${t.expressionType} not handled here`)}lr.typecheckDimension=Tit;function Rit(t,e){if(!(0,Mn.expressionIsAggregate)(t.expressionType))if((0,Mn.expressionIsScalar)(t.expressionType))e.logError("scalar-in-measure","Cannot use a scalar field in a measure declaration, did you mean to use a dimension declaration instead?");else if((0,Mn.expressionIsAnalytic)(t.expressionType))e.logError("analytic-in-measure","Cannot use an analytic field in a measure declaration");else throw new Error(`Unexpected expression type ${t.expressionType} not handled here`)}lr.typecheckMeasure=Rit;function Dit(t,e){t.type==="turtle"?e.logError("view-in-declare","Views cannot be used in a declare block"):(0,Mn.expressionIsAnalytic)(t.expressionType)&&e.logError("analytic-in-declare","Analytic expressions can not be used in a declare block")}lr.typecheckDeclare=Dit;function Oit(t,e){if(t.type==="turtle"||!(0,Mn.expressionIsAnalytic)(t.expressionType)){let r,i,s;if(t.type==="turtle")r="a nest",i="a view",s="calculate-of-view";else if((0,Mn.expressionIsAggregate)(t.expressionType))r="an aggregate",i="an aggregate",s="calculate-of-aggregate";else if((0,Mn.expressionIsScalar)(t.expressionType))r="a group_by or select",i="a scalar",s="calculate-of-scalar";else throw new Error(`Unexpected expression type ${t.expressionType} not handled here`);e.logError(s,`Cannot use ${i} field in a calculate operation, did you mean to use ${r} operation instead?`)}}lr.typecheckCalculate=Oit;function Fit(t,e){if(t.type==="turtle"||!(0,Mn.expressionIsAggregate)(t.expressionType)){let r,i,s;if(t.type==="turtle")r="a nest",i="a view",s="aggregate-of-view";else if((0,Mn.expressionIsAnalytic)(t.expressionType))r="a calculate",i="an analytic",s="aggregate-of-analytic";else if((0,Mn.expressionIsScalar)(t.expressionType))r="a group_by or select",i="a scalar",s="aggregate-of-scalar";else throw new Error(`Unexpected expression type ${t} not handled here`);e.logError(s,`Cannot use ${i} field in an aggregate operation, did you mean to use ${r} operation instead?`)}}lr.typecheckAggregate=Fit;function wit(t,e){if(t.type==="turtle"||!(0,Mn.expressionIsScalar)(t.expressionType)){let r,i,s;if(t.type==="turtle")r="a nest",i="a view",s="group-by-view";else if((0,Mn.expressionIsAnalytic)(t.expressionType))r="a calculate",i="an analytic",s="group-by-analytic";else if((0,Mn.expressionIsAggregate)(t.expressionType))r="an aggregate",i="an aggregate",s="group-by-aggregate";else throw new Error(`Unexpected expression type ${t.expressionType} not handled here`);e.logError(s,`Cannot use ${i} field in a group_by operation, did you mean to use ${r} operation instead?`)}}lr.typecheckGroupBy=wit,Object.defineProperty(_t,"__esModule",{value:!0}),_t.FieldReferences=_t.WildcardFieldReference=_t.ViewOrScalarFieldReference=_t.DimensionFieldReference=_t.MeasureFieldReference=_t.DeclareFieldReference=_t.ProjectFieldReference=_t.GroupByFieldReference=_t.AggregateFieldReference=_t.IndexFieldReference=_t.CalculateFieldReference=_t.ParameterFieldReference=_t.PartitionByFieldReference=_t.ExpressionFieldReference=_t.AccessModifierFieldReference=_t.AcceptExceptFieldReference=_t.FieldReference=void 0;const Nit=dE,Lit=Qs,o0e=Ze,u0e=Qr,Xc=lr;class Yi extends o0e.ListOf{constructor(e){super(e),this.isNoteableObj=!0,this.extendNote=u0e.extendNoteMethod}makeEntry(e){const r=this.outputName;if(e.entry(r))this.logError("output-name-conflict",`Output already has a field named '${r}'`);else{const i=e.isQueryFieldSpace()?e.inputSpace():e;e.newEntry(r,this,new Nit.ReferenceField(this,i))}}getName(){return this.nameString}get refToField(){return{type:"fieldref",path:this.list.map(e=>e.refString)}}get refString(){return this.path.join(".")}get path(){return this.list.map(e=>e.refString)}get outputName(){return this.list[this.list.length-1].refString}get sourceString(){if(this.list.length>1)return this.list.slice(0,-1).map(e=>e.refString).join(".")}get nameString(){return this.list[this.list.length-1].refString}getField(e){const r=e.lookup(this.list);if(r.found){const i=r.found.typeDesc();this.typecheck(i)}return r}}_t.FieldReference=Yi;class Iit extends Yi{constructor(){super(...arguments),this.elementType="acceptExceptFieldReference"}typecheck(){}}_t.AcceptExceptFieldReference=Iit;class $it extends Yi{constructor(){super(...arguments),this.elementType="accessModifierFieldReference"}typecheck(){}}_t.AccessModifierFieldReference=$it;class Bit extends Yi{constructor(){super(...arguments),this.elementType="expressionFieldReference"}typecheck(){}}_t.ExpressionFieldReference=Bit;class kit extends Yi{constructor(){super(...arguments),this.elementType="partitionByFieldReference"}typecheck(){}}_t.PartitionByFieldReference=kit;class Mit extends Yi{constructor(){super(...arguments),this.elementType="parameterFieldReference"}typecheck(){}}_t.ParameterFieldReference=Mit;class Pit extends Yi{constructor(){super(...arguments),this.elementType="calculateFieldReference"}typecheck(e){(0,Xc.typecheckCalculate)(e,this)}}_t.CalculateFieldReference=Pit;class QB extends Yi{constructor(){super(...arguments),this.elementType="indexFieldReference"}typecheck(e){(0,Xc.typecheckIndex)(e,this)}static indexOutputName(e){return e.map(r=>encodeURIComponent(r)).join("/")}get outputName(){return QB.indexOutputName(this.path)}}_t.IndexFieldReference=QB;class Uit extends Yi{constructor(){super(...arguments),this.elementType="aggregateFieldReference"}typecheck(e){(0,Xc.typecheckAggregate)(e,this)}}_t.AggregateFieldReference=Uit;class jit extends Yi{constructor(){super(...arguments),this.elementType="groupByFieldReference"}typecheck(e){(0,Xc.typecheckGroupBy)(e,this)}}_t.GroupByFieldReference=jit;class qit extends Yi{constructor(){super(...arguments),this.elementType="projectFieldReference"}typecheck(e){(0,Xc.typecheckProject)(e,this)}}_t.ProjectFieldReference=qit;class Hit extends Yi{constructor(){super(...arguments),this.elementType="declareFieldReference"}typecheck(e){(0,Xc.typecheckDeclare)(e,this)}}_t.DeclareFieldReference=Hit;class Qit extends Yi{constructor(){super(...arguments),this.elementType="measureFieldReference"}typecheck(e){(0,Xc.typecheckMeasure)(e,this)}}_t.MeasureFieldReference=Qit;class zit extends Yi{constructor(){super(...arguments),this.elementType="dimensionFieldReference"}typecheck(e){(0,Xc.typecheckDimension)(e,this)}}_t.DimensionFieldReference=zit;class Wit extends Yi{constructor(){super(...arguments),this.elementType="viewOrScalarFieldReference"}typecheck(e){}}_t.ViewOrScalarFieldReference=Wit;class Git extends o0e.MalloyElement{constructor(e){super(),this.joinPath=e,this.elementType="wildcardFieldReference",this.isNoteableObj=!0,this.extendNote=u0e.extendNoteMethod,this.except=new Set,this.has({joinPath:e})}getFieldDef(){throw this.internalError("fielddef request from wildcard reference")}get refString(){return this.joinPath?`${this.joinPath.refString}.*`:"*"}}_t.WildcardFieldReference=Git;class Vit extends Lit.DefinitionList{constructor(e){super(e),this.elementType="fieldReferenceList"}}_t.FieldReferences=Vit,Object.defineProperty(aE,"__esModule",{value:!0}),aE.RefinedSource=void 0;const Yit=et,Kit=w2,Jit=Yc,Xit=qa,Zit=I2,est=$2,tst=B2,nst=Ro,rst=k2,ist=Kc,sst=Jc,ost=L2,ust=ys,a0e=bu,zB=_t;class ast extends nst.Source{constructor(e,r,i){super({source:e,refinement:r}),this.source=e,this.refinement=r,this.includeList=i,this.elementType="refinedSource",i&&this.has({includeList:i})}getSourceDef(e){return this.withParameters(e,[])}withParameters(e,r){var i;let s,o;const u=[],a=[];let l;const c=[];for(const v of this.refinement.list){if(v instanceof ist.ObjectAnnotation)continue;const C=v;if(v instanceof est.PrimaryKey){if(s){const S="multiple-primary-keys";s.logError(S,"Primary key already defined"),v.logError(S,"Primary key redefined")}s=v}else if(v instanceof Zit.FieldListEdit){if(o){const S="multiple-field-list-edits";o.logError(S,"Too many accept/except statements"),v.logError(S,"Too many accept/except statements")}o=v}else v instanceof Jit.DeclareFields||v instanceof ust.JoinStatement||v instanceof tst.Views||v instanceof sst.Renames?(u.push(...v.list),v.accessModifier&&c.push({fields:v.delarationNames,access:v.accessModifier})):v instanceof Xit.Filter?a.push(v):v instanceof rst.TimezoneStatement?l=v.tz:C.logError("unexpected-source-property",`Unexpected source property: '${C.elementType}'`)}const f=r?new ost.ParameterSpace(r):void 0,x=structuredClone(this.source.getSourceDef(f)),{fieldsToInclude:h,modifiers:p,renames:m,notes:g}=lst(this.includeList,x);for(const v of c)for(const C of v.fields)p.set(C,v.access);s&&(x.primaryKey=s.field.name);const y=Kit.RefinedSpace.filteredFrom(x,o,h,m,f);if(l&&y.setTimezone(l),r&&y.addParameters(r),y.pushFields(...u),s){const v=s.field.getField(y);v.error&&s.logError(v.error.code,v.error.message)}y.addAccessModifiers(p),y.addNotes(g);const E=y.structDef(),A=E.filterList||[];let _=!1;for(const v of a)for(const C of v.list){const S=C.filterCondition(y);(0,Yit.expressionIsCalculation)(S.expressionType)?C.logError("aggregate-in-source-filter","Can't use aggregate computations in top level filters"):(A.push(S),_=!0)}return _?{...E,filterList:A}:((i=this.document())===null||i===void 0||i.rememberToAddModelAnnotations(E),E)}}aE.RefinedSource=ast;function lst(t,e){var r,i,s,o,u,a,l,c,f;const x=new Set(e.fields.map(S=>S.name)),h=new Set(e.fields.filter(S=>S.accessModifier==="private").map(S=>S.name));let p;const m=new Set;let g,y;const E=new Map,A=[],_=new Map;if(t===void 0)return{fieldsToInclude:void 0,modifiers:E,renames:A,notes:_};for(const S of t)if(S instanceof a0e.IncludeAccessItem)for(const b of S.fields)if(b.name instanceof zB.WildcardFieldReference)b.name.joinPath&&b.logError("unsupported-path-in-include","Wildcards with paths are not supported in `include` blocks"),g!==void 0?S.logError("already-used-star-in-include","Wildcard already used in this include block"):(g=(r=S.kind)!==null&&r!==void 0?r:"inherit",y={notes:(s=(i=b.note)===null||i===void 0?void 0:i.notes)!==null&&s!==void 0?s:[],blockNotes:(u=(o=S.note)===null||o===void 0?void 0:o.blockNotes)!==null&&u!==void 0?u:[]});else{if(p==="exclude"){S.logError("include-after-exclude","Cannot include specific fields if specific fields are already excluded");continue}p="include";const R=b.name.refString;h.has(R)&&b.logError("cannot-expand-access",`Cannot expand access of \`${R}\` from private to ${S.kind}`),E.has(R)?b.logError("duplicate-include",`Field \`${R}\` already referenced in include list`):(S.kind!==void 0&&E.set(R,S.kind),m.add(R),(b.note||S.note)&&_.set(R,{notes:(l=(a=b.note)===null||a===void 0?void 0:a.notes)!==null&&l!==void 0?l:[],blockNotes:(f=(c=S.note)===null||c===void 0?void 0:c.blockNotes)!==null&&f!==void 0?f:[]})),b.as&&(b.name instanceof zB.WildcardFieldReference?b.logError("wildcard-include-rename","Cannot rename a wildcard field in an `include` block"):A.push({name:b.name,as:b.as,location:b.location}))}else if(S instanceof a0e.IncludeExceptItem)for(const b of S.fields)b instanceof zB.WildcardFieldReference?b.joinPath?b.logError("unsupported-path-in-include","Wildcards with paths are not supported in `include` blocks"):b.logWarning("wildcard-except-redundant","`except: *` is implied, unless another clause uses *"):p==="include"?S.logError("exclude-after-include","Cannot exclude specific fields if specific fields are already included"):(p="exclude",g="inherit",m.add(b.refString));const v=new Set(x);m.forEach(S=>v.delete(S)),h.forEach(S=>v.delete(S));let C;if(g!==void 0)for(const S of v)g!=="inherit"&&E.set(S,g),y&&_.set(S,{...y});return p!=="exclude"?g!==void 0?C=x:C=m:C=v,{fieldsToInclude:C,modifiers:E,renames:A,notes:_}}var Tu={};Object.defineProperty(Tu,"__esModule",{value:!0}),Tu.SourceQueryElement=void 0;const cst=Ze;class WB extends cst.MalloyElement{constructor(){super(...arguments),this.errored=!1}getSource(){}getQuery(){}isSource(){return!1}sqLog(e,r,i){return this.isErrorFree()&&this.logError(e,r,i),this.errored=!0,e}isErrorFree(){if(this.errored)return!1;let e=!0;for(const r of this.walk())if(r instanceof WB&&r.errored){e=!1;break}return e}}Tu.SourceQueryElement=WB;var W4={},Sd={};Object.defineProperty(Sd,"__esModule",{value:!0}),Sd.QuerySource=void 0;const fst=Ro,xst=m2;class dst extends fst.Source{constructor(e){super({query:e}),this.query=e,this.elementType="querySource"}getSourceDef(e){return this.withParameters(e,void 0)}withParameters(e,r){var i;const s=this.query.queryComp(!1),o={...s.outputStruct,name:`QuerySource-${(0,xst.v4)()}`,type:"query_source",query:s.query};return(i=this.document())===null||i===void 0||i.rememberToAddModelAnnotations(o),{...o,parameters:this.packParameters(r)}}}Sd.QuerySource=dst;var M2={},hE={};Object.defineProperty(hE,"__esModule",{value:!0}),hE.QueryBase=void 0;const GB=dt,l0e=et,hst=b2,pst=Ze;class mst extends pst.MalloyElement{resolveCompositeSource(e,r){var i;const s=r.pipeline[0];if(s&&((0,l0e.isQuerySegment)(s)||(0,l0e.isIndexSegment)(s))){const o=(i=s.compositeFieldUsage)!==null&&i!==void 0?i:(0,GB.emptyCompositeFieldUsage)();if(!(0,GB.isEmptyCompositeFieldUsage)(o)||e.type==="composite")return(0,GB.resolveCompositeSources)(e,o).sourceDef}}query(){const{query:e}=this.queryComp(!0);return{...e,pipeline:(0,hst.detectAndRemovePartialStages)(e.pipeline,this)}}}hE.QueryBase=mst,Object.defineProperty(M2,"__esModule",{value:!0}),M2.QueryArrow=void 0;const gst=et,yst=Ro,c0e=Wr,Est=hE;class Ast extends Est.QueryBase{constructor(e,r){super({source:e,view:r}),this.source=e,this.view=r,this.elementType="arrow"}queryComp(e){var r;let i,s,o;if(this.source instanceof yst.Source){const h=e?this.source.structRef(void 0):{structRef:this.source.getSourceDef(void 0)};s={type:"query",...h,pipeline:[],location:this.location},i=(0,gst.refIsStructDef)(h.structRef)?h.structRef:this.source.getSourceDef(void 0),o=new c0e.StaticSourceSpace(i)}else{const h=this.source.queryComp(e);s=h.query,i=h.outputStruct,o=new c0e.StaticSourceSpace(h.outputStruct)}const{pipeline:u,annotation:a,outputStruct:l,name:c}=this.view.pipelineComp(o),f={...s,name:c,annotation:a,pipeline:[...s.pipeline,...u]},x=(r=f.compositeResolvedSourceDef)!==null&&r!==void 0?r:this.resolveCompositeSource(i,f);return{query:{...f,compositeResolvedSourceDef:x},outputStruct:l,inputStruct:i}}}M2.QueryArrow=Ast,Object.defineProperty(W4,"__esModule",{value:!0}),W4.SQArrow=void 0;const _st=Tu,vst=Sd,Cst=M2;class Sst extends _st.SourceQueryElement{constructor(e,r){super({applyTo:e,operation:r}),this.applyTo=e,this.operation=r,this.elementType="sq-arrow"}getQuery(){const e=this.applyTo.isSource()?this.applyTo.getSource():this.applyTo.getQuery();if(e===void 0){this.sqLog("failed-to-compute-arrow-source","Could not get LHS of arrow operation");return}const r=new Cst.QueryArrow(e,this.operation);return this.has({query:r}),r}getSource(){const e=this.getQuery();if(!e){this.sqLog("failed-to-compute-source-from-query","Couldn't comprehend query well enough to make a source");return}const r=new vst.QuerySource(e);return this.has({asSource:r}),r}}W4.SQArrow=Sst;var G4={},P2={},zs={};Object.defineProperty(zs,"__esModule",{value:!0}),zs.getStructFieldDef=zs.getFinalStruct=zs.opOutputStruct=void 0;const f0e=D0,bst=js,V4=et,x0e=gi;function d0e(t,e,r){const i=x0e.ErrorFactory.didCreate(e)||(0,V4.structHasErrors)(e);(0,V4.isPartialSegment)(r)&&(r={...r,type:"reduce"});const s=(0,V4.segmentHasErrors)(r);if(!i&&!s)try{const o=bst.Segment.nextStructDef(e,r);if((0,V4.isSourceDef)(o))return o;t.logError("failed-to-compute-output-schema",`INTERNAL ERROR model/Segment.nextStructDef: RETURNED A NON SOURCE
|
|
1553
1553
|
STRUCTDEF: ${(0,f0e.inspect)(o,{breakLength:72,depth:1/0})}`)}catch(o){t.logError("failed-to-compute-output-schema",`INTERNAL ERROR model/Segment.nextStructDef: ${o.message}
|
|
1554
|
-
QUERY: ${(0,f0e.inspect)(r,{breakLength:72,depth:1/0})}`)}return x0e.ErrorFactory.structDef}zs.opOutputStruct=d0e;function Sst(t,e,r){for(const i of r)e=d0e(t,e,i);return e}zs.getFinalStruct=Sst;function bst(t,e){return t.fields.find(r=>(r.as||r.name)===e)}zs.getStructFieldDef=bst,Object.defineProperty(P2,"__esModule",{value:!0}),P2.QueryRefine=void 0;const Tst=Wr,Rst=zs,Dst=hE;class Ost extends Dst.QueryBase{constructor(e,r){super({base:e,refinement:r}),this.base=e,this.refinement=r,this.elementType="query-refine"}queryComp(e){const r=this.base.queryComp(e),i=new Tst.StaticSourceSpace(r.inputStruct),s=this.refinement.refine(i,r.query.pipeline,void 0),o={...r.query,pipeline:s},u=this.resolveCompositeSource(r.inputStruct,o);return{query:{...o,compositeResolvedSourceDef:u},outputStruct:(0,Rst.getFinalStruct)(this.refinement,r.inputStruct,s),inputStruct:r.inputStruct}}}P2.QueryRefine=Ost;var pE={},U2={},Es={};Object.defineProperty(Es,"__esModule",{value:!0}),Es.mkTimeResult=Es.resolution=Es.castTo=Es.timeOffset=void 0;const VB=et;function Fst(t,e,r,i,s){return{node:"delta",kids:{base:(0,VB.mkTemporal)(e,t),delta:i},op:r,units:s}}Es.timeOffset=Fst;function wst(t,e,r,i=!1){let s;return typeof t!="string"?s={node:"cast",dstSQLType:t.raw,e,safe:i}:s={node:"cast",dstType:{type:t},e,safe:i},(0,VB.isCastType)(r)&&(s.srcType={type:r}),s}Es.castTo=wst;function Nst(t){switch(t){case"hour":case"minute":case"second":case"microsecond":case"millisecond":return"timestamp"}return"date"}Es.resolution=Nst;function Lst(t,e){if(e){if(t.type==="timestamp")return{...t,timeframe:e};if((0,VB.isDateUnit)(e))return{...t,timeframe:e}}return t}Es.mkTimeResult=Lst;var bd={},ht={},Yt={};Object.defineProperty(Yt,"__esModule",{value:!0}),Yt.literalTimeResult=Yt.literalExprValue=Yt.computedErrorExprValue=Yt.computedTimeResult=Yt.computedExprValue=void 0;const h0e=Gi,YB=dt;function mE({value:t,dataType:e,from:r}){return{...e,value:t,expressionType:(0,h0e.maxOfExpressionTypes)(r.map(i=>i.expressionType)),evalSpace:(0,h0e.mergeEvalSpaces)(...r.map(i=>i.evalSpace)),compositeFieldUsage:(0,YB.mergeCompositeFieldUsage)(...r.map(i=>i.compositeFieldUsage))}}Yt.computedExprValue=mE;function Ist({value:t,dataType:e,from:r,timeframe:i}){const s=mE({value:t,dataType:e,from:r}),o={...e,expressionType:s.expressionType,evalSpace:s.evalSpace,value:s.value,compositeFieldUsage:(0,YB.mergeCompositeFieldUsage)(...r.map(u=>u.compositeFieldUsage))};return i&&(o.timeframe=i),o}Yt.computedTimeResult=Ist;function $st({dataType:t,from:e,error:r}){return mE({dataType:t??{type:"error"},value:{node:"error",message:r},from:e})}Yt.computedErrorExprValue=$st;function Bst(t){return mE({...t,from:[]})}Yt.literalExprValue=Bst;function kst({value:t,dataType:e,timeframe:r}){const i=mE({value:t,dataType:e,from:[]}),s={...e,expressionType:i.expressionType,evalSpace:i.evalSpace,value:i.value,compositeFieldUsage:(0,YB.emptyCompositeFieldUsage)()};return r&&(s.timeframe=r),s}Yt.literalTimeResult=kst;var j2={};Object.defineProperty(j2,"__esModule",{value:!0}),j2.isGranularResult=void 0;function Mst(t){return t.type==="date"||t.type==="timestamp"?t.timeframe!==void 0:!1}j2.isGranularResult=Mst;var Ru={};Object.defineProperty(Ru,"__esModule",{value:!0}),Ru.isComparison=Ru.isEquality=Ru.getExprNode=void 0;function Pst(t){switch(t){case"~":return"like";case"!~":return"!like"}return t}Ru.getExprNode=Pst;function p0e(t){return t==="="||t==="!="||t==="~"||t==="!~"}Ru.isEquality=p0e;function Ust(t){return p0e(t)||t===">="||t==="<="||t===">"||t==="<"}Ru.isComparison=Ust;var jst=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),qst=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),Hst=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&jst(e,t,r);return qst(e,t),e};Object.defineProperty(ht,"__esModule",{value:!0}),ht.checkFilterExpression=ht.applyBinary=ht.getMorphicValue=ht.ExprDuration=ht.ExpressionDef=ht.ATNodeType=void 0;const Zc=et,Td=Hst(nn),KB=Hs,m0=Yt,Qst=Es,m0e=j2,zst=Ze,gE=Ru,yE=nE;class Wst extends Error{}var JB;(function(t){t[t.And=0]="And",t[t.Or=1]="Or",t[t.Value=2]="Value",t[t.Partial=3]="Partial"})(JB||(ht.ATNodeType=JB={}));class g0e extends zst.MalloyElement{constructor(){super(...arguments),this.legalChildTypes=Td.anyAtomicT}granular(){return!1}requestExpression(e){return this.getExpression(e)}defaultFieldName(){}typeCheck(e,r){return r.type!=="error"&&!Td.any(r,this.legalChildTypes)?(r.type==="sql native"?e.logError("sql-native-not-allowed-in-expression",{rawType:r.rawType}):e.logError("expression-type-error",`'${this.elementType}' Can't use type ${Td.inspect(r)}`),!1):!0}apply(e,r,i,s=!1){return _0e(e,i,r,this)}canSupportPartitionBy(){return!1}canSupportOrderBy(){return!1}canSupportLimit(){return!1}supportsWhere(e){return(0,Zc.expressionIsAggregate)(e.expressionType)}atNodeType(){return JB.Value}atExpr(){return this}}ht.ExpressionDef=g0e;class XB extends g0e{constructor(e,r){super({n:e}),this.n=e,this.timeframe=r,this.elementType="duration",this.legalChildTypes=[Td.timestampT,Td.dateT]}apply(e,r,i){const s=i.getExpression(e);if(this.typeCheck(this,s),(0,Zc.isTemporalType)(s.type)&&(r==="+"||r==="-")){const o=this.n.getExpression(e);if(!Td.typeEq(o,Td.numberT))return this.logError("invalid-duration-quantity",`Duration quantity needs number not '${o.type}`),(0,KB.errorFor)("illegal unit expression");let u;return(0,m0e.isGranularResult)(s)&&s.timeframe===this.timeframe&&(u=s.timeframe),s.type==="date"&&!(0,Zc.isDateUnit)(this.timeframe)?this.loggedErrorExpr("invalid-timeframe-for-time-offset",`Cannot offset date by ${this.timeframe}`):(0,m0.computedTimeResult)({dataType:{type:s.type},value:(0,Qst.timeOffset)(s.type,s.value,r,o.value,this.timeframe),timeframe:u,from:[s,o]})}return super.apply(e,r,i)}getExpression(e){const r=this.n.getExpression(e);return(0,m0.computedErrorExprValue)({dataType:{type:"duration"},error:"Duration is not a value",from:[r]})}}ht.ExprDuration=XB;function y0e(t,e){return t.type===e?t.value:t.morphic&&t.morphic[e]}function Gst(t,e){if(t.type===e)return t;if(t.morphic&&t.morphic[e])return(0,m0.computedExprValue)({dataType:{type:e},value:t.morphic[e],from:[t]})}ht.getMorphicValue=Gst;function E0e(t,e,r,i){const s=(0,Zc.isTemporalType)(e.type),o=(0,Zc.isTemporalType)(i.type),u=(0,gE.getExprNode)(r);if(s&&o)if(e.type!==i.type){const a=y0e(e,"timestamp"),l=y0e(i,"timestamp");if(a&&l)return{node:u,kids:{left:a,right:a}}}else return{node:u,kids:{left:e.value,right:i.value}};if((s||o)&&e.type!=="null"&&i.type!=="null")return t.logError("time-comparison-type-mismatch",`Cannot compare a ${e.type} to a ${i.type}`),{node:"false"}}function Vst(t,e){if(t.type==="string"){if(e.type==="regular expression")return{node:"regexpMatch",kids:{expr:t.value,regex:e.value}}}else if(e.type==="string"&&t.type==="regular expression")return{node:"regexpMatch",kids:{expr:e.value,regex:t.value}}}function Yst(t,e,r,i){const s=e.getExpression(t),o=i.getExpression(t),u=(0,gE.getExprNode)(r),a=EE("boolean",s,o);if(a)return a;const l=Zc.TD.isSQL(s)?s.rawType||"typeless-left":void 0,c=Zc.TD.isSQL(o)?o.rawType||"typeless-right":void 0;if((l||c)&&!(s.type==="null"||o.type==="null"||l===c)){const h=AE(e,s,i,o);if(h)return{...h,type:"boolean"}}let f;if(o.type==="filter expression"){if(r!=="~"&&r!=="!~")return i.loggedErrorExpr("filter-expression-error",`Cannot use the '${r}' operator with a filter expression`);if((0,yE.isFilterable)(s.type)){let x=o.value;for(;x.node==="()";)x=x.e;x.node!=="parameter"&&v0e(i,s.type,x);const h={node:"filterMatch",dataType:s.type,kids:{filterExpr:o.value,expr:s.value}};r==="!~"&&(h.notMatch=!0),f=h}else return e.loggedErrorExpr("filter-expression-type",`Cannot use filter expressions with type '${s.type}'`)}else if(f=E0e(e,s,r,o)||{node:u,kids:{left:s.value,right:o.value}},s.type!=="error"&&o.type!=="error"&&(r==="~"||r==="!~")&&(s.type!=="string"||o.type!=="string")){let x=Vst(s,o);if(x)r[0]==="!"&&(x={node:"not",e:{...x}});else throw new Wst("Incompatible types for match('~') operator");f=x}return(0,m0.computedExprValue)({dataType:{type:"boolean"},value:f,from:[s,o]})}function Kst(t,e,r,i){const s=e.getExpression(t),o=i.getExpression(t),u=EE("boolean",s,o);if(u)return u;const a=AE(e,s,i,o);if(a)return{...a,type:"boolean"};const l=E0e(e,s,r,o)||{node:(0,gE.getExprNode)(r),kids:{left:s.value,right:o.value}};return(0,m0.computedExprValue)({dataType:{type:"boolean"},value:l,from:[s,o]})}function A0e(t,e,r,i){const s=e.getExpression(t),o=i.getExpression(t),u=EE("number",s,o);if(u)return u;const a=AE(e,s,i,o);if(a)return a;if(s.type!=="number")e.logError("arithmetic-operation-type-mismatch",`The '${r}' operator requires a number, not a '${s.type}'`);else if(o.type!=="number")i.logError("arithmetic-operation-type-mismatch",`The '${r}' operator requires a number, not a '${o.type}'`);else return(0,m0.computedExprValue)({dataType:{type:"number"},value:{node:r,kids:{left:s.value,right:o.value}},from:[s,o]});return(0,KB.errorFor)("numbers required")}function Jst(t,e,r,i){const s=e.getExpression(t),o=i.getExpression(t),u=AE(e,s,i,o);if(u)return u;const a=(0,Zc.isTemporalType)(s.type),l=EE(a?"error":"number",s,o);if(l)return l;if(a){let c=i;if(o.type!=="duration")if((0,m0e.isGranularResult)(s))c=new XB(i,s.timeframe);else if(s.type==="date")c=new XB(i,"day");else return e.loggedErrorExpr("time-offset-type-mismatch",`Can not offset time by '${o.type}'`);return c.apply(t,r,e)}return A0e(t,e,r,i)}function _0e(t,e,r,i){if((0,gE.isEquality)(r))return Yst(t,e,r,i);if((0,gE.isComparison)(r))return Kst(t,e,r,i);if(r==="+"||r==="-")return Jst(t,e,r,i);if(r==="*")return A0e(t,e,r,i);if(r==="/"||r==="%"){const s=e.getExpression(t),o=i.getExpression(t),u=AE(e,s,i,o);if(u)return u;const a=EE("number",s,o);if(a)return a;if(s.type!=="number")e.logError("arithmetic-operation-type-mismatch","Numerator must be a number");else if(o.type!=="number")i.logError("arithmetic-operation-type-mismatch","Denominator must be a number");else{const l={node:r,kids:{left:s.value,right:o.value}};return(0,m0.computedExprValue)({dataType:{type:"number"},value:l,from:[s,o]})}return(0,KB.errorFor)("divide type mismatch")}return e.loggedErrorExpr("unexpected-binary-operator",`Cannot use ${r} operator here`)}ht.applyBinary=_0e;function EE(t,...e){if(e.some(r=>r.type==="error"))return(0,m0.computedExprValue)({dataType:{type:t},value:{node:"error",message:"cascading error"},from:e})}function AE(t,e,r,i){const s=(0,m0.computedExprValue)({dataType:e,value:{node:"error",message:"sql-native unsupported"},from:[e,i]});if(e.type==="sql native")return t.logError("sql-native-not-allowed-in-expression",{rawType:e.rawType}),s.type=i.type,s;if(i.type==="sql native")return r.logError("sql-native-not-allowed-in-expression",{rawType:i.rawType}),s}function v0e(t,e,r){for(var i,s,o,u;r.node==="()";)r=r.e;if(r.node!=="filterLiteral"){t.logError("filter-expression-error","Expected a filter expression literal here");return}const a=r.filterSrc;let l;e==="date"||e==="timestamp"?l=(i=yE.TemporalFilterExpression.parse(a).log[0])===null||i===void 0?void 0:i.message:e==="string"?l=(s=yE.StringFilterExpression.parse(a).log[0])===null||s===void 0?void 0:s.message:e==="number"?l=(o=yE.NumberFilterExpression.parse(a).log[0])===null||o===void 0?void 0:o.message:e==="boolean"?l=(u=yE.BooleanFilterExpression.parse(a).log[0])===null||u===void 0?void 0:u.message:t.logError("filter-expression-type",`Cannot apply filter expression to type ${e}`),l!==void 0&&t.logError("filter-expression-error",`Filter syntax error: ${l}`)}ht.checkFilterExpression=v0e,Object.defineProperty(bd,"__esModule",{value:!0}),bd.ExprIdReference=void 0;const Xst=et,Zst=ht,eot=dt;class tot extends Zst.ExpressionDef{constructor(e){super(),this.fieldReference=e,this.elementType="ExpressionIdReference",this.has({fieldPath:e})}get refString(){return this.fieldReference.refString}getExpression(e){const r=this.fieldReference.getField(e),i=this.fieldReference.list.map(s=>s.name).slice(0,-1);if(r.found){const s=r.found.typeDesc(),o=(0,eot.joinedCompositeFieldUsage)(i,s.compositeFieldUsage);if(r.isOutputField)return{...s,evalSpace:s.evalSpace==="constant"?"constant":"output",value:{node:"outputField",name:this.refString},compositeFieldUsage:o};const u={node:r.found.refType,path:this.fieldReference.path},a=(0,Xst.expressionIsAggregate)(s.expressionType)?"output":s.evalSpace;return{...s,value:u,evalSpace:a,compositeFieldUsage:o}}return this.loggedErrorExpr(r.error.code,r.error.message)}}bd.ExprIdReference=tot,Object.defineProperty(U2,"__esModule",{value:!0}),U2.NamedSource=void 0;const ZB=et,not=Ro,rot=gi,iot=Es,C0e=Ze,sot=bd,oot=L2,uot=ht;class aot extends not.Source{constructor(e,r,i){super(),this.ref=e,this.sourceArguments=r,this.args=i,this.elementType="namedSource",i&&this.has({args:i}),e instanceof C0e.ModelEntryReference&&this.has({ref:e})}get refName(){return this.ref instanceof C0e.ModelEntryReference?this.ref.name:this.ref}structRef(e){const r=this.modelEntry(this.ref);return r&&!r.exported?{structRef:this.getSourceDef(e)}:{structRef:this.refName,sourceArguments:this.evaluateArgumentsForRef(e)}}refLogError(e,r,i){typeof this.ref=="string"?this.logError(e,r,i):this.ref.logError(e,r,i)}modelStruct(){var e;const r=this.modelEntry(this.ref),i=r==null?void 0:r.entry;if(!i){this.refLogError("source-not-found",`Undefined source '${this.refName}'`);return}if(i.type==="query"){this.logError("invalid-source-from-query",`Cannot construct a source from query '${this.refName}'`);return}else if(i.type==="function"){this.logError("invalid-source-from-function",`Cannot construct a source from a function '${this.refName}'`);return}else if(i.type==="connection"){this.logError("invalid-source-from-connection",`Cannot construct a source from a connection '${this.refName}'`);return}else if((e=this.document())===null||e===void 0||e.checkExperimentalDialect(this,i.dialect),(0,ZB.isSourceDef)(i))return{...i};this.logError("invalid-source-source","Cannot construct a source from a never type")}evaluateArgumentsForRef(e){const r=this.modelStruct();return r===void 0?{}:this.evaluateArguments(e,r.parameters,[])}evaluateArguments(e,r,i){var s,o;const u={...this.sourceArguments},a=new Set;for(const l of(s=this.args)!==null&&s!==void 0?s:[]){const c=(o=l.id)!==null&&o!==void 0?o:l.value instanceof sot.ExprIdReference?l.value.fieldReference:void 0;if(c===void 0){l.value.logError("unnamed-source-argument","Parameterized source arguments must be named with `parameter_name is`");continue}const f=c.outputName;if(a.has(f)){l.logError("duplicate-source-argument",`Cannot pass argument for \`${f}\` more than once`);continue}a.add(f);const x=(r??{})[f];if(!x)c.logError("source-parameter-not-found",`\`${this.refName}\` has no declared parameter named \`${c.refString}\``);else{const h=e??new oot.ParameterSpace(i??[]),p=l.value.getExpression(h);let m=p.value;p.type==="filter expression"&&x.type==="filter expression"&&x.filterType&&(0,uot.checkFilterExpression)(l.value,x.filterType,m),p.type!==x.type&&(0,ZB.isCastType)(x.type)&&(m=(0,iot.castTo)(x.type,p.value,p.type,!0)),u[f]={...x,value:m}}}for(const l in r)l in u||((0,ZB.paramHasValue)(r[l])?u[l]={...r[l]}:this.refLogError("missing-source-argument",`Argument not provided for required parameter \`${l}\``));return u}getSourceDef(e){return this.withParameters(e,[])}withParameters(e,r){var i;const s=this.modelStruct();if(!s){const l=rot.ErrorFactory.structDef,c=`${this.refName}-undefined`;return l.name=l.name+c,l.dialect=l.dialect+c,l}const o={};for(const l of r??[]){const c=l.parameter();o[c.name]=c}const u=this.evaluateArguments(e,s.parameters,r),a={...s,parameters:o,arguments:u};return(i=this.document())===null||i===void 0||i.rememberToAddModelAnnotations(a),a}}U2.NamedSource=aot;var _E={},Y4={};Object.defineProperty(Y4,"__esModule",{value:!0}),Y4.QueryHeadStruct=void 0;const lot=et,cot=Ro,fot=U2;class xot extends cot.Source{constructor(e,r){super(),this.fromRef=e,this.sourceArguments=r,this.elementType="internalOnlyQueryHead"}structRef(){return{structRef:this.fromRef}}getSourceDef(e){if((0,lot.refIsStructDef)(this.fromRef))return this.fromRef;const r=new fot.NamedSource(this.fromRef,this.sourceArguments,void 0);return this.has({exploreReference:r}),r.getSourceDef(e)}}Y4.QueryHeadStruct=xot,Object.defineProperty(_E,"__esModule",{value:!0}),_E.QueryReference=void 0;const ek=gi,dot=Ze,hot=Y4,pot=et,mot=zs;class got extends dot.MalloyElement{constructor(e){super(),this.name=e,this.elementType="query-reference"}queryComp(e){const r=this.modelEntry(this.name),i=r==null?void 0:r.entry,s=function(){return{inputStruct:ek.ErrorFactory.structDef,outputStruct:ek.ErrorFactory.structDef,query:ek.ErrorFactory.query}};if(!i)return this.logError("query-reference-not-found",`Reference to undefined query '${this.name.refString}'`),s();if(i.type==="query"){const o=new hot.QueryHeadStruct(i.structRef,i.sourceArguments);this.has({queryHead:o});const u=o.getSourceDef(void 0),a=(0,mot.getFinalStruct)(this,u,i.pipeline);return{query:e||(0,pot.refIsStructDef)(i.structRef)?i:{...i,structRef:u},outputStruct:a,inputStruct:u}}return this.logError("non-query-used-as-query",`Illegal reference to '${this.name}', query expected`),s()}query(){return this.queryComp(!0).query}}_E.QueryReference=got,Object.defineProperty(pE,"__esModule",{value:!0}),pE.SQReference=void 0;const yot=Tu,Eot=Sd,Aot=U2,S0e=_E,b0e=Gi;class _ot extends yot.SourceQueryElement{constructor(e,r){super({ref:e}),this.ref=e,this.args=r,this.elementType="sq-reference",r!==void 0&&this.has({args:r})}getQuery(){const e=this.ref.getNamed();if(e)if(e.type==="query"){const r=new S0e.QueryReference(this.ref);return this.has({query:r}),r}else this.sqLog("cannot-use-as-query",`Illegal reference to '${e.as||e.name}', query expected`);else this.ref.logError("source-or-query-not-found",`Reference to undefined object '${this.ref.refString}'`),this.errored=!0}isSource(){const e=this.ref.getNamed();return e!==void 0&&(0,b0e.isSourceDef)(e)}getSource(){if(this.asSource)return this.asSource;const e=this.ref.getNamed();if(!e){this.ref.logError("source-not-found",`Reference to undefined object '${this.ref.refString}'`),this.errored=!0;return}if(e.type==="query"){this.args!==void 0&&this.ref.logError("illegal-query-argument","Arguments cannot be passed to queries");const r=new S0e.QueryReference(this.ref);this.asSource=new Eot.QuerySource(r)}else if((0,b0e.isSourceDef)(e))this.asSource=new Aot.NamedSource(this.ref,void 0,this.args);else{this.sqLog("cannot-use-struct-as-source",`Expected '${this.ref.refString}' to be of type query or source, not '${e.type}'`);return}return this.has({asSource:this.asSource}),this.asSource}}pE.SQReference=_ot,Object.defineProperty(G4,"__esModule",{value:!0}),G4.SQRefine=void 0;const vot=Tu,Cot=Sd,Sot=P2,bot=pE;class Tot extends vot.SourceQueryElement{constructor(e,r){super({toRefine:e,refine:r}),this.toRefine=e,this.refine=r,this.elementType="sq-refine"}getQuery(){if(this.toRefine.isSource()){this.toRefine instanceof bot.SQReference?this.sqLog("illegal-refinement-of-source",`Cannot add view refinements to '${this.toRefine.ref.refString}' because it is a source`):this.sqLog("illegal-refinement-of-source","Cannot add view refinements to a source");return}const e=this.toRefine.getQuery();if(e){const r=new Sot.QueryRefine(e,this.refine);return this.has({query:r}),r}}getSource(){const e=this.getQuery();if(e){const r=new Cot.QuerySource(e);return this.has({queryAsSource:r}),r}}}G4.SQRefine=Tot;var K4={},vE={};Object.defineProperty(vE,"__esModule",{value:!0}),vE.QueryRaw=void 0;const Rot=et,Dot=Ze;class Oot extends Dot.MalloyElement{constructor(e){super({source:e}),this.source=e,this.elementType="query-raw"}queryComp(e){const r=e?this.source.structRef(void 0):{structRef:this.source.getSourceDef(void 0)},i=(0,Rot.refIsStructDef)(r.structRef)?r.structRef:this.source.getSourceDef(void 0);return{query:{type:"query",...r,pipeline:[{type:"raw",fields:[]}],location:this.location},outputStruct:i,inputStruct:i}}query(){return this.queryComp(!0).query}}vE.QueryRaw=Oot;var CE={},g0={};Object.defineProperty(g0,"__esModule",{value:!0}),g0.sqlKey=g0.compileSQLInterpolation=void 0;const Fot=js,wot=et,Not=kt;function Lot(t,e,r){let i,s="",o=!1;for(const u of t)if((0,wot.isSegmentSQL)(u))s+=u.sql,o=u.sql.match(/\(\s*$/)!==null;else{if(!i){if(!r)throw new Error("Internal error: Partial model missing when compiling SQL block");i=new Fot.QueryModel(r)}const a=i.compileQuery(u,{defaultRowLimit:void 0},!1).sql;s+=o?a:`(${a})`,o=!1}return{connection:e,selectStr:s}}g0.compileSQLInterpolation=Lot;function Iot(t,e){return`sql://${t}/${(0,Not.generateHash)(e)}`}g0.sqlKey=Iot,Object.defineProperty(CE,"__esModule",{value:!0}),CE.SQLSource=void 0;const tk=g0,$ot=Ro,SE=gi;class Bot extends $ot.Source{constructor(e,r){super({connectionName:e,select:r}),this.connectionName=e,this.select=r,this.elementType="sqlSource",this.connectionNameInvalid=!1}sqlSourceRequest(e){const r=this.select.containsQueries?e.modelDef():void 0;return(0,tk.compileSQLInterpolation)(this.select.sqlPhrases(),this.connectionName.refString,r)}structRef(){return{structRef:this.getSourceDef()}}validateConnectionName(){var e;const r=this.modelEntry(this.connectionName),i=this.connectionName.refString;if(this.connectionNameInvalid)return!1;if(r===void 0)(e=this.namespace())===null||e===void 0||e.setEntry(i,{entry:{type:"connection",name:i},exported:!0},!0);else if(r.entry.type!=="connection")return this.connectionName.logError("invalid-connection-for-sql-source",`${this.connectionName.refString} is not a connection`),this.connectionNameInvalid=!0,!1;return!0}needs(e){var r;if(!this.validateConnectionName())return;const i=super.needs(e);if(i)return i;this.requestBlock===void 0&&(this.requestBlock=this.sqlSourceRequest(e));const s=this.requestBlock,o=(r=this.translator())===null||r===void 0?void 0:r.root.sqlQueryZone;if(!o){this.logError("failed-to-fetch-sql-source-schema","Cant't look up schema for sql block");return}const u=(0,tk.sqlKey)(s.connection,s.selectStr);o.reference(u,this.location);const a=o.getEntry(u);if(a.status==="reference")return{compileSQL:s};a.status==="present"&&e.checkExperimentalDialect(this,a.value.dialect)}getSourceDef(){var e;if(!this.validateConnectionName())return SE.ErrorFactory.structDef;const r=(e=this.translator())===null||e===void 0?void 0:e.root.sqlQueryZone;if(!r)return this.logError("failed-to-fetch-sql-source-schema","Cant't look up schema for sql block"),SE.ErrorFactory.structDef;if(this.requestBlock===void 0)return this.logError("failed-to-fetch-sql-source-schema","Expected to have already compiled the sql block"),SE.ErrorFactory.structDef;const i=this.requestBlock,s=(0,tk.sqlKey)(i.connection,i.selectStr);r.reference(s,this.location);const o=r.getEntry(s);if(o.status==="error"){const u=o.message.split(/\r?\n/);return this.select.logError("invalid-sql-source","Invalid SQL, "+u.join(`
|
|
1555
|
-
`)),SE.ErrorFactory.structDef}else if(o.status==="present"){const u=this.select.location,a={...o.value,fields:o.value.fields.map(f=>({...f,location:u})),location:this.location},l=this.document(),c=l==null?void 0:l.currentModelAnnotation();return c&&(a.modelAnnotation=c),a}else return this.logError("non-top-level-sql-source","`connection_name.sql(...)` can currently only be used in top level source/query definitions"),SE.ErrorFactory.structDef}}CE.SQLSource=Bot,Object.defineProperty(K4,"__esModule",{value:!0}),K4.SQSource=void 0;const kot=Tu,Mot=vE,Pot=CE;class Uot extends kot.SourceQueryElement{constructor(e){super({theSource:e}),this.theSource=e,this.elementType="sq-source"}isSource(){return!0}getSource(){return this.theSource}getQuery(){if(this.theSource instanceof Pot.SQLSource){const e=new Mot.QueryRaw(this.theSource);return this.has({rawQuery:e}),e}else this.sqLog("invalid-source-as-query","This source cannot be used as a query")}}K4.SQSource=Uot;var J4={};Object.defineProperty(J4,"__esModule",{value:!0}),J4.SQExtend=void 0;const jot=aE,qot=Tu;class Hot extends qot.SourceQueryElement{constructor(e,r,i){super({sqSrc:e,extend:r}),this.sqSrc=e,this.extend=r,this.includeList=i,this.elementType="sq-extend"}getSource(){if(this.asSource)return this.asSource;const e=this.sqSrc.getSource();if(e)return this.asSource=new jot.RefinedSource(e,this.extend,this.includeList),this.has({asSource:this.asSource}),this.asSource;this.sqLog("failed-to-compute-source-to-extend","Could not compute source to extend")}isSource(){return!0}}J4.SQExtend=Hot;var X4={},Z4={};Object.defineProperty(Z4,"__esModule",{value:!0}),Z4.CompositeSource=void 0;const Qot=et,zot=Ro;class Wot extends zot.Source{constructor(e){super({sources:e}),this.sources=e,this.elementType="compositeSource"}getSourceDef(e){return this.withParameters(e,[])}withParameters(e,r){const i=this.sources.map(c=>c.withParameters(e,r)),s=i[0].connection,o=i[0].dialect,u="composite_source",a=[],l=new Map;return this.sources.forEach((c,f)=>{var x;const h=i[f];h.connection!==s&&c.logError("composite-source-connection-mismatch",`All sources in a composite source must share the same connection; connection \`${h.connection}\` differs from previous connection \`${s}\``);for(const p of h.fields){if(!(0,Qot.isAtomic)(p)){c.logWarning("composite-source-atomic-fields-only",`Only atomic fields are supported in composite sources; field \`${p.name}\` is not atomic and will be ignored`);continue}if(p.accessModifier==="private")continue;const m=(x=p.as)!==null&&x!==void 0?x:p.name,g=l.get(m);if(g===void 0){const y={...p,name:m,as:void 0,e:{node:"compositeField"},compositeFieldUsage:{fields:[m],joinedUsage:{}},code:this.code,location:this.codeLocation};l.set(m,y),a.push(y)}else p.accessModifier==="internal"&&(g.accessModifier="internal")}}),{type:"composite",sources:i,connection:s,fields:a,dialect:o,name:u,parameters:i[0].parameters}}}Z4.CompositeSource=Wot,Object.defineProperty(X4,"__esModule",{value:!0}),X4.SQCompose=void 0;const Got=Z4,Vot=Tu;class Yot extends Vot.SourceQueryElement{constructor(e){super({sources:e}),this.sources=e,this.elementType="sq-compose"}getSource(){if(this.asSource)return this.asSource;const e=this.sources.map(r=>r.getSource());if(e.length===0){this.sqLog("empty-composite-source","Composite source must have at least one input source");return}else e.length===1&&this.sqLog("unnecessary-composite-source","A composite source with one input is equivalent to that input",{severity:"warn"});if(Kot(e))return this.asSource=new Got.CompositeSource(e),this.has({asSource:this.asSource}),this.asSource;this.sqLog("invalid-composite-source-input","All composite source inputs must be valid sources")}isSource(){return!0}}X4.SQCompose=Yot;function Kot(t){return t.every(e=>e!==void 0)}var eT={},y0={},bE={},Jot=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),Xot=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),Zot=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&Jot(e,t,r);return Xot(e,t),e};Object.defineProperty(bE,"__esModule",{value:!0}),bE.BinaryBoolean=void 0;const eut=Hs,tut=Zot(nn),nut=Ru,rut=Yt,iut=ht;class sut extends iut.ExpressionDef{constructor(e,r,i){super({left:e,right:i}),this.left=e,this.op=r,this.right=i,this.elementType="abstract boolean binary",this.legalChildTypes=[tut.boolT]}getExpression(e){const r=this.left.getExpression(e),i=this.right.getExpression(e);return this.typeCheck(this.left,r)&&this.typeCheck(this.right,i)?(0,rut.computedExprValue)({dataType:{type:"boolean"},value:{node:(0,nut.getExprNode)(this.op),kids:{left:r.value,right:i.value}},from:[r,i]}):(0,eut.errorFor)("logical-op expected boolean")}}bE.BinaryBoolean=sut;var out=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),uut=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),aut=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&out(e,t,r);return uut(e,t),e};Object.defineProperty(y0,"__esModule",{value:!0}),y0.ExprLegacyIn=y0.ExprEquality=y0.ExprCompare=void 0;const hn=aut(nn),lut=Yt,cut=ht,fut=bE,xut={"~":[hn.stringT],"!~":[hn.stringT],"<":[hn.numberT,hn.stringT,hn.dateT,hn.timestampT],"<=":[hn.numberT,hn.stringT,hn.dateT,hn.timestampT],"=":[hn.numberT,hn.stringT,hn.dateT,hn.timestampT],"!=":[hn.numberT,hn.stringT,hn.dateT,hn.timestampT],">=":[hn.numberT,hn.stringT,hn.dateT,hn.timestampT],">":[hn.numberT,hn.stringT,hn.dateT,hn.timestampT]};class T0e extends fut.BinaryBoolean{constructor(e,r,i){super(e,r,i),this.elementType="a<=>b",this.legalChildTypes=xut[r]}getExpression(e){return this.right.apply(e,this.op,this.left)}}y0.ExprCompare=T0e;class dut extends T0e{constructor(e,r,i){super(e,r,i),this.elementType="a~=b"}getExpression(e){return this.right.apply(e,this.op,this.left,!0)}apply(e,r,i){return super.apply(e,r,i,!0)}}y0.ExprEquality=dut;class hut extends cut.ExpressionDef{constructor(e,r,i){super(),this.expr=e,this.notIn=r,this.choices=i,this.elementType="in",this.has({expr:e,choices:i})}getExpression(e){const r=this.expr.getExpression(e),i=this.choices.map(s=>s.getExpression(e));return(0,lut.computedExprValue)({dataType:{type:"boolean"},value:{node:"in",not:this.notIn,kids:{e:r.value,oneOf:i.map(s=>s.value)}},from:[r,...i]})}}y0.ExprLegacyIn=hut;var TE={},q2={};Object.defineProperty(q2,"__esModule",{value:!0}),q2.ExprTime=void 0;const put=et,mut=Yt,gut=ht;class nk extends gut.ExpressionDef{constructor(e,r,i){super(),this.elementType="timestampOrDate",this.elementType=e,this.translationValue=(0,mut.computedExprValue)({dataType:{type:e},value:r,from:i??[]})}getExpression(e){return this.translationValue}static fromValue(e,r){let i=r.value;if(e!==r.type){const s={node:"cast",safe:!1,dstType:{type:e},e:r.value};(0,put.isTemporalType)(r.type)&&(s.srcType={type:r.type}),i=s}return new nk(e,i,[r])}}q2.ExprTime=nk;var ef={};Object.defineProperty(ef,"__esModule",{value:!0}),ef.Range=void 0;const yut=Hs,Eut=Yt,Aut=ht;class _ut extends Aut.ExpressionDef{constructor(e,r){super({first:e,last:r}),this.first=e,this.last=r,this.elementType="range"}apply(e,r,i){switch(r){case"=":case"!=":{const s=r==="="?">=":"<",o=r==="="?"and":"or",u=r==="="?"<":">=",a=this.first.apply(e,s,i),l=this.last.apply(e,u,i);return(0,Eut.computedExprValue)({dataType:{type:"boolean"},value:{node:o,kids:{left:a.value,right:l.value}},from:[a,l]})}case">":return this.last.apply(e,">=",i);case">=":return this.first.apply(e,">=",i);case"<":return this.first.apply(e,"<",i);case"<=":return this.last.apply(e,"<",i)}throw new Error("mysterious error in range computation")}requestExpression(e){}getExpression(e){return this.logError("range-as-value","A Range is not a value"),(0,yut.errorFor)("a range is not a value")}}ef.Range=_ut;var vut=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),Cut=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),Sut=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&vut(e,t,r);return Cut(e,t),e};Object.defineProperty(TE,"__esModule",{value:!0}),TE.ExprGranularTime=void 0;const rk=et,but=Hs,R0e=Sut(nn),D0e=Es,Tut=ht,tT=q2,O0e=ef;class Rut extends Tut.ExpressionDef{constructor(e,r,i){super({expr:e}),this.expr=e,this.units=r,this.truncate=i,this.elementType="granularTime",this.legalChildTypes=[R0e.timestampT,R0e.dateT]}granular(){return!0}getExpression(e){const r=this.units,i=this.expr.getExpression(e);if(rk.TD.isTemporal(i)){const o={...i,timeframe:r};return this.truncate&&(o.value={node:"trunc",e:(0,rk.mkTemporal)(i.value,i.type),units:r}),o}i.type!=="error"&&this.logError("unsupported-type-for-time-truncation",`Cannot do time truncation on type '${i.type}'`);const s={...i};return i.type==="error"&&(s.type=(0,rk.isDateUnit)(r)?"date":"timestamp"),{...s,value:(0,but.errorFor)("granularity typecheck").value,evalSpace:"constant"}}toRange(e){const r=this.getExpression(e),i={node:"numberLiteral",literal:"1"};if(r.type==="timestamp"){const a=tT.ExprTime.fromValue("timestamp",r),l=new tT.ExprTime("timestamp",(0,D0e.timeOffset)("timestamp",r.value,"+",i,this.units),[r]);return new O0e.Range(a,l)}const s=new tT.ExprTime("date",r.value,[r]),o=(0,D0e.timeOffset)("date",r.value,"+",i,this.units),u=new tT.ExprTime("date",o,[r]);return new O0e.Range(s,u)}}TE.ExprGranularTime=Rut,Object.defineProperty(eT,"__esModule",{value:!0}),eT.Apply=void 0;const Dut=y0,Out=j2,F0e=TE;class Fut extends Dut.ExprCompare{constructor(e,r){super(e,"=",r),this.left=e,this.right=r,this.elementType="apply"}getExpression(e){let r=this.right;if(!this.right.granular()){const i=this.right.requestExpression(e);i&&(0,Out.isGranularResult)(i)&&(r=new F0e.ExprGranularTime(this.right,i.timeframe,!1))}return r instanceof F0e.ExprGranularTime?r.toRange(e).apply(e,this.op,this.left):super.getExpression(e)}}eT.Apply=Fut;var H2={},wut=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),Nut=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),Lut=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&wut(e,t,r);return Nut(e,t),e};Object.defineProperty(H2,"__esModule",{value:!0}),H2.BinaryNumeric=void 0;const Iut=Lut(nn),$ut=ht;class But extends $ut.ExpressionDef{constructor(e,r,i){super({left:e,right:i}),this.left=e,this.op=r,this.right=i,this.elementType="numeric binary abstract",this.legalChildTypes=[Iut.numberT]}getExpression(e){return this.right.apply(e,this.op,this.left)}}H2.BinaryNumeric=But;var nT={},kut=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),Mut=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),Put=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&kut(e,t,r);return Mut(e,t),e};Object.defineProperty(nT,"__esModule",{value:!0}),nT.Boolean=void 0;const Uut=ht,jut=Put(nn);let qut=class extends Uut.ExpressionDef{constructor(e){super(),this.value=e,this.elementType="boolean literal"}getExpression(){return{...jut.boolT,value:{node:this.value}}}};nT.Boolean=qut;var Q2={};Object.defineProperty(Q2,"__esModule",{value:!0}),Q2.ConstantExpression=Q2.ConstantFieldSpace=void 0;const Hut=ht;class w0e{constructor(){this.type="fieldSpace"}structDef(){throw new Error("ConstantFieldSpace cannot generate a structDef")}emptyStructDef(){throw new Error("ConstantFieldSpace cannot generate a structDef")}lookup(e){return{error:{message:"Only constants allowed in parameter default values",code:"illegal-reference-in-parameter-default"},found:void 0}}entries(){return[]}entry(){}dialectName(){return"~constant-space-unknown-dialect~"}dialectObj(){}isQueryFieldSpace(){return!1}isProtectedAccessSpace(){return!1}}Q2.ConstantFieldSpace=w0e;class Qut extends Hut.ExpressionDef{constructor(e){super({expr:e}),this.expr=e,this.elementType="constantExpression"}getExpression(e){return this.constantValue()}get constantFs(){return this.cfs||(this.cfs=new w0e),this.cfs}constantValue(){return this.expr.getExpression(this.constantFs)}apply(e,r,i){return this.expr.apply(e,r,i)}requestExpression(e){return this.expr.requestExpression(e)}}Q2.ConstantExpression=Qut;var tf={};Object.defineProperty(tf,"__esModule",{value:!0}),tf.FunctionOrdering=tf.FunctionOrderBy=void 0;const ik=et,N0e=Ze,zut=bd;class Wut extends N0e.MalloyElement{constructor(e,r){super(),this.field=e,this.dir=r,this.elementType="orderBy",e&&this.has({field:e})}getAnalyticOrderBy(e){if(!this.field)return this.logError("analytic-order-by-missing-field","analytic `order_by` must specify an aggregate expression or output field reference"),{node:"functionOrderBy",e:{node:"error"},dir:this.dir};const r=this.field.getExpression(e);return(0,ik.expressionIsAggregate)(r.expressionType)||((0,ik.expressionIsScalar)(r.expressionType)?(!(this.field instanceof zut.ExprIdReference)||r.evalSpace==="input")&&this.field.logError("analytic-order-by-not-output","analytic `order_by` must be an aggregate or an output field reference"):this.field.logError("analytic-order-by-not-aggregate-or-output","analytic `order_by` must be scalar or aggregate")),{node:"functionOrderBy",e:r.value,dir:this.dir}}getAggregateOrderBy(e,r){if(this.field){const i=this.field.getExpression(e);return(0,ik.expressionIsScalar)(i.expressionType)||this.field.logError("aggregate-order-by-not-scalar","aggregate `order_by` must be scalar"),r||this.field.logError("aggregate-order-by-expression-not-allowed","`order_by` must be only `asc` or `desc` with no expression"),{node:"functionOrderBy",e:i.value,dir:this.dir}}else return this.dir===void 0?(this.logError("aggregate-order-by-without-field-or-direction","field or order direction must be specified"),{node:"functionDefaultOrderBy",dir:"asc"}):{node:"functionDefaultOrderBy",dir:this.dir}}}tf.FunctionOrderBy=Wut;class Gut extends N0e.ListOf{constructor(e){super(e),this.elementType="function-ordering"}getAnalyticOrderBy(e){return this.list.map(r=>r.getAnalyticOrderBy(e))}getAggregateOrderBy(e,r){return this.list.map(i=>i.getAggregateOrderBy(e,r))}}tf.FunctionOrdering=Gut;var rT={};Object.defineProperty(rT,"__esModule",{value:!0}),rT.ExprAddSub=void 0;const Vut=H2;class Yut extends Vut.BinaryNumeric{constructor(){super(...arguments),this.elementType="+-"}}rT.ExprAddSub=Yut;var E0={},Kut=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),Jut=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),Xut=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&Kut(e,t,r);return Jut(e,t),e};Object.defineProperty(E0,"__esModule",{value:!0}),E0.ExprAggregateFunction=void 0;const RE=et,Zut=kt,eat=Hs,L0e=Wr,I0e=Xut(nn),tat=_t,nat=ht,rat=zr,iat=bd;class sat extends nat.ExpressionDef{constructor(e,r,i){super(),this.func=e,this.legalChildTypes=[I0e.numberT],this.elementType=e,this.explicitSource=i,r&&(this.expr=r,this.has({expr:r}))}getExpression(e){var r,i,s;const o=e.isQueryFieldSpace()?e.inputSpace():e;let u=this.expr,a=(r=this.expr)===null||r===void 0?void 0:r.getExpression(o),l=(i=this.source)===null||i===void 0?void 0:i.path,c=[];if(this.source){const x=this.source.getField(o);if(x.found){c=x.joinPath;const h=x.found,p=h.typeDesc();if(!(h instanceof L0e.StructSpaceField))if((0,RE.isAtomicFieldType)(p.type)){u=this.source,a={...I0e.atomicDef(p),expressionType:p.expressionType,value:p.evalSpace==="output"?{node:"outputField",name:this.source.refString}:{node:"field",path:this.source.path},evalSpace:p.evalSpace,compositeFieldUsage:p.compositeFieldUsage},l=this.source.path.slice(0,-1);const m=this.getJoinUsage(o);(m.length===1||m.length>1&&m.slice(1).every(y=>oat(y,m[0])))&&(l=m[0].map(y=>y.name),c=m[0])}else return this.loggedErrorExpr("invalid-aggregate-source",`Aggregate source cannot be a ${p.type}`)}else return this.loggedErrorExpr("aggregate-source-not-found",`Reference to undefined value ${this.source.refString}`)}if(a===void 0)return this.loggedErrorExpr("missing-aggregate-expression","Missing expression for aggregate function");if((0,RE.expressionIsAggregate)(a.expressionType))return this.loggedErrorExpr("aggregate-of-aggregate","Aggregate expression cannot be aggregate");if(!(a.type==="error")){const x=this.getJoinUsage(o),h=this.source!==void 0||this.explicitSource;if(u&&!(!this.source&&x.every(m=>m.length===0))&&!this.isSymmetricFunction()){const m=ok(c,x),g=uk(this.elementType,m),y=h?g==null?void 0:g.message:"Join path is required for this calculation";if(y){const E=uat(y,x,u,this.elementType),A=(s=g==null?void 0:g.code)!==null&&s!==void 0?s:"bad-join-usage";g?this.logError(A,E):this.logWarning(A,E)}}}if(this.typeCheck(this.expr||this,{...a,expressionType:"scalar"})){const x={node:"aggregate",function:this.func,e:a.value};return l&&l.length>0&&(x.structPath=l),{...this.returns(a),expressionType:"aggregate",value:x,evalSpace:"output"}}return(0,eat.errorFor)("aggregate type check")}isSymmetricFunction(){return!0}getJoinUsage(e){const r=[];if(this.source&&this.source.getField(e).found){const s={node:"field",path:this.source.path};r.push(...sk(e,s))}if(this.expr){const i=this.expr.getExpression(e).value;r.push(...sk(e,i))}return r}}E0.ExprAggregateFunction=sat;function oat(t,e){let r=t.length;if(r!==e.length)return!1;for(;r>0;)if(r-=1,t[r].name!==e[r].name)return!1;return!0}function sk(t,e){const r=[],i=(s,o)=>{const u=o[0],a=o.slice(1),l=s.entry(u);if(l===void 0)throw new Error(`Invalid field lookup ${u}`);if(l instanceof L0e.StructSpaceField&&a.length>0){const c=i(l.fieldSpace,a);return{...c,joinPath:[{...l.joinPathElement,name:u},...c.joinPath]}}else if(l instanceof rat.SpaceField){if(a.length!==0)throw new Error(`${u} cannot contain a ${a.join(".")}`);const c=l.fieldDef();if(c)return{fs:s,def:c,joinPath:[]};throw new Error("No field def")}else throw new Error("expected a field def or struct")};for(const s of(0,Zut.exprWalk)(e))if(s.node==="field"){const o=i(t,s.path),u=o.def;if((0,RE.isAtomic)(u)&&!(0,RE.isJoined)(u))if((0,RE.hasExpression)(u)){const a=sk(o.fs,u.e);r.push(...a.map(l=>[...o.joinPath,...l]))}else r.push(o.joinPath)}else if(s.node==="source-reference")if(s.path){const o=i(t,s.path);r.push(o.joinPath)}else r.push([]);return r}function ok(t,e){const r=[];for(const i of e){let s=0;for(let l=0;l<t.length&&l<i.length&&t[l].name===i[l].name;l++)s=l+1;const o=t.slice(s),u=i.slice(s),a=[...o.map(l=>({...l,reverse:!0})),...u.map(l=>({...l,reverse:!1}))];r.push(a)}return r}function uk(t,e){for(const r of e)for(const i of r){if(i.joinType==="cross")return{code:"aggregate-traverses-join-cross",message:`Cannot compute \`${t}\` across \`join_cross\` relationship \`${i.name}\``};if(i.joinElementType==="array"&&!i.reverse)return{code:"aggregate-traverses-repeated-relationship",message:`Cannot compute \`${t}\` across repeated relationship \`${i.name}\``};if(i.joinType==="many"&&!i.reverse)return{code:"aggregate-traverses-join-many",message:`Cannot compute \`${t}\` across \`join_many\` relationship \`${i.name}\``}}}function uat(t,e,r,i){if(e.length===0)return t;let s=e[0];for(const m of e.slice(1))for(let g=0;g<s.length;g++){const y=s[g],E=m[g];if(y.name!==E.name){s=s.slice(0,g);break}}const o=ok(s,e),u=uk(i,o),a=s.slice().reverse().findIndex(m=>m.joinType==="many"||m.joinType==="cross"),l=a===-1?0:s.length-a,c=s.slice(0,l),f=ok(c,e),x=uk(i,f),h=s.length>0?s.map(m=>m.name).join("."):"source",p=c.length>0?c.map(m=>m.name).join("."):"source";if(u)return"Aggregated dimensional expression contains multiple join paths; rewrite, for example `sum(first_join.field + second_join.field)` as `first_join.field.sum() + second_join.field.sum()`";{const m=r instanceof tat.FieldReference?`${r.refString}.${i}()`:r instanceof iat.ExprIdReference?`${r.fieldReference.refString}.${i}()`:`${h}.${i}(${r.code})`,g=`${p}.${i}(${r.code})`;let y=`${t}; use \`${m}\``;return x===void 0&&p!==h&&(y+=` or \`${g}\` to get a result weighted with respect to \`${p}\``),y}}var iT={};Object.defineProperty(iT,"__esModule",{value:!0}),iT.ExprAlternationTree=void 0;const $0e=Yt,z2=ht,aat=Ru;function ak(t){const e=t.atExpr();switch(e.atNodeType()){case z2.ATNodeType.And:case z2.ATNodeType.Partial:return;case z2.ATNodeType.Or:{if(e instanceof B0e){const r=ak(e.left);if(r){const i=ak(e.right);if(i)return[...r,...i]}}return}default:return e.granular()?void 0:[e]}}class B0e extends z2.ExpressionDef{constructor(e,r,i){super({left:e,right:i}),this.left=e,this.op=r,this.right=i,this.elementType="alternation",this.elementType=`${r}alternation${r}`}equalityList(){return this.inList===void 0&&(this.inList=ak(this)||[]),this.inList}apply(e,r,i,s){if((0,aat.isEquality)(r)){const a=this.equalityList();if(a.length>0&&(r==="="||r==="!=")){const l=i.getExpression(e),c=a.map(f=>f.getExpression(e));return(0,$0e.computedExprValue)({dataType:{type:"boolean"},value:{node:"in",not:r==="!=",kids:{e:l.value,oneOf:c.map(f=>f.value)}},from:[l,...c]})}a.length===0&&s&&this.logWarning("or-choices-only",`Only | seperated values are legal when used with ${r} operator`)}const o=this.left.apply(e,r,i),u=this.right.apply(e,r,i);return(0,$0e.computedExprValue)({dataType:{type:"boolean"},value:{node:this.op==="&"?"and":"or",kids:{left:o.value,right:u.value}},from:[o,u]})}requestExpression(e){}getExpression(e){return this.loggedErrorExpr("alternation-as-value","Alternation tree has no value")}atNodeType(){return this.op==="|"?z2.ATNodeType.Or:z2.ATNodeType.And}}iT.ExprAlternationTree=B0e;var W2={};Object.defineProperty(W2,"__esModule",{value:!0}),W2.ExprAsymmetric=void 0;const lat=E0;class cat extends lat.ExprAggregateFunction{constructor(e,r,i,s){super(e,r,s),this.func=e,this.expr=r,this.source=i,this.has({source:i})}isSymmetricFunction(){return!1}returns(e){return e}defaultFieldName(){if(this.source&&this.expr===void 0){const e=this.source.nameString;switch(this.func){case"sum":return`total_${e}`;case"avg":return`avg_${e}`}}}}W2.ExprAsymmetric=cat;var sT={};Object.defineProperty(sT,"__esModule",{value:!0}),sT.ExprAvg=void 0;const fat=W2;class xat extends fat.ExprAsymmetric{constructor(e,r,i){super("avg",e,r,i),this.has({source:r})}}sT.ExprAvg=xat;var oT={};Object.defineProperty(oT,"__esModule",{value:!0}),oT.ExprCast=void 0;const dat=Es,hat=Yt,pat=ht;class mat extends pat.ExpressionDef{constructor(e,r,i=!1){super({expr:e}),this.expr=e,this.castType=r,this.safe=i,this.elementType="cast"}getExpression(e){const r=this.expr.getExpression(e);let i={type:"error"};if(typeof this.castType=="string")i={type:this.castType};else{const s=e.dialectObj();s&&(s.validateTypeName(this.castType.raw)?i=s.sqlTypeToMalloyType(this.castType.raw):this.logError("invalid-sql-native-type",`Cast type \`${this.castType.raw}\` is invalid for ${s.name} dialect`),this.safe&&!s.supportsSafeCast&&this.logError("dialect-cast-unsafe-only",`The SQL dialect '${e.dialectName()}' does not supply a safe cast operator`))}return(0,hat.computedExprValue)({dataType:i,value:(0,dat.castTo)(this.castType,r.value,r.type,this.safe),from:[r]})}}oT.ExprCast=mat;var uT={},gat=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),yat=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),Eat=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&gat(e,t,r);return yat(e,t),e};Object.defineProperty(uT,"__esModule",{value:!0}),uT.ExprCoalesce=void 0;const k0e=Gi,M0e=Eat(nn),Aat=ht;class _at extends Aat.ExpressionDef{constructor(e,r){super({expr:e,altExpr:r}),this.expr=e,this.altExpr=r,this.elementType="coalesce expression",this.legalChildTypes=M0e.anyAtomicT}getExpression(e){const r=this.expr.getExpression(e),i=this.altExpr.getExpression(e);return r.type==="null"?i:(M0e.typeEq(r,i)||this.logError("mismatched-coalesce-types",`Mismatched types for coalesce (${r.type}, ${i.type})`),{...r.type==="error"?i:r,expressionType:(0,k0e.maxExpressionType)(r.expressionType,i.expressionType),value:{node:"coalesce",kids:{left:r.value,right:i.value}},evalSpace:(0,k0e.mergeEvalSpaces)(r.evalSpace,i.evalSpace)})}}uT.ExprCoalesce=_at;var aT={};Object.defineProperty(aT,"__esModule",{value:!0}),aT.ExprCount=void 0;const vat=dt,Cat=E0;class Sat extends Cat.ExprAggregateFunction{constructor(e){super("count"),this.source=e,this.elementType="count",this.has({source:e})}defaultFieldName(){if(this.source)return"count_"+this.source.nameString}returns(e){return{type:"number",numberType:"integer",evalSpace:e.evalSpace,expressionType:"aggregate",value:e.value,compositeFieldUsage:e.compositeFieldUsage}}getExpression(e){const r={node:"aggregate",function:"count",e:{node:""}};return this.source&&(r.structPath=this.source.path),{type:"number",numberType:"integer",expressionType:"aggregate",value:r,evalSpace:"output",compositeFieldUsage:(0,vat.emptyCompositeFieldUsage)()}}}aT.ExprCount=Sat;var lT={},bat=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),Tat=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),Rat=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&bat(e,t,r);return Tat(e,t),e};Object.defineProperty(lT,"__esModule",{value:!0}),lT.ExprCountDistinct=void 0;const cT=Rat(nn),Dat=E0;class Oat extends Dat.ExprAggregateFunction{constructor(e){super("distinct",e),this.legalChildTypes=[cT.numberT,cT.stringT,cT.dateT,cT.timestampT]}returns(e){return{type:"number",numberType:"integer",evalSpace:e.evalSpace,expressionType:"aggregate",value:e.value,compositeFieldUsage:e.compositeFieldUsage}}}lT.ExprCountDistinct=Oat;var fT={},nf={};Object.defineProperty(nf,"__esModule",{value:!0}),nf.Limit=void 0;const Fat=Ze,wat=zn;class Nat extends Fat.MalloyElement{constructor(e){super(),this.limit=e,this.elementType="limit",this.queryRefinementStage=wat.LegalRefinementStage.Tail,this.forceQueryClass=void 0}}nf.Limit=Nat;var G2={};Object.defineProperty(G2,"__esModule",{value:!0}),G2.PartitionBy=void 0;const Lat=Ze;class Iat extends Lat.ListOf{constructor(e){super(e),this.partitionFields=e,this.elementType="partition_by"}}G2.PartitionBy=Iat;var DE={},rf={};Object.defineProperty(rf,"__esModule",{value:!0}),rf.FieldName=void 0;const $at=Ze;class Bat extends $at.MalloyElement{constructor(e){super(),this.name=e,this.elementType="fieldName"}get refString(){return this.name}toString(){return this.refString}getField(e){return e.lookup([this])}}rf.FieldName=Bat;var kat=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),Mat=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),Pat=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&kat(e,t,r);return Mat(e,t),e};Object.defineProperty(DE,"__esModule",{value:!0}),DE.ExprFunc=void 0;const Or=et,Uat=Hs,jat=Cd,qat=Yt,Hat=ht,Qat=rf,P0e=kt,U0e=Pat(nn),zat=dt;class Wat extends Hat.ExpressionDef{constructor(e,r,i,s,o){super({args:r}),this.name=e,this.args=r,this.isRaw=i,this.rawType=s,this.source=o,this.elementType="function call()",this.has({source:o})}canSupportPartitionBy(){return!0}canSupportOrderBy(){return!0}canSupportLimit(){return!0}getExpression(e){return this.getPropsExpression(e)}findFunctionDef(e){var r,i,s;const o=this.name.toLowerCase(),u=e?(i=(r=this.getDialectNamespace(e))===null||r===void 0?void 0:r.getEntry(o))===null||i===void 0?void 0:i.entry:void 0,a=u??((s=this.modelEntry(o))===null||s===void 0?void 0:s.entry);return a===void 0?(this.logError("function-not-found",`Unknown function '${this.name}'. Use '${this.name}!(...)' to call a SQL function directly.`),{found:void 0,error:"unknown function"}):a.type!=="function"?(this.logError("call-of-non-function",`'${this.name}' (with type ${a.type}) is not a function`),{found:void 0,error:"called non function"}):(a.name!==this.name&&this.logWarning("case-insensitive-function",`Case insensitivity for function names is deprecated, use '${a.name}' instead`),{found:a,error:void 0})}getPropsExpression(e,r){var i,s,o,u;const a=this.args.map(B=>B.getExpression(e));if(this.isRaw){const B=[`${this.name}(`];a.forEach((U,V)=>{V!==0&&B.push(","),B.push(U.value)}),B.push(")");const D=(i=a[0])!==null&&i!==void 0?i:{type:"number"},$=this.rawType?{type:this.rawType}:D;return(0,qat.computedExprValue)({dataType:$,value:(0,P0e.composeSQLExpr)(B),from:a})}const l=(s=e.dialectObj())===null||s===void 0?void 0:s.name,{found:c,error:f}=this.findFunctionDef(l);if(c===void 0)return(0,Uat.errorFor)(f);let x,h=(o=this.source)===null||o===void 0?void 0:o.path;if(this.source){const D=this.source.getField(e).found;if(D){const $=D.typeDesc();if((0,Or.isAtomicFieldType)($.type))x={...U0e.atomicDef($),expressionType:$.expressionType,value:{node:"field",path:this.source.path},evalSpace:$.evalSpace,compositeFieldUsage:$.compositeFieldUsage},h=this.source.path.slice(0,-1);else if(!(D instanceof jat.StructSpaceFieldBase))return this.loggedErrorExpr("invalid-aggregate-source",`Aggregate source cannot be a ${$.type}`)}else this.loggedErrorExpr("aggregate-source-not-found",`Reference to undefined value ${this.source.refString}`)}const p=[...x?[x]:[],...a],m=Gat(c,p);if(m===void 0)return this.loggedErrorExpr("no-matching-function-overload",`No matching overload for function ${this.name}(${p.map(B=>B.type).join(", ")})`);const{overload:g,expressionTypeErrors:y,evalSpaceErrors:E,nullabilityErrors:A,returnType:_}=m;for(const B of y){const D=B.argIndex-(x?1:0),$=(0,Or.expressionIsScalar)(B.maxExpressionType)?"scalar":"scalar or aggregate";this.args[D].logError("invalid-function-argument-expression-type",`Parameter ${B.argIndex+1} ('${B.param.name}') of ${this.name} must be ${$}, but received ${B.actualExpressionType}`)}for(const B of E){const D=B.argIndex-(x?1:0),$=B.maxEvalSpace==="literal"?"literal":B.maxEvalSpace==="constant"?"literal or constant":"literal, constant or output";this.args[D].logError("invalid-function-argument-evaluation-space",`Parameter ${B.argIndex+1} ('${B.param.name}') of ${this.name} must be ${$}, but received ${B.actualEvalSpace}`)}for(const B of A){const D=B.argIndex-(x?1:0);this.args[D].logError("literal-null-function-argument",`Parameter ${B.argIndex+1} ('${B.param.name}') of ${this.name} must not be a literal null`)}m.returnTypeError&&this.logError(m.returnTypeError.code,m.returnTypeError.parameters);const v=g.returnType,C=(0,Or.maxOfExpressionTypes)([(u=v.expressionType)!==null&&u!==void 0?u:"scalar",...p.map(B=>B.expressionType)]);if(!(0,Or.expressionIsAggregate)(g.returnType.expressionType)&&this.source!==void 0)return this.loggedErrorExpr("non-aggregate-function-with-source",`Cannot call function ${this.name}(${p.map(B=>B.type).join(", ")}) with source`);const S={node:"function_call",overload:g,name:this.name,kids:{args:p.map(B=>B.value)},expressionType:C,structPath:h};let b=S;if(r!=null&&r.orderBys&&r.orderBys.length>0){const B=(0,Or.expressionIsAnalytic)(g.returnType.expressionType);if(B||this.inExperiment("aggregate_order_by",!0)||r.orderBys[0].logError("aggregate-order-by-experiment-not-enabled","Enable experiment `aggregate_order_by` to use `order_by` with an aggregate function"),g.supportsOrderBy||B){const D=g.supportsOrderBy!=="only_default",$=r.orderBys.flatMap(U=>B?U.getAnalyticOrderBy(e):U.getAggregateOrderBy(e,D));S.kids.orderBy=$}else r.orderBys[0].logError("function-does-not-support-order-by",`Function \`${this.name}\` does not support \`order_by\``)}if((r==null?void 0:r.limit)!==void 0&&(g.supportsLimit?S.limit=r.limit.limit:this.logError("function-does-not-support-limit",`Function ${this.name} does not support limit`)),r!=null&&r.partitionBys&&r.partitionBys.length>0){const B=[];for(const D of r.partitionBys)for(const $ of D.partitionFields){const U=$.getField(e);U.found===void 0?$.logError("partition-by-not-found",`${$.refString} is not defined`):(0,Or.expressionIsAnalytic)(U.found.typeDesc().expressionType)||(0,Or.expressionIsUngroupedAggregate)(U.found.typeDesc().expressionType)?$.logError("non-scalar-or-aggregate-partition-by","Partition expression must be scalar or aggregate"):B.push($.nameString)}S.partitionBy=B}if(["sql_number","sql_string","sql_date","sql_timestamp","sql_boolean"].includes(c.name)){if(!this.inExperiment("sql_functions",!0))return this.loggedErrorExpr("sql-functions-experiment-not-enabled",`Cannot use sql_function \`${c.name}\`; use \`sql_functions\` experiment to enable this behavior`);const B=p[0].value;if(B.node!=="stringLiteral")this.logError("invalid-sql-function-argument",`Invalid string literal for \`${c.name}\``);else{const D=B.literal,$=Vat(D),U=$.filter(Q=>Q.type==="interpolation"&&Q.name.includes(".")).map(Q=>Q.type==="interpolation"?`\${${Q.name}}`:`\${${Q.value}}`);if(U.length>0){const Q=U.length===1?`'.' paths are not yet supported in sql interpolations, found ${U.at(0)}`:`'.' paths are not yet supported in sql interpolations, found (${U.join(", ")})`;return this.loggedErrorExpr("unsupported-sql-function-interpolation",Q)}const V=[];for(const Q of $)if(Q.type==="string")V.push(Q.value);else if(Q.name==="TABLE")V.push({node:"source-reference"});else{const X=new Qat.FieldName(Q.name);this.has({name:X});const xe=e.lookup([X]);if(xe.found===void 0)return this.loggedErrorExpr("sql-function-interpolation-not-found",`Invalid interpolation: ${xe.error.message}`);if(xe.found.typeDesc().type==="filter expression")return this.loggedErrorExpr("filter-expression-error","Filter expressions cannot be used in sql_ functions");xe.found.refType==="parameter"?V.push({node:"parameter",path:[Q.name]}):V.push({node:"field",path:[Q.name]})}b=(0,P0e.composeSQLExpr)(V)}}const R=(0,Or.mergeEvalSpaces)(...p.map(B=>B.evalSpace)),O=R==="constant"?"constant":(0,Or.expressionIsScalar)(C)?R:"output";return{...(0,Or.isAtomic)(_)?U0e.atomicDef(_):_,expressionType:C,value:b,evalSpace:O,compositeFieldUsage:(0,zat.mergeCompositeFieldUsage)(...p.map(B=>B.compositeFieldUsage))}}}DE.ExprFunc=Wat;function Gat(t,e){var r;for(const i of t.overloads){const s=new Map;let o=0,u=!0,a=!1;const l=[],c=[],f=[];for(let p=0;p<e.length;p++){const m=e[p],g=i.params[o];if(g===void 0){u=!1;break}if(!g.allowedTypes.some(E=>{var A;const{dataTypeMatch:_,genericsSet:v}=V2(s,(A=i.genericTypes)!==null&&A!==void 0?A:[],m,E);for(const C of v)s.set(C.name,C.type);return E.expressionType&&((0,Or.isExpressionTypeLEQ)(m.expressionType,E.expressionType)||l.push({argIndex:p,maxExpressionType:E.expressionType,actualExpressionType:m.expressionType,param:g})),(E.evalSpace==="literal"&&m.evalSpace!=="literal"||E.evalSpace==="constant"&&(m.evalSpace==="input"||m.evalSpace==="output")||(0,Or.expressionIsAnalytic)(i.returnType.expressionType)&&m.evalSpace==="input")&&c.push({argIndex:p,param:g,maxEvalSpace:E.evalSpace,actualEvalSpace:m.evalSpace}),E.evalSpace==="literal"&&m.type==="null"&&f.push({argIndex:p,param:g}),_})){u=!1;break}g.isVariadic?p===e.length-1&&(a=!0):o++}if(!a&&(o!==e.length||o!==i.params.length))continue;const x=xT(i.returnType,s),h=(r=x.returnType)!==null&&r!==void 0?r:{type:"number"};if(u)return{overload:i,expressionTypeErrors:l,evalSpaceErrors:c,nullabilityErrors:f,returnTypeError:x.error,returnType:h}}}function Vat(t){const e=[];let r=t;for(;r.length;){const i=r.indexOf("${");if(i===-1){e.push({type:"string",value:r});break}else{const s=r.slice(i).indexOf("}");if(s===-1){e.push({type:"string",value:r});break}i>0&&e.push({type:"string",value:r.slice(0,i)}),e.push({type:"interpolation",name:r.slice(i+2,s+i)}),r=r.slice(s+i+1)}}return e}function V2(t,e,r,i){var s,o,u,a;if(Or.TD.eq(i,r)||i.type==="any"||i.type!=="generic"&&(r.type==="null"||r.type==="error"))return{dataTypeMatch:!0,genericsSet:[]};if(i.type==="array"&&r.type==="array"){if((0,Or.isBasicArray)(r))return(0,Or.isRepeatedRecordFunctionParam)(i)?{dataTypeMatch:!1,genericsSet:[]}:V2(t,e,r.elementTypeDef,i.elementTypeDef);if((0,Or.isRepeatedRecordFunctionParam)(i)){const l={type:"record",fields:i.fields},c={type:"record",fields:r.fields};return V2(t,e,c,l)}else return{dataTypeMatch:!1,genericsSet:[]}}else if(i.type==="record"&&r.type==="record"){const l=[],c=new Map;for(const f of i.fields)c.set((s=f.as)!==null&&s!==void 0?s:f.name,f);for(const f of r.fields){const x=c.get((o=f.as)!==null&&o!==void 0?o:f.name);if(x===void 0)return{dataTypeMatch:!1,genericsSet:[]};const h=V2(new Map([...t.entries(),...l.map(p=>[p.name,p.type])]),e,f,x);l.push(...h.genericsSet)}return{dataTypeMatch:!0,genericsSet:l}}else if(i.type==="generic"){const l=t.get(i.generic);if(l!==void 0&&l.type!=="null"&&l.type!=="error")return V2(t,e,r,l);const c=(a=(u=e.find(f=>f.name===i.generic))===null||u===void 0?void 0:u.acceptibleTypes)!==null&&a!==void 0?a:[];for(const f of c){const x=V2(t,e,r,f);if(x.dataTypeMatch){if(!(0,Or.isAtomic)(r)&&r.type!=="null")continue;const h={name:i.generic,type:r};return{dataTypeMatch:!0,genericsSet:[...x.genericsSet,h]}}}}return{dataTypeMatch:!1,genericsSet:[]}}function xT(t,e){switch(t.type){case"array":{if("fields"in t){const s=t.fields.map(o=>{const u=xT(o,e);return{...o,...u}});return{error:void 0,returnType:{type:"array",elementTypeDef:t.elementTypeDef,fields:s}}}const r=xT(t.elementTypeDef,e);if(r.error)return r;const i=r.returnType;return i.type==="record"?{error:void 0,returnType:{type:"array",elementTypeDef:{type:"record_element"},fields:i.fields}}:(0,Or.isAtomic)(i)?{error:void 0,returnType:{type:"array",elementTypeDef:i}}:{error:{code:"invalid-resolved-type-for-array",parameters:"Invalid resolved type for array; cannot be non-atomic"},returnType:void 0}}case"record":return{error:void 0,returnType:{type:"record",fields:t.fields.map(i=>{const s=xT(i,e);return{...i,...s}})}};case"generic":{const r=e.get(t.generic);return r===void 0?{error:{code:"generic-not-resolved",parameters:`Generic ${t.generic} in return type could not be resolved`},returnType:void 0}:{error:void 0,returnType:r}}default:return{error:void 0,returnType:t}}}var Yat=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),Kat=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),Jat=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&Yat(e,t,r);return Kat(e,t),e};Object.defineProperty(fT,"__esModule",{value:!0}),fT.ExprProps=void 0;const Xat=et,Zat=Hs,elt=Jat(nn),tlt=tf,nlt=nf,rlt=G2,ilt=ht,slt=DE,olt=dt;class ult extends ilt.ExpressionDef{constructor(e,r){super({expr:e,statements:r}),this.expr=e,this.statements=r,this.elementType="expression with props",this.legalChildTypes=elt.anyAtomicT}getFilteredExpression(e,r,i){if(i.length>0){if(!this.expr.supportsWhere(r))return this.expr.logError("filter-of-non-aggregate","Filtered expression requires an aggregate computation"),r;const s=[];for(const o of i){const u=o.getFilterList(e);if(u.find(a=>(0,Xat.expressionIsCalculation)(a.expressionType)))return o.logError("aggregate-filter-expression-not-scalar","Cannot filter an expresion with an aggregate or analytical computation"),r;s.push(...u)}return this.typeCheck(this.expr,{...r,expressionType:"scalar"})?{...r,compositeFieldUsage:(0,olt.mergeCompositeFieldUsage)(r.compositeFieldUsage,...s.map(o=>o.compositeFieldUsage)),value:{node:"filteredExpr",kids:{e:r.value,filterList:s}}}:(this.expr.logError("filter-of-non-aggregate",`Cannot filter '${r.expressionType}' data`),(0,Zat.errorFor)("cannot filter type"))}return r}getExpression(e){const r=[];let i;const s=[],o=[];for(const a of this.statements)a instanceof rlt.PartitionBy?this.expr.canSupportPartitionBy()?r.push(a):a.logError("partition-by-of-non-window-function","`partition_by` is not supported for this kind of expression"):a instanceof nlt.Limit?i?a.logError("expression-limit-already-specified","limit already specified"):this.expr.canSupportLimit()?i=a:a.logError("limit-of-non-aggregate-function","`limit` is not supported for this kind of expression"):a instanceof tlt.FunctionOrdering?this.expr.canSupportOrderBy()?s.push(a):a.logError("order-by-of-non-aggregate-function","`order_by` is not supported for this kind of expression"):o.push(a);const u=this.expr instanceof slt.ExprFunc?this.expr.getPropsExpression(e,{partitionBys:r,limit:i,orderBys:s}):this.expr.getExpression(e);return this.getFilteredExpression(e,u,o)}}fT.ExprProps=ult;var dT={},alt=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),llt=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),clt=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&alt(e,t,r);return llt(e,t),e};Object.defineProperty(dT,"__esModule",{value:!0}),dT.ExprLogicalOp=void 0;const flt=bE,j0e=clt(nn);class xlt extends flt.BinaryBoolean{constructor(){super(...arguments),this.elementType="logical operator",this.legalChildTypes=[j0e.boolT,j0e.aggregateBoolT]}}dT.ExprLogicalOp=xlt;var hT={},dlt=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),hlt=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),plt=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&dlt(e,t,r);return hlt(e,t),e};Object.defineProperty(hT,"__esModule",{value:!0}),hT.ExprMax=void 0;const pT=plt(nn),mlt=E0;class glt extends mlt.ExprAggregateFunction{constructor(e){super("max",e),this.legalChildTypes=[pT.numberT,pT.stringT,pT.dateT,pT.timestampT]}returns(e){return e}}hT.ExprMax=glt;var mT={},ylt=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),Elt=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),Alt=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&ylt(e,t,r);return Elt(e,t),e};Object.defineProperty(mT,"__esModule",{value:!0}),mT.ExprMin=void 0;const gT=Alt(nn),_lt=E0;class vlt extends _lt.ExprAggregateFunction{constructor(e){super("min",e),this.legalChildTypes=[gT.numberT,gT.stringT,gT.dateT,gT.timestampT]}returns(e){return e}}mT.ExprMin=vlt;var yT={},Clt=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),Slt=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),blt=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&Clt(e,t,r);return Slt(e,t),e};Object.defineProperty(yT,"__esModule",{value:!0}),yT.ExprMinus=void 0;const Tlt=Hs,q0e=blt(nn),Rlt=ht;class Dlt extends Rlt.ExpressionDef{constructor(e){super({expr:e}),this.expr=e,this.elementType="unary minus",this.legalChildTypes=[q0e.numberT]}getExpression(e){const r=this.expr.getExpression(e);return q0e.typeIn(r,this.legalChildTypes)?{...r,type:"number",value:{node:"unary-",e:r.value}}:(0,Tlt.errorFor)("negate requires number")}}yT.ExprMinus=Dlt;var ET={};Object.defineProperty(ET,"__esModule",{value:!0}),ET.ExprMulDiv=void 0;const Olt=H2;class Flt extends Olt.BinaryNumeric{constructor(){super(...arguments),this.elementType="*/%"}}ET.ExprMulDiv=Flt;var AT={},OE={};Object.defineProperty(OE,"__esModule",{value:!0}),OE.Unary=void 0;const wlt=ht;class Nlt extends wlt.ExpressionDef{constructor(e){super({expr:e}),this.expr=e}}OE.Unary=Nlt;var Llt=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),Ilt=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),$lt=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&Llt(e,t,r);return Ilt(e,t),e};Object.defineProperty(AT,"__esModule",{value:!0}),AT.ExprNot=void 0;const lk=$lt(nn),Blt=OE;class klt extends Blt.Unary{constructor(e){super(e),this.elementType="not",this.legalChildTypes=[lk.boolT,lk.nullT]}getExpression(e){var r;const i=this.expr.getExpression(e);!((r=e.dialectObj())===null||r===void 0)&&r.booleanAsNumbers&&this.legalChildTypes.find(o=>o.type==="number")===void 0&&this.legalChildTypes.push(lk.numberT);const s=this.typeCheck(this.expr,i);return{...i,type:"boolean",value:{node:"not",e:s?i.value:{node:"false"}}}}}AT.ExprNot=klt;var _T={};Object.defineProperty(_T,"__esModule",{value:!0}),_T.ExprNow=void 0;const Mlt=ht,Plt=dt;class Ult extends Mlt.ExpressionDef{constructor(){super(...arguments),this.elementType="timestamp"}getExpression(e){return{type:"timestamp",expressionType:"scalar",evalSpace:"constant",value:{node:"now",typeDef:{type:"timestamp"}},compositeFieldUsage:(0,Plt.emptyCompositeFieldUsage)()}}}_T.ExprNow=Ult;var sf={};Object.defineProperty(sf,"__esModule",{value:!0}),sf.ExprIsNull=sf.PartialIsNull=sf.ExprNULL=void 0;const jlt=Yt,vT=ht;function ck(t,e,r){const i=r.getExpression(t);return i.type="boolean",i.value={node:e==="="?"is-null":"is-not-null",e:i.value},i}class qlt extends vT.ExpressionDef{constructor(){super(...arguments),this.elementType="NULL"}getExpression(){return(0,jlt.literalExprValue)({dataType:{type:"null"},value:{node:"null"}})}apply(e,r,i){return r==="!="||r==="="?ck(e,r,i):super.apply(e,r,i,!0)}}sf.ExprNULL=qlt;class Hlt extends vT.ExpressionDef{constructor(e){super(),this.op=e,this.elementType="<=> NULL"}apply(e,r,i){return ck(e,this.op,i)}requestExpression(e){}getExpression(e){return this.loggedErrorExpr("partial-as-value","Partial null check does not have a value")}atNodeType(){return vT.ATNodeType.Partial}}sf.PartialIsNull=Hlt;class Qlt extends vT.ExpressionDef{constructor(e,r){super(),this.expr=e,this.op=r,this.elementType="is null",this.has({expr:e})}getExpression(e){return ck(e,this.op,this.expr)}}sf.ExprIsNull=Qlt;var CT={};Object.defineProperty(CT,"__esModule",{value:!0}),CT.ExprNumber=void 0;const zlt=Yt,Wlt=ht;class Glt extends Wlt.ExpressionDef{constructor(e){super(),this.n=e,this.elementType="numeric literal"}getExpression(e){return this.constantExpression()}constantExpression(){const e=Number(this.n),r=Number.isNaN(e)?{type:"number"}:{type:"number",numberType:Number.isInteger(e)?"integer":"float"};return(0,zlt.literalExprValue)({dataType:r,value:{node:"numberLiteral",literal:this.n}})}}CT.ExprNumber=Glt;var ST={};Object.defineProperty(ST,"__esModule",{value:!0}),ST.ExprParens=void 0;const fk=ht;class Vlt extends fk.ExpressionDef{constructor(e){super({expr:e}),this.expr=e,this.elementType="(expression)"}requestExpression(e){return this.expr.requestExpression(e)}getExpression(e){const r=this.expr.getExpression(e);return{...r,value:{node:"()",e:r.value}}}apply(e,r,i,s){return this.expr.atNodeType()===fk.ATNodeType.Or?this.expr.apply(e,r,i,s):(0,fk.applyBinary)(e,i,r,this)}atNodeType(){return this.expr.atNodeType()}atExpr(){return this.expr}}ST.ExprParens=Vlt;var bT={};Object.defineProperty(bT,"__esModule",{value:!0}),bT.ExprFilterExpression=void 0;const Ylt=ht;class Klt extends Ylt.ExpressionDef{constructor(e){super(),this.filterText=e,this.elementType="filter expression literal"}getExpression(){return{type:"filter expression",value:{node:"filterLiteral",filterSrc:this.filterText},expressionType:"scalar",evalSpace:"constant",compositeFieldUsage:{fields:[],joinedUsage:{}}}}}bT.ExprFilterExpression=Klt;var TT={};Object.defineProperty(TT,"__esModule",{value:!0}),TT.ExprRegEx=void 0;const Jlt=Yt,Xlt=ht;class Zlt extends Xlt.ExpressionDef{constructor(e){super(),this.regex=e,this.elementType="regular expression literal"}getExpression(){return(0,Jlt.literalExprValue)({dataType:{type:"regular expression"},value:{node:"regexpLiteral",literal:this.regex}})}}TT.ExprRegEx=Zlt;var RT={};Object.defineProperty(RT,"__esModule",{value:!0}),RT.ExprString=void 0;const e0t=ht,t0t=Yt;class n0t extends e0t.ExpressionDef{constructor(e){super(),this.elementType="string literal",this.value=e}getExpression(e){return(0,t0t.literalExprValue)({dataType:{type:"string"},value:{node:"stringLiteral",literal:this.value}})}}RT.ExprString=n0t;var DT={};Object.defineProperty(DT,"__esModule",{value:!0}),DT.ExprSum=void 0;const r0t=W2;class i0t extends r0t.ExprAsymmetric{constructor(e,r,i){super("sum",e,r,i),this.has({source:r})}}DT.ExprSum=i0t;var OT={};Object.defineProperty(OT,"__esModule",{value:!0}),OT.ExprTimeExtract=void 0;const A0=et,FT=Yt,xk=ht,s0t=ef;class FE extends xk.ExpressionDef{static extractor(e){const r=FE.pluralMap[e];if(r)return r;if((0,A0.isExtractUnit)(e))return e}constructor(e,r){super({args:r}),this.extractText=e,this.args=r,this.elementType="timeExtract"}getExpression(e){const r=FE.extractor(this.extractText);if(r){if(this.args.length!==1)return this.loggedErrorExpr("too-many-arguments-for-time-extraction",`Extraction function ${r} requires one argument`);const i=this.args[0];if(i instanceof s0t.Range){let s=i.first.getExpression(e),o=i.last.getExpression(e);if(s.type==="error"||o.type==="error")return(0,FT.computedErrorExprValue)({dataType:{type:"number"},error:"extract from error",from:[s,o]});if(!(0,A0.isTemporalType)(s.type))return i.first.loggedErrorExpr("invalid-type-for-time-extraction",`Can't extract ${r} from '${s.type}'`);if(!(0,A0.isTemporalType)(o.type))return i.last.loggedErrorExpr("invalid-type-for-time-extraction",`Cannot extract ${r} from '${o.type}'`);let u=s.type;if(!A0.TD.eq(s,o)){let a=!0;if(u="timestamp",s.type==="date"){const l=(0,xk.getMorphicValue)(s,"timestamp");l&&(s=l,a=!1)}else{const l=(0,xk.getMorphicValue)(o,"timestamp");l&&(o=l,a=!1)}if(a)return i.first.loggedErrorExpr("invalid-types-for-time-measurement",`Cannot measure from ${s.type} to ${o.type}`)}return["week","month","quarter","year"].includes(r)?this.loggedErrorExpr("invalid-timeframe-for-time-measurement",`Cannot measure interval using '${r}'`):(0,A0.isTimestampUnit)(r)?(0,FT.computedExprValue)({dataType:{type:"number",numberType:"integer"},value:{node:"timeDiff",units:r,kids:{left:(0,A0.mkTemporal)(s.value,u),right:(0,A0.mkTemporal)(o.value,u)}},from:[s,o]}):this.loggedErrorExpr("invalid-time-extraction-unit",`Cannot extract ${r} from a range`)}else{const s=i.getExpression(e);return(0,A0.isTemporalType)(s.type)?(0,FT.computedExprValue)({dataType:{type:"number",numberType:"integer"},value:{node:"extract",e:(0,A0.mkTemporal)(s.value,s.type),units:r},from:[s]}):(s.type!=="error"&&this.logError("unsupported-type-for-time-extraction",`${this.extractText}() requires time type, not '${s.type}'`),(0,FT.computedErrorExprValue)({dataType:{type:"number",numberType:"integer"},error:`${this.extractText} bad type ${s.type}`,from:[s]}))}}throw this.internalError(`Illegal extraction unit '${this.extractText}'`)}}OT.ExprTimeExtract=FE,FE.pluralMap={years:"year",quarters:"quarter",months:"month",weeks:"week",days:"day",hours:"hour",minutes:"minute",seconds:"second"};var wT={},Du={},NT={};Object.defineProperty(NT,"__esModule",{value:!0}),NT.QueryInputSpace=void 0;const o0t=ys,u0t=w2;class a0t extends u0t.RefinedSpace{constructor(e,r,i){super(e),this.queryOutput=r,this._isProtectedAccessSpace=i,this.extendList=[]}extendSource(e){this.pushFields(e),e instanceof o0t.Join?this.extendList.push(e.name.refString):this.extendList.push(e.defineName)}isQueryFieldSpace(){return!0}outputSpace(){return this.queryOutput}inputSpace(){return this}isProtectedAccessSpace(){return this._isProtectedAccessSpace}}NT.QueryInputSpace=a0t;var l0t=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),c0t=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),f0t=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&l0t(e,t,r);return c0t(e,t),e};Object.defineProperty(Du,"__esModule",{value:!0}),Du.ReduceFieldSpace=Du.QuerySpace=Du.QueryOperationSpace=void 0;const LT=f0t(et),dk=Vc,H0e=rf,Q0e=zr,x0t=_t,d0t=w2,h0t=cE,p0t=Wr,m0t=NT,Ha=dt,g0t=Cd;class z0e extends d0t.RefinedSpace{get compositeFieldUsage(){if(this._compositeFieldUsage===void 0)throw new Error("Composite field usage accessed before computed");return this._compositeFieldUsage}constructor(e,r,i,s){super(e.emptyStructDef()),this.queryInputSpace=e,this.nestParent=i,this.astEl=s,this.expandedWild={},this.compositeFieldUsers=[],this._compositeFieldUsage=void 0,this.exprSpace=new m0t.QueryInputSpace(e.structDef(),this,e.isProtectedAccessSpace()),r&&this.addRefineFromFields(r)}logError(e,r,i){return this.astEl&&this.astEl.logError(e,r,i),e}inputSpace(){return this.exprSpace}outputSpace(){return this}addWild(e){var r;let i=this.exprSpace;const s=[];if(e.joinPath)for(const a of e.joinPath.list){const l=a.refString;s.push(l);const c=i.entry(l);if(c)if(c instanceof p0t.StructSpaceField)i=c.fieldSpace;else{a.logError("invalid-wildcard-source",`Field '${l}' does not contain rows and cannot be expanded with '*'`);return}else{a.logError("wildcard-source-not-defined",`No such field as '${l}'`);return}}const o=this.dialectObj(),u=[];for(const[a,l]of i.entries())if(!e.except.has(a)&&l.refType!=="parameter")if(this.entry(a)){const c=(r=this.expandedWild[a])===null||r===void 0?void 0:r.path.join(".");e.logError("name-conflict-in-wildcard-expansion",`Cannot expand '${a}' in '${e.refString}' because a field with that name already exists${c?` (conflicts with ${c})`:""}`)}else{const c=l.typeDesc();LT.TD.isAtomic(c)&<.expressionIsScalar(c.expressionType)&&(o===void 0||!o.ignoreInProject(a))&&(u.push({name:a,entry:l}),this.expandedWild[a]={path:s.concat(a),entry:l})}for(const a of u.sort((l,c)=>l.name.localeCompare(c.name)))this.newEntry(a.name,e,a.entry)}addValidatedCompositeFieldUserFromEntry(e,r){r instanceof Q0e.SpaceField&&this.compositeFieldUsers.push({type:"field",name:e,field:r,logTo:void 0})}getJoinOnCompositeFieldUsage(e){var r;const i=e.map(o=>new H0e.FieldName(o));this.astEl.has({reference:i});const s=this.exprSpace.lookup(i);if(s.found&&s.found instanceof g0t.StructSpaceFieldBase)return(0,Ha.joinedCompositeFieldUsage)(e.slice(0,-1),(r=s.found.fieldDef().onCompositeFieldUsage)!==null&&r!==void 0?r:(0,Ha.emptyCompositeFieldUsage)());throw new Error("Unexpected join lookup was not found or not a struct")}getCompositeFieldUsageIncludingJoinOns(e){let r=e;const i=(0,Ha.compositeFieldUsageJoinPaths)(e);for(const s of i)r=(0,Ha.mergeCompositeFieldUsage)(this.getJoinOnCompositeFieldUsage(s),r);return r}addCompositeFieldUserFromFilter(e,r){e.compositeFieldUsage!==void 0&&this.compositeFieldUsers.push({type:"filter",filter:e,logTo:r})}newEntry(e,r,i){i instanceof Q0e.SpaceField&&this.compositeFieldUsers.push({type:"field",name:e,field:i,logTo:r}),super.newEntry(e,r,i)}applyNextCompositeFieldUsage(e,r,i,s,o){if(s){const u=this.getCompositeFieldUsageIncludingJoinOns((0,Ha.compositeFieldUsageDifference)(s,r));if(r=(0,Ha.mergeCompositeFieldUsage)(r,u),!(0,Ha.isEmptyCompositeFieldUsage)(u)){const a=(0,Ha.narrowCompositeFieldResolution)(e,r,i);a.error?(o??this).logError("invalid-composite-field-usage",{newUsage:u,allUsage:r}):i=a.narrowedCompositeFieldResolution}}return{compositeFieldUsage:r,narrowedCompositeFieldResolution:i}}}Du.QueryOperationSpace=z0e;class W0e extends z0e{addRefineFromFields(e){var r;if(LT.isQuerySegment(e)){if(e!=null&&e.extendSource)for(const i of e.extendSource)this.exprSpace.addFieldDef(i);for(const i of e.queryFields)if(i.type==="fieldref"){const s=this.exprSpace.lookup(i.path.map(o=>new H0e.FieldName(o)));if(s.found){const o=i.path[i.path.length-1];this.setEntry(o,s.found),this.addValidatedCompositeFieldUserFromEntry(o,s.found)}}else if(i.type!=="turtle"){const s=new h0t.ColumnSpaceField(i),o=(r=i.as)!==null&&r!==void 0?r:i.name;this.setEntry(o,s),this.addValidatedCompositeFieldUserFromEntry(o,s)}}}pushFields(...e){for(const r of e)r instanceof x0t.WildcardFieldReference?this.addWild(r):super.pushFields(r)}canContain(e){return!0}queryFieldDefs(){const e=[];let r=(0,Ha.emptyCompositeFieldUsage)(),i=(0,Ha.emptyNarrowedCompositeFieldResolution)();const s=this.inputSpace().structDef();for(const o of this.compositeFieldUsers){let u;if(o.type==="filter")o.filter.compositeFieldUsage&&(u=o.filter.compositeFieldUsage);else{const{name:l,field:c}=o,f=this.expandedWild[l];if(f)e.push({type:"fieldref",path:f.path}),u=f.entry.typeDesc().compositeFieldUsage;else{const x=c.getQueryFieldDef(this.exprSpace);if(x){const h=c.typeDesc();u=h.compositeFieldUsage,h&&h.type!=="error"&&this.canContain(h)&&!E0t(x)&&e.push(x)}}}const a=this.applyNextCompositeFieldUsage(s,r,i,u,o.logTo);r=a.compositeFieldUsage,i=a.narrowedCompositeFieldResolution}return this._compositeFieldUsage=r,e}getQuerySegment(e){const r=this.getPipeSegment(e);if(LT.isQuerySegment(r))return r;throw new Error("TODO NOT POSSIBLE")}getPipeSegment(e){if(this.segmentType==="index")return this.logError("unexpected-index-segment","internal error generating index segment from non index query"),{type:"reduce",queryFields:[]};const r={type:this.segmentType,queryFields:this.queryFieldDefs()};if(r.queryFields=(0,dk.mergeFields)(e==null?void 0:e.queryFields,r.queryFields),e!=null&&e.extendSource&&(r.extendSource=e.extendSource),this.exprSpace.extendList.length>0){const i=[],s=this.exprSpace.structDef();for(const o of this.exprSpace.extendList){const u=s.fields.find(a=>(0,dk.nameFromDef)(a)===o);u&&i.push(u)}r.extendSource=(0,dk.mergeFields)(r.extendSource,i)}return this.newTimezone&&(r.queryTimezone=this.newTimezone),r}lookup(e){const r=super.lookup(e);return r.found?{...r,isOutputField:!0}:this.exprSpace.lookup(e)}isQueryFieldSpace(){return!0}}Du.QuerySpace=W0e;class y0t extends W0e{constructor(){super(...arguments),this.segmentType="reduce"}}Du.ReduceFieldSpace=y0t;function E0t(t){return typeof t!="string"&&t.type==="turtle"&&t.pipeline.length===0}var A0t=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),_0t=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),v0t=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&A0t(e,t,r);return _0t(e,t),e};Object.defineProperty(wT,"__esModule",{value:!0}),wT.ExprUngroup=void 0;const G0e=et,C0t=Du,V0e=v0t(nn),S0t=ht;class b0t extends S0t.ExpressionDef{constructor(e,r,i){super({expr:r,fields:i}),this.control=e,this.expr=r,this.fields=i,this.legalChildTypes=V0e.anyAtomicT,this.elementType="ungroup"}getExpression(e){const r=this.expr.getExpression(e);if(!(0,G0e.expressionIsAggregate)(r.expressionType))return this.expr.loggedErrorExpr("ungroup-of-non-aggregate",`${this.control}() expression must be an aggregate`);if((0,G0e.expressionIsUngroupedAggregate)(r.expressionType))return this.expr.loggedErrorExpr("ungroup-of-ungrouped-aggregate",`${this.control}() expression must not already be ungrouped`);const i={node:this.control,e:r.value};if(this.typeCheck(this.expr,{...r,expressionType:"scalar"})){if(e.isQueryFieldSpace()&&this.fields.length>0){const s=[],o=this.control==="exclude";for(const u of this.fields){let a=e.outputSpace(),l=!0;for(;a;){const c=a.lookup([u]);if(c.found&&c.isOutputField)s.push(u.refString),l=!1;else if(a instanceof C0t.QuerySpace){a=a.nestParent;continue}break}if(l){const c=o?"exclude()":"all()";u.logError("ungroup-field-not-in-output",`${c} '${u.refString}' is missing from query output`)}}i.fields=s}return{...V0e.atomicDef(r),expressionType:"ungrouped_aggregate",value:i,evalSpace:"output",compositeFieldUsage:r.compositeFieldUsage}}return this.loggedErrorExpr("ungroup-with-non-scalar",`${this.control}() incompatible type`)}}wT.ExprUngroup=b0t;var IT={},T0t=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),R0t=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),D0t=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&T0t(e,t,r);return R0t(e,t),e};Object.defineProperty(IT,"__esModule",{value:!0}),IT.ForRange=void 0;const O0t=Hs,Y0e=D0t(nn),$T=Es,F0t=Yt,w0t=ht,BT=q2,K0e=ef;class N0t extends w0t.ExpressionDef{constructor(e,r,i){super({from:e,duration:r,timeframe:i}),this.from=e,this.duration=r,this.timeframe=i,this.elementType="forRange",this.legalChildTypes=[Y0e.timestampT,Y0e.dateT]}apply(e,r,i){const s=this.from.getExpression(e),o=i.getExpression(e);if(!this.typeCheck(i,o))return(0,O0t.errorFor)("no time for range");const u=this.duration.getExpression(e);if(u.type!=="number")return u.type!=="error"&&this.logError("invalid-duration-quantity",`FOR duration count must be a number, not '${u.type}'`),(0,F0t.computedErrorExprValue)({dataType:{type:"boolean"},error:"for not number",from:[s,o]});const a=this.timeframe.text;let l=(0,$T.resolution)(a);if(s.type==="timestamp"&&(l="timestamp"),o.type==="date"&&l==="date"){const m=this.from,g=(0,$T.timeOffset)("date",s.value,"+",u.value,a),y=new BT.ExprTime("date",g);return new K0e.Range(m,y).apply(e,r,i)}const c=BT.ExprTime.fromValue("timestamp",o);let f=this.from,x=s.value;if(s.type==="date"){const m=s.morphic&&s.morphic.timestamp;m?x=m:x=(0,$T.castTo)("timestamp",x,"date"),f=new BT.ExprTime("timestamp",x,[s])}const h=(0,$T.timeOffset)("timestamp",x,"+",u.value,a),p=new BT.ExprTime("timestamp",h,[s,u]);return new K0e.Range(f,p).apply(e,r,c)}requestExpression(e){}getExpression(e){return this.loggedErrorExpr("range-as-value","A Range is not a value")}}IT.ForRange=N0t;var Fr={};Object.defineProperty(Fr,"__esModule",{value:!0}),Fr.LiteralYear=Fr.LiteralQuarter=Fr.LiteralMonth=Fr.LiteralWeek=Fr.LiteralDay=Fr.LiteralHour=Fr.LiteralTimestamp=Fr.TimeFormatError=void 0;const of=qr,L0t=et,I0t=Yt,$0t=ef,J0e=q2,hk=ht;class B0t extends Error{}Fr.TimeFormatError=B0t;function Rd(t,e){const r=t.slice(1);if(e){const i=r.match(/\[[^\]]+]$/);if(i)return{tzSpec:i[0].slice(1,-1),text:r.slice(0,-i[0].length)}}return{text:r}}const X0e="yyyy",Z0e=`${X0e}-LL`,Do=`${Z0e}-dd`,ece=`${Do} HH`,tce=`${ece}:mm`,pk=`${tce}:ss`;class nce extends hk.ExpressionDef{constructor(e,r,i){super(),this.units=r,this.timeType=i,this.literalPart=e.text,e.tzSpec&&(this.timeZone=e.tzSpec)}makeLiteral(e,r){const i={node:"timeLiteral",literal:e,typeDef:{type:r}};return this.timeZone&&(i.timezone=this.timeZone),i}makeValue(e,r){const i=this.makeLiteral(e,r);return(0,I0t.literalTimeResult)({value:i,dataType:{type:r},timeframe:this.units})}getExpression(e){return this.makeValue(this.literalPart,this.timeType)}getNext(){if(this.nextLit)return this.makeValue(this.nextLit,this.timeType)}granular(){return this.nextLit!==void 0}}class mk extends nce{constructor(e,r){super(e,r,"timestamp"),this.elementType="literal:timestamp"}static parse(e){let r;const i=Rd(e,!0);e=i.text,e[10]==="T"&&(e=e.slice(0,10)+" "+e.slice(11),i.text=e);const s=e.match(/^([^.,]+)[,.](\d+)$/);s&&(e=s[1]);let o=of.DateTime.fromFormat(e,pk);if(o.isValid)return new mk(i,r);if(o=of.DateTime.fromFormat(e,tce),o.isValid){i.text=i.text+":00",r="minute";const u=o.plus({minute:1}).toFormat(pk);return new gk(i,r,"timestamp",u)}}}Fr.LiteralTimestamp=mk;class gk extends nce{constructor(e,r,i,s){super(e,r,i),this.nextLit=s,this.elementType="granularTimeLiteral"}apply(e,r,i){let s=this.getExpression(e),o=this.getNext();if(o){const u=i.getExpression(e);if(u.type==="timestamp"){const a=(0,hk.getMorphicValue)(s,"timestamp"),l=(0,hk.getMorphicValue)(o,"timestamp");if(a&&l)s=a,o=l;else return super.apply(e,r,i)}if(o&&(0,L0t.isTemporalType)(u.type)){const a=u.type;return new $0t.Range(new J0e.ExprTime(a,s.value),new J0e.ExprTime(a,o.value)).apply(e,r,i)}}return super.apply(e,r,i)}}class yk extends gk{constructor(e,r){super(e,"hour","timestamp",r),this.elementType="literal:hour"}static parse(e){const r=Rd(e,!1);let i=r.text;const s=of.DateTime.fromFormat(r.text,ece);if(s.isValid)return r.text=r.text+":00:00",i=s.plus({hour:1}).toFormat(pk),new yk(r,i)}}Fr.LiteralHour=yk;class wE extends gk{constructor(e,r,i){super(e,r,"date",i)}getExpression(e){const r=this.makeValue(this.literalPart,"date"),i=this.makeLiteral(`${this.literalPart} 00:00:00`,"timestamp");return{...r,morphic:{timestamp:i},evalSpace:"literal"}}getNext(){const e=this.makeValue(this.nextLit,"date"),r=this.makeLiteral(`${this.nextLit} 00:00:00`,"timestamp");return{...e,morphic:{timestamp:r}}}}class Ek extends wE{constructor(e,r){super(e,"day",r),this.elementType="literal:day"}static parse(e){const r=Rd(e,!1);let i=r.text;const s=of.DateTime.fromFormat(r.text,Do);if(s.isValid)return i=s.plus({day:1}).toFormat(Do),new Ek(r,i)}}Fr.LiteralDay=Ek;class Ak extends wE{constructor(e,r){super(e,"week",r),this.elementType="literal:week"}static parse(e){const r=Rd(e,!1);let i=r.text;const s=r.text.slice(0,10),o=of.DateTime.fromFormat(s,Do);if(o.isValid&&o.weekday===7){const a=o.plus({days:7});return r.text=o.toFormat(Do),i=a.toFormat(Do),new Ak(r,i)}}}Fr.LiteralWeek=Ak;class _k extends wE{constructor(e,r){super(e,"month",r),this.elementType="literal:month"}static parse(e){const r=Rd(e,!1);let i=r.text;const s=of.DateTime.fromFormat(r.text,Z0e);if(s.isValid){const o=s.plus({months:1});return r.text=s.toFormat(Do),i=o.toFormat(Do),new _k(r,i)}}}Fr.LiteralMonth=_k;class vk extends wE{constructor(e,r){super(e,"quarter",r),this.elementType="literal:quarter"}static parse(e){const r=Rd(e,!1);let i=r.text;const s=r.text.match(/(^\d{4})-[qQ](\d)$/);if(s){const o=Number.parseInt(s[2])-1;let u=of.DateTime.fromFormat(s[1],"yyyy");o>0&&(u=u.plus({quarters:o}));const a=u.plus({quarter:1});return r.text=u.toFormat(Do),i=a.toFormat(Do),new vk(r,i)}}}Fr.LiteralQuarter=vk;class Ck extends wE{constructor(e,r){super(e,"year",r),this.elementType="literal:year"}static parse(e){const r=Rd(e,!1);let i=r.text;const s=of.DateTime.fromFormat(r.text,X0e);if(s.isValid){const o=s.plus({year:1});return r.text=s.toFormat(Do),i=o.toFormat(Do),new Ck(r,i)}}}Fr.LiteralYear=Ck;var kT={};Object.defineProperty(kT,"__esModule",{value:!0}),kT.PartialCompare=void 0;const rce=ht;class k0t extends rce.ExpressionDef{constructor(e,r){super({right:r}),this.op=e,this.right=r,this.elementType="<=> a"}granular(){return this.right.granular()}apply(e,r,i){return this.right.apply(e,this.op,i)}requestExpression(e){}getExpression(e){return this.loggedErrorExpr("partial-as-value","Partial comparison does not have a value")}atNodeType(){return rce.ATNodeType.Partial}}kT.PartialCompare=k0t;var Y2={},M0t=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),P0t=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),U0t=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&M0t(e,t,r);return P0t(e,t),e};Object.defineProperty(Y2,"__esModule",{value:!0}),Y2.PickWhen=Y2.Pick=void 0;const K2=U0t(nn),ice=Yt,j0t=ht,q0t=Ze;function MT(t,e){return t===void 0||t.type==="null"||t.type==="error"?e:t}class H0t extends j0t.ExpressionDef{constructor(e,r){super({choices:e}),this.choices=e,this.elsePick=r,this.elementType="pick",this.has({elsePick:r})}requestExpression(e){if(this.elsePick!==void 0){for(const r of this.choices){if(r.pick===void 0)return;const i=r.when.requestExpression(e);if(i===void 0||i.type!=="boolean")return}return this.getExpression(e)}}apply(e,r,i){var s;const o={node:"case",kids:{caseWhen:[],caseThen:[]}};let u;const a=[];for(const h of this.choices){const p=h.when.apply(e,"=",i),m=h.pick?h.pick.getExpression(e):i.getExpression(e);if(a.push(p,m),u&&!K2.typeEq(u,m,!0))return this.loggedErrorExpr("pick-type-does-not-match",{pickType:m.type,returnType:u.type});u=MT(u,m),o.kids.caseWhen.push(p.value),o.kids.caseThen.push(m.value)}const l=(s=this.elsePick)===null||s===void 0?void 0:s.getExpression(e),c=i.getExpression(e);a.push(c),l&&a.push(l);const f=l??c,x=MT(u,f);return K2.typeEq(x,f,!0)?x.type==="filter expression"?this.loggedErrorExpr("filter-expression-error","Pick statments cannot have filter expression values"):(o.kids.caseElse=f.value,(0,ice.computedExprValue)({dataType:x,value:o,from:a})):this.elsePick?this.loggedErrorExpr("pick-else-type-does-not-match",{elseType:f.type,returnType:x.type}):this.loggedErrorExpr("pick-default-type-does-not-match",{defaultType:f.type,returnType:x.type})}getExpression(e){const r={node:"case",kids:{caseWhen:[],caseThen:[]}};if(this.elsePick===void 0)return this.loggedErrorExpr("pick-missing-else","pick incomplete, missing 'else'");const i=[],s=[];for(const l of this.choices){if(l.pick===void 0)return this.loggedErrorExpr("pick-missing-value","pick with no value can only be used with apply");l.when.requestExpression(e)===void 0&&this.loggedErrorExpr("pick-illegal-partial","pick with partial when can only be used with apply");const f=l.pick.getExpression(e),x=l.when.getExpression(e);i.push({pick:f,when:x}),s.push(f,x)}let o;for(const l of i){if(!K2.typeEq(l.when,K2.boolT))return this.loggedErrorExpr("pick-when-must-be-boolean",{whenType:l.when.type});if(o&&!K2.typeEq(o,l.pick,!0))return this.loggedErrorExpr("pick-type-does-not-match",{pickType:l.pick.type,returnType:o.type});o=MT(o,l.pick),r.kids.caseWhen.push(l.when.value),r.kids.caseThen.push(l.pick.value)}const u=this.elsePick.getExpression(e);s.push(u);const a=MT(o,u);return K2.typeEq(a,u,!0)?a.type==="filter expression"?this.loggedErrorExpr("filter-expression-error","Pick statments cannot have filter expression values"):(r.kids.caseElse=u.value,(0,ice.computedExprValue)({dataType:a,value:r,from:s})):this.elsePick.loggedErrorExpr("pick-else-type-does-not-match",{elseType:u.type,returnType:a.type})}}Y2.Pick=H0t;class Q0t extends q0t.MalloyElement{constructor(e,r){super({when:r}),this.pick=e,this.when=r,this.elementType="caseWhen",this.has({pick:e})}}Y2.PickWhen=Q0t;var J2={},z0t=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),W0t=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),G0t=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&z0t(e,t,r);return W0t(e,t),e};Object.defineProperty(J2,"__esModule",{value:!0}),J2.CaseWhen=J2.Case=void 0;const V0t=Yt,Y0t=ht,K0t=Ze,X2=G0t(nn);function sce(t,e){return t===void 0||t.type==="null"||t.type==="error"?e:t}class J0t extends Y0t.ExpressionDef{constructor(e,r,i){super({choices:r}),this.value=e,this.choices=r,this.elseValue=i,this.elementType="case",this.has({elseValue:i,value:e})}getExpression(e){const r={node:"case",kids:{caseWhen:[],caseThen:[]}},i=[];let s;if(this.value){const a=this.value.getExpression(e);i.push(a),r.kids.caseValue=a.value,s=a}const o=[];for(const a of this.choices){const l=a.when.getExpression(e),c=a.then.getExpression(e);o.push({when:l,then:c}),i.push(l,c)}let u;for(const a of o){if(s!==void 0){if(!X2.typeEq(a.when,s))return this.loggedErrorExpr("case-when-type-does-not-match",{whenType:a.when.type,valueType:s.type})}else if(!X2.typeEq(a.when,X2.boolT))return this.loggedErrorExpr("case-when-must-be-boolean",{whenType:a.when.type});if(u&&!X2.typeEq(u,a.then,!0))return this.loggedErrorExpr("case-then-type-does-not-match",{thenType:a.then.type,returnType:u.type});u=sce(u,a.then),r.kids.caseWhen.push(a.when.value),r.kids.caseThen.push(a.then.value)}if(this.elseValue){const a=this.elseValue.getExpression(e);if(u&&!X2.typeEq(u,a,!0))return this.loggedErrorExpr("case-else-type-does-not-match",{elseType:a.type,returnType:u.type});u=sce(u,a),i.push(a),r.kids.caseElse=a.value}return(0,V0t.computedExprValue)({value:r,dataType:u?X2.atomicDef(u):{type:"null"},from:i})}}J2.Case=J0t;class X0t extends K0t.MalloyElement{constructor(e,r){super({when:e,then:r}),this.when=e,this.then=r,this.elementType="caseWhen"}}J2.CaseWhen=X0t;var PT={},Dd={},Z0t=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),ect=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),tct=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&Z0t(e,t,r);return ect(e,t),e};Object.defineProperty(Dd,"__esModule",{value:!0}),Dd.RecordLiteral=Dd.RecordElement=void 0;const oce=Gi,nct=Yt,rct=ht,ict=Ze,sct=tct(nn);class oct extends ict.MalloyElement{constructor(e){if(super(),this.elementType="record element","value"in e)this.value=e.value,this.has({value:e.value}),e.key&&(this.key=e.key);else{this.has({path:e.path}),this.value=e.path;const r=e.path.fieldReference.path;this.key=r[r.length-1]}}}Dd.RecordElement=oct;class uct extends rct.ExpressionDef{constructor(e){super(),this.pairs=e,this.elementType="record literal",this.has({pairs:e})}getExpression(e){return this.getRecord(e,[])}getRecord(e,r){var i;const s={node:"recordLiteral",kids:{},typeDef:{type:"record",fields:[]}},o=[];let u=0;for(const a of this.pairs){const l=(i=a.key)!==null&&i!==void 0?i:r[u];if(u+=1,l===void 0){a.logError("record-literal-needs-keys","Anonymous record element not legal here");continue}const c=a.value.getExpression(e);oce.TD.isAtomic(c)?(o.push(c),s.kids[l]=c.value,s.typeDef.fields.push((0,oce.mkFieldDef)(sct.atomicDef(c),l))):a.value.logError("illegal-record-property-type",`Record property '${a.key} is type '${c.type}', which is not a legal property value type`)}return(0,nct.computedExprValue)({value:s,dataType:s.typeDef,from:o})}getNextElement(e,r){const i=r.value;return i.node==="recordLiteral"?this.getRecord(e,Object.keys(i.kids)):this.getRecord(e,[])}}Dd.RecordLiteral=uct;var act=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),lct=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),cct=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&act(e,t,r);return lct(e,t),e};Object.defineProperty(PT,"__esModule",{value:!0}),PT.ArrayLiteral=void 0;const fct=Yt,xct=ht,uce=cct(nn),dct=Dd;class hct extends xct.ExpressionDef{constructor(e){super(),this.elements=e,this.elementType="array literal",this.has({elements:e})}getExpression(e){const r=[],i=[];let s;if(this.elements.length>0)for(const l of this.elements){const c=s&&l instanceof dct.RecordLiteral?l.getNextElement(e,s):l.getExpression(e);if(i.push(c),c.type!=="error"){if(s){if(c.type!=="null"&&!uce.typeEq(s,c)){l.logError("array-values-incompatible","All array elements must be same type");continue}}else c.type!=="null"&&(s=c);r.push(c.value)}}const o=uce.atomicDef(s||{type:"number"}),u=o.type==="record"?{type:"array",elementTypeDef:{type:"record_element"},fields:o.fields}:{type:"array",elementTypeDef:o},a={node:"arrayLiteral",kids:{values:r},typeDef:u};return(0,fct.computedExprValue)({dataType:u,value:a,from:i})}}PT.ArrayLiteral=hct;var UT={};Object.defineProperty(UT,"__esModule",{value:!0}),UT.Timeframe=void 0;const pct=et,mct=Ze;class gct extends mct.MalloyElement{constructor(e){super(),this.elementType="timeframe";let r=e.toLowerCase();r.endsWith("s")&&(r=r.slice(0,-1)),this.text=(0,pct.isTimestampUnit)(r)?r:"second"}}UT.Timeframe=gct;var uf={};Object.defineProperty(uf,"__esModule",{value:!0}),uf.ImportStatement=uf.ImportSelect=uf.ImportSourceName=void 0;const Sk=Ze;class yct extends Sk.MalloyElement{constructor(e){super(),this.text=e,this.elementType="importSourceName"}}uf.ImportSourceName=yct;class Ect extends Sk.MalloyElement{constructor(e,r){super(),this.text=e,this.from=r,this.elementType="importName",r&&this.has({from:r})}}uf.ImportSelect=Ect;class Act extends Sk.ListOf{constructor(e,r){super([]),this.url=e,this.elementType="import statement";try{this.fullURL=decodeURI(new URL(e,r).toString())}catch{this.logError("invalid-import-url","Invalid URL in import statement")}}needs(){const e=this.translator();if(e&&this.fullURL&&e.root.importZone.getEntry(this.fullURL).status==="present"){const i=e.childRequest(this.fullURL);if(i)return i}}execute(e){const r=this.translator();if(!r)this.logError("no-translator-for-import","Cannot import without translation context");else if(this.fullURL){const i=r.root.pretranslatedModels.get(this.fullURL),s=r.root.importZone.getEntry(this.fullURL);if(i||s.status==="present"){const o=r.getChildExports(this.fullURL);if(this.notEmpty())for(const u of this.list){const a=u.from||u;if(e.getEntry(u.text))u.logError("name-conflict-on-selective-import",`Cannot redefine '${u.text}'`);else if(o[a.text]){const l={...o[a.text]};u.from&&(l.as=u.text),e.setEntry(u.text,{entry:l,exported:!1})}else a.logError("selective-import-not-found",`Cannot find '${a.text}', not imported`)}else for(const[u,a]of Object.entries(r.getChildExports(this.fullURL)))e.getEntry(u)?this.logError("name-conflict-on-indiscriminate-import",`Cannot redefine '${u}'`):e.setEntry(u,{entry:a,exported:!1})}else s.status==="error"?this.logError("failed-import",`import failed: '${s.message}'`):this.logError("failed-import",`import failed with status: '${s.status}'`)}}}uf.ImportStatement=Act;var NE={};Object.defineProperty(NE,"__esModule",{value:!0}),NE.ExtendBlock=void 0;const _ct=Ze,vct=zn;class Cct extends _ct.ListOf{constructor(){super(...arguments),this.elementType="extendBlock",this.forceQueryClass=void 0,this.queryRefinementStage=vct.LegalRefinementStage.Single}queryExecute(e){for(const r of this.list)for(const i of r.list)e.inputFS.extendSource(i)}}NE.ExtendBlock=Cct;var jT={};Object.defineProperty(jT,"__esModule",{value:!0}),jT.Argument=void 0;const Sct=Ze;class bct extends Sct.MalloyElement{constructor(e){super({...e}),this.elementType="Argument",this.id=e.id,this.value=e.value}}jT.Argument=bct;var qT={};Object.defineProperty(qT,"__esModule",{value:!0}),qT.HasParameter=void 0;const ace=et,Tct=Ze,Rct=ht;class Dct extends Tct.MalloyElement{constructor(e){super(),this.elementType="hasParameter",this.name=e.name,e.type&&(0,ace.isParameterType)(e.type)&&(this.type=e.type),e.default&&(this.default=e.default,this.has({default:this.default})),e.filterType&&(this.filterType=e.filterType)}parameter(){var e;let r;if(this.default!==void 0){const i=this.default.constantValue();if(this.type&&this.type!==i.type&&i.type!=="null"&&i.type!=="error"&&this.default.logError("parameter-default-does-not-match-declared-type",`Default value for parameter does not match declared type \`${this.type}\``),i.type==="null")return this.type?{type:this.type,value:i.value,name:this.name}:(this.default.logError("parameter-null-default-without-declared-type","Default value cannot have type `null` unless parameter type is also specified"),{value:i.value,name:this.name,type:"error"});if(i.type==="filter expression")return this.type!=="filter expression"&&this.logError("parameter-missing-default-or-type",`Filter expression parameters must have expicit filter type, for example '${this.name}::filter<string>'`),this.filterType&&(0,Rct.checkFilterExpression)(this,this.filterType,i.value),{value:i.value,name:this.name,type:i.type};if(!(0,ace.isCastType)(i.type)&&i.type!=="error")return this.default.logError("parameter-illegal-default-type",`Default value cannot have type \`${i.type}\``),{value:i.value,name:this.name,type:"error"};r={value:i.value,name:this.name,type:i.type}}else this.type===void 0&&this.logError("parameter-missing-default-or-type","Parameter must have default value or declared type"),r={value:null,name:this.name,type:(e=this.type)!==null&&e!==void 0?e:"error"};return r.type==="filter expression"&&this.filterType&&(r.filterType=this.filterType),r}}qT.HasParameter=Dct;var HT={};Object.defineProperty(HT,"__esModule",{value:!0}),HT.AnonymousQuery=void 0;const Oct=Ze,Fct=Qr;class wct extends Oct.MalloyElement{constructor(e){super(),this.queryExpr=e,this.elementType="anonymousQuery",this.isNoteableObj=!0,this.extendNote=Fct.extendNoteMethod,this.has({queryExpr:e})}execute(e){const r=this.queryExpr.getQuery();if(!r){this.queryExpr.sqLog("non-query-used-as-query","Cannot run this object as a query");return}const i={...r.query()},s=this.note||{};i.annotation&&(s.inherits=i.annotation),(s.notes||s.blockNotes||s.inherits)&&(i.annotation=s),e.queryList.push(i)}}HT.AnonymousQuery=wct;var af={};Object.defineProperty(af,"__esModule",{value:!0}),af.View=void 0;const Nct=Ze;class Lct extends Nct.MalloyElement{pipeline(e,r){return this.pipelineComp(e,r).pipeline}}af.View=Lct;var QT={};Object.defineProperty(QT,"__esModule",{value:!0}),QT.ViewArrow=void 0;const Ict=Wr,$ct=af;class Bct extends $ct.View{constructor(e,r){super({base:e,operation:r}),this.base=e,this.operation=r,this.elementType="viewArrow"}pipelineComp(e){const r=this.base.pipelineComp(e),i=new Ict.StaticSourceSpace(r.outputStruct),s=this.operation.pipelineComp(i);return{pipeline:[...r.pipeline,...s.pipeline],outputStruct:s.outputStruct}}refine(e,r,i){return this.logError("refinement-with-multistage-view","A multi-segment view cannot be used as a refinement"),[]}getImplicitName(){return this.operation.getImplicitName()}}QT.ViewArrow=Bct;var zT={},LE={};Object.defineProperty(LE,"__esModule",{value:!0}),LE.refine=void 0;const bk=Gi,kct=dt,Tk=Vc;function Mct(t,e,r){var i,s;if(e.length!==1)return t.logError("refinement-with-multistage-view","Named refinements of multi-stage views are not supported"),e;const o={...e[0]},u=r;if((0,bk.isRawSegment)(o))t.logError("refinement-of-raw-query","Cannot refine raw query, must add an explicit query stage");else if(o.type==="partial"&&u.type!=="index"&&u.type!=="raw"?o.type=u.type:u.type!==o.type&&t.logError("mismatched-view-types-for-refinement",`cannot refine ${o.type} view with ${u.type} view`),u.type!=="index"&&o.type!=="index"&&u.type!=="raw"&&(u.orderBy!==void 0&&!u.defaultOrderBy&&(o.orderBy===void 0||o.defaultOrderBy?o.orderBy=u.orderBy:t.logError("ordering-overridden-in-refinement","refinement cannot override existing ordering")),u.limit!==void 0&&(o.limit===void 0?o.limit=u.limit:t.logError("limit-overridden-in-refinement","refinement cannot override existing limit"))),o.filterList=o.filterList!==void 0||u.filterList!==void 0?[...(i=o.filterList)!==null&&i!==void 0?i:[],...(s=u.filterList)!==null&&s!==void 0?s:[]]:void 0,(0,bk.isQuerySegment)(u)&&(0,bk.isQuerySegment)(o)){const a=[],l=[],c=new Map(o.queryFields.map(f=>[(0,Tk.nameFromDef)(f),f]));for(const f of u.queryFields)c.has((0,Tk.nameFromDef)(f))?a.push(f):l.push(f);o.queryFields=[...o.queryFields,...l],a.length>0&&t.logError("name-conflict-in-refinement",`overlapping fields in refinement: ${a.map(Tk.nameFromDef)}`),o.compositeFieldUsage=(0,kct.mergeCompositeFieldUsage)(o.compositeFieldUsage,u.compositeFieldUsage)}else u.type==="index"&&o.type==="index"&&(o.indexFields=[...u.indexFields,...o.indexFields]);return[o]}LE.refine=Mct,Object.defineProperty(zT,"__esModule",{value:!0}),zT.ViewRefine=void 0;const Pct=gi,Uct=zs,jct=LE,qct=af;class Hct extends qct.View{constructor(e,r){super({base:e,refinement:r}),this.base=e,this.refinement=r,this.elementType="refine"}pipelineComp(e,r){const i=this.base.pipelineComp(e),s=this.refinement.refine(e,i.pipeline,r);return{pipeline:s,annotation:i.annotation,outputStruct:s.length>0?(0,Uct.getFinalStruct)(this.refinement,e.structDef(),s):Pct.ErrorFactory.structDef}}refine(e,r,i){const s=this.pipeline(e,i);return s.length!==1?(this.refinement.logError("refinement-with-multistage-view","refinement must have exactly one stage"),r):(0,jct.refine)(this,r,s[0])}getImplicitName(){return this.base.getImplicitName()}}zT.ViewRefine=Hct;var WT={};Object.defineProperty(WT,"__esModule",{value:!0}),WT.ReferenceView=void 0;const Rk=et,lce=gi,Qct=zs,zct=zr,Wct=LE,Gct=af;class Vct extends Gct.View{constructor(e){super({reference:e}),this.reference=e,this.elementType="reference-view"}pipelineComp(e,r){return this._pipelineComp(e)}_pipelineComp(e,{forRefinement:r}={forRefinement:!1}){const i=this.reference.getField(e),s=function(){return{inputStruct:lce.ErrorFactory.structDef,outputStruct:lce.ErrorFactory.structDef,pipeline:[],error:!0}};if(!i.found)return this.reference.logError(i.error.code,i.error.message),s();if(!(i.found instanceof zct.SpaceField))throw new Error("Expected space field");const o=i.found.fieldDef();if(o===void 0)throw new Error("Expected field to have definition");if((0,Rk.isAtomic)(o)){const u={type:"reduce",queryFields:[this.reference.refToField],compositeFieldUsage:o.compositeFieldUsage},a=this.reference.nameString,l={...(0,Rk.sourceBase)(e.structDef()),type:"query_result",name:a,fields:[o]};return{pipeline:[u],name:a,outputStruct:l}}else return(0,Rk.isTurtle)(o)?this.reference.list.length>1?(r?this.logError("refinement-with-joined-view","Cannot use view from join as refinement"):this.logError("nest-of-joined-view","Cannot use view from join"),s()):{pipeline:[...o.pipeline],name:o.name,annotation:o.annotation,outputStruct:(0,Qct.getFinalStruct)(this.reference,e.structDef(),o.pipeline)}:(r?this.reference.logError("refinement-with-source",`named refinement \`${this.reference.refString}\` must be a view, found a ${o.type}`):this.reference.logError("nest-of-source","This operation is not supported"),s())}getRefinementSegment(e){const{pipeline:r,error:i}=this._pipelineComp(e,{forRefinement:!0});if(!i){if(r.length!==1){this.reference.logError("refinement-with-multistage-view",`named refinement \`${this.reference.refString}\` must have exactly one stage`);return}return r[0]}}refine(e,r,i){const s=this.getRefinementSegment(e);return s?(0,Wct.refine)(this,r,s):r}getImplicitName(){return this.reference.nameString}}WT.ReferenceView=Vct;var GT={},IE={},VT={},$E={};Object.defineProperty($E,"__esModule",{value:!0}),$E.Index=void 0;const Yct=Ze,Kct=zn;class Jct extends Yct.MalloyElement{constructor(e){super({fields:e}),this.fields=e,this.elementType="index",this.forceQueryClass=Kct.QueryClass.Index,this.queryRefinementStage=void 0}useWeight(e){this.has({weightBy:e}),this.weightBy=e}}$E.Index=Jct;var BE={};Object.defineProperty(BE,"__esModule",{value:!0}),BE.SampleProperty=void 0;const Xct=Ze,cce=zn;class Zct extends Xct.MalloyElement{constructor(e){super(),this.sample=e,this.elementType="sampleProperty",this.queryRefinementStage=cce.LegalRefinementStage.Tail,this.forceQueryClass=cce.QueryClass.Index}sampling(){return this.sample}}BE.SampleProperty=Zct;var YT={};Object.defineProperty(YT,"__esModule",{value:!0}),YT.IndexFieldSpace=void 0;const fce=dt,xce=et,Dk=_t,eft=zr,tft=Du,nft=dE,rft=Wr;class ift extends tft.QueryOperationSpace{constructor(){super(...arguments),this.segmentType="index"}pushFields(...e){for(const r of e)r instanceof Dk.FieldReference?super.pushFields(r):r instanceof Dk.WildcardFieldReference?this.addWild(r):r.logError("invalid-field-in-index-query","Internal error, not expected in index query")}getPipeSegment(e){if(e)return this.logError("refinement-of-index-segment","index query operations cannot be refined"),{type:"index",indexFields:[]};let r=(0,fce.emptyCompositeFieldUsage)(),i=(0,fce.emptyNarrowedCompositeFieldResolution)();const s=[],o=this.inputSpace().structDef();for(const[u,a]of this.entries())if(a instanceof eft.SpaceField){let l,c;const f=this.expandedWild[u];if(f)s.push({type:"fieldref",path:f.path}),l=f.entry.typeDesc().compositeFieldUsage;else if(a instanceof nft.ReferenceField){const h=a.fieldRef,p=h.getField(this.exprSpace);p.error?h.logError(p.error.code,p.error.message):(s.push(h.refToField),l=p.found.typeDesc().compositeFieldUsage,c=h)}const x=this.applyNextCompositeFieldUsage(o,r,i,l,c);r=x.compositeFieldUsage,i=x.narrowedCompositeFieldResolution}return this._compositeFieldUsage=r,{type:"index",indexFields:s}}addRefineFromFields(e){}addWild(e){var r;let i=this.exprSpace;const s=[];if(e.joinPath)for(const a of e.joinPath.list){const l=a.refString;s.push(l);const c=i.entry(l);if(c)if(c instanceof rft.StructSpaceField)i=c.fieldSpace;else{a.logError("invalid-wildcard-source",`Field '${l}' does not contain rows and cannot be expanded with '*'`);return}else{a.logError("wildcard-source-not-found",`No such field as '${l}'`);return}}const o=this.dialectObj(),u=[];for(const[a,l]of i.entries()){if(e.except.has(a)||l.refType==="parameter")continue;const c=Dk.IndexFieldReference.indexOutputName([...s,a]);if(this.entry(c)){const f=(r=this.expandedWild[c].path)===null||r===void 0?void 0:r.join(".");e.logError("name-conflict-in-wildcard-expansion",`Cannot expand '${a}' in '${e.refString}' because a field with that name already exists${f?` (conflicts with ${f})`:""}`)}else{const f=l.typeDesc();xce.TD.isBasicAtomic(f)&&(0,xce.expressionIsScalar)(f.expressionType)&&(o===void 0||!o.ignoreInProject(a))&&(u.push({name:c,entry:l}),this.expandedWild[c]={path:s.concat(a),entry:l})}}for(const a of u.sort((l,c)=>l.name.localeCompare(c.name)))this.setEntry(a.name,a.entry)}}YT.IndexFieldSpace=ift,Object.defineProperty(VT,"__esModule",{value:!0}),VT.IndexBuilder=void 0;const Ok=et,sft=gi,oft=qa,uft=$E,aft=nf,lft=BE,cft=YT,Fk=dt;class fft{constructor(e,r,i,s){this.filters=[],this.alwaysJoins=[],this.type="index",this.resultFS=new cft.IndexFieldSpace(e,r,i,s),this.inputFS=this.resultFS.inputSpace()}execute(e){e instanceof oft.Filter?e.queryExecute(this):e instanceof aft.Limit?(this.limit&&this.limit.logError("index-limit-already-specified","Ignored, too many limit: statements"),this.limit=e):e instanceof uft.Index?(this.resultFS.pushFields(...e.fields.list),e.weightBy&&(this.indexOn&&this.indexOn.logError("index-by-already-specified","Ignoring previous BY"),this.indexOn=e.weightBy)):e instanceof lft.SampleProperty?this.sample=e.sampling():e.logError("illegal-operation-for-index","Not legal in an index query operation")}get compositeFieldUsage(){return this.resultFS.compositeFieldUsage}finalize(e){var r;if(e&&!(0,Ok.isIndexSegment)(e)&&!(0,Ok.isPartialSegment)(e))return this.resultFS.logError("refinement-of-index-segment",`Can't refine index with ${e.type}`),sft.ErrorFactory.indexSegment;const i=this.resultFS.getPipeSegment(e),s=(e==null?void 0:e.filterList)||[];this.filters.length>0&&!s?i.filterList=this.filters:s&&(i.filterList=[...s,...this.filters]),e!=null&&e.limit&&(i.limit=e.limit),this.limit&&(i.limit=this.limit.limit),this.indexOn&&(i.weightMeasure=this.indexOn.refString),e&&(0,Ok.isIndexSegment)(e)&&(e!=null&&e.sample)&&(i.sample=e.sample),this.sample&&(i.sample=this.sample),this.alwaysJoins.length>0&&(i.alwaysJoins=[...this.alwaysJoins]);const o=e&&e.type==="index"&&(r=e.compositeFieldUsage)!==null&&r!==void 0?r:(0,Fk.emptyCompositeFieldUsage)();return i.compositeFieldUsage=(0,Fk.mergeCompositeFieldUsage)(o,this.compositeFieldUsage),i}}VT.IndexBuilder=fft;var KT={},kE={};Object.defineProperty(kE,"__esModule",{value:!0}),kE.GroupBy=void 0;const xft=Qs,dce=zn;class dft extends xft.DefinitionList{constructor(){super(...arguments),this.elementType="groupBy",this.queryRefinementStage=dce.LegalRefinementStage.Single,this.forceQueryClass=dce.QueryClass.Grouping}}kE.GroupBy=dft;var JT={};Object.defineProperty(JT,"__esModule",{value:!0}),JT.ProjectFieldSpace=void 0;const XT=et,hft=Du;class pft extends hft.QuerySpace{constructor(){super(...arguments),this.segmentType="project"}canContain(e){return e===void 0||!XT.TD.isAtomic(e)||(0,XT.expressionIsAggregate)(e.expressionType)?!1:(0,XT.expressionInvolvesAggregate)(e.expressionType)&&(0,XT.expressionIsAnalytic)(e.expressionType)?(this.logError("aggregate-analytic-in-select","Cannot add aggregate analyics to select"),!1):!0}}JT.ProjectFieldSpace=pft;var lf={},Od={};Object.defineProperty(Od,"__esModule",{value:!0}),Od.Ordering=Od.OrderBy=void 0;const mft=et,hce=rf,pce=Ze,gft=zn;class yft extends pce.MalloyElement{constructor(e,r){super(),this.field=e,this.dir=r,this.elementType="orderBy",e instanceof hce.FieldName&&this.has({field:e})}get modelField(){return typeof this.field=="number"?this.field:this.field.refString}getOrderBy(e){var r;if(this.field instanceof hce.FieldName&&e.isQueryFieldSpace()){const s=e.outputSpace(),o=this.field.getField(s);o.error&&this.field.logError(o.error.code,o.error.message),(!o.found||!o.isOutputField)&&this.logError("order-by-not-found-in-output",`Unknown field ${this.field.refString} in output space`),(0,mft.expressionIsAnalytic)((r=o.found)===null||r===void 0?void 0:r.typeDesc().expressionType)&&this.logError("order-by-analytic",`Illegal order by of analytic field ${this.field.refString}`)}const i={field:this.modelField};return this.dir&&(i.dir=this.dir),i}}Od.OrderBy=yft;class Eft extends pce.ListOf{constructor(e){super(e),this.elementType="ordering",this.queryRefinementStage=gft.LegalRefinementStage.Tail,this.forceQueryClass=void 0}getOrderBy(e){return this.list.map(r=>r.getOrderBy(e))}}Od.Ordering=Eft,Object.defineProperty(lf,"__esModule",{value:!0}),lf.ReduceBuilder=lf.QuerySegmentBuilder=void 0;const Ou=et,Aft=gi,_ft=rf,vft=nf,Cft=Od,Sft=Du,bft=Qs,wk=dt;function mce(t){return t.type==="fieldref"?t.path[t.path.length-1]:t.name}class gce{constructor(){this.alwaysJoins=[],this.filters=[]}execute(e){if(e.queryExecute){e.queryExecute(this);return}e instanceof bft.DefinitionList?this.resultFS.pushFields(...e.list):e instanceof vft.Limit?this.limit?e.logError("limit-already-specified","Query operation already limited"):this.limit=e.limit:e instanceof Cft.Ordering&&(this.order?e.logError("ordering-already-specified","Query operation already sorted"):this.order=e)}get compositeFieldUsage(){return this.resultFS.compositeFieldUsage}refineFrom(e,r){var i;e&&e.type!=="index"&&e.type!=="raw"&&(!this.limit&&e.orderBy&&!e.defaultOrderBy&&(r.orderBy=e.orderBy),!this.limit&&e.limit&&(r.limit=e.limit)),this.order&&(r.orderBy=this.order.getOrderBy(this.inputFS),delete r.defaultOrderBy),this.limit&&(r.limit=this.limit);const s=(e==null?void 0:e.filterList)||[];this.filters.length>0&&!s?r.filterList=this.filters:s&&(r.filterList=[...s,...this.filters]),this.alwaysJoins.length>0&&(r.alwaysJoins=[...this.alwaysJoins]);const o=e&&(0,Ou.isQuerySegment)(e)&&(i=e.compositeFieldUsage)!==null&&i!==void 0?i:(0,wk.emptyCompositeFieldUsage)();r.compositeFieldUsage=(0,wk.mergeCompositeFieldUsage)(o,this.compositeFieldUsage)}}lf.QuerySegmentBuilder=gce;class Tft extends gce{constructor(e,r,i,s){super(),this.type="grouping",this.resultFS=new Sft.ReduceFieldSpace(e,r,i,s),this.inputFS=this.resultFS.inputSpace()}finalize(e){let r;if(e)if((0,Ou.isReduceSegment)(e)||(0,Ou.isPartialSegment)(e))r=e;else return this.resultFS.logError("incompatible-segment-for-reduce-refinement",`Can't refine reduce with ${e.type}`),Aft.ErrorFactory.reduceSegment;const i=this.resultFS.getQuerySegment(r);if(this.refineFrom(r,i),i.orderBy){for(const s of i.orderBy)if(typeof s.field=="number"){const o=i.queryFields[s.field-1];s.field=mce(o)}}if(i.orderBy===void 0||i.defaultOrderBy){let s;for(const o of i.queryFields){let u=!1,a=!1,l;const c=mce(o);if(o.type==="fieldref"){const f=o.path.map(h=>new _ft.FieldName(h)),x=this.inputFS.lookup(f).found;if(x){const h=x.typeDesc();l=h.type,u=(0,Ou.expressionIsAggregate)(h.expressionType),a=(0,Ou.expressionIsAnalytic)(h.expressionType)}else continue}else l=o.type,u=(0,Ou.hasExpression)(o)&&(0,Ou.expressionIsAggregate)(o.expressionType),a=(0,Ou.hasExpression)(o)&&(0,Ou.expressionIsAnalytic)(o.expressionType);if((0,Ou.isTemporalType)(l)||u){i.defaultOrderBy=!0,i.orderBy=[{field:c,dir:"desc"}],s=void 0;break}(0,Ou.canOrderBy)(l)&&!a&&!s&&(s=c)}s&&(i.defaultOrderBy=!0,i.orderBy=[{field:s,dir:"asc"}])}return i}}lf.ReduceBuilder=Tft,Object.defineProperty(KT,"__esModule",{value:!0}),KT.ProjectBuilder=void 0;const yce=et,Rft=gi,Dft=kE,Oft=JT,Fft=lf;class wft extends Fft.QuerySegmentBuilder{constructor(e,r,i,s){super(),this.type="project",this.resultFS=new Oft.ProjectFieldSpace(e,r,i,s),this.inputFS=this.resultFS.inputSpace()}execute(e){e.elementType==="having"||e instanceof Dft.GroupBy?e.logError("illegal-operation-in-select-segment","Illegal statement in a select query operation"):super.execute(e)}finalize(e){let r;if(e)if((0,yce.isProjectSegment)(e)||(0,yce.isPartialSegment)(e))r=e;else return this.resultFS.logError("incompatible-segment-for-select-refinement",`Can't refine select with ${e.type}`),Rft.ErrorFactory.projectSegment;const i=this.resultFS.getQuerySegment(r);return this.refineFrom(r,i),i}}KT.ProjectBuilder=wft;var ZT={};Object.defineProperty(ZT,"__esModule",{value:!0}),ZT.PartialBuilder=void 0;const Nft=Gi,Lft=lf;class Ift extends Lft.ReduceBuilder{finalize(e){const r=super.finalize(e);if((0,Nft.isQuerySegment)(r))return{...r,type:"partial"};throw new Error(`Partial Builder cannot finalize from ${r.type}`)}}ZT.PartialBuilder=Ift,Object.defineProperty(IE,"__esModule",{value:!0}),IE.QOpDesc=void 0;const $ft=VT,Bft=KT,kft=lf,Mft=Ze,Pft=zs,Uft=Wr,Fd=zn,jft=ZT;class qft extends Mft.ListOf{constructor(){super(...arguments),this.elementType="queryOperation"}computeType(){var e;let r,i=!1;this.refineThis&&(this.refineThis.type==="reduce"?r=Fd.QueryClass.Grouping:this.refineThis.type==="project"?r=Fd.QueryClass.Project:this.refineThis.type==="index"&&(r=Fd.QueryClass.Index));for(const s of this.list)s.forceQueryClass&&(r?r!==s.forceQueryClass&&s.logError(`illegal-${r}-operation`,`Not legal in ${r} query`):r=s.forceQueryClass),i||(i=(e=s.needsExplicitQueryClass)!==null&&e!==void 0?e:!1);return r===void 0&&i&&(this.logError("ambiguous-view-type",{}),r=Fd.QueryClass.Project),this.opClass=r,r}refineFrom(e){this.refineThis=e}getBuilder(e,r,i){switch(this.computeType()){case Fd.QueryClass.Grouping:return new kft.ReduceBuilder(e,this.refineThis,r,i);case Fd.QueryClass.Project:return new Bft.ProjectBuilder(e,this.refineThis,r,i);case Fd.QueryClass.Index:return new $ft.IndexBuilder(e,this.refineThis,r,i);case void 0:return new jft.PartialBuilder(e,this.refineThis,r,i)}}getOp(e,r){const i=this.getBuilder(e,r,this);for(const o of this.list)i.execute(o);const s=i.finalize(this.refineThis);return{segment:s,outputSpace:()=>new Uft.StaticSourceSpace((0,Pft.opOutputStruct)(this,e.structDef(),s))}}}IE.QOpDesc=qft,Object.defineProperty(GT,"__esModule",{value:!0}),GT.QOpDescView=void 0;const Hft=et,Qft=Wr,Ece=IE,zft=zs,Nk=zn,Wft=af;class Gft extends Wft.View{constructor(e){super({operation:e}),this.operation=e,this.elementType="qopdesc-view"}pipelineComp(e,r){const i=this.operation.getOp(e,r);return{pipeline:[i.segment],outputStruct:i.outputSpace().structDef()}}getOp(e,r,i,s){return(0,Hft.isRawSegment)(s)?(this.logError("refinement-of-raw-query","A raw query cannot be refined"),s):(i.refineFrom(s),i.getOp(e,r).segment)}refine(e,r,i){const s=[...r];if(s.length===0)return s;if(s.length===1)return this.operation.refineFrom(s[0]),[this.getOp(e,i,this.operation,s[0])];const o=new Ece.QOpDesc([]),u=new Ece.QOpDesc([]);for(const a of this.operation.list)switch(a.queryRefinementStage){case Nk.LegalRefinementStage.Head:o.push(a);break;case Nk.LegalRefinementStage.Single:a.logError("illegal-multistage-refinement-operation","Illegal in refinement of a query with more than one stage");break;case Nk.LegalRefinementStage.Tail:u.push(a);break;default:a.logError("illegal-refinement-operation","Illegal query refinement")}if(o.notEmpty()&&(this.has({headRefinements:o}),s[0]=this.getOp(e,void 0,o,s[0])),u.notEmpty()){const a=s.length-1;this.has({tailRefinements:u});const l=(0,zft.getFinalStruct)(this,e.structDef(),s.slice(-1));s[a]=this.getOp(new Qft.StaticSourceSpace(l),void 0,u,s[a])}return s}getImplicitName(){}}GT.QOpDescView=Gft;var wn={},Vft=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),Yft=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),Kft=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&Vft(e,t,r);return Yft(e,t),e};Object.defineProperty(wn,"__esModule",{value:!0}),wn.FieldDefinitionValue=wn.DefSpace=wn.DimensionFieldDeclaration=wn.MeasureFieldDeclaration=wn.DeclareFieldDeclaration=wn.ProjectFieldDeclaration=wn.GroupByFieldDeclaration=wn.AggregateFieldDeclaration=wn.CalculateFieldDeclaration=wn.AtomicFieldDeclaration=void 0;const Lk=et,Ace=Kft(nn),Jft=j2,Xft=Ze,wd=lr,Zft=Qr,ext=zr;class cf extends Xft.MalloyElement{constructor(e,r,i){super({expr:e}),this.expr=e,this.defineName=r,this.exprSrc=i,this.isNoteableObj=!0,this.extendNote=Zft.extendNoteMethod}getName(){return this.defineName}fieldDef(e,r){return this.queryFieldDef(new Ik(e,this),r)}executesInOutputSpace(){return!1}queryFieldDef(e,r){let i;function s(){if(e.isQueryFieldSpace())return e.outputSpace();throw new Error("must be in a query -- weird internal error")}try{const u=this.executesInOutputSpace()?s():e;i=this.expr.getExpression(u)}catch(u){return this.logError("failed-field-definition",`Cannot define '${r}', ${u.message}`),{name:r,type:"error"}}if(i.type==="null"&&(this.expr.logWarning("null-typed-field-definition",'null value defaults to type number, use "null::TYPE" to specify correct type'),i={type:"number",value:i.value,expressionType:i.expressionType,evalSpace:i.evalSpace,compositeFieldUsage:i.compositeFieldUsage}),(0,Lk.isAtomicFieldType)(i.type)&&i.type!=="error"){this.typecheckExprValue(i);const u=(0,Lk.mkFieldDef)(Ace.atomicDef(i),r);return(u.type==="date"||u.type==="timestamp")&&(0,Jft.isGranularResult)(i)&&(u.timeframe=i.timeframe),u.location=this.location,u.e=i.value,u.compositeFieldUsage=i.compositeFieldUsage,i.expressionType&&(u.expressionType=i.expressionType),this.exprSrc&&(u.code=this.exprSrc),this.note&&(u.annotation=this.note),u}if(!(e instanceof Ik&&e.foundCircle)&&i.type!=="error"){const u=Ace.inspect(i);this.logError("invalid-type-for-field-definition",`Cannot define '${r}', unexpected type: ${u}`)}return{name:r,type:"error"}}makeEntry(e){e.newEntry(this.defineName,this,new _ce(e,this))}}wn.AtomicFieldDeclaration=cf;class txt extends cf{constructor(){super(...arguments),this.elementType="calculateFieldDeclaration"}typecheckExprValue(e){(0,wd.typecheckCalculate)(e,this)}executesInOutputSpace(){return!0}}wn.CalculateFieldDeclaration=txt;class nxt extends cf{constructor(){super(...arguments),this.elementType="aggregateFieldDeclaration"}typecheckExprValue(e){(0,wd.typecheckAggregate)(e,this)}}wn.AggregateFieldDeclaration=nxt;class rxt extends cf{constructor(){super(...arguments),this.elementType="groupByFieldDeclaration"}typecheckExprValue(e){(0,wd.typecheckGroupBy)(e,this)}}wn.GroupByFieldDeclaration=rxt;class ixt extends cf{constructor(){super(...arguments),this.elementType="projectFieldDeclaration"}typecheckExprValue(e){(0,wd.typecheckProject)(e,this)}}wn.ProjectFieldDeclaration=ixt;class sxt extends cf{constructor(){super(...arguments),this.elementType="declareFieldDeclaration"}typecheckExprValue(e){(0,wd.typecheckDeclare)(e,this)}}wn.DeclareFieldDeclaration=sxt;class oxt extends cf{constructor(){super(...arguments),this.elementType="measureFieldDeclaration"}typecheckExprValue(e){(0,wd.typecheckMeasure)(e,this)}}wn.MeasureFieldDeclaration=oxt;class uxt extends cf{constructor(){super(...arguments),this.elementType="dimensionFieldDeclaration"}typecheckExprValue(e){(0,wd.typecheckDimension)(e,this)}}wn.DimensionFieldDeclaration=uxt;class Ik{constructor(e,r){this.realFS=e,this.circular=r,this.type="fieldSpace",this.foundCircle=!1}structDef(){return this.realFS.structDef()}emptyStructDef(){return this.realFS.emptyStructDef()}entry(e){return this.realFS.entry(e)}lookup(e){return e[0]&&e[0].refString===this.circular.defineName?(this.foundCircle=!0,{error:{message:`Circular reference to '${this.circular.defineName}' in definition`,code:"circular-reference-in-field-definition"},found:void 0}):this.realFS.lookup(e)}entries(){return this.realFS.entries()}dialectName(){return this.realFS.dialectName()}dialectObj(){return this.realFS.dialectObj()}isQueryFieldSpace(){return this.realFS.isQueryFieldSpace()}outputSpace(){if(this.realFS.isQueryFieldSpace())return this.realFS.outputSpace();throw new Error("Not a query field space")}inputSpace(){if(this.realFS.isQueryFieldSpace())return this.realFS.inputSpace();throw new Error("Not a query field space")}isProtectedAccessSpace(){return!0}}wn.DefSpace=Ik;class _ce extends ext.SpaceField{constructor(e,r){super(),this.space=e,this.exprDef=r,this.fieldName=r.defineName}get name(){return this.fieldName}fieldDef(){var e;const r=(e=this.defInSource)!==null&&e!==void 0?e:this.exprDef.fieldDef(this.space,this.name);return this.defInSource=r,r}getQueryFieldDef(e){if(!this.defInQuery){const r=this.exprDef.queryFieldDef(e,this.name);this.defInQuery=r}return this.defInQuery}typeDesc(){const e=this.defInQuery||this.fieldDef();if((0,Lk.isAtomic)(e))return this.fieldTypeFromFieldDef(e);throw new Error(`Can't get typeDesc for ${e.type}`)}}wn.FieldDefinitionValue=_ce;var eR={};Object.defineProperty(eR,"__esModule",{value:!0}),eR.Aggregate=void 0;const axt=Qs,vce=zn;class lxt extends axt.DefinitionList{constructor(){super(...arguments),this.elementType="aggregateList",this.queryRefinementStage=vce.LegalRefinementStage.Single,this.forceQueryClass=vce.QueryClass.Grouping}}eR.Aggregate=lxt;var tR={};Object.defineProperty(tR,"__esModule",{value:!0}),tR.Calculate=void 0;const cxt=Qs,fxt=zn;class xxt extends cxt.DefinitionList{constructor(){super(...arguments),this.elementType="calculate",this.forceQueryClass=void 0,this.needsExplicitQueryClass=!0,this.queryRefinementStage=fxt.LegalRefinementStage.Single}}tR.Calculate=xxt;var ME={};Object.defineProperty(ME,"__esModule",{value:!0}),ME.Dimensions=void 0;const dxt=Yc;class hxt extends dxt.DeclareFields{constructor(){super(...arguments),this.elementType="dimensionList"}}ME.Dimensions=hxt;var PE={};Object.defineProperty(PE,"__esModule",{value:!0}),PE.Measures=void 0;const pxt=Yc;class mxt extends pxt.DeclareFields{constructor(){super(...arguments),this.elementType="measureList"}}PE.Measures=mxt;var nR={};Object.defineProperty(nR,"__esModule",{value:!0}),nR.Nests=void 0;const gxt=Qs,Cce=zn;class yxt extends gxt.DefinitionList{constructor(e){super(e),this.elementType="nestedQueries",this.queryRefinementStage=Cce.LegalRefinementStage.Single,this.forceQueryClass=Cce.QueryClass.Grouping}}nR.Nests=yxt;var rR={};Object.defineProperty(rR,"__esModule",{value:!0}),rR.ProjectStatement=void 0;const Ext=Qs,Sce=zn;class Axt extends Ext.DefinitionList{constructor(){super(...arguments),this.elementType="projectStatement",this.forceQueryClass=Sce.QueryClass.Project,this.queryRefinementStage=Sce.LegalRefinementStage.Single}queryExecute(e){e.type==="project"&&e.resultFS.pushFields(...this.list)}}rR.ProjectStatement=Axt;var ff={},_0={},Pn={};Object.defineProperty(Pn,"__esModule",{value:!0}),Pn.getPlainString=Pn.unIndent=Pn.getOptionalId=Pn.idToStr=Pn.getId=Pn.getStringParts=Pn.getStringIfShort=Pn.getShortString=void 0;const bce=$o;function Tce(t){var e,r;const i=((e=t.DQ_STRING())===null||e===void 0?void 0:e.text)||((r=t.SQ_STRING())===null||r===void 0?void 0:r.text);return i?bce.ParseUtil.parseString(i,i[0]):""}Pn.getShortString=Tce;function Rce(t){const e=t.string().shortString();if(e)return Tce(e)}Pn.getStringIfShort=Rce;function*Dce(t){var e;if(t){for(const i of t.sqlInterpolation()){const s=i.OPEN_CODE().text;s.length>2&&(yield s.slice(0,s.length-2)),i.sqExpr()&&(yield i.sqExpr())}const r=(e=t.SQL_END())===null||e===void 0?void 0:e.text.slice(0,-3);r&&r.length>0&&(yield r)}}Pn.getStringParts=Dce;function Oce(t){return Fce(t.id())}Pn.getId=Oce;function Fce(t){const e=t.BQ_STRING();return e?bce.ParseUtil.parseString(e.text,"`"):t.text}Pn.idToStr=Fce;function _xt(t){function e(r){return"id"in r}if(e(t)&&t.id())return Oce(t)}Pn.getOptionalId=_xt;function*wce(t){for(;t.length>0;){const e=t.match(/^.*?\r?\n/);let r=t;e&&(r=e[0]),yield r,t=t.slice(r.length)}}function vxt(t){let e;for(const r of wce(t)){const i=r.match(/^( *).*[^\s]/);if(i){const s=i[1].length;(e===void 0||s<e)&&(e=s)}}return e}function Nce(t){let e;for(const r of t)if(typeof r=="string"){const i=vxt(r);i!==void 0&&(e===void 0||i<e)&&(e=i)}if(e)for(let r=0;r<=t.length;r+=1){const i=t[r];if(typeof i=="string"){let s="";for(let o of wce(i))o[0]===" "&&(o=o.slice(e)),s+=o;t[r]=s}}}Pn.unIndent=Nce;function Cxt(t,e=!1){const r=[],i=Rce(t);if(i)return[i,r];const s=[],o=t.string().sqlString();if(o){for(const u of Dce(o))if(typeof u=="string")s.push(u);else if(r.push(u),e)return[void 0,r];return Nce(s),[s.join(""),r]}return["",r]}Pn.getPlainString=Cxt,Object.defineProperty(_0,"__esModule",{value:!0}),_0.findReferences=_0.deprecatedParseTableURI=_0.constructTableKey=void 0;const Sxt=T0,$k=Pn;function Lce(t){const e=(0,$k.getStringIfShort)(t);if(e)return e;const r=[],i=t.string().sqlString();if(i){for(const s of(0,$k.getStringParts)(i))typeof s=="string"&&r.push(s);return r.join("")}return""}class bxt{constructor(e,r){this.trans=e,this.tokens=r,this.needTables={},this.needImports={}}registerTableReference(e,r,i){const s=Ice(e,r);this.needTables[s]||(this.needTables[s]={connectionName:e,tablePath:r,firstReference:i})}enterExploreTable(e){const r=(0,$k.getId)(e.connectionId()),i=Lce(e.tablePath()),s=this.trans.rangeFromContext(e);this.registerTableReference(r,i,s)}enterImportURL(e){const r=Lce(e);this.needImports[r]||(this.needImports[r]=this.trans.rangeFromContext(e))}}function Ice(t,e){return t===void 0?e:`${t}:${e}`}_0.constructTableKey=Ice;function Txt(t){const e=t.match(/^([^:]*):(.*)$/);if(e){const[,r,i]=e;return{connectionName:r,tablePath:i}}else return{tablePath:t}}_0.deprecatedParseTableURI=Txt;function Rxt(t,e,r){const i=new bxt(t,e),s=i;return Sxt.ParseTreeWalker.DEFAULT.walk(s,r),{tables:i.needTables,urls:i.needImports}}_0.findReferences=Rxt,Object.defineProperty(ff,"__esModule",{value:!0}),ff.TableFunctionSource=ff.TableMethodSource=ff.TableSource=void 0;const $ce=_0,Dxt=Ro,Bce=gi;class Bk extends Dxt.Source{getSourceDef(){var e,r,i;const s=this.getTableInfo();if(s===void 0)return Bce.ErrorFactory.structDef;const{tablePath:o,connectionName:u}=s,a=(0,$ce.constructTableKey)(u,o),l=(e=this.translator())===null||e===void 0?void 0:e.root.schemaZone.getEntry(a);let c=`Schema read failure for table '${o}' for connection '${u}'`;if(l){if(l.status==="present"){(r=this.document())===null||r===void 0||r.checkExperimentalDialect(this,l.value.dialect),l.value.location=this.location,l.value.fields.forEach(x=>{x.location=this.location});const f={...l.value,fields:l.value.fields.map(x=>({...x,location:this.location})),location:this.location};return(i=this.document())===null||i===void 0||i.rememberToAddModelAnnotations(f),f}l.status==="error"&&(c=l.message)}return this.logError("failed-to-fetch-table-schema",c),Bce.ErrorFactory.structDef}}ff.TableSource=Bk;class Oxt extends Bk{constructor(e,r){super(),this.connectionName=e,this.tablePath=r,this.elementType="tableMethodSource",this.has({connectionName:e})}getTableInfo(){var e;const r=this.modelEntry(this.connectionName),i=this.connectionName.refString;if(r===void 0)(e=this.namespace())===null||e===void 0||e.setEntry(i,{entry:{type:"connection",name:i},exported:!0},!0);else if(r.entry.type!=="connection"){this.connectionName.logError("invalid-connection-for-table-source",`${this.connectionName.refString} is not a connection`);return}return{tablePath:this.tablePath,connectionName:this.connectionName.refString}}}ff.TableMethodSource=Oxt;class Fxt extends Bk{constructor(e){super(),this.tableURI=e,this.elementType="tableFunctionSource"}getTableInfo(){return(0,$ce.deprecatedParseTableURI)(this.tableURI)}}ff.TableFunctionSource=Fxt;var iR={};Object.defineProperty(iR,"__esModule",{value:!0}),iR.SQLString=void 0;const wxt=Ze,kce=Tu;class Nxt extends wxt.MalloyElement{constructor(){super(...arguments),this.elementType="sqlString",this.elements=[],this.containsQueries=!1}complete(){this.has({queries:this.elements.filter(Lxt)})}push(e){typeof e=="string"?e.length>0&&this.elements.push(e):e instanceof kce.SourceQueryElement?(this.elements.push(e),this.containsQueries=!0,e.parent=this):e.logError("invalid-sql-source-interpolation","This element is not legal inside an SQL string")}sqlPhrases(){const e=[];for(const r of this.elements)if(typeof r=="string")e.push({sql:r});else{const i=r.getQuery();i?e.push(i.query()):r.sqLog("failed-to-expand-sql-source","Cannot expand into a query")}return e}}iR.SQLString=Nxt;function Lxt(t){return t instanceof kce.SourceQueryElement}var sR={};Object.defineProperty(sR,"__esModule",{value:!0}),sR.SourceDesc=void 0;const Ixt=Ze;class $xt extends Ixt.ListOf{constructor(){super(...arguments),this.elementType="sourceDescription"}}sR.SourceDesc=$xt;var oR={};Object.defineProperty(oR,"__esModule",{value:!0}),oR.isSourceProperty=void 0;const Bxt=qa,kxt=Yc,Mxt=I2,Pxt=Jc,Uxt=$2,jxt=B2,qxt=k2,Hxt=Kc,Qxt=ys;function zxt(t){return t instanceof Bxt.Filter||t instanceof Qxt.JoinStatement||t instanceof kxt.DeclareFields||t instanceof Mxt.FieldListEdit||t instanceof Pxt.Renames||t instanceof Uxt.PrimaryKey||t instanceof Hxt.ObjectAnnotation||t instanceof jxt.Views||t instanceof qxt.TimezoneStatement}oR.isSourceProperty=zxt;var uR={};Object.defineProperty(uR,"__esModule",{value:!0}),uR.isFieldCollectionMember=void 0;const Wxt=wn,Mce=_t;function Gxt(t){return t instanceof Mce.FieldReference||t instanceof Mce.WildcardFieldReference||t instanceof Wxt.AtomicFieldDeclaration}uR.isFieldCollectionMember=Gxt;var aR={};Object.defineProperty(aR,"__esModule",{value:!0}),aR.isQueryElement=void 0;const Vxt=M2,Yxt=P2,Kxt=_E,Jxt=vE;function Xxt(t){return t instanceof Vxt.QueryArrow||t instanceof Yxt.QueryRefine||t instanceof Kxt.QueryReference||t instanceof Jxt.QueryRaw}aR.isQueryElement=Xxt;var Pce={};Object.defineProperty(Pce,"__esModule",{value:!0});var lR={};Object.defineProperty(lR,"__esModule",{value:!0}),lR.isQueryProperty=void 0;function Zxt(t){return"queryRefinementStage"in t&&"forceQueryClass"in t}lR.isQueryProperty=Zxt;var cR={};Object.defineProperty(cR,"__esModule",{value:!0}),cR.isQueryExtendProperty=void 0;const edt=ME,tdt=ys,ndt=PE;function rdt(t){return t instanceof edt.Dimensions||t instanceof ndt.Measures||t instanceof tdt.JoinStatement}cR.isQueryExtendProperty=rdt;var fR={};Object.defineProperty(fR,"__esModule",{value:!0}),fR.isFieldPropStatement=void 0;const idt=tf,sdt=qa,odt=nf,udt=G2;function adt(t){return t instanceof sdt.Filter||t instanceof odt.Limit||t instanceof udt.PartitionBy||t instanceof idt.FunctionOrdering}fR.isFieldPropStatement=adt,function(t){var e=T&&T.__createBinding||(Object.create?function(i,s,o,u){u===void 0&&(u=o);var a=Object.getOwnPropertyDescriptor(s,o);(!a||("get"in a?!s.__esModule:a.writable||a.configurable))&&(a={enumerable:!0,get:function(){return s[o]}}),Object.defineProperty(i,u,a)}:function(i,s,o,u){u===void 0&&(u=o),i[u]=s[o]}),r=T&&T.__exportStar||function(i,s){for(var o in i)o!=="default"&&!Object.prototype.hasOwnProperty.call(s,o)&&e(s,i,o)};Object.defineProperty(t,"__esModule",{value:!0}),r(sE,t),r(O2,t),r(F2,t),r(Ro,t),r(aE,t),r(Tu,t),r(W4,t),r(G4,t),r(K4,t),r(pE,t),r(J4,t),r(X4,t),r(bu,t),r(I2,t),r($2,t),r(Jc,t),r(B2,t),r(k2,t),r(eT,t),r(H2,t),r(nT,t),r(Q2,t),r(tf,t),r(rT,t),r(E0,t),r(iT,t),r(W2,t),r(sT,t),r(oT,t),r(uT,t),r(y0,t),r(aT,t),r(lT,t),r(fT,t),r(DE,t),r(TE,t),r(bd,t),r(dT,t),r(hT,t),r(mT,t),r(yT,t),r(ET,t),r(AT,t),r(_T,t),r(sf,t),r(CT,t),r(ST,t),r(bT,t),r(TT,t),r(RT,t),r(DT,t),r(OT,t),r(wT,t),r(IT,t),r(Fr,t),r(kT,t),r(G2,t),r(Y2,t),r(J2,t),r(PT,t),r(Dd,t),r(ef,t),r(UT,t),r(OE,t),r(uf,t),r(NE,t),r(jT,t),r(qT,t),r(HT,t),r(P2,t),r(M2,t),r(af,t),r(QT,t),r(zT,t),r(WT,t),r(GT,t),r(wn,t),r(_t,t),r(eR,t),r(tR,t),r(Yc,t),r(ME,t),r(NE,t),r(qa,t),r(kE,t),r($E,t),r(ys,t),r(oE,t),r(nf,t),r(PE,t),r(sE,t),r(nR,t),r(Od,t),r(rR,t),r(IE,t),r(BE,t),r(U2,t),r(Sd,t),r(CE,t),r(ff,t),r(iR,t),r(Kc,t),r(Ru,t),r(sR,t),r(oR,t),r(ht,t),r(uR,t),r(rf,t),r(Ze,t),r(aR,t),r(Pce,t),r(lR,t),r(cR,t),r(fR,t)}(P4);var xR={},ldt=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),cdt=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),fdt=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&ldt(e,t,r);return cdt(e,t),e};Object.defineProperty(xR,"__esModule",{value:!0}),xR.MalloyToAST=void 0;const Uce=ng,xdt=qd,ue=fdt(P4),kk=T2,jce=xr,ddt=P4,Xn=Pn,dR=et,hdt=$o,qce=Jn,pdt=nE;class Hce extends ue.SourceQueryElement{constructor(){super(...arguments),this.elementType="parseErrorSourceQuery"}}class Mk extends ue.MalloyElement{constructor(e){super(),this.elementType="ignoredByParser",this.malloySrc=e}}const mdt=[];class gdt extends xdt.AbstractParseTreeVisitor{constructor(e,r,i){super(),this.parseInfo=e,this.msgLog=r,this.compilerFlags=i;for(const s of mdt){const o=hdt.Tag.fromTagLine(s,0,this.compilerFlags);this.compilerFlags=o.tag}}internalError(e,r){return this.contextError(e,"internal-translator-error",{message:r}),new Error(`Internal Translator Error: ${r}`)}astError(e,r,i,s){this.msgLog.log((0,kk.makeLogMessage)(r,i,{at:e.location,...s}))}rangeFromContext(e){return(0,qce.rangeFromContext)(this.parseInfo.sourceInfo,e)}getLocation(e){return{url:this.parseInfo.sourceURL,range:this.rangeFromContext(e)}}getSourceString(e){return this.parseInfo.sourceStream.getText(new jce.Interval(e.start.startIndex,e.stop?e.stop.stopIndex:e.start.startIndex))}contextError(e,r,i,s){this.msgLog.log((0,kk.makeLogMessage)(r,i,{at:this.getLocation(e),...s}))}warnWithReplacement(e,r,i,s){this.msgLog.log((0,kk.makeLogMessage)(e,r,{at:{url:this.parseInfo.sourceURL,range:i},severity:"warn",replacement:s}))}inExperiment(e,r){const i=this.compilerFlags.tag("experimental");return i&&(i.bare()||i.has(e))?!0:(this.contextError(r,"experiment-not-enabled",{experimentId:e}),!1)}only(e,r,i){const s=[];for(const o of e){const u=r(o);u?s.push(u):o instanceof Mk||this.astError(o,"unexpected-statement-in-translation",`Parser enountered unexpected statement type '${o.elementType}' when it needed '${i}'`)}return s}getNumber(e){return Number.parseInt(e.text)}getFieldName(e){return this.astAt(new ue.FieldName((0,Xn.getId)(e)),e.id())}getModelEntryName(e){return this.astAt(new ue.ModelEntryReference((0,Xn.getId)(e)),e.id())}defaultResult(){return new ue.Unimplemented}astAt(e,r){return e.location={url:this.parseInfo.sourceURL,range:this.rangeFromContext(r)},e}getSourceCode(e){const r=e.start.startIndex,i=e.stop||e.start,s=new jce.Interval(r,i.stopIndex);return this.parseInfo.sourceStream.getText(s)}getFilterElement(e){const r=this.getFieldExpr(e),i=new ue.FilterElement(r,this.getSourceCode(e));return this.astAt(i,e)}getFieldDefs(e,r){return e.map(i=>this.getFieldDef(i,r))}getFieldExpr(e){const r=this.visit(e);if(r instanceof ue.ExpressionDef)return this.astAt(r,e);throw this.internalError(e,`expression node unknown type '${r.elementType}'`)}getPlainStringFrom(e){const[r,i]=(0,Xn.getPlainString)(e);for(const s of i)s instanceof Uce.ParserRuleContext&&this.contextError(s,"illegal-query-interpolation-outside-sql-block","%{ query } illegal in this string");return r||""}makeSqlString(e,r){for(const i of(0,Xn.getStringParts)(e))i instanceof Uce.ParserRuleContext?r.push(this.visit(i)):r.push(i);r.complete(),this.astAt(r,e)}parseTime(e,r){let i=r(e.text);return i||(this.contextError(e,"failed-to-parse-time-literal","Time data parse error"),i=new ue.LiteralTimestamp({text:e.text})),this.astAt(i,e)}getNotes(e){return e.ANNOTATION().map(r=>({text:r.text,at:this.getLocation(e)}))}getIsNotes(e){return this.getNotes(e._beforeIs).concat(this.getNotes(e._afterIs))}visitMalloyDocument(e){const r=this.only(e.malloyStatement().map(i=>this.visit(i)),i=>ue.isDocStatementOrDocStatementList(i)&&i,"statement");return new ue.Document(r)}visitDefineSourceStatement(e){const i=e.sourcePropertyList().sourceDefinition().map(u=>this.visitSourceDefinition(u)),s=this.getNotes(e.tags()),o=new ue.DefineSourceList(i);return o.extendNote({blockNotes:s}),o}getSourceParameter(e){const r=(0,Xn.getId)(e.parameterNameDef());let i,s;const o=e.legalParamType();if(o){const l=o.malloyType();if(l){const f=this.getMalloyType(l);(0,pdt.isFilterable)(f)?s=f:this.contextError(o,"parameter-illegal-default-type",`Unknown filter type ${f}`)}const c=o.FILTER()?"filter expression":o.text.toLowerCase();if(!(0,dR.isParameterType)(c))return this.contextError(o,"parameter-illegal-default-type",`Unknown parameter type ${c}`),null;i=c}const u=e.fieldExpr();let a;if(u){const l=new ue.ConstantExpression(this.getFieldExpr(u));a=this.astAt(l,u)}return this.astAt(new ue.HasParameter({name:r,type:i,default:a,filterType:s}),e)}getSourceParameters(e){if(e===void 0)return[];this.inExperiment("parameters",e);function r(i){return i!==null}return e.sourceParameter().map(i=>this.getSourceParameter(i)).filter(r)}visitSourceDefinition(e){const r=this.visit(e.sqExplore()),i=this.getSourceParameters(e.sourceParameters()),s=new ue.DefineSource((0,Xn.getId)(e.sourceNameDef()),r instanceof ue.SourceQueryElement?r:void 0,!0,i),o=this.getNotes(e.tags()).concat(this.getIsNotes(e.isDefine()));return s.extendNote({notes:o}),this.astAt(s,e)}getSourceExtensions(e){return this.astAt(this.visitExploreProperties(e),e)}visitExploreProperties(e){const r=this.only(e.exploreStatement().map(s=>this.visit(s)),s=>ue.isSourceProperty(s)&&s,"source property");return new ue.SourceDesc(r)}visitExploreTable(e){const r=e.connectionId(),i=this.astAt(this.getModelEntryName(r),r),s=this.getPlainStringFrom(e.tablePath());return this.astAt(new ue.TableMethodSource(i,s),e)}visitSqlSource(e){const r=e.connectionId(),i=this.astAt(this.getModelEntryName(r),r),s=new ue.SQLString,o=e.sqlString();o&&this.makeSqlString(o,s);const u=e.shortString();u&&s.push((0,Xn.getShortString)(u));const a=new ue.SQLSource(i,s);return this.astAt(a,e)}visitDefJoinMany(e){const r=this.getAccessLabel(e.accessLabel()),i=[];for(const o of e.joinList().joinDef()){const u=this.visit(o);u instanceof ue.Join&&(i.push(u),u instanceof ue.ExpressionJoin?(u.joinType="many",u.joinOn===void 0&&this.contextError(e,"missing-on-in-join-many","join_many: requires ON expression")):u instanceof ue.KeyJoin&&this.contextError(e,"foreign-key-in-join-many","Foreign key join not legal in join_many:"))}const s=new ue.JoinStatement(i,r);return s.extendNote({blockNotes:this.getNotes(e.tags())}),s}visitDefJoinOne(e){const r=this.getAccessLabel(e.accessLabel()),i=this.getJoinList(e.joinList()),s=[];for(const u of i)u instanceof ue.Join&&(s.push(u),u instanceof ue.ExpressionJoin&&(u.joinType="one"));const o=new ue.JoinStatement(s,r);return o.extendNote({blockNotes:this.getNotes(e.tags())}),o}visitDefJoinCross(e){const r=this.getAccessLabel(e.accessLabel()),i=this.getJoinList(e.joinList()),s=[];for(const u of i)u instanceof ue.Join&&(s.push(u),u instanceof ue.ExpressionJoin?u.joinType="cross":u.logError("foreign-key-in-join-cross","Foreign key join not legal in join_cross:"));const o=new ue.JoinStatement(s,r);return o.extendNote({blockNotes:this.getNotes(e.tags())}),o}getJoinList(e){return this.only(e.joinDef().map(r=>this.visit(r)),r=>r instanceof ue.Join&&r,"join")}getJoinFrom(e){const r=e.isExplore(),i=this.getModelEntryName(e.joinNameDef());if(r){const o=this.getSqExpr(r.sqExpr()),u=this.getNotes(r._before_is).concat(this.getNotes(r._after_is));return{joinFrom:o,notes:u,joinAs:i}}const s=e.sourceArguments();return s?{joinFrom:this.astAt(new ue.SQReference(i,this.getSQArguments(s)),e),notes:[],joinAs:i}:{joinAs:i,joinFrom:new ue.SQReference(i),notes:[]}}visitQueryJoinStatement(e){return this.astAt(this.visit(e.joinStatement()),e)}visitJoinOn(e){var r;const{joinAs:i,joinFrom:s,notes:o}=this.getJoinFrom(e.joinFrom()),u=new ue.ExpressionJoin(i,s),a=e.joinExpression(),l=((r=e.matrixOperation())===null||r===void 0?void 0:r.text.toLocaleLowerCase())||"left";return(0,dR.isMatrixOperation)(l)?u.matrixOperation=l:this.contextError(e,"unknown-matrix-operation","Internal Error: Unknown matrixOperation"),a&&(u.joinOn=this.getFieldExpr(a)),u.extendNote({notes:this.getNotes(e).concat(o)}),this.astAt(u,e)}visitJoinWith(e){const{joinAs:r,joinFrom:i,notes:s}=this.getJoinFrom(e.joinFrom()),o=this.getFieldExpr(e.fieldExpr()),u=new ue.KeyJoin(r,i,o);return u.extendNote({notes:this.getNotes(e).concat(s)}),this.astAt(u,e)}getFieldDef(e,r){const i=e.fieldExpr(),s=(0,Xn.getId)(e.fieldNameDef()),o=this.getFieldExpr(i),u=new r(o,s,this.getSourceCode(i)),a=this.getNotes(e.tags()).concat(this.getIsNotes(e.isDefine()));return u.extendNote({notes:a}),this.astAt(u,e)}visitDefDimensions(e){const r=this.getAccessLabel(e.accessLabel()),i=this.getFieldDefs(e.defList().fieldDef(),ue.DimensionFieldDeclaration),s=new ue.Dimensions(i,r);return s.extendNote({blockNotes:this.getNotes(e.tags())}),this.astAt(s,e)}getAccessLabel(e){if(e!==void 0){if(e.INTERNAL_KW())return"internal";if(e.PRIVATE_KW())return"private";if(e.PUBLIC_KW())return"public";throw this.internalError(e,`Unknown access modifier label ${e.text}`)}}getAccessLabelProp(e){if(e!==void 0){if(e.INTERNAL())return"internal";if(e.PRIVATE())return"private";if(e.PUBLIC())return"public";throw this.internalError(e,`Unknown access modifier label ${e.text}`)}}visitDefMeasures(e){const r=this.getAccessLabel(e.accessLabel()),i=this.getFieldDefs(e.defList().fieldDef(),ue.MeasureFieldDeclaration),s=new ue.Measures(i,r);return s.extendNote({blockNotes:this.getNotes(e.tags())}),this.astAt(s,e)}visitQueryExtend(e){const r=[],i=e.queryExtendStatementList().queryExtendStatement().map(o=>this.visit(o));for(const o of i)if(ue.isQueryExtendProperty(o))r.push(o);else throw this.internalError(e,`Query extend matched, but ${o.elementType} found`);const s=new ue.ExtendBlock(r);return this.astAt(s,e)}visitExploreRenameDef(e){const r=e.fieldName(0),i=e.fieldName(1),s=new ue.RenameField((0,Xn.getId)(r),this.getFieldName(i));return this.astAt(s,e)}visitDefExploreRename(e){const r=this.getAccessLabel(e.accessLabel()),s=e.renameList().exploreRenameDef().map(u=>this.visitExploreRenameDef(u)),o=new ue.Renames(s,r);return this.astAt(o,e)}visitFilterClauseList(e){return new ue.Filter(e.fieldExpr().map(r=>this.getFilterElement(r)))}visitWhereStatement(e){const r=this.visitFilterClauseList(e.filterClauseList());return r.having=!1,this.astAt(r,e)}visitHavingStatement(e){const r=this.visitFilterClauseList(e.filterClauseList());return r.having=!0,this.astAt(r,e)}visitDefExploreQuery(e){const r=this.getAccessLabel(e.accessLabel()),i=e.subQueryDefList().exploreQueryDef().map(u=>this.visitExploreQueryDef(u)),s=new ue.Views(i,r),o=this.getNotes(e.tags());return s.extendNote({blockNotes:o}),s}visitDefExplorePrimaryKey(e){const r=new ue.PrimaryKey(this.getFieldName(e.fieldName()));return this.astAt(r,e)}getFieldNameList(e,r){const i=e.fieldName().map(s=>this.astAt(new r([this.getFieldName(s)]),s));return new ue.FieldReferences(i)}visitDefExploreEditField(e){const r=e.ACCEPT()?"accept":"except";return new ue.FieldListEdit(r,this.getFieldNameList(e.fieldNameList(),ue.AcceptExceptFieldReference))}visitSQInclude(e){const r=this.getSqExpr(e.sqExpr()),i=e.includeBlock(),s=i?this.getIncludeItems(i):void 0,o=new ue.SQExtend(r,new ue.SourceDesc([]),s);return this.astAt(o,e)}visitDefExploreTimezone(e){return this.visitTimezoneStatement(e.timezoneStatement())}visitTimezoneStatement(e){const r=this.getPlainStringFrom(e),i=this.astAt(new ue.TimezoneStatement(r),e.string());return i.isValid||this.astError(i,"invalid-timezone",{timezone:i.tz}),this.astAt(i,e)}visitQueryProperties(e){const r=this.only(e.queryStatement().map(i=>this.astAt(this.visit(i),i)),i=>ue.isQueryProperty(i)&&i,"query statement");return new ue.QOpDesc(r)}getFieldPath(e,r){const i=e.fieldName().map(s=>this.getFieldName(s));return this.astAt(new r(i),e)}getQueryFieldDef(e,r){const i=this.getFieldDef(e,r);return this.astAt(i,e)}getQueryFieldEntry(e,r,i){const s=e.taggedRef();if(s)return this.getTaggedRef(s,r,i);const o=e.fieldDef();if(o)return this.getQueryFieldDef(o,r);throw new Error("Expected query field entry to be a field reference or definition")}getQueryItems(e,r,i){return this.only(e.queryFieldEntry().map(s=>this.getQueryFieldEntry(s,r,i)),s=>s instanceof ue.FieldReference||s instanceof ue.AtomicFieldDeclaration?s:!1,"view field")}visitAggregateStatement(e){const r=new ue.Aggregate(this.getQueryItems(e.queryFieldList(),ue.AggregateFieldDeclaration,ue.AggregateFieldReference));return r.extendNote({blockNotes:this.getNotes(e.tags())}),r}visitGroupByStatement(e){const r=new ue.GroupBy(this.getQueryItems(e.queryFieldList(),ue.GroupByFieldDeclaration,ue.GroupByFieldReference));return r.extendNote({blockNotes:this.getNotes(e.tags())}),r}visitCalculateStatement(e){const r=new ue.Calculate(this.getQueryItems(e.queryFieldList(),ue.CalculateFieldDeclaration,ue.CalculateFieldReference));return r.extendNote({blockNotes:this.getNotes(e.tags())}),r}getTaggedRef(e,r,i){const s=e.refExpr();if(s){const u=this.getFieldPath(e.fieldPath(),ue.ExpressionFieldReference);let a;const l=s.timeframe();l&&(a=new ue.ExprGranularTime(new ue.ExprIdReference(u),this.visitTimeframe(l).text,!0));const c=s.aggregate();if(c){const x=c.text.toLowerCase();if(x==="sum")a=new ue.ExprSum(void 0,u);else return this.contextError(c,"invalid-reference-only-aggregation",`\`${x}\` is not legal in a reference-only aggregation`),u}const f=new r(a,u.outputName);return f.extendNote({notes:this.getNotes(e.tags())}),f}const o=this.getFieldPath(e.fieldPath(),i);return o.extendNote({notes:this.getNotes(e.tags())}),o}getFieldCollectionMember(e,r,i){const s=e.fieldDef();if(s)return this.getFieldDef(s,r);const o=e.taggedRef();if(o)return this.getTaggedRef(o,r,i);const u=e.collectionWildCard();if(u)return this.visitCollectionWildCard(u);throw this.internalError(e,"Unexpected element in fieldCollectionMember")}visitFieldCollection(e){const r=e.collectionMember().map(i=>this.getFieldCollectionMember(i,ue.ProjectFieldDeclaration,ue.ProjectFieldReference));return this.astAt(new ue.ProjectStatement(r),e)}visitProjectStatement(e){const r=this.visitFieldCollection(e.fieldCollection());return r.extendNote({blockNotes:this.getNotes(e.tags())}),r}visitCollectionWildCard(e){var r;const i=e.fieldPath(),s=i?this.getFieldPath(i,ue.ProjectFieldReference):void 0,o=this.astAt(new ue.WildcardFieldReference(s),e),u=((r=e.starQualified())===null||r===void 0?void 0:r.fieldNameList())||[];for(const a of u)for(const l of a.fieldName())o.except.add((0,Xn.getId)(l));return o}visitIndexFields(e){const r=e.indexElement().map(i=>{const s=i.fieldPath();if(!s)return this.astAt(new ue.WildcardFieldReference(void 0),e);const o=this.getFieldPath(s,ue.IndexFieldReference);return i.STAR()?this.astAt(new ue.WildcardFieldReference(o),e):this.astAt(o,e)});return new ue.FieldReferences(r)}visitIndexStatement(e){const r=this.visitIndexFields(e.indexFields()),i=new ue.Index(r),s=e.fieldName();return s&&i.useWeight(this.getFieldName(s)),this.astAt(i,e)}visitFieldPropertyLimitStatement(e){return this.inExperiment("aggregate_limit",e),this.visitLimitStatement(e.limitStatement())}visitLimitStatement(e){return new ue.Limit(this.getNumber(e.INTEGER_LITERAL()))}visitAggregateOrderBySpec(e){const r=e.ASC()?"asc":e.DESC()?"desc":void 0,i=e.fieldExpr(),s=i?this.getFieldExpr(i):void 0;return this.astAt(new ue.FunctionOrderBy(s,r),e)}visitAggregateOrderByStatement(e){return this.visitAggregateOrdering(e.aggregateOrdering())}visitAggregateOrdering(e){const r=e.aggregateOrderBySpec().map(i=>this.visitAggregateOrderBySpec(i));return this.astAt(new ue.FunctionOrdering(r),e)}visitOrderBySpec(e){const r=e.ASC()?"asc":e.DESC()?"desc":void 0,i=e.INTEGER_LITERAL();if(i)return new ue.OrderBy(this.getNumber(i),r);const s=e.fieldName();if(s)return new ue.OrderBy(this.getFieldName(s),r);throw this.internalError(e,"can't parse order_by specification")}visitOrdering(e){const r=e.orderBySpec().map(i=>this.visitOrderBySpec(i));return this.astAt(new ue.Ordering(r),e)}visitTopStatement(e){const r=this.getNumber(e.INTEGER_LITERAL());return this.astAt(new ue.Limit(r),e)}visitTopLevelQueryDefs(e){const r=e.topLevelQueryDef().map(o=>this.visitTopLevelQueryDef(o)),i=this.getNotes(e.tags()),s=new ue.DefineQueryList(r);return s.extendNote({blockNotes:i}),s}visitTopLevelQueryDef(e){const r=(0,Xn.getId)(e.queryName()),i=this.visit(e.sqExpr()),s=this.getNotes(e.tags()).concat(this.getIsNotes(e.isDefine()));if(i instanceof ue.SourceQueryElement){const o=new ue.DefineQuery(r,i);return o.extendNote({notes:s}),this.astAt(o,e)}throw this.internalError(e,`Expected query definition, got a '${i.elementType}'`)}visitRunStatement(e){const r=e.topLevelAnonQueryDef(),i=this.getSqExpr(r.sqExpr()),s=this.astAt(new ue.AnonymousQuery(i),r),o=this.getNotes(e.topLevelAnonQueryDef().tags()),u=this.getNotes(e.tags());return s.extendNote({notes:o,blockNotes:u}),this.astAt(s,e)}visitNestStatement(e){const r=this.visitNestedQueryList(e.nestedQueryList());return r.extendNote({blockNotes:this.getNotes(e.tags())}),r}visitNestedQueryList(e){return new ue.Nests(this.only(e.nestEntry().map(r=>this.visit(r)),r=>r instanceof ue.NestFieldDeclaration&&r,"query"))}visitNestDef(e){const r=e.queryName();let i;const s=this.getVExpr(e.vExpr());if(r)i=(0,Xn.getId)(r);else{const a=s.getImplicitName();a===void 0&&this.contextError(e,"anonymous-nest","`nest:` view requires a name (add `nest_name is ...`)"),i=a??"__unnamed__"}const o=new ue.NestFieldDeclaration(i,s),u=e.isDefine();return o.extendNote({notes:this.getNotes(e.tags()).concat(u?this.getIsNotes(u):[])}),this.astAt(o,e)}visitExploreQueryDef(e){const r=(0,Xn.getId)(e.exploreQueryNameDef()),i=new ue.ViewFieldDeclaration(r,this.getVExpr(e.vExpr())),s=this.getNotes(e).concat(this.getIsNotes(e.isDefine()));return i.extendNote({notes:s}),this.astAt(i,e)}visitExprNot(e){return new ue.ExprNot(this.getFieldExpr(e.fieldExpr()))}visitExprBool(e){return new ue.Boolean(e.TRUE()?"true":"false")}allFieldExpressions(e){return e.map(r=>this.getFieldExpr(r))}visitExprLogicalOr(e){const r=this.getFieldExpr(e.fieldExpr(0)),i=this.getFieldExpr(e.fieldExpr(1));return new ue.ExprLogicalOp(r,"or",i)}visitExprLogicalAnd(e){const r=this.getFieldExpr(e.fieldExpr(0)),i=this.getFieldExpr(e.fieldExpr(1));return new ue.ExprLogicalOp(r,"and",i)}visitExprOrTree(e){const r=this.getFieldExpr(e.fieldExpr()),i=this.getFieldExpr(e.partialAllowedFieldExpr());return this.astAt(new ue.ExprAlternationTree(r,"|",i),e)}visitExprAndTree(e){const r=this.getFieldExpr(e.fieldExpr()),i=this.getFieldExpr(e.partialAllowedFieldExpr());return this.astAt(new ue.ExprAlternationTree(r,"&",i),e)}visitExprCoalesce(e){const r=this.getFieldExpr(e.fieldExpr()[0]),i=this.getFieldExpr(e.fieldExpr()[1]);return this.astAt(new ue.ExprCoalesce(r,i),e)}visitPartialCompare(e){const r=e.compareOp().text;if(ue.isComparison(r))return this.astAt(new ue.PartialCompare(r,this.getFieldExpr(e.fieldExpr())),e);throw this.internalError(e,`partial comparison '${r}' not recognized`)}visitPartialTest(e){const r=e.partialCompare();return r?this.visitPartialCompare(r):this.astAt(new ue.PartialIsNull(e.NOT()?"!=":"="),e)}visitPartialAllowedFieldExpr(e){const r=e.fieldExpr();if(r)return this.getFieldExpr(r);const i=e.partialTest();if(i)return this.visitPartialTest(i);throw this.internalError(e,"impossible partial")}visitExprString(e){const r=this.getPlainStringFrom(e);return new ue.ExprString(r)}visitRawString(e){const r=e.text.slice(1).trimStart();if(r[r.length-1]===`
|
|
1556
|
-
`){const o=r[0]==="'"?'"':"'";this.contextError(e,"literal-string-newline",`Missing ${o}${r[0]}${o} before end-of-line`)}const s=new ue.ExprString(r.slice(1,-1));return this.astAt(s,e)}visitExprRegex(e){const r=e.HACKY_REGEX().text;return new ue.ExprRegEx(r.slice(2,-1))}visitExprNow(e){return new ue.ExprNow}visitExprNumber(e){return new ue.ExprNumber(e.text)}visitExprFieldPath(e){const r=new ue.ExprIdReference(this.getFieldPath(e.fieldPath(),ue.ExpressionFieldReference));return this.astAt(r,e)}visitExprNULL(e){return new ue.ExprNULL}visitExprExpr(e){return new ue.ExprParens(this.getFieldExpr(e.fieldExpr()))}visitExprMinus(e){return new ue.ExprMinus(this.getFieldExpr(e.fieldExpr()))}visitExprAddSub(e){const r=this.getFieldExpr(e.fieldExpr(0)),i=this.getFieldExpr(e.fieldExpr(1)),s=e.PLUS()?"+":"-";return new ue.ExprAddSub(r,s,i)}visitExprMulDiv(e){const r=e.STAR()?"*":e.SLASH()?"/":"%";return new ue.ExprMulDiv(this.getFieldExpr(e.fieldExpr(0)),r,this.getFieldExpr(e.fieldExpr(1)))}visitExprCompare(e){const r=e.compareOp().text,i=this.getFieldExpr(e.fieldExpr(0)),s=this.getFieldExpr(e.fieldExpr(1));if(ue.isEquality(r)){const o=this.rangeFromContext(e);return s instanceof ue.ExprNULL&&(r==="="?this.warnWithReplacement("sql-is-null","Use 'is null' to check for NULL instead of '= null'",o,`${this.getSourceCode(e.fieldExpr(0))} is null`):r==="!="&&this.warnWithReplacement("sql-is-not-null","Use 'is not null' to check for NULL instead of '!= null'",o,`${this.getSourceCode(e.fieldExpr(0))} is not null`)),this.astAt(new ue.ExprEquality(i,r,s),e)}else if(ue.isComparison(r))return this.astAt(new ue.ExprCompare(i,r,s),e);throw this.internalError(e,`untranslatable comparison operator '${r}'`)}visitExprUngroup(e){const r=e.fieldName().map(s=>this.getFieldName(s)),i=e.ungroup().text.toLowerCase();return this.astAt(new ue.ExprUngroup(i==="all"?i:"exclude",this.getFieldExpr(e.fieldExpr()),r),e)}symmetricAggregateUsageError(e){return`Symmetric aggregate function \`${e}\` must be written as \`${e}(expression)\` or \`path.to.field.${e}()\``}asymmetricAggregateUsageError(e){return`Asymmetric aggregate function \`${e}\` must be written as \`path.to.field.${e}()\`, \`path.to.join.${e}(expression)\`, or \`${e}(expression)\``}visitExprAggregate(e){const r=e.fieldPath(),i=this.getFieldPath(r,ue.ExpressionFieldReference),s=r&&i?this.astAt(i,r):void 0,o=e.aggregate().text.toLowerCase(),u=e.fieldExpr();if(e.aggregate().COUNT())return u&&this.contextError(u,"count-expression-with-locality","Expression illegal inside path.count()"),new ue.ExprCount(s);const a=u?this.getFieldExpr(u):void 0;if(o==="min"||o==="max")if(a)this.contextError(e,"invalid-symmetric-aggregate",this.symmetricAggregateUsageError(o));else{const l=this.astAt(new ue.ExprIdReference(i),r);return o==="min"?new ue.ExprMin(l):new ue.ExprMax(l)}else{if(o==="avg")return new ue.ExprAvg(a,s);if(o==="sum")return new ue.ExprSum(a,s);this.contextError(e,"aggregate-parse-error",`Cannot parse aggregate function ${o}`)}return new ue.ExprNULL}visitExprPathlessAggregate(e){const r=e.fieldExpr(),i=r?this.getFieldExpr(r):void 0,s=void 0,o=e.aggregate().text.toLowerCase();if(o==="count")return this.astAt(i?new ue.ExprCountDistinct(i):new ue.ExprCount,e);if(o==="min"){if(i)return new ue.ExprMin(i);this.contextError(e,"invalid-symmetric-aggregate",this.symmetricAggregateUsageError(o))}else if(o==="max"){if(i)return new ue.ExprMax(i);this.contextError(e,"invalid-symmetric-aggregate",this.symmetricAggregateUsageError(o))}else{if(i===void 0)return this.contextError(e,"invalid-asymmetric-aggregate",this.asymmetricAggregateUsageError(o)),new ue.ExprNULL;const u=e.SOURCE_KW()!==void 0;if(o==="avg")return new ue.ExprAvg(i,s,u);if(o==="sum")return new ue.ExprSum(i,s,u)}return new ue.ExprNULL}visitExprApply(e){return new ue.Apply(this.getFieldExpr(e.fieldExpr()),this.getFieldExpr(e.partialAllowedFieldExpr()))}visitExprRange(e){return new ue.Range(this.getFieldExpr(e.fieldExpr(0)),this.getFieldExpr(e.fieldExpr(1)))}visitExprCast(e){const r=this.getMalloyOrSQLType(e.malloyOrSQLType());return new ue.ExprCast(this.getFieldExpr(e.fieldExpr()),r)}getMalloyType(e){const r=e.text;if((0,dR.isCastType)(r))return r;throw this.internalError(e,`unknown type '${r}'`)}getMalloyOrSQLType(e){const r=e.malloyType();if(r)return this.getMalloyType(r);const i=e.string();if(i)return{raw:this.getPlainStringFrom({string:()=>i})};throw this.internalError(e,"Expected Malloy or SQL type to either be a Malloy type or a string")}visitExprSafeCast(e){const r=this.getMalloyOrSQLType(e.malloyOrSQLType());return new ue.ExprCast(this.getFieldExpr(e.fieldExpr()),r,!0)}visitExprTimeTrunc(e){return new ue.ExprGranularTime(this.getFieldExpr(e.fieldExpr()),this.visitTimeframe(e.timeframe()).text,!0)}visitTimeframe(e){return new ue.Timeframe(e.text)}visitExprForRange(e){const r=this.getFieldExpr(e._startAt),i=this.getFieldExpr(e._duration),s=this.visitTimeframe(e.timeframe());return new ue.ForRange(r,i,s)}visitExprAggFunc(e){const r=e.argumentList(),i=r?this.allFieldExpressions(r.fieldExpr()):[],s=(0,Xn.getId)(e),o=e.fieldPath(),u=o?this.getFieldPath(o,ue.ExpressionFieldReference):void 0,a=o&&u?this.astAt(u,o):void 0;return ue.ExprTimeExtract.extractor(s)?this.astAt(new ue.ExprTimeExtract(s,i),e):this.astAt(new ue.ExprFunc(s,i,!1,void 0,a),e)}visitExprFunc(e){var r,i;const s=e.argumentList(),o=s?this.allFieldExpressions(s.fieldExpr()):[],u=e.EXCLAM()!==void 0,a=(r=e.malloyType())===null||r===void 0?void 0:r.text;let l;a&&((0,dR.isCastType)(a)?l=a:(this.contextError(e,"unexpected-malloy-type",`'#' assertion for unknown type '${a}'`),l=void 0));let c=(0,Xn.getOptionalId)(e)||((i=e.timeframe())===null||i===void 0?void 0:i.text);return c===void 0&&(this.contextError(e,"failed-to-parse-function-name","Function name error"),c="FUNCTION_NAME_ERROR"),ue.ExprTimeExtract.extractor(c)?this.astAt(new ue.ExprTimeExtract(c,o),e):this.astAt(new ue.ExprFunc(c,o,u,l),e)}visitExprDuration(e){return new ue.ExprDuration(this.getFieldExpr(e.fieldExpr()),this.visitTimeframe(e.timeframe()).text)}visitCaseStatement(e){const r=e._valueExpr,i=r?this.getFieldExpr(r):void 0,s=e.caseWhen(),o=s.map(l=>new ue.CaseWhen(this.getFieldExpr(l._condition),this.getFieldExpr(l._result))),u=e._caseElse,a=u?this.getFieldExpr(u):void 0;return this.warnWithReplacement("sql-case","Use a `pick` statement instead of `case`",this.rangeFromContext(e),`${[...r?[`${this.getSourceCode(r)} ?`]:[],...s.map(l=>`pick ${this.getSourceCode(l._result)} when ${this.getSourceCode(l._condition)}`),u?`else ${u.text}`:"else null"].join(" ")}`),new ue.Case(i,o,a)}visitPickStatement(e){const r=e.pick().map(i=>{let s;return i._pickValue&&(s=this.getFieldExpr(i._pickValue)),new ue.PickWhen(s,this.getFieldExpr(i._pickWhen))});return e.ELSE()?new ue.Pick(r,this.getFieldExpr(e._pickElse)):new ue.Pick(r)}visitExprFieldProps(e){const r=this.only(e.fieldProperties().fieldPropertyStatement().map(i=>this.visit(i)),i=>ue.isFieldPropStatement(i)&&i,"field property statement");return new ue.ExprProps(this.getFieldExpr(e.fieldExpr()),r)}visitPartitionByStatement(e){return this.astAt(new ue.PartitionBy(e.id().map(r=>this.astAt(new ue.PartitionByFieldReference([this.astAt(new ue.FieldName((0,Xn.idToStr)(r)),r)]),r))),e)}visitLiteralTimestamp(e){return this.parseTime(e,ue.LiteralTimestamp.parse)}visitLiteralHour(e){return this.parseTime(e,ue.LiteralHour.parse)}visitLiteralDay(e){return this.parseTime(e,ue.LiteralDay.parse)}visitLiteralWeek(e){return this.parseTime(e,ue.LiteralWeek.parse)}visitLiteralMonth(e){return this.parseTime(e,ue.LiteralMonth.parse)}visitLiteralQuarter(e){return this.parseTime(e,ue.LiteralQuarter.parse)}visitLiteralYear(e){return this.parseTime(e,ue.LiteralYear.parse)}visitImportStatement(e){const r=this.getPlainStringFrom(e.importURL()),i=this.astAt(new ue.ImportStatement(r,this.parseInfo.importBaseURL),e),s=e.importSelect();if(s)for(const o of s.importItem()){const u=o.id(),a=u[1]?this.astAt(new ue.ImportSourceName((0,Xn.idToStr)(u[1])),u[1]):void 0;i.push(this.astAt(new ue.ImportSelect((0,Xn.idToStr)(u[0]),a),u[0]))}return i}visitDebugExpr(e){return this.getFieldExpr(e.fieldExpr())}visitSampleStatement(e){const r=e.sampleSpec().INTEGER_LITERAL();if(r)return new ue.SampleProperty({rows:this.getNumber(r)});const i=e.sampleSpec().PERCENT_LITERAL();if(i)return new ue.SampleProperty({percent:this.getNumber(i)});const s=e.sampleSpec().TRUE()!==void 0;return new ue.SampleProperty({enable:s})}visitDocAnnotations(e){const r=e.DOC_ANNOTATION().map(s=>({text:s.text,at:this.getLocation(e)})),i=new ue.ModelAnnotation(r);return this.compilerFlags=i.getCompilerFlags(this.compilerFlags,this.msgLog),i}visitIgnoredObjectAnnotations(e){return this.contextError(e,"orphaned-object-annotation","Object annotation not connected to any object"),new Mk(e.text)}visitIgnoredModelAnnotations(e){return this.contextError(e,"misplaced-model-annotation","Model annotations not allowed at this scope"),new Mk(e.text)}visitDefExploreAnnotation(e){const r=this.getNotes(e);return new ue.ObjectAnnotation(r)}getSQArgument(e){const r=e.argumentId(),i=r?this.astAt(new ue.PartitionByFieldReference([this.astAt(new ue.FieldName((0,Xn.idToStr)(r.id())),r)]),r):void 0;return this.astAt(new ue.Argument({id:i,value:this.getFieldExpr(e.fieldExpr())}),e)}getSQArguments(e){if(e!==void 0)return this.inExperiment("parameters",e),e.sourceArgument().map(r=>this.getSQArgument(r))}visitSQID(e){const r=this.getModelEntryName(e),i=this.getSQArguments(e.sourceArguments());return this.astAt(new ue.SQReference(r,i),e.id())}getSqExpr(e){const r=this.visit(e);return r instanceof ue.SourceQueryElement?r:(this.contextError(e,"unexpected-non-source-query-expression-node",`Expected a source/query expression, not '${r.elementType}'`),new Hce)}visitSQExtendedSource(e){const r=this.getSqExpr(e.sqExpr()),i=e.includeBlock(),s=i?this.getIncludeItems(i):void 0,o=new ue.SQExtend(r,this.getSourceExtensions(e.exploreProperties()),s);return this.astAt(o,e)}getIncludeItems(e){return this.inExperiment("access_modifiers",e),e.includeItem().map(r=>this.getIncludeItem(r)).filter(qce.isNotUndefined)}getIncludeItem(e){var r;const i=e.tags(),s=i?this.getNotes(i):[],o=e.includeExceptList();if(o){i&&s.length>0&&this.contextError(i,"cannot-tag-include-except","Tags on `except:` are ignored",{severity:"warn"});const u=this.getExcludeList(o);return this.astAt(new ue.IncludeExceptItem(u),e)}else{const u=e.includeList();if(u===void 0){this.contextError((r=e.orphanedAnnotation())!==null&&r!==void 0?r:e,"orphaned-object-annotation","This tag is not attached to anything",{severity:"warn"});return}const a=this.getAccessLabelProp(e.accessLabelProp()),l=this.getIncludeList(u),c=this.astAt(new ue.IncludeAccessItem(a,l),e);return c.extendNote({blockNotes:s}),c}}getIncludeList(e){const r=e.includeField();if(r===void 0)throw this.internalError(e,"Expected a field name list");return r.map(i=>this.getIncludeListItem(i))}getExcludeList(e){return e.includeExceptListItem().map(r=>{r.tags().ANNOTATION().length>0&&this.contextError(r.tags(),"cannot-tag-include-except","Tags on `except:` are ignored",{severity:"warn"});const i=r.fieldName();if(i)return this.astAt(new ue.AccessModifierFieldReference([this.astAt(this.getFieldName(i),r)]),i);const s=r.collectionWildCard();if(s)return this.astAt(this.visitCollectionWildCard(s),s);throw this.internalError(r,"Expected a field name or wildcard")})}getIncludeListItem(e){const r=e.collectionWildCard(),i=r?this.visitCollectionWildCard(r):void 0,s=e._as?e._as.text:void 0,o=e.tags(),u=o?this.getNotes(o):[],a=e.isDefine(),l=a?this.getIsNotes(a):[],c=[...u,...l],f=e._name?this.astAt(new ue.AccessModifierFieldReference([this.astAt(this.getFieldName(e._name),e._name)]),e._name):void 0,x=f??i;if(x===void 0)throw this.internalError(e,"Expected a field name or wildcard");const h=this.astAt(new ue.IncludeListItem(x,s),e);return h.extendNote({notes:c}),h}visitSQParens(e){const r=this.getSqExpr(e.sqExpr());return this.astAt(r,e)}visitSQCompose(e){const r=e.sqExpr().map(i=>this.getSqExpr(i));return this.inExperiment("composite_sources",e),this.astAt(new ue.SQCompose(r),e)}visitSQArrow(e){const r=this.getSqExpr(e.sqExpr()),i=e.segExpr(),s=new ue.SQArrow(r,this.getVExpr(i));return this.astAt(s,e)}getVExpr(e){const r=this.visit(e);if(r instanceof ue.View)return r;throw this.internalError(e,`Expected view, got a '${r.elementType}'`)}visitSegField(e){return new ue.ReferenceView(this.getFieldPath(e.fieldPath(),ue.ViewOrScalarFieldReference))}visitSegOps(e){return new ue.QOpDescView(this.visitQueryProperties(e.queryProperties()))}visitSegParen(e){return this.visit(e.vExpr())}visitVSeg(e){return this.visit(e.segExpr())}visitSegRefine(e){return new ue.ViewRefine(this.getVExpr(e._lhs),this.getVExpr(e._rhs))}visitVArrow(e){return new ue.ViewArrow(this.getVExpr(e._lhs),this.getVExpr(e._rhs))}visitSQRefinedQuery(e){const r=this.getSqExpr(e.sqExpr()),i=e.segExpr(),s=new ue.SQRefine(r,this.getVExpr(i));return this.astAt(s,e)}visitSQTable(e){const r=this.visit(e.exploreTable());if(r instanceof ddt.TableSource){const i=new ue.SQSource(r);return this.astAt(i,e)}return new Hce}visitSQSQL(e){const r=new ue.SQSource(this.visitSqlSource(e.sqlSource()));return this.astAt(r,e)}visitExperimentalStatementForTesting(e){return this.inExperiment("compilerTestExperimentParse",e),this.astAt(new ue.ExperimentalExperiment("compilerTestExperimentTranslate"),e)}visitRecordRef(e){const r=new ue.ExprIdReference(this.getFieldPath(e.fieldPath(),ue.ExpressionFieldReference));return this.astAt(new ue.RecordElement({path:r}),e)}visitRecordExpr(e){const r=this.getFieldExpr(e.fieldExpr()),i=e.recordKey(),s=i?{key:(0,Xn.getId)(i),value:r}:{value:r};return this.astAt(new ue.RecordElement(s),e)}visitExprLiteralRecord(e){const r=this.only(e.recordElement().map(i=>this.astAt(this.visit(i),i)),i=>i instanceof ue.RecordElement&&i,"a legal record property description");return new ue.RecordLiteral(r)}visitExprArrayLiteral(e){const r=e.fieldExpr().map(s=>this.getFieldExpr(s)),i=new ue.ArrayLiteral(r);return this.astAt(i,e)}visitExprWarnLike(e){let r="~";const i=e.fieldExpr(0),s=e.fieldExpr(1),o=this.rangeFromContext(e);return e.NOT()?(r="!~",this.warnWithReplacement("sql-not-like","Use Malloy operator '!~' instead of 'NOT LIKE'",o,`${this.getSourceCode(i)} !~ ${this.getSourceCode(s)}`)):this.warnWithReplacement("sql-like","Use Malloy operator '~' instead of 'LIKE'",o,`${this.getSourceCode(i)} ~ ${this.getSourceCode(s)}`),this.astAt(new ue.ExprCompare(this.getFieldExpr(i),r,this.getFieldExpr(s)),e)}visitExprNullCheck(e){const r=e.fieldExpr();return this.astAt(new ue.ExprIsNull(this.getFieldExpr(r),e.NOT()?"!=":"="),e)}visitExprWarnIn(e){const r=this.getFieldExpr(e.fieldExpr()),i=!!e.NOT(),s=e.fieldExprList().fieldExpr(),o=this.astAt(new ue.ExprLegacyIn(r,i,s.map(u=>this.getFieldExpr(u))),e);return this.warnWithReplacement("sql-in",`Use = (a|b|c) instead of${i?" NOT":""} IN (a,b,c)`,this.rangeFromContext(e),`${this.getSourceCode(e.fieldExpr())} ${i?"!=":"="} (${s.map(u=>this.getSourceCode(u)).join(" | ")})`),o}visitTickFilterString(e){const r=e.text.slice(1).trimStart();if(r[r.length-1]===`
|
|
1557
|
-
`){const u=r[0]==="'"?'"':"'";this.contextError(e,"literal-string-newline",`Missing $${u}${r[0]}${u} before end-of-line`)}const s=r.slice(1,-1),o=new ue.ExprFilterExpression(s);return this.astAt(o,e)}visitTripFilterString(e){const i=e.text.slice(1).trimStart().slice(3,-3),s=new ue.ExprFilterExpression(i);return this.astAt(s,e)}}xR.MalloyToAST=gdt;var hR={};Object.defineProperty(hR,"__esModule",{value:!0}),hR.Zone=void 0;class ydt{constructor(){this.location={},this.zone=new Map}get(e){const r=this.zone.get(e);if((r==null?void 0:r.status)==="present")return r.value}getEntry(e){const r=this.zone.get(e);return r?r.firstReference||!this.location[e]?r:{...r,firstReference:this.location[e]}:{status:"error",message:"import reference failure"}}define(e,r){this.zone.set(e,{status:"present",value:r})}reference(e,r){const i=this.zone.get(e);(i==null?void 0:i.status)===void 0&&(this.zone.set(e,{status:"reference",firstReference:r}),this.location[e]=r)}getUndefined(){const e=[];for(const[r,i]of this.zone)i.status==="reference"&&e.push(r);return e.length>0?e:void 0}updateFrom(e,r){if(e)for(const[i,s]of Object.entries(e))s!==void 0&&this.define(i,s);if(r)for(const[i,s]of Object.entries(r))this.zone.set(i,{status:"error",message:s})}}hR.Zone=ydt;var pR={};Object.defineProperty(pR,"__esModule",{value:!0}),pR.walkForDocumentSymbols=void 0;const Edt=T0,Adt=Pn;class _dt{constructor(e,r,i,s){this.translator=e,this.tokens=r,this.scopes=i,this.symbols=s}popScope(){return this.scopes.pop()}peekScope(){return this.scopes[this.scopes.length-1]}enterTopLevelQueryDefs(e){const r=this.translator.rangeFromContext(e);e.topLevelQueryDef().length===1&&(this.blockRange=r)}enterTopLevelQueryDef(e){this.symbols.push({range:this.translator.rangeFromContext(e),name:e.queryName().text,type:"query",children:[],lensRange:this.blockRange}),this.blockRange=void 0}enterRunStatement(e){this.symbols.push({range:this.translator.rangeFromContext(e.topLevelAnonQueryDef()),name:"unnamed_query",type:"unnamed_query",children:[],lensRange:this.translator.rangeFromContext(e)})}enterDefineSourceStatement(e){const r=this.translator.rangeFromContext(e);e.sourcePropertyList().sourceDefinition().length===1&&(this.blockRange=r)}enterSourceDefinition(e){const r=this.translator.rangeFromContext(e);this.scopes.push({range:r,name:e.sourceNameDef().id().text,type:"explore",children:[],lensRange:this.blockRange}),this.blockRange=void 0}exitSourceDefinition(e){const r=this.popScope();r&&this.symbols.push(r)}enterDefExploreQuery(e){const r=this.translator.rangeFromContext(e);e.subQueryDefList().exploreQueryDef().length===1&&(this.blockRange=r)}enterExploreQueryDef(e){const r={range:this.translator.rangeFromContext(e),name:e.exploreQueryNameDef().id().text,type:"query",children:[],lensRange:this.blockRange},i=this.peekScope();i&&i.children.push(r),this.scopes.push(r),this.blockRange=void 0}exitExploreQueryDef(e){this.popScope()}getNestDefName(e){const r=e.queryName();if(r)return r.id().text;let i,s=!1;const o={enterVArrow(a){a.vExpr().enterRule(o)},enterVSeg(a){a.segExpr().enterRule(u)}},u={enterSegField(a){const l=a.fieldPath().fieldName();s||(i??(i=l[l.length-1].id().text))},enterSegParen(a){a.vExpr().enterRule(o)},enterSegRefine(a){a._lhs.enterRule(u)},enterSegOps(){i=void 0,s=!0}};return e.vExpr().enterRule(o),i}handleNestEntry(e){const r=this.getNestDefName(e);if(r===void 0)return;const i={range:this.translator.rangeFromContext(e),name:r,type:"query",children:[]},s=this.peekScope();return s&&s.children.push(i),i}enterNestDef(e){const r=this.handleNestEntry(e);r&&this.scopes.push(r)}exitNestDef(e){this.popScope()}enterFieldDef(e){const r={range:this.translator.rangeFromContext(e),name:e.fieldNameDef().id().text,type:"field",children:[]},i=this.peekScope();i&&i.children.push(r)}enterQueryFieldEntry(e){var r;const i=(r=e.taggedRef())===null||r===void 0?void 0:r.fieldPath();if(i===void 0)return;const s={range:this.translator.rangeFromContext(e),name:i.text,type:"field",children:[]},o=this.peekScope();o&&o.children.push(s)}enterExploreRenameDef(e){const r={range:this.translator.rangeFromContext(e),name:e.fieldName()[0].text,type:"field",children:[]},i=this.peekScope();i&&i.children.push(r)}enterJoinWith(e){this.handleJoinDef(e)}enterJoinOn(e){this.handleJoinDef(e)}handleJoinDef(e){const r={range:this.translator.rangeFromContext(e),name:e.joinFrom().joinNameDef().id().text,type:"join",children:[]},i=this.peekScope();i&&i.children.push(r)}enterImportStatement(e){const r=(0,Adt.getStringIfShort)(e.importURL());r&&this.scopes.push({range:this.translator.rangeFromContext(e),name:r,type:"import",children:[]})}exitImportStatement(){const e=this.popScope();e&&this.symbols.push(e)}enterImportSelect(e){const r=this.peekScope();if(r)for(const i of e.importItem()){const s={range:this.translator.rangeFromContext(e),name:i.text,type:"import_item",children:[]};r.children.push(s)}}}function vdt(t,e,r){const i=new _dt(t,e,[],[]),s=i;return Edt.ParseTreeWalker.DEFAULT.walk(s,r),i.symbols}pR.walkForDocumentSymbols=vdt;var mR={};Object.defineProperty(mR,"__esModule",{value:!0}),mR.walkForDocumentCompletions=void 0;const Cdt=T0,Sdt=["dimension","measure","join_one","join_many","join_cross","where","primary_key","rename","accept","except","query","declare"],bdt=["group_by","project","index","aggregate","top","limit","order_by","where","having","nest","declare"],Tdt=["source","explore","query","sql"];class Rdt{constructor(e,r,i){this.tokens=e,this.completions=r,this.position=i}rangeOf(e){const r=e.stop||e.start;return{start:{line:e.start.line-1,character:e.start.charPositionInLine},end:{line:r.line-1,character:r.stopIndex-(r.startIndex-r.charPositionInLine)+1}}}inRange(e){const{start:r,end:i}=e,s=this.position.line>r.line||this.position.line===r.line&&this.position.character>=r.character,o=this.position.line<i.line||this.position.line===i.line&&this.position.character<=i.character;return s&&o}enterExploreProperties(e){if(this.inRange(this.rangeOf(e))){let r=!1;for(const i of e.exploreStatement())this.inRange(this.rangeOf(i))&&(r=!0);if(!r)for(const i of Sdt)this.completions.push({type:"explore_property",text:`${i}: `})}}enterQueryProperties(e){if(this.inRange(this.rangeOf(e))){let r=!1;for(const i of e.queryStatement())this.inRange(this.rangeOf(i))&&(r=!0);if(!r)for(const i of bdt)this.completions.push({type:"query_property",text:`${i}: `})}}enterMalloyDocument(e){if(this.inRange(this.rangeOf(e))){let r=!1;for(const i of e.malloyStatement())this.inRange(this.rangeOf(i))&&(r=!0);if(!r)for(const i of Tdt)this.completions.push({type:"model_property",text:`${i}: `})}}}function Ddt(t,e,r){const i=new Rdt(t,[],r),s=i;return Cdt.ParseTreeWalker.DEFAULT.walk(s,e),i.completions}mR.walkForDocumentCompletions=Ddt;var gR={};Object.defineProperty(gR,"__esModule",{value:!0}),gR.walkForDocumentHelpContext=void 0;const Odt=s6;class Fdt extends Odt.AbstractParseTreeVisitor{constructor(e){super(),this.position=e,this.type=""}rangeOf(e){const r=e.stop||e.start;return{start:{line:e.start.line-1,character:e.start.charPositionInLine},end:{line:r.line-1,character:r.stopIndex-(r.startIndex-r.charPositionInLine)+1}}}inRange(e){return e.start.line<=this.position.line&&e.end.line>=this.position.line&&(this.position.line!==e.start.line||this.position.character>=e.start.character)&&(this.position.line!==e.end.line||this.position.character<=e.end.character)}defaultResult(){}visitChildren(e){let r=this.defaultResult();if(this.inRange(this.rangeOf(e))){r={type:this.type,token:e.start.text};const i=e.childCount;for(let s=0;s<i;s++){const u=e.getChild(s).accept(this);u&&(r=this.aggregateResult(r,u))}}return r}visitMalloyDocument(e){return this.inRange(this.rangeOf(e))?(this.type="model_property",this.visitChildren(e)):this.defaultResult()}visitExploreProperties(e){return this.inRange(this.rangeOf(e))?(this.type="explore_property",this.visitChildren(e)):this.defaultResult()}visitQueryProperties(e){return this.inRange(this.rangeOf(e))?(this.type="query_property",this.visitChildren(e)):this.defaultResult()}aggregateResult(e,r){return r}}function wdt(t,e){return new Fdt(e).visit(t)}gR.walkForDocumentHelpContext=wdt;var yR={};Object.defineProperty(yR,"__esModule",{value:!0}),yR.ReferenceList=void 0;const Ndt=Jn;class Ldt{constructor(e){this.sourceURL=e,this.references=[]}findIndexBefore(e){let r=0,i=this.references.length;for(;r<i;){const s=Math.floor((r+i)/2),o=this.references[s].location.range.end;o.line<e.line||o.line===e.line&&o.character<e.character?r=s+1:i=s}return r}add(e){if(e.location.url!==this.sourceURL)return;const r=this.findIndexBefore(e.location.range.end);r<this.references.length&&this.isPositionEqual(e,this.references[r])||this.references.splice(r,0,e)}isPositionEqual(e,r){const i=e.location.range,s=r.location.range;return i.start.line===s.start.line&&i.start.character===s.start.character&&i.end.line===s.end.line&&i.end.character===s.end.character}find(e){const r=this.findIndexBefore(e);if(r===this.references.length)return;const i=this.references[r];if((0,Ndt.locationContainsPosition)(i.location,e))return i}}yR.ReferenceList=Ldt;var ER={};Object.defineProperty(ER,"__esModule",{value:!0}),ER.isNeedResponse=void 0;function Idt(t){return!!t&&(t.tables||t.urls||t.compileSQL)!==void 0}ER.isNeedResponse=Idt;var AR={};Object.defineProperty(AR,"__esModule",{value:!0}),AR.walkForModelAnnotation=void 0;const $dt=T0;class Bdt{constructor(e,r,i){this.translator=e,this.tokens=r,this.parseInfo=i,this.notes=[]}getLocation(e){return{url:this.parseInfo.sourceURL,range:this.translator.rangeFromContext(e)}}enterDocAnnotations(e){const r=e.DOC_ANNOTATION().map(i=>({text:i.text,at:this.getLocation(e)}));this.notes.push(...r)}get annotation(){return{notes:this.notes}}}function kdt(t,e,r){const i=new Bdt(t,e,r),s=i;return $dt.ParseTreeWalker.DEFAULT.walk(s,r.root),i.annotation}AR.walkForModelAnnotation=kdt;var _R={};Object.defineProperty(_R,"__esModule",{value:!0}),_R.walkForTablePath=void 0;const Qce=Pn,Mdt=T0;class Pdt{constructor(e,r){this.translator=e,this.tokens=r,this.pathInfos=[]}enterExploreTable(e){const r=(0,Qce.getId)(e.connectionId()),[i,s]=(0,Qce.getPlainString)(e.tablePath(),!0);i!==void 0&&this.pathInfos.push({connectionId:r,tablePath:i,range:this.translator.rangeFromContext(e)})}}function Udt(t,e,r){const i=new Pdt(t,e),s=i;return Mdt.ParseTreeWalker.DEFAULT.walk(s,r.root),i.pathInfos}_R.walkForTablePath=Udt;var UE={},vR={},jdt=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),qdt=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),Hdt=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&jdt(e,t,r);return qdt(e,t),e};Object.defineProperty(vR,"__esModule",{value:!0}),vR.MalloyLexer=void 0;const Qdt=ph(),zdt=xl(),Wdt=P1(),Gdt=Ts,zce=Hdt(Cn);class ae extends zdt.Lexer{get vocabulary(){return ae.VOCABULARY}constructor(e){super(e),this._interp=new Wdt.LexerATNSimulator(ae._ATN,this)}get grammarFileName(){return"MalloyLexer.g4"}get ruleNames(){return ae.ruleNames}get serializedATN(){return ae._serializedATN}get channelNames(){return ae.channelNames}get modeNames(){return ae.modeNames}static get _ATN(){return ae.__ATN||(ae.__ATN=new Qdt.ATNDeserializer().deserialize(zce.toCharArray(ae._serializedATN))),ae.__ATN}}vR.MalloyLexer=ae,ae.ACCEPT=1,ae.AGGREGATE=2,ae.CALCULATE=3,ae.CALCULATION=4,ae.CONNECTION=5,ae.DECLARE=6,ae.DIMENSION=7,ae.EXCEPT=8,ae.EXTENDQ=9,ae.GROUP_BY=10,ae.HAVING=11,ae.INDEX=12,ae.INTERNAL=13,ae.JOIN_CROSS=14,ae.JOIN_ONE=15,ae.JOIN_MANY=16,ae.LIMIT=17,ae.MEASURE=18,ae.NEST=19,ae.ORDER_BY=20,ae.PARTITION_BY=21,ae.PRIMARY_KEY=22,ae.PRIVATE=23,ae.PROJECT=24,ae.PUBLIC=25,ae.QUERY=26,ae.RENAME=27,ae.RUN=28,ae.SAMPLE=29,ae.SELECT=30,ae.SOURCE=31,ae.TOP=32,ae.WHERE=33,ae.VIEW=34,ae.TIMEZONE=35,ae.ALL=36,ae.AND=37,ae.AS=38,ae.ASC=39,ae.AVG=40,ae.BOOLEAN=41,ae.BY=42,ae.CASE=43,ae.CAST=44,ae.CONDITION=45,ae.COUNT=46,ae.COMPOSE=47,ae.DATE=48,ae.DAY=49,ae.DESC=50,ae.DISTINCT=51,ae.ELSE=52,ae.END=53,ae.EXCLUDE=54,ae.EXTEND=55,ae.FALSE=56,ae.FILTER=57,ae.FULL=58,ae.FOR=59,ae.FROM=60,ae.HAS=61,ae.HOUR=62,ae.IMPORT=63,ae.INCLUDE=64,ae.INNER=65,ae.IS=66,ae.IN=67,ae.INTERNAL_KW=68,ae.JSON=69,ae.LAST=70,ae.LEFT=71,ae.LIKE=72,ae.MAX=73,ae.MIN=74,ae.MINUTE=75,ae.MONTH=76,ae.NOT=77,ae.NOW=78,ae.NULL=79,ae.NUMBER=80,ae.ON=81,ae.OR=82,ae.PICK=83,ae.PRIVATE_KW=84,ae.PUBLIC_KW=85,ae.QUARTER=86,ae.RIGHT=87,ae.SECOND=88,ae.STRING=89,ae.SOURCE_KW=90,ae.SUM=91,ae.SQL=92,ae.TABLE=93,ae.THEN=94,ae.THIS=95,ae.TIMESTAMP=96,ae.TO=97,ae.TRUE=98,ae.TURTLE=99,ae.WEEK=100,ae.WHEN=101,ae.WITH=102,ae.YEAR=103,ae.UNGROUPED=104,ae.HACKY_REGEX=105,ae.RAW_SQ=106,ae.RAW_DQ=107,ae.SQ3_FILTER=108,ae.SQ_FILTER=109,ae.DQ3_FILTER=110,ae.DQ_FILTER=111,ae.BQ3_FILTER=112,ae.BQ_FILTER=113,ae.SQ_STRING=114,ae.DQ_STRING=115,ae.BQ_STRING=116,ae.DOC_ANNOTATION=117,ae.ANNOTATION=118,ae.AMPER=119,ae.ARROW=120,ae.FAT_ARROW=121,ae.OPAREN=122,ae.CPAREN=123,ae.OBRACK=124,ae.CBRACK=125,ae.OCURLY=126,ae.CCURLY=127,ae.DOUBLECOLON=128,ae.TRIPLECOLON=129,ae.EXCLAM=130,ae.COLON=131,ae.COMMA=132,ae.DOT=133,ae.LT=134,ae.GT=135,ae.EQ=136,ae.NE=137,ae.LTE=138,ae.GTE=139,ae.PLUS=140,ae.MINUS=141,ae.STAR=142,ae.STARSTAR=143,ae.SLASH=144,ae.BAR=145,ae.SEMI=146,ae.NOT_MATCH=147,ae.MATCH=148,ae.PERCENT=149,ae.DOUBLE_QMARK=150,ae.QMARK=151,ae.LITERAL_TIMESTAMP=152,ae.LITERAL_HOUR=153,ae.LITERAL_DAY=154,ae.LITERAL_QUARTER=155,ae.LITERAL_MONTH=156,ae.LITERAL_WEEK=157,ae.LITERAL_YEAR=158,ae.IDENTIFIER=159,ae.PERCENT_LITERAL=160,ae.NUMERIC_LITERAL=161,ae.INTEGER_LITERAL=162,ae.BLOCK_COMMENT=163,ae.COMMENT_TO_EOL=164,ae.WHITE_SPACE=165,ae.SQL_BEGIN=166,ae.UNWATED_CHARS_TRAILING_NUMBERS=167,ae.UNEXPECTED_CHAR=168,ae.OPEN_CODE=169,ae.SQL_END=170,ae.SQL_MODE=1,ae.channelNames=["DEFAULT_TOKEN_CHANNEL","HIDDEN"],ae.modeNames=["DEFAULT_MODE","SQL_MODE"],ae.ruleNames=["SPACE_CHAR","ACCEPT","AGGREGATE","CALCULATE","CALCULATION","CONNECTION","DECLARE","DIMENSION","EXCEPT","EXTENDQ","GROUP_BY","HAVING","INDEX","INTERNAL","JOIN_CROSS","JOIN_ONE","JOIN_MANY","LIMIT","MEASURE","NEST","ORDER_BY","PARTITION_BY","PRIMARY_KEY","PRIVATE","PROJECT","PUBLIC","QUERY","RENAME","RUN","SAMPLE","SELECT","SOURCE","TOP","WHERE","VIEW","TIMEZONE","ALL","AND","AS","ASC","AVG","BOOLEAN","BY","CASE","CAST","CONDITION","COUNT","COMPOSE","DATE","DAY","DESC","DISTINCT","ELSE","END","EXCLUDE","EXTEND","FALSE","FILTER","FULL","FOR","FROM","HAS","HOUR","IMPORT","INCLUDE","INNER","IS","IN","INTERNAL_KW","JSON","LAST","LEFT","LIKE","MAX","MIN","MINUTE","MONTH","NOT","NOW","NULL","NUMBER","ON","OR","PICK","PRIVATE_KW","PUBLIC_KW","QUARTER","RIGHT","SECOND","STRING","SOURCE_KW","SUM","SQL","TABLE","THEN","THIS","TIMESTAMP","TO","TRUE","TURTLE","WEEK","WHEN","WITH","YEAR","UNGROUPED","SQ","BQ","DQ","SQ3","DQ3","BQ3","RAW_CHAR","RAW3_CHAR","F_PREFIX","S_PREFIX","HACKY_REGEX","RAW_SQ","RAW_DQ","SQ3_FILTER","SQ_FILTER","DQ3_FILTER","DQ_FILTER","BQ3_FILTER","BQ_FILTER","HEX","UNICODE","SAFE_NON_QUOTE","ESCAPED","STR_CHAR","SQ_STRING","DQ_STRING","BQ_STRING","F_TO_EOL","DOC_ANNOTATION","ANNOTATION","AMPER","ARROW","FAT_ARROW","OPAREN","CPAREN","OBRACK","CBRACK","OCURLY","CCURLY","DOUBLECOLON","TRIPLECOLON","EXCLAM","COLON","COMMA","DOT","LT","GT","EQ","NE","LTE","GTE","PLUS","MINUS","STAR","STARSTAR","SLASH","BAR","SEMI","NOT_MATCH","MATCH","PERCENT","DOUBLE_QMARK","QMARK","F_YEAR","F_DD","F_TZ","LITERAL_TIMESTAMP","LITERAL_HOUR","LITERAL_DAY","LITERAL_QUARTER","LITERAL_MONTH","LITERAL_WEEK","LITERAL_YEAR","IDENTIFIER","PERCENT_LITERAL","EXPONENT","NUMERIC_LITERAL","INTEGER_LITERAL","ID_CHAR","DIGIT","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","BLOCK_COMMENT","COMMENT_TO_EOL","WHITE_SPACE","SQL_BEGIN","UNWATED_CHARS_TRAILING_NUMBERS","UNEXPECTED_CHAR","SQL_CHAR","OPEN_CODE","SQL_END"],ae._LITERAL_NAMES=[void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,"'&'","'->'","'=>'","'('","')'","'['","']'","'{'","'}'","'::'","':::'","'!'","':'","','","'.'","'<'","'>'","'='","'!='","'<='","'>='","'+'","'-'","'*'","'**'","'/'","'|'","';'","'!~'","'~'","'%'","'??'","'?'",void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,`'"""'`],ae._SYMBOLIC_NAMES=[void 0,"ACCEPT","AGGREGATE","CALCULATE","CALCULATION","CONNECTION","DECLARE","DIMENSION","EXCEPT","EXTENDQ","GROUP_BY","HAVING","INDEX","INTERNAL","JOIN_CROSS","JOIN_ONE","JOIN_MANY","LIMIT","MEASURE","NEST","ORDER_BY","PARTITION_BY","PRIMARY_KEY","PRIVATE","PROJECT","PUBLIC","QUERY","RENAME","RUN","SAMPLE","SELECT","SOURCE","TOP","WHERE","VIEW","TIMEZONE","ALL","AND","AS","ASC","AVG","BOOLEAN","BY","CASE","CAST","CONDITION","COUNT","COMPOSE","DATE","DAY","DESC","DISTINCT","ELSE","END","EXCLUDE","EXTEND","FALSE","FILTER","FULL","FOR","FROM","HAS","HOUR","IMPORT","INCLUDE","INNER","IS","IN","INTERNAL_KW","JSON","LAST","LEFT","LIKE","MAX","MIN","MINUTE","MONTH","NOT","NOW","NULL","NUMBER","ON","OR","PICK","PRIVATE_KW","PUBLIC_KW","QUARTER","RIGHT","SECOND","STRING","SOURCE_KW","SUM","SQL","TABLE","THEN","THIS","TIMESTAMP","TO","TRUE","TURTLE","WEEK","WHEN","WITH","YEAR","UNGROUPED","HACKY_REGEX","RAW_SQ","RAW_DQ","SQ3_FILTER","SQ_FILTER","DQ3_FILTER","DQ_FILTER","BQ3_FILTER","BQ_FILTER","SQ_STRING","DQ_STRING","BQ_STRING","DOC_ANNOTATION","ANNOTATION","AMPER","ARROW","FAT_ARROW","OPAREN","CPAREN","OBRACK","CBRACK","OCURLY","CCURLY","DOUBLECOLON","TRIPLECOLON","EXCLAM","COLON","COMMA","DOT","LT","GT","EQ","NE","LTE","GTE","PLUS","MINUS","STAR","STARSTAR","SLASH","BAR","SEMI","NOT_MATCH","MATCH","PERCENT","DOUBLE_QMARK","QMARK","LITERAL_TIMESTAMP","LITERAL_HOUR","LITERAL_DAY","LITERAL_QUARTER","LITERAL_MONTH","LITERAL_WEEK","LITERAL_YEAR","IDENTIFIER","PERCENT_LITERAL","NUMERIC_LITERAL","INTEGER_LITERAL","BLOCK_COMMENT","COMMENT_TO_EOL","WHITE_SPACE","SQL_BEGIN","UNWATED_CHARS_TRAILING_NUMBERS","UNEXPECTED_CHAR","OPEN_CODE","SQL_END"],ae.VOCABULARY=new Gdt.VocabularyImpl(ae._LITERAL_NAMES,ae._SYMBOLIC_NAMES,[]),ae._serializedATNSegments=4,ae._serializedATNSegment0=`줝쪺֍꾺体؇쉁¬ފ\b\b \x07 \x07\b \b
|
|
1554
|
+
QUERY: ${(0,f0e.inspect)(r,{breakLength:72,depth:1/0})}`)}return x0e.ErrorFactory.structDef}zs.opOutputStruct=d0e;function Tst(t,e,r){for(const i of r)e=d0e(t,e,i);return e}zs.getFinalStruct=Tst;function Rst(t,e){return t.fields.find(r=>(r.as||r.name)===e)}zs.getStructFieldDef=Rst,Object.defineProperty(P2,"__esModule",{value:!0}),P2.QueryRefine=void 0;const Dst=Wr,Ost=zs,Fst=hE;class wst extends Fst.QueryBase{constructor(e,r){super({base:e,refinement:r}),this.base=e,this.refinement=r,this.elementType="query-refine"}queryComp(e){const r=this.base.queryComp(e),i=new Dst.StaticSourceSpace(r.inputStruct),s=this.refinement.refine(i,r.query.pipeline,void 0),o={...r.query,pipeline:s},u=this.resolveCompositeSource(r.inputStruct,o);return{query:{...o,compositeResolvedSourceDef:u},outputStruct:(0,Ost.getFinalStruct)(this.refinement,r.inputStruct,s),inputStruct:r.inputStruct}}}P2.QueryRefine=wst;var pE={},U2={},Es={};Object.defineProperty(Es,"__esModule",{value:!0}),Es.mkTimeResult=Es.resolution=Es.castTo=Es.timeOffset=void 0;const VB=et;function Nst(t,e,r,i,s){return{node:"delta",kids:{base:(0,VB.mkTemporal)(e,t),delta:i},op:r,units:s}}Es.timeOffset=Nst;function Lst(t,e,r,i=!1){let s;return typeof t!="string"?s={node:"cast",dstSQLType:t.raw,e,safe:i}:s={node:"cast",dstType:{type:t},e,safe:i},(0,VB.isCastType)(r)&&(s.srcType={type:r}),s}Es.castTo=Lst;function Ist(t){switch(t){case"hour":case"minute":case"second":case"microsecond":case"millisecond":return"timestamp"}return"date"}Es.resolution=Ist;function $st(t,e){if(e){if(t.type==="timestamp")return{...t,timeframe:e};if((0,VB.isDateUnit)(e))return{...t,timeframe:e}}return t}Es.mkTimeResult=$st;var bd={},ht={},Yt={};Object.defineProperty(Yt,"__esModule",{value:!0}),Yt.literalTimeResult=Yt.literalExprValue=Yt.computedErrorExprValue=Yt.computedTimeResult=Yt.computedExprValue=void 0;const h0e=Gi,YB=dt;function mE({value:t,dataType:e,from:r}){return{...e,value:t,expressionType:(0,h0e.maxOfExpressionTypes)(r.map(i=>i.expressionType)),evalSpace:(0,h0e.mergeEvalSpaces)(...r.map(i=>i.evalSpace)),compositeFieldUsage:(0,YB.mergeCompositeFieldUsage)(...r.map(i=>i.compositeFieldUsage))}}Yt.computedExprValue=mE;function Bst({value:t,dataType:e,from:r,timeframe:i}){const s=mE({value:t,dataType:e,from:r}),o={...e,expressionType:s.expressionType,evalSpace:s.evalSpace,value:s.value,compositeFieldUsage:(0,YB.mergeCompositeFieldUsage)(...r.map(u=>u.compositeFieldUsage))};return i&&(o.timeframe=i),o}Yt.computedTimeResult=Bst;function kst({dataType:t,from:e,error:r}){return mE({dataType:t??{type:"error"},value:{node:"error",message:r},from:e})}Yt.computedErrorExprValue=kst;function Mst(t){return mE({...t,from:[]})}Yt.literalExprValue=Mst;function Pst({value:t,dataType:e,timeframe:r}){const i=mE({value:t,dataType:e,from:[]}),s={...e,expressionType:i.expressionType,evalSpace:i.evalSpace,value:i.value,compositeFieldUsage:(0,YB.emptyCompositeFieldUsage)()};return r&&(s.timeframe=r),s}Yt.literalTimeResult=Pst;var j2={};Object.defineProperty(j2,"__esModule",{value:!0}),j2.isGranularResult=void 0;function Ust(t){return t.type==="date"||t.type==="timestamp"?t.timeframe!==void 0:!1}j2.isGranularResult=Ust;var Ru={};Object.defineProperty(Ru,"__esModule",{value:!0}),Ru.isComparison=Ru.isEquality=Ru.getExprNode=void 0;function jst(t){switch(t){case"~":return"like";case"!~":return"!like"}return t}Ru.getExprNode=jst;function p0e(t){return t==="="||t==="!="||t==="~"||t==="!~"}Ru.isEquality=p0e;function qst(t){return p0e(t)||t===">="||t==="<="||t===">"||t==="<"}Ru.isComparison=qst;var Hst=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),Qst=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),zst=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&Hst(e,t,r);return Qst(e,t),e};Object.defineProperty(ht,"__esModule",{value:!0}),ht.checkFilterExpression=ht.applyBinary=ht.getMorphicValue=ht.ExprDuration=ht.ExpressionDef=ht.ATNodeType=void 0;const Zc=et,Td=zst(nn),KB=Hs,m0=Yt,Wst=Es,m0e=j2,Gst=Ze,gE=Ru,yE=nE;class Vst extends Error{}var JB;(function(t){t[t.And=0]="And",t[t.Or=1]="Or",t[t.Value=2]="Value",t[t.Partial=3]="Partial"})(JB||(ht.ATNodeType=JB={}));class g0e extends Gst.MalloyElement{constructor(){super(...arguments),this.legalChildTypes=Td.anyAtomicT}granular(){return!1}requestExpression(e){return this.getExpression(e)}defaultFieldName(){}typeCheck(e,r){return r.type!=="error"&&!Td.any(r,this.legalChildTypes)?(r.type==="sql native"?e.logError("sql-native-not-allowed-in-expression",{rawType:r.rawType}):e.logError("expression-type-error",`'${this.elementType}' Can't use type ${Td.inspect(r)}`),!1):!0}apply(e,r,i,s=!1){return _0e(e,i,r,this)}canSupportPartitionBy(){return!1}canSupportOrderBy(){return!1}canSupportLimit(){return!1}supportsWhere(e){return(0,Zc.expressionIsAggregate)(e.expressionType)}atNodeType(){return JB.Value}atExpr(){return this}}ht.ExpressionDef=g0e;class XB extends g0e{constructor(e,r){super({n:e}),this.n=e,this.timeframe=r,this.elementType="duration",this.legalChildTypes=[Td.timestampT,Td.dateT]}apply(e,r,i){const s=i.getExpression(e);if(this.typeCheck(this,s),(0,Zc.isTemporalType)(s.type)&&(r==="+"||r==="-")){const o=this.n.getExpression(e);if(!Td.typeEq(o,Td.numberT))return this.logError("invalid-duration-quantity",`Duration quantity needs number not '${o.type}`),(0,KB.errorFor)("illegal unit expression");let u;return(0,m0e.isGranularResult)(s)&&s.timeframe===this.timeframe&&(u=s.timeframe),s.type==="date"&&!(0,Zc.isDateUnit)(this.timeframe)?this.loggedErrorExpr("invalid-timeframe-for-time-offset",`Cannot offset date by ${this.timeframe}`):(0,m0.computedTimeResult)({dataType:{type:s.type},value:(0,Wst.timeOffset)(s.type,s.value,r,o.value,this.timeframe),timeframe:u,from:[s,o]})}return super.apply(e,r,i)}getExpression(e){const r=this.n.getExpression(e);return(0,m0.computedErrorExprValue)({dataType:{type:"duration"},error:"Duration is not a value",from:[r]})}}ht.ExprDuration=XB;function y0e(t,e){return t.type===e?t.value:t.morphic&&t.morphic[e]}function Yst(t,e){if(t.type===e)return t;if(t.morphic&&t.morphic[e])return(0,m0.computedExprValue)({dataType:{type:e},value:t.morphic[e],from:[t]})}ht.getMorphicValue=Yst;function E0e(t,e,r,i){const s=(0,Zc.isTemporalType)(e.type),o=(0,Zc.isTemporalType)(i.type),u=(0,gE.getExprNode)(r);if(s&&o)if(e.type!==i.type){const a=y0e(e,"timestamp"),l=y0e(i,"timestamp");if(a&&l)return{node:u,kids:{left:a,right:a}}}else return{node:u,kids:{left:e.value,right:i.value}};if((s||o)&&e.type!=="null"&&i.type!=="null")return t.logError("time-comparison-type-mismatch",`Cannot compare a ${e.type} to a ${i.type}`),{node:"false"}}function Kst(t,e){if(t.type==="string"){if(e.type==="regular expression")return{node:"regexpMatch",kids:{expr:t.value,regex:e.value}}}else if(e.type==="string"&&t.type==="regular expression")return{node:"regexpMatch",kids:{expr:e.value,regex:t.value}}}function Jst(t,e,r,i){const s=e.getExpression(t),o=i.getExpression(t),u=(0,gE.getExprNode)(r),a=EE("boolean",s,o);if(a)return a;const l=Zc.TD.isSQL(s)?s.rawType||"typeless-left":void 0,c=Zc.TD.isSQL(o)?o.rawType||"typeless-right":void 0;if((l||c)&&!(s.type==="null"||o.type==="null"||l===c)){const h=AE(e,s,i,o);if(h)return{...h,type:"boolean"}}let f;if(o.type==="filter expression"){if(r!=="~"&&r!=="!~")return i.loggedErrorExpr("filter-expression-error",`Cannot use the '${r}' operator with a filter expression`);if((0,yE.isFilterable)(s.type)){let x=o.value;for(;x.node==="()";)x=x.e;x.node!=="parameter"&&v0e(i,s.type,x);const h={node:"filterMatch",dataType:s.type,kids:{filterExpr:o.value,expr:s.value}};r==="!~"&&(h.notMatch=!0),f=h}else return e.loggedErrorExpr("filter-expression-type",`Cannot use filter expressions with type '${s.type}'`)}else if(f=E0e(e,s,r,o)||{node:u,kids:{left:s.value,right:o.value}},s.type!=="error"&&o.type!=="error"&&(r==="~"||r==="!~")&&(s.type!=="string"||o.type!=="string")){let x=Kst(s,o);if(x)r[0]==="!"&&(x={node:"not",e:{...x}});else throw new Vst("Incompatible types for match('~') operator");f=x}return(0,m0.computedExprValue)({dataType:{type:"boolean"},value:f,from:[s,o]})}function Xst(t,e,r,i){const s=e.getExpression(t),o=i.getExpression(t),u=EE("boolean",s,o);if(u)return u;const a=AE(e,s,i,o);if(a)return{...a,type:"boolean"};const l=E0e(e,s,r,o)||{node:(0,gE.getExprNode)(r),kids:{left:s.value,right:o.value}};return(0,m0.computedExprValue)({dataType:{type:"boolean"},value:l,from:[s,o]})}function A0e(t,e,r,i){const s=e.getExpression(t),o=i.getExpression(t),u=EE("number",s,o);if(u)return u;const a=AE(e,s,i,o);if(a)return a;if(s.type!=="number")e.logError("arithmetic-operation-type-mismatch",`The '${r}' operator requires a number, not a '${s.type}'`);else if(o.type!=="number")i.logError("arithmetic-operation-type-mismatch",`The '${r}' operator requires a number, not a '${o.type}'`);else return(0,m0.computedExprValue)({dataType:{type:"number"},value:{node:r,kids:{left:s.value,right:o.value}},from:[s,o]});return(0,KB.errorFor)("numbers required")}function Zst(t,e,r,i){const s=e.getExpression(t),o=i.getExpression(t),u=AE(e,s,i,o);if(u)return u;const a=(0,Zc.isTemporalType)(s.type),l=EE(a?"error":"number",s,o);if(l)return l;if(a){let c=i;if(o.type!=="duration")if((0,m0e.isGranularResult)(s))c=new XB(i,s.timeframe);else if(s.type==="date")c=new XB(i,"day");else return e.loggedErrorExpr("time-offset-type-mismatch",`Can not offset time by '${o.type}'`);return c.apply(t,r,e)}return A0e(t,e,r,i)}function _0e(t,e,r,i){if((0,gE.isEquality)(r))return Jst(t,e,r,i);if((0,gE.isComparison)(r))return Xst(t,e,r,i);if(r==="+"||r==="-")return Zst(t,e,r,i);if(r==="*")return A0e(t,e,r,i);if(r==="/"||r==="%"){const s=e.getExpression(t),o=i.getExpression(t),u=AE(e,s,i,o);if(u)return u;const a=EE("number",s,o);if(a)return a;if(s.type!=="number")e.logError("arithmetic-operation-type-mismatch","Numerator must be a number");else if(o.type!=="number")i.logError("arithmetic-operation-type-mismatch","Denominator must be a number");else{const l={node:r,kids:{left:s.value,right:o.value}};return(0,m0.computedExprValue)({dataType:{type:"number"},value:l,from:[s,o]})}return(0,KB.errorFor)("divide type mismatch")}return e.loggedErrorExpr("unexpected-binary-operator",`Cannot use ${r} operator here`)}ht.applyBinary=_0e;function EE(t,...e){if(e.some(r=>r.type==="error"))return(0,m0.computedExprValue)({dataType:{type:t},value:{node:"error",message:"cascading error"},from:e})}function AE(t,e,r,i){const s=(0,m0.computedExprValue)({dataType:e,value:{node:"error",message:"sql-native unsupported"},from:[e,i]});if(e.type==="sql native")return t.logError("sql-native-not-allowed-in-expression",{rawType:e.rawType}),s.type=i.type,s;if(i.type==="sql native")return r.logError("sql-native-not-allowed-in-expression",{rawType:i.rawType}),s}function v0e(t,e,r){for(var i,s,o,u;r.node==="()";)r=r.e;if(r.node!=="filterLiteral"){t.logError("filter-expression-error","Expected a filter expression literal here");return}const a=r.filterSrc;let l;e==="date"||e==="timestamp"?l=(i=yE.TemporalFilterExpression.parse(a).log[0])===null||i===void 0?void 0:i.message:e==="string"?l=(s=yE.StringFilterExpression.parse(a).log[0])===null||s===void 0?void 0:s.message:e==="number"?l=(o=yE.NumberFilterExpression.parse(a).log[0])===null||o===void 0?void 0:o.message:e==="boolean"?l=(u=yE.BooleanFilterExpression.parse(a).log[0])===null||u===void 0?void 0:u.message:t.logError("filter-expression-type",`Cannot apply filter expression to type ${e}`),l!==void 0&&t.logError("filter-expression-error",`Filter syntax error: ${l}`)}ht.checkFilterExpression=v0e,Object.defineProperty(bd,"__esModule",{value:!0}),bd.ExprIdReference=void 0;const eot=et,tot=ht,not=dt;class rot extends tot.ExpressionDef{constructor(e){super(),this.fieldReference=e,this.elementType="ExpressionIdReference",this.has({fieldPath:e})}get refString(){return this.fieldReference.refString}getExpression(e){const r=this.fieldReference.getField(e),i=this.fieldReference.list.map(s=>s.name).slice(0,-1);if(r.found){const s=r.found.typeDesc(),o=(0,not.joinedCompositeFieldUsage)(i,s.compositeFieldUsage);if(r.isOutputField)return{...s,evalSpace:s.evalSpace==="constant"?"constant":"output",value:{node:"outputField",name:this.refString},compositeFieldUsage:o};const u={node:r.found.refType,path:this.fieldReference.path},a=(0,eot.expressionIsAggregate)(s.expressionType)?"output":s.evalSpace;return{...s,value:u,evalSpace:a,compositeFieldUsage:o}}return this.loggedErrorExpr(r.error.code,r.error.message)}}bd.ExprIdReference=rot,Object.defineProperty(U2,"__esModule",{value:!0}),U2.NamedSource=void 0;const ZB=et,iot=Ro,sot=gi,oot=Es,C0e=Ze,uot=bd,aot=L2,lot=ht;class cot extends iot.Source{constructor(e,r,i){super(),this.ref=e,this.sourceArguments=r,this.args=i,this.elementType="namedSource",i&&this.has({args:i}),e instanceof C0e.ModelEntryReference&&this.has({ref:e})}get refName(){return this.ref instanceof C0e.ModelEntryReference?this.ref.name:this.ref}structRef(e){const r=this.modelEntry(this.ref);return r&&!r.exported?{structRef:this.getSourceDef(e)}:{structRef:this.refName,sourceArguments:this.evaluateArgumentsForRef(e)}}refLogError(e,r,i){typeof this.ref=="string"?this.logError(e,r,i):this.ref.logError(e,r,i)}modelStruct(){var e;const r=this.modelEntry(this.ref),i=r==null?void 0:r.entry;if(!i){this.refLogError("source-not-found",`Undefined source '${this.refName}'`);return}if(i.type==="query"){this.logError("invalid-source-from-query",`Cannot construct a source from query '${this.refName}'`);return}else if(i.type==="function"){this.logError("invalid-source-from-function",`Cannot construct a source from a function '${this.refName}'`);return}else if(i.type==="connection"){this.logError("invalid-source-from-connection",`Cannot construct a source from a connection '${this.refName}'`);return}else if((e=this.document())===null||e===void 0||e.checkExperimentalDialect(this,i.dialect),(0,ZB.isSourceDef)(i))return{...i};this.logError("invalid-source-source","Cannot construct a source from a never type")}evaluateArgumentsForRef(e){const r=this.modelStruct();return r===void 0?{}:this.evaluateArguments(e,r.parameters,[])}evaluateArguments(e,r,i){var s,o;const u={...this.sourceArguments},a=new Set;for(const l of(s=this.args)!==null&&s!==void 0?s:[]){const c=(o=l.id)!==null&&o!==void 0?o:l.value instanceof uot.ExprIdReference?l.value.fieldReference:void 0;if(c===void 0){l.value.logError("unnamed-source-argument","Parameterized source arguments must be named with `parameter_name is`");continue}const f=c.outputName;if(a.has(f)){l.logError("duplicate-source-argument",`Cannot pass argument for \`${f}\` more than once`);continue}a.add(f);const x=(r??{})[f];if(!x)c.logError("source-parameter-not-found",`\`${this.refName}\` has no declared parameter named \`${c.refString}\``);else{const h=e??new aot.ParameterSpace(i??[]),p=l.value.getExpression(h);let m=p.value;p.type==="filter expression"&&x.type==="filter expression"&&x.filterType&&(0,lot.checkFilterExpression)(l.value,x.filterType,m),p.type!==x.type&&(0,ZB.isCastType)(x.type)&&(m=(0,oot.castTo)(x.type,p.value,p.type,!0)),u[f]={...x,value:m}}}for(const l in r)l in u||((0,ZB.paramHasValue)(r[l])?u[l]={...r[l]}:this.refLogError("missing-source-argument",`Argument not provided for required parameter \`${l}\``));return u}getSourceDef(e){return this.withParameters(e,[])}withParameters(e,r){var i;const s=this.modelStruct();if(!s){const l=sot.ErrorFactory.structDef,c=`${this.refName}-undefined`;return l.name=l.name+c,l.dialect=l.dialect+c,l}const o={};for(const l of r??[]){const c=l.parameter();o[c.name]=c}const u=this.evaluateArguments(e,s.parameters,r),a={...s,parameters:o,arguments:u};return(i=this.document())===null||i===void 0||i.rememberToAddModelAnnotations(a),a}}U2.NamedSource=cot;var _E={},Y4={};Object.defineProperty(Y4,"__esModule",{value:!0}),Y4.QueryHeadStruct=void 0;const fot=et,xot=Ro,dot=U2;class hot extends xot.Source{constructor(e,r){super(),this.fromRef=e,this.sourceArguments=r,this.elementType="internalOnlyQueryHead"}structRef(){return{structRef:this.fromRef}}getSourceDef(e){if((0,fot.refIsStructDef)(this.fromRef))return this.fromRef;const r=new dot.NamedSource(this.fromRef,this.sourceArguments,void 0);return this.has({exploreReference:r}),r.getSourceDef(e)}}Y4.QueryHeadStruct=hot,Object.defineProperty(_E,"__esModule",{value:!0}),_E.QueryReference=void 0;const ek=gi,pot=Ze,mot=Y4,got=et,yot=zs;class Eot extends pot.MalloyElement{constructor(e){super(),this.name=e,this.elementType="query-reference"}queryComp(e){const r=this.modelEntry(this.name),i=r==null?void 0:r.entry,s=function(){return{inputStruct:ek.ErrorFactory.structDef,outputStruct:ek.ErrorFactory.structDef,query:ek.ErrorFactory.query}};if(!i)return this.logError("query-reference-not-found",`Reference to undefined query '${this.name.refString}'`),s();if(i.type==="query"){const o=new mot.QueryHeadStruct(i.structRef,i.sourceArguments);this.has({queryHead:o});const u=o.getSourceDef(void 0),a=(0,yot.getFinalStruct)(this,u,i.pipeline);return{query:e||(0,got.refIsStructDef)(i.structRef)?i:{...i,structRef:u},outputStruct:a,inputStruct:u}}return this.logError("non-query-used-as-query",`Illegal reference to '${this.name}', query expected`),s()}query(){return this.queryComp(!0).query}}_E.QueryReference=Eot,Object.defineProperty(pE,"__esModule",{value:!0}),pE.SQReference=void 0;const Aot=Tu,_ot=Sd,vot=U2,S0e=_E,b0e=Gi;class Cot extends Aot.SourceQueryElement{constructor(e,r){super({ref:e}),this.ref=e,this.args=r,this.elementType="sq-reference",r!==void 0&&this.has({args:r})}getQuery(){const e=this.ref.getNamed();if(e)if(e.type==="query"){const r=new S0e.QueryReference(this.ref);return this.has({query:r}),r}else this.sqLog("cannot-use-as-query",`Illegal reference to '${e.as||e.name}', query expected`);else this.ref.logError("source-or-query-not-found",`Reference to undefined object '${this.ref.refString}'`),this.errored=!0}isSource(){const e=this.ref.getNamed();return e!==void 0&&(0,b0e.isSourceDef)(e)}getSource(){if(this.asSource)return this.asSource;const e=this.ref.getNamed();if(!e){this.ref.logError("source-not-found",`Reference to undefined object '${this.ref.refString}'`),this.errored=!0;return}if(e.type==="query"){this.args!==void 0&&this.ref.logError("illegal-query-argument","Arguments cannot be passed to queries");const r=new S0e.QueryReference(this.ref);this.asSource=new _ot.QuerySource(r)}else if((0,b0e.isSourceDef)(e))this.asSource=new vot.NamedSource(this.ref,void 0,this.args);else{this.sqLog("cannot-use-struct-as-source",`Expected '${this.ref.refString}' to be of type query or source, not '${e.type}'`);return}return this.has({asSource:this.asSource}),this.asSource}}pE.SQReference=Cot,Object.defineProperty(G4,"__esModule",{value:!0}),G4.SQRefine=void 0;const Sot=Tu,bot=Sd,Tot=P2,Rot=pE;class Dot extends Sot.SourceQueryElement{constructor(e,r){super({toRefine:e,refine:r}),this.toRefine=e,this.refine=r,this.elementType="sq-refine"}getQuery(){if(this.toRefine.isSource()){this.toRefine instanceof Rot.SQReference?this.sqLog("illegal-refinement-of-source",`Cannot add view refinements to '${this.toRefine.ref.refString}' because it is a source`):this.sqLog("illegal-refinement-of-source","Cannot add view refinements to a source");return}const e=this.toRefine.getQuery();if(e){const r=new Tot.QueryRefine(e,this.refine);return this.has({query:r}),r}}getSource(){const e=this.getQuery();if(e){const r=new bot.QuerySource(e);return this.has({queryAsSource:r}),r}}}G4.SQRefine=Dot;var K4={},vE={};Object.defineProperty(vE,"__esModule",{value:!0}),vE.QueryRaw=void 0;const Oot=et,Fot=Ze;class wot extends Fot.MalloyElement{constructor(e){super({source:e}),this.source=e,this.elementType="query-raw"}queryComp(e){const r=e?this.source.structRef(void 0):{structRef:this.source.getSourceDef(void 0)},i=(0,Oot.refIsStructDef)(r.structRef)?r.structRef:this.source.getSourceDef(void 0);return{query:{type:"query",...r,pipeline:[{type:"raw",fields:[]}],location:this.location},outputStruct:i,inputStruct:i}}query(){return this.queryComp(!0).query}}vE.QueryRaw=wot;var CE={},g0={};Object.defineProperty(g0,"__esModule",{value:!0}),g0.sqlKey=g0.compileSQLInterpolation=void 0;const Not=js,Lot=et,Iot=kt;function $ot(t,e,r){let i,s="",o=!1;for(const u of t)if((0,Lot.isSegmentSQL)(u))s+=u.sql,o=u.sql.match(/\(\s*$/)!==null;else{if(!i){if(!r)throw new Error("Internal error: Partial model missing when compiling SQL block");i=new Not.QueryModel(r)}const a=i.compileQuery(u,{defaultRowLimit:void 0},!1).sql;s+=o?a:`(${a})`,o=!1}return{connection:e,selectStr:s}}g0.compileSQLInterpolation=$ot;function Bot(t,e){return`sql://${t}/${(0,Iot.generateHash)(e)}`}g0.sqlKey=Bot,Object.defineProperty(CE,"__esModule",{value:!0}),CE.SQLSource=void 0;const tk=g0,kot=Ro,SE=gi;class Mot extends kot.Source{constructor(e,r){super({connectionName:e,select:r}),this.connectionName=e,this.select=r,this.elementType="sqlSource",this.connectionNameInvalid=!1}sqlSourceRequest(e){const r=this.select.containsQueries?e.modelDef():void 0;return(0,tk.compileSQLInterpolation)(this.select.sqlPhrases(),this.connectionName.refString,r)}structRef(){return{structRef:this.getSourceDef()}}validateConnectionName(){var e;const r=this.modelEntry(this.connectionName),i=this.connectionName.refString;if(this.connectionNameInvalid)return!1;if(r===void 0)(e=this.namespace())===null||e===void 0||e.setEntry(i,{entry:{type:"connection",name:i},exported:!0},!0);else if(r.entry.type!=="connection")return this.connectionName.logError("invalid-connection-for-sql-source",`${this.connectionName.refString} is not a connection`),this.connectionNameInvalid=!0,!1;return!0}needs(e){var r;if(!this.validateConnectionName())return;const i=super.needs(e);if(i)return i;this.requestBlock===void 0&&(this.requestBlock=this.sqlSourceRequest(e));const s=this.requestBlock,o=(r=this.translator())===null||r===void 0?void 0:r.root.sqlQueryZone;if(!o){this.logError("failed-to-fetch-sql-source-schema","Cant't look up schema for sql block");return}const u=(0,tk.sqlKey)(s.connection,s.selectStr);o.reference(u,this.location);const a=o.getEntry(u);if(a.status==="reference")return{compileSQL:s};a.status==="present"&&e.checkExperimentalDialect(this,a.value.dialect)}getSourceDef(){var e;if(!this.validateConnectionName())return SE.ErrorFactory.structDef;const r=(e=this.translator())===null||e===void 0?void 0:e.root.sqlQueryZone;if(!r)return this.logError("failed-to-fetch-sql-source-schema","Cant't look up schema for sql block"),SE.ErrorFactory.structDef;if(this.requestBlock===void 0)return this.logError("failed-to-fetch-sql-source-schema","Expected to have already compiled the sql block"),SE.ErrorFactory.structDef;const i=this.requestBlock,s=(0,tk.sqlKey)(i.connection,i.selectStr);r.reference(s,this.location);const o=r.getEntry(s);if(o.status==="error"){const u=o.message.split(/\r?\n/);return this.select.logError("invalid-sql-source","Invalid SQL, "+u.join(`
|
|
1555
|
+
`)),SE.ErrorFactory.structDef}else if(o.status==="present"){const u=this.select.location,a={...o.value,fields:o.value.fields.map(f=>({...f,location:u})),location:this.location},l=this.document(),c=l==null?void 0:l.currentModelAnnotation();return c&&(a.modelAnnotation=c),a}else return this.logError("non-top-level-sql-source","`connection_name.sql(...)` can currently only be used in top level source/query definitions"),SE.ErrorFactory.structDef}}CE.SQLSource=Mot,Object.defineProperty(K4,"__esModule",{value:!0}),K4.SQSource=void 0;const Pot=Tu,Uot=vE,jot=CE;class qot extends Pot.SourceQueryElement{constructor(e){super({theSource:e}),this.theSource=e,this.elementType="sq-source"}isSource(){return!0}getSource(){return this.theSource}getQuery(){if(this.theSource instanceof jot.SQLSource){const e=new Uot.QueryRaw(this.theSource);return this.has({rawQuery:e}),e}else this.sqLog("invalid-source-as-query","This source cannot be used as a query")}}K4.SQSource=qot;var J4={};Object.defineProperty(J4,"__esModule",{value:!0}),J4.SQExtend=void 0;const Hot=aE,Qot=Tu;class zot extends Qot.SourceQueryElement{constructor(e,r,i){super({sqSrc:e,extend:r}),this.sqSrc=e,this.extend=r,this.includeList=i,this.elementType="sq-extend"}getSource(){if(this.asSource)return this.asSource;const e=this.sqSrc.getSource();if(e)return this.asSource=new Hot.RefinedSource(e,this.extend,this.includeList),this.has({asSource:this.asSource}),this.asSource;this.sqLog("failed-to-compute-source-to-extend","Could not compute source to extend")}isSource(){return!0}}J4.SQExtend=zot;var X4={},Z4={};Object.defineProperty(Z4,"__esModule",{value:!0}),Z4.CompositeSource=void 0;const Wot=et,Got=Ro;class Vot extends Got.Source{constructor(e){super({sources:e}),this.sources=e,this.elementType="compositeSource"}getSourceDef(e){return this.withParameters(e,[])}withParameters(e,r){const i=this.sources.map(c=>c.withParameters(e,r)),s=i[0].connection,o=i[0].dialect,u="composite_source",a=[],l=new Map;return this.sources.forEach((c,f)=>{var x;const h=i[f];h.connection!==s&&c.logError("composite-source-connection-mismatch",`All sources in a composite source must share the same connection; connection \`${h.connection}\` differs from previous connection \`${s}\``);for(const p of h.fields){if(!(0,Wot.isAtomic)(p)){c.logWarning("composite-source-atomic-fields-only",`Only atomic fields are supported in composite sources; field \`${p.name}\` is not atomic and will be ignored`);continue}if(p.accessModifier==="private")continue;const m=(x=p.as)!==null&&x!==void 0?x:p.name,g=l.get(m);if(g===void 0){const y={...p,name:m,as:void 0,e:{node:"compositeField"},compositeFieldUsage:{fields:[m],joinedUsage:{}},code:this.code,location:this.codeLocation};l.set(m,y),a.push(y)}else p.accessModifier==="internal"&&(g.accessModifier="internal")}}),{type:"composite",sources:i,connection:s,fields:a,dialect:o,name:u,parameters:i[0].parameters}}}Z4.CompositeSource=Vot,Object.defineProperty(X4,"__esModule",{value:!0}),X4.SQCompose=void 0;const Yot=Z4,Kot=Tu;class Jot extends Kot.SourceQueryElement{constructor(e){super({sources:e}),this.sources=e,this.elementType="sq-compose"}getSource(){if(this.asSource)return this.asSource;const e=this.sources.map(r=>r.getSource());if(e.length===0){this.sqLog("empty-composite-source","Composite source must have at least one input source");return}else e.length===1&&this.sqLog("unnecessary-composite-source","A composite source with one input is equivalent to that input",{severity:"warn"});if(Xot(e))return this.asSource=new Yot.CompositeSource(e),this.has({asSource:this.asSource}),this.asSource;this.sqLog("invalid-composite-source-input","All composite source inputs must be valid sources")}isSource(){return!0}}X4.SQCompose=Jot;function Xot(t){return t.every(e=>e!==void 0)}var eT={},y0={},bE={},Zot=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),eut=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),tut=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&Zot(e,t,r);return eut(e,t),e};Object.defineProperty(bE,"__esModule",{value:!0}),bE.BinaryBoolean=void 0;const nut=Hs,rut=tut(nn),iut=Ru,sut=Yt,out=ht;class uut extends out.ExpressionDef{constructor(e,r,i){super({left:e,right:i}),this.left=e,this.op=r,this.right=i,this.elementType="abstract boolean binary",this.legalChildTypes=[rut.boolT]}getExpression(e){const r=this.left.getExpression(e),i=this.right.getExpression(e);return this.typeCheck(this.left,r)&&this.typeCheck(this.right,i)?(0,sut.computedExprValue)({dataType:{type:"boolean"},value:{node:(0,iut.getExprNode)(this.op),kids:{left:r.value,right:i.value}},from:[r,i]}):(0,nut.errorFor)("logical-op expected boolean")}}bE.BinaryBoolean=uut;var aut=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),lut=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),cut=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&aut(e,t,r);return lut(e,t),e};Object.defineProperty(y0,"__esModule",{value:!0}),y0.ExprLegacyIn=y0.ExprEquality=y0.ExprCompare=void 0;const hn=cut(nn),fut=Yt,xut=ht,dut=bE,hut={"~":[hn.stringT],"!~":[hn.stringT],"<":[hn.numberT,hn.stringT,hn.dateT,hn.timestampT],"<=":[hn.numberT,hn.stringT,hn.dateT,hn.timestampT],"=":[hn.numberT,hn.stringT,hn.dateT,hn.timestampT],"!=":[hn.numberT,hn.stringT,hn.dateT,hn.timestampT],">=":[hn.numberT,hn.stringT,hn.dateT,hn.timestampT],">":[hn.numberT,hn.stringT,hn.dateT,hn.timestampT]};class T0e extends dut.BinaryBoolean{constructor(e,r,i){super(e,r,i),this.elementType="a<=>b",this.legalChildTypes=hut[r]}getExpression(e){return this.right.apply(e,this.op,this.left)}}y0.ExprCompare=T0e;class put extends T0e{constructor(e,r,i){super(e,r,i),this.elementType="a~=b"}getExpression(e){return this.right.apply(e,this.op,this.left,!0)}apply(e,r,i){return super.apply(e,r,i,!0)}}y0.ExprEquality=put;class mut extends xut.ExpressionDef{constructor(e,r,i){super(),this.expr=e,this.notIn=r,this.choices=i,this.elementType="in",this.has({expr:e,choices:i})}getExpression(e){const r=this.expr.getExpression(e),i=this.choices.map(s=>s.getExpression(e));return(0,fut.computedExprValue)({dataType:{type:"boolean"},value:{node:"in",not:this.notIn,kids:{e:r.value,oneOf:i.map(s=>s.value)}},from:[r,...i]})}}y0.ExprLegacyIn=mut;var TE={},q2={};Object.defineProperty(q2,"__esModule",{value:!0}),q2.ExprTime=void 0;const gut=et,yut=Yt,Eut=ht;class nk extends Eut.ExpressionDef{constructor(e,r,i){super(),this.elementType="timestampOrDate",this.elementType=e,this.translationValue=(0,yut.computedExprValue)({dataType:{type:e},value:r,from:i??[]})}getExpression(e){return this.translationValue}static fromValue(e,r){let i=r.value;if(e!==r.type){const s={node:"cast",safe:!1,dstType:{type:e},e:r.value};(0,gut.isTemporalType)(r.type)&&(s.srcType={type:r.type}),i=s}return new nk(e,i,[r])}}q2.ExprTime=nk;var ef={};Object.defineProperty(ef,"__esModule",{value:!0}),ef.Range=void 0;const Aut=Hs,_ut=Yt,vut=ht;class Cut extends vut.ExpressionDef{constructor(e,r){super({first:e,last:r}),this.first=e,this.last=r,this.elementType="range"}apply(e,r,i){switch(r){case"=":case"!=":{const s=r==="="?">=":"<",o=r==="="?"and":"or",u=r==="="?"<":">=",a=this.first.apply(e,s,i),l=this.last.apply(e,u,i);return(0,_ut.computedExprValue)({dataType:{type:"boolean"},value:{node:o,kids:{left:a.value,right:l.value}},from:[a,l]})}case">":return this.last.apply(e,">=",i);case">=":return this.first.apply(e,">=",i);case"<":return this.first.apply(e,"<",i);case"<=":return this.last.apply(e,"<",i)}throw new Error("mysterious error in range computation")}requestExpression(e){}getExpression(e){return this.logError("range-as-value","A Range is not a value"),(0,Aut.errorFor)("a range is not a value")}}ef.Range=Cut;var Sut=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),but=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),Tut=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&Sut(e,t,r);return but(e,t),e};Object.defineProperty(TE,"__esModule",{value:!0}),TE.ExprGranularTime=void 0;const rk=et,Rut=Hs,R0e=Tut(nn),D0e=Es,Dut=ht,tT=q2,O0e=ef;class Out extends Dut.ExpressionDef{constructor(e,r,i){super({expr:e}),this.expr=e,this.units=r,this.truncate=i,this.elementType="granularTime",this.legalChildTypes=[R0e.timestampT,R0e.dateT]}granular(){return!0}getExpression(e){const r=this.units,i=this.expr.getExpression(e);if(rk.TD.isTemporal(i)){const o={...i,timeframe:r};return this.truncate&&(o.value={node:"trunc",e:(0,rk.mkTemporal)(i.value,i.type),units:r}),o}i.type!=="error"&&this.logError("unsupported-type-for-time-truncation",`Cannot do time truncation on type '${i.type}'`);const s={...i};return i.type==="error"&&(s.type=(0,rk.isDateUnit)(r)?"date":"timestamp"),{...s,value:(0,Rut.errorFor)("granularity typecheck").value,evalSpace:"constant"}}toRange(e){const r=this.getExpression(e),i={node:"numberLiteral",literal:"1"};if(r.type==="timestamp"){const a=tT.ExprTime.fromValue("timestamp",r),l=new tT.ExprTime("timestamp",(0,D0e.timeOffset)("timestamp",r.value,"+",i,this.units),[r]);return new O0e.Range(a,l)}const s=new tT.ExprTime("date",r.value,[r]),o=(0,D0e.timeOffset)("date",r.value,"+",i,this.units),u=new tT.ExprTime("date",o,[r]);return new O0e.Range(s,u)}}TE.ExprGranularTime=Out,Object.defineProperty(eT,"__esModule",{value:!0}),eT.Apply=void 0;const Fut=y0,wut=j2,F0e=TE;class Nut extends Fut.ExprCompare{constructor(e,r){super(e,"=",r),this.left=e,this.right=r,this.elementType="apply"}getExpression(e){let r=this.right;if(!this.right.granular()){const i=this.right.requestExpression(e);i&&(0,wut.isGranularResult)(i)&&(r=new F0e.ExprGranularTime(this.right,i.timeframe,!1))}return r instanceof F0e.ExprGranularTime?r.toRange(e).apply(e,this.op,this.left):super.getExpression(e)}}eT.Apply=Nut;var H2={},Lut=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),Iut=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),$ut=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&Lut(e,t,r);return Iut(e,t),e};Object.defineProperty(H2,"__esModule",{value:!0}),H2.BinaryNumeric=void 0;const But=$ut(nn),kut=ht;class Mut extends kut.ExpressionDef{constructor(e,r,i){super({left:e,right:i}),this.left=e,this.op=r,this.right=i,this.elementType="numeric binary abstract",this.legalChildTypes=[But.numberT]}getExpression(e){return this.right.apply(e,this.op,this.left)}}H2.BinaryNumeric=Mut;var nT={},Put=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),Uut=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),jut=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&Put(e,t,r);return Uut(e,t),e};Object.defineProperty(nT,"__esModule",{value:!0}),nT.Boolean=void 0;const qut=ht,Hut=jut(nn);let Qut=class extends qut.ExpressionDef{constructor(e){super(),this.value=e,this.elementType="boolean literal"}getExpression(){return{...Hut.boolT,value:{node:this.value}}}};nT.Boolean=Qut;var Q2={};Object.defineProperty(Q2,"__esModule",{value:!0}),Q2.ConstantExpression=Q2.ConstantFieldSpace=void 0;const zut=ht;class w0e{constructor(){this.type="fieldSpace"}structDef(){throw new Error("ConstantFieldSpace cannot generate a structDef")}emptyStructDef(){throw new Error("ConstantFieldSpace cannot generate a structDef")}lookup(e){return{error:{message:"Only constants allowed in parameter default values",code:"illegal-reference-in-parameter-default"},found:void 0}}entries(){return[]}entry(){}dialectName(){return"~constant-space-unknown-dialect~"}dialectObj(){}isQueryFieldSpace(){return!1}isProtectedAccessSpace(){return!1}}Q2.ConstantFieldSpace=w0e;class Wut extends zut.ExpressionDef{constructor(e){super({expr:e}),this.expr=e,this.elementType="constantExpression"}getExpression(e){return this.constantValue()}get constantFs(){return this.cfs||(this.cfs=new w0e),this.cfs}constantValue(){return this.expr.getExpression(this.constantFs)}apply(e,r,i){return this.expr.apply(e,r,i)}requestExpression(e){return this.expr.requestExpression(e)}}Q2.ConstantExpression=Wut;var tf={};Object.defineProperty(tf,"__esModule",{value:!0}),tf.FunctionOrdering=tf.FunctionOrderBy=void 0;const ik=et,N0e=Ze,Gut=bd;class Vut extends N0e.MalloyElement{constructor(e,r){super(),this.field=e,this.dir=r,this.elementType="orderBy",e&&this.has({field:e})}getAnalyticOrderBy(e){if(!this.field)return this.logError("analytic-order-by-missing-field","analytic `order_by` must specify an aggregate expression or output field reference"),{node:"functionOrderBy",e:{node:"error"},dir:this.dir};const r=this.field.getExpression(e);return(0,ik.expressionIsAggregate)(r.expressionType)||((0,ik.expressionIsScalar)(r.expressionType)?(!(this.field instanceof Gut.ExprIdReference)||r.evalSpace==="input")&&this.field.logError("analytic-order-by-not-output","analytic `order_by` must be an aggregate or an output field reference"):this.field.logError("analytic-order-by-not-aggregate-or-output","analytic `order_by` must be scalar or aggregate")),{node:"functionOrderBy",e:r.value,dir:this.dir}}getAggregateOrderBy(e,r){if(this.field){const i=this.field.getExpression(e);return(0,ik.expressionIsScalar)(i.expressionType)||this.field.logError("aggregate-order-by-not-scalar","aggregate `order_by` must be scalar"),r||this.field.logError("aggregate-order-by-expression-not-allowed","`order_by` must be only `asc` or `desc` with no expression"),{node:"functionOrderBy",e:i.value,dir:this.dir}}else return this.dir===void 0?(this.logError("aggregate-order-by-without-field-or-direction","field or order direction must be specified"),{node:"functionDefaultOrderBy",dir:"asc"}):{node:"functionDefaultOrderBy",dir:this.dir}}}tf.FunctionOrderBy=Vut;class Yut extends N0e.ListOf{constructor(e){super(e),this.elementType="function-ordering"}getAnalyticOrderBy(e){return this.list.map(r=>r.getAnalyticOrderBy(e))}getAggregateOrderBy(e,r){return this.list.map(i=>i.getAggregateOrderBy(e,r))}}tf.FunctionOrdering=Yut;var rT={};Object.defineProperty(rT,"__esModule",{value:!0}),rT.ExprAddSub=void 0;const Kut=H2;class Jut extends Kut.BinaryNumeric{constructor(){super(...arguments),this.elementType="+-"}}rT.ExprAddSub=Jut;var E0={},Xut=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),Zut=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),eat=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&Xut(e,t,r);return Zut(e,t),e};Object.defineProperty(E0,"__esModule",{value:!0}),E0.ExprAggregateFunction=void 0;const RE=et,tat=kt,nat=Hs,L0e=Wr,I0e=eat(nn),rat=_t,iat=ht,sat=zr,oat=bd;class uat extends iat.ExpressionDef{constructor(e,r,i){super(),this.func=e,this.legalChildTypes=[I0e.numberT],this.elementType=e,this.explicitSource=i,r&&(this.expr=r,this.has({expr:r}))}getExpression(e){var r,i,s;const o=e.isQueryFieldSpace()?e.inputSpace():e;let u=this.expr,a=(r=this.expr)===null||r===void 0?void 0:r.getExpression(o),l=(i=this.source)===null||i===void 0?void 0:i.path,c=[];if(this.source){const x=this.source.getField(o);if(x.found){c=x.joinPath;const h=x.found,p=h.typeDesc();if(!(h instanceof L0e.StructSpaceField))if((0,RE.isAtomicFieldType)(p.type)){u=this.source,a={...I0e.atomicDef(p),expressionType:p.expressionType,value:p.evalSpace==="output"?{node:"outputField",name:this.source.refString}:{node:"field",path:this.source.path},evalSpace:p.evalSpace,compositeFieldUsage:p.compositeFieldUsage},l=this.source.path.slice(0,-1);const m=this.getJoinUsage(o);(m.length===1||m.length>1&&m.slice(1).every(y=>aat(y,m[0])))&&(l=m[0].map(y=>y.name),c=m[0])}else return this.loggedErrorExpr("invalid-aggregate-source",`Aggregate source cannot be a ${p.type}`)}else return this.loggedErrorExpr("aggregate-source-not-found",`Reference to undefined value ${this.source.refString}`)}if(a===void 0)return this.loggedErrorExpr("missing-aggregate-expression","Missing expression for aggregate function");if((0,RE.expressionIsAggregate)(a.expressionType))return this.loggedErrorExpr("aggregate-of-aggregate","Aggregate expression cannot be aggregate");if(!(a.type==="error")){const x=this.getJoinUsage(o),h=this.source!==void 0||this.explicitSource;if(u&&!(!this.source&&x.every(m=>m.length===0))&&!this.isSymmetricFunction()){const m=ok(c,x),g=uk(this.elementType,m),y=h?g==null?void 0:g.message:"Join path is required for this calculation";if(y){const E=lat(y,x,u,this.elementType),A=(s=g==null?void 0:g.code)!==null&&s!==void 0?s:"bad-join-usage";g?this.logError(A,E):this.logWarning(A,E)}}}if(this.typeCheck(this.expr||this,{...a,expressionType:"scalar"})){const x={node:"aggregate",function:this.func,e:a.value};return l&&l.length>0&&(x.structPath=l),{...this.returns(a),expressionType:"aggregate",value:x,evalSpace:"output"}}return(0,nat.errorFor)("aggregate type check")}isSymmetricFunction(){return!0}getJoinUsage(e){const r=[];if(this.source&&this.source.getField(e).found){const s={node:"field",path:this.source.path};r.push(...sk(e,s))}if(this.expr){const i=this.expr.getExpression(e).value;r.push(...sk(e,i))}return r}}E0.ExprAggregateFunction=uat;function aat(t,e){let r=t.length;if(r!==e.length)return!1;for(;r>0;)if(r-=1,t[r].name!==e[r].name)return!1;return!0}function sk(t,e){const r=[],i=(s,o)=>{const u=o[0],a=o.slice(1),l=s.entry(u);if(l===void 0)throw new Error(`Invalid field lookup ${u}`);if(l instanceof L0e.StructSpaceField&&a.length>0){const c=i(l.fieldSpace,a);return{...c,joinPath:[{...l.joinPathElement,name:u},...c.joinPath]}}else if(l instanceof sat.SpaceField){if(a.length!==0)throw new Error(`${u} cannot contain a ${a.join(".")}`);const c=l.fieldDef();if(c)return{fs:s,def:c,joinPath:[]};throw new Error("No field def")}else throw new Error("expected a field def or struct")};for(const s of(0,tat.exprWalk)(e))if(s.node==="field"){const o=i(t,s.path),u=o.def;if((0,RE.isAtomic)(u)&&!(0,RE.isJoined)(u))if((0,RE.hasExpression)(u)){const a=sk(o.fs,u.e);r.push(...a.map(l=>[...o.joinPath,...l]))}else r.push(o.joinPath)}else if(s.node==="source-reference")if(s.path){const o=i(t,s.path);r.push(o.joinPath)}else r.push([]);return r}function ok(t,e){const r=[];for(const i of e){let s=0;for(let l=0;l<t.length&&l<i.length&&t[l].name===i[l].name;l++)s=l+1;const o=t.slice(s),u=i.slice(s),a=[...o.map(l=>({...l,reverse:!0})),...u.map(l=>({...l,reverse:!1}))];r.push(a)}return r}function uk(t,e){for(const r of e)for(const i of r){if(i.joinType==="cross")return{code:"aggregate-traverses-join-cross",message:`Cannot compute \`${t}\` across \`join_cross\` relationship \`${i.name}\``};if(i.joinElementType==="array"&&!i.reverse)return{code:"aggregate-traverses-repeated-relationship",message:`Cannot compute \`${t}\` across repeated relationship \`${i.name}\``};if(i.joinType==="many"&&!i.reverse)return{code:"aggregate-traverses-join-many",message:`Cannot compute \`${t}\` across \`join_many\` relationship \`${i.name}\``}}}function lat(t,e,r,i){if(e.length===0)return t;let s=e[0];for(const m of e.slice(1))for(let g=0;g<s.length;g++){const y=s[g],E=m[g];if(y.name!==E.name){s=s.slice(0,g);break}}const o=ok(s,e),u=uk(i,o),a=s.slice().reverse().findIndex(m=>m.joinType==="many"||m.joinType==="cross"),l=a===-1?0:s.length-a,c=s.slice(0,l),f=ok(c,e),x=uk(i,f),h=s.length>0?s.map(m=>m.name).join("."):"source",p=c.length>0?c.map(m=>m.name).join("."):"source";if(u)return"Aggregated dimensional expression contains multiple join paths; rewrite, for example `sum(first_join.field + second_join.field)` as `first_join.field.sum() + second_join.field.sum()`";{const m=r instanceof rat.FieldReference?`${r.refString}.${i}()`:r instanceof oat.ExprIdReference?`${r.fieldReference.refString}.${i}()`:`${h}.${i}(${r.code})`,g=`${p}.${i}(${r.code})`;let y=`${t}; use \`${m}\``;return x===void 0&&p!==h&&(y+=` or \`${g}\` to get a result weighted with respect to \`${p}\``),y}}var iT={};Object.defineProperty(iT,"__esModule",{value:!0}),iT.ExprAlternationTree=void 0;const $0e=Yt,z2=ht,cat=Ru;function ak(t){const e=t.atExpr();switch(e.atNodeType()){case z2.ATNodeType.And:case z2.ATNodeType.Partial:return;case z2.ATNodeType.Or:{if(e instanceof B0e){const r=ak(e.left);if(r){const i=ak(e.right);if(i)return[...r,...i]}}return}default:return e.granular()?void 0:[e]}}class B0e extends z2.ExpressionDef{constructor(e,r,i){super({left:e,right:i}),this.left=e,this.op=r,this.right=i,this.elementType="alternation",this.elementType=`${r}alternation${r}`}equalityList(){return this.inList===void 0&&(this.inList=ak(this)||[]),this.inList}apply(e,r,i,s){if((0,cat.isEquality)(r)){const a=this.equalityList();if(a.length>0&&(r==="="||r==="!=")){const l=i.getExpression(e),c=a.map(f=>f.getExpression(e));return(0,$0e.computedExprValue)({dataType:{type:"boolean"},value:{node:"in",not:r==="!=",kids:{e:l.value,oneOf:c.map(f=>f.value)}},from:[l,...c]})}a.length===0&&s&&this.logWarning("or-choices-only",`Only | seperated values are legal when used with ${r} operator`)}const o=this.left.apply(e,r,i),u=this.right.apply(e,r,i);return(0,$0e.computedExprValue)({dataType:{type:"boolean"},value:{node:this.op==="&"?"and":"or",kids:{left:o.value,right:u.value}},from:[o,u]})}requestExpression(e){}getExpression(e){return this.loggedErrorExpr("alternation-as-value","Alternation tree has no value")}atNodeType(){return this.op==="|"?z2.ATNodeType.Or:z2.ATNodeType.And}}iT.ExprAlternationTree=B0e;var W2={};Object.defineProperty(W2,"__esModule",{value:!0}),W2.ExprAsymmetric=void 0;const fat=E0;class xat extends fat.ExprAggregateFunction{constructor(e,r,i,s){super(e,r,s),this.func=e,this.expr=r,this.source=i,this.has({source:i})}isSymmetricFunction(){return!1}returns(e){return e}defaultFieldName(){if(this.source&&this.expr===void 0){const e=this.source.nameString;switch(this.func){case"sum":return`total_${e}`;case"avg":return`avg_${e}`}}}}W2.ExprAsymmetric=xat;var sT={};Object.defineProperty(sT,"__esModule",{value:!0}),sT.ExprAvg=void 0;const dat=W2;class hat extends dat.ExprAsymmetric{constructor(e,r,i){super("avg",e,r,i),this.has({source:r})}}sT.ExprAvg=hat;var oT={};Object.defineProperty(oT,"__esModule",{value:!0}),oT.ExprCast=void 0;const pat=Es,mat=Yt,gat=ht;class yat extends gat.ExpressionDef{constructor(e,r,i=!1){super({expr:e}),this.expr=e,this.castType=r,this.safe=i,this.elementType="cast"}getExpression(e){const r=this.expr.getExpression(e);let i={type:"error"};if(typeof this.castType=="string")i={type:this.castType};else{const s=e.dialectObj();s&&(s.validateTypeName(this.castType.raw)?i=s.sqlTypeToMalloyType(this.castType.raw):this.logError("invalid-sql-native-type",`Cast type \`${this.castType.raw}\` is invalid for ${s.name} dialect`),this.safe&&!s.supportsSafeCast&&this.logError("dialect-cast-unsafe-only",`The SQL dialect '${e.dialectName()}' does not supply a safe cast operator`))}return(0,mat.computedExprValue)({dataType:i,value:(0,pat.castTo)(this.castType,r.value,r.type,this.safe),from:[r]})}}oT.ExprCast=yat;var uT={},Eat=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),Aat=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),_at=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&Eat(e,t,r);return Aat(e,t),e};Object.defineProperty(uT,"__esModule",{value:!0}),uT.ExprCoalesce=void 0;const k0e=Gi,M0e=_at(nn),vat=ht;class Cat extends vat.ExpressionDef{constructor(e,r){super({expr:e,altExpr:r}),this.expr=e,this.altExpr=r,this.elementType="coalesce expression",this.legalChildTypes=M0e.anyAtomicT}getExpression(e){const r=this.expr.getExpression(e),i=this.altExpr.getExpression(e);return r.type==="null"?i:(M0e.typeEq(r,i)||this.logError("mismatched-coalesce-types",`Mismatched types for coalesce (${r.type}, ${i.type})`),{...r.type==="error"?i:r,expressionType:(0,k0e.maxExpressionType)(r.expressionType,i.expressionType),value:{node:"coalesce",kids:{left:r.value,right:i.value}},evalSpace:(0,k0e.mergeEvalSpaces)(r.evalSpace,i.evalSpace)})}}uT.ExprCoalesce=Cat;var aT={};Object.defineProperty(aT,"__esModule",{value:!0}),aT.ExprCount=void 0;const Sat=dt,bat=E0;class Tat extends bat.ExprAggregateFunction{constructor(e){super("count"),this.source=e,this.elementType="count",this.has({source:e})}defaultFieldName(){if(this.source)return"count_"+this.source.nameString}returns(e){return{type:"number",numberType:"integer",evalSpace:e.evalSpace,expressionType:"aggregate",value:e.value,compositeFieldUsage:e.compositeFieldUsage}}getExpression(e){const r={node:"aggregate",function:"count",e:{node:""}};return this.source&&(r.structPath=this.source.path),{type:"number",numberType:"integer",expressionType:"aggregate",value:r,evalSpace:"output",compositeFieldUsage:(0,Sat.emptyCompositeFieldUsage)()}}}aT.ExprCount=Tat;var lT={},Rat=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),Dat=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),Oat=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&Rat(e,t,r);return Dat(e,t),e};Object.defineProperty(lT,"__esModule",{value:!0}),lT.ExprCountDistinct=void 0;const cT=Oat(nn),Fat=E0;class wat extends Fat.ExprAggregateFunction{constructor(e){super("distinct",e),this.legalChildTypes=[cT.numberT,cT.stringT,cT.dateT,cT.timestampT]}returns(e){return{type:"number",numberType:"integer",evalSpace:e.evalSpace,expressionType:"aggregate",value:e.value,compositeFieldUsage:e.compositeFieldUsage}}}lT.ExprCountDistinct=wat;var fT={},nf={};Object.defineProperty(nf,"__esModule",{value:!0}),nf.Limit=void 0;const Nat=Ze,Lat=zn;class Iat extends Nat.MalloyElement{constructor(e){super(),this.limit=e,this.elementType="limit",this.queryRefinementStage=Lat.LegalRefinementStage.Tail,this.forceQueryClass=void 0}}nf.Limit=Iat;var G2={};Object.defineProperty(G2,"__esModule",{value:!0}),G2.PartitionBy=void 0;const $at=Ze;class Bat extends $at.ListOf{constructor(e){super(e),this.partitionFields=e,this.elementType="partition_by"}}G2.PartitionBy=Bat;var DE={},rf={};Object.defineProperty(rf,"__esModule",{value:!0}),rf.FieldName=void 0;const kat=Ze;class Mat extends kat.MalloyElement{constructor(e){super(),this.name=e,this.elementType="fieldName"}get refString(){return this.name}toString(){return this.refString}getField(e){return e.lookup([this])}}rf.FieldName=Mat;var Pat=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),Uat=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),jat=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&Pat(e,t,r);return Uat(e,t),e};Object.defineProperty(DE,"__esModule",{value:!0}),DE.ExprFunc=void 0;const Or=et,qat=Hs,Hat=Cd,Qat=Yt,zat=ht,Wat=rf,P0e=kt,U0e=jat(nn),Gat=dt;class Vat extends zat.ExpressionDef{constructor(e,r,i,s,o){super({args:r}),this.name=e,this.args=r,this.isRaw=i,this.rawType=s,this.source=o,this.elementType="function call()",this.has({source:o})}canSupportPartitionBy(){return!0}canSupportOrderBy(){return!0}canSupportLimit(){return!0}getExpression(e){return this.getPropsExpression(e)}findFunctionDef(e){var r,i,s;const o=this.name.toLowerCase(),u=e?(i=(r=this.getDialectNamespace(e))===null||r===void 0?void 0:r.getEntry(o))===null||i===void 0?void 0:i.entry:void 0,a=u??((s=this.modelEntry(o))===null||s===void 0?void 0:s.entry);return a===void 0?(this.logError("function-not-found",`Unknown function '${this.name}'. Use '${this.name}!(...)' to call a SQL function directly.`),{found:void 0,error:"unknown function"}):a.type!=="function"?(this.logError("call-of-non-function",`'${this.name}' (with type ${a.type}) is not a function`),{found:void 0,error:"called non function"}):(a.name!==this.name&&this.logWarning("case-insensitive-function",`Case insensitivity for function names is deprecated, use '${a.name}' instead`),{found:a,error:void 0})}getPropsExpression(e,r){var i,s,o,u;const a=this.args.map(B=>B.getExpression(e));if(this.isRaw){const B=[`${this.name}(`];a.forEach((U,V)=>{V!==0&&B.push(","),B.push(U.value)}),B.push(")");const D=(i=a[0])!==null&&i!==void 0?i:{type:"number"},$=this.rawType?{type:this.rawType}:D;return(0,Qat.computedExprValue)({dataType:$,value:(0,P0e.composeSQLExpr)(B),from:a})}const l=(s=e.dialectObj())===null||s===void 0?void 0:s.name,{found:c,error:f}=this.findFunctionDef(l);if(c===void 0)return(0,qat.errorFor)(f);let x,h=(o=this.source)===null||o===void 0?void 0:o.path;if(this.source){const D=this.source.getField(e).found;if(D){const $=D.typeDesc();if((0,Or.isAtomicFieldType)($.type))x={...U0e.atomicDef($),expressionType:$.expressionType,value:{node:"field",path:this.source.path},evalSpace:$.evalSpace,compositeFieldUsage:$.compositeFieldUsage},h=this.source.path.slice(0,-1);else if(!(D instanceof Hat.StructSpaceFieldBase))return this.loggedErrorExpr("invalid-aggregate-source",`Aggregate source cannot be a ${$.type}`)}else this.loggedErrorExpr("aggregate-source-not-found",`Reference to undefined value ${this.source.refString}`)}const p=[...x?[x]:[],...a],m=Yat(c,p);if(m===void 0)return this.loggedErrorExpr("no-matching-function-overload",`No matching overload for function ${this.name}(${p.map(B=>B.type).join(", ")})`);const{overload:g,expressionTypeErrors:y,evalSpaceErrors:E,nullabilityErrors:A,returnType:_}=m;for(const B of y){const D=B.argIndex-(x?1:0),$=(0,Or.expressionIsScalar)(B.maxExpressionType)?"scalar":"scalar or aggregate";this.args[D].logError("invalid-function-argument-expression-type",`Parameter ${B.argIndex+1} ('${B.param.name}') of ${this.name} must be ${$}, but received ${B.actualExpressionType}`)}for(const B of E){const D=B.argIndex-(x?1:0),$=B.maxEvalSpace==="literal"?"literal":B.maxEvalSpace==="constant"?"literal or constant":"literal, constant or output";this.args[D].logError("invalid-function-argument-evaluation-space",`Parameter ${B.argIndex+1} ('${B.param.name}') of ${this.name} must be ${$}, but received ${B.actualEvalSpace}`)}for(const B of A){const D=B.argIndex-(x?1:0);this.args[D].logError("literal-null-function-argument",`Parameter ${B.argIndex+1} ('${B.param.name}') of ${this.name} must not be a literal null`)}m.returnTypeError&&this.logError(m.returnTypeError.code,m.returnTypeError.parameters);const v=g.returnType,C=(0,Or.maxOfExpressionTypes)([(u=v.expressionType)!==null&&u!==void 0?u:"scalar",...p.map(B=>B.expressionType)]);if(!(0,Or.expressionIsAggregate)(g.returnType.expressionType)&&this.source!==void 0)return this.loggedErrorExpr("non-aggregate-function-with-source",`Cannot call function ${this.name}(${p.map(B=>B.type).join(", ")}) with source`);const S={node:"function_call",overload:g,name:this.name,kids:{args:p.map(B=>B.value)},expressionType:C,structPath:h};let b=S;if(r!=null&&r.orderBys&&r.orderBys.length>0){const B=(0,Or.expressionIsAnalytic)(g.returnType.expressionType);if(B||this.inExperiment("aggregate_order_by",!0)||r.orderBys[0].logError("aggregate-order-by-experiment-not-enabled","Enable experiment `aggregate_order_by` to use `order_by` with an aggregate function"),g.supportsOrderBy||B){const D=g.supportsOrderBy!=="only_default",$=r.orderBys.flatMap(U=>B?U.getAnalyticOrderBy(e):U.getAggregateOrderBy(e,D));S.kids.orderBy=$}else r.orderBys[0].logError("function-does-not-support-order-by",`Function \`${this.name}\` does not support \`order_by\``)}if((r==null?void 0:r.limit)!==void 0&&(g.supportsLimit?S.limit=r.limit.limit:this.logError("function-does-not-support-limit",`Function ${this.name} does not support limit`)),r!=null&&r.partitionBys&&r.partitionBys.length>0){const B=[];for(const D of r.partitionBys)for(const $ of D.partitionFields){const U=$.getField(e);U.found===void 0?$.logError("partition-by-not-found",`${$.refString} is not defined`):(0,Or.expressionIsAnalytic)(U.found.typeDesc().expressionType)||(0,Or.expressionIsUngroupedAggregate)(U.found.typeDesc().expressionType)?$.logError("non-scalar-or-aggregate-partition-by","Partition expression must be scalar or aggregate"):B.push($.nameString)}S.partitionBy=B}if(["sql_number","sql_string","sql_date","sql_timestamp","sql_boolean"].includes(c.name)){if(!this.inExperiment("sql_functions",!0))return this.loggedErrorExpr("sql-functions-experiment-not-enabled",`Cannot use sql_function \`${c.name}\`; use \`sql_functions\` experiment to enable this behavior`);const B=p[0].value;if(B.node!=="stringLiteral")this.logError("invalid-sql-function-argument",`Invalid string literal for \`${c.name}\``);else{const D=B.literal,$=Kat(D),U=$.filter(Q=>Q.type==="interpolation"&&Q.name.includes(".")).map(Q=>Q.type==="interpolation"?`\${${Q.name}}`:`\${${Q.value}}`);if(U.length>0){const Q=U.length===1?`'.' paths are not yet supported in sql interpolations, found ${U.at(0)}`:`'.' paths are not yet supported in sql interpolations, found (${U.join(", ")})`;return this.loggedErrorExpr("unsupported-sql-function-interpolation",Q)}const V=[];for(const Q of $)if(Q.type==="string")V.push(Q.value);else if(Q.name==="TABLE")V.push({node:"source-reference"});else{const X=new Wat.FieldName(Q.name);this.has({name:X});const xe=e.lookup([X]);if(xe.found===void 0)return this.loggedErrorExpr("sql-function-interpolation-not-found",`Invalid interpolation: ${xe.error.message}`);if(xe.found.typeDesc().type==="filter expression")return this.loggedErrorExpr("filter-expression-error","Filter expressions cannot be used in sql_ functions");xe.found.refType==="parameter"?V.push({node:"parameter",path:[Q.name]}):V.push({node:"field",path:[Q.name]})}b=(0,P0e.composeSQLExpr)(V)}}const R=(0,Or.mergeEvalSpaces)(...p.map(B=>B.evalSpace)),O=R==="constant"?"constant":(0,Or.expressionIsScalar)(C)?R:"output";return{...(0,Or.isAtomic)(_)?U0e.atomicDef(_):_,expressionType:C,value:b,evalSpace:O,compositeFieldUsage:(0,Gat.mergeCompositeFieldUsage)(...p.map(B=>B.compositeFieldUsage))}}}DE.ExprFunc=Vat;function Yat(t,e){var r;for(const i of t.overloads){const s=new Map;let o=0,u=!0,a=!1;const l=[],c=[],f=[];for(let p=0;p<e.length;p++){const m=e[p],g=i.params[o];if(g===void 0){u=!1;break}if(!g.allowedTypes.some(E=>{var A;const{dataTypeMatch:_,genericsSet:v}=V2(s,(A=i.genericTypes)!==null&&A!==void 0?A:[],m,E);for(const C of v)s.set(C.name,C.type);return E.expressionType&&((0,Or.isExpressionTypeLEQ)(m.expressionType,E.expressionType)||l.push({argIndex:p,maxExpressionType:E.expressionType,actualExpressionType:m.expressionType,param:g})),(E.evalSpace==="literal"&&m.evalSpace!=="literal"||E.evalSpace==="constant"&&(m.evalSpace==="input"||m.evalSpace==="output")||(0,Or.expressionIsAnalytic)(i.returnType.expressionType)&&m.evalSpace==="input")&&c.push({argIndex:p,param:g,maxEvalSpace:E.evalSpace,actualEvalSpace:m.evalSpace}),E.evalSpace==="literal"&&m.type==="null"&&f.push({argIndex:p,param:g}),_})){u=!1;break}g.isVariadic?p===e.length-1&&(a=!0):o++}if(!a&&(o!==e.length||o!==i.params.length))continue;const x=xT(i.returnType,s),h=(r=x.returnType)!==null&&r!==void 0?r:{type:"number"};if(u)return{overload:i,expressionTypeErrors:l,evalSpaceErrors:c,nullabilityErrors:f,returnTypeError:x.error,returnType:h}}}function Kat(t){const e=[];let r=t;for(;r.length;){const i=r.indexOf("${");if(i===-1){e.push({type:"string",value:r});break}else{const s=r.slice(i).indexOf("}");if(s===-1){e.push({type:"string",value:r});break}i>0&&e.push({type:"string",value:r.slice(0,i)}),e.push({type:"interpolation",name:r.slice(i+2,s+i)}),r=r.slice(s+i+1)}}return e}function V2(t,e,r,i){var s,o,u,a;if(Or.TD.eq(i,r)||i.type==="any"||i.type!=="generic"&&(r.type==="null"||r.type==="error"))return{dataTypeMatch:!0,genericsSet:[]};if(i.type==="array"&&r.type==="array"){if((0,Or.isBasicArray)(r))return(0,Or.isRepeatedRecordFunctionParam)(i)?{dataTypeMatch:!1,genericsSet:[]}:V2(t,e,r.elementTypeDef,i.elementTypeDef);if((0,Or.isRepeatedRecordFunctionParam)(i)){const l={type:"record",fields:i.fields},c={type:"record",fields:r.fields};return V2(t,e,c,l)}else return{dataTypeMatch:!1,genericsSet:[]}}else if(i.type==="record"&&r.type==="record"){const l=[],c=new Map;for(const f of i.fields)c.set((s=f.as)!==null&&s!==void 0?s:f.name,f);for(const f of r.fields){const x=c.get((o=f.as)!==null&&o!==void 0?o:f.name);if(x===void 0)return{dataTypeMatch:!1,genericsSet:[]};const h=V2(new Map([...t.entries(),...l.map(p=>[p.name,p.type])]),e,f,x);l.push(...h.genericsSet)}return{dataTypeMatch:!0,genericsSet:l}}else if(i.type==="generic"){const l=t.get(i.generic);if(l!==void 0&&l.type!=="null"&&l.type!=="error")return V2(t,e,r,l);const c=(a=(u=e.find(f=>f.name===i.generic))===null||u===void 0?void 0:u.acceptibleTypes)!==null&&a!==void 0?a:[];for(const f of c){const x=V2(t,e,r,f);if(x.dataTypeMatch){if(!(0,Or.isAtomic)(r)&&r.type!=="null")continue;const h={name:i.generic,type:r};return{dataTypeMatch:!0,genericsSet:[...x.genericsSet,h]}}}}return{dataTypeMatch:!1,genericsSet:[]}}function xT(t,e){switch(t.type){case"array":{if("fields"in t){const s=t.fields.map(o=>{const u=xT(o,e);return{...o,...u}});return{error:void 0,returnType:{type:"array",elementTypeDef:t.elementTypeDef,fields:s}}}const r=xT(t.elementTypeDef,e);if(r.error)return r;const i=r.returnType;return i.type==="record"?{error:void 0,returnType:{type:"array",elementTypeDef:{type:"record_element"},fields:i.fields}}:(0,Or.isAtomic)(i)?{error:void 0,returnType:{type:"array",elementTypeDef:i}}:{error:{code:"invalid-resolved-type-for-array",parameters:"Invalid resolved type for array; cannot be non-atomic"},returnType:void 0}}case"record":return{error:void 0,returnType:{type:"record",fields:t.fields.map(i=>{const s=xT(i,e);return{...i,...s}})}};case"generic":{const r=e.get(t.generic);return r===void 0?{error:{code:"generic-not-resolved",parameters:`Generic ${t.generic} in return type could not be resolved`},returnType:void 0}:{error:void 0,returnType:r}}default:return{error:void 0,returnType:t}}}var Jat=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),Xat=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),Zat=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&Jat(e,t,r);return Xat(e,t),e};Object.defineProperty(fT,"__esModule",{value:!0}),fT.ExprProps=void 0;const elt=et,tlt=Hs,nlt=Zat(nn),rlt=tf,ilt=nf,slt=G2,olt=ht,ult=DE,alt=dt;class llt extends olt.ExpressionDef{constructor(e,r){super({expr:e,statements:r}),this.expr=e,this.statements=r,this.elementType="expression with props",this.legalChildTypes=nlt.anyAtomicT}getFilteredExpression(e,r,i){if(i.length>0){if(!this.expr.supportsWhere(r))return this.expr.logError("filter-of-non-aggregate","Filtered expression requires an aggregate computation"),r;const s=[];for(const o of i){const u=o.getFilterList(e);if(u.find(a=>(0,elt.expressionIsCalculation)(a.expressionType)))return o.logError("aggregate-filter-expression-not-scalar","Cannot filter an expresion with an aggregate or analytical computation"),r;s.push(...u)}return this.typeCheck(this.expr,{...r,expressionType:"scalar"})?{...r,compositeFieldUsage:(0,alt.mergeCompositeFieldUsage)(r.compositeFieldUsage,...s.map(o=>o.compositeFieldUsage)),value:{node:"filteredExpr",kids:{e:r.value,filterList:s}}}:(this.expr.logError("filter-of-non-aggregate",`Cannot filter '${r.expressionType}' data`),(0,tlt.errorFor)("cannot filter type"))}return r}getExpression(e){const r=[];let i;const s=[],o=[];for(const a of this.statements)a instanceof slt.PartitionBy?this.expr.canSupportPartitionBy()?r.push(a):a.logError("partition-by-of-non-window-function","`partition_by` is not supported for this kind of expression"):a instanceof ilt.Limit?i?a.logError("expression-limit-already-specified","limit already specified"):this.expr.canSupportLimit()?i=a:a.logError("limit-of-non-aggregate-function","`limit` is not supported for this kind of expression"):a instanceof rlt.FunctionOrdering?this.expr.canSupportOrderBy()?s.push(a):a.logError("order-by-of-non-aggregate-function","`order_by` is not supported for this kind of expression"):o.push(a);const u=this.expr instanceof ult.ExprFunc?this.expr.getPropsExpression(e,{partitionBys:r,limit:i,orderBys:s}):this.expr.getExpression(e);return this.getFilteredExpression(e,u,o)}}fT.ExprProps=llt;var dT={},clt=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),flt=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),xlt=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&clt(e,t,r);return flt(e,t),e};Object.defineProperty(dT,"__esModule",{value:!0}),dT.ExprLogicalOp=void 0;const dlt=bE,j0e=xlt(nn);class hlt extends dlt.BinaryBoolean{constructor(){super(...arguments),this.elementType="logical operator",this.legalChildTypes=[j0e.boolT,j0e.aggregateBoolT]}}dT.ExprLogicalOp=hlt;var hT={},plt=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),mlt=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),glt=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&plt(e,t,r);return mlt(e,t),e};Object.defineProperty(hT,"__esModule",{value:!0}),hT.ExprMax=void 0;const pT=glt(nn),ylt=E0;class Elt extends ylt.ExprAggregateFunction{constructor(e){super("max",e),this.legalChildTypes=[pT.numberT,pT.stringT,pT.dateT,pT.timestampT]}returns(e){return e}}hT.ExprMax=Elt;var mT={},Alt=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),_lt=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),vlt=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&Alt(e,t,r);return _lt(e,t),e};Object.defineProperty(mT,"__esModule",{value:!0}),mT.ExprMin=void 0;const gT=vlt(nn),Clt=E0;class Slt extends Clt.ExprAggregateFunction{constructor(e){super("min",e),this.legalChildTypes=[gT.numberT,gT.stringT,gT.dateT,gT.timestampT]}returns(e){return e}}mT.ExprMin=Slt;var yT={},blt=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),Tlt=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),Rlt=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&blt(e,t,r);return Tlt(e,t),e};Object.defineProperty(yT,"__esModule",{value:!0}),yT.ExprMinus=void 0;const Dlt=Hs,q0e=Rlt(nn),Olt=ht;class Flt extends Olt.ExpressionDef{constructor(e){super({expr:e}),this.expr=e,this.elementType="unary minus",this.legalChildTypes=[q0e.numberT]}getExpression(e){const r=this.expr.getExpression(e);return q0e.typeIn(r,this.legalChildTypes)?{...r,type:"number",value:{node:"unary-",e:r.value}}:(0,Dlt.errorFor)("negate requires number")}}yT.ExprMinus=Flt;var ET={};Object.defineProperty(ET,"__esModule",{value:!0}),ET.ExprMulDiv=void 0;const wlt=H2;class Nlt extends wlt.BinaryNumeric{constructor(){super(...arguments),this.elementType="*/%"}}ET.ExprMulDiv=Nlt;var AT={},OE={};Object.defineProperty(OE,"__esModule",{value:!0}),OE.Unary=void 0;const Llt=ht;class Ilt extends Llt.ExpressionDef{constructor(e){super({expr:e}),this.expr=e}}OE.Unary=Ilt;var $lt=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),Blt=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),klt=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&$lt(e,t,r);return Blt(e,t),e};Object.defineProperty(AT,"__esModule",{value:!0}),AT.ExprNot=void 0;const lk=klt(nn),Mlt=OE;class Plt extends Mlt.Unary{constructor(e){super(e),this.elementType="not",this.legalChildTypes=[lk.boolT,lk.nullT]}getExpression(e){var r;const i=this.expr.getExpression(e);!((r=e.dialectObj())===null||r===void 0)&&r.booleanAsNumbers&&this.legalChildTypes.find(o=>o.type==="number")===void 0&&this.legalChildTypes.push(lk.numberT);const s=this.typeCheck(this.expr,i);return{...i,type:"boolean",value:{node:"not",e:s?i.value:{node:"false"}}}}}AT.ExprNot=Plt;var _T={};Object.defineProperty(_T,"__esModule",{value:!0}),_T.ExprNow=void 0;const Ult=ht,jlt=dt;class qlt extends Ult.ExpressionDef{constructor(){super(...arguments),this.elementType="timestamp"}getExpression(e){return{type:"timestamp",expressionType:"scalar",evalSpace:"constant",value:{node:"now",typeDef:{type:"timestamp"}},compositeFieldUsage:(0,jlt.emptyCompositeFieldUsage)()}}}_T.ExprNow=qlt;var sf={};Object.defineProperty(sf,"__esModule",{value:!0}),sf.ExprIsNull=sf.PartialIsNull=sf.ExprNULL=void 0;const Hlt=Yt,vT=ht;function ck(t,e,r){const i=r.getExpression(t);return i.type="boolean",i.value={node:e==="="?"is-null":"is-not-null",e:i.value},i}class Qlt extends vT.ExpressionDef{constructor(){super(...arguments),this.elementType="NULL"}getExpression(){return(0,Hlt.literalExprValue)({dataType:{type:"null"},value:{node:"null"}})}apply(e,r,i){return r==="!="||r==="="?ck(e,r,i):super.apply(e,r,i,!0)}}sf.ExprNULL=Qlt;class zlt extends vT.ExpressionDef{constructor(e){super(),this.op=e,this.elementType="<=> NULL"}apply(e,r,i){return ck(e,this.op,i)}requestExpression(e){}getExpression(e){return this.loggedErrorExpr("partial-as-value","Partial null check does not have a value")}atNodeType(){return vT.ATNodeType.Partial}}sf.PartialIsNull=zlt;class Wlt extends vT.ExpressionDef{constructor(e,r){super(),this.expr=e,this.op=r,this.elementType="is null",this.has({expr:e})}getExpression(e){return ck(e,this.op,this.expr)}}sf.ExprIsNull=Wlt;var CT={};Object.defineProperty(CT,"__esModule",{value:!0}),CT.ExprNumber=void 0;const Glt=Yt,Vlt=ht;class Ylt extends Vlt.ExpressionDef{constructor(e){super(),this.n=e,this.elementType="numeric literal"}getExpression(e){return this.constantExpression()}constantExpression(){const e=Number(this.n),r=Number.isNaN(e)?{type:"number"}:{type:"number",numberType:Number.isInteger(e)?"integer":"float"};return(0,Glt.literalExprValue)({dataType:r,value:{node:"numberLiteral",literal:this.n}})}}CT.ExprNumber=Ylt;var ST={};Object.defineProperty(ST,"__esModule",{value:!0}),ST.ExprParens=void 0;const fk=ht;class Klt extends fk.ExpressionDef{constructor(e){super({expr:e}),this.expr=e,this.elementType="(expression)"}requestExpression(e){return this.expr.requestExpression(e)}getExpression(e){const r=this.expr.getExpression(e);return{...r,value:{node:"()",e:r.value}}}apply(e,r,i,s){return this.expr.atNodeType()===fk.ATNodeType.Or?this.expr.apply(e,r,i,s):(0,fk.applyBinary)(e,i,r,this)}atNodeType(){return this.expr.atNodeType()}atExpr(){return this.expr}}ST.ExprParens=Klt;var bT={};Object.defineProperty(bT,"__esModule",{value:!0}),bT.ExprFilterExpression=void 0;const Jlt=ht;class Xlt extends Jlt.ExpressionDef{constructor(e){super(),this.filterText=e,this.elementType="filter expression literal"}getExpression(){return{type:"filter expression",value:{node:"filterLiteral",filterSrc:this.filterText},expressionType:"scalar",evalSpace:"constant",compositeFieldUsage:{fields:[],joinedUsage:{}}}}}bT.ExprFilterExpression=Xlt;var TT={};Object.defineProperty(TT,"__esModule",{value:!0}),TT.ExprRegEx=void 0;const Zlt=Yt,e0t=ht;class t0t extends e0t.ExpressionDef{constructor(e){super(),this.regex=e,this.elementType="regular expression literal"}getExpression(){return(0,Zlt.literalExprValue)({dataType:{type:"regular expression"},value:{node:"regexpLiteral",literal:this.regex}})}}TT.ExprRegEx=t0t;var RT={};Object.defineProperty(RT,"__esModule",{value:!0}),RT.ExprString=void 0;const n0t=ht,r0t=Yt;class i0t extends n0t.ExpressionDef{constructor(e){super(),this.elementType="string literal",this.value=e}getExpression(e){return(0,r0t.literalExprValue)({dataType:{type:"string"},value:{node:"stringLiteral",literal:this.value}})}}RT.ExprString=i0t;var DT={};Object.defineProperty(DT,"__esModule",{value:!0}),DT.ExprSum=void 0;const s0t=W2;class o0t extends s0t.ExprAsymmetric{constructor(e,r,i){super("sum",e,r,i),this.has({source:r})}}DT.ExprSum=o0t;var OT={};Object.defineProperty(OT,"__esModule",{value:!0}),OT.ExprTimeExtract=void 0;const A0=et,FT=Yt,xk=ht,u0t=ef;class FE extends xk.ExpressionDef{static extractor(e){const r=FE.pluralMap[e];if(r)return r;if((0,A0.isExtractUnit)(e))return e}constructor(e,r){super({args:r}),this.extractText=e,this.args=r,this.elementType="timeExtract"}getExpression(e){const r=FE.extractor(this.extractText);if(r){if(this.args.length!==1)return this.loggedErrorExpr("too-many-arguments-for-time-extraction",`Extraction function ${r} requires one argument`);const i=this.args[0];if(i instanceof u0t.Range){let s=i.first.getExpression(e),o=i.last.getExpression(e);if(s.type==="error"||o.type==="error")return(0,FT.computedErrorExprValue)({dataType:{type:"number"},error:"extract from error",from:[s,o]});if(!(0,A0.isTemporalType)(s.type))return i.first.loggedErrorExpr("invalid-type-for-time-extraction",`Can't extract ${r} from '${s.type}'`);if(!(0,A0.isTemporalType)(o.type))return i.last.loggedErrorExpr("invalid-type-for-time-extraction",`Cannot extract ${r} from '${o.type}'`);let u=s.type;if(!A0.TD.eq(s,o)){let a=!0;if(u="timestamp",s.type==="date"){const l=(0,xk.getMorphicValue)(s,"timestamp");l&&(s=l,a=!1)}else{const l=(0,xk.getMorphicValue)(o,"timestamp");l&&(o=l,a=!1)}if(a)return i.first.loggedErrorExpr("invalid-types-for-time-measurement",`Cannot measure from ${s.type} to ${o.type}`)}return["week","month","quarter","year"].includes(r)?this.loggedErrorExpr("invalid-timeframe-for-time-measurement",`Cannot measure interval using '${r}'`):(0,A0.isTimestampUnit)(r)?(0,FT.computedExprValue)({dataType:{type:"number",numberType:"integer"},value:{node:"timeDiff",units:r,kids:{left:(0,A0.mkTemporal)(s.value,u),right:(0,A0.mkTemporal)(o.value,u)}},from:[s,o]}):this.loggedErrorExpr("invalid-time-extraction-unit",`Cannot extract ${r} from a range`)}else{const s=i.getExpression(e);return(0,A0.isTemporalType)(s.type)?(0,FT.computedExprValue)({dataType:{type:"number",numberType:"integer"},value:{node:"extract",e:(0,A0.mkTemporal)(s.value,s.type),units:r},from:[s]}):(s.type!=="error"&&this.logError("unsupported-type-for-time-extraction",`${this.extractText}() requires time type, not '${s.type}'`),(0,FT.computedErrorExprValue)({dataType:{type:"number",numberType:"integer"},error:`${this.extractText} bad type ${s.type}`,from:[s]}))}}throw this.internalError(`Illegal extraction unit '${this.extractText}'`)}}OT.ExprTimeExtract=FE,FE.pluralMap={years:"year",quarters:"quarter",months:"month",weeks:"week",days:"day",hours:"hour",minutes:"minute",seconds:"second"};var wT={},Du={},NT={};Object.defineProperty(NT,"__esModule",{value:!0}),NT.QueryInputSpace=void 0;const a0t=ys,l0t=w2;class c0t extends l0t.RefinedSpace{constructor(e,r,i){super(e),this.queryOutput=r,this._isProtectedAccessSpace=i,this.extendList=[]}extendSource(e){this.pushFields(e),e instanceof a0t.Join?this.extendList.push(e.name.refString):this.extendList.push(e.defineName)}isQueryFieldSpace(){return!0}outputSpace(){return this.queryOutput}inputSpace(){return this}isProtectedAccessSpace(){return this._isProtectedAccessSpace}}NT.QueryInputSpace=c0t;var f0t=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),x0t=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),d0t=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&f0t(e,t,r);return x0t(e,t),e};Object.defineProperty(Du,"__esModule",{value:!0}),Du.ReduceFieldSpace=Du.QuerySpace=Du.QueryOperationSpace=void 0;const LT=d0t(et),dk=Vc,H0e=rf,Q0e=zr,h0t=_t,p0t=w2,m0t=cE,g0t=Wr,y0t=NT,Ha=dt,E0t=Cd;class z0e extends p0t.RefinedSpace{get compositeFieldUsage(){if(this._compositeFieldUsage===void 0)throw new Error("Composite field usage accessed before computed");return this._compositeFieldUsage}constructor(e,r,i,s){super(e.emptyStructDef()),this.queryInputSpace=e,this.nestParent=i,this.astEl=s,this.expandedWild={},this.compositeFieldUsers=[],this._compositeFieldUsage=void 0,this.exprSpace=new y0t.QueryInputSpace(e.structDef(),this,e.isProtectedAccessSpace()),r&&this.addRefineFromFields(r)}logError(e,r,i){return this.astEl&&this.astEl.logError(e,r,i),e}inputSpace(){return this.exprSpace}outputSpace(){return this}addWild(e){var r;let i=this.exprSpace;const s=[];if(e.joinPath)for(const a of e.joinPath.list){const l=a.refString;s.push(l);const c=i.entry(l);if(c)if(c instanceof g0t.StructSpaceField)i=c.fieldSpace;else{a.logError("invalid-wildcard-source",`Field '${l}' does not contain rows and cannot be expanded with '*'`);return}else{a.logError("wildcard-source-not-defined",`No such field as '${l}'`);return}}const o=this.dialectObj(),u=[];for(const[a,l]of i.entries())if(!e.except.has(a)&&l.refType!=="parameter")if(this.entry(a)){const c=(r=this.expandedWild[a])===null||r===void 0?void 0:r.path.join(".");e.logError("name-conflict-in-wildcard-expansion",`Cannot expand '${a}' in '${e.refString}' because a field with that name already exists${c?` (conflicts with ${c})`:""}`)}else{const c=l.typeDesc();LT.TD.isAtomic(c)&<.expressionIsScalar(c.expressionType)&&(o===void 0||!o.ignoreInProject(a))&&(u.push({name:a,entry:l}),this.expandedWild[a]={path:s.concat(a),entry:l})}for(const a of u.sort((l,c)=>l.name.localeCompare(c.name)))this.newEntry(a.name,e,a.entry)}addValidatedCompositeFieldUserFromEntry(e,r){r instanceof Q0e.SpaceField&&this.compositeFieldUsers.push({type:"field",name:e,field:r,logTo:void 0})}getJoinOnCompositeFieldUsage(e){var r;const i=e.map(o=>new H0e.FieldName(o));this.astEl.has({reference:i});const s=this.exprSpace.lookup(i);if(s.found&&s.found instanceof E0t.StructSpaceFieldBase)return(0,Ha.joinedCompositeFieldUsage)(e.slice(0,-1),(r=s.found.fieldDef().onCompositeFieldUsage)!==null&&r!==void 0?r:(0,Ha.emptyCompositeFieldUsage)());throw new Error("Unexpected join lookup was not found or not a struct")}getCompositeFieldUsageIncludingJoinOns(e){let r=e;const i=(0,Ha.compositeFieldUsageJoinPaths)(e);for(const s of i)r=(0,Ha.mergeCompositeFieldUsage)(this.getJoinOnCompositeFieldUsage(s),r);return r}addCompositeFieldUserFromFilter(e,r){e.compositeFieldUsage!==void 0&&this.compositeFieldUsers.push({type:"filter",filter:e,logTo:r})}newEntry(e,r,i){i instanceof Q0e.SpaceField&&this.compositeFieldUsers.push({type:"field",name:e,field:i,logTo:r}),super.newEntry(e,r,i)}applyNextCompositeFieldUsage(e,r,i,s,o){if(s){const u=this.getCompositeFieldUsageIncludingJoinOns((0,Ha.compositeFieldUsageDifference)(s,r));if(r=(0,Ha.mergeCompositeFieldUsage)(r,u),!(0,Ha.isEmptyCompositeFieldUsage)(u)){const a=(0,Ha.narrowCompositeFieldResolution)(e,r,i);a.error?(o??this).logError("invalid-composite-field-usage",{newUsage:u,allUsage:r}):i=a.narrowedCompositeFieldResolution}}return{compositeFieldUsage:r,narrowedCompositeFieldResolution:i}}}Du.QueryOperationSpace=z0e;class W0e extends z0e{addRefineFromFields(e){var r;if(LT.isQuerySegment(e)){if(e!=null&&e.extendSource)for(const i of e.extendSource)this.exprSpace.addFieldDef(i);for(const i of e.queryFields)if(i.type==="fieldref"){const s=this.exprSpace.lookup(i.path.map(o=>new H0e.FieldName(o)));if(s.found){const o=i.path[i.path.length-1];this.setEntry(o,s.found),this.addValidatedCompositeFieldUserFromEntry(o,s.found)}}else if(i.type!=="turtle"){const s=new m0t.ColumnSpaceField(i),o=(r=i.as)!==null&&r!==void 0?r:i.name;this.setEntry(o,s),this.addValidatedCompositeFieldUserFromEntry(o,s)}}}pushFields(...e){for(const r of e)r instanceof h0t.WildcardFieldReference?this.addWild(r):super.pushFields(r)}canContain(e){return!0}queryFieldDefs(){const e=[];let r=(0,Ha.emptyCompositeFieldUsage)(),i=(0,Ha.emptyNarrowedCompositeFieldResolution)();const s=this.inputSpace().structDef();for(const o of this.compositeFieldUsers){let u;if(o.type==="filter")o.filter.compositeFieldUsage&&(u=o.filter.compositeFieldUsage);else{const{name:l,field:c}=o,f=this.expandedWild[l];if(f)e.push({type:"fieldref",path:f.path}),u=f.entry.typeDesc().compositeFieldUsage;else{const x=c.getQueryFieldDef(this.exprSpace);if(x){const h=c.typeDesc();u=h.compositeFieldUsage,h&&h.type!=="error"&&this.canContain(h)&&!_0t(x)&&e.push(x)}}}const a=this.applyNextCompositeFieldUsage(s,r,i,u,o.logTo);r=a.compositeFieldUsage,i=a.narrowedCompositeFieldResolution}return this._compositeFieldUsage=r,e}getQuerySegment(e){const r=this.getPipeSegment(e);if(LT.isQuerySegment(r))return r;throw new Error("TODO NOT POSSIBLE")}getPipeSegment(e){if(this.segmentType==="index")return this.logError("unexpected-index-segment","internal error generating index segment from non index query"),{type:"reduce",queryFields:[]};const r={type:this.segmentType,queryFields:this.queryFieldDefs()};if(r.queryFields=(0,dk.mergeFields)(e==null?void 0:e.queryFields,r.queryFields),e!=null&&e.extendSource&&(r.extendSource=e.extendSource),this.exprSpace.extendList.length>0){const i=[],s=this.exprSpace.structDef();for(const o of this.exprSpace.extendList){const u=s.fields.find(a=>(0,dk.nameFromDef)(a)===o);u&&i.push(u)}r.extendSource=(0,dk.mergeFields)(r.extendSource,i)}return this.newTimezone&&(r.queryTimezone=this.newTimezone),r}lookup(e){const r=super.lookup(e);return r.found?{...r,isOutputField:!0}:this.exprSpace.lookup(e)}isQueryFieldSpace(){return!0}}Du.QuerySpace=W0e;class A0t extends W0e{constructor(){super(...arguments),this.segmentType="reduce"}}Du.ReduceFieldSpace=A0t;function _0t(t){return typeof t!="string"&&t.type==="turtle"&&t.pipeline.length===0}var v0t=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),C0t=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),S0t=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&v0t(e,t,r);return C0t(e,t),e};Object.defineProperty(wT,"__esModule",{value:!0}),wT.ExprUngroup=void 0;const G0e=et,b0t=Du,V0e=S0t(nn),T0t=ht;class R0t extends T0t.ExpressionDef{constructor(e,r,i){super({expr:r,fields:i}),this.control=e,this.expr=r,this.fields=i,this.legalChildTypes=V0e.anyAtomicT,this.elementType="ungroup"}getExpression(e){const r=this.expr.getExpression(e);if(!(0,G0e.expressionIsAggregate)(r.expressionType))return this.expr.loggedErrorExpr("ungroup-of-non-aggregate",`${this.control}() expression must be an aggregate`);if((0,G0e.expressionIsUngroupedAggregate)(r.expressionType))return this.expr.loggedErrorExpr("ungroup-of-ungrouped-aggregate",`${this.control}() expression must not already be ungrouped`);const i={node:this.control,e:r.value};if(this.typeCheck(this.expr,{...r,expressionType:"scalar"})){if(e.isQueryFieldSpace()&&this.fields.length>0){const s=[],o=this.control==="exclude";for(const u of this.fields){let a=e.outputSpace(),l=!0;for(;a;){const c=a.lookup([u]);if(c.found&&c.isOutputField)s.push(u.refString),l=!1;else if(a instanceof b0t.QuerySpace){a=a.nestParent;continue}break}if(l){const c=o?"exclude()":"all()";u.logError("ungroup-field-not-in-output",`${c} '${u.refString}' is missing from query output`)}}i.fields=s}return{...V0e.atomicDef(r),expressionType:"ungrouped_aggregate",value:i,evalSpace:"output",compositeFieldUsage:r.compositeFieldUsage}}return this.loggedErrorExpr("ungroup-with-non-scalar",`${this.control}() incompatible type`)}}wT.ExprUngroup=R0t;var IT={},D0t=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),O0t=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),F0t=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&D0t(e,t,r);return O0t(e,t),e};Object.defineProperty(IT,"__esModule",{value:!0}),IT.ForRange=void 0;const w0t=Hs,Y0e=F0t(nn),$T=Es,N0t=Yt,L0t=ht,BT=q2,K0e=ef;class I0t extends L0t.ExpressionDef{constructor(e,r,i){super({from:e,duration:r,timeframe:i}),this.from=e,this.duration=r,this.timeframe=i,this.elementType="forRange",this.legalChildTypes=[Y0e.timestampT,Y0e.dateT]}apply(e,r,i){const s=this.from.getExpression(e),o=i.getExpression(e);if(!this.typeCheck(i,o))return(0,w0t.errorFor)("no time for range");const u=this.duration.getExpression(e);if(u.type!=="number")return u.type!=="error"&&this.logError("invalid-duration-quantity",`FOR duration count must be a number, not '${u.type}'`),(0,N0t.computedErrorExprValue)({dataType:{type:"boolean"},error:"for not number",from:[s,o]});const a=this.timeframe.text;let l=(0,$T.resolution)(a);if(s.type==="timestamp"&&(l="timestamp"),o.type==="date"&&l==="date"){const m=this.from,g=(0,$T.timeOffset)("date",s.value,"+",u.value,a),y=new BT.ExprTime("date",g);return new K0e.Range(m,y).apply(e,r,i)}const c=BT.ExprTime.fromValue("timestamp",o);let f=this.from,x=s.value;if(s.type==="date"){const m=s.morphic&&s.morphic.timestamp;m?x=m:x=(0,$T.castTo)("timestamp",x,"date"),f=new BT.ExprTime("timestamp",x,[s])}const h=(0,$T.timeOffset)("timestamp",x,"+",u.value,a),p=new BT.ExprTime("timestamp",h,[s,u]);return new K0e.Range(f,p).apply(e,r,c)}requestExpression(e){}getExpression(e){return this.loggedErrorExpr("range-as-value","A Range is not a value")}}IT.ForRange=I0t;var Fr={};Object.defineProperty(Fr,"__esModule",{value:!0}),Fr.LiteralYear=Fr.LiteralQuarter=Fr.LiteralMonth=Fr.LiteralWeek=Fr.LiteralDay=Fr.LiteralHour=Fr.LiteralTimestamp=Fr.TimeFormatError=void 0;const of=qr,$0t=et,B0t=Yt,k0t=ef,J0e=q2,hk=ht;class M0t extends Error{}Fr.TimeFormatError=M0t;function Rd(t,e){const r=t.slice(1);if(e){const i=r.match(/\[[^\]]+]$/);if(i)return{tzSpec:i[0].slice(1,-1),text:r.slice(0,-i[0].length)}}return{text:r}}const X0e="yyyy",Z0e=`${X0e}-LL`,Do=`${Z0e}-dd`,ece=`${Do} HH`,tce=`${ece}:mm`,pk=`${tce}:ss`;class nce extends hk.ExpressionDef{constructor(e,r,i){super(),this.units=r,this.timeType=i,this.literalPart=e.text,e.tzSpec&&(this.timeZone=e.tzSpec)}makeLiteral(e,r){const i={node:"timeLiteral",literal:e,typeDef:{type:r}};return this.timeZone&&(i.timezone=this.timeZone),i}makeValue(e,r){const i=this.makeLiteral(e,r);return(0,B0t.literalTimeResult)({value:i,dataType:{type:r},timeframe:this.units})}getExpression(e){return this.makeValue(this.literalPart,this.timeType)}getNext(){if(this.nextLit)return this.makeValue(this.nextLit,this.timeType)}granular(){return this.nextLit!==void 0}}class mk extends nce{constructor(e,r){super(e,r,"timestamp"),this.elementType="literal:timestamp"}static parse(e){let r;const i=Rd(e,!0);e=i.text,e[10]==="T"&&(e=e.slice(0,10)+" "+e.slice(11),i.text=e);const s=e.match(/^([^.,]+)[,.](\d+)$/);s&&(e=s[1]);let o=of.DateTime.fromFormat(e,pk);if(o.isValid)return new mk(i,r);if(o=of.DateTime.fromFormat(e,tce),o.isValid){i.text=i.text+":00",r="minute";const u=o.plus({minute:1}).toFormat(pk);return new gk(i,r,"timestamp",u)}}}Fr.LiteralTimestamp=mk;class gk extends nce{constructor(e,r,i,s){super(e,r,i),this.nextLit=s,this.elementType="granularTimeLiteral"}apply(e,r,i){let s=this.getExpression(e),o=this.getNext();if(o){const u=i.getExpression(e);if(u.type==="timestamp"){const a=(0,hk.getMorphicValue)(s,"timestamp"),l=(0,hk.getMorphicValue)(o,"timestamp");if(a&&l)s=a,o=l;else return super.apply(e,r,i)}if(o&&(0,$0t.isTemporalType)(u.type)){const a=u.type;return new k0t.Range(new J0e.ExprTime(a,s.value),new J0e.ExprTime(a,o.value)).apply(e,r,i)}}return super.apply(e,r,i)}}class yk extends gk{constructor(e,r){super(e,"hour","timestamp",r),this.elementType="literal:hour"}static parse(e){const r=Rd(e,!1);let i=r.text;const s=of.DateTime.fromFormat(r.text,ece);if(s.isValid)return r.text=r.text+":00:00",i=s.plus({hour:1}).toFormat(pk),new yk(r,i)}}Fr.LiteralHour=yk;class wE extends gk{constructor(e,r,i){super(e,r,"date",i)}getExpression(e){const r=this.makeValue(this.literalPart,"date"),i=this.makeLiteral(`${this.literalPart} 00:00:00`,"timestamp");return{...r,morphic:{timestamp:i},evalSpace:"literal"}}getNext(){const e=this.makeValue(this.nextLit,"date"),r=this.makeLiteral(`${this.nextLit} 00:00:00`,"timestamp");return{...e,morphic:{timestamp:r}}}}class Ek extends wE{constructor(e,r){super(e,"day",r),this.elementType="literal:day"}static parse(e){const r=Rd(e,!1);let i=r.text;const s=of.DateTime.fromFormat(r.text,Do);if(s.isValid)return i=s.plus({day:1}).toFormat(Do),new Ek(r,i)}}Fr.LiteralDay=Ek;class Ak extends wE{constructor(e,r){super(e,"week",r),this.elementType="literal:week"}static parse(e){const r=Rd(e,!1);let i=r.text;const s=r.text.slice(0,10),o=of.DateTime.fromFormat(s,Do);if(o.isValid&&o.weekday===7){const a=o.plus({days:7});return r.text=o.toFormat(Do),i=a.toFormat(Do),new Ak(r,i)}}}Fr.LiteralWeek=Ak;class _k extends wE{constructor(e,r){super(e,"month",r),this.elementType="literal:month"}static parse(e){const r=Rd(e,!1);let i=r.text;const s=of.DateTime.fromFormat(r.text,Z0e);if(s.isValid){const o=s.plus({months:1});return r.text=s.toFormat(Do),i=o.toFormat(Do),new _k(r,i)}}}Fr.LiteralMonth=_k;class vk extends wE{constructor(e,r){super(e,"quarter",r),this.elementType="literal:quarter"}static parse(e){const r=Rd(e,!1);let i=r.text;const s=r.text.match(/(^\d{4})-[qQ](\d)$/);if(s){const o=Number.parseInt(s[2])-1;let u=of.DateTime.fromFormat(s[1],"yyyy");o>0&&(u=u.plus({quarters:o}));const a=u.plus({quarter:1});return r.text=u.toFormat(Do),i=a.toFormat(Do),new vk(r,i)}}}Fr.LiteralQuarter=vk;class Ck extends wE{constructor(e,r){super(e,"year",r),this.elementType="literal:year"}static parse(e){const r=Rd(e,!1);let i=r.text;const s=of.DateTime.fromFormat(r.text,X0e);if(s.isValid){const o=s.plus({year:1});return r.text=s.toFormat(Do),i=o.toFormat(Do),new Ck(r,i)}}}Fr.LiteralYear=Ck;var kT={};Object.defineProperty(kT,"__esModule",{value:!0}),kT.PartialCompare=void 0;const rce=ht;class P0t extends rce.ExpressionDef{constructor(e,r){super({right:r}),this.op=e,this.right=r,this.elementType="<=> a"}granular(){return this.right.granular()}apply(e,r,i){return this.right.apply(e,this.op,i)}requestExpression(e){}getExpression(e){return this.loggedErrorExpr("partial-as-value","Partial comparison does not have a value")}atNodeType(){return rce.ATNodeType.Partial}}kT.PartialCompare=P0t;var Y2={},U0t=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),j0t=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),q0t=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&U0t(e,t,r);return j0t(e,t),e};Object.defineProperty(Y2,"__esModule",{value:!0}),Y2.PickWhen=Y2.Pick=void 0;const K2=q0t(nn),ice=Yt,H0t=ht,Q0t=Ze;function MT(t,e){return t===void 0||t.type==="null"||t.type==="error"?e:t}class z0t extends H0t.ExpressionDef{constructor(e,r){super({choices:e}),this.choices=e,this.elsePick=r,this.elementType="pick",this.has({elsePick:r})}requestExpression(e){if(this.elsePick!==void 0){for(const r of this.choices){if(r.pick===void 0)return;const i=r.when.requestExpression(e);if(i===void 0||i.type!=="boolean")return}return this.getExpression(e)}}apply(e,r,i){var s;const o={node:"case",kids:{caseWhen:[],caseThen:[]}};let u;const a=[];for(const h of this.choices){const p=h.when.apply(e,"=",i),m=h.pick?h.pick.getExpression(e):i.getExpression(e);if(a.push(p,m),u&&!K2.typeEq(u,m,!0))return this.loggedErrorExpr("pick-type-does-not-match",{pickType:m.type,returnType:u.type});u=MT(u,m),o.kids.caseWhen.push(p.value),o.kids.caseThen.push(m.value)}const l=(s=this.elsePick)===null||s===void 0?void 0:s.getExpression(e),c=i.getExpression(e);a.push(c),l&&a.push(l);const f=l??c,x=MT(u,f);return K2.typeEq(x,f,!0)?x.type==="filter expression"?this.loggedErrorExpr("filter-expression-error","Pick statments cannot have filter expression values"):(o.kids.caseElse=f.value,(0,ice.computedExprValue)({dataType:x,value:o,from:a})):this.elsePick?this.loggedErrorExpr("pick-else-type-does-not-match",{elseType:f.type,returnType:x.type}):this.loggedErrorExpr("pick-default-type-does-not-match",{defaultType:f.type,returnType:x.type})}getExpression(e){const r={node:"case",kids:{caseWhen:[],caseThen:[]}};if(this.elsePick===void 0)return this.loggedErrorExpr("pick-missing-else","pick incomplete, missing 'else'");const i=[],s=[];for(const l of this.choices){if(l.pick===void 0)return this.loggedErrorExpr("pick-missing-value","pick with no value can only be used with apply");l.when.requestExpression(e)===void 0&&this.loggedErrorExpr("pick-illegal-partial","pick with partial when can only be used with apply");const f=l.pick.getExpression(e),x=l.when.getExpression(e);i.push({pick:f,when:x}),s.push(f,x)}let o;for(const l of i){if(!K2.typeEq(l.when,K2.boolT))return this.loggedErrorExpr("pick-when-must-be-boolean",{whenType:l.when.type});if(o&&!K2.typeEq(o,l.pick,!0))return this.loggedErrorExpr("pick-type-does-not-match",{pickType:l.pick.type,returnType:o.type});o=MT(o,l.pick),r.kids.caseWhen.push(l.when.value),r.kids.caseThen.push(l.pick.value)}const u=this.elsePick.getExpression(e);s.push(u);const a=MT(o,u);return K2.typeEq(a,u,!0)?a.type==="filter expression"?this.loggedErrorExpr("filter-expression-error","Pick statments cannot have filter expression values"):(r.kids.caseElse=u.value,(0,ice.computedExprValue)({dataType:a,value:r,from:s})):this.elsePick.loggedErrorExpr("pick-else-type-does-not-match",{elseType:u.type,returnType:a.type})}}Y2.Pick=z0t;class W0t extends Q0t.MalloyElement{constructor(e,r){super({when:r}),this.pick=e,this.when=r,this.elementType="caseWhen",this.has({pick:e})}}Y2.PickWhen=W0t;var J2={},G0t=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),V0t=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),Y0t=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&G0t(e,t,r);return V0t(e,t),e};Object.defineProperty(J2,"__esModule",{value:!0}),J2.CaseWhen=J2.Case=void 0;const K0t=Yt,J0t=ht,X0t=Ze,X2=Y0t(nn);function sce(t,e){return t===void 0||t.type==="null"||t.type==="error"?e:t}class Z0t extends J0t.ExpressionDef{constructor(e,r,i){super({choices:r}),this.value=e,this.choices=r,this.elseValue=i,this.elementType="case",this.has({elseValue:i,value:e})}getExpression(e){const r={node:"case",kids:{caseWhen:[],caseThen:[]}},i=[];let s;if(this.value){const a=this.value.getExpression(e);i.push(a),r.kids.caseValue=a.value,s=a}const o=[];for(const a of this.choices){const l=a.when.getExpression(e),c=a.then.getExpression(e);o.push({when:l,then:c}),i.push(l,c)}let u;for(const a of o){if(s!==void 0){if(!X2.typeEq(a.when,s))return this.loggedErrorExpr("case-when-type-does-not-match",{whenType:a.when.type,valueType:s.type})}else if(!X2.typeEq(a.when,X2.boolT))return this.loggedErrorExpr("case-when-must-be-boolean",{whenType:a.when.type});if(u&&!X2.typeEq(u,a.then,!0))return this.loggedErrorExpr("case-then-type-does-not-match",{thenType:a.then.type,returnType:u.type});u=sce(u,a.then),r.kids.caseWhen.push(a.when.value),r.kids.caseThen.push(a.then.value)}if(this.elseValue){const a=this.elseValue.getExpression(e);if(u&&!X2.typeEq(u,a,!0))return this.loggedErrorExpr("case-else-type-does-not-match",{elseType:a.type,returnType:u.type});u=sce(u,a),i.push(a),r.kids.caseElse=a.value}return(0,K0t.computedExprValue)({value:r,dataType:u?X2.atomicDef(u):{type:"null"},from:i})}}J2.Case=Z0t;class ect extends X0t.MalloyElement{constructor(e,r){super({when:e,then:r}),this.when=e,this.then=r,this.elementType="caseWhen"}}J2.CaseWhen=ect;var PT={},Dd={},tct=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),nct=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),rct=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&tct(e,t,r);return nct(e,t),e};Object.defineProperty(Dd,"__esModule",{value:!0}),Dd.RecordLiteral=Dd.RecordElement=void 0;const oce=Gi,ict=Yt,sct=ht,oct=Ze,uct=rct(nn);class act extends oct.MalloyElement{constructor(e){if(super(),this.elementType="record element","value"in e)this.value=e.value,this.has({value:e.value}),e.key&&(this.key=e.key);else{this.has({path:e.path}),this.value=e.path;const r=e.path.fieldReference.path;this.key=r[r.length-1]}}}Dd.RecordElement=act;class lct extends sct.ExpressionDef{constructor(e){super(),this.pairs=e,this.elementType="record literal",this.has({pairs:e})}getExpression(e){return this.getRecord(e,[])}getRecord(e,r){var i;const s={node:"recordLiteral",kids:{},typeDef:{type:"record",fields:[]}},o=[];let u=0;for(const a of this.pairs){const l=(i=a.key)!==null&&i!==void 0?i:r[u];if(u+=1,l===void 0){a.logError("record-literal-needs-keys","Anonymous record element not legal here");continue}const c=a.value.getExpression(e);oce.TD.isAtomic(c)?(o.push(c),s.kids[l]=c.value,s.typeDef.fields.push((0,oce.mkFieldDef)(uct.atomicDef(c),l))):a.value.logError("illegal-record-property-type",`Record property '${a.key} is type '${c.type}', which is not a legal property value type`)}return(0,ict.computedExprValue)({value:s,dataType:s.typeDef,from:o})}getNextElement(e,r){const i=r.value;return i.node==="recordLiteral"?this.getRecord(e,Object.keys(i.kids)):this.getRecord(e,[])}}Dd.RecordLiteral=lct;var cct=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),fct=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),xct=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&cct(e,t,r);return fct(e,t),e};Object.defineProperty(PT,"__esModule",{value:!0}),PT.ArrayLiteral=void 0;const dct=Yt,hct=ht,uce=xct(nn),pct=Dd;class mct extends hct.ExpressionDef{constructor(e){super(),this.elements=e,this.elementType="array literal",this.has({elements:e})}getExpression(e){const r=[],i=[];let s;if(this.elements.length>0)for(const l of this.elements){const c=s&&l instanceof pct.RecordLiteral?l.getNextElement(e,s):l.getExpression(e);if(i.push(c),c.type!=="error"){if(s){if(c.type!=="null"&&!uce.typeEq(s,c)){l.logError("array-values-incompatible","All array elements must be same type");continue}}else c.type!=="null"&&(s=c);r.push(c.value)}}const o=uce.atomicDef(s||{type:"number"}),u=o.type==="record"?{type:"array",elementTypeDef:{type:"record_element"},fields:o.fields}:{type:"array",elementTypeDef:o},a={node:"arrayLiteral",kids:{values:r},typeDef:u};return(0,dct.computedExprValue)({dataType:u,value:a,from:i})}}PT.ArrayLiteral=mct;var UT={};Object.defineProperty(UT,"__esModule",{value:!0}),UT.Timeframe=void 0;const gct=et,yct=Ze;class Ect extends yct.MalloyElement{constructor(e){super(),this.elementType="timeframe";let r=e.toLowerCase();r.endsWith("s")&&(r=r.slice(0,-1)),this.text=(0,gct.isTimestampUnit)(r)?r:"second"}}UT.Timeframe=Ect;var uf={};Object.defineProperty(uf,"__esModule",{value:!0}),uf.ImportStatement=uf.ImportSelect=uf.ImportSourceName=void 0;const Sk=Ze;class Act extends Sk.MalloyElement{constructor(e){super(),this.text=e,this.elementType="importSourceName"}}uf.ImportSourceName=Act;class _ct extends Sk.MalloyElement{constructor(e,r){super(),this.text=e,this.from=r,this.elementType="importName",r&&this.has({from:r})}}uf.ImportSelect=_ct;class vct extends Sk.ListOf{constructor(e,r){super([]),this.url=e,this.elementType="import statement";try{this.fullURL=decodeURI(new URL(e,r).toString())}catch{this.logError("invalid-import-url","Invalid URL in import statement")}}needs(){const e=this.translator();if(e&&this.fullURL&&e.root.importZone.getEntry(this.fullURL).status==="present"){const i=e.childRequest(this.fullURL);if(i)return i}}execute(e){const r=this.translator();if(!r)this.logError("no-translator-for-import","Cannot import without translation context");else if(this.fullURL){const i=r.root.pretranslatedModels.get(this.fullURL),s=r.root.importZone.getEntry(this.fullURL);if(i||s.status==="present"){const o=r.getChildExports(this.fullURL);if(this.notEmpty())for(const u of this.list){const a=u.from||u;if(e.getEntry(u.text))u.logError("name-conflict-on-selective-import",`Cannot redefine '${u.text}'`);else if(o[a.text]){const l={...o[a.text]};u.from&&(l.as=u.text),e.setEntry(u.text,{entry:l,exported:!1})}else a.logError("selective-import-not-found",`Cannot find '${a.text}', not imported`)}else for(const[u,a]of Object.entries(r.getChildExports(this.fullURL)))e.getEntry(u)?this.logError("name-conflict-on-indiscriminate-import",`Cannot redefine '${u}'`):e.setEntry(u,{entry:a,exported:!1})}else s.status==="error"?this.logError("failed-import",`import failed: '${s.message}'`):this.logError("failed-import",`import failed with status: '${s.status}'`)}}}uf.ImportStatement=vct;var NE={};Object.defineProperty(NE,"__esModule",{value:!0}),NE.ExtendBlock=void 0;const Cct=Ze,Sct=zn;class bct extends Cct.ListOf{constructor(){super(...arguments),this.elementType="extendBlock",this.forceQueryClass=void 0,this.queryRefinementStage=Sct.LegalRefinementStage.Single}queryExecute(e){for(const r of this.list)for(const i of r.list)e.inputFS.extendSource(i)}}NE.ExtendBlock=bct;var jT={};Object.defineProperty(jT,"__esModule",{value:!0}),jT.Argument=void 0;const Tct=Ze;class Rct extends Tct.MalloyElement{constructor(e){super({...e}),this.elementType="Argument",this.id=e.id,this.value=e.value}}jT.Argument=Rct;var qT={};Object.defineProperty(qT,"__esModule",{value:!0}),qT.HasParameter=void 0;const ace=et,Dct=Ze,Oct=ht;class Fct extends Dct.MalloyElement{constructor(e){super(),this.elementType="hasParameter",this.name=e.name,e.type&&(0,ace.isParameterType)(e.type)&&(this.type=e.type),e.default&&(this.default=e.default,this.has({default:this.default})),e.filterType&&(this.filterType=e.filterType)}parameter(){var e;let r;if(this.default!==void 0){const i=this.default.constantValue();if(this.type&&this.type!==i.type&&i.type!=="null"&&i.type!=="error"&&this.default.logError("parameter-default-does-not-match-declared-type",`Default value for parameter does not match declared type \`${this.type}\``),i.type==="null")return this.type?{type:this.type,value:i.value,name:this.name}:(this.default.logError("parameter-null-default-without-declared-type","Default value cannot have type `null` unless parameter type is also specified"),{value:i.value,name:this.name,type:"error"});if(i.type==="filter expression")return this.type!=="filter expression"&&this.logError("parameter-missing-default-or-type",`Filter expression parameters must have expicit filter type, for example '${this.name}::filter<string>'`),this.filterType&&(0,Oct.checkFilterExpression)(this,this.filterType,i.value),{value:i.value,name:this.name,type:i.type};if(!(0,ace.isCastType)(i.type)&&i.type!=="error")return this.default.logError("parameter-illegal-default-type",`Default value cannot have type \`${i.type}\``),{value:i.value,name:this.name,type:"error"};r={value:i.value,name:this.name,type:i.type}}else this.type===void 0&&this.logError("parameter-missing-default-or-type","Parameter must have default value or declared type"),r={value:null,name:this.name,type:(e=this.type)!==null&&e!==void 0?e:"error"};return r.type==="filter expression"&&this.filterType&&(r.filterType=this.filterType),r}}qT.HasParameter=Fct;var HT={};Object.defineProperty(HT,"__esModule",{value:!0}),HT.AnonymousQuery=void 0;const wct=Ze,Nct=Qr;class Lct extends wct.MalloyElement{constructor(e){super(),this.queryExpr=e,this.elementType="anonymousQuery",this.isNoteableObj=!0,this.extendNote=Nct.extendNoteMethod,this.has({queryExpr:e})}execute(e){const r=this.queryExpr.getQuery();if(!r){this.queryExpr.sqLog("non-query-used-as-query","Cannot run this object as a query");return}const i={...r.query()},s=this.note||{};i.annotation&&(s.inherits=i.annotation),(s.notes||s.blockNotes||s.inherits)&&(i.annotation=s),e.queryList.push(i)}}HT.AnonymousQuery=Lct;var af={};Object.defineProperty(af,"__esModule",{value:!0}),af.View=void 0;const Ict=Ze;class $ct extends Ict.MalloyElement{pipeline(e,r){return this.pipelineComp(e,r).pipeline}}af.View=$ct;var QT={};Object.defineProperty(QT,"__esModule",{value:!0}),QT.ViewArrow=void 0;const Bct=Wr,kct=af;class Mct extends kct.View{constructor(e,r){super({base:e,operation:r}),this.base=e,this.operation=r,this.elementType="viewArrow"}pipelineComp(e){const r=this.base.pipelineComp(e),i=new Bct.StaticSourceSpace(r.outputStruct),s=this.operation.pipelineComp(i);return{pipeline:[...r.pipeline,...s.pipeline],outputStruct:s.outputStruct}}refine(e,r,i){return this.logError("refinement-with-multistage-view","A multi-segment view cannot be used as a refinement"),[]}getImplicitName(){return this.operation.getImplicitName()}}QT.ViewArrow=Mct;var zT={},LE={};Object.defineProperty(LE,"__esModule",{value:!0}),LE.refine=void 0;const bk=Gi,Pct=dt,Tk=Vc;function Uct(t,e,r){var i,s;if(e.length!==1)return t.logError("refinement-with-multistage-view","Named refinements of multi-stage views are not supported"),e;const o={...e[0]},u=r;if((0,bk.isRawSegment)(o))t.logError("refinement-of-raw-query","Cannot refine raw query, must add an explicit query stage");else if(o.type==="partial"&&u.type!=="index"&&u.type!=="raw"?o.type=u.type:u.type!==o.type&&t.logError("mismatched-view-types-for-refinement",`cannot refine ${o.type} view with ${u.type} view`),u.type!=="index"&&o.type!=="index"&&u.type!=="raw"&&(u.orderBy!==void 0&&!u.defaultOrderBy&&(o.orderBy===void 0||o.defaultOrderBy?o.orderBy=u.orderBy:t.logError("ordering-overridden-in-refinement","refinement cannot override existing ordering")),u.limit!==void 0&&(o.limit===void 0?o.limit=u.limit:t.logError("limit-overridden-in-refinement","refinement cannot override existing limit"))),o.filterList=o.filterList!==void 0||u.filterList!==void 0?[...(i=o.filterList)!==null&&i!==void 0?i:[],...(s=u.filterList)!==null&&s!==void 0?s:[]]:void 0,(0,bk.isQuerySegment)(u)&&(0,bk.isQuerySegment)(o)){const a=[],l=[],c=new Map(o.queryFields.map(f=>[(0,Tk.nameFromDef)(f),f]));for(const f of u.queryFields)c.has((0,Tk.nameFromDef)(f))?a.push(f):l.push(f);o.queryFields=[...o.queryFields,...l],a.length>0&&t.logError("name-conflict-in-refinement",`overlapping fields in refinement: ${a.map(Tk.nameFromDef)}`),o.compositeFieldUsage=(0,Pct.mergeCompositeFieldUsage)(o.compositeFieldUsage,u.compositeFieldUsage)}else u.type==="index"&&o.type==="index"&&(o.indexFields=[...u.indexFields,...o.indexFields]);return[o]}LE.refine=Uct,Object.defineProperty(zT,"__esModule",{value:!0}),zT.ViewRefine=void 0;const jct=gi,qct=zs,Hct=LE,Qct=af;class zct extends Qct.View{constructor(e,r){super({base:e,refinement:r}),this.base=e,this.refinement=r,this.elementType="refine"}pipelineComp(e,r){const i=this.base.pipelineComp(e),s=this.refinement.refine(e,i.pipeline,r);return{pipeline:s,annotation:i.annotation,outputStruct:s.length>0?(0,qct.getFinalStruct)(this.refinement,e.structDef(),s):jct.ErrorFactory.structDef}}refine(e,r,i){const s=this.pipeline(e,i);return s.length!==1?(this.refinement.logError("refinement-with-multistage-view","refinement must have exactly one stage"),r):(0,Hct.refine)(this,r,s[0])}getImplicitName(){return this.base.getImplicitName()}}zT.ViewRefine=zct;var WT={};Object.defineProperty(WT,"__esModule",{value:!0}),WT.ReferenceView=void 0;const Rk=et,lce=gi,Wct=zs,Gct=zr,Vct=LE,Yct=af;class Kct extends Yct.View{constructor(e){super({reference:e}),this.reference=e,this.elementType="reference-view"}pipelineComp(e,r){return this._pipelineComp(e)}_pipelineComp(e,{forRefinement:r}={forRefinement:!1}){const i=this.reference.getField(e),s=function(){return{inputStruct:lce.ErrorFactory.structDef,outputStruct:lce.ErrorFactory.structDef,pipeline:[],error:!0}};if(!i.found)return this.reference.logError(i.error.code,i.error.message),s();if(!(i.found instanceof Gct.SpaceField))throw new Error("Expected space field");const o=i.found.fieldDef();if(o===void 0)throw new Error("Expected field to have definition");if((0,Rk.isAtomic)(o)){const u={type:"reduce",queryFields:[this.reference.refToField],compositeFieldUsage:o.compositeFieldUsage},a=this.reference.nameString,l={...(0,Rk.sourceBase)(e.structDef()),type:"query_result",name:a,fields:[o]};return{pipeline:[u],name:a,outputStruct:l}}else return(0,Rk.isTurtle)(o)?this.reference.list.length>1?(r?this.logError("refinement-with-joined-view","Cannot use view from join as refinement"):this.logError("nest-of-joined-view","Cannot use view from join"),s()):{pipeline:[...o.pipeline],name:o.name,annotation:o.annotation,outputStruct:(0,Wct.getFinalStruct)(this.reference,e.structDef(),o.pipeline)}:(r?this.reference.logError("refinement-with-source",`named refinement \`${this.reference.refString}\` must be a view, found a ${o.type}`):this.reference.logError("nest-of-source","This operation is not supported"),s())}getRefinementSegment(e){const{pipeline:r,error:i}=this._pipelineComp(e,{forRefinement:!0});if(!i){if(r.length!==1){this.reference.logError("refinement-with-multistage-view",`named refinement \`${this.reference.refString}\` must have exactly one stage`);return}return r[0]}}refine(e,r,i){const s=this.getRefinementSegment(e);return s?(0,Vct.refine)(this,r,s):r}getImplicitName(){return this.reference.nameString}}WT.ReferenceView=Kct;var GT={},IE={},VT={},$E={};Object.defineProperty($E,"__esModule",{value:!0}),$E.Index=void 0;const Jct=Ze,Xct=zn;class Zct extends Jct.MalloyElement{constructor(e){super({fields:e}),this.fields=e,this.elementType="index",this.forceQueryClass=Xct.QueryClass.Index,this.queryRefinementStage=void 0}useWeight(e){this.has({weightBy:e}),this.weightBy=e}}$E.Index=Zct;var BE={};Object.defineProperty(BE,"__esModule",{value:!0}),BE.SampleProperty=void 0;const eft=Ze,cce=zn;class tft extends eft.MalloyElement{constructor(e){super(),this.sample=e,this.elementType="sampleProperty",this.queryRefinementStage=cce.LegalRefinementStage.Tail,this.forceQueryClass=cce.QueryClass.Index}sampling(){return this.sample}}BE.SampleProperty=tft;var YT={};Object.defineProperty(YT,"__esModule",{value:!0}),YT.IndexFieldSpace=void 0;const fce=dt,xce=et,Dk=_t,nft=zr,rft=Du,ift=dE,sft=Wr;class oft extends rft.QueryOperationSpace{constructor(){super(...arguments),this.segmentType="index"}pushFields(...e){for(const r of e)r instanceof Dk.FieldReference?super.pushFields(r):r instanceof Dk.WildcardFieldReference?this.addWild(r):r.logError("invalid-field-in-index-query","Internal error, not expected in index query")}getPipeSegment(e){if(e)return this.logError("refinement-of-index-segment","index query operations cannot be refined"),{type:"index",indexFields:[]};let r=(0,fce.emptyCompositeFieldUsage)(),i=(0,fce.emptyNarrowedCompositeFieldResolution)();const s=[],o=this.inputSpace().structDef();for(const[u,a]of this.entries())if(a instanceof nft.SpaceField){let l,c;const f=this.expandedWild[u];if(f)s.push({type:"fieldref",path:f.path}),l=f.entry.typeDesc().compositeFieldUsage;else if(a instanceof ift.ReferenceField){const h=a.fieldRef,p=h.getField(this.exprSpace);p.error?h.logError(p.error.code,p.error.message):(s.push(h.refToField),l=p.found.typeDesc().compositeFieldUsage,c=h)}const x=this.applyNextCompositeFieldUsage(o,r,i,l,c);r=x.compositeFieldUsage,i=x.narrowedCompositeFieldResolution}return this._compositeFieldUsage=r,{type:"index",indexFields:s}}addRefineFromFields(e){}addWild(e){var r;let i=this.exprSpace;const s=[];if(e.joinPath)for(const a of e.joinPath.list){const l=a.refString;s.push(l);const c=i.entry(l);if(c)if(c instanceof sft.StructSpaceField)i=c.fieldSpace;else{a.logError("invalid-wildcard-source",`Field '${l}' does not contain rows and cannot be expanded with '*'`);return}else{a.logError("wildcard-source-not-found",`No such field as '${l}'`);return}}const o=this.dialectObj(),u=[];for(const[a,l]of i.entries()){if(e.except.has(a)||l.refType==="parameter")continue;const c=Dk.IndexFieldReference.indexOutputName([...s,a]);if(this.entry(c)){const f=(r=this.expandedWild[c].path)===null||r===void 0?void 0:r.join(".");e.logError("name-conflict-in-wildcard-expansion",`Cannot expand '${a}' in '${e.refString}' because a field with that name already exists${f?` (conflicts with ${f})`:""}`)}else{const f=l.typeDesc();xce.TD.isBasicAtomic(f)&&(0,xce.expressionIsScalar)(f.expressionType)&&(o===void 0||!o.ignoreInProject(a))&&(u.push({name:c,entry:l}),this.expandedWild[c]={path:s.concat(a),entry:l})}}for(const a of u.sort((l,c)=>l.name.localeCompare(c.name)))this.setEntry(a.name,a.entry)}}YT.IndexFieldSpace=oft,Object.defineProperty(VT,"__esModule",{value:!0}),VT.IndexBuilder=void 0;const Ok=et,uft=gi,aft=qa,lft=$E,cft=nf,fft=BE,xft=YT,Fk=dt;class dft{constructor(e,r,i,s){this.filters=[],this.alwaysJoins=[],this.type="index",this.resultFS=new xft.IndexFieldSpace(e,r,i,s),this.inputFS=this.resultFS.inputSpace()}execute(e){e instanceof aft.Filter?e.queryExecute(this):e instanceof cft.Limit?(this.limit&&this.limit.logError("index-limit-already-specified","Ignored, too many limit: statements"),this.limit=e):e instanceof lft.Index?(this.resultFS.pushFields(...e.fields.list),e.weightBy&&(this.indexOn&&this.indexOn.logError("index-by-already-specified","Ignoring previous BY"),this.indexOn=e.weightBy)):e instanceof fft.SampleProperty?this.sample=e.sampling():e.logError("illegal-operation-for-index","Not legal in an index query operation")}get compositeFieldUsage(){return this.resultFS.compositeFieldUsage}finalize(e){var r;if(e&&!(0,Ok.isIndexSegment)(e)&&!(0,Ok.isPartialSegment)(e))return this.resultFS.logError("refinement-of-index-segment",`Can't refine index with ${e.type}`),uft.ErrorFactory.indexSegment;const i=this.resultFS.getPipeSegment(e),s=(e==null?void 0:e.filterList)||[];this.filters.length>0&&!s?i.filterList=this.filters:s&&(i.filterList=[...s,...this.filters]),e!=null&&e.limit&&(i.limit=e.limit),this.limit&&(i.limit=this.limit.limit),this.indexOn&&(i.weightMeasure=this.indexOn.refString),e&&(0,Ok.isIndexSegment)(e)&&(e!=null&&e.sample)&&(i.sample=e.sample),this.sample&&(i.sample=this.sample),this.alwaysJoins.length>0&&(i.alwaysJoins=[...this.alwaysJoins]);const o=e&&e.type==="index"&&(r=e.compositeFieldUsage)!==null&&r!==void 0?r:(0,Fk.emptyCompositeFieldUsage)();return i.compositeFieldUsage=(0,Fk.mergeCompositeFieldUsage)(o,this.compositeFieldUsage),i}}VT.IndexBuilder=dft;var KT={},kE={};Object.defineProperty(kE,"__esModule",{value:!0}),kE.GroupBy=void 0;const hft=Qs,dce=zn;class pft extends hft.DefinitionList{constructor(){super(...arguments),this.elementType="groupBy",this.queryRefinementStage=dce.LegalRefinementStage.Single,this.forceQueryClass=dce.QueryClass.Grouping}}kE.GroupBy=pft;var JT={};Object.defineProperty(JT,"__esModule",{value:!0}),JT.ProjectFieldSpace=void 0;const XT=et,mft=Du;class gft extends mft.QuerySpace{constructor(){super(...arguments),this.segmentType="project"}canContain(e){return e===void 0||!XT.TD.isAtomic(e)||(0,XT.expressionIsAggregate)(e.expressionType)?!1:(0,XT.expressionInvolvesAggregate)(e.expressionType)&&(0,XT.expressionIsAnalytic)(e.expressionType)?(this.logError("aggregate-analytic-in-select","Cannot add aggregate analyics to select"),!1):!0}}JT.ProjectFieldSpace=gft;var lf={},Od={};Object.defineProperty(Od,"__esModule",{value:!0}),Od.Ordering=Od.OrderBy=void 0;const yft=et,hce=rf,pce=Ze,Eft=zn;class Aft extends pce.MalloyElement{constructor(e,r){super(),this.field=e,this.dir=r,this.elementType="orderBy",e instanceof hce.FieldName&&this.has({field:e})}get modelField(){return typeof this.field=="number"?this.field:this.field.refString}getOrderBy(e){var r;if(this.field instanceof hce.FieldName&&e.isQueryFieldSpace()){const s=e.outputSpace(),o=this.field.getField(s);o.error&&this.field.logError(o.error.code,o.error.message),(!o.found||!o.isOutputField)&&this.logError("order-by-not-found-in-output",`Unknown field ${this.field.refString} in output space`),(0,yft.expressionIsAnalytic)((r=o.found)===null||r===void 0?void 0:r.typeDesc().expressionType)&&this.logError("order-by-analytic",`Illegal order by of analytic field ${this.field.refString}`)}const i={field:this.modelField};return this.dir&&(i.dir=this.dir),i}}Od.OrderBy=Aft;class _ft extends pce.ListOf{constructor(e){super(e),this.elementType="ordering",this.queryRefinementStage=Eft.LegalRefinementStage.Tail,this.forceQueryClass=void 0}getOrderBy(e){return this.list.map(r=>r.getOrderBy(e))}}Od.Ordering=_ft,Object.defineProperty(lf,"__esModule",{value:!0}),lf.ReduceBuilder=lf.QuerySegmentBuilder=void 0;const Ou=et,vft=gi,Cft=rf,Sft=nf,bft=Od,Tft=Du,Rft=Qs,wk=dt;function mce(t){return t.type==="fieldref"?t.path[t.path.length-1]:t.name}class gce{constructor(){this.alwaysJoins=[],this.filters=[]}execute(e){if(e.queryExecute){e.queryExecute(this);return}e instanceof Rft.DefinitionList?this.resultFS.pushFields(...e.list):e instanceof Sft.Limit?this.limit?e.logError("limit-already-specified","Query operation already limited"):this.limit=e.limit:e instanceof bft.Ordering&&(this.order?e.logError("ordering-already-specified","Query operation already sorted"):this.order=e)}get compositeFieldUsage(){return this.resultFS.compositeFieldUsage}refineFrom(e,r){var i;e&&e.type!=="index"&&e.type!=="raw"&&(!this.limit&&e.orderBy&&!e.defaultOrderBy&&(r.orderBy=e.orderBy),!this.limit&&e.limit&&(r.limit=e.limit)),this.order&&(r.orderBy=this.order.getOrderBy(this.inputFS),delete r.defaultOrderBy),this.limit&&(r.limit=this.limit);const s=(e==null?void 0:e.filterList)||[];this.filters.length>0&&!s?r.filterList=this.filters:s&&(r.filterList=[...s,...this.filters]),this.alwaysJoins.length>0&&(r.alwaysJoins=[...this.alwaysJoins]);const o=e&&(0,Ou.isQuerySegment)(e)&&(i=e.compositeFieldUsage)!==null&&i!==void 0?i:(0,wk.emptyCompositeFieldUsage)();r.compositeFieldUsage=(0,wk.mergeCompositeFieldUsage)(o,this.compositeFieldUsage)}}lf.QuerySegmentBuilder=gce;class Dft extends gce{constructor(e,r,i,s){super(),this.type="grouping",this.resultFS=new Tft.ReduceFieldSpace(e,r,i,s),this.inputFS=this.resultFS.inputSpace()}finalize(e){let r;if(e)if((0,Ou.isReduceSegment)(e)||(0,Ou.isPartialSegment)(e))r=e;else return this.resultFS.logError("incompatible-segment-for-reduce-refinement",`Can't refine reduce with ${e.type}`),vft.ErrorFactory.reduceSegment;const i=this.resultFS.getQuerySegment(r);if(this.refineFrom(r,i),i.orderBy){for(const s of i.orderBy)if(typeof s.field=="number"){const o=i.queryFields[s.field-1];s.field=mce(o)}}if(i.orderBy===void 0||i.defaultOrderBy){let s;for(const o of i.queryFields){let u=!1,a=!1,l;const c=mce(o);if(o.type==="fieldref"){const f=o.path.map(h=>new Cft.FieldName(h)),x=this.inputFS.lookup(f).found;if(x){const h=x.typeDesc();l=h.type,u=(0,Ou.expressionIsAggregate)(h.expressionType),a=(0,Ou.expressionIsAnalytic)(h.expressionType)}else continue}else l=o.type,u=(0,Ou.hasExpression)(o)&&(0,Ou.expressionIsAggregate)(o.expressionType),a=(0,Ou.hasExpression)(o)&&(0,Ou.expressionIsAnalytic)(o.expressionType);if((0,Ou.isTemporalType)(l)||u){i.defaultOrderBy=!0,i.orderBy=[{field:c,dir:"desc"}],s=void 0;break}(0,Ou.canOrderBy)(l)&&!a&&!s&&(s=c)}s&&(i.defaultOrderBy=!0,i.orderBy=[{field:s,dir:"asc"}])}return i}}lf.ReduceBuilder=Dft,Object.defineProperty(KT,"__esModule",{value:!0}),KT.ProjectBuilder=void 0;const yce=et,Oft=gi,Fft=kE,wft=JT,Nft=lf;class Lft extends Nft.QuerySegmentBuilder{constructor(e,r,i,s){super(),this.type="project",this.resultFS=new wft.ProjectFieldSpace(e,r,i,s),this.inputFS=this.resultFS.inputSpace()}execute(e){e.elementType==="having"||e instanceof Fft.GroupBy?e.logError("illegal-operation-in-select-segment","Illegal statement in a select query operation"):super.execute(e)}finalize(e){let r;if(e)if((0,yce.isProjectSegment)(e)||(0,yce.isPartialSegment)(e))r=e;else return this.resultFS.logError("incompatible-segment-for-select-refinement",`Can't refine select with ${e.type}`),Oft.ErrorFactory.projectSegment;const i=this.resultFS.getQuerySegment(r);return this.refineFrom(r,i),i}}KT.ProjectBuilder=Lft;var ZT={};Object.defineProperty(ZT,"__esModule",{value:!0}),ZT.PartialBuilder=void 0;const Ift=Gi,$ft=lf;class Bft extends $ft.ReduceBuilder{finalize(e){const r=super.finalize(e);if((0,Ift.isQuerySegment)(r))return{...r,type:"partial"};throw new Error(`Partial Builder cannot finalize from ${r.type}`)}}ZT.PartialBuilder=Bft,Object.defineProperty(IE,"__esModule",{value:!0}),IE.QOpDesc=void 0;const kft=VT,Mft=KT,Pft=lf,Uft=Ze,jft=zs,qft=Wr,Fd=zn,Hft=ZT;class Qft extends Uft.ListOf{constructor(){super(...arguments),this.elementType="queryOperation"}computeType(){var e;let r,i=!1;this.refineThis&&(this.refineThis.type==="reduce"?r=Fd.QueryClass.Grouping:this.refineThis.type==="project"?r=Fd.QueryClass.Project:this.refineThis.type==="index"&&(r=Fd.QueryClass.Index));for(const s of this.list)s.forceQueryClass&&(r?r!==s.forceQueryClass&&s.logError(`illegal-${r}-operation`,`Not legal in ${r} query`):r=s.forceQueryClass),i||(i=(e=s.needsExplicitQueryClass)!==null&&e!==void 0?e:!1);return r===void 0&&i&&(this.logError("ambiguous-view-type",{}),r=Fd.QueryClass.Project),this.opClass=r,r}refineFrom(e){this.refineThis=e}getBuilder(e,r,i){switch(this.computeType()){case Fd.QueryClass.Grouping:return new Pft.ReduceBuilder(e,this.refineThis,r,i);case Fd.QueryClass.Project:return new Mft.ProjectBuilder(e,this.refineThis,r,i);case Fd.QueryClass.Index:return new kft.IndexBuilder(e,this.refineThis,r,i);case void 0:return new Hft.PartialBuilder(e,this.refineThis,r,i)}}getOp(e,r){const i=this.getBuilder(e,r,this);for(const o of this.list)i.execute(o);const s=i.finalize(this.refineThis);return{segment:s,outputSpace:()=>new qft.StaticSourceSpace((0,jft.opOutputStruct)(this,e.structDef(),s))}}}IE.QOpDesc=Qft,Object.defineProperty(GT,"__esModule",{value:!0}),GT.QOpDescView=void 0;const zft=et,Wft=Wr,Ece=IE,Gft=zs,Nk=zn,Vft=af;class Yft extends Vft.View{constructor(e){super({operation:e}),this.operation=e,this.elementType="qopdesc-view"}pipelineComp(e,r){const i=this.operation.getOp(e,r);return{pipeline:[i.segment],outputStruct:i.outputSpace().structDef()}}getOp(e,r,i,s){return(0,zft.isRawSegment)(s)?(this.logError("refinement-of-raw-query","A raw query cannot be refined"),s):(i.refineFrom(s),i.getOp(e,r).segment)}refine(e,r,i){const s=[...r];if(s.length===0)return s;if(s.length===1)return this.operation.refineFrom(s[0]),[this.getOp(e,i,this.operation,s[0])];const o=new Ece.QOpDesc([]),u=new Ece.QOpDesc([]);for(const a of this.operation.list)switch(a.queryRefinementStage){case Nk.LegalRefinementStage.Head:o.push(a);break;case Nk.LegalRefinementStage.Single:a.logError("illegal-multistage-refinement-operation","Illegal in refinement of a query with more than one stage");break;case Nk.LegalRefinementStage.Tail:u.push(a);break;default:a.logError("illegal-refinement-operation","Illegal query refinement")}if(o.notEmpty()&&(this.has({headRefinements:o}),s[0]=this.getOp(e,void 0,o,s[0])),u.notEmpty()){const a=s.length-1;this.has({tailRefinements:u});const l=(0,Gft.getFinalStruct)(this,e.structDef(),s.slice(-1));s[a]=this.getOp(new Wft.StaticSourceSpace(l),void 0,u,s[a])}return s}getImplicitName(){}}GT.QOpDescView=Yft;var wn={},Kft=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),Jft=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),Xft=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&Kft(e,t,r);return Jft(e,t),e};Object.defineProperty(wn,"__esModule",{value:!0}),wn.FieldDefinitionValue=wn.DefSpace=wn.DimensionFieldDeclaration=wn.MeasureFieldDeclaration=wn.DeclareFieldDeclaration=wn.ProjectFieldDeclaration=wn.GroupByFieldDeclaration=wn.AggregateFieldDeclaration=wn.CalculateFieldDeclaration=wn.AtomicFieldDeclaration=void 0;const Lk=et,Ace=Xft(nn),Zft=j2,ext=Ze,wd=lr,txt=Qr,nxt=zr;class cf extends ext.MalloyElement{constructor(e,r,i){super({expr:e}),this.expr=e,this.defineName=r,this.exprSrc=i,this.isNoteableObj=!0,this.extendNote=txt.extendNoteMethod}getName(){return this.defineName}fieldDef(e,r){return this.queryFieldDef(new Ik(e,this),r)}executesInOutputSpace(){return!1}queryFieldDef(e,r){let i;function s(){if(e.isQueryFieldSpace())return e.outputSpace();throw new Error("must be in a query -- weird internal error")}try{const u=this.executesInOutputSpace()?s():e;i=this.expr.getExpression(u)}catch(u){return this.logError("failed-field-definition",`Cannot define '${r}', ${u.message}`),{name:r,type:"error"}}if(i.type==="null"&&(this.expr.logWarning("null-typed-field-definition",'null value defaults to type number, use "null::TYPE" to specify correct type'),i={type:"number",value:i.value,expressionType:i.expressionType,evalSpace:i.evalSpace,compositeFieldUsage:i.compositeFieldUsage}),(0,Lk.isAtomicFieldType)(i.type)&&i.type!=="error"){this.typecheckExprValue(i);const u=(0,Lk.mkFieldDef)(Ace.atomicDef(i),r);return(u.type==="date"||u.type==="timestamp")&&(0,Zft.isGranularResult)(i)&&(u.timeframe=i.timeframe),u.location=this.location,u.e=i.value,u.compositeFieldUsage=i.compositeFieldUsage,i.expressionType&&(u.expressionType=i.expressionType),this.exprSrc&&(u.code=this.exprSrc),this.note&&(u.annotation=this.note),u}if(!(e instanceof Ik&&e.foundCircle)&&i.type!=="error"){const u=Ace.inspect(i);this.logError("invalid-type-for-field-definition",`Cannot define '${r}', unexpected type: ${u}`)}return{name:r,type:"error"}}makeEntry(e){e.newEntry(this.defineName,this,new _ce(e,this))}}wn.AtomicFieldDeclaration=cf;class rxt extends cf{constructor(){super(...arguments),this.elementType="calculateFieldDeclaration"}typecheckExprValue(e){(0,wd.typecheckCalculate)(e,this)}executesInOutputSpace(){return!0}}wn.CalculateFieldDeclaration=rxt;class ixt extends cf{constructor(){super(...arguments),this.elementType="aggregateFieldDeclaration"}typecheckExprValue(e){(0,wd.typecheckAggregate)(e,this)}}wn.AggregateFieldDeclaration=ixt;class sxt extends cf{constructor(){super(...arguments),this.elementType="groupByFieldDeclaration"}typecheckExprValue(e){(0,wd.typecheckGroupBy)(e,this)}}wn.GroupByFieldDeclaration=sxt;class oxt extends cf{constructor(){super(...arguments),this.elementType="projectFieldDeclaration"}typecheckExprValue(e){(0,wd.typecheckProject)(e,this)}}wn.ProjectFieldDeclaration=oxt;class uxt extends cf{constructor(){super(...arguments),this.elementType="declareFieldDeclaration"}typecheckExprValue(e){(0,wd.typecheckDeclare)(e,this)}}wn.DeclareFieldDeclaration=uxt;class axt extends cf{constructor(){super(...arguments),this.elementType="measureFieldDeclaration"}typecheckExprValue(e){(0,wd.typecheckMeasure)(e,this)}}wn.MeasureFieldDeclaration=axt;class lxt extends cf{constructor(){super(...arguments),this.elementType="dimensionFieldDeclaration"}typecheckExprValue(e){(0,wd.typecheckDimension)(e,this)}}wn.DimensionFieldDeclaration=lxt;class Ik{constructor(e,r){this.realFS=e,this.circular=r,this.type="fieldSpace",this.foundCircle=!1}structDef(){return this.realFS.structDef()}emptyStructDef(){return this.realFS.emptyStructDef()}entry(e){return this.realFS.entry(e)}lookup(e){return e[0]&&e[0].refString===this.circular.defineName?(this.foundCircle=!0,{error:{message:`Circular reference to '${this.circular.defineName}' in definition`,code:"circular-reference-in-field-definition"},found:void 0}):this.realFS.lookup(e)}entries(){return this.realFS.entries()}dialectName(){return this.realFS.dialectName()}dialectObj(){return this.realFS.dialectObj()}isQueryFieldSpace(){return this.realFS.isQueryFieldSpace()}outputSpace(){if(this.realFS.isQueryFieldSpace())return this.realFS.outputSpace();throw new Error("Not a query field space")}inputSpace(){if(this.realFS.isQueryFieldSpace())return this.realFS.inputSpace();throw new Error("Not a query field space")}isProtectedAccessSpace(){return!0}}wn.DefSpace=Ik;class _ce extends nxt.SpaceField{constructor(e,r){super(),this.space=e,this.exprDef=r,this.fieldName=r.defineName}get name(){return this.fieldName}fieldDef(){var e;const r=(e=this.defInSource)!==null&&e!==void 0?e:this.exprDef.fieldDef(this.space,this.name);return this.defInSource=r,r}getQueryFieldDef(e){if(!this.defInQuery){const r=this.exprDef.queryFieldDef(e,this.name);this.defInQuery=r}return this.defInQuery}typeDesc(){const e=this.defInQuery||this.fieldDef();if((0,Lk.isAtomic)(e))return this.fieldTypeFromFieldDef(e);throw new Error(`Can't get typeDesc for ${e.type}`)}}wn.FieldDefinitionValue=_ce;var eR={};Object.defineProperty(eR,"__esModule",{value:!0}),eR.Aggregate=void 0;const cxt=Qs,vce=zn;class fxt extends cxt.DefinitionList{constructor(){super(...arguments),this.elementType="aggregateList",this.queryRefinementStage=vce.LegalRefinementStage.Single,this.forceQueryClass=vce.QueryClass.Grouping}}eR.Aggregate=fxt;var tR={};Object.defineProperty(tR,"__esModule",{value:!0}),tR.Calculate=void 0;const xxt=Qs,dxt=zn;class hxt extends xxt.DefinitionList{constructor(){super(...arguments),this.elementType="calculate",this.forceQueryClass=void 0,this.needsExplicitQueryClass=!0,this.queryRefinementStage=dxt.LegalRefinementStage.Single}}tR.Calculate=hxt;var ME={};Object.defineProperty(ME,"__esModule",{value:!0}),ME.Dimensions=void 0;const pxt=Yc;class mxt extends pxt.DeclareFields{constructor(){super(...arguments),this.elementType="dimensionList"}}ME.Dimensions=mxt;var PE={};Object.defineProperty(PE,"__esModule",{value:!0}),PE.Measures=void 0;const gxt=Yc;class yxt extends gxt.DeclareFields{constructor(){super(...arguments),this.elementType="measureList"}}PE.Measures=yxt;var nR={};Object.defineProperty(nR,"__esModule",{value:!0}),nR.Nests=void 0;const Ext=Qs,Cce=zn;class Axt extends Ext.DefinitionList{constructor(e){super(e),this.elementType="nestedQueries",this.queryRefinementStage=Cce.LegalRefinementStage.Single,this.forceQueryClass=Cce.QueryClass.Grouping}}nR.Nests=Axt;var rR={};Object.defineProperty(rR,"__esModule",{value:!0}),rR.ProjectStatement=void 0;const _xt=Qs,Sce=zn;class vxt extends _xt.DefinitionList{constructor(){super(...arguments),this.elementType="projectStatement",this.forceQueryClass=Sce.QueryClass.Project,this.queryRefinementStage=Sce.LegalRefinementStage.Single}queryExecute(e){e.type==="project"&&e.resultFS.pushFields(...this.list)}}rR.ProjectStatement=vxt;var ff={},_0={},Pn={};Object.defineProperty(Pn,"__esModule",{value:!0}),Pn.getPlainString=Pn.unIndent=Pn.getOptionalId=Pn.idToStr=Pn.getId=Pn.getStringParts=Pn.getStringIfShort=Pn.getShortString=void 0;const bce=$o;function Tce(t){var e,r;const i=((e=t.DQ_STRING())===null||e===void 0?void 0:e.text)||((r=t.SQ_STRING())===null||r===void 0?void 0:r.text);return i?bce.ParseUtil.parseString(i,i[0]):""}Pn.getShortString=Tce;function Rce(t){const e=t.string().shortString();if(e)return Tce(e)}Pn.getStringIfShort=Rce;function*Dce(t){var e;if(t){for(const i of t.sqlInterpolation()){const s=i.OPEN_CODE().text;s.length>2&&(yield s.slice(0,s.length-2)),i.sqExpr()&&(yield i.sqExpr())}const r=(e=t.SQL_END())===null||e===void 0?void 0:e.text.slice(0,-3);r&&r.length>0&&(yield r)}}Pn.getStringParts=Dce;function Oce(t){return Fce(t.id())}Pn.getId=Oce;function Fce(t){const e=t.BQ_STRING();return e?bce.ParseUtil.parseString(e.text,"`"):t.text}Pn.idToStr=Fce;function Cxt(t){function e(r){return"id"in r}if(e(t)&&t.id())return Oce(t)}Pn.getOptionalId=Cxt;function*wce(t){for(;t.length>0;){const e=t.match(/^.*?\r?\n/);let r=t;e&&(r=e[0]),yield r,t=t.slice(r.length)}}function Sxt(t){let e;for(const r of wce(t)){const i=r.match(/^( *).*[^\s]/);if(i){const s=i[1].length;(e===void 0||s<e)&&(e=s)}}return e}function Nce(t){let e;for(const r of t)if(typeof r=="string"){const i=Sxt(r);i!==void 0&&(e===void 0||i<e)&&(e=i)}if(e)for(let r=0;r<=t.length;r+=1){const i=t[r];if(typeof i=="string"){let s="";for(let o of wce(i))o[0]===" "&&(o=o.slice(e)),s+=o;t[r]=s}}}Pn.unIndent=Nce;function bxt(t,e=!1){const r=[],i=Rce(t);if(i)return[i,r];const s=[],o=t.string().sqlString();if(o){for(const u of Dce(o))if(typeof u=="string")s.push(u);else if(r.push(u),e)return[void 0,r];return Nce(s),[s.join(""),r]}return["",r]}Pn.getPlainString=bxt,Object.defineProperty(_0,"__esModule",{value:!0}),_0.findReferences=_0.deprecatedParseTableURI=_0.constructTableKey=void 0;const Txt=T0,$k=Pn;function Lce(t){const e=(0,$k.getStringIfShort)(t);if(e)return e;const r=[],i=t.string().sqlString();if(i){for(const s of(0,$k.getStringParts)(i))typeof s=="string"&&r.push(s);return r.join("")}return""}class Rxt{constructor(e,r){this.trans=e,this.tokens=r,this.needTables={},this.needImports={}}registerTableReference(e,r,i){const s=Ice(e,r);this.needTables[s]||(this.needTables[s]={connectionName:e,tablePath:r,firstReference:i})}enterExploreTable(e){const r=(0,$k.getId)(e.connectionId()),i=Lce(e.tablePath()),s=this.trans.rangeFromContext(e);this.registerTableReference(r,i,s)}enterImportURL(e){const r=Lce(e);this.needImports[r]||(this.needImports[r]=this.trans.rangeFromContext(e))}}function Ice(t,e){return t===void 0?e:`${t}:${e}`}_0.constructTableKey=Ice;function Dxt(t){const e=t.match(/^([^:]*):(.*)$/);if(e){const[,r,i]=e;return{connectionName:r,tablePath:i}}else return{tablePath:t}}_0.deprecatedParseTableURI=Dxt;function Oxt(t,e,r){const i=new Rxt(t,e),s=i;return Txt.ParseTreeWalker.DEFAULT.walk(s,r),{tables:i.needTables,urls:i.needImports}}_0.findReferences=Oxt,Object.defineProperty(ff,"__esModule",{value:!0}),ff.TableFunctionSource=ff.TableMethodSource=ff.TableSource=void 0;const $ce=_0,Fxt=Ro,Bce=gi;class Bk extends Fxt.Source{getSourceDef(){var e,r,i;const s=this.getTableInfo();if(s===void 0)return Bce.ErrorFactory.structDef;const{tablePath:o,connectionName:u}=s,a=(0,$ce.constructTableKey)(u,o),l=(e=this.translator())===null||e===void 0?void 0:e.root.schemaZone.getEntry(a);let c=`Schema read failure for table '${o}' for connection '${u}'`;if(l){if(l.status==="present"){(r=this.document())===null||r===void 0||r.checkExperimentalDialect(this,l.value.dialect),l.value.location=this.location,l.value.fields.forEach(x=>{x.location=this.location});const f={...l.value,fields:l.value.fields.map(x=>({...x,location:this.location})),location:this.location};return(i=this.document())===null||i===void 0||i.rememberToAddModelAnnotations(f),f}l.status==="error"&&(c=l.message)}return this.logError("failed-to-fetch-table-schema",c),Bce.ErrorFactory.structDef}}ff.TableSource=Bk;class wxt extends Bk{constructor(e,r){super(),this.connectionName=e,this.tablePath=r,this.elementType="tableMethodSource",this.has({connectionName:e})}getTableInfo(){var e;const r=this.modelEntry(this.connectionName),i=this.connectionName.refString;if(r===void 0)(e=this.namespace())===null||e===void 0||e.setEntry(i,{entry:{type:"connection",name:i},exported:!0},!0);else if(r.entry.type!=="connection"){this.connectionName.logError("invalid-connection-for-table-source",`${this.connectionName.refString} is not a connection`);return}return{tablePath:this.tablePath,connectionName:this.connectionName.refString}}}ff.TableMethodSource=wxt;class Nxt extends Bk{constructor(e){super(),this.tableURI=e,this.elementType="tableFunctionSource"}getTableInfo(){return(0,$ce.deprecatedParseTableURI)(this.tableURI)}}ff.TableFunctionSource=Nxt;var iR={};Object.defineProperty(iR,"__esModule",{value:!0}),iR.SQLString=void 0;const Lxt=Ze,kce=Tu;class Ixt extends Lxt.MalloyElement{constructor(){super(...arguments),this.elementType="sqlString",this.elements=[],this.containsQueries=!1}complete(){this.has({queries:this.elements.filter($xt)})}push(e){typeof e=="string"?e.length>0&&this.elements.push(e):e instanceof kce.SourceQueryElement?(this.elements.push(e),this.containsQueries=!0,e.parent=this):e.logError("invalid-sql-source-interpolation","This element is not legal inside an SQL string")}sqlPhrases(){const e=[];for(const r of this.elements)if(typeof r=="string")e.push({sql:r});else{const i=r.getQuery();i?e.push(i.query()):r.sqLog("failed-to-expand-sql-source","Cannot expand into a query")}return e}}iR.SQLString=Ixt;function $xt(t){return t instanceof kce.SourceQueryElement}var sR={};Object.defineProperty(sR,"__esModule",{value:!0}),sR.SourceDesc=void 0;const Bxt=Ze;class kxt extends Bxt.ListOf{constructor(){super(...arguments),this.elementType="sourceDescription"}}sR.SourceDesc=kxt;var oR={};Object.defineProperty(oR,"__esModule",{value:!0}),oR.isSourceProperty=void 0;const Mxt=qa,Pxt=Yc,Uxt=I2,jxt=Jc,qxt=$2,Hxt=B2,Qxt=k2,zxt=Kc,Wxt=ys;function Gxt(t){return t instanceof Mxt.Filter||t instanceof Wxt.JoinStatement||t instanceof Pxt.DeclareFields||t instanceof Uxt.FieldListEdit||t instanceof jxt.Renames||t instanceof qxt.PrimaryKey||t instanceof zxt.ObjectAnnotation||t instanceof Hxt.Views||t instanceof Qxt.TimezoneStatement}oR.isSourceProperty=Gxt;var uR={};Object.defineProperty(uR,"__esModule",{value:!0}),uR.isFieldCollectionMember=void 0;const Vxt=wn,Mce=_t;function Yxt(t){return t instanceof Mce.FieldReference||t instanceof Mce.WildcardFieldReference||t instanceof Vxt.AtomicFieldDeclaration}uR.isFieldCollectionMember=Yxt;var aR={};Object.defineProperty(aR,"__esModule",{value:!0}),aR.isQueryElement=void 0;const Kxt=M2,Jxt=P2,Xxt=_E,Zxt=vE;function edt(t){return t instanceof Kxt.QueryArrow||t instanceof Jxt.QueryRefine||t instanceof Xxt.QueryReference||t instanceof Zxt.QueryRaw}aR.isQueryElement=edt;var Pce={};Object.defineProperty(Pce,"__esModule",{value:!0});var lR={};Object.defineProperty(lR,"__esModule",{value:!0}),lR.isQueryProperty=void 0;function tdt(t){return"queryRefinementStage"in t&&"forceQueryClass"in t}lR.isQueryProperty=tdt;var cR={};Object.defineProperty(cR,"__esModule",{value:!0}),cR.isQueryExtendProperty=void 0;const ndt=ME,rdt=ys,idt=PE;function sdt(t){return t instanceof ndt.Dimensions||t instanceof idt.Measures||t instanceof rdt.JoinStatement}cR.isQueryExtendProperty=sdt;var fR={};Object.defineProperty(fR,"__esModule",{value:!0}),fR.isFieldPropStatement=void 0;const odt=tf,udt=qa,adt=nf,ldt=G2;function cdt(t){return t instanceof udt.Filter||t instanceof adt.Limit||t instanceof ldt.PartitionBy||t instanceof odt.FunctionOrdering}fR.isFieldPropStatement=cdt,function(t){var e=T&&T.__createBinding||(Object.create?function(i,s,o,u){u===void 0&&(u=o);var a=Object.getOwnPropertyDescriptor(s,o);(!a||("get"in a?!s.__esModule:a.writable||a.configurable))&&(a={enumerable:!0,get:function(){return s[o]}}),Object.defineProperty(i,u,a)}:function(i,s,o,u){u===void 0&&(u=o),i[u]=s[o]}),r=T&&T.__exportStar||function(i,s){for(var o in i)o!=="default"&&!Object.prototype.hasOwnProperty.call(s,o)&&e(s,i,o)};Object.defineProperty(t,"__esModule",{value:!0}),r(sE,t),r(O2,t),r(F2,t),r(Ro,t),r(aE,t),r(Tu,t),r(W4,t),r(G4,t),r(K4,t),r(pE,t),r(J4,t),r(X4,t),r(bu,t),r(I2,t),r($2,t),r(Jc,t),r(B2,t),r(k2,t),r(eT,t),r(H2,t),r(nT,t),r(Q2,t),r(tf,t),r(rT,t),r(E0,t),r(iT,t),r(W2,t),r(sT,t),r(oT,t),r(uT,t),r(y0,t),r(aT,t),r(lT,t),r(fT,t),r(DE,t),r(TE,t),r(bd,t),r(dT,t),r(hT,t),r(mT,t),r(yT,t),r(ET,t),r(AT,t),r(_T,t),r(sf,t),r(CT,t),r(ST,t),r(bT,t),r(TT,t),r(RT,t),r(DT,t),r(OT,t),r(wT,t),r(IT,t),r(Fr,t),r(kT,t),r(G2,t),r(Y2,t),r(J2,t),r(PT,t),r(Dd,t),r(ef,t),r(UT,t),r(OE,t),r(uf,t),r(NE,t),r(jT,t),r(qT,t),r(HT,t),r(P2,t),r(M2,t),r(af,t),r(QT,t),r(zT,t),r(WT,t),r(GT,t),r(wn,t),r(_t,t),r(eR,t),r(tR,t),r(Yc,t),r(ME,t),r(NE,t),r(qa,t),r(kE,t),r($E,t),r(ys,t),r(oE,t),r(nf,t),r(PE,t),r(sE,t),r(nR,t),r(Od,t),r(rR,t),r(IE,t),r(BE,t),r(U2,t),r(Sd,t),r(CE,t),r(ff,t),r(iR,t),r(Kc,t),r(Ru,t),r(sR,t),r(oR,t),r(ht,t),r(uR,t),r(rf,t),r(Ze,t),r(aR,t),r(Pce,t),r(lR,t),r(cR,t),r(fR,t)}(P4);var xR={},fdt=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),xdt=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),ddt=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&fdt(e,t,r);return xdt(e,t),e};Object.defineProperty(xR,"__esModule",{value:!0}),xR.MalloyToAST=void 0;const Uce=ng,hdt=qd,ue=ddt(P4),kk=T2,jce=xr,pdt=P4,Xn=Pn,dR=et,mdt=$o,qce=Jn,gdt=nE;class Hce extends ue.SourceQueryElement{constructor(){super(...arguments),this.elementType="parseErrorSourceQuery"}}class Mk extends ue.MalloyElement{constructor(e){super(),this.elementType="ignoredByParser",this.malloySrc=e}}const ydt=[];class Edt extends hdt.AbstractParseTreeVisitor{constructor(e,r,i){super(),this.parseInfo=e,this.msgLog=r,this.compilerFlags=i;for(const s of ydt){const o=mdt.Tag.fromTagLine(s,0,this.compilerFlags);this.compilerFlags=o.tag}}internalError(e,r){return this.contextError(e,"internal-translator-error",{message:r}),new Error(`Internal Translator Error: ${r}`)}astError(e,r,i,s){this.msgLog.log((0,kk.makeLogMessage)(r,i,{at:e.location,...s}))}rangeFromContext(e){return(0,qce.rangeFromContext)(this.parseInfo.sourceInfo,e)}getLocation(e){return{url:this.parseInfo.sourceURL,range:this.rangeFromContext(e)}}getSourceString(e){return this.parseInfo.sourceStream.getText(new jce.Interval(e.start.startIndex,e.stop?e.stop.stopIndex:e.start.startIndex))}contextError(e,r,i,s){this.msgLog.log((0,kk.makeLogMessage)(r,i,{at:this.getLocation(e),...s}))}warnWithReplacement(e,r,i,s){this.msgLog.log((0,kk.makeLogMessage)(e,r,{at:{url:this.parseInfo.sourceURL,range:i},severity:"warn",replacement:s}))}inExperiment(e,r){const i=this.compilerFlags.tag("experimental");return i&&(i.bare()||i.has(e))?!0:(this.contextError(r,"experiment-not-enabled",{experimentId:e}),!1)}only(e,r,i){const s=[];for(const o of e){const u=r(o);u?s.push(u):o instanceof Mk||this.astError(o,"unexpected-statement-in-translation",`Parser enountered unexpected statement type '${o.elementType}' when it needed '${i}'`)}return s}getNumber(e){return Number.parseInt(e.text)}getFieldName(e){return this.astAt(new ue.FieldName((0,Xn.getId)(e)),e.id())}getModelEntryName(e){return this.astAt(new ue.ModelEntryReference((0,Xn.getId)(e)),e.id())}defaultResult(){return new ue.Unimplemented}astAt(e,r){return e.location={url:this.parseInfo.sourceURL,range:this.rangeFromContext(r)},e}getSourceCode(e){const r=e.start.startIndex,i=e.stop||e.start,s=new jce.Interval(r,i.stopIndex);return this.parseInfo.sourceStream.getText(s)}getFilterElement(e){const r=this.getFieldExpr(e),i=new ue.FilterElement(r,this.getSourceCode(e));return this.astAt(i,e)}getFieldDefs(e,r){return e.map(i=>this.getFieldDef(i,r))}getFieldExpr(e){const r=this.visit(e);if(r instanceof ue.ExpressionDef)return this.astAt(r,e);throw this.internalError(e,`expression node unknown type '${r.elementType}'`)}getPlainStringFrom(e){const[r,i]=(0,Xn.getPlainString)(e);for(const s of i)s instanceof Uce.ParserRuleContext&&this.contextError(s,"illegal-query-interpolation-outside-sql-block","%{ query } illegal in this string");return r||""}makeSqlString(e,r){for(const i of(0,Xn.getStringParts)(e))i instanceof Uce.ParserRuleContext?r.push(this.visit(i)):r.push(i);r.complete(),this.astAt(r,e)}parseTime(e,r){let i=r(e.text);return i||(this.contextError(e,"failed-to-parse-time-literal","Time data parse error"),i=new ue.LiteralTimestamp({text:e.text})),this.astAt(i,e)}getNotes(e){return e.ANNOTATION().map(r=>({text:r.text,at:this.getLocation(e)}))}getIsNotes(e){return this.getNotes(e._beforeIs).concat(this.getNotes(e._afterIs))}visitMalloyDocument(e){const r=this.only(e.malloyStatement().map(i=>this.visit(i)),i=>ue.isDocStatementOrDocStatementList(i)&&i,"statement");return new ue.Document(r)}visitDefineSourceStatement(e){const i=e.sourcePropertyList().sourceDefinition().map(u=>this.visitSourceDefinition(u)),s=this.getNotes(e.tags()),o=new ue.DefineSourceList(i);return o.extendNote({blockNotes:s}),o}getSourceParameter(e){const r=(0,Xn.getId)(e.parameterNameDef());let i,s;const o=e.legalParamType();if(o){const l=o.malloyType();if(l){const f=this.getMalloyType(l);(0,gdt.isFilterable)(f)?s=f:this.contextError(o,"parameter-illegal-default-type",`Unknown filter type ${f}`)}const c=o.FILTER()?"filter expression":o.text.toLowerCase();if(!(0,dR.isParameterType)(c))return this.contextError(o,"parameter-illegal-default-type",`Unknown parameter type ${c}`),null;i=c}const u=e.fieldExpr();let a;if(u){const l=new ue.ConstantExpression(this.getFieldExpr(u));a=this.astAt(l,u)}return this.astAt(new ue.HasParameter({name:r,type:i,default:a,filterType:s}),e)}getSourceParameters(e){if(e===void 0)return[];this.inExperiment("parameters",e);function r(i){return i!==null}return e.sourceParameter().map(i=>this.getSourceParameter(i)).filter(r)}visitSourceDefinition(e){const r=this.visit(e.sqExplore()),i=this.getSourceParameters(e.sourceParameters()),s=new ue.DefineSource((0,Xn.getId)(e.sourceNameDef()),r instanceof ue.SourceQueryElement?r:void 0,!0,i),o=this.getNotes(e.tags()).concat(this.getIsNotes(e.isDefine()));return s.extendNote({notes:o}),this.astAt(s,e)}getSourceExtensions(e){return this.astAt(this.visitExploreProperties(e),e)}visitExploreProperties(e){const r=this.only(e.exploreStatement().map(s=>this.visit(s)),s=>ue.isSourceProperty(s)&&s,"source property");return new ue.SourceDesc(r)}visitExploreTable(e){const r=e.connectionId(),i=this.astAt(this.getModelEntryName(r),r),s=this.getPlainStringFrom(e.tablePath());return this.astAt(new ue.TableMethodSource(i,s),e)}visitSqlSource(e){const r=e.connectionId(),i=this.astAt(this.getModelEntryName(r),r),s=new ue.SQLString,o=e.sqlString();o&&this.makeSqlString(o,s);const u=e.shortString();u&&s.push((0,Xn.getShortString)(u));const a=new ue.SQLSource(i,s);return this.astAt(a,e)}visitDefJoinMany(e){const r=this.getAccessLabel(e.accessLabel()),i=[];for(const o of e.joinList().joinDef()){const u=this.visit(o);u instanceof ue.Join&&(i.push(u),u instanceof ue.ExpressionJoin?(u.joinType="many",u.joinOn===void 0&&this.contextError(e,"missing-on-in-join-many","join_many: requires ON expression")):u instanceof ue.KeyJoin&&this.contextError(e,"foreign-key-in-join-many","Foreign key join not legal in join_many:"))}const s=new ue.JoinStatement(i,r);return s.extendNote({blockNotes:this.getNotes(e.tags())}),s}visitDefJoinOne(e){const r=this.getAccessLabel(e.accessLabel()),i=this.getJoinList(e.joinList()),s=[];for(const u of i)u instanceof ue.Join&&(s.push(u),u instanceof ue.ExpressionJoin&&(u.joinType="one"));const o=new ue.JoinStatement(s,r);return o.extendNote({blockNotes:this.getNotes(e.tags())}),o}visitDefJoinCross(e){const r=this.getAccessLabel(e.accessLabel()),i=this.getJoinList(e.joinList()),s=[];for(const u of i)u instanceof ue.Join&&(s.push(u),u instanceof ue.ExpressionJoin?u.joinType="cross":u.logError("foreign-key-in-join-cross","Foreign key join not legal in join_cross:"));const o=new ue.JoinStatement(s,r);return o.extendNote({blockNotes:this.getNotes(e.tags())}),o}getJoinList(e){return this.only(e.joinDef().map(r=>this.visit(r)),r=>r instanceof ue.Join&&r,"join")}getJoinFrom(e){const r=e.isExplore(),i=this.getModelEntryName(e.joinNameDef());if(r){const o=this.getSqExpr(r.sqExpr()),u=this.getNotes(r._before_is).concat(this.getNotes(r._after_is));return{joinFrom:o,notes:u,joinAs:i}}const s=e.sourceArguments();return s?{joinFrom:this.astAt(new ue.SQReference(i,this.getSQArguments(s)),e),notes:[],joinAs:i}:{joinAs:i,joinFrom:new ue.SQReference(i),notes:[]}}visitQueryJoinStatement(e){return this.astAt(this.visit(e.joinStatement()),e)}visitJoinOn(e){var r;const{joinAs:i,joinFrom:s,notes:o}=this.getJoinFrom(e.joinFrom()),u=new ue.ExpressionJoin(i,s),a=e.joinExpression(),l=((r=e.matrixOperation())===null||r===void 0?void 0:r.text.toLocaleLowerCase())||"left";return(0,dR.isMatrixOperation)(l)?u.matrixOperation=l:this.contextError(e,"unknown-matrix-operation","Internal Error: Unknown matrixOperation"),a&&(u.joinOn=this.getFieldExpr(a)),u.extendNote({notes:this.getNotes(e).concat(o)}),this.astAt(u,e)}visitJoinWith(e){const{joinAs:r,joinFrom:i,notes:s}=this.getJoinFrom(e.joinFrom()),o=this.getFieldExpr(e.fieldExpr()),u=new ue.KeyJoin(r,i,o);return u.extendNote({notes:this.getNotes(e).concat(s)}),this.astAt(u,e)}getFieldDef(e,r){const i=e.fieldExpr(),s=(0,Xn.getId)(e.fieldNameDef()),o=this.getFieldExpr(i),u=new r(o,s,this.getSourceCode(i)),a=this.getNotes(e.tags()).concat(this.getIsNotes(e.isDefine()));return u.extendNote({notes:a}),this.astAt(u,e)}visitDefDimensions(e){const r=this.getAccessLabel(e.accessLabel()),i=this.getFieldDefs(e.defList().fieldDef(),ue.DimensionFieldDeclaration),s=new ue.Dimensions(i,r);return s.extendNote({blockNotes:this.getNotes(e.tags())}),this.astAt(s,e)}getAccessLabel(e){if(e!==void 0){if(e.INTERNAL_KW())return"internal";if(e.PRIVATE_KW())return"private";if(e.PUBLIC_KW())return"public";throw this.internalError(e,`Unknown access modifier label ${e.text}`)}}getAccessLabelProp(e){if(e!==void 0){if(e.INTERNAL())return"internal";if(e.PRIVATE())return"private";if(e.PUBLIC())return"public";throw this.internalError(e,`Unknown access modifier label ${e.text}`)}}visitDefMeasures(e){const r=this.getAccessLabel(e.accessLabel()),i=this.getFieldDefs(e.defList().fieldDef(),ue.MeasureFieldDeclaration),s=new ue.Measures(i,r);return s.extendNote({blockNotes:this.getNotes(e.tags())}),this.astAt(s,e)}visitQueryExtend(e){const r=[],i=e.queryExtendStatementList().queryExtendStatement().map(o=>this.visit(o));for(const o of i)if(ue.isQueryExtendProperty(o))r.push(o);else throw this.internalError(e,`Query extend matched, but ${o.elementType} found`);const s=new ue.ExtendBlock(r);return this.astAt(s,e)}visitExploreRenameDef(e){const r=e.fieldName(0),i=e.fieldName(1),s=new ue.RenameField((0,Xn.getId)(r),this.getFieldName(i));return this.astAt(s,e)}visitDefExploreRename(e){const r=this.getAccessLabel(e.accessLabel()),s=e.renameList().exploreRenameDef().map(u=>this.visitExploreRenameDef(u)),o=new ue.Renames(s,r);return this.astAt(o,e)}visitFilterClauseList(e){return new ue.Filter(e.fieldExpr().map(r=>this.getFilterElement(r)))}visitWhereStatement(e){const r=this.visitFilterClauseList(e.filterClauseList());return r.having=!1,this.astAt(r,e)}visitHavingStatement(e){const r=this.visitFilterClauseList(e.filterClauseList());return r.having=!0,this.astAt(r,e)}visitDefExploreQuery(e){const r=this.getAccessLabel(e.accessLabel()),i=e.subQueryDefList().exploreQueryDef().map(u=>this.visitExploreQueryDef(u)),s=new ue.Views(i,r),o=this.getNotes(e.tags());return s.extendNote({blockNotes:o}),s}visitDefExplorePrimaryKey(e){const r=new ue.PrimaryKey(this.getFieldName(e.fieldName()));return this.astAt(r,e)}getFieldNameList(e,r){const i=e.fieldName().map(s=>this.astAt(new r([this.getFieldName(s)]),s));return new ue.FieldReferences(i)}visitDefExploreEditField(e){const r=e.ACCEPT()?"accept":"except";return new ue.FieldListEdit(r,this.getFieldNameList(e.fieldNameList(),ue.AcceptExceptFieldReference))}visitSQInclude(e){const r=this.getSqExpr(e.sqExpr()),i=e.includeBlock(),s=i?this.getIncludeItems(i):void 0,o=new ue.SQExtend(r,new ue.SourceDesc([]),s);return this.astAt(o,e)}visitDefExploreTimezone(e){return this.visitTimezoneStatement(e.timezoneStatement())}visitTimezoneStatement(e){const r=this.getPlainStringFrom(e),i=this.astAt(new ue.TimezoneStatement(r),e.string());return i.isValid||this.astError(i,"invalid-timezone",{timezone:i.tz}),this.astAt(i,e)}visitQueryProperties(e){const r=this.only(e.queryStatement().map(i=>this.astAt(this.visit(i),i)),i=>ue.isQueryProperty(i)&&i,"query statement");return new ue.QOpDesc(r)}getFieldPath(e,r){const i=e.fieldName().map(s=>this.getFieldName(s));return this.astAt(new r(i),e)}getQueryFieldDef(e,r){const i=this.getFieldDef(e,r);return this.astAt(i,e)}getQueryFieldEntry(e,r,i){const s=e.taggedRef();if(s)return this.getTaggedRef(s,r,i);const o=e.fieldDef();if(o)return this.getQueryFieldDef(o,r);throw new Error("Expected query field entry to be a field reference or definition")}getQueryItems(e,r,i){return this.only(e.queryFieldEntry().map(s=>this.getQueryFieldEntry(s,r,i)),s=>s instanceof ue.FieldReference||s instanceof ue.AtomicFieldDeclaration?s:!1,"view field")}visitAggregateStatement(e){const r=new ue.Aggregate(this.getQueryItems(e.queryFieldList(),ue.AggregateFieldDeclaration,ue.AggregateFieldReference));return r.extendNote({blockNotes:this.getNotes(e.tags())}),r}visitGroupByStatement(e){const r=new ue.GroupBy(this.getQueryItems(e.queryFieldList(),ue.GroupByFieldDeclaration,ue.GroupByFieldReference));return r.extendNote({blockNotes:this.getNotes(e.tags())}),r}visitCalculateStatement(e){const r=new ue.Calculate(this.getQueryItems(e.queryFieldList(),ue.CalculateFieldDeclaration,ue.CalculateFieldReference));return r.extendNote({blockNotes:this.getNotes(e.tags())}),r}getTaggedRef(e,r,i){const s=e.refExpr();if(s){const u=this.getFieldPath(e.fieldPath(),ue.ExpressionFieldReference);let a;const l=s.timeframe();l&&(a=new ue.ExprGranularTime(new ue.ExprIdReference(u),this.visitTimeframe(l).text,!0));const c=s.aggregate();if(c){const x=c.text.toLowerCase();if(x==="sum")a=new ue.ExprSum(void 0,u);else return this.contextError(c,"invalid-reference-only-aggregation",`\`${x}\` is not legal in a reference-only aggregation`),u}const f=new r(a,u.outputName);return f.extendNote({notes:this.getNotes(e.tags())}),f}const o=this.getFieldPath(e.fieldPath(),i);return o.extendNote({notes:this.getNotes(e.tags())}),o}getFieldCollectionMember(e,r,i){const s=e.fieldDef();if(s)return this.getFieldDef(s,r);const o=e.taggedRef();if(o)return this.getTaggedRef(o,r,i);const u=e.collectionWildCard();if(u)return this.visitCollectionWildCard(u);throw this.internalError(e,"Unexpected element in fieldCollectionMember")}visitFieldCollection(e){const r=e.collectionMember().map(i=>this.getFieldCollectionMember(i,ue.ProjectFieldDeclaration,ue.ProjectFieldReference));return this.astAt(new ue.ProjectStatement(r),e)}visitProjectStatement(e){const r=this.visitFieldCollection(e.fieldCollection());return r.extendNote({blockNotes:this.getNotes(e.tags())}),r}visitCollectionWildCard(e){var r;const i=e.fieldPath(),s=i?this.getFieldPath(i,ue.ProjectFieldReference):void 0,o=this.astAt(new ue.WildcardFieldReference(s),e),u=((r=e.starQualified())===null||r===void 0?void 0:r.fieldNameList())||[];for(const a of u)for(const l of a.fieldName())o.except.add((0,Xn.getId)(l));return o}visitIndexFields(e){const r=e.indexElement().map(i=>{const s=i.fieldPath();if(!s)return this.astAt(new ue.WildcardFieldReference(void 0),e);const o=this.getFieldPath(s,ue.IndexFieldReference);return i.STAR()?this.astAt(new ue.WildcardFieldReference(o),e):this.astAt(o,e)});return new ue.FieldReferences(r)}visitIndexStatement(e){const r=this.visitIndexFields(e.indexFields()),i=new ue.Index(r),s=e.fieldName();return s&&i.useWeight(this.getFieldName(s)),this.astAt(i,e)}visitFieldPropertyLimitStatement(e){return this.inExperiment("aggregate_limit",e),this.visitLimitStatement(e.limitStatement())}visitLimitStatement(e){return new ue.Limit(this.getNumber(e.INTEGER_LITERAL()))}visitAggregateOrderBySpec(e){const r=e.ASC()?"asc":e.DESC()?"desc":void 0,i=e.fieldExpr(),s=i?this.getFieldExpr(i):void 0;return this.astAt(new ue.FunctionOrderBy(s,r),e)}visitAggregateOrderByStatement(e){return this.visitAggregateOrdering(e.aggregateOrdering())}visitAggregateOrdering(e){const r=e.aggregateOrderBySpec().map(i=>this.visitAggregateOrderBySpec(i));return this.astAt(new ue.FunctionOrdering(r),e)}visitOrderBySpec(e){const r=e.ASC()?"asc":e.DESC()?"desc":void 0,i=e.INTEGER_LITERAL();if(i)return new ue.OrderBy(this.getNumber(i),r);const s=e.fieldName();if(s)return new ue.OrderBy(this.getFieldName(s),r);throw this.internalError(e,"can't parse order_by specification")}visitOrdering(e){const r=e.orderBySpec().map(i=>this.visitOrderBySpec(i));return this.astAt(new ue.Ordering(r),e)}visitTopStatement(e){const r=this.getNumber(e.INTEGER_LITERAL());return this.astAt(new ue.Limit(r),e)}visitTopLevelQueryDefs(e){const r=e.topLevelQueryDef().map(o=>this.visitTopLevelQueryDef(o)),i=this.getNotes(e.tags()),s=new ue.DefineQueryList(r);return s.extendNote({blockNotes:i}),s}visitTopLevelQueryDef(e){const r=(0,Xn.getId)(e.queryName()),i=this.visit(e.sqExpr()),s=this.getNotes(e.tags()).concat(this.getIsNotes(e.isDefine()));if(i instanceof ue.SourceQueryElement){const o=new ue.DefineQuery(r,i);return o.extendNote({notes:s}),this.astAt(o,e)}throw this.internalError(e,`Expected query definition, got a '${i.elementType}'`)}visitRunStatement(e){const r=e.topLevelAnonQueryDef(),i=this.getSqExpr(r.sqExpr()),s=this.astAt(new ue.AnonymousQuery(i),r),o=this.getNotes(e.topLevelAnonQueryDef().tags()),u=this.getNotes(e.tags());return s.extendNote({notes:o,blockNotes:u}),this.astAt(s,e)}visitNestStatement(e){const r=this.visitNestedQueryList(e.nestedQueryList());return r.extendNote({blockNotes:this.getNotes(e.tags())}),r}visitNestedQueryList(e){return new ue.Nests(this.only(e.nestEntry().map(r=>this.visit(r)),r=>r instanceof ue.NestFieldDeclaration&&r,"query"))}visitNestDef(e){const r=e.queryName();let i;const s=this.getVExpr(e.vExpr());if(r)i=(0,Xn.getId)(r);else{const a=s.getImplicitName();a===void 0&&this.contextError(e,"anonymous-nest","`nest:` view requires a name (add `nest_name is ...`)"),i=a??"__unnamed__"}const o=new ue.NestFieldDeclaration(i,s),u=e.isDefine();return o.extendNote({notes:this.getNotes(e.tags()).concat(u?this.getIsNotes(u):[])}),this.astAt(o,e)}visitExploreQueryDef(e){const r=(0,Xn.getId)(e.exploreQueryNameDef()),i=new ue.ViewFieldDeclaration(r,this.getVExpr(e.vExpr())),s=this.getNotes(e).concat(this.getIsNotes(e.isDefine()));return i.extendNote({notes:s}),this.astAt(i,e)}visitExprNot(e){return new ue.ExprNot(this.getFieldExpr(e.fieldExpr()))}visitExprBool(e){return new ue.Boolean(e.TRUE()?"true":"false")}allFieldExpressions(e){return e.map(r=>this.getFieldExpr(r))}visitExprLogicalOr(e){const r=this.getFieldExpr(e.fieldExpr(0)),i=this.getFieldExpr(e.fieldExpr(1));return new ue.ExprLogicalOp(r,"or",i)}visitExprLogicalAnd(e){const r=this.getFieldExpr(e.fieldExpr(0)),i=this.getFieldExpr(e.fieldExpr(1));return new ue.ExprLogicalOp(r,"and",i)}visitExprOrTree(e){const r=this.getFieldExpr(e.fieldExpr()),i=this.getFieldExpr(e.partialAllowedFieldExpr());return this.astAt(new ue.ExprAlternationTree(r,"|",i),e)}visitExprAndTree(e){const r=this.getFieldExpr(e.fieldExpr()),i=this.getFieldExpr(e.partialAllowedFieldExpr());return this.astAt(new ue.ExprAlternationTree(r,"&",i),e)}visitExprCoalesce(e){const r=this.getFieldExpr(e.fieldExpr()[0]),i=this.getFieldExpr(e.fieldExpr()[1]);return this.astAt(new ue.ExprCoalesce(r,i),e)}visitPartialCompare(e){const r=e.compareOp().text;if(ue.isComparison(r))return this.astAt(new ue.PartialCompare(r,this.getFieldExpr(e.fieldExpr())),e);throw this.internalError(e,`partial comparison '${r}' not recognized`)}visitPartialTest(e){const r=e.partialCompare();return r?this.visitPartialCompare(r):this.astAt(new ue.PartialIsNull(e.NOT()?"!=":"="),e)}visitPartialAllowedFieldExpr(e){const r=e.fieldExpr();if(r)return this.getFieldExpr(r);const i=e.partialTest();if(i)return this.visitPartialTest(i);throw this.internalError(e,"impossible partial")}visitExprString(e){const r=this.getPlainStringFrom(e);return new ue.ExprString(r)}visitRawString(e){const r=e.text.slice(1).trimStart();if(r[r.length-1]===`
|
|
1556
|
+
`){const o=r[0]==="'"?'"':"'";this.contextError(e,"literal-string-newline",`Missing ${o}${r[0]}${o} before end-of-line`)}const s=new ue.ExprString(r.slice(1,-1));return this.astAt(s,e)}visitExprRegex(e){const r=e.HACKY_REGEX().text;return new ue.ExprRegEx(r.slice(2,-1))}visitExprNow(e){return new ue.ExprNow}visitExprNumber(e){return new ue.ExprNumber(e.text)}visitExprFieldPath(e){const r=new ue.ExprIdReference(this.getFieldPath(e.fieldPath(),ue.ExpressionFieldReference));return this.astAt(r,e)}visitExprNULL(e){return new ue.ExprNULL}visitExprExpr(e){return new ue.ExprParens(this.getFieldExpr(e.fieldExpr()))}visitExprMinus(e){return new ue.ExprMinus(this.getFieldExpr(e.fieldExpr()))}visitExprAddSub(e){const r=this.getFieldExpr(e.fieldExpr(0)),i=this.getFieldExpr(e.fieldExpr(1)),s=e.PLUS()?"+":"-";return new ue.ExprAddSub(r,s,i)}visitExprMulDiv(e){const r=e.STAR()?"*":e.SLASH()?"/":"%";return new ue.ExprMulDiv(this.getFieldExpr(e.fieldExpr(0)),r,this.getFieldExpr(e.fieldExpr(1)))}visitExprCompare(e){const r=e.compareOp().text,i=this.getFieldExpr(e.fieldExpr(0)),s=this.getFieldExpr(e.fieldExpr(1));if(ue.isEquality(r)){const o=this.rangeFromContext(e);return s instanceof ue.ExprNULL&&(r==="="?this.warnWithReplacement("sql-is-null","Use 'is null' to check for NULL instead of '= null'",o,`${this.getSourceCode(e.fieldExpr(0))} is null`):r==="!="&&this.warnWithReplacement("sql-is-not-null","Use 'is not null' to check for NULL instead of '!= null'",o,`${this.getSourceCode(e.fieldExpr(0))} is not null`)),this.astAt(new ue.ExprEquality(i,r,s),e)}else if(ue.isComparison(r))return this.astAt(new ue.ExprCompare(i,r,s),e);throw this.internalError(e,`untranslatable comparison operator '${r}'`)}visitExprUngroup(e){const r=e.fieldName().map(s=>this.getFieldName(s)),i=e.ungroup().text.toLowerCase();return this.astAt(new ue.ExprUngroup(i==="all"?i:"exclude",this.getFieldExpr(e.fieldExpr()),r),e)}symmetricAggregateUsageError(e){return`Symmetric aggregate function \`${e}\` must be written as \`${e}(expression)\` or \`path.to.field.${e}()\``}asymmetricAggregateUsageError(e){return`Asymmetric aggregate function \`${e}\` must be written as \`path.to.field.${e}()\`, \`path.to.join.${e}(expression)\`, or \`${e}(expression)\``}visitExprAggregate(e){const r=e.fieldPath(),i=this.getFieldPath(r,ue.ExpressionFieldReference),s=r&&i?this.astAt(i,r):void 0,o=e.aggregate().text.toLowerCase(),u=e.fieldExpr();if(e.aggregate().COUNT())return u&&this.contextError(u,"count-expression-with-locality","Expression illegal inside path.count()"),new ue.ExprCount(s);const a=u?this.getFieldExpr(u):void 0;if(o==="min"||o==="max")if(a)this.contextError(e,"invalid-symmetric-aggregate",this.symmetricAggregateUsageError(o));else{const l=this.astAt(new ue.ExprIdReference(i),r);return o==="min"?new ue.ExprMin(l):new ue.ExprMax(l)}else{if(o==="avg")return new ue.ExprAvg(a,s);if(o==="sum")return new ue.ExprSum(a,s);this.contextError(e,"aggregate-parse-error",`Cannot parse aggregate function ${o}`)}return new ue.ExprNULL}visitExprPathlessAggregate(e){const r=e.fieldExpr(),i=r?this.getFieldExpr(r):void 0,s=void 0,o=e.aggregate().text.toLowerCase();if(o==="count")return this.astAt(i?new ue.ExprCountDistinct(i):new ue.ExprCount,e);if(o==="min"){if(i)return new ue.ExprMin(i);this.contextError(e,"invalid-symmetric-aggregate",this.symmetricAggregateUsageError(o))}else if(o==="max"){if(i)return new ue.ExprMax(i);this.contextError(e,"invalid-symmetric-aggregate",this.symmetricAggregateUsageError(o))}else{if(i===void 0)return this.contextError(e,"invalid-asymmetric-aggregate",this.asymmetricAggregateUsageError(o)),new ue.ExprNULL;const u=e.SOURCE_KW()!==void 0;if(o==="avg")return new ue.ExprAvg(i,s,u);if(o==="sum")return new ue.ExprSum(i,s,u)}return new ue.ExprNULL}visitExprApply(e){return new ue.Apply(this.getFieldExpr(e.fieldExpr()),this.getFieldExpr(e.partialAllowedFieldExpr()))}visitExprRange(e){return new ue.Range(this.getFieldExpr(e.fieldExpr(0)),this.getFieldExpr(e.fieldExpr(1)))}visitExprCast(e){const r=this.getMalloyOrSQLType(e.malloyOrSQLType());return new ue.ExprCast(this.getFieldExpr(e.fieldExpr()),r)}getMalloyType(e){const r=e.text;if((0,dR.isCastType)(r))return r;throw this.internalError(e,`unknown type '${r}'`)}getMalloyOrSQLType(e){const r=e.malloyType();if(r)return this.getMalloyType(r);const i=e.string();if(i)return{raw:this.getPlainStringFrom({string:()=>i})};throw this.internalError(e,"Expected Malloy or SQL type to either be a Malloy type or a string")}visitExprSafeCast(e){const r=this.getMalloyOrSQLType(e.malloyOrSQLType());return new ue.ExprCast(this.getFieldExpr(e.fieldExpr()),r,!0)}visitExprTimeTrunc(e){return new ue.ExprGranularTime(this.getFieldExpr(e.fieldExpr()),this.visitTimeframe(e.timeframe()).text,!0)}visitTimeframe(e){return new ue.Timeframe(e.text)}visitExprForRange(e){const r=this.getFieldExpr(e._startAt),i=this.getFieldExpr(e._duration),s=this.visitTimeframe(e.timeframe());return new ue.ForRange(r,i,s)}visitExprAggFunc(e){const r=e.argumentList(),i=r?this.allFieldExpressions(r.fieldExpr()):[],s=(0,Xn.getId)(e),o=e.fieldPath(),u=o?this.getFieldPath(o,ue.ExpressionFieldReference):void 0,a=o&&u?this.astAt(u,o):void 0;return ue.ExprTimeExtract.extractor(s)?this.astAt(new ue.ExprTimeExtract(s,i),e):this.astAt(new ue.ExprFunc(s,i,!1,void 0,a),e)}visitExprFunc(e){var r,i;const s=e.argumentList(),o=s?this.allFieldExpressions(s.fieldExpr()):[],u=e.EXCLAM()!==void 0,a=(r=e.malloyType())===null||r===void 0?void 0:r.text;let l;a&&((0,dR.isCastType)(a)?l=a:(this.contextError(e,"unexpected-malloy-type",`'#' assertion for unknown type '${a}'`),l=void 0));let c=(0,Xn.getOptionalId)(e)||((i=e.timeframe())===null||i===void 0?void 0:i.text);return c===void 0&&(this.contextError(e,"failed-to-parse-function-name","Function name error"),c="FUNCTION_NAME_ERROR"),ue.ExprTimeExtract.extractor(c)?this.astAt(new ue.ExprTimeExtract(c,o),e):this.astAt(new ue.ExprFunc(c,o,u,l),e)}visitExprDuration(e){return new ue.ExprDuration(this.getFieldExpr(e.fieldExpr()),this.visitTimeframe(e.timeframe()).text)}visitCaseStatement(e){const r=e._valueExpr,i=r?this.getFieldExpr(r):void 0,s=e.caseWhen(),o=s.map(l=>new ue.CaseWhen(this.getFieldExpr(l._condition),this.getFieldExpr(l._result))),u=e._caseElse,a=u?this.getFieldExpr(u):void 0;return this.warnWithReplacement("sql-case","Use a `pick` statement instead of `case`",this.rangeFromContext(e),`${[...r?[`${this.getSourceCode(r)} ?`]:[],...s.map(l=>`pick ${this.getSourceCode(l._result)} when ${this.getSourceCode(l._condition)}`),u?`else ${u.text}`:"else null"].join(" ")}`),new ue.Case(i,o,a)}visitPickStatement(e){const r=e.pick().map(i=>{let s;return i._pickValue&&(s=this.getFieldExpr(i._pickValue)),new ue.PickWhen(s,this.getFieldExpr(i._pickWhen))});return e.ELSE()?new ue.Pick(r,this.getFieldExpr(e._pickElse)):new ue.Pick(r)}visitExprFieldProps(e){const r=this.only(e.fieldProperties().fieldPropertyStatement().map(i=>this.visit(i)),i=>ue.isFieldPropStatement(i)&&i,"field property statement");return new ue.ExprProps(this.getFieldExpr(e.fieldExpr()),r)}visitPartitionByStatement(e){return this.astAt(new ue.PartitionBy(e.id().map(r=>this.astAt(new ue.PartitionByFieldReference([this.astAt(new ue.FieldName((0,Xn.idToStr)(r)),r)]),r))),e)}visitLiteralTimestamp(e){return this.parseTime(e,ue.LiteralTimestamp.parse)}visitLiteralHour(e){return this.parseTime(e,ue.LiteralHour.parse)}visitLiteralDay(e){return this.parseTime(e,ue.LiteralDay.parse)}visitLiteralWeek(e){return this.parseTime(e,ue.LiteralWeek.parse)}visitLiteralMonth(e){return this.parseTime(e,ue.LiteralMonth.parse)}visitLiteralQuarter(e){return this.parseTime(e,ue.LiteralQuarter.parse)}visitLiteralYear(e){return this.parseTime(e,ue.LiteralYear.parse)}visitImportStatement(e){const r=this.getPlainStringFrom(e.importURL()),i=this.astAt(new ue.ImportStatement(r,this.parseInfo.importBaseURL),e),s=e.importSelect();if(s)for(const o of s.importItem()){const u=o.id(),a=u[1]?this.astAt(new ue.ImportSourceName((0,Xn.idToStr)(u[1])),u[1]):void 0;i.push(this.astAt(new ue.ImportSelect((0,Xn.idToStr)(u[0]),a),u[0]))}return i}visitDebugExpr(e){return this.getFieldExpr(e.fieldExpr())}visitSampleStatement(e){const r=e.sampleSpec().INTEGER_LITERAL();if(r)return new ue.SampleProperty({rows:this.getNumber(r)});const i=e.sampleSpec().PERCENT_LITERAL();if(i)return new ue.SampleProperty({percent:this.getNumber(i)});const s=e.sampleSpec().TRUE()!==void 0;return new ue.SampleProperty({enable:s})}visitDocAnnotations(e){const r=e.DOC_ANNOTATION().map(s=>({text:s.text,at:this.getLocation(e)})),i=new ue.ModelAnnotation(r);return this.compilerFlags=i.getCompilerFlags(this.compilerFlags,this.msgLog),i}visitIgnoredObjectAnnotations(e){return this.contextError(e,"orphaned-object-annotation","Object annotation not connected to any object"),new Mk(e.text)}visitIgnoredModelAnnotations(e){return this.contextError(e,"misplaced-model-annotation","Model annotations not allowed at this scope"),new Mk(e.text)}visitDefExploreAnnotation(e){const r=this.getNotes(e);return new ue.ObjectAnnotation(r)}getSQArgument(e){const r=e.argumentId(),i=r?this.astAt(new ue.PartitionByFieldReference([this.astAt(new ue.FieldName((0,Xn.idToStr)(r.id())),r)]),r):void 0;return this.astAt(new ue.Argument({id:i,value:this.getFieldExpr(e.fieldExpr())}),e)}getSQArguments(e){if(e!==void 0)return this.inExperiment("parameters",e),e.sourceArgument().map(r=>this.getSQArgument(r))}visitSQID(e){const r=this.getModelEntryName(e),i=this.getSQArguments(e.sourceArguments());return this.astAt(new ue.SQReference(r,i),e.id())}getSqExpr(e){const r=this.visit(e);return r instanceof ue.SourceQueryElement?r:(this.contextError(e,"unexpected-non-source-query-expression-node",`Expected a source/query expression, not '${r.elementType}'`),new Hce)}visitSQExtendedSource(e){const r=this.getSqExpr(e.sqExpr()),i=e.includeBlock(),s=i?this.getIncludeItems(i):void 0,o=new ue.SQExtend(r,this.getSourceExtensions(e.exploreProperties()),s);return this.astAt(o,e)}getIncludeItems(e){return this.inExperiment("access_modifiers",e),e.includeItem().map(r=>this.getIncludeItem(r)).filter(qce.isNotUndefined)}getIncludeItem(e){var r;const i=e.tags(),s=i?this.getNotes(i):[],o=e.includeExceptList();if(o){i&&s.length>0&&this.contextError(i,"cannot-tag-include-except","Tags on `except:` are ignored",{severity:"warn"});const u=this.getExcludeList(o);return this.astAt(new ue.IncludeExceptItem(u),e)}else{const u=e.includeList();if(u===void 0){this.contextError((r=e.orphanedAnnotation())!==null&&r!==void 0?r:e,"orphaned-object-annotation","This tag is not attached to anything",{severity:"warn"});return}const a=this.getAccessLabelProp(e.accessLabelProp()),l=this.getIncludeList(u),c=this.astAt(new ue.IncludeAccessItem(a,l),e);return c.extendNote({blockNotes:s}),c}}getIncludeList(e){const r=e.includeField();if(r===void 0)throw this.internalError(e,"Expected a field name list");return r.map(i=>this.getIncludeListItem(i))}getExcludeList(e){return e.includeExceptListItem().map(r=>{r.tags().ANNOTATION().length>0&&this.contextError(r.tags(),"cannot-tag-include-except","Tags on `except:` are ignored",{severity:"warn"});const i=r.fieldName();if(i)return this.astAt(new ue.AccessModifierFieldReference([this.astAt(this.getFieldName(i),r)]),i);const s=r.collectionWildCard();if(s)return this.astAt(this.visitCollectionWildCard(s),s);throw this.internalError(r,"Expected a field name or wildcard")})}getIncludeListItem(e){const r=e.collectionWildCard(),i=r?this.visitCollectionWildCard(r):void 0,s=e._as?e._as.text:void 0,o=e.tags(),u=o?this.getNotes(o):[],a=e.isDefine(),l=a?this.getIsNotes(a):[],c=[...u,...l],f=e._name?this.astAt(new ue.AccessModifierFieldReference([this.astAt(this.getFieldName(e._name),e._name)]),e._name):void 0,x=f??i;if(x===void 0)throw this.internalError(e,"Expected a field name or wildcard");const h=this.astAt(new ue.IncludeListItem(x,s),e);return h.extendNote({notes:c}),h}visitSQParens(e){const r=this.getSqExpr(e.sqExpr());return this.astAt(r,e)}visitSQCompose(e){const r=e.sqExpr().map(i=>this.getSqExpr(i));return this.inExperiment("composite_sources",e),this.astAt(new ue.SQCompose(r),e)}visitSQArrow(e){const r=this.getSqExpr(e.sqExpr()),i=e.segExpr(),s=new ue.SQArrow(r,this.getVExpr(i));return this.astAt(s,e)}getVExpr(e){const r=this.visit(e);if(r instanceof ue.View)return r;throw this.internalError(e,`Expected view, got a '${r.elementType}'`)}visitSegField(e){return new ue.ReferenceView(this.getFieldPath(e.fieldPath(),ue.ViewOrScalarFieldReference))}visitSegOps(e){return new ue.QOpDescView(this.visitQueryProperties(e.queryProperties()))}visitSegParen(e){return this.visit(e.vExpr())}visitVSeg(e){return this.visit(e.segExpr())}visitSegRefine(e){return new ue.ViewRefine(this.getVExpr(e._lhs),this.getVExpr(e._rhs))}visitVArrow(e){return new ue.ViewArrow(this.getVExpr(e._lhs),this.getVExpr(e._rhs))}visitSQRefinedQuery(e){const r=this.getSqExpr(e.sqExpr()),i=e.segExpr(),s=new ue.SQRefine(r,this.getVExpr(i));return this.astAt(s,e)}visitSQTable(e){const r=this.visit(e.exploreTable());if(r instanceof pdt.TableSource){const i=new ue.SQSource(r);return this.astAt(i,e)}return new Hce}visitSQSQL(e){const r=new ue.SQSource(this.visitSqlSource(e.sqlSource()));return this.astAt(r,e)}visitExperimentalStatementForTesting(e){return this.inExperiment("compilerTestExperimentParse",e),this.astAt(new ue.ExperimentalExperiment("compilerTestExperimentTranslate"),e)}visitRecordRef(e){const r=new ue.ExprIdReference(this.getFieldPath(e.fieldPath(),ue.ExpressionFieldReference));return this.astAt(new ue.RecordElement({path:r}),e)}visitRecordExpr(e){const r=this.getFieldExpr(e.fieldExpr()),i=e.recordKey(),s=i?{key:(0,Xn.getId)(i),value:r}:{value:r};return this.astAt(new ue.RecordElement(s),e)}visitExprLiteralRecord(e){const r=this.only(e.recordElement().map(i=>this.astAt(this.visit(i),i)),i=>i instanceof ue.RecordElement&&i,"a legal record property description");return new ue.RecordLiteral(r)}visitExprArrayLiteral(e){const r=e.fieldExpr().map(s=>this.getFieldExpr(s)),i=new ue.ArrayLiteral(r);return this.astAt(i,e)}visitExprWarnLike(e){let r="~";const i=e.fieldExpr(0),s=e.fieldExpr(1),o=this.rangeFromContext(e);return e.NOT()?(r="!~",this.warnWithReplacement("sql-not-like","Use Malloy operator '!~' instead of 'NOT LIKE'",o,`${this.getSourceCode(i)} !~ ${this.getSourceCode(s)}`)):this.warnWithReplacement("sql-like","Use Malloy operator '~' instead of 'LIKE'",o,`${this.getSourceCode(i)} ~ ${this.getSourceCode(s)}`),this.astAt(new ue.ExprCompare(this.getFieldExpr(i),r,this.getFieldExpr(s)),e)}visitExprNullCheck(e){const r=e.fieldExpr();return this.astAt(new ue.ExprIsNull(this.getFieldExpr(r),e.NOT()?"!=":"="),e)}visitExprWarnIn(e){const r=this.getFieldExpr(e.fieldExpr()),i=!!e.NOT(),s=e.fieldExprList().fieldExpr(),o=this.astAt(new ue.ExprLegacyIn(r,i,s.map(u=>this.getFieldExpr(u))),e);return this.warnWithReplacement("sql-in",`Use = (a|b|c) instead of${i?" NOT":""} IN (a,b,c)`,this.rangeFromContext(e),`${this.getSourceCode(e.fieldExpr())} ${i?"!=":"="} (${s.map(u=>this.getSourceCode(u)).join(" | ")})`),o}visitTickFilterString(e){const r=e.text.slice(1).trimStart();if(r[r.length-1]===`
|
|
1557
|
+
`){const u=r[0]==="'"?'"':"'";this.contextError(e,"literal-string-newline",`Missing $${u}${r[0]}${u} before end-of-line`)}const s=r.slice(1,-1),o=new ue.ExprFilterExpression(s);return this.astAt(o,e)}visitTripFilterString(e){const i=e.text.slice(1).trimStart().slice(3,-3),s=new ue.ExprFilterExpression(i);return this.astAt(s,e)}}xR.MalloyToAST=Edt;var hR={};Object.defineProperty(hR,"__esModule",{value:!0}),hR.Zone=void 0;class Adt{constructor(){this.location={},this.zone=new Map}get(e){const r=this.zone.get(e);if((r==null?void 0:r.status)==="present")return r.value}getEntry(e){const r=this.zone.get(e);return r?r.firstReference||!this.location[e]?r:{...r,firstReference:this.location[e]}:{status:"error",message:"import reference failure"}}define(e,r){this.zone.set(e,{status:"present",value:r})}reference(e,r){const i=this.zone.get(e);(i==null?void 0:i.status)===void 0&&(this.zone.set(e,{status:"reference",firstReference:r}),this.location[e]=r)}getUndefined(){const e=[];for(const[r,i]of this.zone)i.status==="reference"&&e.push(r);return e.length>0?e:void 0}updateFrom(e,r){if(e)for(const[i,s]of Object.entries(e))s!==void 0&&this.define(i,s);if(r)for(const[i,s]of Object.entries(r))this.zone.set(i,{status:"error",message:s})}}hR.Zone=Adt;var pR={};Object.defineProperty(pR,"__esModule",{value:!0}),pR.walkForDocumentSymbols=void 0;const _dt=T0,vdt=Pn;class Cdt{constructor(e,r,i,s){this.translator=e,this.tokens=r,this.scopes=i,this.symbols=s}popScope(){return this.scopes.pop()}peekScope(){return this.scopes[this.scopes.length-1]}enterTopLevelQueryDefs(e){const r=this.translator.rangeFromContext(e);e.topLevelQueryDef().length===1&&(this.blockRange=r)}enterTopLevelQueryDef(e){this.symbols.push({range:this.translator.rangeFromContext(e),name:e.queryName().text,type:"query",children:[],lensRange:this.blockRange}),this.blockRange=void 0}enterRunStatement(e){this.symbols.push({range:this.translator.rangeFromContext(e.topLevelAnonQueryDef()),name:"unnamed_query",type:"unnamed_query",children:[],lensRange:this.translator.rangeFromContext(e)})}enterDefineSourceStatement(e){const r=this.translator.rangeFromContext(e);e.sourcePropertyList().sourceDefinition().length===1&&(this.blockRange=r)}enterSourceDefinition(e){const r=this.translator.rangeFromContext(e);this.scopes.push({range:r,name:e.sourceNameDef().id().text,type:"explore",children:[],lensRange:this.blockRange}),this.blockRange=void 0}exitSourceDefinition(e){const r=this.popScope();r&&this.symbols.push(r)}enterDefExploreQuery(e){const r=this.translator.rangeFromContext(e);e.subQueryDefList().exploreQueryDef().length===1&&(this.blockRange=r)}enterExploreQueryDef(e){const r={range:this.translator.rangeFromContext(e),name:e.exploreQueryNameDef().id().text,type:"query",children:[],lensRange:this.blockRange},i=this.peekScope();i&&i.children.push(r),this.scopes.push(r),this.blockRange=void 0}exitExploreQueryDef(e){this.popScope()}getNestDefName(e){const r=e.queryName();if(r)return r.id().text;let i,s=!1;const o={enterVArrow(a){a.vExpr().enterRule(o)},enterVSeg(a){a.segExpr().enterRule(u)}},u={enterSegField(a){const l=a.fieldPath().fieldName();s||(i??(i=l[l.length-1].id().text))},enterSegParen(a){a.vExpr().enterRule(o)},enterSegRefine(a){a._lhs.enterRule(u)},enterSegOps(){i=void 0,s=!0}};return e.vExpr().enterRule(o),i}handleNestEntry(e){const r=this.getNestDefName(e);if(r===void 0)return;const i={range:this.translator.rangeFromContext(e),name:r,type:"query",children:[]},s=this.peekScope();return s&&s.children.push(i),i}enterNestDef(e){const r=this.handleNestEntry(e);r&&this.scopes.push(r)}exitNestDef(e){this.popScope()}enterFieldDef(e){const r={range:this.translator.rangeFromContext(e),name:e.fieldNameDef().id().text,type:"field",children:[]},i=this.peekScope();i&&i.children.push(r)}enterQueryFieldEntry(e){var r;const i=(r=e.taggedRef())===null||r===void 0?void 0:r.fieldPath();if(i===void 0)return;const s={range:this.translator.rangeFromContext(e),name:i.text,type:"field",children:[]},o=this.peekScope();o&&o.children.push(s)}enterExploreRenameDef(e){const r={range:this.translator.rangeFromContext(e),name:e.fieldName()[0].text,type:"field",children:[]},i=this.peekScope();i&&i.children.push(r)}enterJoinWith(e){this.handleJoinDef(e)}enterJoinOn(e){this.handleJoinDef(e)}handleJoinDef(e){const r={range:this.translator.rangeFromContext(e),name:e.joinFrom().joinNameDef().id().text,type:"join",children:[]},i=this.peekScope();i&&i.children.push(r)}enterImportStatement(e){const r=(0,vdt.getStringIfShort)(e.importURL());r&&this.scopes.push({range:this.translator.rangeFromContext(e),name:r,type:"import",children:[]})}exitImportStatement(){const e=this.popScope();e&&this.symbols.push(e)}enterImportSelect(e){const r=this.peekScope();if(r)for(const i of e.importItem()){const s={range:this.translator.rangeFromContext(e),name:i.text,type:"import_item",children:[]};r.children.push(s)}}}function Sdt(t,e,r){const i=new Cdt(t,e,[],[]),s=i;return _dt.ParseTreeWalker.DEFAULT.walk(s,r),i.symbols}pR.walkForDocumentSymbols=Sdt;var mR={};Object.defineProperty(mR,"__esModule",{value:!0}),mR.walkForDocumentCompletions=void 0;const bdt=T0,Tdt=["dimension","measure","join_one","join_many","join_cross","where","primary_key","rename","accept","except","query","declare"],Rdt=["group_by","project","index","aggregate","top","limit","order_by","where","having","nest","declare"],Ddt=["source","explore","query","sql"];class Odt{constructor(e,r,i){this.tokens=e,this.completions=r,this.position=i}rangeOf(e){const r=e.stop||e.start;return{start:{line:e.start.line-1,character:e.start.charPositionInLine},end:{line:r.line-1,character:r.stopIndex-(r.startIndex-r.charPositionInLine)+1}}}inRange(e){const{start:r,end:i}=e,s=this.position.line>r.line||this.position.line===r.line&&this.position.character>=r.character,o=this.position.line<i.line||this.position.line===i.line&&this.position.character<=i.character;return s&&o}enterExploreProperties(e){if(this.inRange(this.rangeOf(e))){let r=!1;for(const i of e.exploreStatement())this.inRange(this.rangeOf(i))&&(r=!0);if(!r)for(const i of Tdt)this.completions.push({type:"explore_property",text:`${i}: `})}}enterQueryProperties(e){if(this.inRange(this.rangeOf(e))){let r=!1;for(const i of e.queryStatement())this.inRange(this.rangeOf(i))&&(r=!0);if(!r)for(const i of Rdt)this.completions.push({type:"query_property",text:`${i}: `})}}enterMalloyDocument(e){if(this.inRange(this.rangeOf(e))){let r=!1;for(const i of e.malloyStatement())this.inRange(this.rangeOf(i))&&(r=!0);if(!r)for(const i of Ddt)this.completions.push({type:"model_property",text:`${i}: `})}}}function Fdt(t,e,r){const i=new Odt(t,[],r),s=i;return bdt.ParseTreeWalker.DEFAULT.walk(s,e),i.completions}mR.walkForDocumentCompletions=Fdt;var gR={};Object.defineProperty(gR,"__esModule",{value:!0}),gR.walkForDocumentHelpContext=void 0;const wdt=s6;class Ndt extends wdt.AbstractParseTreeVisitor{constructor(e){super(),this.position=e,this.type=""}rangeOf(e){const r=e.stop||e.start;return{start:{line:e.start.line-1,character:e.start.charPositionInLine},end:{line:r.line-1,character:r.stopIndex-(r.startIndex-r.charPositionInLine)+1}}}inRange(e){return e.start.line<=this.position.line&&e.end.line>=this.position.line&&(this.position.line!==e.start.line||this.position.character>=e.start.character)&&(this.position.line!==e.end.line||this.position.character<=e.end.character)}defaultResult(){}visitChildren(e){let r=this.defaultResult();if(this.inRange(this.rangeOf(e))){r={type:this.type,token:e.start.text};const i=e.childCount;for(let s=0;s<i;s++){const u=e.getChild(s).accept(this);u&&(r=this.aggregateResult(r,u))}}return r}visitMalloyDocument(e){return this.inRange(this.rangeOf(e))?(this.type="model_property",this.visitChildren(e)):this.defaultResult()}visitExploreProperties(e){return this.inRange(this.rangeOf(e))?(this.type="explore_property",this.visitChildren(e)):this.defaultResult()}visitQueryProperties(e){return this.inRange(this.rangeOf(e))?(this.type="query_property",this.visitChildren(e)):this.defaultResult()}aggregateResult(e,r){return r}}function Ldt(t,e){return new Ndt(e).visit(t)}gR.walkForDocumentHelpContext=Ldt;var yR={};Object.defineProperty(yR,"__esModule",{value:!0}),yR.ReferenceList=void 0;const Idt=Jn;class $dt{constructor(e){this.sourceURL=e,this.references=[]}findIndexBefore(e){let r=0,i=this.references.length;for(;r<i;){const s=Math.floor((r+i)/2),o=this.references[s].location.range.end;o.line<e.line||o.line===e.line&&o.character<e.character?r=s+1:i=s}return r}add(e){if(e.location.url!==this.sourceURL)return;const r=this.findIndexBefore(e.location.range.end);r<this.references.length&&this.isPositionEqual(e,this.references[r])||this.references.splice(r,0,e)}isPositionEqual(e,r){const i=e.location.range,s=r.location.range;return i.start.line===s.start.line&&i.start.character===s.start.character&&i.end.line===s.end.line&&i.end.character===s.end.character}find(e){const r=this.findIndexBefore(e);if(r===this.references.length)return;const i=this.references[r];if((0,Idt.locationContainsPosition)(i.location,e))return i}}yR.ReferenceList=$dt;var ER={};Object.defineProperty(ER,"__esModule",{value:!0}),ER.isNeedResponse=void 0;function Bdt(t){return!!t&&(t.tables||t.urls||t.compileSQL)!==void 0}ER.isNeedResponse=Bdt;var AR={};Object.defineProperty(AR,"__esModule",{value:!0}),AR.walkForModelAnnotation=void 0;const kdt=T0;class Mdt{constructor(e,r,i){this.translator=e,this.tokens=r,this.parseInfo=i,this.notes=[]}getLocation(e){return{url:this.parseInfo.sourceURL,range:this.translator.rangeFromContext(e)}}enterDocAnnotations(e){const r=e.DOC_ANNOTATION().map(i=>({text:i.text,at:this.getLocation(e)}));this.notes.push(...r)}get annotation(){return{notes:this.notes}}}function Pdt(t,e,r){const i=new Mdt(t,e,r),s=i;return kdt.ParseTreeWalker.DEFAULT.walk(s,r.root),i.annotation}AR.walkForModelAnnotation=Pdt;var _R={};Object.defineProperty(_R,"__esModule",{value:!0}),_R.walkForTablePath=void 0;const Qce=Pn,Udt=T0;class jdt{constructor(e,r){this.translator=e,this.tokens=r,this.pathInfos=[]}enterExploreTable(e){const r=(0,Qce.getId)(e.connectionId()),[i,s]=(0,Qce.getPlainString)(e.tablePath(),!0);i!==void 0&&this.pathInfos.push({connectionId:r,tablePath:i,range:this.translator.rangeFromContext(e)})}}function qdt(t,e,r){const i=new jdt(t,e),s=i;return Udt.ParseTreeWalker.DEFAULT.walk(s,r.root),i.pathInfos}_R.walkForTablePath=qdt;var UE={},vR={},Hdt=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),Qdt=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),zdt=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&Hdt(e,t,r);return Qdt(e,t),e};Object.defineProperty(vR,"__esModule",{value:!0}),vR.MalloyLexer=void 0;const Wdt=ph(),Gdt=xl(),Vdt=P1(),Ydt=Ts,zce=zdt(Cn);class ae extends Gdt.Lexer{get vocabulary(){return ae.VOCABULARY}constructor(e){super(e),this._interp=new Vdt.LexerATNSimulator(ae._ATN,this)}get grammarFileName(){return"MalloyLexer.g4"}get ruleNames(){return ae.ruleNames}get serializedATN(){return ae._serializedATN}get channelNames(){return ae.channelNames}get modeNames(){return ae.modeNames}static get _ATN(){return ae.__ATN||(ae.__ATN=new Wdt.ATNDeserializer().deserialize(zce.toCharArray(ae._serializedATN))),ae.__ATN}}vR.MalloyLexer=ae,ae.ACCEPT=1,ae.AGGREGATE=2,ae.CALCULATE=3,ae.CALCULATION=4,ae.CONNECTION=5,ae.DECLARE=6,ae.DIMENSION=7,ae.EXCEPT=8,ae.EXTENDQ=9,ae.GROUP_BY=10,ae.HAVING=11,ae.INDEX=12,ae.INTERNAL=13,ae.JOIN_CROSS=14,ae.JOIN_ONE=15,ae.JOIN_MANY=16,ae.LIMIT=17,ae.MEASURE=18,ae.NEST=19,ae.ORDER_BY=20,ae.PARTITION_BY=21,ae.PRIMARY_KEY=22,ae.PRIVATE=23,ae.PROJECT=24,ae.PUBLIC=25,ae.QUERY=26,ae.RENAME=27,ae.RUN=28,ae.SAMPLE=29,ae.SELECT=30,ae.SOURCE=31,ae.TOP=32,ae.WHERE=33,ae.VIEW=34,ae.TIMEZONE=35,ae.ALL=36,ae.AND=37,ae.AS=38,ae.ASC=39,ae.AVG=40,ae.BOOLEAN=41,ae.BY=42,ae.CASE=43,ae.CAST=44,ae.CONDITION=45,ae.COUNT=46,ae.COMPOSE=47,ae.DATE=48,ae.DAY=49,ae.DESC=50,ae.DISTINCT=51,ae.ELSE=52,ae.END=53,ae.EXCLUDE=54,ae.EXTEND=55,ae.FALSE=56,ae.FILTER=57,ae.FULL=58,ae.FOR=59,ae.FROM=60,ae.HAS=61,ae.HOUR=62,ae.IMPORT=63,ae.INCLUDE=64,ae.INNER=65,ae.IS=66,ae.IN=67,ae.INTERNAL_KW=68,ae.JSON=69,ae.LAST=70,ae.LEFT=71,ae.LIKE=72,ae.MAX=73,ae.MIN=74,ae.MINUTE=75,ae.MONTH=76,ae.NOT=77,ae.NOW=78,ae.NULL=79,ae.NUMBER=80,ae.ON=81,ae.OR=82,ae.PICK=83,ae.PRIVATE_KW=84,ae.PUBLIC_KW=85,ae.QUARTER=86,ae.RIGHT=87,ae.SECOND=88,ae.STRING=89,ae.SOURCE_KW=90,ae.SUM=91,ae.SQL=92,ae.TABLE=93,ae.THEN=94,ae.THIS=95,ae.TIMESTAMP=96,ae.TO=97,ae.TRUE=98,ae.TURTLE=99,ae.WEEK=100,ae.WHEN=101,ae.WITH=102,ae.YEAR=103,ae.UNGROUPED=104,ae.HACKY_REGEX=105,ae.RAW_SQ=106,ae.RAW_DQ=107,ae.SQ3_FILTER=108,ae.SQ_FILTER=109,ae.DQ3_FILTER=110,ae.DQ_FILTER=111,ae.BQ3_FILTER=112,ae.BQ_FILTER=113,ae.SQ_STRING=114,ae.DQ_STRING=115,ae.BQ_STRING=116,ae.DOC_ANNOTATION=117,ae.ANNOTATION=118,ae.AMPER=119,ae.ARROW=120,ae.FAT_ARROW=121,ae.OPAREN=122,ae.CPAREN=123,ae.OBRACK=124,ae.CBRACK=125,ae.OCURLY=126,ae.CCURLY=127,ae.DOUBLECOLON=128,ae.TRIPLECOLON=129,ae.EXCLAM=130,ae.COLON=131,ae.COMMA=132,ae.DOT=133,ae.LT=134,ae.GT=135,ae.EQ=136,ae.NE=137,ae.LTE=138,ae.GTE=139,ae.PLUS=140,ae.MINUS=141,ae.STAR=142,ae.STARSTAR=143,ae.SLASH=144,ae.BAR=145,ae.SEMI=146,ae.NOT_MATCH=147,ae.MATCH=148,ae.PERCENT=149,ae.DOUBLE_QMARK=150,ae.QMARK=151,ae.LITERAL_TIMESTAMP=152,ae.LITERAL_HOUR=153,ae.LITERAL_DAY=154,ae.LITERAL_QUARTER=155,ae.LITERAL_MONTH=156,ae.LITERAL_WEEK=157,ae.LITERAL_YEAR=158,ae.IDENTIFIER=159,ae.PERCENT_LITERAL=160,ae.NUMERIC_LITERAL=161,ae.INTEGER_LITERAL=162,ae.BLOCK_COMMENT=163,ae.COMMENT_TO_EOL=164,ae.WHITE_SPACE=165,ae.SQL_BEGIN=166,ae.UNWATED_CHARS_TRAILING_NUMBERS=167,ae.UNEXPECTED_CHAR=168,ae.OPEN_CODE=169,ae.SQL_END=170,ae.SQL_MODE=1,ae.channelNames=["DEFAULT_TOKEN_CHANNEL","HIDDEN"],ae.modeNames=["DEFAULT_MODE","SQL_MODE"],ae.ruleNames=["SPACE_CHAR","ACCEPT","AGGREGATE","CALCULATE","CALCULATION","CONNECTION","DECLARE","DIMENSION","EXCEPT","EXTENDQ","GROUP_BY","HAVING","INDEX","INTERNAL","JOIN_CROSS","JOIN_ONE","JOIN_MANY","LIMIT","MEASURE","NEST","ORDER_BY","PARTITION_BY","PRIMARY_KEY","PRIVATE","PROJECT","PUBLIC","QUERY","RENAME","RUN","SAMPLE","SELECT","SOURCE","TOP","WHERE","VIEW","TIMEZONE","ALL","AND","AS","ASC","AVG","BOOLEAN","BY","CASE","CAST","CONDITION","COUNT","COMPOSE","DATE","DAY","DESC","DISTINCT","ELSE","END","EXCLUDE","EXTEND","FALSE","FILTER","FULL","FOR","FROM","HAS","HOUR","IMPORT","INCLUDE","INNER","IS","IN","INTERNAL_KW","JSON","LAST","LEFT","LIKE","MAX","MIN","MINUTE","MONTH","NOT","NOW","NULL","NUMBER","ON","OR","PICK","PRIVATE_KW","PUBLIC_KW","QUARTER","RIGHT","SECOND","STRING","SOURCE_KW","SUM","SQL","TABLE","THEN","THIS","TIMESTAMP","TO","TRUE","TURTLE","WEEK","WHEN","WITH","YEAR","UNGROUPED","SQ","BQ","DQ","SQ3","DQ3","BQ3","RAW_CHAR","RAW3_CHAR","F_PREFIX","S_PREFIX","HACKY_REGEX","RAW_SQ","RAW_DQ","SQ3_FILTER","SQ_FILTER","DQ3_FILTER","DQ_FILTER","BQ3_FILTER","BQ_FILTER","HEX","UNICODE","SAFE_NON_QUOTE","ESCAPED","STR_CHAR","SQ_STRING","DQ_STRING","BQ_STRING","F_TO_EOL","DOC_ANNOTATION","ANNOTATION","AMPER","ARROW","FAT_ARROW","OPAREN","CPAREN","OBRACK","CBRACK","OCURLY","CCURLY","DOUBLECOLON","TRIPLECOLON","EXCLAM","COLON","COMMA","DOT","LT","GT","EQ","NE","LTE","GTE","PLUS","MINUS","STAR","STARSTAR","SLASH","BAR","SEMI","NOT_MATCH","MATCH","PERCENT","DOUBLE_QMARK","QMARK","F_YEAR","F_DD","F_TZ","LITERAL_TIMESTAMP","LITERAL_HOUR","LITERAL_DAY","LITERAL_QUARTER","LITERAL_MONTH","LITERAL_WEEK","LITERAL_YEAR","IDENTIFIER","PERCENT_LITERAL","EXPONENT","NUMERIC_LITERAL","INTEGER_LITERAL","ID_CHAR","DIGIT","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","BLOCK_COMMENT","COMMENT_TO_EOL","WHITE_SPACE","SQL_BEGIN","UNWATED_CHARS_TRAILING_NUMBERS","UNEXPECTED_CHAR","SQL_CHAR","OPEN_CODE","SQL_END"],ae._LITERAL_NAMES=[void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,"'&'","'->'","'=>'","'('","')'","'['","']'","'{'","'}'","'::'","':::'","'!'","':'","','","'.'","'<'","'>'","'='","'!='","'<='","'>='","'+'","'-'","'*'","'**'","'/'","'|'","';'","'!~'","'~'","'%'","'??'","'?'",void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,`'"""'`],ae._SYMBOLIC_NAMES=[void 0,"ACCEPT","AGGREGATE","CALCULATE","CALCULATION","CONNECTION","DECLARE","DIMENSION","EXCEPT","EXTENDQ","GROUP_BY","HAVING","INDEX","INTERNAL","JOIN_CROSS","JOIN_ONE","JOIN_MANY","LIMIT","MEASURE","NEST","ORDER_BY","PARTITION_BY","PRIMARY_KEY","PRIVATE","PROJECT","PUBLIC","QUERY","RENAME","RUN","SAMPLE","SELECT","SOURCE","TOP","WHERE","VIEW","TIMEZONE","ALL","AND","AS","ASC","AVG","BOOLEAN","BY","CASE","CAST","CONDITION","COUNT","COMPOSE","DATE","DAY","DESC","DISTINCT","ELSE","END","EXCLUDE","EXTEND","FALSE","FILTER","FULL","FOR","FROM","HAS","HOUR","IMPORT","INCLUDE","INNER","IS","IN","INTERNAL_KW","JSON","LAST","LEFT","LIKE","MAX","MIN","MINUTE","MONTH","NOT","NOW","NULL","NUMBER","ON","OR","PICK","PRIVATE_KW","PUBLIC_KW","QUARTER","RIGHT","SECOND","STRING","SOURCE_KW","SUM","SQL","TABLE","THEN","THIS","TIMESTAMP","TO","TRUE","TURTLE","WEEK","WHEN","WITH","YEAR","UNGROUPED","HACKY_REGEX","RAW_SQ","RAW_DQ","SQ3_FILTER","SQ_FILTER","DQ3_FILTER","DQ_FILTER","BQ3_FILTER","BQ_FILTER","SQ_STRING","DQ_STRING","BQ_STRING","DOC_ANNOTATION","ANNOTATION","AMPER","ARROW","FAT_ARROW","OPAREN","CPAREN","OBRACK","CBRACK","OCURLY","CCURLY","DOUBLECOLON","TRIPLECOLON","EXCLAM","COLON","COMMA","DOT","LT","GT","EQ","NE","LTE","GTE","PLUS","MINUS","STAR","STARSTAR","SLASH","BAR","SEMI","NOT_MATCH","MATCH","PERCENT","DOUBLE_QMARK","QMARK","LITERAL_TIMESTAMP","LITERAL_HOUR","LITERAL_DAY","LITERAL_QUARTER","LITERAL_MONTH","LITERAL_WEEK","LITERAL_YEAR","IDENTIFIER","PERCENT_LITERAL","NUMERIC_LITERAL","INTEGER_LITERAL","BLOCK_COMMENT","COMMENT_TO_EOL","WHITE_SPACE","SQL_BEGIN","UNWATED_CHARS_TRAILING_NUMBERS","UNEXPECTED_CHAR","OPEN_CODE","SQL_END"],ae.VOCABULARY=new Ydt.VocabularyImpl(ae._LITERAL_NAMES,ae._SYMBOLIC_NAMES,[]),ae._serializedATNSegments=4,ae._serializedATNSegment0=`줝쪺֍꾺体؇쉁¬ފ\b\b \x07 \x07\b \b
|
|
1558
1558
|
|
|
1559
1559
|
\v \v\f \f\r \r \x1B \x1B ! !" "# #$ $% %& &' '( () )* *+ +, ,- -. ./ /0 01 12 23 34 45 56 67 78 89 9: :; ;< <= => >? ?@ @A AB BC CD DE EF FG GH HI IJ JK KL LM MN NO OP PQ QR RS ST TU UV VW WX XY YZ Z[ [\\ \\] ]^ ^_ _\` \`a ab bc cd de ef fg gh hi ij jk kl lm mn no op pq qr rs st tu uv vw wx xy yz z{ {| |} }~ ~
¡ ¡¢ ¢£ £¤ ¤¥ ¥¦ ¦§ §¨ ¨© ©ª ª« «¬ ¬ ® ®¯ ¯° °± ±² ²³ ³´ ´µ µ¶ ¶· ·¸ ¸¹ ¹º º» »¼ ¼½ ½¾ ¾¿ ¿À ÀÁ Á Âà ÃÄ ÄÅ ÅÆ ÆÇ ÇÈ ÈÉ ÉÊ ÊË ËÌ ÌÍ ÍÎ ÎÏ ÏÐ ÐÑ ÑÒ ÒÓ ÓÔ ÔÕ ÕÖ Ö× ×Ø ØÙ ÙÚ ÚÛ ÛÜ ÜÝ Ý\x07dž
|
|
1560
1560
|
\flj\v\x07Ǘ
|
|
@@ -1672,7 +1672,7 @@ z\fzzֻ\vzzz{{{\x07{ׂ
|
|
|
1672
1672
|
+ݩݪ\x07$ݪݲ
|
|
1673
1673
|
,ݫݬ\x07$ݬݭ\x07$ݭݮݮݲ
|
|
1674
1674
|
,ݯݰ\x07'ݰݲ
|
|
1675
|
-
-ݱݦݱݨݱݩݱݫݱݯݲƷݳݵƶÛݴݳݵݸݶݷݶݴݷݹݸݶݹݺ\x07'ݺݻ\x07}ݻݼݼݽ\bÜݽƹݾހƶÛݿݾހރށނށݿނބރށބޅ\x07$ޅކ\x07$ކއ\x07$އވވމ\bÝމƻcLJǘǩǼȎȨȶɄɔɢɯɿʛʬʹˈ˔ˤ˸̷̩̋̈́͒ͫ̚͝·ΒΟΫλЉѕҞҦӞӭԳՄեժհշջցֲֹ֣֭֗֜׃ימײ؋؍ؙؕ؝ڃڅښڜڞڡێې۪ۭۖۜۡۤ۲۷ܷ݃ݖݛݟݡݱݶށ\x07\x07\b\x07`,ae._serializedATN=zce.join([ae._serializedATNSegment0,ae._serializedATNSegment1,ae._serializedATNSegment2,ae._serializedATNSegment3],"");var I={},Vdt=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),Ydt=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),Kdt=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&Vdt(e,t,r);return Ydt(e,t),e};Object.defineProperty(I,"__esModule",{value:!0}),I.AccessLabelContext=I.DefIgnoreModel_stubContext=I.DefExploreAnnotationContext=I.DefExploreTimezoneContext=I.DefExploreQueryContext=I.DefExploreEditFieldContext=I.DefExploreRenameContext=I.DefExplorePrimaryKeyContext=I.DefExploreWhere_stubContext=I.DefJoin_stubContext=I.DefExploreMeasure_stubContext=I.DefExploreDimension_stubContext=I.ExploreStatementContext=I.ExplorePropertiesContext=I.SourceNameDefContext=I.ParameterNameDefContext=I.SourceParameterContext=I.LegalParamTypeContext=I.SourceParametersContext=I.SqExploreContext=I.SourceDefinitionContext=I.SourcePropertyListContext=I.QueryNameContext=I.QueryPropertiesContext=I.ConnectionIdContext=I.ExploreTableContext=I.SqlSourceContext=I.TurtleNameContext=I.RefineOperatorContext=I.TopLevelQueryDefContext=I.TopLevelQueryDefsContext=I.IgnoredModelAnnotationsContext=I.IgnoredObjectAnnotationsContext=I.DocAnnotationsContext=I.ImportURLContext=I.ImportItemContext=I.ImportSelectContext=I.ImportStatementContext=I.SqlInterpolationContext=I.SqlStringContext=I.RunStatementContext=I.IsDefineContext=I.TagsContext=I.TopLevelAnonQueryDefContext=I.Use_top_level_query_defsContext=I.DefineQueryContext=I.DefineSourceStatementContext=I.MalloyStatementContext=I.MalloyDocumentContext=I.MalloyParser=void 0,I.MatrixOperationContext=I.IsExploreContext=I.JoinListContext=I.QueryExtendStatementListContext=I.QueryExtendStatementContext=I.VArrowContext=I.VSegContext=I.VExprContext=I.SegRefineContext=I.SegParenContext=I.SegOpsContext=I.SegFieldContext=I.SegExprContext=I.IncludeFieldContext=I.IncludeListContext=I.IncludeExceptListItemContext=I.IncludeExceptListContext=I.AccessLabelPropContext=I.OrphanedAnnotationContext=I.IncludeItemContext=I.IncludeBlockContext=I.SQSQLContext=I.SQTableContext=I.SQIncludeContext=I.SQExtendedSourceContext=I.SQArrowContext=I.SQRefinedQueryContext=I.SQComposeContext=I.SQParensContext=I.SQIDContext=I.SqExprContext=I.SourceArgumentContext=I.ArgumentIdContext=I.SourceArgumentsContext=I.ModEitherContext=I.QueryExtendContext=I.DefJoinCrossContext=I.DefJoinManyContext=I.DefJoinOneContext=I.JoinStatementContext=I.DeclareStatementContext=I.JoinNameDefContext=I.FieldNameDefContext=I.FieldDefContext=I.DefListContext=I.ExploreRenameDefContext=I.RenameListContext=I.DefDimensionsContext=I.DefMeasuresContext=I.AccessModifierListContext=void 0,I.RawStringContext=I.ShortStringContext=I.StringContext=I.CompareOpContext=I.MalloyTypeContext=I.AggregateContext=I.SampleSpecContext=I.QueryAnnotationContext=I.TimezoneStatementContext=I.SampleStatementContext=I.IndexStatementContext=I.IndexFieldsContext=I.IndexElementContext=I.TopStatementContext=I.BySpecContext=I.LimitStatementContext=I.OrderBySpecContext=I.OrderingContext=I.OrderByStatementContext=I.PartitionByStatementContext=I.ProjectStatementContext=I.CalculateStatementContext=I.AggregateStatementContext=I.NestDefContext=I.NestEntryContext=I.NestedQueryListContext=I.NestStatementContext=I.QueryFieldEntryContext=I.QueryFieldListContext=I.GroupByStatementContext=I.QueryJoinStatementContext=I.QueryStatementContext=I.ExploreQueryDefContext=I.ExploreQueryNameDefContext=I.SubQueryDefListContext=I.HavingStatementContext=I.WhereStatementContext=I.FilterClauseListContext=I.FieldPropertyStatementContext=I.FieldPropertyLimitStatementContext=I.AggregateOrderByStatementContext=I.AggregateOrderBySpecContext=I.AggregateOrderingContext=I.FieldPropertiesContext=I.FilterStatementContext=I.JoinExpressionContext=I.JoinOnContext=I.JoinWithContext=I.JoinDefContext=I.JoinFromContext=void 0,I.ExprLogicalOrContext=I.ExprLogicalAndContext=I.ExprNotContext=I.ExprApplyContext=I.ExprWarnInContext=I.ExprNullCheckContext=I.ExprWarnLikeContext=I.ExprCompareContext=I.ExprOrTreeContext=I.ExprAndTreeContext=I.ExprForRangeContext=I.ExprRangeContext=I.ExprAddSubContext=I.ExprMulDivContext=I.ExprMinusContext=I.ExprSafeCastContext=I.ExprCastContext=I.ExprTimeTruncContext=I.ExprDurationContext=I.ExprFieldPropsContext=I.ExprLiteralRecordContext=I.ExprArrayLiteralContext=I.ExprLiteralContext=I.ExprFieldPathContext=I.FieldExprContext=I.MalloyOrSQLTypeContext=I.UngroupContext=I.TimeframeContext=I.IdContext=I.TableURIContext=I.TablePathContext=I.LiteralYearContext=I.LiteralQuarterContext=I.LiteralMonthContext=I.LiteralWeekContext=I.LiteralDayContext=I.LiteralHourContext=I.LiteralTimestampContext=I.DateLiteralContext=I.ExprNowContext=I.FilterString_stubContext=I.ExprRegexContext=I.ExprBoolContext=I.ExprNULLContext=I.ExprTimeContext=I.ExprNumberContext=I.Stub_rawStringContext=I.ExprStringContext=I.LiteralContext=I.NumericLiteralContext=void 0,I.ExperimentalStatementForTestingContext=I.DebugPartialContext=I.DebugExprContext=I.FilterStringContext=I.TickFilterStringContext=I.TripFilterStringContext=I.ConnectionNameContext=I.NameSQLBlockContext=I.SqlExploreNameRefContext=I.FieldNameContext=I.JoinNameContext=I.FieldPathContext=I.CollectionMemberContext=I.RefExprContext=I.TaggedRefContext=I.StarQualifiedContext=I.CollectionWildCardContext=I.FieldCollectionContext=I.FieldNameListContext=I.ArgumentListContext=I.RecordExprContext=I.RecordRefContext=I.RecordElementContext=I.RecordKeyContext=I.CaseWhenContext=I.CaseStatementContext=I.PickContext=I.PickStatementContext=I.FieldExprListContext=I.PartialAllowedFieldExprContext=I.PartialTestContext=I.PartialCompareContext=I.ExprUngroupContext=I.ExprCaseContext=I.ExprPickContext=I.ExprFuncContext=I.ExprAggFuncContext=I.ExprExprContext=I.ExprAggregateContext=I.ExprPathlessAggregateContext=I.ExprCoalesceContext=void 0;const rn=Ho(),Jdt=ph(),Xdt=B0,sn=cm(),Zdt=Eh(),ge=eo(),eht=dh(),ye=Zs,Wn=un,tht=Ts,Wce=Kdt(Cn);class d extends Zdt.Parser{get vocabulary(){return d.VOCABULARY}get grammarFileName(){return"MalloyParser.g4"}get ruleNames(){return d.ruleNames}get serializedATN(){return d._serializedATN}createFailedPredicateException(e,r){return new Xdt.FailedPredicateException(this,e,r)}constructor(e){super(e),this._interp=new eht.ParserATNSimulator(d._ATN,this)}malloyDocument(){let e=new Gce(this._ctx,this.state);this.enterRule(e,0,d.RULE_malloyDocument);let r;try{this.enterOuterAlt(e,1);{for(this.state=316,this._errHandler.sync(this),r=this._input.LA(1);!(r&-32)&&1<<r&(1<<d.AGGREGATE|1<<d.CALCULATE|1<<d.DIMENSION|1<<d.EXCEPT|1<<d.GROUP_BY|1<<d.INTERNAL|1<<d.JOIN_CROSS|1<<d.JOIN_ONE|1<<d.JOIN_MANY|1<<d.MEASURE|1<<d.NEST|1<<d.PRIVATE|1<<d.PUBLIC|1<<d.QUERY|1<<d.RUN|1<<d.SELECT|1<<d.SOURCE)||!(r-34&-32)&&1<<r-34&(1<<d.VIEW-34|1<<d.ALL-34|1<<d.AVG-34|1<<d.CASE-34|1<<d.CAST-34|1<<d.COUNT-34|1<<d.COMPOSE-34|1<<d.DAY-34|1<<d.EXCLUDE-34|1<<d.FALSE-34|1<<d.HOUR-34|1<<d.IMPORT-34)||!(r-66&-32)&&1<<r-66&(1<<d.IS-66|1<<d.INTERNAL_KW-66|1<<d.MAX-66|1<<d.MIN-66|1<<d.MINUTE-66|1<<d.MONTH-66|1<<d.NOT-66|1<<d.NOW-66|1<<d.NULL-66|1<<d.PICK-66|1<<d.PRIVATE_KW-66|1<<d.PUBLIC_KW-66|1<<d.QUARTER-66|1<<d.SECOND-66|1<<d.SOURCE_KW-66|1<<d.SUM-66)||!(r-98&-32)&&1<<r-98&(1<<d.TRUE-98|1<<d.WEEK-98|1<<d.YEAR-98|1<<d.HACKY_REGEX-98|1<<d.RAW_SQ-98|1<<d.RAW_DQ-98|1<<d.SQ3_FILTER-98|1<<d.SQ_FILTER-98|1<<d.DQ3_FILTER-98|1<<d.DQ_FILTER-98|1<<d.BQ3_FILTER-98|1<<d.BQ_FILTER-98|1<<d.SQ_STRING-98|1<<d.DQ_STRING-98|1<<d.BQ_STRING-98|1<<d.DOC_ANNOTATION-98|1<<d.ANNOTATION-98|1<<d.OPAREN-98|1<<d.OBRACK-98|1<<d.OCURLY-98)||!(r-141&-32)&&1<<r-141&(1<<d.MINUS-141|1<<d.STAR-141|1<<d.SEMI-141|1<<d.LITERAL_TIMESTAMP-141|1<<d.LITERAL_HOUR-141|1<<d.LITERAL_DAY-141|1<<d.LITERAL_QUARTER-141|1<<d.LITERAL_MONTH-141|1<<d.LITERAL_WEEK-141|1<<d.LITERAL_YEAR-141|1<<d.IDENTIFIER-141|1<<d.NUMERIC_LITERAL-141|1<<d.INTEGER_LITERAL-141|1<<d.SQL_BEGIN-141);){switch(this.state=314,this._errHandler.sync(this),this.interpreter.adaptivePredict(this._input,0,this._ctx)){case 1:this.state=312,this.malloyStatement();break;case 2:this.state=313,this.match(d.SEMI);break}this.state=318,this._errHandler.sync(this),r=this._input.LA(1)}this.state=319,this.match(d.EOF)}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}malloyStatement(){let e=new CR(this._ctx,this.state);this.enterRule(e,2,d.RULE_malloyStatement);try{switch(this.state=328,this._errHandler.sync(this),this.interpreter.adaptivePredict(this._input,2,this._ctx)){case 1:this.enterOuterAlt(e,1),this.state=321,this.defineSourceStatement();break;case 2:this.enterOuterAlt(e,2),this.state=322,this.defineQuery();break;case 3:this.enterOuterAlt(e,3),this.state=323,this.importStatement();break;case 4:this.enterOuterAlt(e,4),this.state=324,this.runStatement();break;case 5:this.enterOuterAlt(e,5),this.state=325,this.docAnnotations();break;case 6:this.enterOuterAlt(e,6),this.state=326,this.ignoredObjectAnnotations();break;case 7:this.enterOuterAlt(e,7),this.state=327,this.experimentalStatementForTesting();break}}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}defineSourceStatement(){let e=new Pk(this._ctx,this.state);this.enterRule(e,4,d.RULE_defineSourceStatement);try{this.enterOuterAlt(e,1),this.state=330,this.tags(),this.state=331,this.match(d.SOURCE),this.state=332,this.sourcePropertyList()}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}defineQuery(){let e=new SR(this._ctx,this.state);this.enterRule(e,6,d.RULE_defineQuery);try{e=new Vce(e),this.enterOuterAlt(e,1),this.state=334,this.topLevelQueryDefs()}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}topLevelAnonQueryDef(){let e=new Uk(this._ctx,this.state);this.enterRule(e,8,d.RULE_topLevelAnonQueryDef);try{this.enterOuterAlt(e,1),this.state=336,this.tags(),this.state=337,this.sqExpr(0)}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}tags(){let e=new Xt(this._ctx,this.state);this.enterRule(e,10,d.RULE_tags);let r;try{for(this.enterOuterAlt(e,1),this.state=342,this._errHandler.sync(this),r=this._input.LA(1);r===d.ANNOTATION;)this.state=339,this.match(d.ANNOTATION),this.state=344,this._errHandler.sync(this),r=this._input.LA(1)}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}isDefine(){let e=new v0(this._ctx,this.state);this.enterRule(e,12,d.RULE_isDefine);try{this.enterOuterAlt(e,1),this.state=345,e._beforeIs=this.tags(),this.state=346,this.match(d.IS),this.state=347,e._afterIs=this.tags()}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}runStatement(){let e=new jk(this._ctx,this.state);this.enterRule(e,14,d.RULE_runStatement);try{this.enterOuterAlt(e,1),this.state=349,this.tags(),this.state=350,this.match(d.RUN),this.state=351,this.topLevelAnonQueryDef()}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}sqlString(){let e=new bR(this._ctx,this.state);this.enterRule(e,16,d.RULE_sqlString);let r;try{this.enterOuterAlt(e,1);{for(this.state=353,this.match(d.SQL_BEGIN),this.state=357,this._errHandler.sync(this),r=this._input.LA(1);r===d.OPEN_CODE;)this.state=354,this.sqlInterpolation(),this.state=359,this._errHandler.sync(this),r=this._input.LA(1);this.state=360,this.match(d.SQL_END)}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}sqlInterpolation(){let e=new TR(this._ctx,this.state);this.enterRule(e,18,d.RULE_sqlInterpolation);try{this.enterOuterAlt(e,1),this.state=362,this.match(d.OPEN_CODE),this.state=363,this.sqExpr(0),this.state=364,this.match(d.CCURLY)}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}importStatement(){let e=new qk(this._ctx,this.state);this.enterRule(e,20,d.RULE_importStatement);let r;try{this.enterOuterAlt(e,1),this.state=366,this.match(d.IMPORT),this.state=368,this._errHandler.sync(this),r=this._input.LA(1),r===d.OCURLY&&(this.state=367,this.importSelect()),this.state=370,this.importURL()}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}importSelect(){let e=new Hk(this._ctx,this.state);this.enterRule(e,22,d.RULE_importSelect);let r;try{this.enterOuterAlt(e,1);{for(this.state=372,this.match(d.OCURLY),this.state=373,this.importItem(),this.state=378,this._errHandler.sync(this),r=this._input.LA(1);r===d.COMMA;)this.state=374,this.match(d.COMMA),this.state=375,this.importItem(),this.state=380,this._errHandler.sync(this),r=this._input.LA(1);this.state=381,this.match(d.CCURLY),this.state=382,this.match(d.FROM)}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}importItem(){let e=new RR(this._ctx,this.state);this.enterRule(e,24,d.RULE_importItem);let r;try{this.enterOuterAlt(e,1),this.state=384,this.id(),this.state=387,this._errHandler.sync(this),r=this._input.LA(1),r===d.IS&&(this.state=385,this.match(d.IS),this.state=386,this.id())}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}importURL(){let e=new Qk(this._ctx,this.state);this.enterRule(e,26,d.RULE_importURL);try{this.enterOuterAlt(e,1),this.state=389,this.string()}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}docAnnotations(){let e=new zk(this._ctx,this.state);this.enterRule(e,28,d.RULE_docAnnotations);try{let r;this.enterOuterAlt(e,1);{this.state=392,this._errHandler.sync(this),r=1;do{switch(r){case 1:this.state=391,this.match(d.DOC_ANNOTATION);break;default:throw new sn.NoViableAltException(this)}this.state=394,this._errHandler.sync(this),r=this.interpreter.adaptivePredict(this._input,8,this._ctx)}while(r!==2&&r!==rn.ATN.INVALID_ALT_NUMBER)}}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}ignoredObjectAnnotations(){let e=new Wk(this._ctx,this.state);this.enterRule(e,30,d.RULE_ignoredObjectAnnotations);try{let r;this.enterOuterAlt(e,1);{this.state=397,this._errHandler.sync(this),r=1;do{switch(r){case 1:this.state=396,this.match(d.ANNOTATION);break;default:throw new sn.NoViableAltException(this)}this.state=399,this._errHandler.sync(this),r=this.interpreter.adaptivePredict(this._input,9,this._ctx)}while(r!==2&&r!==rn.ATN.INVALID_ALT_NUMBER)}}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}ignoredModelAnnotations(){let e=new DR(this._ctx,this.state);this.enterRule(e,32,d.RULE_ignoredModelAnnotations);try{let r;this.enterOuterAlt(e,1);{this.state=402,this._errHandler.sync(this),r=1;do{switch(r){case 1:this.state=401,this.match(d.DOC_ANNOTATION);break;default:throw new sn.NoViableAltException(this)}this.state=404,this._errHandler.sync(this),r=this.interpreter.adaptivePredict(this._input,10,this._ctx)}while(r!==2&&r!==rn.ATN.INVALID_ALT_NUMBER)}}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}topLevelQueryDefs(){let e=new Gk(this._ctx,this.state);this.enterRule(e,34,d.RULE_topLevelQueryDefs);let r;try{let i;this.enterOuterAlt(e,1);{for(this.state=406,this.tags(),this.state=407,this.match(d.QUERY),this.state=408,this.topLevelQueryDef(),this.state=415,this._errHandler.sync(this),i=this.interpreter.adaptivePredict(this._input,12,this._ctx);i!==2&&i!==rn.ATN.INVALID_ALT_NUMBER;)i===1&&(this.state=410,this._errHandler.sync(this),r=this._input.LA(1),r===d.COMMA&&(this.state=409,this.match(d.COMMA)),this.state=412,this.topLevelQueryDef()),this.state=417,this._errHandler.sync(this),i=this.interpreter.adaptivePredict(this._input,12,this._ctx);this.state=419,this._errHandler.sync(this),r=this._input.LA(1),r===d.COMMA&&(this.state=418,this.match(d.COMMA))}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}topLevelQueryDef(){let e=new FR(this._ctx,this.state);this.enterRule(e,36,d.RULE_topLevelQueryDef);try{this.enterOuterAlt(e,1),this.state=421,this.tags(),this.state=422,this.queryName(),this.state=423,this.isDefine(),this.state=424,this.sqExpr(0)}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}refineOperator(){let e=new Yce(this._ctx,this.state);this.enterRule(e,38,d.RULE_refineOperator);try{this.enterOuterAlt(e,1),this.state=426,this.match(d.PLUS)}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}turtleName(){let e=new Kce(this._ctx,this.state);this.enterRule(e,40,d.RULE_turtleName);try{this.enterOuterAlt(e,1),this.state=428,this.id()}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}sqlSource(){let e=new Vk(this._ctx,this.state);this.enterRule(e,42,d.RULE_sqlSource);try{this.enterOuterAlt(e,1);{switch(this.state=430,this.connectionId(),this.state=431,this.match(d.DOT),this.state=432,this.match(d.SQL),this.state=433,this.match(d.OPAREN),this.state=436,this._errHandler.sync(this),this._input.LA(1)){case d.SQL_BEGIN:this.state=434,this.sqlString();break;case d.SQ_STRING:case d.DQ_STRING:this.state=435,this.shortString();break;default:throw new sn.NoViableAltException(this)}this.state=438,this.match(d.CPAREN)}}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}exploreTable(){let e=new Yk(this._ctx,this.state);this.enterRule(e,44,d.RULE_exploreTable);try{this.enterOuterAlt(e,1),this.state=440,this.connectionId(),this.state=441,this.match(d.DOT),this.state=442,this.match(d.TABLE),this.state=443,this.match(d.OPAREN),this.state=444,this.tablePath(),this.state=445,this.match(d.CPAREN)}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}connectionId(){let e=new wR(this._ctx,this.state);this.enterRule(e,46,d.RULE_connectionId);try{this.enterOuterAlt(e,1),this.state=447,this.id()}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}queryProperties(){let e=new Kk(this._ctx,this.state);this.enterRule(e,48,d.RULE_queryProperties);let r;try{this.enterOuterAlt(e,1);{for(this.state=449,this.match(d.OCURLY),this.state=454,this._errHandler.sync(this),r=this._input.LA(1);!(r&-32)&&1<<r&(1<<d.AGGREGATE|1<<d.CALCULATE|1<<d.DECLARE|1<<d.DIMENSION|1<<d.EXCEPT|1<<d.EXTENDQ|1<<d.GROUP_BY|1<<d.HAVING|1<<d.INDEX|1<<d.INTERNAL|1<<d.JOIN_CROSS|1<<d.JOIN_ONE|1<<d.JOIN_MANY|1<<d.LIMIT|1<<d.MEASURE|1<<d.NEST|1<<d.ORDER_BY|1<<d.PRIVATE|1<<d.PUBLIC|1<<d.QUERY|1<<d.RUN|1<<d.SAMPLE|1<<d.SELECT|1<<d.SOURCE)||!(r-32&-32)&&1<<r-32&(1<<d.TOP-32|1<<d.WHERE-32|1<<d.VIEW-32|1<<d.TIMEZONE-32|1<<d.ALL-32|1<<d.AVG-32|1<<d.CASE-32|1<<d.CAST-32|1<<d.COUNT-32|1<<d.COMPOSE-32|1<<d.DAY-32|1<<d.EXCLUDE-32|1<<d.FALSE-32|1<<d.HOUR-32)||!(r-66&-32)&&1<<r-66&(1<<d.IS-66|1<<d.INTERNAL_KW-66|1<<d.MAX-66|1<<d.MIN-66|1<<d.MINUTE-66|1<<d.MONTH-66|1<<d.NOT-66|1<<d.NOW-66|1<<d.NULL-66|1<<d.PICK-66|1<<d.PRIVATE_KW-66|1<<d.PUBLIC_KW-66|1<<d.QUARTER-66|1<<d.SECOND-66|1<<d.SOURCE_KW-66|1<<d.SUM-66)||!(r-98&-32)&&1<<r-98&(1<<d.TRUE-98|1<<d.WEEK-98|1<<d.YEAR-98|1<<d.HACKY_REGEX-98|1<<d.RAW_SQ-98|1<<d.RAW_DQ-98|1<<d.SQ3_FILTER-98|1<<d.SQ_FILTER-98|1<<d.DQ3_FILTER-98|1<<d.DQ_FILTER-98|1<<d.BQ3_FILTER-98|1<<d.BQ_FILTER-98|1<<d.SQ_STRING-98|1<<d.DQ_STRING-98|1<<d.BQ_STRING-98|1<<d.DOC_ANNOTATION-98|1<<d.ANNOTATION-98|1<<d.OPAREN-98|1<<d.OBRACK-98|1<<d.OCURLY-98)||!(r-141&-32)&&1<<r-141&(1<<d.MINUS-141|1<<d.STAR-141|1<<d.SEMI-141|1<<d.LITERAL_TIMESTAMP-141|1<<d.LITERAL_HOUR-141|1<<d.LITERAL_DAY-141|1<<d.LITERAL_QUARTER-141|1<<d.LITERAL_MONTH-141|1<<d.LITERAL_WEEK-141|1<<d.LITERAL_YEAR-141|1<<d.IDENTIFIER-141|1<<d.NUMERIC_LITERAL-141|1<<d.INTEGER_LITERAL-141|1<<d.SQL_BEGIN-141);){switch(this.state=452,this._errHandler.sync(this),this._input.LA(1)){case d.AGGREGATE:case d.CALCULATE:case d.DECLARE:case d.DIMENSION:case d.EXCEPT:case d.EXTENDQ:case d.GROUP_BY:case d.HAVING:case d.INDEX:case d.INTERNAL:case d.JOIN_CROSS:case d.JOIN_ONE:case d.JOIN_MANY:case d.LIMIT:case d.MEASURE:case d.NEST:case d.ORDER_BY:case d.PRIVATE:case d.PUBLIC:case d.QUERY:case d.RUN:case d.SAMPLE:case d.SELECT:case d.SOURCE:case d.TOP:case d.WHERE:case d.VIEW:case d.TIMEZONE:case d.ALL:case d.AVG:case d.CASE:case d.CAST:case d.COUNT:case d.COMPOSE:case d.DAY:case d.EXCLUDE:case d.FALSE:case d.HOUR:case d.IS:case d.INTERNAL_KW:case d.MAX:case d.MIN:case d.MINUTE:case d.MONTH:case d.NOT:case d.NOW:case d.NULL:case d.PICK:case d.PRIVATE_KW:case d.PUBLIC_KW:case d.QUARTER:case d.SECOND:case d.SOURCE_KW:case d.SUM:case d.TRUE:case d.WEEK:case d.YEAR:case d.HACKY_REGEX:case d.RAW_SQ:case d.RAW_DQ:case d.SQ3_FILTER:case d.SQ_FILTER:case d.DQ3_FILTER:case d.DQ_FILTER:case d.BQ3_FILTER:case d.BQ_FILTER:case d.SQ_STRING:case d.DQ_STRING:case d.BQ_STRING:case d.DOC_ANNOTATION:case d.ANNOTATION:case d.OPAREN:case d.OBRACK:case d.OCURLY:case d.MINUS:case d.STAR:case d.LITERAL_TIMESTAMP:case d.LITERAL_HOUR:case d.LITERAL_DAY:case d.LITERAL_QUARTER:case d.LITERAL_MONTH:case d.LITERAL_WEEK:case d.LITERAL_YEAR:case d.IDENTIFIER:case d.NUMERIC_LITERAL:case d.INTEGER_LITERAL:case d.SQL_BEGIN:this.state=450,this.queryStatement();break;case d.SEMI:this.state=451,this.match(d.SEMI);break;default:throw new sn.NoViableAltException(this)}this.state=456,this._errHandler.sync(this),r=this._input.LA(1)}this.state=457,this.match(d.CCURLY)}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}queryName(){let e=new NR(this._ctx,this.state);this.enterRule(e,50,d.RULE_queryName);try{this.enterOuterAlt(e,1),this.state=459,this.id()}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}sourcePropertyList(){let e=new Jk(this._ctx,this.state);this.enterRule(e,52,d.RULE_sourcePropertyList);let r;try{let i;this.enterOuterAlt(e,1);{for(this.state=461,this.sourceDefinition(),this.state=468,this._errHandler.sync(this),i=this.interpreter.adaptivePredict(this._input,18,this._ctx);i!==2&&i!==rn.ATN.INVALID_ALT_NUMBER;)i===1&&(this.state=463,this._errHandler.sync(this),r=this._input.LA(1),r===d.COMMA&&(this.state=462,this.match(d.COMMA)),this.state=465,this.sourceDefinition()),this.state=470,this._errHandler.sync(this),i=this.interpreter.adaptivePredict(this._input,18,this._ctx);this.state=472,this._errHandler.sync(this),r=this._input.LA(1),r===d.COMMA&&(this.state=471,this.match(d.COMMA))}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}sourceDefinition(){let e=new LR(this._ctx,this.state);this.enterRule(e,54,d.RULE_sourceDefinition);try{this.enterOuterAlt(e,1);{switch(this.state=474,this.tags(),this.state=475,this.sourceNameDef(),this.state=477,this._errHandler.sync(this),this.interpreter.adaptivePredict(this._input,20,this._ctx)){case 1:this.state=476,this.sourceParameters();break}this.state=479,this.isDefine(),this.state=480,this.sqExplore()}}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}sqExplore(){let e=new Xk(this._ctx,this.state);this.enterRule(e,56,d.RULE_sqExplore);try{this.enterOuterAlt(e,1),this.state=482,this.sqExpr(0)}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}sourceParameters(){let e=new Zk(this._ctx,this.state);this.enterRule(e,58,d.RULE_sourceParameters);let r;try{switch(this.state=497,this._errHandler.sync(this),this.interpreter.adaptivePredict(this._input,22,this._ctx)){case 1:this.enterOuterAlt(e,1),this.state=484,this.match(d.OPAREN),this.state=485,this.match(d.CPAREN);break;case 2:this.enterOuterAlt(e,2);{for(this.state=486,this.match(d.OPAREN),this.state=487,this.sourceParameter(),this.state=492,this._errHandler.sync(this),r=this._input.LA(1);r===d.COMMA;)this.state=488,this.match(d.COMMA),this.state=489,this.sourceParameter(),this.state=494,this._errHandler.sync(this),r=this._input.LA(1);this.state=495,this.match(d.CPAREN)}break}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}legalParamType(){let e=new eM(this._ctx,this.state);this.enterRule(e,60,d.RULE_legalParamType);try{switch(this.state=505,this._errHandler.sync(this),this._input.LA(1)){case d.BOOLEAN:case d.DATE:case d.NUMBER:case d.STRING:case d.TIMESTAMP:this.enterOuterAlt(e,1),this.state=499,this.malloyType();break;case d.FILTER:this.enterOuterAlt(e,2),this.state=500,this.match(d.FILTER),this.state=501,this.match(d.LT),this.state=502,this.malloyType(),this.state=503,this.match(d.GT);break;default:throw new sn.NoViableAltException(this)}}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}sourceParameter(){let e=new IR(this._ctx,this.state);this.enterRule(e,62,d.RULE_sourceParameter);let r;try{this.enterOuterAlt(e,1),this.state=507,this.parameterNameDef(),this.state=510,this._errHandler.sync(this),r=this._input.LA(1),r===d.DOUBLECOLON&&(this.state=508,this.match(d.DOUBLECOLON),this.state=509,this.legalParamType()),this.state=514,this._errHandler.sync(this),r=this._input.LA(1),r===d.IS&&(this.state=512,this.match(d.IS),this.state=513,this.fieldExpr(0))}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}parameterNameDef(){let e=new tM(this._ctx,this.state);this.enterRule(e,64,d.RULE_parameterNameDef);try{this.enterOuterAlt(e,1),this.state=516,this.id()}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}sourceNameDef(){let e=new nM(this._ctx,this.state);this.enterRule(e,66,d.RULE_sourceNameDef);try{this.enterOuterAlt(e,1),this.state=518,this.id()}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}exploreProperties(){let e=new rM(this._ctx,this.state);this.enterRule(e,68,d.RULE_exploreProperties);let r;try{this.enterOuterAlt(e,1);{for(this.state=520,this.match(d.OCURLY),this.state=525,this._errHandler.sync(this),r=this._input.LA(1);!(r&-32)&&1<<r&(1<<d.ACCEPT|1<<d.AGGREGATE|1<<d.CALCULATE|1<<d.DIMENSION|1<<d.EXCEPT|1<<d.GROUP_BY|1<<d.INTERNAL|1<<d.JOIN_CROSS|1<<d.JOIN_ONE|1<<d.JOIN_MANY|1<<d.MEASURE|1<<d.NEST|1<<d.PRIMARY_KEY|1<<d.PRIVATE|1<<d.PUBLIC|1<<d.QUERY|1<<d.RENAME|1<<d.RUN|1<<d.SELECT|1<<d.SOURCE)||!(r-33&-32)&&1<<r-33&(1<<d.WHERE-33|1<<d.VIEW-33|1<<d.TIMEZONE-33|1<<d.ALL-33|1<<d.AVG-33|1<<d.CASE-33|1<<d.CAST-33|1<<d.COUNT-33|1<<d.COMPOSE-33|1<<d.DAY-33|1<<d.EXCLUDE-33|1<<d.FALSE-33|1<<d.HOUR-33)||!(r-66&-32)&&1<<r-66&(1<<d.IS-66|1<<d.INTERNAL_KW-66|1<<d.MAX-66|1<<d.MIN-66|1<<d.MINUTE-66|1<<d.MONTH-66|1<<d.NOT-66|1<<d.NOW-66|1<<d.NULL-66|1<<d.PICK-66|1<<d.PRIVATE_KW-66|1<<d.PUBLIC_KW-66|1<<d.QUARTER-66|1<<d.SECOND-66|1<<d.SOURCE_KW-66|1<<d.SUM-66)||!(r-98&-32)&&1<<r-98&(1<<d.TRUE-98|1<<d.WEEK-98|1<<d.YEAR-98|1<<d.HACKY_REGEX-98|1<<d.RAW_SQ-98|1<<d.RAW_DQ-98|1<<d.SQ3_FILTER-98|1<<d.SQ_FILTER-98|1<<d.DQ3_FILTER-98|1<<d.DQ_FILTER-98|1<<d.BQ3_FILTER-98|1<<d.BQ_FILTER-98|1<<d.SQ_STRING-98|1<<d.DQ_STRING-98|1<<d.BQ_STRING-98|1<<d.DOC_ANNOTATION-98|1<<d.ANNOTATION-98|1<<d.OPAREN-98|1<<d.OBRACK-98|1<<d.OCURLY-98)||!(r-141&-32)&&1<<r-141&(1<<d.MINUS-141|1<<d.STAR-141|1<<d.SEMI-141|1<<d.LITERAL_TIMESTAMP-141|1<<d.LITERAL_HOUR-141|1<<d.LITERAL_DAY-141|1<<d.LITERAL_QUARTER-141|1<<d.LITERAL_MONTH-141|1<<d.LITERAL_WEEK-141|1<<d.LITERAL_YEAR-141|1<<d.IDENTIFIER-141|1<<d.NUMERIC_LITERAL-141|1<<d.INTEGER_LITERAL-141|1<<d.SQL_BEGIN-141);){switch(this.state=523,this._errHandler.sync(this),this._input.LA(1)){case d.ACCEPT:case d.AGGREGATE:case d.CALCULATE:case d.DIMENSION:case d.EXCEPT:case d.GROUP_BY:case d.INTERNAL:case d.JOIN_CROSS:case d.JOIN_ONE:case d.JOIN_MANY:case d.MEASURE:case d.NEST:case d.PRIMARY_KEY:case d.PRIVATE:case d.PUBLIC:case d.QUERY:case d.RENAME:case d.RUN:case d.SELECT:case d.SOURCE:case d.WHERE:case d.VIEW:case d.TIMEZONE:case d.ALL:case d.AVG:case d.CASE:case d.CAST:case d.COUNT:case d.COMPOSE:case d.DAY:case d.EXCLUDE:case d.FALSE:case d.HOUR:case d.IS:case d.INTERNAL_KW:case d.MAX:case d.MIN:case d.MINUTE:case d.MONTH:case d.NOT:case d.NOW:case d.NULL:case d.PICK:case d.PRIVATE_KW:case d.PUBLIC_KW:case d.QUARTER:case d.SECOND:case d.SOURCE_KW:case d.SUM:case d.TRUE:case d.WEEK:case d.YEAR:case d.HACKY_REGEX:case d.RAW_SQ:case d.RAW_DQ:case d.SQ3_FILTER:case d.SQ_FILTER:case d.DQ3_FILTER:case d.DQ_FILTER:case d.BQ3_FILTER:case d.BQ_FILTER:case d.SQ_STRING:case d.DQ_STRING:case d.BQ_STRING:case d.DOC_ANNOTATION:case d.ANNOTATION:case d.OPAREN:case d.OBRACK:case d.OCURLY:case d.MINUS:case d.STAR:case d.LITERAL_TIMESTAMP:case d.LITERAL_HOUR:case d.LITERAL_DAY:case d.LITERAL_QUARTER:case d.LITERAL_MONTH:case d.LITERAL_WEEK:case d.LITERAL_YEAR:case d.IDENTIFIER:case d.NUMERIC_LITERAL:case d.INTEGER_LITERAL:case d.SQL_BEGIN:this.state=521,this.exploreStatement();break;case d.SEMI:this.state=522,this.match(d.SEMI);break;default:throw new sn.NoViableAltException(this)}this.state=527,this._errHandler.sync(this),r=this._input.LA(1)}this.state=528,this.match(d.CCURLY)}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}exploreStatement(){let e=new Ki(this._ctx,this.state);this.enterRule(e,70,d.RULE_exploreStatement);let r;try{let i;switch(this.state=557,this._errHandler.sync(this),this.interpreter.adaptivePredict(this._input,31,this._ctx)){case 1:e=new Jce(e),this.enterOuterAlt(e,1),this.state=530,this.defDimensions();break;case 2:e=new Xce(e),this.enterOuterAlt(e,2),this.state=531,this.defMeasures();break;case 3:e=new Zce(e),this.enterOuterAlt(e,3),this.state=532,this.joinStatement();break;case 4:e=new efe(e),this.enterOuterAlt(e,4),this.state=533,this.whereStatement();break;case 5:e=new tfe(e),this.enterOuterAlt(e,5),this.state=534,this.match(d.PRIMARY_KEY),this.state=535,this.fieldName();break;case 6:e=new nfe(e),this.enterOuterAlt(e,6),this.state=537,this._errHandler.sync(this),r=this._input.LA(1),!(r-68&-32)&&1<<r-68&(1<<d.INTERNAL_KW-68|1<<d.PRIVATE_KW-68|1<<d.PUBLIC_KW-68)&&(this.state=536,this.accessLabel()),this.state=539,this.match(d.RENAME),this.state=540,this.renameList();break;case 7:e=new rfe(e),this.enterOuterAlt(e,7),this.state=541,r=this._input.LA(1),r===d.ACCEPT||r===d.EXCEPT?(this._input.LA(1)===Wn.Token.EOF&&(this.matchedEOF=!0),this._errHandler.reportMatch(this),this.consume()):this._errHandler.recoverInline(this),this.state=542,this.fieldNameList();break;case 8:e=new ife(e),this.enterOuterAlt(e,8),this.state=543,this.tags(),this.state=545,this._errHandler.sync(this),r=this._input.LA(1),!(r-68&-32)&&1<<r-68&(1<<d.INTERNAL_KW-68|1<<d.PRIVATE_KW-68|1<<d.PUBLIC_KW-68)&&(this.state=544,this.accessLabel()),this.state=547,this.match(d.VIEW),this.state=548,this.subQueryDefList();break;case 9:e=new sfe(e),this.enterOuterAlt(e,9),this.state=550,this.timezoneStatement();break;case 10:e=new ofe(e),this.enterOuterAlt(e,10);{this.state=552,this._errHandler.sync(this),i=1;do{switch(i){case 1:this.state=551,this.match(d.ANNOTATION);break;default:throw new sn.NoViableAltException(this)}this.state=554,this._errHandler.sync(this),i=this.interpreter.adaptivePredict(this._input,30,this._ctx)}while(i!==2&&i!==rn.ATN.INVALID_ALT_NUMBER)}break;case 11:e=new ufe(e),this.enterOuterAlt(e,11),this.state=556,this.ignoredModelAnnotations();break}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}accessLabel(){let e=new Qa(this._ctx,this.state);this.enterRule(e,72,d.RULE_accessLabel);let r;try{this.enterOuterAlt(e,1),this.state=559,r=this._input.LA(1),!(r-68&-32)&&1<<r-68&(1<<d.INTERNAL_KW-68|1<<d.PRIVATE_KW-68|1<<d.PUBLIC_KW-68)?(this._input.LA(1)===Wn.Token.EOF&&(this.matchedEOF=!0),this._errHandler.reportMatch(this),this.consume()):this._errHandler.recoverInline(this)}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}accessModifierList(){let e=new afe(this._ctx,this.state);this.enterRule(e,74,d.RULE_accessModifierList);let r;try{switch(this.state=566,this._errHandler.sync(this),this._input.LA(1)){case d.BQ_STRING:case d.IDENTIFIER:this.enterOuterAlt(e,1),this.state=561,this.fieldNameList();break;case d.STAR:this.enterOuterAlt(e,2),this.state=562,this.match(d.STAR),this.state=564,this._errHandler.sync(this),r=this._input.LA(1),r===d.OCURLY&&(this.state=563,this.starQualified());break;default:throw new sn.NoViableAltException(this)}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}defMeasures(){let e=new $R(this._ctx,this.state);this.enterRule(e,76,d.RULE_defMeasures);let r;try{this.enterOuterAlt(e,1),this.state=568,this.tags(),this.state=570,this._errHandler.sync(this),r=this._input.LA(1),!(r-68&-32)&&1<<r-68&(1<<d.INTERNAL_KW-68|1<<d.PRIVATE_KW-68|1<<d.PUBLIC_KW-68)&&(this.state=569,this.accessLabel()),this.state=572,this.match(d.MEASURE),this.state=573,this.defList()}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}defDimensions(){let e=new BR(this._ctx,this.state);this.enterRule(e,78,d.RULE_defDimensions);let r;try{this.enterOuterAlt(e,1),this.state=575,this.tags(),this.state=577,this._errHandler.sync(this),r=this._input.LA(1),!(r-68&-32)&&1<<r-68&(1<<d.INTERNAL_KW-68|1<<d.PRIVATE_KW-68|1<<d.PUBLIC_KW-68)&&(this.state=576,this.accessLabel()),this.state=579,this.match(d.DIMENSION),this.state=580,this.defList()}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}renameList(){let e=new iM(this._ctx,this.state);this.enterRule(e,80,d.RULE_renameList);let r;try{let i;this.enterOuterAlt(e,1);{for(this.state=582,this.exploreRenameDef(),this.state=589,this._errHandler.sync(this),i=this.interpreter.adaptivePredict(this._input,37,this._ctx);i!==2&&i!==rn.ATN.INVALID_ALT_NUMBER;)i===1&&(this.state=584,this._errHandler.sync(this),r=this._input.LA(1),r===d.COMMA&&(this.state=583,this.match(d.COMMA)),this.state=586,this.exploreRenameDef()),this.state=591,this._errHandler.sync(this),i=this.interpreter.adaptivePredict(this._input,37,this._ctx);this.state=593,this._errHandler.sync(this),r=this._input.LA(1),r===d.COMMA&&(this.state=592,this.match(d.COMMA))}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}exploreRenameDef(){let e=new kR(this._ctx,this.state);this.enterRule(e,82,d.RULE_exploreRenameDef);try{this.enterOuterAlt(e,1),this.state=595,this.fieldName(),this.state=596,this.isDefine(),this.state=597,this.fieldName()}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}defList(){let e=new jE(this._ctx,this.state);this.enterRule(e,84,d.RULE_defList);let r;try{let i;this.enterOuterAlt(e,1);{for(this.state=599,this.fieldDef(),this.state=606,this._errHandler.sync(this),i=this.interpreter.adaptivePredict(this._input,40,this._ctx);i!==2&&i!==rn.ATN.INVALID_ALT_NUMBER;)i===1&&(this.state=601,this._errHandler.sync(this),r=this._input.LA(1),r===d.COMMA&&(this.state=600,this.match(d.COMMA)),this.state=603,this.fieldDef()),this.state=608,this._errHandler.sync(this),i=this.interpreter.adaptivePredict(this._input,40,this._ctx);this.state=610,this._errHandler.sync(this),r=this._input.LA(1),r===d.COMMA&&(this.state=609,this.match(d.COMMA))}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}fieldDef(){let e=new Z2(this._ctx,this.state);this.enterRule(e,86,d.RULE_fieldDef);try{this.enterOuterAlt(e,1),this.state=612,this.tags(),this.state=613,this.fieldNameDef(),this.state=614,this.isDefine(),this.state=615,this.fieldExpr(0)}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}fieldNameDef(){let e=new sM(this._ctx,this.state);this.enterRule(e,88,d.RULE_fieldNameDef);try{this.enterOuterAlt(e,1),this.state=617,this.id()}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}joinNameDef(){let e=new oM(this._ctx,this.state);this.enterRule(e,90,d.RULE_joinNameDef);try{this.enterOuterAlt(e,1),this.state=619,this.id()}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}declareStatement(){let e=new MR(this._ctx,this.state);this.enterRule(e,92,d.RULE_declareStatement);try{this.enterOuterAlt(e,1);{switch(this.state=621,this.match(d.DECLARE),this.state=623,this._errHandler.sync(this),this.interpreter.adaptivePredict(this._input,42,this._ctx)){case 1:this.state=622,this.accessLabel();break}this.state=625,this.defList()}}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}joinStatement(){let e=new C0(this._ctx,this.state);this.enterRule(e,94,d.RULE_joinStatement);let r;try{switch(this.state=648,this._errHandler.sync(this),this.interpreter.adaptivePredict(this._input,46,this._ctx)){case 1:e=new lfe(e),this.enterOuterAlt(e,1),this.state=627,this.tags(),this.state=629,this._errHandler.sync(this),r=this._input.LA(1),!(r-68&-32)&&1<<r-68&(1<<d.INTERNAL_KW-68|1<<d.PRIVATE_KW-68|1<<d.PUBLIC_KW-68)&&(this.state=628,this.accessLabel()),this.state=631,this.match(d.JOIN_ONE),this.state=632,this.joinList();break;case 2:e=new cfe(e),this.enterOuterAlt(e,2),this.state=634,this.tags(),this.state=636,this._errHandler.sync(this),r=this._input.LA(1),!(r-68&-32)&&1<<r-68&(1<<d.INTERNAL_KW-68|1<<d.PRIVATE_KW-68|1<<d.PUBLIC_KW-68)&&(this.state=635,this.accessLabel()),this.state=638,this.match(d.JOIN_MANY),this.state=639,this.joinList();break;case 3:e=new ffe(e),this.enterOuterAlt(e,3),this.state=641,this.tags(),this.state=643,this._errHandler.sync(this),r=this._input.LA(1),!(r-68&-32)&&1<<r-68&(1<<d.INTERNAL_KW-68|1<<d.PRIVATE_KW-68|1<<d.PUBLIC_KW-68)&&(this.state=642,this.accessLabel()),this.state=645,this.match(d.JOIN_CROSS),this.state=646,this.joinList();break}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}queryExtend(){let e=new uM(this._ctx,this.state);this.enterRule(e,96,d.RULE_queryExtend);try{this.enterOuterAlt(e,1),this.state=650,this.match(d.EXTENDQ),this.state=651,this.queryExtendStatementList()}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}modEither(){let e=new xfe(this._ctx,this.state);this.enterRule(e,98,d.RULE_modEither);try{switch(this.state=656,this._errHandler.sync(this),this._input.LA(1)){case d.AGGREGATE:case d.CALCULATE:case d.DIMENSION:case d.EXCEPT:case d.GROUP_BY:case d.INTERNAL:case d.JOIN_CROSS:case d.JOIN_ONE:case d.JOIN_MANY:case d.MEASURE:case d.NEST:case d.PRIVATE:case d.PUBLIC:case d.QUERY:case d.RUN:case d.SELECT:case d.SOURCE:case d.VIEW:case d.ALL:case d.AVG:case d.CASE:case d.CAST:case d.COUNT:case d.COMPOSE:case d.DAY:case d.EXCLUDE:case d.FALSE:case d.HOUR:case d.IS:case d.INTERNAL_KW:case d.MAX:case d.MIN:case d.MINUTE:case d.MONTH:case d.NOT:case d.NOW:case d.NULL:case d.PICK:case d.PRIVATE_KW:case d.PUBLIC_KW:case d.QUARTER:case d.SECOND:case d.SOURCE_KW:case d.SUM:case d.TRUE:case d.WEEK:case d.YEAR:case d.HACKY_REGEX:case d.RAW_SQ:case d.RAW_DQ:case d.SQ3_FILTER:case d.SQ_FILTER:case d.DQ3_FILTER:case d.DQ_FILTER:case d.BQ3_FILTER:case d.BQ_FILTER:case d.SQ_STRING:case d.DQ_STRING:case d.BQ_STRING:case d.ANNOTATION:case d.OPAREN:case d.OBRACK:case d.OCURLY:case d.MINUS:case d.STAR:case d.LITERAL_TIMESTAMP:case d.LITERAL_HOUR:case d.LITERAL_DAY:case d.LITERAL_QUARTER:case d.LITERAL_MONTH:case d.LITERAL_WEEK:case d.LITERAL_YEAR:case d.IDENTIFIER:case d.NUMERIC_LITERAL:case d.INTEGER_LITERAL:case d.SQL_BEGIN:this.enterOuterAlt(e,1),this.state=653,this.joinStatement();break;case d.WHERE:this.enterOuterAlt(e,2),this.state=654,this.whereStatement();break;case d.DECLARE:this.enterOuterAlt(e,3),this.state=655,this.declareStatement();break;default:throw new sn.NoViableAltException(this)}}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}sourceArguments(){let e=new PR(this._ctx,this.state);this.enterRule(e,100,d.RULE_sourceArguments);let r;try{switch(this.state=671,this._errHandler.sync(this),this.interpreter.adaptivePredict(this._input,49,this._ctx)){case 1:this.enterOuterAlt(e,1),this.state=658,this.match(d.OPAREN),this.state=659,this.match(d.CPAREN);break;case 2:this.enterOuterAlt(e,2);{for(this.state=660,this.match(d.OPAREN),this.state=661,this.sourceArgument(),this.state=666,this._errHandler.sync(this),r=this._input.LA(1);r===d.COMMA;)this.state=662,this.match(d.COMMA),this.state=663,this.sourceArgument(),this.state=668,this._errHandler.sync(this),r=this._input.LA(1);this.state=669,this.match(d.CPAREN)}break}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}argumentId(){let e=new aM(this._ctx,this.state);this.enterRule(e,102,d.RULE_argumentId);try{this.enterOuterAlt(e,1),this.state=673,this.id()}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}sourceArgument(){let e=new UR(this._ctx,this.state);this.enterRule(e,104,d.RULE_sourceArgument);try{this.enterOuterAlt(e,1);{switch(this.state=678,this._errHandler.sync(this),this.interpreter.adaptivePredict(this._input,50,this._ctx)){case 1:this.state=675,this.argumentId(),this.state=676,this.match(d.IS);break}this.state=680,this.fieldExpr(0)}}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}sqExpr(e){e===void 0&&(e=0);let r=this._ctx,i=this.state,s=new cn(this._ctx,i),o=s,u=106;this.enterRecursionRule(s,106,d.RULE_sqExpr,e);let a;try{let l;this.enterOuterAlt(s,1);{switch(this.state=706,this._errHandler.sync(this),this.interpreter.adaptivePredict(this._input,54,this._ctx)){case 1:switch(s=new dfe(s),this._ctx=s,o=s,this.state=683,this.id(),this.state=685,this._errHandler.sync(this),this.interpreter.adaptivePredict(this._input,51,this._ctx)){case 1:this.state=684,this.sourceArguments();break}break;case 2:s=new hfe(s),this._ctx=s,o=s,this.state=687,this.match(d.OPAREN),this.state=688,this.sqExpr(0),this.state=689,this.match(d.CPAREN);break;case 3:{if(s=new pfe(s),this._ctx=s,o=s,this.state=691,this.match(d.COMPOSE),this.state=692,this.match(d.OPAREN),this.state=701,this._errHandler.sync(this),a=this._input.LA(1),a===d.COMPOSE||a===d.BQ_STRING||a===d.OPAREN||a===d.IDENTIFIER)for(this.state=693,this.sqExpr(0),this.state=698,this._errHandler.sync(this),a=this._input.LA(1);a===d.COMMA;)this.state=694,this.match(d.COMMA),this.state=695,this.sqExpr(0),this.state=700,this._errHandler.sync(this),a=this._input.LA(1);this.state=703,this.match(d.CPAREN)}break;case 4:s=new Afe(s),this._ctx=s,o=s,this.state=704,this.exploreTable();break;case 5:s=new _fe(s),this._ctx=s,o=s,this.state=705,this.sqlSource();break}for(this._ctx._stop=this._input.tryLT(-1),this.state=726,this._errHandler.sync(this),l=this.interpreter.adaptivePredict(this._input,57,this._ctx);l!==2&&l!==rn.ATN.INVALID_ALT_NUMBER;){if(l===1)switch(this._parseListeners!=null&&this.triggerExitRuleEvent(),o=s,this.state=724,this._errHandler.sync(this),this.interpreter.adaptivePredict(this._input,56,this._ctx)){case 1:{if(s=new mfe(new cn(r,i)),this.pushNewRecursionContext(s,u,d.RULE_sqExpr),this.state=708,!this.precpred(this._ctx,6))throw this.createFailedPredicateException("this.precpred(this._ctx, 6)");this.state=709,this.match(d.PLUS),this.state=710,this.segExpr(0)}break;case 2:{if(s=new gfe(new cn(r,i)),this.pushNewRecursionContext(s,u,d.RULE_sqExpr),this.state=711,!this.precpred(this._ctx,5))throw this.createFailedPredicateException("this.precpred(this._ctx, 5)");this.state=712,this.match(d.ARROW),this.state=713,this.segExpr(0)}break;case 3:{if(s=new yfe(new cn(r,i)),this.pushNewRecursionContext(s,u,d.RULE_sqExpr),this.state=714,!this.precpred(this._ctx,4))throw this.createFailedPredicateException("this.precpred(this._ctx, 4)");this.state=717,this._errHandler.sync(this),a=this._input.LA(1),a===d.INCLUDE&&(this.state=715,this.match(d.INCLUDE),this.state=716,this.includeBlock()),this.state=719,this.match(d.EXTEND),this.state=720,this.exploreProperties()}break;case 4:{if(s=new Efe(new cn(r,i)),this.pushNewRecursionContext(s,u,d.RULE_sqExpr),this.state=721,!this.precpred(this._ctx,3))throw this.createFailedPredicateException("this.precpred(this._ctx, 3)");this.state=722,this.match(d.INCLUDE),this.state=723,this.includeBlock()}break}this.state=728,this._errHandler.sync(this),l=this.interpreter.adaptivePredict(this._input,57,this._ctx)}}}catch(l){if(l instanceof ye.RecognitionException)s.exception=l,this._errHandler.reportError(this,l),this._errHandler.recover(this,l);else throw l}finally{this.unrollRecursionContexts(r)}return s}includeBlock(){let e=new jR(this._ctx,this.state);this.enterRule(e,108,d.RULE_includeBlock);let r;try{this.enterOuterAlt(e,1);{for(this.state=729,this.match(d.OCURLY),this.state=734,this._errHandler.sync(this),r=this._input.LA(1);!(r&-32)&&1<<r&(1<<d.AGGREGATE|1<<d.CALCULATE|1<<d.DIMENSION|1<<d.EXCEPT|1<<d.GROUP_BY|1<<d.INTERNAL|1<<d.JOIN_CROSS|1<<d.JOIN_ONE|1<<d.JOIN_MANY|1<<d.MEASURE|1<<d.NEST|1<<d.PRIVATE|1<<d.PUBLIC|1<<d.QUERY|1<<d.RUN|1<<d.SELECT|1<<d.SOURCE)||!(r-34&-32)&&1<<r-34&(1<<d.VIEW-34|1<<d.ALL-34|1<<d.AVG-34|1<<d.CASE-34|1<<d.CAST-34|1<<d.COUNT-34|1<<d.COMPOSE-34|1<<d.DAY-34|1<<d.EXCLUDE-34|1<<d.FALSE-34|1<<d.HOUR-34)||!(r-66&-32)&&1<<r-66&(1<<d.IS-66|1<<d.INTERNAL_KW-66|1<<d.MAX-66|1<<d.MIN-66|1<<d.MINUTE-66|1<<d.MONTH-66|1<<d.NOT-66|1<<d.NOW-66|1<<d.NULL-66|1<<d.PICK-66|1<<d.PRIVATE_KW-66|1<<d.PUBLIC_KW-66|1<<d.QUARTER-66|1<<d.SECOND-66|1<<d.SOURCE_KW-66|1<<d.SUM-66)||!(r-98&-32)&&1<<r-98&(1<<d.TRUE-98|1<<d.WEEK-98|1<<d.YEAR-98|1<<d.HACKY_REGEX-98|1<<d.RAW_SQ-98|1<<d.RAW_DQ-98|1<<d.SQ3_FILTER-98|1<<d.SQ_FILTER-98|1<<d.DQ3_FILTER-98|1<<d.DQ_FILTER-98|1<<d.BQ3_FILTER-98|1<<d.BQ_FILTER-98|1<<d.SQ_STRING-98|1<<d.DQ_STRING-98|1<<d.BQ_STRING-98|1<<d.ANNOTATION-98|1<<d.OPAREN-98|1<<d.OBRACK-98|1<<d.OCURLY-98)||!(r-141&-32)&&1<<r-141&(1<<d.MINUS-141|1<<d.STAR-141|1<<d.SEMI-141|1<<d.LITERAL_TIMESTAMP-141|1<<d.LITERAL_HOUR-141|1<<d.LITERAL_DAY-141|1<<d.LITERAL_QUARTER-141|1<<d.LITERAL_MONTH-141|1<<d.LITERAL_WEEK-141|1<<d.LITERAL_YEAR-141|1<<d.IDENTIFIER-141|1<<d.NUMERIC_LITERAL-141|1<<d.INTEGER_LITERAL-141|1<<d.SQL_BEGIN-141);){switch(this.state=732,this._errHandler.sync(this),this._input.LA(1)){case d.AGGREGATE:case d.CALCULATE:case d.DIMENSION:case d.EXCEPT:case d.GROUP_BY:case d.INTERNAL:case d.JOIN_CROSS:case d.JOIN_ONE:case d.JOIN_MANY:case d.MEASURE:case d.NEST:case d.PRIVATE:case d.PUBLIC:case d.QUERY:case d.RUN:case d.SELECT:case d.SOURCE:case d.VIEW:case d.ALL:case d.AVG:case d.CASE:case d.CAST:case d.COUNT:case d.COMPOSE:case d.DAY:case d.EXCLUDE:case d.FALSE:case d.HOUR:case d.IS:case d.INTERNAL_KW:case d.MAX:case d.MIN:case d.MINUTE:case d.MONTH:case d.NOT:case d.NOW:case d.NULL:case d.PICK:case d.PRIVATE_KW:case d.PUBLIC_KW:case d.QUARTER:case d.SECOND:case d.SOURCE_KW:case d.SUM:case d.TRUE:case d.WEEK:case d.YEAR:case d.HACKY_REGEX:case d.RAW_SQ:case d.RAW_DQ:case d.SQ3_FILTER:case d.SQ_FILTER:case d.DQ3_FILTER:case d.DQ_FILTER:case d.BQ3_FILTER:case d.BQ_FILTER:case d.SQ_STRING:case d.DQ_STRING:case d.BQ_STRING:case d.ANNOTATION:case d.OPAREN:case d.OBRACK:case d.OCURLY:case d.MINUS:case d.STAR:case d.LITERAL_TIMESTAMP:case d.LITERAL_HOUR:case d.LITERAL_DAY:case d.LITERAL_QUARTER:case d.LITERAL_MONTH:case d.LITERAL_WEEK:case d.LITERAL_YEAR:case d.IDENTIFIER:case d.NUMERIC_LITERAL:case d.INTEGER_LITERAL:case d.SQL_BEGIN:this.state=730,this.includeItem();break;case d.SEMI:this.state=731,this.match(d.SEMI);break;default:throw new sn.NoViableAltException(this)}this.state=736,this._errHandler.sync(this),r=this._input.LA(1)}this.state=737,this.match(d.CCURLY)}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}includeItem(){let e=new qR(this._ctx,this.state);this.enterRule(e,110,d.RULE_includeItem);try{switch(this.state=749,this._errHandler.sync(this),this.interpreter.adaptivePredict(this._input,60,this._ctx)){case 1:this.enterOuterAlt(e,1),this.state=739,this.tags(),this.state=740,this.accessLabelProp(),this.state=741,this.includeList();break;case 2:this.enterOuterAlt(e,2),this.state=743,this.includeList();break;case 3:this.enterOuterAlt(e,3),this.state=744,this.tags(),this.state=745,this.match(d.EXCEPT),this.state=746,this.includeExceptList();break;case 4:this.enterOuterAlt(e,4),this.state=748,this.orphanedAnnotation();break}}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}orphanedAnnotation(){let e=new lM(this._ctx,this.state);this.enterRule(e,112,d.RULE_orphanedAnnotation);try{this.enterOuterAlt(e,1),this.state=751,this.match(d.ANNOTATION)}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}accessLabelProp(){let e=new cM(this._ctx,this.state);this.enterRule(e,114,d.RULE_accessLabelProp);let r;try{this.enterOuterAlt(e,1),this.state=753,r=this._input.LA(1),!(r&-32)&&1<<r&(1<<d.INTERNAL|1<<d.PRIVATE|1<<d.PUBLIC)?(this._input.LA(1)===Wn.Token.EOF&&(this.matchedEOF=!0),this._errHandler.reportMatch(this),this.consume()):this._errHandler.recoverInline(this)}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}includeExceptList(){let e=new fM(this._ctx,this.state);this.enterRule(e,116,d.RULE_includeExceptList);let r;try{let i;this.enterOuterAlt(e,1);{for(this.state=755,this.includeExceptListItem(),this.state=762,this._errHandler.sync(this),i=this.interpreter.adaptivePredict(this._input,62,this._ctx);i!==2&&i!==rn.ATN.INVALID_ALT_NUMBER;)i===1&&(this.state=757,this._errHandler.sync(this),r=this._input.LA(1),r===d.COMMA&&(this.state=756,this.match(d.COMMA)),this.state=759,this.includeExceptListItem()),this.state=764,this._errHandler.sync(this),i=this.interpreter.adaptivePredict(this._input,62,this._ctx);this.state=766,this._errHandler.sync(this),r=this._input.LA(1),r===d.COMMA&&(this.state=765,this.match(d.COMMA))}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}includeExceptListItem(){let e=new HR(this._ctx,this.state);this.enterRule(e,118,d.RULE_includeExceptListItem);try{switch(this.state=774,this._errHandler.sync(this),this.interpreter.adaptivePredict(this._input,64,this._ctx)){case 1:this.enterOuterAlt(e,1),this.state=768,this.tags(),this.state=769,this.fieldName();break;case 2:this.enterOuterAlt(e,2),this.state=771,this.tags(),this.state=772,this.collectionWildCard();break}}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}includeList(){let e=new xM(this._ctx,this.state);this.enterRule(e,120,d.RULE_includeList);let r;try{let i;this.enterOuterAlt(e,1);{for(this.state=776,this.includeField(),this.state=783,this._errHandler.sync(this),i=this.interpreter.adaptivePredict(this._input,66,this._ctx);i!==2&&i!==rn.ATN.INVALID_ALT_NUMBER;)i===1&&(this.state=778,this._errHandler.sync(this),r=this._input.LA(1),r===d.COMMA&&(this.state=777,this.match(d.COMMA)),this.state=780,this.includeField()),this.state=785,this._errHandler.sync(this),i=this.interpreter.adaptivePredict(this._input,66,this._ctx);this.state=787,this._errHandler.sync(this),r=this._input.LA(1),r===d.COMMA&&(this.state=786,this.match(d.COMMA))}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}includeField(){let e=new QR(this._ctx,this.state);this.enterRule(e,122,d.RULE_includeField);try{switch(this.state=803,this._errHandler.sync(this),this.interpreter.adaptivePredict(this._input,69,this._ctx)){case 1:this.enterOuterAlt(e,1);{switch(this.state=789,this.tags(),this.state=793,this._errHandler.sync(this),this.interpreter.adaptivePredict(this._input,68,this._ctx)){case 1:this.state=790,e._as=this.fieldName(),this.state=791,this.isDefine();break}this.state=795,e._name=this.fieldName()}break;case 2:this.enterOuterAlt(e,2),this.state=797,this.tags(),this.state=798,e._name=this.fieldName();break;case 3:this.enterOuterAlt(e,3),this.state=800,this.tags(),this.state=801,this.collectionWildCard();break}}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}segExpr(e){e===void 0&&(e=0);let r=this._ctx,i=this.state,s=new Ws(this._ctx,i),o=s,u=124;this.enterRecursionRule(s,124,d.RULE_segExpr,e);try{let a;this.enterOuterAlt(s,1);{switch(this.state=812,this._errHandler.sync(this),this._input.LA(1)){case d.BQ_STRING:case d.IDENTIFIER:s=new vfe(s),this._ctx=s,o=s,this.state=806,this.fieldPath();break;case d.OCURLY:s=new Cfe(s),this._ctx=s,o=s,this.state=807,this.queryProperties();break;case d.OPAREN:s=new Sfe(s),this._ctx=s,o=s,this.state=808,this.match(d.OPAREN),this.state=809,this.vExpr(),this.state=810,this.match(d.CPAREN);break;default:throw new sn.NoViableAltException(this)}for(this._ctx._stop=this._input.tryLT(-1),this.state=819,this._errHandler.sync(this),a=this.interpreter.adaptivePredict(this._input,71,this._ctx);a!==2&&a!==rn.ATN.INVALID_ALT_NUMBER;){if(a===1){this._parseListeners!=null&&this.triggerExitRuleEvent(),o=s;{if(s=new bfe(new Ws(r,i)),s._lhs=o,this.pushNewRecursionContext(s,u,d.RULE_segExpr),this.state=814,!this.precpred(this._ctx,1))throw this.createFailedPredicateException("this.precpred(this._ctx, 1)");this.state=815,this.match(d.PLUS),this.state=816,s._rhs=this.segExpr(2)}}this.state=821,this._errHandler.sync(this),a=this.interpreter.adaptivePredict(this._input,71,this._ctx)}}}catch(a){if(a instanceof ye.RecognitionException)s.exception=a,this._errHandler.reportError(this,a),this._errHandler.recover(this,a);else throw a}finally{this.unrollRecursionContexts(r)}return s}vExpr(){let e=new xf(this._ctx,this.state);this.enterRule(e,126,d.RULE_vExpr);try{switch(this.state=827,this._errHandler.sync(this),this.interpreter.adaptivePredict(this._input,72,this._ctx)){case 1:e=new Tfe(e),this.enterOuterAlt(e,1),this.state=822,this.segExpr(0);break;case 2:e=new Rfe(e),this.enterOuterAlt(e,2),this.state=823,e._lhs=this.segExpr(0),this.state=824,this.match(d.ARROW),this.state=825,e._rhs=this.vExpr();break}}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}queryExtendStatement(){let e=new zR(this._ctx,this.state);this.enterRule(e,128,d.RULE_queryExtendStatement);try{switch(this.state=832,this._errHandler.sync(this),this.interpreter.adaptivePredict(this._input,73,this._ctx)){case 1:this.enterOuterAlt(e,1),this.state=829,this.defDimensions();break;case 2:this.enterOuterAlt(e,2),this.state=830,this.defMeasures();break;case 3:this.enterOuterAlt(e,3),this.state=831,this.joinStatement();break}}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}queryExtendStatementList(){let e=new dM(this._ctx,this.state);this.enterRule(e,130,d.RULE_queryExtendStatementList);let r;try{this.enterOuterAlt(e,1);{for(this.state=834,this.match(d.OCURLY),this.state=839,this._errHandler.sync(this),r=this._input.LA(1);!(r&-32)&&1<<r&(1<<d.AGGREGATE|1<<d.CALCULATE|1<<d.DIMENSION|1<<d.EXCEPT|1<<d.GROUP_BY|1<<d.INTERNAL|1<<d.JOIN_CROSS|1<<d.JOIN_ONE|1<<d.JOIN_MANY|1<<d.MEASURE|1<<d.NEST|1<<d.PRIVATE|1<<d.PUBLIC|1<<d.QUERY|1<<d.RUN|1<<d.SELECT|1<<d.SOURCE)||!(r-34&-32)&&1<<r-34&(1<<d.VIEW-34|1<<d.ALL-34|1<<d.AVG-34|1<<d.CASE-34|1<<d.CAST-34|1<<d.COUNT-34|1<<d.COMPOSE-34|1<<d.DAY-34|1<<d.EXCLUDE-34|1<<d.FALSE-34|1<<d.HOUR-34)||!(r-66&-32)&&1<<r-66&(1<<d.IS-66|1<<d.INTERNAL_KW-66|1<<d.MAX-66|1<<d.MIN-66|1<<d.MINUTE-66|1<<d.MONTH-66|1<<d.NOT-66|1<<d.NOW-66|1<<d.NULL-66|1<<d.PICK-66|1<<d.PRIVATE_KW-66|1<<d.PUBLIC_KW-66|1<<d.QUARTER-66|1<<d.SECOND-66|1<<d.SOURCE_KW-66|1<<d.SUM-66)||!(r-98&-32)&&1<<r-98&(1<<d.TRUE-98|1<<d.WEEK-98|1<<d.YEAR-98|1<<d.HACKY_REGEX-98|1<<d.RAW_SQ-98|1<<d.RAW_DQ-98|1<<d.SQ3_FILTER-98|1<<d.SQ_FILTER-98|1<<d.DQ3_FILTER-98|1<<d.DQ_FILTER-98|1<<d.BQ3_FILTER-98|1<<d.BQ_FILTER-98|1<<d.SQ_STRING-98|1<<d.DQ_STRING-98|1<<d.BQ_STRING-98|1<<d.ANNOTATION-98|1<<d.OPAREN-98|1<<d.OBRACK-98|1<<d.OCURLY-98)||!(r-141&-32)&&1<<r-141&(1<<d.MINUS-141|1<<d.STAR-141|1<<d.SEMI-141|1<<d.LITERAL_TIMESTAMP-141|1<<d.LITERAL_HOUR-141|1<<d.LITERAL_DAY-141|1<<d.LITERAL_QUARTER-141|1<<d.LITERAL_MONTH-141|1<<d.LITERAL_WEEK-141|1<<d.LITERAL_YEAR-141|1<<d.IDENTIFIER-141|1<<d.NUMERIC_LITERAL-141|1<<d.INTEGER_LITERAL-141|1<<d.SQL_BEGIN-141);){switch(this.state=837,this._errHandler.sync(this),this._input.LA(1)){case d.AGGREGATE:case d.CALCULATE:case d.DIMENSION:case d.EXCEPT:case d.GROUP_BY:case d.INTERNAL:case d.JOIN_CROSS:case d.JOIN_ONE:case d.JOIN_MANY:case d.MEASURE:case d.NEST:case d.PRIVATE:case d.PUBLIC:case d.QUERY:case d.RUN:case d.SELECT:case d.SOURCE:case d.VIEW:case d.ALL:case d.AVG:case d.CASE:case d.CAST:case d.COUNT:case d.COMPOSE:case d.DAY:case d.EXCLUDE:case d.FALSE:case d.HOUR:case d.IS:case d.INTERNAL_KW:case d.MAX:case d.MIN:case d.MINUTE:case d.MONTH:case d.NOT:case d.NOW:case d.NULL:case d.PICK:case d.PRIVATE_KW:case d.PUBLIC_KW:case d.QUARTER:case d.SECOND:case d.SOURCE_KW:case d.SUM:case d.TRUE:case d.WEEK:case d.YEAR:case d.HACKY_REGEX:case d.RAW_SQ:case d.RAW_DQ:case d.SQ3_FILTER:case d.SQ_FILTER:case d.DQ3_FILTER:case d.DQ_FILTER:case d.BQ3_FILTER:case d.BQ_FILTER:case d.SQ_STRING:case d.DQ_STRING:case d.BQ_STRING:case d.ANNOTATION:case d.OPAREN:case d.OBRACK:case d.OCURLY:case d.MINUS:case d.STAR:case d.LITERAL_TIMESTAMP:case d.LITERAL_HOUR:case d.LITERAL_DAY:case d.LITERAL_QUARTER:case d.LITERAL_MONTH:case d.LITERAL_WEEK:case d.LITERAL_YEAR:case d.IDENTIFIER:case d.NUMERIC_LITERAL:case d.INTEGER_LITERAL:case d.SQL_BEGIN:this.state=835,this.queryExtendStatement();break;case d.SEMI:this.state=836,this.match(d.SEMI);break;default:throw new sn.NoViableAltException(this)}this.state=841,this._errHandler.sync(this),r=this._input.LA(1)}this.state=842,this.match(d.CCURLY)}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}joinList(){let e=new qE(this._ctx,this.state);this.enterRule(e,132,d.RULE_joinList);let r;try{let i;this.enterOuterAlt(e,1);{for(this.state=844,this.joinDef(),this.state=851,this._errHandler.sync(this),i=this.interpreter.adaptivePredict(this._input,77,this._ctx);i!==2&&i!==rn.ATN.INVALID_ALT_NUMBER;)i===1&&(this.state=846,this._errHandler.sync(this),r=this._input.LA(1),r===d.COMMA&&(this.state=845,this.match(d.COMMA)),this.state=848,this.joinDef()),this.state=853,this._errHandler.sync(this),i=this.interpreter.adaptivePredict(this._input,77,this._ctx);this.state=855,this._errHandler.sync(this),r=this._input.LA(1),r===d.COMMA&&(this.state=854,this.match(d.COMMA))}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}isExplore(){let e=new hM(this._ctx,this.state);this.enterRule(e,134,d.RULE_isExplore);try{this.enterOuterAlt(e,1),this.state=857,e._before_is=this.tags(),this.state=858,this.match(d.IS),this.state=859,e._after_is=this.tags(),this.state=860,this.sqExpr(0)}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}matrixOperation(){let e=new WR(this._ctx,this.state);this.enterRule(e,136,d.RULE_matrixOperation);let r;try{this.enterOuterAlt(e,1),this.state=862,r=this._input.LA(1),!(r-58&-32)&&1<<r-58&(1<<d.FULL-58|1<<d.INNER-58|1<<d.LEFT-58|1<<d.RIGHT-58)?(this._input.LA(1)===Wn.Token.EOF&&(this.matchedEOF=!0),this._errHandler.reportMatch(this),this.consume()):this._errHandler.recoverInline(this)}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}joinFrom(){let e=new GR(this._ctx,this.state);this.enterRule(e,138,d.RULE_joinFrom);try{switch(this.state=871,this._errHandler.sync(this),this.interpreter.adaptivePredict(this._input,79,this._ctx)){case 1:this.enterOuterAlt(e,1),this.state=864,this.joinNameDef();break;case 2:this.enterOuterAlt(e,2),this.state=865,this.joinNameDef(),this.state=866,this.sourceArguments();break;case 3:this.enterOuterAlt(e,3),this.state=868,this.joinNameDef(),this.state=869,this.isExplore();break}}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}joinDef(){let e=new e1(this._ctx,this.state);this.enterRule(e,140,d.RULE_joinDef);let r;try{switch(this.state=900,this._errHandler.sync(this),this.interpreter.adaptivePredict(this._input,85,this._ctx)){case 1:e=new Dfe(e),this.enterOuterAlt(e,1);{for(this.state=876,this._errHandler.sync(this),r=this._input.LA(1);r===d.ANNOTATION;)this.state=873,this.match(d.ANNOTATION),this.state=878,this._errHandler.sync(this),r=this._input.LA(1);this.state=879,this.joinFrom(),this.state=881,this._errHandler.sync(this),r=this._input.LA(1),!(r-58&-32)&&1<<r-58&(1<<d.FULL-58|1<<d.INNER-58|1<<d.LEFT-58|1<<d.RIGHT-58)&&(this.state=880,this.matrixOperation()),this.state=883,this.match(d.WITH),this.state=884,this.fieldExpr(0)}break;case 2:e=new Ofe(e),this.enterOuterAlt(e,2);{for(this.state=889,this._errHandler.sync(this),r=this._input.LA(1);r===d.ANNOTATION;)this.state=886,this.match(d.ANNOTATION),this.state=891,this._errHandler.sync(this),r=this._input.LA(1);this.state=892,this.joinFrom(),this.state=898,this._errHandler.sync(this),r=this._input.LA(1),!(r-58&-32)&&1<<r-58&(1<<d.FULL-58|1<<d.INNER-58|1<<d.LEFT-58|1<<d.ON-58|1<<d.RIGHT-58)&&(this.state=894,this._errHandler.sync(this),r=this._input.LA(1),!(r-58&-32)&&1<<r-58&(1<<d.FULL-58|1<<d.INNER-58|1<<d.LEFT-58|1<<d.RIGHT-58)&&(this.state=893,this.matrixOperation()),this.state=896,this.match(d.ON),this.state=897,this.joinExpression())}break}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}joinExpression(){let e=new pM(this._ctx,this.state);this.enterRule(e,142,d.RULE_joinExpression);try{this.enterOuterAlt(e,1),this.state=902,this.fieldExpr(0)}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}filterStatement(){let e=new Ffe(this._ctx,this.state);this.enterRule(e,144,d.RULE_filterStatement);try{switch(this.state=906,this._errHandler.sync(this),this._input.LA(1)){case d.WHERE:this.enterOuterAlt(e,1),this.state=904,this.whereStatement();break;case d.HAVING:this.enterOuterAlt(e,2),this.state=905,this.havingStatement();break;default:throw new sn.NoViableAltException(this)}}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}fieldProperties(){let e=new mM(this._ctx,this.state);this.enterRule(e,146,d.RULE_fieldProperties);let r;try{this.enterOuterAlt(e,1);{for(this.state=908,this.match(d.OCURLY),this.state=913,this._errHandler.sync(this),r=this._input.LA(1);!(r-17&-32)&&1<<r-17&(1<<d.LIMIT-17|1<<d.ORDER_BY-17|1<<d.PARTITION_BY-17|1<<d.WHERE-17)||r===d.SEMI;){switch(this.state=911,this._errHandler.sync(this),this._input.LA(1)){case d.LIMIT:case d.ORDER_BY:case d.PARTITION_BY:case d.WHERE:this.state=909,this.fieldPropertyStatement();break;case d.SEMI:this.state=910,this.match(d.SEMI);break;default:throw new sn.NoViableAltException(this)}this.state=915,this._errHandler.sync(this),r=this._input.LA(1)}this.state=916,this.match(d.CCURLY)}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}aggregateOrdering(){let e=new gM(this._ctx,this.state);this.enterRule(e,148,d.RULE_aggregateOrdering);let r;try{let i;this.enterOuterAlt(e,1);{for(this.state=918,this.aggregateOrderBySpec(),this.state=923,this._errHandler.sync(this),i=this.interpreter.adaptivePredict(this._input,89,this._ctx);i!==2&&i!==rn.ATN.INVALID_ALT_NUMBER;)i===1&&(this.state=919,this.match(d.COMMA),this.state=920,this.aggregateOrderBySpec()),this.state=925,this._errHandler.sync(this),i=this.interpreter.adaptivePredict(this._input,89,this._ctx);this.state=927,this._errHandler.sync(this),r=this._input.LA(1),r===d.COMMA&&(this.state=926,this.match(d.COMMA))}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}aggregateOrderBySpec(){let e=new VR(this._ctx,this.state);this.enterRule(e,150,d.RULE_aggregateOrderBySpec);let r;try{switch(this.state=935,this._errHandler.sync(this),this._input.LA(1)){case d.ALL:case d.AVG:case d.CASE:case d.CAST:case d.COUNT:case d.DAY:case d.EXCLUDE:case d.FALSE:case d.HOUR:case d.MAX:case d.MIN:case d.MINUTE:case d.MONTH:case d.NOT:case d.NOW:case d.NULL:case d.PICK:case d.QUARTER:case d.SECOND:case d.SOURCE_KW:case d.SUM:case d.TRUE:case d.WEEK:case d.YEAR:case d.HACKY_REGEX:case d.RAW_SQ:case d.RAW_DQ:case d.SQ3_FILTER:case d.SQ_FILTER:case d.DQ3_FILTER:case d.DQ_FILTER:case d.BQ3_FILTER:case d.BQ_FILTER:case d.SQ_STRING:case d.DQ_STRING:case d.BQ_STRING:case d.OPAREN:case d.OBRACK:case d.OCURLY:case d.MINUS:case d.LITERAL_TIMESTAMP:case d.LITERAL_HOUR:case d.LITERAL_DAY:case d.LITERAL_QUARTER:case d.LITERAL_MONTH:case d.LITERAL_WEEK:case d.LITERAL_YEAR:case d.IDENTIFIER:case d.NUMERIC_LITERAL:case d.INTEGER_LITERAL:case d.SQL_BEGIN:this.enterOuterAlt(e,1),this.state=929,this.fieldExpr(0),this.state=931,this._errHandler.sync(this),r=this._input.LA(1),(r===d.ASC||r===d.DESC)&&(this.state=930,r=this._input.LA(1),r===d.ASC||r===d.DESC?(this._input.LA(1)===Wn.Token.EOF&&(this.matchedEOF=!0),this._errHandler.reportMatch(this),this.consume()):this._errHandler.recoverInline(this));break;case d.ASC:this.enterOuterAlt(e,2),this.state=933,this.match(d.ASC);break;case d.DESC:this.enterOuterAlt(e,3),this.state=934,this.match(d.DESC);break;default:throw new sn.NoViableAltException(this)}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}aggregateOrderByStatement(){let e=new yM(this._ctx,this.state);this.enterRule(e,152,d.RULE_aggregateOrderByStatement);try{this.enterOuterAlt(e,1),this.state=937,this.match(d.ORDER_BY),this.state=938,this.aggregateOrdering()}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}fieldPropertyLimitStatement(){let e=new EM(this._ctx,this.state);this.enterRule(e,154,d.RULE_fieldPropertyLimitStatement);try{this.enterOuterAlt(e,1),this.state=940,this.limitStatement()}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}fieldPropertyStatement(){let e=new YR(this._ctx,this.state);this.enterRule(e,156,d.RULE_fieldPropertyStatement);try{switch(this.state=946,this._errHandler.sync(this),this._input.LA(1)){case d.WHERE:this.enterOuterAlt(e,1),this.state=942,this.whereStatement();break;case d.PARTITION_BY:this.enterOuterAlt(e,2),this.state=943,this.partitionByStatement();break;case d.ORDER_BY:this.enterOuterAlt(e,3),this.state=944,this.aggregateOrderByStatement();break;case d.LIMIT:this.enterOuterAlt(e,4),this.state=945,this.fieldPropertyLimitStatement();break;default:throw new sn.NoViableAltException(this)}}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}filterClauseList(){let e=new KR(this._ctx,this.state);this.enterRule(e,158,d.RULE_filterClauseList);let r;try{let i;this.enterOuterAlt(e,1);{for(this.state=948,this.fieldExpr(0),this.state=953,this._errHandler.sync(this),i=this.interpreter.adaptivePredict(this._input,94,this._ctx);i!==2&&i!==rn.ATN.INVALID_ALT_NUMBER;)i===1&&(this.state=949,this.match(d.COMMA),this.state=950,this.fieldExpr(0)),this.state=955,this._errHandler.sync(this),i=this.interpreter.adaptivePredict(this._input,94,this._ctx);this.state=957,this._errHandler.sync(this),r=this._input.LA(1),r===d.COMMA&&(this.state=956,this.match(d.COMMA))}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}whereStatement(){let e=new Nd(this._ctx,this.state);this.enterRule(e,160,d.RULE_whereStatement);try{this.enterOuterAlt(e,1),this.state=959,this.match(d.WHERE),this.state=960,this.filterClauseList()}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}havingStatement(){let e=new JR(this._ctx,this.state);this.enterRule(e,162,d.RULE_havingStatement);try{this.enterOuterAlt(e,1),this.state=962,this.match(d.HAVING),this.state=963,this.filterClauseList()}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}subQueryDefList(){let e=new AM(this._ctx,this.state);this.enterRule(e,164,d.RULE_subQueryDefList);let r;try{let i;this.enterOuterAlt(e,1);{for(this.state=965,this.exploreQueryDef(),this.state=972,this._errHandler.sync(this),i=this.interpreter.adaptivePredict(this._input,97,this._ctx);i!==2&&i!==rn.ATN.INVALID_ALT_NUMBER;)i===1&&(this.state=967,this._errHandler.sync(this),r=this._input.LA(1),r===d.COMMA&&(this.state=966,this.match(d.COMMA)),this.state=969,this.exploreQueryDef()),this.state=974,this._errHandler.sync(this),i=this.interpreter.adaptivePredict(this._input,97,this._ctx);this.state=976,this._errHandler.sync(this),r=this._input.LA(1),r===d.COMMA&&(this.state=975,this.match(d.COMMA))}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}exploreQueryNameDef(){let e=new _M(this._ctx,this.state);this.enterRule(e,166,d.RULE_exploreQueryNameDef);try{this.enterOuterAlt(e,1),this.state=978,this.id()}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}exploreQueryDef(){let e=new XR(this._ctx,this.state);this.enterRule(e,168,d.RULE_exploreQueryDef);let r;try{this.enterOuterAlt(e,1);{for(this.state=983,this._errHandler.sync(this),r=this._input.LA(1);r===d.ANNOTATION;)this.state=980,this.match(d.ANNOTATION),this.state=985,this._errHandler.sync(this),r=this._input.LA(1);this.state=986,this.exploreQueryNameDef(),this.state=987,this.isDefine(),this.state=988,this.vExpr()}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}queryStatement(){let e=new ZR(this._ctx,this.state);this.enterRule(e,170,d.RULE_queryStatement);try{switch(this.state=1008,this._errHandler.sync(this),this.interpreter.adaptivePredict(this._input,100,this._ctx)){case 1:this.enterOuterAlt(e,1),this.state=990,this.groupByStatement();break;case 2:this.enterOuterAlt(e,2),this.state=991,this.declareStatement();break;case 3:this.enterOuterAlt(e,3),this.state=992,this.queryJoinStatement();break;case 4:this.enterOuterAlt(e,4),this.state=993,this.queryExtend();break;case 5:this.enterOuterAlt(e,5),this.state=994,this.projectStatement();break;case 6:this.enterOuterAlt(e,6),this.state=995,this.indexStatement();break;case 7:this.enterOuterAlt(e,7),this.state=996,this.aggregateStatement();break;case 8:this.enterOuterAlt(e,8),this.state=997,this.calculateStatement();break;case 9:this.enterOuterAlt(e,9),this.state=998,this.topStatement();break;case 10:this.enterOuterAlt(e,10),this.state=999,this.limitStatement();break;case 11:this.enterOuterAlt(e,11),this.state=1e3,this.orderByStatement();break;case 12:this.enterOuterAlt(e,12),this.state=1001,this.whereStatement();break;case 13:this.enterOuterAlt(e,13),this.state=1002,this.havingStatement();break;case 14:this.enterOuterAlt(e,14),this.state=1003,this.nestStatement();break;case 15:this.enterOuterAlt(e,15),this.state=1004,this.sampleStatement();break;case 16:this.enterOuterAlt(e,16),this.state=1005,this.timezoneStatement();break;case 17:this.enterOuterAlt(e,17),this.state=1006,this.queryAnnotation();break;case 18:this.enterOuterAlt(e,18),this.state=1007,this.ignoredModelAnnotations();break}}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}queryJoinStatement(){let e=new vM(this._ctx,this.state);this.enterRule(e,172,d.RULE_queryJoinStatement);try{this.enterOuterAlt(e,1),this.state=1010,this.joinStatement()}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}groupByStatement(){let e=new CM(this._ctx,this.state);this.enterRule(e,174,d.RULE_groupByStatement);try{this.enterOuterAlt(e,1),this.state=1012,this.tags(),this.state=1013,this.match(d.GROUP_BY),this.state=1014,this.queryFieldList()}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}queryFieldList(){let e=new HE(this._ctx,this.state);this.enterRule(e,176,d.RULE_queryFieldList);let r;try{let i;this.enterOuterAlt(e,1);{for(this.state=1016,this.queryFieldEntry(),this.state=1023,this._errHandler.sync(this),i=this.interpreter.adaptivePredict(this._input,102,this._ctx);i!==2&&i!==rn.ATN.INVALID_ALT_NUMBER;)i===1&&(this.state=1018,this._errHandler.sync(this),r=this._input.LA(1),r===d.COMMA&&(this.state=1017,this.match(d.COMMA)),this.state=1020,this.queryFieldEntry()),this.state=1025,this._errHandler.sync(this),i=this.interpreter.adaptivePredict(this._input,102,this._ctx);this.state=1027,this._errHandler.sync(this),r=this._input.LA(1),r===d.COMMA&&(this.state=1026,this.match(d.COMMA))}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}queryFieldEntry(){let e=new eD(this._ctx,this.state);this.enterRule(e,178,d.RULE_queryFieldEntry);try{switch(this.state=1031,this._errHandler.sync(this),this.interpreter.adaptivePredict(this._input,104,this._ctx)){case 1:this.enterOuterAlt(e,1),this.state=1029,this.taggedRef();break;case 2:this.enterOuterAlt(e,2),this.state=1030,this.fieldDef();break}}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}nestStatement(){let e=new SM(this._ctx,this.state);this.enterRule(e,180,d.RULE_nestStatement);try{this.enterOuterAlt(e,1),this.state=1033,this.tags(),this.state=1034,this.match(d.NEST),this.state=1035,this.nestedQueryList()}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}nestedQueryList(){let e=new bM(this._ctx,this.state);this.enterRule(e,182,d.RULE_nestedQueryList);let r;try{let i;this.enterOuterAlt(e,1);{for(this.state=1037,this.nestEntry(),this.state=1044,this._errHandler.sync(this),i=this.interpreter.adaptivePredict(this._input,106,this._ctx);i!==2&&i!==rn.ATN.INVALID_ALT_NUMBER;)i===1&&(this.state=1039,this._errHandler.sync(this),r=this._input.LA(1),r===d.COMMA&&(this.state=1038,this.match(d.COMMA)),this.state=1041,this.nestEntry()),this.state=1046,this._errHandler.sync(this),i=this.interpreter.adaptivePredict(this._input,106,this._ctx);this.state=1048,this._errHandler.sync(this),r=this._input.LA(1),r===d.COMMA&&(this.state=1047,this.match(d.COMMA))}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}nestEntry(){let e=new QE(this._ctx,this.state);this.enterRule(e,184,d.RULE_nestEntry);try{e=new wfe(e),this.enterOuterAlt(e,1);{switch(this.state=1050,this.tags(),this.state=1054,this._errHandler.sync(this),this.interpreter.adaptivePredict(this._input,108,this._ctx)){case 1:this.state=1051,this.queryName(),this.state=1052,this.isDefine();break}this.state=1056,this.vExpr()}}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}aggregateStatement(){let e=new TM(this._ctx,this.state);this.enterRule(e,186,d.RULE_aggregateStatement);try{this.enterOuterAlt(e,1),this.state=1058,this.tags(),this.state=1059,this.match(d.AGGREGATE),this.state=1060,this.queryFieldList()}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}calculateStatement(){let e=new RM(this._ctx,this.state);this.enterRule(e,188,d.RULE_calculateStatement);try{this.enterOuterAlt(e,1),this.state=1062,this.tags(),this.state=1063,this.match(d.CALCULATE),this.state=1064,this.queryFieldList()}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}projectStatement(){let e=new DM(this._ctx,this.state);this.enterRule(e,190,d.RULE_projectStatement);try{this.enterOuterAlt(e,1),this.state=1066,this.tags(),this.state=1067,this.match(d.SELECT),this.state=1068,this.fieldCollection()}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}partitionByStatement(){let e=new OM(this._ctx,this.state);this.enterRule(e,192,d.RULE_partitionByStatement);let r;try{let i;this.enterOuterAlt(e,1);{for(this.state=1070,this.match(d.PARTITION_BY),this.state=1071,this.id(),this.state=1076,this._errHandler.sync(this),i=this.interpreter.adaptivePredict(this._input,109,this._ctx);i!==2&&i!==rn.ATN.INVALID_ALT_NUMBER;)i===1&&(this.state=1072,this.match(d.COMMA),this.state=1073,this.id()),this.state=1078,this._errHandler.sync(this),i=this.interpreter.adaptivePredict(this._input,109,this._ctx);this.state=1080,this._errHandler.sync(this),r=this._input.LA(1),r===d.COMMA&&(this.state=1079,this.match(d.COMMA))}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}orderByStatement(){let e=new FM(this._ctx,this.state);this.enterRule(e,194,d.RULE_orderByStatement);try{this.enterOuterAlt(e,1),this.state=1082,this.match(d.ORDER_BY),this.state=1083,this.ordering()}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}ordering(){let e=new wM(this._ctx,this.state);this.enterRule(e,196,d.RULE_ordering);let r;try{let i;this.enterOuterAlt(e,1);{for(this.state=1085,this.orderBySpec(),this.state=1092,this._errHandler.sync(this),i=this.interpreter.adaptivePredict(this._input,112,this._ctx);i!==2&&i!==rn.ATN.INVALID_ALT_NUMBER;)i===1&&(this.state=1087,this._errHandler.sync(this),r=this._input.LA(1),r===d.COMMA&&(this.state=1086,this.match(d.COMMA)),this.state=1089,this.orderBySpec()),this.state=1094,this._errHandler.sync(this),i=this.interpreter.adaptivePredict(this._input,112,this._ctx);this.state=1096,this._errHandler.sync(this),r=this._input.LA(1),r===d.COMMA&&(this.state=1095,this.match(d.COMMA))}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}orderBySpec(){let e=new tD(this._ctx,this.state);this.enterRule(e,198,d.RULE_orderBySpec);let r;try{this.enterOuterAlt(e,1);{switch(this.state=1100,this._errHandler.sync(this),this._input.LA(1)){case d.INTEGER_LITERAL:this.state=1098,this.match(d.INTEGER_LITERAL);break;case d.BQ_STRING:case d.IDENTIFIER:this.state=1099,this.fieldName();break;default:throw new sn.NoViableAltException(this)}this.state=1103,this._errHandler.sync(this),r=this._input.LA(1),(r===d.ASC||r===d.DESC)&&(this.state=1102,r=this._input.LA(1),r===d.ASC||r===d.DESC?(this._input.LA(1)===Wn.Token.EOF&&(this.matchedEOF=!0),this._errHandler.reportMatch(this),this.consume()):this._errHandler.recoverInline(this))}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}limitStatement(){let e=new nD(this._ctx,this.state);this.enterRule(e,200,d.RULE_limitStatement);try{this.enterOuterAlt(e,1),this.state=1105,this.match(d.LIMIT),this.state=1106,this.match(d.INTEGER_LITERAL)}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}bySpec(){let e=new Nfe(this._ctx,this.state);this.enterRule(e,202,d.RULE_bySpec);try{switch(this.state=1112,this._errHandler.sync(this),this.interpreter.adaptivePredict(this._input,116,this._ctx)){case 1:this.enterOuterAlt(e,1),this.state=1108,this.match(d.BY),this.state=1109,this.fieldName();break;case 2:this.enterOuterAlt(e,2),this.state=1110,this.match(d.BY),this.state=1111,this.fieldExpr(0);break}}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}topStatement(){let e=new NM(this._ctx,this.state);this.enterRule(e,204,d.RULE_topStatement);try{this.enterOuterAlt(e,1),this.state=1114,this.match(d.TOP),this.state=1115,this.match(d.INTEGER_LITERAL)}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}indexElement(){let e=new rD(this._ctx,this.state);this.enterRule(e,206,d.RULE_indexElement);let r;try{switch(this.state=1123,this._errHandler.sync(this),this._input.LA(1)){case d.BQ_STRING:case d.IDENTIFIER:this.enterOuterAlt(e,1),this.state=1117,this.fieldPath(),this.state=1120,this._errHandler.sync(this),r=this._input.LA(1),r===d.DOT&&(this.state=1118,this.match(d.DOT),this.state=1119,this.match(d.STAR));break;case d.STAR:this.enterOuterAlt(e,2),this.state=1122,this.match(d.STAR);break;default:throw new sn.NoViableAltException(this)}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}indexFields(){let e=new LM(this._ctx,this.state);this.enterRule(e,208,d.RULE_indexFields);let r;try{let i;for(this.enterOuterAlt(e,1),this.state=1125,this.indexElement(),this.state=1132,this._errHandler.sync(this),i=this.interpreter.adaptivePredict(this._input,120,this._ctx);i!==2&&i!==rn.ATN.INVALID_ALT_NUMBER;)i===1&&(this.state=1127,this._errHandler.sync(this),r=this._input.LA(1),r===d.COMMA&&(this.state=1126,this.match(d.COMMA)),this.state=1129,this.indexElement()),this.state=1134,this._errHandler.sync(this),i=this.interpreter.adaptivePredict(this._input,120,this._ctx)}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}indexStatement(){let e=new IM(this._ctx,this.state);this.enterRule(e,210,d.RULE_indexStatement);let r;try{this.enterOuterAlt(e,1),this.state=1135,this.match(d.INDEX),this.state=1136,this.indexFields(),this.state=1139,this._errHandler.sync(this),r=this._input.LA(1),r===d.BY&&(this.state=1137,this.match(d.BY),this.state=1138,this.fieldName())}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}sampleStatement(){let e=new $M(this._ctx,this.state);this.enterRule(e,212,d.RULE_sampleStatement);try{this.enterOuterAlt(e,1),this.state=1141,this.match(d.SAMPLE),this.state=1142,this.sampleSpec()}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}timezoneStatement(){let e=new iD(this._ctx,this.state);this.enterRule(e,214,d.RULE_timezoneStatement);try{this.enterOuterAlt(e,1),this.state=1144,this.match(d.TIMEZONE),this.state=1145,this.string()}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}queryAnnotation(){let e=new BM(this._ctx,this.state);this.enterRule(e,216,d.RULE_queryAnnotation);try{this.enterOuterAlt(e,1),this.state=1147,this.match(d.ANNOTATION)}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}sampleSpec(){let e=new kM(this._ctx,this.state);this.enterRule(e,218,d.RULE_sampleSpec);let r;try{this.enterOuterAlt(e,1),this.state=1149,r=this._input.LA(1),r===d.FALSE||r===d.TRUE||r===d.PERCENT_LITERAL||r===d.INTEGER_LITERAL?(this._input.LA(1)===Wn.Token.EOF&&(this.matchedEOF=!0),this._errHandler.reportMatch(this),this.consume()):this._errHandler.recoverInline(this)}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}aggregate(){let e=new zE(this._ctx,this.state);this.enterRule(e,220,d.RULE_aggregate);let r;try{this.enterOuterAlt(e,1),this.state=1151,r=this._input.LA(1),r===d.AVG||r===d.COUNT||!(r-73&-32)&&1<<r-73&(1<<d.MAX-73|1<<d.MIN-73|1<<d.SUM-73)?(this._input.LA(1)===Wn.Token.EOF&&(this.matchedEOF=!0),this._errHandler.reportMatch(this),this.consume()):this._errHandler.recoverInline(this)}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}malloyType(){let e=new WE(this._ctx,this.state);this.enterRule(e,222,d.RULE_malloyType);let r;try{this.enterOuterAlt(e,1),this.state=1153,r=this._input.LA(1),r===d.BOOLEAN||r===d.DATE||!(r-80&-32)&&1<<r-80&(1<<d.NUMBER-80|1<<d.STRING-80|1<<d.TIMESTAMP-80)?(this._input.LA(1)===Wn.Token.EOF&&(this.matchedEOF=!0),this._errHandler.reportMatch(this),this.consume()):this._errHandler.recoverInline(this)}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}compareOp(){let e=new sD(this._ctx,this.state);this.enterRule(e,224,d.RULE_compareOp);let r;try{this.enterOuterAlt(e,1),this.state=1155,r=this._input.LA(1),!(r-134&-32)&&1<<r-134&(1<<d.LT-134|1<<d.GT-134|1<<d.EQ-134|1<<d.NE-134|1<<d.LTE-134|1<<d.GTE-134|1<<d.NOT_MATCH-134|1<<d.MATCH-134)?(this._input.LA(1)===Wn.Token.EOF&&(this.matchedEOF=!0),this._errHandler.reportMatch(this),this.consume()):this._errHandler.recoverInline(this)}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}string(){let e=new za(this._ctx,this.state);this.enterRule(e,226,d.RULE_string);try{switch(this.state=1159,this._errHandler.sync(this),this._input.LA(1)){case d.SQ_STRING:case d.DQ_STRING:this.enterOuterAlt(e,1),this.state=1157,this.shortString();break;case d.SQL_BEGIN:this.enterOuterAlt(e,2),this.state=1158,this.sqlString();break;default:throw new sn.NoViableAltException(this)}}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}shortString(){let e=new oD(this._ctx,this.state);this.enterRule(e,228,d.RULE_shortString);let r;try{this.enterOuterAlt(e,1),this.state=1161,r=this._input.LA(1),r===d.SQ_STRING||r===d.DQ_STRING?(this._input.LA(1)===Wn.Token.EOF&&(this.matchedEOF=!0),this._errHandler.reportMatch(this),this.consume()):this._errHandler.recoverInline(this)}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}rawString(){let e=new MM(this._ctx,this.state);this.enterRule(e,230,d.RULE_rawString);let r;try{this.enterOuterAlt(e,1),this.state=1163,r=this._input.LA(1),r===d.RAW_SQ||r===d.RAW_DQ?(this._input.LA(1)===Wn.Token.EOF&&(this.matchedEOF=!0),this._errHandler.reportMatch(this),this.consume()):this._errHandler.recoverInline(this)}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}numericLiteral(){let e=new PM(this._ctx,this.state);this.enterRule(e,232,d.RULE_numericLiteral);let r;try{this.enterOuterAlt(e,1),this.state=1165,r=this._input.LA(1),r===d.NUMERIC_LITERAL||r===d.INTEGER_LITERAL?(this._input.LA(1)===Wn.Token.EOF&&(this.matchedEOF=!0),this._errHandler.reportMatch(this),this.consume()):this._errHandler.recoverInline(this)}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}literal(){let e=new Oo(this._ctx,this.state);this.enterRule(e,234,d.RULE_literal);let r;try{switch(this.state=1176,this._errHandler.sync(this),this._input.LA(1)){case d.SQ_STRING:case d.DQ_STRING:case d.SQL_BEGIN:e=new Lfe(e),this.enterOuterAlt(e,1),this.state=1167,this.string();break;case d.RAW_SQ:case d.RAW_DQ:e=new Ife(e),this.enterOuterAlt(e,2),this.state=1168,this.rawString();break;case d.NUMERIC_LITERAL:case d.INTEGER_LITERAL:e=new $fe(e),this.enterOuterAlt(e,3),this.state=1169,this.numericLiteral();break;case d.LITERAL_TIMESTAMP:case d.LITERAL_HOUR:case d.LITERAL_DAY:case d.LITERAL_QUARTER:case d.LITERAL_MONTH:case d.LITERAL_WEEK:case d.LITERAL_YEAR:e=new Bfe(e),this.enterOuterAlt(e,4),this.state=1170,this.dateLiteral();break;case d.NULL:e=new kfe(e),this.enterOuterAlt(e,5),this.state=1171,this.match(d.NULL);break;case d.FALSE:case d.TRUE:e=new Mfe(e),this.enterOuterAlt(e,6),this.state=1172,r=this._input.LA(1),r===d.FALSE||r===d.TRUE?(this._input.LA(1)===Wn.Token.EOF&&(this.matchedEOF=!0),this._errHandler.reportMatch(this),this.consume()):this._errHandler.recoverInline(this);break;case d.HACKY_REGEX:e=new Pfe(e),this.enterOuterAlt(e,7),this.state=1173,this.match(d.HACKY_REGEX);break;case d.SQ3_FILTER:case d.SQ_FILTER:case d.DQ3_FILTER:case d.DQ_FILTER:case d.BQ3_FILTER:case d.BQ_FILTER:e=new Ufe(e),this.enterOuterAlt(e,8),this.state=1174,this.filterString();break;case d.NOW:e=new jfe(e),this.enterOuterAlt(e,9),this.state=1175,this.match(d.NOW);break;default:throw new sn.NoViableAltException(this)}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}dateLiteral(){let e=new Wa(this._ctx,this.state);this.enterRule(e,236,d.RULE_dateLiteral);try{switch(this.state=1185,this._errHandler.sync(this),this._input.LA(1)){case d.LITERAL_TIMESTAMP:e=new qfe(e),this.enterOuterAlt(e,1),this.state=1178,this.match(d.LITERAL_TIMESTAMP);break;case d.LITERAL_HOUR:e=new Hfe(e),this.enterOuterAlt(e,2),this.state=1179,this.match(d.LITERAL_HOUR);break;case d.LITERAL_DAY:e=new Qfe(e),this.enterOuterAlt(e,3),this.state=1180,this.match(d.LITERAL_DAY);break;case d.LITERAL_WEEK:e=new zfe(e),this.enterOuterAlt(e,4),this.state=1181,this.match(d.LITERAL_WEEK);break;case d.LITERAL_MONTH:e=new Wfe(e),this.enterOuterAlt(e,5),this.state=1182,this.match(d.LITERAL_MONTH);break;case d.LITERAL_QUARTER:e=new Gfe(e),this.enterOuterAlt(e,6),this.state=1183,this.match(d.LITERAL_QUARTER);break;case d.LITERAL_YEAR:e=new Vfe(e),this.enterOuterAlt(e,7),this.state=1184,this.match(d.LITERAL_YEAR);break;default:throw new sn.NoViableAltException(this)}}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}tablePath(){let e=new UM(this._ctx,this.state);this.enterRule(e,238,d.RULE_tablePath);try{this.enterOuterAlt(e,1),this.state=1187,this.string()}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}tableURI(){let e=new Yfe(this._ctx,this.state);this.enterRule(e,240,d.RULE_tableURI);try{this.enterOuterAlt(e,1),this.state=1189,this.string()}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}id(){let e=new Nn(this._ctx,this.state);this.enterRule(e,242,d.RULE_id);let r;try{this.enterOuterAlt(e,1),this.state=1191,r=this._input.LA(1),r===d.BQ_STRING||r===d.IDENTIFIER?(this._input.LA(1)===Wn.Token.EOF&&(this.matchedEOF=!0),this._errHandler.reportMatch(this),this.consume()):this._errHandler.recoverInline(this)}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}timeframe(){let e=new Ld(this._ctx,this.state);this.enterRule(e,244,d.RULE_timeframe);let r;try{this.enterOuterAlt(e,1),this.state=1193,r=this._input.LA(1),!(r-49&-32)&&1<<r-49&(1<<d.DAY-49|1<<d.HOUR-49|1<<d.MINUTE-49|1<<d.MONTH-49)||!(r-86&-32)&&1<<r-86&(1<<d.QUARTER-86|1<<d.SECOND-86|1<<d.WEEK-86|1<<d.YEAR-86)?(this._input.LA(1)===Wn.Token.EOF&&(this.matchedEOF=!0),this._errHandler.reportMatch(this),this.consume()):this._errHandler.recoverInline(this)}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}ungroup(){let e=new jM(this._ctx,this.state);this.enterRule(e,246,d.RULE_ungroup);let r;try{this.enterOuterAlt(e,1),this.state=1195,r=this._input.LA(1),r===d.ALL||r===d.EXCLUDE?(this._input.LA(1)===Wn.Token.EOF&&(this.matchedEOF=!0),this._errHandler.reportMatch(this),this.consume()):this._errHandler.recoverInline(this)}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}malloyOrSQLType(){let e=new uD(this._ctx,this.state);this.enterRule(e,248,d.RULE_malloyOrSQLType);try{switch(this.state=1199,this._errHandler.sync(this),this._input.LA(1)){case d.BOOLEAN:case d.DATE:case d.NUMBER:case d.STRING:case d.TIMESTAMP:this.enterOuterAlt(e,1),this.state=1197,this.malloyType();break;case d.SQ_STRING:case d.DQ_STRING:case d.SQL_BEGIN:this.enterOuterAlt(e,2),this.state=1198,this.string();break;default:throw new sn.NoViableAltException(this)}}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}fieldExpr(e){e===void 0&&(e=0);let r=this._ctx,i=this.state,s=new Re(this._ctx,i),o=s,u=250;this.enterRecursionRule(s,250,d.RULE_fieldExpr,e);let a;try{let l;this.enterOuterAlt(s,1);{switch(this.state=1303,this._errHandler.sync(this),this.interpreter.adaptivePredict(this._input,138,this._ctx)){case 1:s=new Kfe(s),this._ctx=s,o=s,this.state=1202,this.fieldPath();break;case 2:s=new Jfe(s),this._ctx=s,o=s,this.state=1203,this.literal();break;case 3:{for(s=new Xfe(s),this._ctx=s,o=s,this.state=1204,this.match(d.OBRACK),this.state=1205,this.fieldExpr(0),this.state=1210,this._errHandler.sync(this),l=this.interpreter.adaptivePredict(this._input,126,this._ctx);l!==2&&l!==rn.ATN.INVALID_ALT_NUMBER;)l===1&&(this.state=1206,this.match(d.COMMA),this.state=1207,this.fieldExpr(0)),this.state=1212,this._errHandler.sync(this),l=this.interpreter.adaptivePredict(this._input,126,this._ctx);this.state=1214,this._errHandler.sync(this),a=this._input.LA(1),a===d.COMMA&&(this.state=1213,this.match(d.COMMA)),this.state=1216,this.match(d.CBRACK)}break;case 4:{for(s=new Zfe(s),this._ctx=s,o=s,this.state=1218,this.match(d.OCURLY),this.state=1219,this.recordElement(),this.state=1224,this._errHandler.sync(this),a=this._input.LA(1);a===d.COMMA;)this.state=1220,this.match(d.COMMA),this.state=1221,this.recordElement(),this.state=1226,this._errHandler.sync(this),a=this._input.LA(1);this.state=1227,this.match(d.CCURLY)}break;case 5:s=new ixe(s),this._ctx=s,o=s,this.state=1229,this.match(d.MINUS),this.state=1230,this.fieldExpr(25);break;case 6:s=new mxe(s),this._ctx=s,o=s,this.state=1231,this.match(d.NOT),this.state=1232,this.fieldExpr(13);break;case 7:s=new qM(s),this._ctx=s,o=s,this.state=1233,this.match(d.CAST),this.state=1234,this.match(d.OPAREN),this.state=1235,this.fieldExpr(0),this.state=1236,this.match(d.AS),this.state=1237,this.malloyOrSQLType(),this.state=1238,this.match(d.CPAREN);break;case 8:s=new Axe(s),this._ctx=s,o=s,this.state=1242,this._errHandler.sync(this),a=this._input.LA(1),a===d.SOURCE_KW&&(this.state=1240,this.match(d.SOURCE_KW),this.state=1241,this.match(d.DOT)),this.state=1244,this.aggregate(),this.state=1245,this.match(d.OPAREN),this.state=1247,this._errHandler.sync(this),a=this._input.LA(1),(!(a-36&-32)&&1<<a-36&(1<<d.ALL-36|1<<d.AVG-36|1<<d.CASE-36|1<<d.CAST-36|1<<d.COUNT-36|1<<d.DAY-36|1<<d.EXCLUDE-36|1<<d.FALSE-36|1<<d.HOUR-36)||!(a-73&-32)&&1<<a-73&(1<<d.MAX-73|1<<d.MIN-73|1<<d.MINUTE-73|1<<d.MONTH-73|1<<d.NOT-73|1<<d.NOW-73|1<<d.NULL-73|1<<d.PICK-73|1<<d.QUARTER-73|1<<d.SECOND-73|1<<d.SOURCE_KW-73|1<<d.SUM-73|1<<d.TRUE-73|1<<d.WEEK-73|1<<d.YEAR-73)||!(a-105&-32)&&1<<a-105&(1<<d.HACKY_REGEX-105|1<<d.RAW_SQ-105|1<<d.RAW_DQ-105|1<<d.SQ3_FILTER-105|1<<d.SQ_FILTER-105|1<<d.DQ3_FILTER-105|1<<d.DQ_FILTER-105|1<<d.BQ3_FILTER-105|1<<d.BQ_FILTER-105|1<<d.SQ_STRING-105|1<<d.DQ_STRING-105|1<<d.BQ_STRING-105|1<<d.OPAREN-105|1<<d.OBRACK-105|1<<d.OCURLY-105)||!(a-141&-32)&&1<<a-141&(1<<d.MINUS-141|1<<d.LITERAL_TIMESTAMP-141|1<<d.LITERAL_HOUR-141|1<<d.LITERAL_DAY-141|1<<d.LITERAL_QUARTER-141|1<<d.LITERAL_MONTH-141|1<<d.LITERAL_WEEK-141|1<<d.LITERAL_YEAR-141|1<<d.IDENTIFIER-141|1<<d.NUMERIC_LITERAL-141|1<<d.INTEGER_LITERAL-141|1<<d.SQL_BEGIN-141))&&(this.state=1246,this.fieldExpr(0)),this.state=1249,this.match(d.CPAREN);break;case 9:s=new _xe(s),this._ctx=s,o=s,this.state=1251,this.fieldPath(),this.state=1252,this.match(d.DOT),this.state=1253,this.aggregate(),this.state=1254,this.match(d.OPAREN),this.state=1256,this._errHandler.sync(this),a=this._input.LA(1),(!(a-36&-32)&&1<<a-36&(1<<d.ALL-36|1<<d.AVG-36|1<<d.CASE-36|1<<d.CAST-36|1<<d.COUNT-36|1<<d.DAY-36|1<<d.EXCLUDE-36|1<<d.FALSE-36|1<<d.HOUR-36)||!(a-73&-32)&&1<<a-73&(1<<d.MAX-73|1<<d.MIN-73|1<<d.MINUTE-73|1<<d.MONTH-73|1<<d.NOT-73|1<<d.NOW-73|1<<d.NULL-73|1<<d.PICK-73|1<<d.QUARTER-73|1<<d.SECOND-73|1<<d.SOURCE_KW-73|1<<d.SUM-73|1<<d.TRUE-73|1<<d.WEEK-73|1<<d.YEAR-73)||!(a-105&-32)&&1<<a-105&(1<<d.HACKY_REGEX-105|1<<d.RAW_SQ-105|1<<d.RAW_DQ-105|1<<d.SQ3_FILTER-105|1<<d.SQ_FILTER-105|1<<d.DQ3_FILTER-105|1<<d.DQ_FILTER-105|1<<d.BQ3_FILTER-105|1<<d.BQ_FILTER-105|1<<d.SQ_STRING-105|1<<d.DQ_STRING-105|1<<d.BQ_STRING-105|1<<d.OPAREN-105|1<<d.OBRACK-105|1<<d.OCURLY-105)||!(a-141&-32)&&1<<a-141&(1<<d.MINUS-141|1<<d.LITERAL_TIMESTAMP-141|1<<d.LITERAL_HOUR-141|1<<d.LITERAL_DAY-141|1<<d.LITERAL_QUARTER-141|1<<d.LITERAL_MONTH-141|1<<d.LITERAL_WEEK-141|1<<d.LITERAL_YEAR-141|1<<d.IDENTIFIER-141|1<<d.NUMERIC_LITERAL-141|1<<d.INTEGER_LITERAL-141|1<<d.SQL_BEGIN-141))&&(this.state=1255,this.fieldExpr(0)),this.state=1258,this.match(d.CPAREN);break;case 10:s=new vxe(s),this._ctx=s,o=s,this.state=1260,this.match(d.OPAREN),this.state=1261,this.fieldExpr(0),this.state=1262,this.match(d.CPAREN);break;case 11:s=new Cxe(s),this._ctx=s,o=s,this.state=1264,this.fieldPath(),this.state=1265,this.match(d.DOT),this.state=1266,this.id(),this.state=1267,this.match(d.OPAREN),this.state=1269,this._errHandler.sync(this),a=this._input.LA(1),(!(a-36&-32)&&1<<a-36&(1<<d.ALL-36|1<<d.AVG-36|1<<d.CASE-36|1<<d.CAST-36|1<<d.COUNT-36|1<<d.DAY-36|1<<d.EXCLUDE-36|1<<d.FALSE-36|1<<d.HOUR-36)||!(a-73&-32)&&1<<a-73&(1<<d.MAX-73|1<<d.MIN-73|1<<d.MINUTE-73|1<<d.MONTH-73|1<<d.NOT-73|1<<d.NOW-73|1<<d.NULL-73|1<<d.PICK-73|1<<d.QUARTER-73|1<<d.SECOND-73|1<<d.SOURCE_KW-73|1<<d.SUM-73|1<<d.TRUE-73|1<<d.WEEK-73|1<<d.YEAR-73)||!(a-105&-32)&&1<<a-105&(1<<d.HACKY_REGEX-105|1<<d.RAW_SQ-105|1<<d.RAW_DQ-105|1<<d.SQ3_FILTER-105|1<<d.SQ_FILTER-105|1<<d.DQ3_FILTER-105|1<<d.DQ_FILTER-105|1<<d.BQ3_FILTER-105|1<<d.BQ_FILTER-105|1<<d.SQ_STRING-105|1<<d.DQ_STRING-105|1<<d.BQ_STRING-105|1<<d.OPAREN-105|1<<d.OBRACK-105|1<<d.OCURLY-105)||!(a-141&-32)&&1<<a-141&(1<<d.MINUS-141|1<<d.LITERAL_TIMESTAMP-141|1<<d.LITERAL_HOUR-141|1<<d.LITERAL_DAY-141|1<<d.LITERAL_QUARTER-141|1<<d.LITERAL_MONTH-141|1<<d.LITERAL_WEEK-141|1<<d.LITERAL_YEAR-141|1<<d.IDENTIFIER-141|1<<d.NUMERIC_LITERAL-141|1<<d.INTEGER_LITERAL-141|1<<d.SQL_BEGIN-141))&&(this.state=1268,this.argumentList()),this.state=1271,this.match(d.CPAREN);break;case 12:{switch(s=new Sxe(s),this._ctx=s,o=s,this.state=1281,this._errHandler.sync(this),this._input.LA(1)){case d.BQ_STRING:case d.IDENTIFIER:this.state=1273,this.id(),this.state=1278,this._errHandler.sync(this),a=this._input.LA(1),a===d.EXCLAM&&(this.state=1274,this.match(d.EXCLAM),this.state=1276,this._errHandler.sync(this),a=this._input.LA(1),(a===d.BOOLEAN||a===d.DATE||!(a-80&-32)&&1<<a-80&(1<<d.NUMBER-80|1<<d.STRING-80|1<<d.TIMESTAMP-80))&&(this.state=1275,this.malloyType()));break;case d.DAY:case d.HOUR:case d.MINUTE:case d.MONTH:case d.QUARTER:case d.SECOND:case d.WEEK:case d.YEAR:this.state=1280,this.timeframe();break;default:throw new sn.NoViableAltException(this)}this.state=1283,this.match(d.OPAREN),this.state=1285,this._errHandler.sync(this),a=this._input.LA(1),(!(a-36&-32)&&1<<a-36&(1<<d.ALL-36|1<<d.AVG-36|1<<d.CASE-36|1<<d.CAST-36|1<<d.COUNT-36|1<<d.DAY-36|1<<d.EXCLUDE-36|1<<d.FALSE-36|1<<d.HOUR-36)||!(a-73&-32)&&1<<a-73&(1<<d.MAX-73|1<<d.MIN-73|1<<d.MINUTE-73|1<<d.MONTH-73|1<<d.NOT-73|1<<d.NOW-73|1<<d.NULL-73|1<<d.PICK-73|1<<d.QUARTER-73|1<<d.SECOND-73|1<<d.SOURCE_KW-73|1<<d.SUM-73|1<<d.TRUE-73|1<<d.WEEK-73|1<<d.YEAR-73)||!(a-105&-32)&&1<<a-105&(1<<d.HACKY_REGEX-105|1<<d.RAW_SQ-105|1<<d.RAW_DQ-105|1<<d.SQ3_FILTER-105|1<<d.SQ_FILTER-105|1<<d.DQ3_FILTER-105|1<<d.DQ_FILTER-105|1<<d.BQ3_FILTER-105|1<<d.BQ_FILTER-105|1<<d.SQ_STRING-105|1<<d.DQ_STRING-105|1<<d.BQ_STRING-105|1<<d.OPAREN-105|1<<d.OBRACK-105|1<<d.OCURLY-105)||!(a-141&-32)&&1<<a-141&(1<<d.MINUS-141|1<<d.LITERAL_TIMESTAMP-141|1<<d.LITERAL_HOUR-141|1<<d.LITERAL_DAY-141|1<<d.LITERAL_QUARTER-141|1<<d.LITERAL_MONTH-141|1<<d.LITERAL_WEEK-141|1<<d.LITERAL_YEAR-141|1<<d.IDENTIFIER-141|1<<d.NUMERIC_LITERAL-141|1<<d.INTEGER_LITERAL-141|1<<d.SQL_BEGIN-141))&&(this.state=1284,this.argumentList()),this.state=1287,this.match(d.CPAREN)}break;case 13:s=new bxe(s),this._ctx=s,o=s,this.state=1289,this.pickStatement();break;case 14:s=new Txe(s),this._ctx=s,o=s,this.state=1290,this.caseStatement();break;case 15:{for(s=new Rxe(s),this._ctx=s,o=s,this.state=1291,this.ungroup(),this.state=1292,this.match(d.OPAREN),this.state=1293,this.fieldExpr(0),this.state=1298,this._errHandler.sync(this),a=this._input.LA(1);a===d.COMMA;)this.state=1294,this.match(d.COMMA),this.state=1295,this.fieldName(),this.state=1300,this._errHandler.sync(this),a=this._input.LA(1);this.state=1301,this.match(d.CPAREN)}break}for(this._ctx._stop=this._input.tryLT(-1),this.state=1377,this._errHandler.sync(this),l=this.interpreter.adaptivePredict(this._input,143,this._ctx);l!==2&&l!==rn.ATN.INVALID_ALT_NUMBER;){if(l===1)switch(this._parseListeners!=null&&this.triggerExitRuleEvent(),o=s,this.state=1375,this._errHandler.sync(this),this.interpreter.adaptivePredict(this._input,142,this._ctx)){case 1:{if(s=new sxe(new Re(r,i)),this.pushNewRecursionContext(s,u,d.RULE_fieldExpr),this.state=1305,!this.precpred(this._ctx,24))throw this.createFailedPredicateException("this.precpred(this._ctx, 24)");this.state=1306,a=this._input.LA(1),!(a-142&-32)&&1<<a-142&(1<<d.STAR-142|1<<d.SLASH-142|1<<d.PERCENT-142)?(this._input.LA(1)===Wn.Token.EOF&&(this.matchedEOF=!0),this._errHandler.reportMatch(this),this.consume()):this._errHandler.recoverInline(this),this.state=1307,this.fieldExpr(25)}break;case 2:{if(s=new oxe(new Re(r,i)),this.pushNewRecursionContext(s,u,d.RULE_fieldExpr),this.state=1308,!this.precpred(this._ctx,23))throw this.createFailedPredicateException("this.precpred(this._ctx, 23)");this.state=1309,a=this._input.LA(1),a===d.PLUS||a===d.MINUS?(this._input.LA(1)===Wn.Token.EOF&&(this.matchedEOF=!0),this._errHandler.reportMatch(this),this.consume()):this._errHandler.recoverInline(this),this.state=1310,this.fieldExpr(24)}break;case 3:{if(s=new uxe(new Re(r,i)),this.pushNewRecursionContext(s,u,d.RULE_fieldExpr),this.state=1311,!this.precpred(this._ctx,22))throw this.createFailedPredicateException("this.precpred(this._ctx, 22)");this.state=1312,this.match(d.TO),this.state=1313,this.fieldExpr(23)}break;case 4:{if(s=new fxe(new Re(r,i)),this.pushNewRecursionContext(s,u,d.RULE_fieldExpr),this.state=1314,!this.precpred(this._ctx,18))throw this.createFailedPredicateException("this.precpred(this._ctx, 18)");this.state=1315,this.compareOp(),this.state=1316,this.fieldExpr(19)}break;case 5:{if(s=new xxe(new Re(r,i)),this.pushNewRecursionContext(s,u,d.RULE_fieldExpr),this.state=1318,!this.precpred(this._ctx,17))throw this.createFailedPredicateException("this.precpred(this._ctx, 17)");this.state=1320,this._errHandler.sync(this),a=this._input.LA(1),a===d.NOT&&(this.state=1319,this.match(d.NOT)),this.state=1322,this.match(d.LIKE),this.state=1323,this.fieldExpr(18)}break;case 6:{if(s=new gxe(new Re(r,i)),this.pushNewRecursionContext(s,u,d.RULE_fieldExpr),this.state=1324,!this.precpred(this._ctx,12))throw this.createFailedPredicateException("this.precpred(this._ctx, 12)");this.state=1325,this.match(d.AND),this.state=1326,this.fieldExpr(13)}break;case 7:{if(s=new yxe(new Re(r,i)),this.pushNewRecursionContext(s,u,d.RULE_fieldExpr),this.state=1327,!this.precpred(this._ctx,11))throw this.createFailedPredicateException("this.precpred(this._ctx, 11)");this.state=1328,this.match(d.OR),this.state=1329,this.fieldExpr(12)}break;case 8:{if(s=new Exe(new Re(r,i)),this.pushNewRecursionContext(s,u,d.RULE_fieldExpr),this.state=1330,!this.precpred(this._ctx,10))throw this.createFailedPredicateException("this.precpred(this._ctx, 10)");this.state=1331,this.match(d.DOUBLE_QMARK),this.state=1332,this.fieldExpr(11)}break;case 9:{if(s=new exe(new Re(r,i)),this.pushNewRecursionContext(s,u,d.RULE_fieldExpr),this.state=1333,!this.precpred(this._ctx,30))throw this.createFailedPredicateException("this.precpred(this._ctx, 30)");this.state=1334,this.fieldProperties()}break;case 10:{if(s=new txe(new Re(r,i)),this.pushNewRecursionContext(s,u,d.RULE_fieldExpr),this.state=1335,!this.precpred(this._ctx,29))throw this.createFailedPredicateException("this.precpred(this._ctx, 29)");this.state=1336,this.timeframe()}break;case 11:{if(s=new nxe(new Re(r,i)),this.pushNewRecursionContext(s,u,d.RULE_fieldExpr),this.state=1337,!this.precpred(this._ctx,28))throw this.createFailedPredicateException("this.precpred(this._ctx, 28)");this.state=1338,this.match(d.DOT),this.state=1339,this.timeframe()}break;case 12:{if(s=new qM(new Re(r,i)),this.pushNewRecursionContext(s,u,d.RULE_fieldExpr),this.state=1340,!this.precpred(this._ctx,27))throw this.createFailedPredicateException("this.precpred(this._ctx, 27)");this.state=1341,this.match(d.DOUBLECOLON),this.state=1342,this.malloyOrSQLType()}break;case 13:{if(s=new rxe(new Re(r,i)),this.pushNewRecursionContext(s,u,d.RULE_fieldExpr),this.state=1343,!this.precpred(this._ctx,26))throw this.createFailedPredicateException("this.precpred(this._ctx, 26)");this.state=1344,this.match(d.TRIPLECOLON),this.state=1345,this.malloyOrSQLType()}break;case 14:{if(s=new axe(new Re(r,i)),s._startAt=o,this.pushNewRecursionContext(s,u,d.RULE_fieldExpr),this.state=1346,!this.precpred(this._ctx,21))throw this.createFailedPredicateException("this.precpred(this._ctx, 21)");this.state=1347,this.match(d.FOR),this.state=1348,s._duration=this.fieldExpr(0),this.state=1349,this.timeframe()}break;case 15:{if(s=new lxe(new Re(r,i)),this.pushNewRecursionContext(s,u,d.RULE_fieldExpr),this.state=1351,!this.precpred(this._ctx,20))throw this.createFailedPredicateException("this.precpred(this._ctx, 20)");this.state=1352,this.match(d.AMPER),this.state=1353,this.partialAllowedFieldExpr()}break;case 16:{if(s=new cxe(new Re(r,i)),this.pushNewRecursionContext(s,u,d.RULE_fieldExpr),this.state=1354,!this.precpred(this._ctx,19))throw this.createFailedPredicateException("this.precpred(this._ctx, 19)");this.state=1355,this.match(d.BAR),this.state=1356,this.partialAllowedFieldExpr()}break;case 17:{if(s=new dxe(new Re(r,i)),this.pushNewRecursionContext(s,u,d.RULE_fieldExpr),this.state=1357,!this.precpred(this._ctx,16))throw this.createFailedPredicateException("this.precpred(this._ctx, 16)");this.state=1358,this.match(d.IS),this.state=1360,this._errHandler.sync(this),a=this._input.LA(1),a===d.NOT&&(this.state=1359,this.match(d.NOT)),this.state=1362,this.match(d.NULL)}break;case 18:{if(s=new hxe(new Re(r,i)),this.pushNewRecursionContext(s,u,d.RULE_fieldExpr),this.state=1363,!this.precpred(this._ctx,15))throw this.createFailedPredicateException("this.precpred(this._ctx, 15)");this.state=1365,this._errHandler.sync(this),a=this._input.LA(1),a===d.NOT&&(this.state=1364,this.match(d.NOT)),this.state=1367,this.match(d.IN),this.state=1368,this.match(d.OPAREN),this.state=1369,this.fieldExprList(),this.state=1370,this.match(d.CPAREN)}break;case 19:{if(s=new pxe(new Re(r,i)),this.pushNewRecursionContext(s,u,d.RULE_fieldExpr),this.state=1372,!this.precpred(this._ctx,14))throw this.createFailedPredicateException("this.precpred(this._ctx, 14)");this.state=1373,this.match(d.QMARK),this.state=1374,this.partialAllowedFieldExpr()}break}this.state=1379,this._errHandler.sync(this),l=this.interpreter.adaptivePredict(this._input,143,this._ctx)}}}catch(l){if(l instanceof ye.RecognitionException)s.exception=l,this._errHandler.reportError(this,l),this._errHandler.recover(this,l);else throw l}finally{this.unrollRecursionContexts(r)}return s}partialCompare(){let e=new HM(this._ctx,this.state);this.enterRule(e,252,d.RULE_partialCompare);try{this.enterOuterAlt(e,1),this.state=1380,this.compareOp(),this.state=1381,this.fieldExpr(0)}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}partialTest(){let e=new QM(this._ctx,this.state);this.enterRule(e,254,d.RULE_partialTest);let r;try{switch(this.state=1389,this._errHandler.sync(this),this._input.LA(1)){case d.LT:case d.GT:case d.EQ:case d.NE:case d.LTE:case d.GTE:case d.NOT_MATCH:case d.MATCH:this.enterOuterAlt(e,1),this.state=1383,this.partialCompare();break;case d.IS:this.enterOuterAlt(e,2),this.state=1384,this.match(d.IS),this.state=1386,this._errHandler.sync(this),r=this._input.LA(1),r===d.NOT&&(this.state=1385,this.match(d.NOT)),this.state=1388,this.match(d.NULL);break;default:throw new sn.NoViableAltException(this)}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}partialAllowedFieldExpr(){let e=new Id(this._ctx,this.state);this.enterRule(e,256,d.RULE_partialAllowedFieldExpr);try{switch(this.state=1397,this._errHandler.sync(this),this.interpreter.adaptivePredict(this._input,146,this._ctx)){case 1:this.enterOuterAlt(e,1),this.state=1391,this.partialTest();break;case 2:this.enterOuterAlt(e,2),this.state=1392,this.match(d.OPAREN),this.state=1393,this.partialTest(),this.state=1394,this.match(d.CPAREN);break;case 3:this.enterOuterAlt(e,3),this.state=1396,this.fieldExpr(0);break}}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}fieldExprList(){let e=new zM(this._ctx,this.state);this.enterRule(e,258,d.RULE_fieldExprList);let r;try{for(this.enterOuterAlt(e,1),this.state=1399,this.fieldExpr(0),this.state=1404,this._errHandler.sync(this),r=this._input.LA(1);r===d.COMMA;)this.state=1400,this.match(d.COMMA),this.state=1401,this.fieldExpr(0),this.state=1406,this._errHandler.sync(this),r=this._input.LA(1)}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}pickStatement(){let e=new WM(this._ctx,this.state);this.enterRule(e,260,d.RULE_pickStatement);try{let r;this.enterOuterAlt(e,1);{this.state=1408,this._errHandler.sync(this),r=1;do{switch(r){case 1:this.state=1407,this.pick();break;default:throw new sn.NoViableAltException(this)}this.state=1410,this._errHandler.sync(this),r=this.interpreter.adaptivePredict(this._input,148,this._ctx)}while(r!==2&&r!==rn.ATN.INVALID_ALT_NUMBER);switch(this.state=1414,this._errHandler.sync(this),this.interpreter.adaptivePredict(this._input,149,this._ctx)){case 1:this.state=1412,this.match(d.ELSE),this.state=1413,e._pickElse=this.fieldExpr(0);break}}}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}pick(){let e=new aD(this._ctx,this.state);this.enterRule(e,262,d.RULE_pick);let r;try{this.enterOuterAlt(e,1),this.state=1416,this.match(d.PICK),this.state=1418,this._errHandler.sync(this),r=this._input.LA(1),(!(r-36&-32)&&1<<r-36&(1<<d.ALL-36|1<<d.AVG-36|1<<d.CASE-36|1<<d.CAST-36|1<<d.COUNT-36|1<<d.DAY-36|1<<d.EXCLUDE-36|1<<d.FALSE-36|1<<d.HOUR-36)||!(r-73&-32)&&1<<r-73&(1<<d.MAX-73|1<<d.MIN-73|1<<d.MINUTE-73|1<<d.MONTH-73|1<<d.NOT-73|1<<d.NOW-73|1<<d.NULL-73|1<<d.PICK-73|1<<d.QUARTER-73|1<<d.SECOND-73|1<<d.SOURCE_KW-73|1<<d.SUM-73|1<<d.TRUE-73|1<<d.WEEK-73|1<<d.YEAR-73)||!(r-105&-32)&&1<<r-105&(1<<d.HACKY_REGEX-105|1<<d.RAW_SQ-105|1<<d.RAW_DQ-105|1<<d.SQ3_FILTER-105|1<<d.SQ_FILTER-105|1<<d.DQ3_FILTER-105|1<<d.DQ_FILTER-105|1<<d.BQ3_FILTER-105|1<<d.BQ_FILTER-105|1<<d.SQ_STRING-105|1<<d.DQ_STRING-105|1<<d.BQ_STRING-105|1<<d.OPAREN-105|1<<d.OBRACK-105|1<<d.OCURLY-105)||!(r-141&-32)&&1<<r-141&(1<<d.MINUS-141|1<<d.LITERAL_TIMESTAMP-141|1<<d.LITERAL_HOUR-141|1<<d.LITERAL_DAY-141|1<<d.LITERAL_QUARTER-141|1<<d.LITERAL_MONTH-141|1<<d.LITERAL_WEEK-141|1<<d.LITERAL_YEAR-141|1<<d.IDENTIFIER-141|1<<d.NUMERIC_LITERAL-141|1<<d.INTEGER_LITERAL-141|1<<d.SQL_BEGIN-141))&&(this.state=1417,e._pickValue=this.fieldExpr(0)),this.state=1420,this.match(d.WHEN),this.state=1421,e._pickWhen=this.partialAllowedFieldExpr()}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}caseStatement(){let e=new GM(this._ctx,this.state);this.enterRule(e,264,d.RULE_caseStatement);let r;try{this.enterOuterAlt(e,1);{this.state=1423,this.match(d.CASE),this.state=1425,this._errHandler.sync(this),r=this._input.LA(1),(!(r-36&-32)&&1<<r-36&(1<<d.ALL-36|1<<d.AVG-36|1<<d.CASE-36|1<<d.CAST-36|1<<d.COUNT-36|1<<d.DAY-36|1<<d.EXCLUDE-36|1<<d.FALSE-36|1<<d.HOUR-36)||!(r-73&-32)&&1<<r-73&(1<<d.MAX-73|1<<d.MIN-73|1<<d.MINUTE-73|1<<d.MONTH-73|1<<d.NOT-73|1<<d.NOW-73|1<<d.NULL-73|1<<d.PICK-73|1<<d.QUARTER-73|1<<d.SECOND-73|1<<d.SOURCE_KW-73|1<<d.SUM-73|1<<d.TRUE-73|1<<d.WEEK-73|1<<d.YEAR-73)||!(r-105&-32)&&1<<r-105&(1<<d.HACKY_REGEX-105|1<<d.RAW_SQ-105|1<<d.RAW_DQ-105|1<<d.SQ3_FILTER-105|1<<d.SQ_FILTER-105|1<<d.DQ3_FILTER-105|1<<d.DQ_FILTER-105|1<<d.BQ3_FILTER-105|1<<d.BQ_FILTER-105|1<<d.SQ_STRING-105|1<<d.DQ_STRING-105|1<<d.BQ_STRING-105|1<<d.OPAREN-105|1<<d.OBRACK-105|1<<d.OCURLY-105)||!(r-141&-32)&&1<<r-141&(1<<d.MINUS-141|1<<d.LITERAL_TIMESTAMP-141|1<<d.LITERAL_HOUR-141|1<<d.LITERAL_DAY-141|1<<d.LITERAL_QUARTER-141|1<<d.LITERAL_MONTH-141|1<<d.LITERAL_WEEK-141|1<<d.LITERAL_YEAR-141|1<<d.IDENTIFIER-141|1<<d.NUMERIC_LITERAL-141|1<<d.INTEGER_LITERAL-141|1<<d.SQL_BEGIN-141))&&(this.state=1424,e._valueExpr=this.fieldExpr(0)),this.state=1428,this._errHandler.sync(this),r=this._input.LA(1);do this.state=1427,this.caseWhen(),this.state=1430,this._errHandler.sync(this),r=this._input.LA(1);while(r===d.WHEN);this.state=1434,this._errHandler.sync(this),r=this._input.LA(1),r===d.ELSE&&(this.state=1432,this.match(d.ELSE),this.state=1433,e._caseElse=this.fieldExpr(0)),this.state=1436,this.match(d.END)}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}caseWhen(){let e=new lD(this._ctx,this.state);this.enterRule(e,266,d.RULE_caseWhen);try{this.enterOuterAlt(e,1),this.state=1438,this.match(d.WHEN),this.state=1439,e._condition=this.fieldExpr(0),this.state=1440,this.match(d.THEN),this.state=1441,e._result=this.fieldExpr(0)}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}recordKey(){let e=new VM(this._ctx,this.state);this.enterRule(e,268,d.RULE_recordKey);try{this.enterOuterAlt(e,1),this.state=1443,this.id()}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}recordElement(){let e=new t1(this._ctx,this.state);this.enterRule(e,270,d.RULE_recordElement);try{switch(this.state=1452,this._errHandler.sync(this),this.interpreter.adaptivePredict(this._input,155,this._ctx)){case 1:e=new Dxe(e),this.enterOuterAlt(e,1),this.state=1445,this.fieldPath();break;case 2:e=new Oxe(e),this.enterOuterAlt(e,2);{switch(this.state=1449,this._errHandler.sync(this),this.interpreter.adaptivePredict(this._input,154,this._ctx)){case 1:this.state=1446,this.recordKey(),this.state=1447,this.match(d.IS);break}this.state=1451,this.fieldExpr(0)}break}}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}argumentList(){let e=new cD(this._ctx,this.state);this.enterRule(e,272,d.RULE_argumentList);let r;try{let i;this.enterOuterAlt(e,1);{for(this.state=1454,this.fieldExpr(0),this.state=1459,this._errHandler.sync(this),i=this.interpreter.adaptivePredict(this._input,156,this._ctx);i!==2&&i!==rn.ATN.INVALID_ALT_NUMBER;)i===1&&(this.state=1455,this.match(d.COMMA),this.state=1456,this.fieldExpr(0)),this.state=1461,this._errHandler.sync(this),i=this.interpreter.adaptivePredict(this._input,156,this._ctx);this.state=1463,this._errHandler.sync(this),r=this._input.LA(1),r===d.COMMA&&(this.state=1462,this.match(d.COMMA))}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}fieldNameList(){let e=new n1(this._ctx,this.state);this.enterRule(e,274,d.RULE_fieldNameList);let r;try{let i;for(this.enterOuterAlt(e,1),this.state=1465,this.fieldName(),this.state=1472,this._errHandler.sync(this),i=this.interpreter.adaptivePredict(this._input,159,this._ctx);i!==2&&i!==rn.ATN.INVALID_ALT_NUMBER;)i===1&&(this.state=1467,this._errHandler.sync(this),r=this._input.LA(1),r===d.COMMA&&(this.state=1466,this.match(d.COMMA)),this.state=1469,this.fieldName()),this.state=1474,this._errHandler.sync(this),i=this.interpreter.adaptivePredict(this._input,159,this._ctx)}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}fieldCollection(){let e=new YM(this._ctx,this.state);this.enterRule(e,276,d.RULE_fieldCollection);let r;try{let i;this.enterOuterAlt(e,1);{for(this.state=1475,this.collectionMember(),this.state=1482,this._errHandler.sync(this),i=this.interpreter.adaptivePredict(this._input,161,this._ctx);i!==2&&i!==rn.ATN.INVALID_ALT_NUMBER;)i===1&&(this.state=1477,this._errHandler.sync(this),r=this._input.LA(1),r===d.COMMA&&(this.state=1476,this.match(d.COMMA)),this.state=1479,this.collectionMember()),this.state=1484,this._errHandler.sync(this),i=this.interpreter.adaptivePredict(this._input,161,this._ctx);this.state=1486,this._errHandler.sync(this),r=this._input.LA(1),r===d.COMMA&&(this.state=1485,this.match(d.COMMA))}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}collectionWildCard(){let e=new GE(this._ctx,this.state);this.enterRule(e,278,d.RULE_collectionWildCard);let r;try{switch(this.enterOuterAlt(e,1),this.state=1491,this._errHandler.sync(this),r=this._input.LA(1),(r===d.BQ_STRING||r===d.IDENTIFIER)&&(this.state=1488,this.fieldPath(),this.state=1489,this.match(d.DOT)),this.state=1493,this.match(d.STAR),this.state=1495,this._errHandler.sync(this),this.interpreter.adaptivePredict(this._input,164,this._ctx)){case 1:this.state=1494,this.starQualified();break}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}starQualified(){let e=new fD(this._ctx,this.state);this.enterRule(e,280,d.RULE_starQualified);let r;try{this.enterOuterAlt(e,1);{this.state=1497,this.match(d.OCURLY),this.state=1501,this._errHandler.sync(this),r=this._input.LA(1);do{switch(this.state=1501,this._errHandler.sync(this),this._input.LA(1)){case d.EXCEPT:this.state=1498,this.match(d.EXCEPT),this.state=1499,this.fieldNameList();break;case d.COMMA:this.state=1500,this.match(d.COMMA);break;default:throw new sn.NoViableAltException(this)}this.state=1503,this._errHandler.sync(this),r=this._input.LA(1)}while(r===d.EXCEPT||r===d.COMMA);this.state=1505,this.match(d.CCURLY)}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}taggedRef(){let e=new xD(this._ctx,this.state);this.enterRule(e,282,d.RULE_taggedRef);let r;try{this.enterOuterAlt(e,1),this.state=1507,this.tags(),this.state=1508,this.fieldPath(),this.state=1510,this._errHandler.sync(this),r=this._input.LA(1),r===d.DOT&&(this.state=1509,this.refExpr())}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}refExpr(){let e=new KM(this._ctx,this.state);this.enterRule(e,284,d.RULE_refExpr);try{switch(this.state=1519,this._errHandler.sync(this),this.interpreter.adaptivePredict(this._input,168,this._ctx)){case 1:this.enterOuterAlt(e,1),this.state=1512,this.match(d.DOT),this.state=1513,this.timeframe();break;case 2:this.enterOuterAlt(e,2),this.state=1514,this.match(d.DOT),this.state=1515,this.aggregate(),this.state=1516,this.match(d.OPAREN),this.state=1517,this.match(d.CPAREN);break}}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}collectionMember(){let e=new dD(this._ctx,this.state);this.enterRule(e,286,d.RULE_collectionMember);try{switch(this.state=1524,this._errHandler.sync(this),this.interpreter.adaptivePredict(this._input,169,this._ctx)){case 1:this.enterOuterAlt(e,1),this.state=1521,this.taggedRef();break;case 2:this.enterOuterAlt(e,2),this.state=1522,this.collectionWildCard();break;case 3:this.enterOuterAlt(e,3),this.state=1523,this.fieldDef();break}}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}fieldPath(){let e=new Ga(this._ctx,this.state);this.enterRule(e,288,d.RULE_fieldPath);try{let r;for(this.enterOuterAlt(e,1),this.state=1526,this.fieldName(),this.state=1531,this._errHandler.sync(this),r=this.interpreter.adaptivePredict(this._input,170,this._ctx);r!==2&&r!==rn.ATN.INVALID_ALT_NUMBER;)r===1&&(this.state=1527,this.match(d.DOT),this.state=1528,this.fieldName()),this.state=1533,this._errHandler.sync(this),r=this.interpreter.adaptivePredict(this._input,170,this._ctx)}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}joinName(){let e=new Fxe(this._ctx,this.state);this.enterRule(e,290,d.RULE_joinName);try{this.enterOuterAlt(e,1),this.state=1534,this.id()}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}fieldName(){let e=new Gr(this._ctx,this.state);this.enterRule(e,292,d.RULE_fieldName);try{this.enterOuterAlt(e,1),this.state=1536,this.id()}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}sqlExploreNameRef(){let e=new wxe(this._ctx,this.state);this.enterRule(e,294,d.RULE_sqlExploreNameRef);try{this.enterOuterAlt(e,1),this.state=1538,this.id()}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}nameSQLBlock(){let e=new Nxe(this._ctx,this.state);this.enterRule(e,296,d.RULE_nameSQLBlock);try{this.enterOuterAlt(e,1),this.state=1540,this.id()}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}connectionName(){let e=new Lxe(this._ctx,this.state);this.enterRule(e,298,d.RULE_connectionName);try{this.enterOuterAlt(e,1),this.state=1542,this.string()}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}tripFilterString(){let e=new JM(this._ctx,this.state);this.enterRule(e,300,d.RULE_tripFilterString);let r;try{this.enterOuterAlt(e,1),this.state=1544,r=this._input.LA(1),!(r-108&-32)&&1<<r-108&(1<<d.SQ3_FILTER-108|1<<d.DQ3_FILTER-108|1<<d.BQ3_FILTER-108)?(this._input.LA(1)===Wn.Token.EOF&&(this.matchedEOF=!0),this._errHandler.reportMatch(this),this.consume()):this._errHandler.recoverInline(this)}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}tickFilterString(){let e=new XM(this._ctx,this.state);this.enterRule(e,302,d.RULE_tickFilterString);let r;try{this.enterOuterAlt(e,1),this.state=1546,r=this._input.LA(1),!(r-109&-32)&&1<<r-109&(1<<d.SQ_FILTER-109|1<<d.DQ_FILTER-109|1<<d.BQ_FILTER-109)?(this._input.LA(1)===Wn.Token.EOF&&(this.matchedEOF=!0),this._errHandler.reportMatch(this),this.consume()):this._errHandler.recoverInline(this)}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}filterString(){let e=new ZM(this._ctx,this.state);this.enterRule(e,304,d.RULE_filterString);try{switch(this.state=1550,this._errHandler.sync(this),this._input.LA(1)){case d.SQ3_FILTER:case d.DQ3_FILTER:case d.BQ3_FILTER:this.enterOuterAlt(e,1),this.state=1548,this.tripFilterString();break;case d.SQ_FILTER:case d.DQ_FILTER:case d.BQ_FILTER:this.enterOuterAlt(e,2),this.state=1549,this.tickFilterString();break;default:throw new sn.NoViableAltException(this)}}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}debugExpr(){let e=new Ixe(this._ctx,this.state);this.enterRule(e,306,d.RULE_debugExpr);try{this.enterOuterAlt(e,1),this.state=1552,this.fieldExpr(0),this.state=1553,this.match(d.EOF)}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}debugPartial(){let e=new $xe(this._ctx,this.state);this.enterRule(e,308,d.RULE_debugPartial);try{this.enterOuterAlt(e,1),this.state=1555,this.partialAllowedFieldExpr(),this.state=1556,this.match(d.EOF)}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}experimentalStatementForTesting(){let e=new eP(this._ctx,this.state);this.enterRule(e,310,d.RULE_experimentalStatementForTesting);try{this.enterOuterAlt(e,1),this.state=1558,this.match(d.SEMI),this.state=1559,this.match(d.SEMI),this.state=1560,this.match(d.OBRACK),this.state=1561,this.string(),this.state=1562,this.match(d.CBRACK)}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}sempred(e,r,i){switch(r){case 53:return this.sqExpr_sempred(e,i);case 62:return this.segExpr_sempred(e,i);case 125:return this.fieldExpr_sempred(e,i)}return!0}sqExpr_sempred(e,r){switch(r){case 0:return this.precpred(this._ctx,6);case 1:return this.precpred(this._ctx,5);case 2:return this.precpred(this._ctx,4);case 3:return this.precpred(this._ctx,3)}return!0}segExpr_sempred(e,r){switch(r){case 4:return this.precpred(this._ctx,1)}return!0}fieldExpr_sempred(e,r){switch(r){case 5:return this.precpred(this._ctx,24);case 6:return this.precpred(this._ctx,23);case 7:return this.precpred(this._ctx,22);case 8:return this.precpred(this._ctx,18);case 9:return this.precpred(this._ctx,17);case 10:return this.precpred(this._ctx,12);case 11:return this.precpred(this._ctx,11);case 12:return this.precpred(this._ctx,10);case 13:return this.precpred(this._ctx,30);case 14:return this.precpred(this._ctx,29);case 15:return this.precpred(this._ctx,28);case 16:return this.precpred(this._ctx,27);case 17:return this.precpred(this._ctx,26);case 18:return this.precpred(this._ctx,21);case 19:return this.precpred(this._ctx,20);case 20:return this.precpred(this._ctx,19);case 21:return this.precpred(this._ctx,16);case 22:return this.precpred(this._ctx,15);case 23:return this.precpred(this._ctx,14)}return!0}static get _ATN(){return d.__ATN||(d.__ATN=new Jdt.ATNDeserializer().deserialize(Wce.toCharArray(d._serializedATN))),d.__ATN}}I.MalloyParser=d,d.ACCEPT=1,d.AGGREGATE=2,d.CALCULATE=3,d.CALCULATION=4,d.CONNECTION=5,d.DECLARE=6,d.DIMENSION=7,d.EXCEPT=8,d.EXTENDQ=9,d.GROUP_BY=10,d.HAVING=11,d.INDEX=12,d.INTERNAL=13,d.JOIN_CROSS=14,d.JOIN_ONE=15,d.JOIN_MANY=16,d.LIMIT=17,d.MEASURE=18,d.NEST=19,d.ORDER_BY=20,d.PARTITION_BY=21,d.PRIMARY_KEY=22,d.PRIVATE=23,d.PROJECT=24,d.PUBLIC=25,d.QUERY=26,d.RENAME=27,d.RUN=28,d.SAMPLE=29,d.SELECT=30,d.SOURCE=31,d.TOP=32,d.WHERE=33,d.VIEW=34,d.TIMEZONE=35,d.ALL=36,d.AND=37,d.AS=38,d.ASC=39,d.AVG=40,d.BOOLEAN=41,d.BY=42,d.CASE=43,d.CAST=44,d.CONDITION=45,d.COUNT=46,d.COMPOSE=47,d.DATE=48,d.DAY=49,d.DESC=50,d.DISTINCT=51,d.ELSE=52,d.END=53,d.EXCLUDE=54,d.EXTEND=55,d.FALSE=56,d.FILTER=57,d.FULL=58,d.FOR=59,d.FROM=60,d.HAS=61,d.HOUR=62,d.IMPORT=63,d.INCLUDE=64,d.INNER=65,d.IS=66,d.IN=67,d.INTERNAL_KW=68,d.JSON=69,d.LAST=70,d.LEFT=71,d.LIKE=72,d.MAX=73,d.MIN=74,d.MINUTE=75,d.MONTH=76,d.NOT=77,d.NOW=78,d.NULL=79,d.NUMBER=80,d.ON=81,d.OR=82,d.PICK=83,d.PRIVATE_KW=84,d.PUBLIC_KW=85,d.QUARTER=86,d.RIGHT=87,d.SECOND=88,d.STRING=89,d.SOURCE_KW=90,d.SUM=91,d.SQL=92,d.TABLE=93,d.THEN=94,d.THIS=95,d.TIMESTAMP=96,d.TO=97,d.TRUE=98,d.TURTLE=99,d.WEEK=100,d.WHEN=101,d.WITH=102,d.YEAR=103,d.UNGROUPED=104,d.HACKY_REGEX=105,d.RAW_SQ=106,d.RAW_DQ=107,d.SQ3_FILTER=108,d.SQ_FILTER=109,d.DQ3_FILTER=110,d.DQ_FILTER=111,d.BQ3_FILTER=112,d.BQ_FILTER=113,d.SQ_STRING=114,d.DQ_STRING=115,d.BQ_STRING=116,d.DOC_ANNOTATION=117,d.ANNOTATION=118,d.AMPER=119,d.ARROW=120,d.FAT_ARROW=121,d.OPAREN=122,d.CPAREN=123,d.OBRACK=124,d.CBRACK=125,d.OCURLY=126,d.CCURLY=127,d.DOUBLECOLON=128,d.TRIPLECOLON=129,d.EXCLAM=130,d.COLON=131,d.COMMA=132,d.DOT=133,d.LT=134,d.GT=135,d.EQ=136,d.NE=137,d.LTE=138,d.GTE=139,d.PLUS=140,d.MINUS=141,d.STAR=142,d.STARSTAR=143,d.SLASH=144,d.BAR=145,d.SEMI=146,d.NOT_MATCH=147,d.MATCH=148,d.PERCENT=149,d.DOUBLE_QMARK=150,d.QMARK=151,d.LITERAL_TIMESTAMP=152,d.LITERAL_HOUR=153,d.LITERAL_DAY=154,d.LITERAL_QUARTER=155,d.LITERAL_MONTH=156,d.LITERAL_WEEK=157,d.LITERAL_YEAR=158,d.IDENTIFIER=159,d.PERCENT_LITERAL=160,d.NUMERIC_LITERAL=161,d.INTEGER_LITERAL=162,d.BLOCK_COMMENT=163,d.COMMENT_TO_EOL=164,d.WHITE_SPACE=165,d.SQL_BEGIN=166,d.UNWATED_CHARS_TRAILING_NUMBERS=167,d.UNEXPECTED_CHAR=168,d.OPEN_CODE=169,d.SQL_END=170,d.RULE_malloyDocument=0,d.RULE_malloyStatement=1,d.RULE_defineSourceStatement=2,d.RULE_defineQuery=3,d.RULE_topLevelAnonQueryDef=4,d.RULE_tags=5,d.RULE_isDefine=6,d.RULE_runStatement=7,d.RULE_sqlString=8,d.RULE_sqlInterpolation=9,d.RULE_importStatement=10,d.RULE_importSelect=11,d.RULE_importItem=12,d.RULE_importURL=13,d.RULE_docAnnotations=14,d.RULE_ignoredObjectAnnotations=15,d.RULE_ignoredModelAnnotations=16,d.RULE_topLevelQueryDefs=17,d.RULE_topLevelQueryDef=18,d.RULE_refineOperator=19,d.RULE_turtleName=20,d.RULE_sqlSource=21,d.RULE_exploreTable=22,d.RULE_connectionId=23,d.RULE_queryProperties=24,d.RULE_queryName=25,d.RULE_sourcePropertyList=26,d.RULE_sourceDefinition=27,d.RULE_sqExplore=28,d.RULE_sourceParameters=29,d.RULE_legalParamType=30,d.RULE_sourceParameter=31,d.RULE_parameterNameDef=32,d.RULE_sourceNameDef=33,d.RULE_exploreProperties=34,d.RULE_exploreStatement=35,d.RULE_accessLabel=36,d.RULE_accessModifierList=37,d.RULE_defMeasures=38,d.RULE_defDimensions=39,d.RULE_renameList=40,d.RULE_exploreRenameDef=41,d.RULE_defList=42,d.RULE_fieldDef=43,d.RULE_fieldNameDef=44,d.RULE_joinNameDef=45,d.RULE_declareStatement=46,d.RULE_joinStatement=47,d.RULE_queryExtend=48,d.RULE_modEither=49,d.RULE_sourceArguments=50,d.RULE_argumentId=51,d.RULE_sourceArgument=52,d.RULE_sqExpr=53,d.RULE_includeBlock=54,d.RULE_includeItem=55,d.RULE_orphanedAnnotation=56,d.RULE_accessLabelProp=57,d.RULE_includeExceptList=58,d.RULE_includeExceptListItem=59,d.RULE_includeList=60,d.RULE_includeField=61,d.RULE_segExpr=62,d.RULE_vExpr=63,d.RULE_queryExtendStatement=64,d.RULE_queryExtendStatementList=65,d.RULE_joinList=66,d.RULE_isExplore=67,d.RULE_matrixOperation=68,d.RULE_joinFrom=69,d.RULE_joinDef=70,d.RULE_joinExpression=71,d.RULE_filterStatement=72,d.RULE_fieldProperties=73,d.RULE_aggregateOrdering=74,d.RULE_aggregateOrderBySpec=75,d.RULE_aggregateOrderByStatement=76,d.RULE_fieldPropertyLimitStatement=77,d.RULE_fieldPropertyStatement=78,d.RULE_filterClauseList=79,d.RULE_whereStatement=80,d.RULE_havingStatement=81,d.RULE_subQueryDefList=82,d.RULE_exploreQueryNameDef=83,d.RULE_exploreQueryDef=84,d.RULE_queryStatement=85,d.RULE_queryJoinStatement=86,d.RULE_groupByStatement=87,d.RULE_queryFieldList=88,d.RULE_queryFieldEntry=89,d.RULE_nestStatement=90,d.RULE_nestedQueryList=91,d.RULE_nestEntry=92,d.RULE_aggregateStatement=93,d.RULE_calculateStatement=94,d.RULE_projectStatement=95,d.RULE_partitionByStatement=96,d.RULE_orderByStatement=97,d.RULE_ordering=98,d.RULE_orderBySpec=99,d.RULE_limitStatement=100,d.RULE_bySpec=101,d.RULE_topStatement=102,d.RULE_indexElement=103,d.RULE_indexFields=104,d.RULE_indexStatement=105,d.RULE_sampleStatement=106,d.RULE_timezoneStatement=107,d.RULE_queryAnnotation=108,d.RULE_sampleSpec=109,d.RULE_aggregate=110,d.RULE_malloyType=111,d.RULE_compareOp=112,d.RULE_string=113,d.RULE_shortString=114,d.RULE_rawString=115,d.RULE_numericLiteral=116,d.RULE_literal=117,d.RULE_dateLiteral=118,d.RULE_tablePath=119,d.RULE_tableURI=120,d.RULE_id=121,d.RULE_timeframe=122,d.RULE_ungroup=123,d.RULE_malloyOrSQLType=124,d.RULE_fieldExpr=125,d.RULE_partialCompare=126,d.RULE_partialTest=127,d.RULE_partialAllowedFieldExpr=128,d.RULE_fieldExprList=129,d.RULE_pickStatement=130,d.RULE_pick=131,d.RULE_caseStatement=132,d.RULE_caseWhen=133,d.RULE_recordKey=134,d.RULE_recordElement=135,d.RULE_argumentList=136,d.RULE_fieldNameList=137,d.RULE_fieldCollection=138,d.RULE_collectionWildCard=139,d.RULE_starQualified=140,d.RULE_taggedRef=141,d.RULE_refExpr=142,d.RULE_collectionMember=143,d.RULE_fieldPath=144,d.RULE_joinName=145,d.RULE_fieldName=146,d.RULE_sqlExploreNameRef=147,d.RULE_nameSQLBlock=148,d.RULE_connectionName=149,d.RULE_tripFilterString=150,d.RULE_tickFilterString=151,d.RULE_filterString=152,d.RULE_debugExpr=153,d.RULE_debugPartial=154,d.RULE_experimentalStatementForTesting=155,d.ruleNames=["malloyDocument","malloyStatement","defineSourceStatement","defineQuery","topLevelAnonQueryDef","tags","isDefine","runStatement","sqlString","sqlInterpolation","importStatement","importSelect","importItem","importURL","docAnnotations","ignoredObjectAnnotations","ignoredModelAnnotations","topLevelQueryDefs","topLevelQueryDef","refineOperator","turtleName","sqlSource","exploreTable","connectionId","queryProperties","queryName","sourcePropertyList","sourceDefinition","sqExplore","sourceParameters","legalParamType","sourceParameter","parameterNameDef","sourceNameDef","exploreProperties","exploreStatement","accessLabel","accessModifierList","defMeasures","defDimensions","renameList","exploreRenameDef","defList","fieldDef","fieldNameDef","joinNameDef","declareStatement","joinStatement","queryExtend","modEither","sourceArguments","argumentId","sourceArgument","sqExpr","includeBlock","includeItem","orphanedAnnotation","accessLabelProp","includeExceptList","includeExceptListItem","includeList","includeField","segExpr","vExpr","queryExtendStatement","queryExtendStatementList","joinList","isExplore","matrixOperation","joinFrom","joinDef","joinExpression","filterStatement","fieldProperties","aggregateOrdering","aggregateOrderBySpec","aggregateOrderByStatement","fieldPropertyLimitStatement","fieldPropertyStatement","filterClauseList","whereStatement","havingStatement","subQueryDefList","exploreQueryNameDef","exploreQueryDef","queryStatement","queryJoinStatement","groupByStatement","queryFieldList","queryFieldEntry","nestStatement","nestedQueryList","nestEntry","aggregateStatement","calculateStatement","projectStatement","partitionByStatement","orderByStatement","ordering","orderBySpec","limitStatement","bySpec","topStatement","indexElement","indexFields","indexStatement","sampleStatement","timezoneStatement","queryAnnotation","sampleSpec","aggregate","malloyType","compareOp","string","shortString","rawString","numericLiteral","literal","dateLiteral","tablePath","tableURI","id","timeframe","ungroup","malloyOrSQLType","fieldExpr","partialCompare","partialTest","partialAllowedFieldExpr","fieldExprList","pickStatement","pick","caseStatement","caseWhen","recordKey","recordElement","argumentList","fieldNameList","fieldCollection","collectionWildCard","starQualified","taggedRef","refExpr","collectionMember","fieldPath","joinName","fieldName","sqlExploreNameRef","nameSQLBlock","connectionName","tripFilterString","tickFilterString","filterString","debugExpr","debugPartial","experimentalStatementForTesting"],d._LITERAL_NAMES=[void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,"'&'","'->'","'=>'","'('","')'","'['","']'","'{'","'}'","'::'","':::'","'!'","':'","','","'.'","'<'","'>'","'='","'!='","'<='","'>='","'+'","'-'","'*'","'**'","'/'","'|'","';'","'!~'","'~'","'%'","'??'","'?'",void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,`'"""'`],d._SYMBOLIC_NAMES=[void 0,"ACCEPT","AGGREGATE","CALCULATE","CALCULATION","CONNECTION","DECLARE","DIMENSION","EXCEPT","EXTENDQ","GROUP_BY","HAVING","INDEX","INTERNAL","JOIN_CROSS","JOIN_ONE","JOIN_MANY","LIMIT","MEASURE","NEST","ORDER_BY","PARTITION_BY","PRIMARY_KEY","PRIVATE","PROJECT","PUBLIC","QUERY","RENAME","RUN","SAMPLE","SELECT","SOURCE","TOP","WHERE","VIEW","TIMEZONE","ALL","AND","AS","ASC","AVG","BOOLEAN","BY","CASE","CAST","CONDITION","COUNT","COMPOSE","DATE","DAY","DESC","DISTINCT","ELSE","END","EXCLUDE","EXTEND","FALSE","FILTER","FULL","FOR","FROM","HAS","HOUR","IMPORT","INCLUDE","INNER","IS","IN","INTERNAL_KW","JSON","LAST","LEFT","LIKE","MAX","MIN","MINUTE","MONTH","NOT","NOW","NULL","NUMBER","ON","OR","PICK","PRIVATE_KW","PUBLIC_KW","QUARTER","RIGHT","SECOND","STRING","SOURCE_KW","SUM","SQL","TABLE","THEN","THIS","TIMESTAMP","TO","TRUE","TURTLE","WEEK","WHEN","WITH","YEAR","UNGROUPED","HACKY_REGEX","RAW_SQ","RAW_DQ","SQ3_FILTER","SQ_FILTER","DQ3_FILTER","DQ_FILTER","BQ3_FILTER","BQ_FILTER","SQ_STRING","DQ_STRING","BQ_STRING","DOC_ANNOTATION","ANNOTATION","AMPER","ARROW","FAT_ARROW","OPAREN","CPAREN","OBRACK","CBRACK","OCURLY","CCURLY","DOUBLECOLON","TRIPLECOLON","EXCLAM","COLON","COMMA","DOT","LT","GT","EQ","NE","LTE","GTE","PLUS","MINUS","STAR","STARSTAR","SLASH","BAR","SEMI","NOT_MATCH","MATCH","PERCENT","DOUBLE_QMARK","QMARK","LITERAL_TIMESTAMP","LITERAL_HOUR","LITERAL_DAY","LITERAL_QUARTER","LITERAL_MONTH","LITERAL_WEEK","LITERAL_YEAR","IDENTIFIER","PERCENT_LITERAL","NUMERIC_LITERAL","INTEGER_LITERAL","BLOCK_COMMENT","COMMENT_TO_EOL","WHITE_SPACE","SQL_BEGIN","UNWATED_CHARS_TRAILING_NUMBERS","UNEXPECTED_CHAR","OPEN_CODE","SQL_END"],d.VOCABULARY=new tht.VocabularyImpl(d._LITERAL_NAMES,d._SYMBOLIC_NAMES,[]),d._serializedATNSegments=3,d._serializedATNSegment0=`줝쪺֍꾺体؇쉁¬؟ \x07 \x07\b \b
|
|
1675
|
+
-ݱݦݱݨݱݩݱݫݱݯݲƷݳݵƶÛݴݳݵݸݶݷݶݴݷݹݸݶݹݺ\x07'ݺݻ\x07}ݻݼݼݽ\bÜݽƹݾހƶÛݿݾހރށނށݿނބރށބޅ\x07$ޅކ\x07$ކއ\x07$އވވމ\bÝމƻcLJǘǩǼȎȨȶɄɔɢɯɿʛʬʹˈ˔ˤ˸̷̩̋̈́͒ͫ̚͝·ΒΟΫλЉѕҞҦӞӭԳՄեժհշջցֲֹ֣֭֗֜׃ימײ؋؍ؙؕ؝ڃڅښڜڞڡێې۪ۭۖۜۡۤ۲۷ܷ݃ݖݛݟݡݱݶށ\x07\x07\b\x07`,ae._serializedATN=zce.join([ae._serializedATNSegment0,ae._serializedATNSegment1,ae._serializedATNSegment2,ae._serializedATNSegment3],"");var I={},Kdt=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),Jdt=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),Xdt=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&Kdt(e,t,r);return Jdt(e,t),e};Object.defineProperty(I,"__esModule",{value:!0}),I.AccessLabelContext=I.DefIgnoreModel_stubContext=I.DefExploreAnnotationContext=I.DefExploreTimezoneContext=I.DefExploreQueryContext=I.DefExploreEditFieldContext=I.DefExploreRenameContext=I.DefExplorePrimaryKeyContext=I.DefExploreWhere_stubContext=I.DefJoin_stubContext=I.DefExploreMeasure_stubContext=I.DefExploreDimension_stubContext=I.ExploreStatementContext=I.ExplorePropertiesContext=I.SourceNameDefContext=I.ParameterNameDefContext=I.SourceParameterContext=I.LegalParamTypeContext=I.SourceParametersContext=I.SqExploreContext=I.SourceDefinitionContext=I.SourcePropertyListContext=I.QueryNameContext=I.QueryPropertiesContext=I.ConnectionIdContext=I.ExploreTableContext=I.SqlSourceContext=I.TurtleNameContext=I.RefineOperatorContext=I.TopLevelQueryDefContext=I.TopLevelQueryDefsContext=I.IgnoredModelAnnotationsContext=I.IgnoredObjectAnnotationsContext=I.DocAnnotationsContext=I.ImportURLContext=I.ImportItemContext=I.ImportSelectContext=I.ImportStatementContext=I.SqlInterpolationContext=I.SqlStringContext=I.RunStatementContext=I.IsDefineContext=I.TagsContext=I.TopLevelAnonQueryDefContext=I.Use_top_level_query_defsContext=I.DefineQueryContext=I.DefineSourceStatementContext=I.MalloyStatementContext=I.MalloyDocumentContext=I.MalloyParser=void 0,I.MatrixOperationContext=I.IsExploreContext=I.JoinListContext=I.QueryExtendStatementListContext=I.QueryExtendStatementContext=I.VArrowContext=I.VSegContext=I.VExprContext=I.SegRefineContext=I.SegParenContext=I.SegOpsContext=I.SegFieldContext=I.SegExprContext=I.IncludeFieldContext=I.IncludeListContext=I.IncludeExceptListItemContext=I.IncludeExceptListContext=I.AccessLabelPropContext=I.OrphanedAnnotationContext=I.IncludeItemContext=I.IncludeBlockContext=I.SQSQLContext=I.SQTableContext=I.SQIncludeContext=I.SQExtendedSourceContext=I.SQArrowContext=I.SQRefinedQueryContext=I.SQComposeContext=I.SQParensContext=I.SQIDContext=I.SqExprContext=I.SourceArgumentContext=I.ArgumentIdContext=I.SourceArgumentsContext=I.ModEitherContext=I.QueryExtendContext=I.DefJoinCrossContext=I.DefJoinManyContext=I.DefJoinOneContext=I.JoinStatementContext=I.DeclareStatementContext=I.JoinNameDefContext=I.FieldNameDefContext=I.FieldDefContext=I.DefListContext=I.ExploreRenameDefContext=I.RenameListContext=I.DefDimensionsContext=I.DefMeasuresContext=I.AccessModifierListContext=void 0,I.RawStringContext=I.ShortStringContext=I.StringContext=I.CompareOpContext=I.MalloyTypeContext=I.AggregateContext=I.SampleSpecContext=I.QueryAnnotationContext=I.TimezoneStatementContext=I.SampleStatementContext=I.IndexStatementContext=I.IndexFieldsContext=I.IndexElementContext=I.TopStatementContext=I.BySpecContext=I.LimitStatementContext=I.OrderBySpecContext=I.OrderingContext=I.OrderByStatementContext=I.PartitionByStatementContext=I.ProjectStatementContext=I.CalculateStatementContext=I.AggregateStatementContext=I.NestDefContext=I.NestEntryContext=I.NestedQueryListContext=I.NestStatementContext=I.QueryFieldEntryContext=I.QueryFieldListContext=I.GroupByStatementContext=I.QueryJoinStatementContext=I.QueryStatementContext=I.ExploreQueryDefContext=I.ExploreQueryNameDefContext=I.SubQueryDefListContext=I.HavingStatementContext=I.WhereStatementContext=I.FilterClauseListContext=I.FieldPropertyStatementContext=I.FieldPropertyLimitStatementContext=I.AggregateOrderByStatementContext=I.AggregateOrderBySpecContext=I.AggregateOrderingContext=I.FieldPropertiesContext=I.FilterStatementContext=I.JoinExpressionContext=I.JoinOnContext=I.JoinWithContext=I.JoinDefContext=I.JoinFromContext=void 0,I.ExprLogicalOrContext=I.ExprLogicalAndContext=I.ExprNotContext=I.ExprApplyContext=I.ExprWarnInContext=I.ExprNullCheckContext=I.ExprWarnLikeContext=I.ExprCompareContext=I.ExprOrTreeContext=I.ExprAndTreeContext=I.ExprForRangeContext=I.ExprRangeContext=I.ExprAddSubContext=I.ExprMulDivContext=I.ExprMinusContext=I.ExprSafeCastContext=I.ExprCastContext=I.ExprTimeTruncContext=I.ExprDurationContext=I.ExprFieldPropsContext=I.ExprLiteralRecordContext=I.ExprArrayLiteralContext=I.ExprLiteralContext=I.ExprFieldPathContext=I.FieldExprContext=I.MalloyOrSQLTypeContext=I.UngroupContext=I.TimeframeContext=I.IdContext=I.TableURIContext=I.TablePathContext=I.LiteralYearContext=I.LiteralQuarterContext=I.LiteralMonthContext=I.LiteralWeekContext=I.LiteralDayContext=I.LiteralHourContext=I.LiteralTimestampContext=I.DateLiteralContext=I.ExprNowContext=I.FilterString_stubContext=I.ExprRegexContext=I.ExprBoolContext=I.ExprNULLContext=I.ExprTimeContext=I.ExprNumberContext=I.Stub_rawStringContext=I.ExprStringContext=I.LiteralContext=I.NumericLiteralContext=void 0,I.ExperimentalStatementForTestingContext=I.DebugPartialContext=I.DebugExprContext=I.FilterStringContext=I.TickFilterStringContext=I.TripFilterStringContext=I.ConnectionNameContext=I.NameSQLBlockContext=I.SqlExploreNameRefContext=I.FieldNameContext=I.JoinNameContext=I.FieldPathContext=I.CollectionMemberContext=I.RefExprContext=I.TaggedRefContext=I.StarQualifiedContext=I.CollectionWildCardContext=I.FieldCollectionContext=I.FieldNameListContext=I.ArgumentListContext=I.RecordExprContext=I.RecordRefContext=I.RecordElementContext=I.RecordKeyContext=I.CaseWhenContext=I.CaseStatementContext=I.PickContext=I.PickStatementContext=I.FieldExprListContext=I.PartialAllowedFieldExprContext=I.PartialTestContext=I.PartialCompareContext=I.ExprUngroupContext=I.ExprCaseContext=I.ExprPickContext=I.ExprFuncContext=I.ExprAggFuncContext=I.ExprExprContext=I.ExprAggregateContext=I.ExprPathlessAggregateContext=I.ExprCoalesceContext=void 0;const rn=Ho(),Zdt=ph(),eht=B0,sn=cm(),tht=Eh(),ge=eo(),nht=dh(),ye=Zs,Wn=un,rht=Ts,Wce=Xdt(Cn);class d extends tht.Parser{get vocabulary(){return d.VOCABULARY}get grammarFileName(){return"MalloyParser.g4"}get ruleNames(){return d.ruleNames}get serializedATN(){return d._serializedATN}createFailedPredicateException(e,r){return new eht.FailedPredicateException(this,e,r)}constructor(e){super(e),this._interp=new nht.ParserATNSimulator(d._ATN,this)}malloyDocument(){let e=new Gce(this._ctx,this.state);this.enterRule(e,0,d.RULE_malloyDocument);let r;try{this.enterOuterAlt(e,1);{for(this.state=316,this._errHandler.sync(this),r=this._input.LA(1);!(r&-32)&&1<<r&(1<<d.AGGREGATE|1<<d.CALCULATE|1<<d.DIMENSION|1<<d.EXCEPT|1<<d.GROUP_BY|1<<d.INTERNAL|1<<d.JOIN_CROSS|1<<d.JOIN_ONE|1<<d.JOIN_MANY|1<<d.MEASURE|1<<d.NEST|1<<d.PRIVATE|1<<d.PUBLIC|1<<d.QUERY|1<<d.RUN|1<<d.SELECT|1<<d.SOURCE)||!(r-34&-32)&&1<<r-34&(1<<d.VIEW-34|1<<d.ALL-34|1<<d.AVG-34|1<<d.CASE-34|1<<d.CAST-34|1<<d.COUNT-34|1<<d.COMPOSE-34|1<<d.DAY-34|1<<d.EXCLUDE-34|1<<d.FALSE-34|1<<d.HOUR-34|1<<d.IMPORT-34)||!(r-66&-32)&&1<<r-66&(1<<d.IS-66|1<<d.INTERNAL_KW-66|1<<d.MAX-66|1<<d.MIN-66|1<<d.MINUTE-66|1<<d.MONTH-66|1<<d.NOT-66|1<<d.NOW-66|1<<d.NULL-66|1<<d.PICK-66|1<<d.PRIVATE_KW-66|1<<d.PUBLIC_KW-66|1<<d.QUARTER-66|1<<d.SECOND-66|1<<d.SOURCE_KW-66|1<<d.SUM-66)||!(r-98&-32)&&1<<r-98&(1<<d.TRUE-98|1<<d.WEEK-98|1<<d.YEAR-98|1<<d.HACKY_REGEX-98|1<<d.RAW_SQ-98|1<<d.RAW_DQ-98|1<<d.SQ3_FILTER-98|1<<d.SQ_FILTER-98|1<<d.DQ3_FILTER-98|1<<d.DQ_FILTER-98|1<<d.BQ3_FILTER-98|1<<d.BQ_FILTER-98|1<<d.SQ_STRING-98|1<<d.DQ_STRING-98|1<<d.BQ_STRING-98|1<<d.DOC_ANNOTATION-98|1<<d.ANNOTATION-98|1<<d.OPAREN-98|1<<d.OBRACK-98|1<<d.OCURLY-98)||!(r-141&-32)&&1<<r-141&(1<<d.MINUS-141|1<<d.STAR-141|1<<d.SEMI-141|1<<d.LITERAL_TIMESTAMP-141|1<<d.LITERAL_HOUR-141|1<<d.LITERAL_DAY-141|1<<d.LITERAL_QUARTER-141|1<<d.LITERAL_MONTH-141|1<<d.LITERAL_WEEK-141|1<<d.LITERAL_YEAR-141|1<<d.IDENTIFIER-141|1<<d.NUMERIC_LITERAL-141|1<<d.INTEGER_LITERAL-141|1<<d.SQL_BEGIN-141);){switch(this.state=314,this._errHandler.sync(this),this.interpreter.adaptivePredict(this._input,0,this._ctx)){case 1:this.state=312,this.malloyStatement();break;case 2:this.state=313,this.match(d.SEMI);break}this.state=318,this._errHandler.sync(this),r=this._input.LA(1)}this.state=319,this.match(d.EOF)}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}malloyStatement(){let e=new CR(this._ctx,this.state);this.enterRule(e,2,d.RULE_malloyStatement);try{switch(this.state=328,this._errHandler.sync(this),this.interpreter.adaptivePredict(this._input,2,this._ctx)){case 1:this.enterOuterAlt(e,1),this.state=321,this.defineSourceStatement();break;case 2:this.enterOuterAlt(e,2),this.state=322,this.defineQuery();break;case 3:this.enterOuterAlt(e,3),this.state=323,this.importStatement();break;case 4:this.enterOuterAlt(e,4),this.state=324,this.runStatement();break;case 5:this.enterOuterAlt(e,5),this.state=325,this.docAnnotations();break;case 6:this.enterOuterAlt(e,6),this.state=326,this.ignoredObjectAnnotations();break;case 7:this.enterOuterAlt(e,7),this.state=327,this.experimentalStatementForTesting();break}}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}defineSourceStatement(){let e=new Pk(this._ctx,this.state);this.enterRule(e,4,d.RULE_defineSourceStatement);try{this.enterOuterAlt(e,1),this.state=330,this.tags(),this.state=331,this.match(d.SOURCE),this.state=332,this.sourcePropertyList()}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}defineQuery(){let e=new SR(this._ctx,this.state);this.enterRule(e,6,d.RULE_defineQuery);try{e=new Vce(e),this.enterOuterAlt(e,1),this.state=334,this.topLevelQueryDefs()}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}topLevelAnonQueryDef(){let e=new Uk(this._ctx,this.state);this.enterRule(e,8,d.RULE_topLevelAnonQueryDef);try{this.enterOuterAlt(e,1),this.state=336,this.tags(),this.state=337,this.sqExpr(0)}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}tags(){let e=new Xt(this._ctx,this.state);this.enterRule(e,10,d.RULE_tags);let r;try{for(this.enterOuterAlt(e,1),this.state=342,this._errHandler.sync(this),r=this._input.LA(1);r===d.ANNOTATION;)this.state=339,this.match(d.ANNOTATION),this.state=344,this._errHandler.sync(this),r=this._input.LA(1)}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}isDefine(){let e=new v0(this._ctx,this.state);this.enterRule(e,12,d.RULE_isDefine);try{this.enterOuterAlt(e,1),this.state=345,e._beforeIs=this.tags(),this.state=346,this.match(d.IS),this.state=347,e._afterIs=this.tags()}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}runStatement(){let e=new jk(this._ctx,this.state);this.enterRule(e,14,d.RULE_runStatement);try{this.enterOuterAlt(e,1),this.state=349,this.tags(),this.state=350,this.match(d.RUN),this.state=351,this.topLevelAnonQueryDef()}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}sqlString(){let e=new bR(this._ctx,this.state);this.enterRule(e,16,d.RULE_sqlString);let r;try{this.enterOuterAlt(e,1);{for(this.state=353,this.match(d.SQL_BEGIN),this.state=357,this._errHandler.sync(this),r=this._input.LA(1);r===d.OPEN_CODE;)this.state=354,this.sqlInterpolation(),this.state=359,this._errHandler.sync(this),r=this._input.LA(1);this.state=360,this.match(d.SQL_END)}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}sqlInterpolation(){let e=new TR(this._ctx,this.state);this.enterRule(e,18,d.RULE_sqlInterpolation);try{this.enterOuterAlt(e,1),this.state=362,this.match(d.OPEN_CODE),this.state=363,this.sqExpr(0),this.state=364,this.match(d.CCURLY)}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}importStatement(){let e=new qk(this._ctx,this.state);this.enterRule(e,20,d.RULE_importStatement);let r;try{this.enterOuterAlt(e,1),this.state=366,this.match(d.IMPORT),this.state=368,this._errHandler.sync(this),r=this._input.LA(1),r===d.OCURLY&&(this.state=367,this.importSelect()),this.state=370,this.importURL()}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}importSelect(){let e=new Hk(this._ctx,this.state);this.enterRule(e,22,d.RULE_importSelect);let r;try{this.enterOuterAlt(e,1);{for(this.state=372,this.match(d.OCURLY),this.state=373,this.importItem(),this.state=378,this._errHandler.sync(this),r=this._input.LA(1);r===d.COMMA;)this.state=374,this.match(d.COMMA),this.state=375,this.importItem(),this.state=380,this._errHandler.sync(this),r=this._input.LA(1);this.state=381,this.match(d.CCURLY),this.state=382,this.match(d.FROM)}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}importItem(){let e=new RR(this._ctx,this.state);this.enterRule(e,24,d.RULE_importItem);let r;try{this.enterOuterAlt(e,1),this.state=384,this.id(),this.state=387,this._errHandler.sync(this),r=this._input.LA(1),r===d.IS&&(this.state=385,this.match(d.IS),this.state=386,this.id())}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}importURL(){let e=new Qk(this._ctx,this.state);this.enterRule(e,26,d.RULE_importURL);try{this.enterOuterAlt(e,1),this.state=389,this.string()}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}docAnnotations(){let e=new zk(this._ctx,this.state);this.enterRule(e,28,d.RULE_docAnnotations);try{let r;this.enterOuterAlt(e,1);{this.state=392,this._errHandler.sync(this),r=1;do{switch(r){case 1:this.state=391,this.match(d.DOC_ANNOTATION);break;default:throw new sn.NoViableAltException(this)}this.state=394,this._errHandler.sync(this),r=this.interpreter.adaptivePredict(this._input,8,this._ctx)}while(r!==2&&r!==rn.ATN.INVALID_ALT_NUMBER)}}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}ignoredObjectAnnotations(){let e=new Wk(this._ctx,this.state);this.enterRule(e,30,d.RULE_ignoredObjectAnnotations);try{let r;this.enterOuterAlt(e,1);{this.state=397,this._errHandler.sync(this),r=1;do{switch(r){case 1:this.state=396,this.match(d.ANNOTATION);break;default:throw new sn.NoViableAltException(this)}this.state=399,this._errHandler.sync(this),r=this.interpreter.adaptivePredict(this._input,9,this._ctx)}while(r!==2&&r!==rn.ATN.INVALID_ALT_NUMBER)}}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}ignoredModelAnnotations(){let e=new DR(this._ctx,this.state);this.enterRule(e,32,d.RULE_ignoredModelAnnotations);try{let r;this.enterOuterAlt(e,1);{this.state=402,this._errHandler.sync(this),r=1;do{switch(r){case 1:this.state=401,this.match(d.DOC_ANNOTATION);break;default:throw new sn.NoViableAltException(this)}this.state=404,this._errHandler.sync(this),r=this.interpreter.adaptivePredict(this._input,10,this._ctx)}while(r!==2&&r!==rn.ATN.INVALID_ALT_NUMBER)}}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}topLevelQueryDefs(){let e=new Gk(this._ctx,this.state);this.enterRule(e,34,d.RULE_topLevelQueryDefs);let r;try{let i;this.enterOuterAlt(e,1);{for(this.state=406,this.tags(),this.state=407,this.match(d.QUERY),this.state=408,this.topLevelQueryDef(),this.state=415,this._errHandler.sync(this),i=this.interpreter.adaptivePredict(this._input,12,this._ctx);i!==2&&i!==rn.ATN.INVALID_ALT_NUMBER;)i===1&&(this.state=410,this._errHandler.sync(this),r=this._input.LA(1),r===d.COMMA&&(this.state=409,this.match(d.COMMA)),this.state=412,this.topLevelQueryDef()),this.state=417,this._errHandler.sync(this),i=this.interpreter.adaptivePredict(this._input,12,this._ctx);this.state=419,this._errHandler.sync(this),r=this._input.LA(1),r===d.COMMA&&(this.state=418,this.match(d.COMMA))}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}topLevelQueryDef(){let e=new FR(this._ctx,this.state);this.enterRule(e,36,d.RULE_topLevelQueryDef);try{this.enterOuterAlt(e,1),this.state=421,this.tags(),this.state=422,this.queryName(),this.state=423,this.isDefine(),this.state=424,this.sqExpr(0)}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}refineOperator(){let e=new Yce(this._ctx,this.state);this.enterRule(e,38,d.RULE_refineOperator);try{this.enterOuterAlt(e,1),this.state=426,this.match(d.PLUS)}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}turtleName(){let e=new Kce(this._ctx,this.state);this.enterRule(e,40,d.RULE_turtleName);try{this.enterOuterAlt(e,1),this.state=428,this.id()}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}sqlSource(){let e=new Vk(this._ctx,this.state);this.enterRule(e,42,d.RULE_sqlSource);try{this.enterOuterAlt(e,1);{switch(this.state=430,this.connectionId(),this.state=431,this.match(d.DOT),this.state=432,this.match(d.SQL),this.state=433,this.match(d.OPAREN),this.state=436,this._errHandler.sync(this),this._input.LA(1)){case d.SQL_BEGIN:this.state=434,this.sqlString();break;case d.SQ_STRING:case d.DQ_STRING:this.state=435,this.shortString();break;default:throw new sn.NoViableAltException(this)}this.state=438,this.match(d.CPAREN)}}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}exploreTable(){let e=new Yk(this._ctx,this.state);this.enterRule(e,44,d.RULE_exploreTable);try{this.enterOuterAlt(e,1),this.state=440,this.connectionId(),this.state=441,this.match(d.DOT),this.state=442,this.match(d.TABLE),this.state=443,this.match(d.OPAREN),this.state=444,this.tablePath(),this.state=445,this.match(d.CPAREN)}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}connectionId(){let e=new wR(this._ctx,this.state);this.enterRule(e,46,d.RULE_connectionId);try{this.enterOuterAlt(e,1),this.state=447,this.id()}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}queryProperties(){let e=new Kk(this._ctx,this.state);this.enterRule(e,48,d.RULE_queryProperties);let r;try{this.enterOuterAlt(e,1);{for(this.state=449,this.match(d.OCURLY),this.state=454,this._errHandler.sync(this),r=this._input.LA(1);!(r&-32)&&1<<r&(1<<d.AGGREGATE|1<<d.CALCULATE|1<<d.DECLARE|1<<d.DIMENSION|1<<d.EXCEPT|1<<d.EXTENDQ|1<<d.GROUP_BY|1<<d.HAVING|1<<d.INDEX|1<<d.INTERNAL|1<<d.JOIN_CROSS|1<<d.JOIN_ONE|1<<d.JOIN_MANY|1<<d.LIMIT|1<<d.MEASURE|1<<d.NEST|1<<d.ORDER_BY|1<<d.PRIVATE|1<<d.PUBLIC|1<<d.QUERY|1<<d.RUN|1<<d.SAMPLE|1<<d.SELECT|1<<d.SOURCE)||!(r-32&-32)&&1<<r-32&(1<<d.TOP-32|1<<d.WHERE-32|1<<d.VIEW-32|1<<d.TIMEZONE-32|1<<d.ALL-32|1<<d.AVG-32|1<<d.CASE-32|1<<d.CAST-32|1<<d.COUNT-32|1<<d.COMPOSE-32|1<<d.DAY-32|1<<d.EXCLUDE-32|1<<d.FALSE-32|1<<d.HOUR-32)||!(r-66&-32)&&1<<r-66&(1<<d.IS-66|1<<d.INTERNAL_KW-66|1<<d.MAX-66|1<<d.MIN-66|1<<d.MINUTE-66|1<<d.MONTH-66|1<<d.NOT-66|1<<d.NOW-66|1<<d.NULL-66|1<<d.PICK-66|1<<d.PRIVATE_KW-66|1<<d.PUBLIC_KW-66|1<<d.QUARTER-66|1<<d.SECOND-66|1<<d.SOURCE_KW-66|1<<d.SUM-66)||!(r-98&-32)&&1<<r-98&(1<<d.TRUE-98|1<<d.WEEK-98|1<<d.YEAR-98|1<<d.HACKY_REGEX-98|1<<d.RAW_SQ-98|1<<d.RAW_DQ-98|1<<d.SQ3_FILTER-98|1<<d.SQ_FILTER-98|1<<d.DQ3_FILTER-98|1<<d.DQ_FILTER-98|1<<d.BQ3_FILTER-98|1<<d.BQ_FILTER-98|1<<d.SQ_STRING-98|1<<d.DQ_STRING-98|1<<d.BQ_STRING-98|1<<d.DOC_ANNOTATION-98|1<<d.ANNOTATION-98|1<<d.OPAREN-98|1<<d.OBRACK-98|1<<d.OCURLY-98)||!(r-141&-32)&&1<<r-141&(1<<d.MINUS-141|1<<d.STAR-141|1<<d.SEMI-141|1<<d.LITERAL_TIMESTAMP-141|1<<d.LITERAL_HOUR-141|1<<d.LITERAL_DAY-141|1<<d.LITERAL_QUARTER-141|1<<d.LITERAL_MONTH-141|1<<d.LITERAL_WEEK-141|1<<d.LITERAL_YEAR-141|1<<d.IDENTIFIER-141|1<<d.NUMERIC_LITERAL-141|1<<d.INTEGER_LITERAL-141|1<<d.SQL_BEGIN-141);){switch(this.state=452,this._errHandler.sync(this),this._input.LA(1)){case d.AGGREGATE:case d.CALCULATE:case d.DECLARE:case d.DIMENSION:case d.EXCEPT:case d.EXTENDQ:case d.GROUP_BY:case d.HAVING:case d.INDEX:case d.INTERNAL:case d.JOIN_CROSS:case d.JOIN_ONE:case d.JOIN_MANY:case d.LIMIT:case d.MEASURE:case d.NEST:case d.ORDER_BY:case d.PRIVATE:case d.PUBLIC:case d.QUERY:case d.RUN:case d.SAMPLE:case d.SELECT:case d.SOURCE:case d.TOP:case d.WHERE:case d.VIEW:case d.TIMEZONE:case d.ALL:case d.AVG:case d.CASE:case d.CAST:case d.COUNT:case d.COMPOSE:case d.DAY:case d.EXCLUDE:case d.FALSE:case d.HOUR:case d.IS:case d.INTERNAL_KW:case d.MAX:case d.MIN:case d.MINUTE:case d.MONTH:case d.NOT:case d.NOW:case d.NULL:case d.PICK:case d.PRIVATE_KW:case d.PUBLIC_KW:case d.QUARTER:case d.SECOND:case d.SOURCE_KW:case d.SUM:case d.TRUE:case d.WEEK:case d.YEAR:case d.HACKY_REGEX:case d.RAW_SQ:case d.RAW_DQ:case d.SQ3_FILTER:case d.SQ_FILTER:case d.DQ3_FILTER:case d.DQ_FILTER:case d.BQ3_FILTER:case d.BQ_FILTER:case d.SQ_STRING:case d.DQ_STRING:case d.BQ_STRING:case d.DOC_ANNOTATION:case d.ANNOTATION:case d.OPAREN:case d.OBRACK:case d.OCURLY:case d.MINUS:case d.STAR:case d.LITERAL_TIMESTAMP:case d.LITERAL_HOUR:case d.LITERAL_DAY:case d.LITERAL_QUARTER:case d.LITERAL_MONTH:case d.LITERAL_WEEK:case d.LITERAL_YEAR:case d.IDENTIFIER:case d.NUMERIC_LITERAL:case d.INTEGER_LITERAL:case d.SQL_BEGIN:this.state=450,this.queryStatement();break;case d.SEMI:this.state=451,this.match(d.SEMI);break;default:throw new sn.NoViableAltException(this)}this.state=456,this._errHandler.sync(this),r=this._input.LA(1)}this.state=457,this.match(d.CCURLY)}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}queryName(){let e=new NR(this._ctx,this.state);this.enterRule(e,50,d.RULE_queryName);try{this.enterOuterAlt(e,1),this.state=459,this.id()}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}sourcePropertyList(){let e=new Jk(this._ctx,this.state);this.enterRule(e,52,d.RULE_sourcePropertyList);let r;try{let i;this.enterOuterAlt(e,1);{for(this.state=461,this.sourceDefinition(),this.state=468,this._errHandler.sync(this),i=this.interpreter.adaptivePredict(this._input,18,this._ctx);i!==2&&i!==rn.ATN.INVALID_ALT_NUMBER;)i===1&&(this.state=463,this._errHandler.sync(this),r=this._input.LA(1),r===d.COMMA&&(this.state=462,this.match(d.COMMA)),this.state=465,this.sourceDefinition()),this.state=470,this._errHandler.sync(this),i=this.interpreter.adaptivePredict(this._input,18,this._ctx);this.state=472,this._errHandler.sync(this),r=this._input.LA(1),r===d.COMMA&&(this.state=471,this.match(d.COMMA))}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}sourceDefinition(){let e=new LR(this._ctx,this.state);this.enterRule(e,54,d.RULE_sourceDefinition);try{this.enterOuterAlt(e,1);{switch(this.state=474,this.tags(),this.state=475,this.sourceNameDef(),this.state=477,this._errHandler.sync(this),this.interpreter.adaptivePredict(this._input,20,this._ctx)){case 1:this.state=476,this.sourceParameters();break}this.state=479,this.isDefine(),this.state=480,this.sqExplore()}}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}sqExplore(){let e=new Xk(this._ctx,this.state);this.enterRule(e,56,d.RULE_sqExplore);try{this.enterOuterAlt(e,1),this.state=482,this.sqExpr(0)}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}sourceParameters(){let e=new Zk(this._ctx,this.state);this.enterRule(e,58,d.RULE_sourceParameters);let r;try{switch(this.state=497,this._errHandler.sync(this),this.interpreter.adaptivePredict(this._input,22,this._ctx)){case 1:this.enterOuterAlt(e,1),this.state=484,this.match(d.OPAREN),this.state=485,this.match(d.CPAREN);break;case 2:this.enterOuterAlt(e,2);{for(this.state=486,this.match(d.OPAREN),this.state=487,this.sourceParameter(),this.state=492,this._errHandler.sync(this),r=this._input.LA(1);r===d.COMMA;)this.state=488,this.match(d.COMMA),this.state=489,this.sourceParameter(),this.state=494,this._errHandler.sync(this),r=this._input.LA(1);this.state=495,this.match(d.CPAREN)}break}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}legalParamType(){let e=new eM(this._ctx,this.state);this.enterRule(e,60,d.RULE_legalParamType);try{switch(this.state=505,this._errHandler.sync(this),this._input.LA(1)){case d.BOOLEAN:case d.DATE:case d.NUMBER:case d.STRING:case d.TIMESTAMP:this.enterOuterAlt(e,1),this.state=499,this.malloyType();break;case d.FILTER:this.enterOuterAlt(e,2),this.state=500,this.match(d.FILTER),this.state=501,this.match(d.LT),this.state=502,this.malloyType(),this.state=503,this.match(d.GT);break;default:throw new sn.NoViableAltException(this)}}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}sourceParameter(){let e=new IR(this._ctx,this.state);this.enterRule(e,62,d.RULE_sourceParameter);let r;try{this.enterOuterAlt(e,1),this.state=507,this.parameterNameDef(),this.state=510,this._errHandler.sync(this),r=this._input.LA(1),r===d.DOUBLECOLON&&(this.state=508,this.match(d.DOUBLECOLON),this.state=509,this.legalParamType()),this.state=514,this._errHandler.sync(this),r=this._input.LA(1),r===d.IS&&(this.state=512,this.match(d.IS),this.state=513,this.fieldExpr(0))}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}parameterNameDef(){let e=new tM(this._ctx,this.state);this.enterRule(e,64,d.RULE_parameterNameDef);try{this.enterOuterAlt(e,1),this.state=516,this.id()}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}sourceNameDef(){let e=new nM(this._ctx,this.state);this.enterRule(e,66,d.RULE_sourceNameDef);try{this.enterOuterAlt(e,1),this.state=518,this.id()}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}exploreProperties(){let e=new rM(this._ctx,this.state);this.enterRule(e,68,d.RULE_exploreProperties);let r;try{this.enterOuterAlt(e,1);{for(this.state=520,this.match(d.OCURLY),this.state=525,this._errHandler.sync(this),r=this._input.LA(1);!(r&-32)&&1<<r&(1<<d.ACCEPT|1<<d.AGGREGATE|1<<d.CALCULATE|1<<d.DIMENSION|1<<d.EXCEPT|1<<d.GROUP_BY|1<<d.INTERNAL|1<<d.JOIN_CROSS|1<<d.JOIN_ONE|1<<d.JOIN_MANY|1<<d.MEASURE|1<<d.NEST|1<<d.PRIMARY_KEY|1<<d.PRIVATE|1<<d.PUBLIC|1<<d.QUERY|1<<d.RENAME|1<<d.RUN|1<<d.SELECT|1<<d.SOURCE)||!(r-33&-32)&&1<<r-33&(1<<d.WHERE-33|1<<d.VIEW-33|1<<d.TIMEZONE-33|1<<d.ALL-33|1<<d.AVG-33|1<<d.CASE-33|1<<d.CAST-33|1<<d.COUNT-33|1<<d.COMPOSE-33|1<<d.DAY-33|1<<d.EXCLUDE-33|1<<d.FALSE-33|1<<d.HOUR-33)||!(r-66&-32)&&1<<r-66&(1<<d.IS-66|1<<d.INTERNAL_KW-66|1<<d.MAX-66|1<<d.MIN-66|1<<d.MINUTE-66|1<<d.MONTH-66|1<<d.NOT-66|1<<d.NOW-66|1<<d.NULL-66|1<<d.PICK-66|1<<d.PRIVATE_KW-66|1<<d.PUBLIC_KW-66|1<<d.QUARTER-66|1<<d.SECOND-66|1<<d.SOURCE_KW-66|1<<d.SUM-66)||!(r-98&-32)&&1<<r-98&(1<<d.TRUE-98|1<<d.WEEK-98|1<<d.YEAR-98|1<<d.HACKY_REGEX-98|1<<d.RAW_SQ-98|1<<d.RAW_DQ-98|1<<d.SQ3_FILTER-98|1<<d.SQ_FILTER-98|1<<d.DQ3_FILTER-98|1<<d.DQ_FILTER-98|1<<d.BQ3_FILTER-98|1<<d.BQ_FILTER-98|1<<d.SQ_STRING-98|1<<d.DQ_STRING-98|1<<d.BQ_STRING-98|1<<d.DOC_ANNOTATION-98|1<<d.ANNOTATION-98|1<<d.OPAREN-98|1<<d.OBRACK-98|1<<d.OCURLY-98)||!(r-141&-32)&&1<<r-141&(1<<d.MINUS-141|1<<d.STAR-141|1<<d.SEMI-141|1<<d.LITERAL_TIMESTAMP-141|1<<d.LITERAL_HOUR-141|1<<d.LITERAL_DAY-141|1<<d.LITERAL_QUARTER-141|1<<d.LITERAL_MONTH-141|1<<d.LITERAL_WEEK-141|1<<d.LITERAL_YEAR-141|1<<d.IDENTIFIER-141|1<<d.NUMERIC_LITERAL-141|1<<d.INTEGER_LITERAL-141|1<<d.SQL_BEGIN-141);){switch(this.state=523,this._errHandler.sync(this),this._input.LA(1)){case d.ACCEPT:case d.AGGREGATE:case d.CALCULATE:case d.DIMENSION:case d.EXCEPT:case d.GROUP_BY:case d.INTERNAL:case d.JOIN_CROSS:case d.JOIN_ONE:case d.JOIN_MANY:case d.MEASURE:case d.NEST:case d.PRIMARY_KEY:case d.PRIVATE:case d.PUBLIC:case d.QUERY:case d.RENAME:case d.RUN:case d.SELECT:case d.SOURCE:case d.WHERE:case d.VIEW:case d.TIMEZONE:case d.ALL:case d.AVG:case d.CASE:case d.CAST:case d.COUNT:case d.COMPOSE:case d.DAY:case d.EXCLUDE:case d.FALSE:case d.HOUR:case d.IS:case d.INTERNAL_KW:case d.MAX:case d.MIN:case d.MINUTE:case d.MONTH:case d.NOT:case d.NOW:case d.NULL:case d.PICK:case d.PRIVATE_KW:case d.PUBLIC_KW:case d.QUARTER:case d.SECOND:case d.SOURCE_KW:case d.SUM:case d.TRUE:case d.WEEK:case d.YEAR:case d.HACKY_REGEX:case d.RAW_SQ:case d.RAW_DQ:case d.SQ3_FILTER:case d.SQ_FILTER:case d.DQ3_FILTER:case d.DQ_FILTER:case d.BQ3_FILTER:case d.BQ_FILTER:case d.SQ_STRING:case d.DQ_STRING:case d.BQ_STRING:case d.DOC_ANNOTATION:case d.ANNOTATION:case d.OPAREN:case d.OBRACK:case d.OCURLY:case d.MINUS:case d.STAR:case d.LITERAL_TIMESTAMP:case d.LITERAL_HOUR:case d.LITERAL_DAY:case d.LITERAL_QUARTER:case d.LITERAL_MONTH:case d.LITERAL_WEEK:case d.LITERAL_YEAR:case d.IDENTIFIER:case d.NUMERIC_LITERAL:case d.INTEGER_LITERAL:case d.SQL_BEGIN:this.state=521,this.exploreStatement();break;case d.SEMI:this.state=522,this.match(d.SEMI);break;default:throw new sn.NoViableAltException(this)}this.state=527,this._errHandler.sync(this),r=this._input.LA(1)}this.state=528,this.match(d.CCURLY)}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}exploreStatement(){let e=new Ki(this._ctx,this.state);this.enterRule(e,70,d.RULE_exploreStatement);let r;try{let i;switch(this.state=557,this._errHandler.sync(this),this.interpreter.adaptivePredict(this._input,31,this._ctx)){case 1:e=new Jce(e),this.enterOuterAlt(e,1),this.state=530,this.defDimensions();break;case 2:e=new Xce(e),this.enterOuterAlt(e,2),this.state=531,this.defMeasures();break;case 3:e=new Zce(e),this.enterOuterAlt(e,3),this.state=532,this.joinStatement();break;case 4:e=new efe(e),this.enterOuterAlt(e,4),this.state=533,this.whereStatement();break;case 5:e=new tfe(e),this.enterOuterAlt(e,5),this.state=534,this.match(d.PRIMARY_KEY),this.state=535,this.fieldName();break;case 6:e=new nfe(e),this.enterOuterAlt(e,6),this.state=537,this._errHandler.sync(this),r=this._input.LA(1),!(r-68&-32)&&1<<r-68&(1<<d.INTERNAL_KW-68|1<<d.PRIVATE_KW-68|1<<d.PUBLIC_KW-68)&&(this.state=536,this.accessLabel()),this.state=539,this.match(d.RENAME),this.state=540,this.renameList();break;case 7:e=new rfe(e),this.enterOuterAlt(e,7),this.state=541,r=this._input.LA(1),r===d.ACCEPT||r===d.EXCEPT?(this._input.LA(1)===Wn.Token.EOF&&(this.matchedEOF=!0),this._errHandler.reportMatch(this),this.consume()):this._errHandler.recoverInline(this),this.state=542,this.fieldNameList();break;case 8:e=new ife(e),this.enterOuterAlt(e,8),this.state=543,this.tags(),this.state=545,this._errHandler.sync(this),r=this._input.LA(1),!(r-68&-32)&&1<<r-68&(1<<d.INTERNAL_KW-68|1<<d.PRIVATE_KW-68|1<<d.PUBLIC_KW-68)&&(this.state=544,this.accessLabel()),this.state=547,this.match(d.VIEW),this.state=548,this.subQueryDefList();break;case 9:e=new sfe(e),this.enterOuterAlt(e,9),this.state=550,this.timezoneStatement();break;case 10:e=new ofe(e),this.enterOuterAlt(e,10);{this.state=552,this._errHandler.sync(this),i=1;do{switch(i){case 1:this.state=551,this.match(d.ANNOTATION);break;default:throw new sn.NoViableAltException(this)}this.state=554,this._errHandler.sync(this),i=this.interpreter.adaptivePredict(this._input,30,this._ctx)}while(i!==2&&i!==rn.ATN.INVALID_ALT_NUMBER)}break;case 11:e=new ufe(e),this.enterOuterAlt(e,11),this.state=556,this.ignoredModelAnnotations();break}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}accessLabel(){let e=new Qa(this._ctx,this.state);this.enterRule(e,72,d.RULE_accessLabel);let r;try{this.enterOuterAlt(e,1),this.state=559,r=this._input.LA(1),!(r-68&-32)&&1<<r-68&(1<<d.INTERNAL_KW-68|1<<d.PRIVATE_KW-68|1<<d.PUBLIC_KW-68)?(this._input.LA(1)===Wn.Token.EOF&&(this.matchedEOF=!0),this._errHandler.reportMatch(this),this.consume()):this._errHandler.recoverInline(this)}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}accessModifierList(){let e=new afe(this._ctx,this.state);this.enterRule(e,74,d.RULE_accessModifierList);let r;try{switch(this.state=566,this._errHandler.sync(this),this._input.LA(1)){case d.BQ_STRING:case d.IDENTIFIER:this.enterOuterAlt(e,1),this.state=561,this.fieldNameList();break;case d.STAR:this.enterOuterAlt(e,2),this.state=562,this.match(d.STAR),this.state=564,this._errHandler.sync(this),r=this._input.LA(1),r===d.OCURLY&&(this.state=563,this.starQualified());break;default:throw new sn.NoViableAltException(this)}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}defMeasures(){let e=new $R(this._ctx,this.state);this.enterRule(e,76,d.RULE_defMeasures);let r;try{this.enterOuterAlt(e,1),this.state=568,this.tags(),this.state=570,this._errHandler.sync(this),r=this._input.LA(1),!(r-68&-32)&&1<<r-68&(1<<d.INTERNAL_KW-68|1<<d.PRIVATE_KW-68|1<<d.PUBLIC_KW-68)&&(this.state=569,this.accessLabel()),this.state=572,this.match(d.MEASURE),this.state=573,this.defList()}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}defDimensions(){let e=new BR(this._ctx,this.state);this.enterRule(e,78,d.RULE_defDimensions);let r;try{this.enterOuterAlt(e,1),this.state=575,this.tags(),this.state=577,this._errHandler.sync(this),r=this._input.LA(1),!(r-68&-32)&&1<<r-68&(1<<d.INTERNAL_KW-68|1<<d.PRIVATE_KW-68|1<<d.PUBLIC_KW-68)&&(this.state=576,this.accessLabel()),this.state=579,this.match(d.DIMENSION),this.state=580,this.defList()}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}renameList(){let e=new iM(this._ctx,this.state);this.enterRule(e,80,d.RULE_renameList);let r;try{let i;this.enterOuterAlt(e,1);{for(this.state=582,this.exploreRenameDef(),this.state=589,this._errHandler.sync(this),i=this.interpreter.adaptivePredict(this._input,37,this._ctx);i!==2&&i!==rn.ATN.INVALID_ALT_NUMBER;)i===1&&(this.state=584,this._errHandler.sync(this),r=this._input.LA(1),r===d.COMMA&&(this.state=583,this.match(d.COMMA)),this.state=586,this.exploreRenameDef()),this.state=591,this._errHandler.sync(this),i=this.interpreter.adaptivePredict(this._input,37,this._ctx);this.state=593,this._errHandler.sync(this),r=this._input.LA(1),r===d.COMMA&&(this.state=592,this.match(d.COMMA))}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}exploreRenameDef(){let e=new kR(this._ctx,this.state);this.enterRule(e,82,d.RULE_exploreRenameDef);try{this.enterOuterAlt(e,1),this.state=595,this.fieldName(),this.state=596,this.isDefine(),this.state=597,this.fieldName()}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}defList(){let e=new jE(this._ctx,this.state);this.enterRule(e,84,d.RULE_defList);let r;try{let i;this.enterOuterAlt(e,1);{for(this.state=599,this.fieldDef(),this.state=606,this._errHandler.sync(this),i=this.interpreter.adaptivePredict(this._input,40,this._ctx);i!==2&&i!==rn.ATN.INVALID_ALT_NUMBER;)i===1&&(this.state=601,this._errHandler.sync(this),r=this._input.LA(1),r===d.COMMA&&(this.state=600,this.match(d.COMMA)),this.state=603,this.fieldDef()),this.state=608,this._errHandler.sync(this),i=this.interpreter.adaptivePredict(this._input,40,this._ctx);this.state=610,this._errHandler.sync(this),r=this._input.LA(1),r===d.COMMA&&(this.state=609,this.match(d.COMMA))}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}fieldDef(){let e=new Z2(this._ctx,this.state);this.enterRule(e,86,d.RULE_fieldDef);try{this.enterOuterAlt(e,1),this.state=612,this.tags(),this.state=613,this.fieldNameDef(),this.state=614,this.isDefine(),this.state=615,this.fieldExpr(0)}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}fieldNameDef(){let e=new sM(this._ctx,this.state);this.enterRule(e,88,d.RULE_fieldNameDef);try{this.enterOuterAlt(e,1),this.state=617,this.id()}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}joinNameDef(){let e=new oM(this._ctx,this.state);this.enterRule(e,90,d.RULE_joinNameDef);try{this.enterOuterAlt(e,1),this.state=619,this.id()}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}declareStatement(){let e=new MR(this._ctx,this.state);this.enterRule(e,92,d.RULE_declareStatement);try{this.enterOuterAlt(e,1);{switch(this.state=621,this.match(d.DECLARE),this.state=623,this._errHandler.sync(this),this.interpreter.adaptivePredict(this._input,42,this._ctx)){case 1:this.state=622,this.accessLabel();break}this.state=625,this.defList()}}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}joinStatement(){let e=new C0(this._ctx,this.state);this.enterRule(e,94,d.RULE_joinStatement);let r;try{switch(this.state=648,this._errHandler.sync(this),this.interpreter.adaptivePredict(this._input,46,this._ctx)){case 1:e=new lfe(e),this.enterOuterAlt(e,1),this.state=627,this.tags(),this.state=629,this._errHandler.sync(this),r=this._input.LA(1),!(r-68&-32)&&1<<r-68&(1<<d.INTERNAL_KW-68|1<<d.PRIVATE_KW-68|1<<d.PUBLIC_KW-68)&&(this.state=628,this.accessLabel()),this.state=631,this.match(d.JOIN_ONE),this.state=632,this.joinList();break;case 2:e=new cfe(e),this.enterOuterAlt(e,2),this.state=634,this.tags(),this.state=636,this._errHandler.sync(this),r=this._input.LA(1),!(r-68&-32)&&1<<r-68&(1<<d.INTERNAL_KW-68|1<<d.PRIVATE_KW-68|1<<d.PUBLIC_KW-68)&&(this.state=635,this.accessLabel()),this.state=638,this.match(d.JOIN_MANY),this.state=639,this.joinList();break;case 3:e=new ffe(e),this.enterOuterAlt(e,3),this.state=641,this.tags(),this.state=643,this._errHandler.sync(this),r=this._input.LA(1),!(r-68&-32)&&1<<r-68&(1<<d.INTERNAL_KW-68|1<<d.PRIVATE_KW-68|1<<d.PUBLIC_KW-68)&&(this.state=642,this.accessLabel()),this.state=645,this.match(d.JOIN_CROSS),this.state=646,this.joinList();break}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}queryExtend(){let e=new uM(this._ctx,this.state);this.enterRule(e,96,d.RULE_queryExtend);try{this.enterOuterAlt(e,1),this.state=650,this.match(d.EXTENDQ),this.state=651,this.queryExtendStatementList()}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}modEither(){let e=new xfe(this._ctx,this.state);this.enterRule(e,98,d.RULE_modEither);try{switch(this.state=656,this._errHandler.sync(this),this._input.LA(1)){case d.AGGREGATE:case d.CALCULATE:case d.DIMENSION:case d.EXCEPT:case d.GROUP_BY:case d.INTERNAL:case d.JOIN_CROSS:case d.JOIN_ONE:case d.JOIN_MANY:case d.MEASURE:case d.NEST:case d.PRIVATE:case d.PUBLIC:case d.QUERY:case d.RUN:case d.SELECT:case d.SOURCE:case d.VIEW:case d.ALL:case d.AVG:case d.CASE:case d.CAST:case d.COUNT:case d.COMPOSE:case d.DAY:case d.EXCLUDE:case d.FALSE:case d.HOUR:case d.IS:case d.INTERNAL_KW:case d.MAX:case d.MIN:case d.MINUTE:case d.MONTH:case d.NOT:case d.NOW:case d.NULL:case d.PICK:case d.PRIVATE_KW:case d.PUBLIC_KW:case d.QUARTER:case d.SECOND:case d.SOURCE_KW:case d.SUM:case d.TRUE:case d.WEEK:case d.YEAR:case d.HACKY_REGEX:case d.RAW_SQ:case d.RAW_DQ:case d.SQ3_FILTER:case d.SQ_FILTER:case d.DQ3_FILTER:case d.DQ_FILTER:case d.BQ3_FILTER:case d.BQ_FILTER:case d.SQ_STRING:case d.DQ_STRING:case d.BQ_STRING:case d.ANNOTATION:case d.OPAREN:case d.OBRACK:case d.OCURLY:case d.MINUS:case d.STAR:case d.LITERAL_TIMESTAMP:case d.LITERAL_HOUR:case d.LITERAL_DAY:case d.LITERAL_QUARTER:case d.LITERAL_MONTH:case d.LITERAL_WEEK:case d.LITERAL_YEAR:case d.IDENTIFIER:case d.NUMERIC_LITERAL:case d.INTEGER_LITERAL:case d.SQL_BEGIN:this.enterOuterAlt(e,1),this.state=653,this.joinStatement();break;case d.WHERE:this.enterOuterAlt(e,2),this.state=654,this.whereStatement();break;case d.DECLARE:this.enterOuterAlt(e,3),this.state=655,this.declareStatement();break;default:throw new sn.NoViableAltException(this)}}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}sourceArguments(){let e=new PR(this._ctx,this.state);this.enterRule(e,100,d.RULE_sourceArguments);let r;try{switch(this.state=671,this._errHandler.sync(this),this.interpreter.adaptivePredict(this._input,49,this._ctx)){case 1:this.enterOuterAlt(e,1),this.state=658,this.match(d.OPAREN),this.state=659,this.match(d.CPAREN);break;case 2:this.enterOuterAlt(e,2);{for(this.state=660,this.match(d.OPAREN),this.state=661,this.sourceArgument(),this.state=666,this._errHandler.sync(this),r=this._input.LA(1);r===d.COMMA;)this.state=662,this.match(d.COMMA),this.state=663,this.sourceArgument(),this.state=668,this._errHandler.sync(this),r=this._input.LA(1);this.state=669,this.match(d.CPAREN)}break}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}argumentId(){let e=new aM(this._ctx,this.state);this.enterRule(e,102,d.RULE_argumentId);try{this.enterOuterAlt(e,1),this.state=673,this.id()}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}sourceArgument(){let e=new UR(this._ctx,this.state);this.enterRule(e,104,d.RULE_sourceArgument);try{this.enterOuterAlt(e,1);{switch(this.state=678,this._errHandler.sync(this),this.interpreter.adaptivePredict(this._input,50,this._ctx)){case 1:this.state=675,this.argumentId(),this.state=676,this.match(d.IS);break}this.state=680,this.fieldExpr(0)}}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}sqExpr(e){e===void 0&&(e=0);let r=this._ctx,i=this.state,s=new cn(this._ctx,i),o=s,u=106;this.enterRecursionRule(s,106,d.RULE_sqExpr,e);let a;try{let l;this.enterOuterAlt(s,1);{switch(this.state=706,this._errHandler.sync(this),this.interpreter.adaptivePredict(this._input,54,this._ctx)){case 1:switch(s=new dfe(s),this._ctx=s,o=s,this.state=683,this.id(),this.state=685,this._errHandler.sync(this),this.interpreter.adaptivePredict(this._input,51,this._ctx)){case 1:this.state=684,this.sourceArguments();break}break;case 2:s=new hfe(s),this._ctx=s,o=s,this.state=687,this.match(d.OPAREN),this.state=688,this.sqExpr(0),this.state=689,this.match(d.CPAREN);break;case 3:{if(s=new pfe(s),this._ctx=s,o=s,this.state=691,this.match(d.COMPOSE),this.state=692,this.match(d.OPAREN),this.state=701,this._errHandler.sync(this),a=this._input.LA(1),a===d.COMPOSE||a===d.BQ_STRING||a===d.OPAREN||a===d.IDENTIFIER)for(this.state=693,this.sqExpr(0),this.state=698,this._errHandler.sync(this),a=this._input.LA(1);a===d.COMMA;)this.state=694,this.match(d.COMMA),this.state=695,this.sqExpr(0),this.state=700,this._errHandler.sync(this),a=this._input.LA(1);this.state=703,this.match(d.CPAREN)}break;case 4:s=new Afe(s),this._ctx=s,o=s,this.state=704,this.exploreTable();break;case 5:s=new _fe(s),this._ctx=s,o=s,this.state=705,this.sqlSource();break}for(this._ctx._stop=this._input.tryLT(-1),this.state=726,this._errHandler.sync(this),l=this.interpreter.adaptivePredict(this._input,57,this._ctx);l!==2&&l!==rn.ATN.INVALID_ALT_NUMBER;){if(l===1)switch(this._parseListeners!=null&&this.triggerExitRuleEvent(),o=s,this.state=724,this._errHandler.sync(this),this.interpreter.adaptivePredict(this._input,56,this._ctx)){case 1:{if(s=new mfe(new cn(r,i)),this.pushNewRecursionContext(s,u,d.RULE_sqExpr),this.state=708,!this.precpred(this._ctx,6))throw this.createFailedPredicateException("this.precpred(this._ctx, 6)");this.state=709,this.match(d.PLUS),this.state=710,this.segExpr(0)}break;case 2:{if(s=new gfe(new cn(r,i)),this.pushNewRecursionContext(s,u,d.RULE_sqExpr),this.state=711,!this.precpred(this._ctx,5))throw this.createFailedPredicateException("this.precpred(this._ctx, 5)");this.state=712,this.match(d.ARROW),this.state=713,this.segExpr(0)}break;case 3:{if(s=new yfe(new cn(r,i)),this.pushNewRecursionContext(s,u,d.RULE_sqExpr),this.state=714,!this.precpred(this._ctx,4))throw this.createFailedPredicateException("this.precpred(this._ctx, 4)");this.state=717,this._errHandler.sync(this),a=this._input.LA(1),a===d.INCLUDE&&(this.state=715,this.match(d.INCLUDE),this.state=716,this.includeBlock()),this.state=719,this.match(d.EXTEND),this.state=720,this.exploreProperties()}break;case 4:{if(s=new Efe(new cn(r,i)),this.pushNewRecursionContext(s,u,d.RULE_sqExpr),this.state=721,!this.precpred(this._ctx,3))throw this.createFailedPredicateException("this.precpred(this._ctx, 3)");this.state=722,this.match(d.INCLUDE),this.state=723,this.includeBlock()}break}this.state=728,this._errHandler.sync(this),l=this.interpreter.adaptivePredict(this._input,57,this._ctx)}}}catch(l){if(l instanceof ye.RecognitionException)s.exception=l,this._errHandler.reportError(this,l),this._errHandler.recover(this,l);else throw l}finally{this.unrollRecursionContexts(r)}return s}includeBlock(){let e=new jR(this._ctx,this.state);this.enterRule(e,108,d.RULE_includeBlock);let r;try{this.enterOuterAlt(e,1);{for(this.state=729,this.match(d.OCURLY),this.state=734,this._errHandler.sync(this),r=this._input.LA(1);!(r&-32)&&1<<r&(1<<d.AGGREGATE|1<<d.CALCULATE|1<<d.DIMENSION|1<<d.EXCEPT|1<<d.GROUP_BY|1<<d.INTERNAL|1<<d.JOIN_CROSS|1<<d.JOIN_ONE|1<<d.JOIN_MANY|1<<d.MEASURE|1<<d.NEST|1<<d.PRIVATE|1<<d.PUBLIC|1<<d.QUERY|1<<d.RUN|1<<d.SELECT|1<<d.SOURCE)||!(r-34&-32)&&1<<r-34&(1<<d.VIEW-34|1<<d.ALL-34|1<<d.AVG-34|1<<d.CASE-34|1<<d.CAST-34|1<<d.COUNT-34|1<<d.COMPOSE-34|1<<d.DAY-34|1<<d.EXCLUDE-34|1<<d.FALSE-34|1<<d.HOUR-34)||!(r-66&-32)&&1<<r-66&(1<<d.IS-66|1<<d.INTERNAL_KW-66|1<<d.MAX-66|1<<d.MIN-66|1<<d.MINUTE-66|1<<d.MONTH-66|1<<d.NOT-66|1<<d.NOW-66|1<<d.NULL-66|1<<d.PICK-66|1<<d.PRIVATE_KW-66|1<<d.PUBLIC_KW-66|1<<d.QUARTER-66|1<<d.SECOND-66|1<<d.SOURCE_KW-66|1<<d.SUM-66)||!(r-98&-32)&&1<<r-98&(1<<d.TRUE-98|1<<d.WEEK-98|1<<d.YEAR-98|1<<d.HACKY_REGEX-98|1<<d.RAW_SQ-98|1<<d.RAW_DQ-98|1<<d.SQ3_FILTER-98|1<<d.SQ_FILTER-98|1<<d.DQ3_FILTER-98|1<<d.DQ_FILTER-98|1<<d.BQ3_FILTER-98|1<<d.BQ_FILTER-98|1<<d.SQ_STRING-98|1<<d.DQ_STRING-98|1<<d.BQ_STRING-98|1<<d.ANNOTATION-98|1<<d.OPAREN-98|1<<d.OBRACK-98|1<<d.OCURLY-98)||!(r-141&-32)&&1<<r-141&(1<<d.MINUS-141|1<<d.STAR-141|1<<d.SEMI-141|1<<d.LITERAL_TIMESTAMP-141|1<<d.LITERAL_HOUR-141|1<<d.LITERAL_DAY-141|1<<d.LITERAL_QUARTER-141|1<<d.LITERAL_MONTH-141|1<<d.LITERAL_WEEK-141|1<<d.LITERAL_YEAR-141|1<<d.IDENTIFIER-141|1<<d.NUMERIC_LITERAL-141|1<<d.INTEGER_LITERAL-141|1<<d.SQL_BEGIN-141);){switch(this.state=732,this._errHandler.sync(this),this._input.LA(1)){case d.AGGREGATE:case d.CALCULATE:case d.DIMENSION:case d.EXCEPT:case d.GROUP_BY:case d.INTERNAL:case d.JOIN_CROSS:case d.JOIN_ONE:case d.JOIN_MANY:case d.MEASURE:case d.NEST:case d.PRIVATE:case d.PUBLIC:case d.QUERY:case d.RUN:case d.SELECT:case d.SOURCE:case d.VIEW:case d.ALL:case d.AVG:case d.CASE:case d.CAST:case d.COUNT:case d.COMPOSE:case d.DAY:case d.EXCLUDE:case d.FALSE:case d.HOUR:case d.IS:case d.INTERNAL_KW:case d.MAX:case d.MIN:case d.MINUTE:case d.MONTH:case d.NOT:case d.NOW:case d.NULL:case d.PICK:case d.PRIVATE_KW:case d.PUBLIC_KW:case d.QUARTER:case d.SECOND:case d.SOURCE_KW:case d.SUM:case d.TRUE:case d.WEEK:case d.YEAR:case d.HACKY_REGEX:case d.RAW_SQ:case d.RAW_DQ:case d.SQ3_FILTER:case d.SQ_FILTER:case d.DQ3_FILTER:case d.DQ_FILTER:case d.BQ3_FILTER:case d.BQ_FILTER:case d.SQ_STRING:case d.DQ_STRING:case d.BQ_STRING:case d.ANNOTATION:case d.OPAREN:case d.OBRACK:case d.OCURLY:case d.MINUS:case d.STAR:case d.LITERAL_TIMESTAMP:case d.LITERAL_HOUR:case d.LITERAL_DAY:case d.LITERAL_QUARTER:case d.LITERAL_MONTH:case d.LITERAL_WEEK:case d.LITERAL_YEAR:case d.IDENTIFIER:case d.NUMERIC_LITERAL:case d.INTEGER_LITERAL:case d.SQL_BEGIN:this.state=730,this.includeItem();break;case d.SEMI:this.state=731,this.match(d.SEMI);break;default:throw new sn.NoViableAltException(this)}this.state=736,this._errHandler.sync(this),r=this._input.LA(1)}this.state=737,this.match(d.CCURLY)}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}includeItem(){let e=new qR(this._ctx,this.state);this.enterRule(e,110,d.RULE_includeItem);try{switch(this.state=749,this._errHandler.sync(this),this.interpreter.adaptivePredict(this._input,60,this._ctx)){case 1:this.enterOuterAlt(e,1),this.state=739,this.tags(),this.state=740,this.accessLabelProp(),this.state=741,this.includeList();break;case 2:this.enterOuterAlt(e,2),this.state=743,this.includeList();break;case 3:this.enterOuterAlt(e,3),this.state=744,this.tags(),this.state=745,this.match(d.EXCEPT),this.state=746,this.includeExceptList();break;case 4:this.enterOuterAlt(e,4),this.state=748,this.orphanedAnnotation();break}}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}orphanedAnnotation(){let e=new lM(this._ctx,this.state);this.enterRule(e,112,d.RULE_orphanedAnnotation);try{this.enterOuterAlt(e,1),this.state=751,this.match(d.ANNOTATION)}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}accessLabelProp(){let e=new cM(this._ctx,this.state);this.enterRule(e,114,d.RULE_accessLabelProp);let r;try{this.enterOuterAlt(e,1),this.state=753,r=this._input.LA(1),!(r&-32)&&1<<r&(1<<d.INTERNAL|1<<d.PRIVATE|1<<d.PUBLIC)?(this._input.LA(1)===Wn.Token.EOF&&(this.matchedEOF=!0),this._errHandler.reportMatch(this),this.consume()):this._errHandler.recoverInline(this)}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}includeExceptList(){let e=new fM(this._ctx,this.state);this.enterRule(e,116,d.RULE_includeExceptList);let r;try{let i;this.enterOuterAlt(e,1);{for(this.state=755,this.includeExceptListItem(),this.state=762,this._errHandler.sync(this),i=this.interpreter.adaptivePredict(this._input,62,this._ctx);i!==2&&i!==rn.ATN.INVALID_ALT_NUMBER;)i===1&&(this.state=757,this._errHandler.sync(this),r=this._input.LA(1),r===d.COMMA&&(this.state=756,this.match(d.COMMA)),this.state=759,this.includeExceptListItem()),this.state=764,this._errHandler.sync(this),i=this.interpreter.adaptivePredict(this._input,62,this._ctx);this.state=766,this._errHandler.sync(this),r=this._input.LA(1),r===d.COMMA&&(this.state=765,this.match(d.COMMA))}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}includeExceptListItem(){let e=new HR(this._ctx,this.state);this.enterRule(e,118,d.RULE_includeExceptListItem);try{switch(this.state=774,this._errHandler.sync(this),this.interpreter.adaptivePredict(this._input,64,this._ctx)){case 1:this.enterOuterAlt(e,1),this.state=768,this.tags(),this.state=769,this.fieldName();break;case 2:this.enterOuterAlt(e,2),this.state=771,this.tags(),this.state=772,this.collectionWildCard();break}}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}includeList(){let e=new xM(this._ctx,this.state);this.enterRule(e,120,d.RULE_includeList);let r;try{let i;this.enterOuterAlt(e,1);{for(this.state=776,this.includeField(),this.state=783,this._errHandler.sync(this),i=this.interpreter.adaptivePredict(this._input,66,this._ctx);i!==2&&i!==rn.ATN.INVALID_ALT_NUMBER;)i===1&&(this.state=778,this._errHandler.sync(this),r=this._input.LA(1),r===d.COMMA&&(this.state=777,this.match(d.COMMA)),this.state=780,this.includeField()),this.state=785,this._errHandler.sync(this),i=this.interpreter.adaptivePredict(this._input,66,this._ctx);this.state=787,this._errHandler.sync(this),r=this._input.LA(1),r===d.COMMA&&(this.state=786,this.match(d.COMMA))}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}includeField(){let e=new QR(this._ctx,this.state);this.enterRule(e,122,d.RULE_includeField);try{switch(this.state=803,this._errHandler.sync(this),this.interpreter.adaptivePredict(this._input,69,this._ctx)){case 1:this.enterOuterAlt(e,1);{switch(this.state=789,this.tags(),this.state=793,this._errHandler.sync(this),this.interpreter.adaptivePredict(this._input,68,this._ctx)){case 1:this.state=790,e._as=this.fieldName(),this.state=791,this.isDefine();break}this.state=795,e._name=this.fieldName()}break;case 2:this.enterOuterAlt(e,2),this.state=797,this.tags(),this.state=798,e._name=this.fieldName();break;case 3:this.enterOuterAlt(e,3),this.state=800,this.tags(),this.state=801,this.collectionWildCard();break}}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}segExpr(e){e===void 0&&(e=0);let r=this._ctx,i=this.state,s=new Ws(this._ctx,i),o=s,u=124;this.enterRecursionRule(s,124,d.RULE_segExpr,e);try{let a;this.enterOuterAlt(s,1);{switch(this.state=812,this._errHandler.sync(this),this._input.LA(1)){case d.BQ_STRING:case d.IDENTIFIER:s=new vfe(s),this._ctx=s,o=s,this.state=806,this.fieldPath();break;case d.OCURLY:s=new Cfe(s),this._ctx=s,o=s,this.state=807,this.queryProperties();break;case d.OPAREN:s=new Sfe(s),this._ctx=s,o=s,this.state=808,this.match(d.OPAREN),this.state=809,this.vExpr(),this.state=810,this.match(d.CPAREN);break;default:throw new sn.NoViableAltException(this)}for(this._ctx._stop=this._input.tryLT(-1),this.state=819,this._errHandler.sync(this),a=this.interpreter.adaptivePredict(this._input,71,this._ctx);a!==2&&a!==rn.ATN.INVALID_ALT_NUMBER;){if(a===1){this._parseListeners!=null&&this.triggerExitRuleEvent(),o=s;{if(s=new bfe(new Ws(r,i)),s._lhs=o,this.pushNewRecursionContext(s,u,d.RULE_segExpr),this.state=814,!this.precpred(this._ctx,1))throw this.createFailedPredicateException("this.precpred(this._ctx, 1)");this.state=815,this.match(d.PLUS),this.state=816,s._rhs=this.segExpr(2)}}this.state=821,this._errHandler.sync(this),a=this.interpreter.adaptivePredict(this._input,71,this._ctx)}}}catch(a){if(a instanceof ye.RecognitionException)s.exception=a,this._errHandler.reportError(this,a),this._errHandler.recover(this,a);else throw a}finally{this.unrollRecursionContexts(r)}return s}vExpr(){let e=new xf(this._ctx,this.state);this.enterRule(e,126,d.RULE_vExpr);try{switch(this.state=827,this._errHandler.sync(this),this.interpreter.adaptivePredict(this._input,72,this._ctx)){case 1:e=new Tfe(e),this.enterOuterAlt(e,1),this.state=822,this.segExpr(0);break;case 2:e=new Rfe(e),this.enterOuterAlt(e,2),this.state=823,e._lhs=this.segExpr(0),this.state=824,this.match(d.ARROW),this.state=825,e._rhs=this.vExpr();break}}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}queryExtendStatement(){let e=new zR(this._ctx,this.state);this.enterRule(e,128,d.RULE_queryExtendStatement);try{switch(this.state=832,this._errHandler.sync(this),this.interpreter.adaptivePredict(this._input,73,this._ctx)){case 1:this.enterOuterAlt(e,1),this.state=829,this.defDimensions();break;case 2:this.enterOuterAlt(e,2),this.state=830,this.defMeasures();break;case 3:this.enterOuterAlt(e,3),this.state=831,this.joinStatement();break}}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}queryExtendStatementList(){let e=new dM(this._ctx,this.state);this.enterRule(e,130,d.RULE_queryExtendStatementList);let r;try{this.enterOuterAlt(e,1);{for(this.state=834,this.match(d.OCURLY),this.state=839,this._errHandler.sync(this),r=this._input.LA(1);!(r&-32)&&1<<r&(1<<d.AGGREGATE|1<<d.CALCULATE|1<<d.DIMENSION|1<<d.EXCEPT|1<<d.GROUP_BY|1<<d.INTERNAL|1<<d.JOIN_CROSS|1<<d.JOIN_ONE|1<<d.JOIN_MANY|1<<d.MEASURE|1<<d.NEST|1<<d.PRIVATE|1<<d.PUBLIC|1<<d.QUERY|1<<d.RUN|1<<d.SELECT|1<<d.SOURCE)||!(r-34&-32)&&1<<r-34&(1<<d.VIEW-34|1<<d.ALL-34|1<<d.AVG-34|1<<d.CASE-34|1<<d.CAST-34|1<<d.COUNT-34|1<<d.COMPOSE-34|1<<d.DAY-34|1<<d.EXCLUDE-34|1<<d.FALSE-34|1<<d.HOUR-34)||!(r-66&-32)&&1<<r-66&(1<<d.IS-66|1<<d.INTERNAL_KW-66|1<<d.MAX-66|1<<d.MIN-66|1<<d.MINUTE-66|1<<d.MONTH-66|1<<d.NOT-66|1<<d.NOW-66|1<<d.NULL-66|1<<d.PICK-66|1<<d.PRIVATE_KW-66|1<<d.PUBLIC_KW-66|1<<d.QUARTER-66|1<<d.SECOND-66|1<<d.SOURCE_KW-66|1<<d.SUM-66)||!(r-98&-32)&&1<<r-98&(1<<d.TRUE-98|1<<d.WEEK-98|1<<d.YEAR-98|1<<d.HACKY_REGEX-98|1<<d.RAW_SQ-98|1<<d.RAW_DQ-98|1<<d.SQ3_FILTER-98|1<<d.SQ_FILTER-98|1<<d.DQ3_FILTER-98|1<<d.DQ_FILTER-98|1<<d.BQ3_FILTER-98|1<<d.BQ_FILTER-98|1<<d.SQ_STRING-98|1<<d.DQ_STRING-98|1<<d.BQ_STRING-98|1<<d.ANNOTATION-98|1<<d.OPAREN-98|1<<d.OBRACK-98|1<<d.OCURLY-98)||!(r-141&-32)&&1<<r-141&(1<<d.MINUS-141|1<<d.STAR-141|1<<d.SEMI-141|1<<d.LITERAL_TIMESTAMP-141|1<<d.LITERAL_HOUR-141|1<<d.LITERAL_DAY-141|1<<d.LITERAL_QUARTER-141|1<<d.LITERAL_MONTH-141|1<<d.LITERAL_WEEK-141|1<<d.LITERAL_YEAR-141|1<<d.IDENTIFIER-141|1<<d.NUMERIC_LITERAL-141|1<<d.INTEGER_LITERAL-141|1<<d.SQL_BEGIN-141);){switch(this.state=837,this._errHandler.sync(this),this._input.LA(1)){case d.AGGREGATE:case d.CALCULATE:case d.DIMENSION:case d.EXCEPT:case d.GROUP_BY:case d.INTERNAL:case d.JOIN_CROSS:case d.JOIN_ONE:case d.JOIN_MANY:case d.MEASURE:case d.NEST:case d.PRIVATE:case d.PUBLIC:case d.QUERY:case d.RUN:case d.SELECT:case d.SOURCE:case d.VIEW:case d.ALL:case d.AVG:case d.CASE:case d.CAST:case d.COUNT:case d.COMPOSE:case d.DAY:case d.EXCLUDE:case d.FALSE:case d.HOUR:case d.IS:case d.INTERNAL_KW:case d.MAX:case d.MIN:case d.MINUTE:case d.MONTH:case d.NOT:case d.NOW:case d.NULL:case d.PICK:case d.PRIVATE_KW:case d.PUBLIC_KW:case d.QUARTER:case d.SECOND:case d.SOURCE_KW:case d.SUM:case d.TRUE:case d.WEEK:case d.YEAR:case d.HACKY_REGEX:case d.RAW_SQ:case d.RAW_DQ:case d.SQ3_FILTER:case d.SQ_FILTER:case d.DQ3_FILTER:case d.DQ_FILTER:case d.BQ3_FILTER:case d.BQ_FILTER:case d.SQ_STRING:case d.DQ_STRING:case d.BQ_STRING:case d.ANNOTATION:case d.OPAREN:case d.OBRACK:case d.OCURLY:case d.MINUS:case d.STAR:case d.LITERAL_TIMESTAMP:case d.LITERAL_HOUR:case d.LITERAL_DAY:case d.LITERAL_QUARTER:case d.LITERAL_MONTH:case d.LITERAL_WEEK:case d.LITERAL_YEAR:case d.IDENTIFIER:case d.NUMERIC_LITERAL:case d.INTEGER_LITERAL:case d.SQL_BEGIN:this.state=835,this.queryExtendStatement();break;case d.SEMI:this.state=836,this.match(d.SEMI);break;default:throw new sn.NoViableAltException(this)}this.state=841,this._errHandler.sync(this),r=this._input.LA(1)}this.state=842,this.match(d.CCURLY)}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}joinList(){let e=new qE(this._ctx,this.state);this.enterRule(e,132,d.RULE_joinList);let r;try{let i;this.enterOuterAlt(e,1);{for(this.state=844,this.joinDef(),this.state=851,this._errHandler.sync(this),i=this.interpreter.adaptivePredict(this._input,77,this._ctx);i!==2&&i!==rn.ATN.INVALID_ALT_NUMBER;)i===1&&(this.state=846,this._errHandler.sync(this),r=this._input.LA(1),r===d.COMMA&&(this.state=845,this.match(d.COMMA)),this.state=848,this.joinDef()),this.state=853,this._errHandler.sync(this),i=this.interpreter.adaptivePredict(this._input,77,this._ctx);this.state=855,this._errHandler.sync(this),r=this._input.LA(1),r===d.COMMA&&(this.state=854,this.match(d.COMMA))}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}isExplore(){let e=new hM(this._ctx,this.state);this.enterRule(e,134,d.RULE_isExplore);try{this.enterOuterAlt(e,1),this.state=857,e._before_is=this.tags(),this.state=858,this.match(d.IS),this.state=859,e._after_is=this.tags(),this.state=860,this.sqExpr(0)}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}matrixOperation(){let e=new WR(this._ctx,this.state);this.enterRule(e,136,d.RULE_matrixOperation);let r;try{this.enterOuterAlt(e,1),this.state=862,r=this._input.LA(1),!(r-58&-32)&&1<<r-58&(1<<d.FULL-58|1<<d.INNER-58|1<<d.LEFT-58|1<<d.RIGHT-58)?(this._input.LA(1)===Wn.Token.EOF&&(this.matchedEOF=!0),this._errHandler.reportMatch(this),this.consume()):this._errHandler.recoverInline(this)}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}joinFrom(){let e=new GR(this._ctx,this.state);this.enterRule(e,138,d.RULE_joinFrom);try{switch(this.state=871,this._errHandler.sync(this),this.interpreter.adaptivePredict(this._input,79,this._ctx)){case 1:this.enterOuterAlt(e,1),this.state=864,this.joinNameDef();break;case 2:this.enterOuterAlt(e,2),this.state=865,this.joinNameDef(),this.state=866,this.sourceArguments();break;case 3:this.enterOuterAlt(e,3),this.state=868,this.joinNameDef(),this.state=869,this.isExplore();break}}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}joinDef(){let e=new e1(this._ctx,this.state);this.enterRule(e,140,d.RULE_joinDef);let r;try{switch(this.state=900,this._errHandler.sync(this),this.interpreter.adaptivePredict(this._input,85,this._ctx)){case 1:e=new Dfe(e),this.enterOuterAlt(e,1);{for(this.state=876,this._errHandler.sync(this),r=this._input.LA(1);r===d.ANNOTATION;)this.state=873,this.match(d.ANNOTATION),this.state=878,this._errHandler.sync(this),r=this._input.LA(1);this.state=879,this.joinFrom(),this.state=881,this._errHandler.sync(this),r=this._input.LA(1),!(r-58&-32)&&1<<r-58&(1<<d.FULL-58|1<<d.INNER-58|1<<d.LEFT-58|1<<d.RIGHT-58)&&(this.state=880,this.matrixOperation()),this.state=883,this.match(d.WITH),this.state=884,this.fieldExpr(0)}break;case 2:e=new Ofe(e),this.enterOuterAlt(e,2);{for(this.state=889,this._errHandler.sync(this),r=this._input.LA(1);r===d.ANNOTATION;)this.state=886,this.match(d.ANNOTATION),this.state=891,this._errHandler.sync(this),r=this._input.LA(1);this.state=892,this.joinFrom(),this.state=898,this._errHandler.sync(this),r=this._input.LA(1),!(r-58&-32)&&1<<r-58&(1<<d.FULL-58|1<<d.INNER-58|1<<d.LEFT-58|1<<d.ON-58|1<<d.RIGHT-58)&&(this.state=894,this._errHandler.sync(this),r=this._input.LA(1),!(r-58&-32)&&1<<r-58&(1<<d.FULL-58|1<<d.INNER-58|1<<d.LEFT-58|1<<d.RIGHT-58)&&(this.state=893,this.matrixOperation()),this.state=896,this.match(d.ON),this.state=897,this.joinExpression())}break}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}joinExpression(){let e=new pM(this._ctx,this.state);this.enterRule(e,142,d.RULE_joinExpression);try{this.enterOuterAlt(e,1),this.state=902,this.fieldExpr(0)}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}filterStatement(){let e=new Ffe(this._ctx,this.state);this.enterRule(e,144,d.RULE_filterStatement);try{switch(this.state=906,this._errHandler.sync(this),this._input.LA(1)){case d.WHERE:this.enterOuterAlt(e,1),this.state=904,this.whereStatement();break;case d.HAVING:this.enterOuterAlt(e,2),this.state=905,this.havingStatement();break;default:throw new sn.NoViableAltException(this)}}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}fieldProperties(){let e=new mM(this._ctx,this.state);this.enterRule(e,146,d.RULE_fieldProperties);let r;try{this.enterOuterAlt(e,1);{for(this.state=908,this.match(d.OCURLY),this.state=913,this._errHandler.sync(this),r=this._input.LA(1);!(r-17&-32)&&1<<r-17&(1<<d.LIMIT-17|1<<d.ORDER_BY-17|1<<d.PARTITION_BY-17|1<<d.WHERE-17)||r===d.SEMI;){switch(this.state=911,this._errHandler.sync(this),this._input.LA(1)){case d.LIMIT:case d.ORDER_BY:case d.PARTITION_BY:case d.WHERE:this.state=909,this.fieldPropertyStatement();break;case d.SEMI:this.state=910,this.match(d.SEMI);break;default:throw new sn.NoViableAltException(this)}this.state=915,this._errHandler.sync(this),r=this._input.LA(1)}this.state=916,this.match(d.CCURLY)}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}aggregateOrdering(){let e=new gM(this._ctx,this.state);this.enterRule(e,148,d.RULE_aggregateOrdering);let r;try{let i;this.enterOuterAlt(e,1);{for(this.state=918,this.aggregateOrderBySpec(),this.state=923,this._errHandler.sync(this),i=this.interpreter.adaptivePredict(this._input,89,this._ctx);i!==2&&i!==rn.ATN.INVALID_ALT_NUMBER;)i===1&&(this.state=919,this.match(d.COMMA),this.state=920,this.aggregateOrderBySpec()),this.state=925,this._errHandler.sync(this),i=this.interpreter.adaptivePredict(this._input,89,this._ctx);this.state=927,this._errHandler.sync(this),r=this._input.LA(1),r===d.COMMA&&(this.state=926,this.match(d.COMMA))}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}aggregateOrderBySpec(){let e=new VR(this._ctx,this.state);this.enterRule(e,150,d.RULE_aggregateOrderBySpec);let r;try{switch(this.state=935,this._errHandler.sync(this),this._input.LA(1)){case d.ALL:case d.AVG:case d.CASE:case d.CAST:case d.COUNT:case d.DAY:case d.EXCLUDE:case d.FALSE:case d.HOUR:case d.MAX:case d.MIN:case d.MINUTE:case d.MONTH:case d.NOT:case d.NOW:case d.NULL:case d.PICK:case d.QUARTER:case d.SECOND:case d.SOURCE_KW:case d.SUM:case d.TRUE:case d.WEEK:case d.YEAR:case d.HACKY_REGEX:case d.RAW_SQ:case d.RAW_DQ:case d.SQ3_FILTER:case d.SQ_FILTER:case d.DQ3_FILTER:case d.DQ_FILTER:case d.BQ3_FILTER:case d.BQ_FILTER:case d.SQ_STRING:case d.DQ_STRING:case d.BQ_STRING:case d.OPAREN:case d.OBRACK:case d.OCURLY:case d.MINUS:case d.LITERAL_TIMESTAMP:case d.LITERAL_HOUR:case d.LITERAL_DAY:case d.LITERAL_QUARTER:case d.LITERAL_MONTH:case d.LITERAL_WEEK:case d.LITERAL_YEAR:case d.IDENTIFIER:case d.NUMERIC_LITERAL:case d.INTEGER_LITERAL:case d.SQL_BEGIN:this.enterOuterAlt(e,1),this.state=929,this.fieldExpr(0),this.state=931,this._errHandler.sync(this),r=this._input.LA(1),(r===d.ASC||r===d.DESC)&&(this.state=930,r=this._input.LA(1),r===d.ASC||r===d.DESC?(this._input.LA(1)===Wn.Token.EOF&&(this.matchedEOF=!0),this._errHandler.reportMatch(this),this.consume()):this._errHandler.recoverInline(this));break;case d.ASC:this.enterOuterAlt(e,2),this.state=933,this.match(d.ASC);break;case d.DESC:this.enterOuterAlt(e,3),this.state=934,this.match(d.DESC);break;default:throw new sn.NoViableAltException(this)}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}aggregateOrderByStatement(){let e=new yM(this._ctx,this.state);this.enterRule(e,152,d.RULE_aggregateOrderByStatement);try{this.enterOuterAlt(e,1),this.state=937,this.match(d.ORDER_BY),this.state=938,this.aggregateOrdering()}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}fieldPropertyLimitStatement(){let e=new EM(this._ctx,this.state);this.enterRule(e,154,d.RULE_fieldPropertyLimitStatement);try{this.enterOuterAlt(e,1),this.state=940,this.limitStatement()}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}fieldPropertyStatement(){let e=new YR(this._ctx,this.state);this.enterRule(e,156,d.RULE_fieldPropertyStatement);try{switch(this.state=946,this._errHandler.sync(this),this._input.LA(1)){case d.WHERE:this.enterOuterAlt(e,1),this.state=942,this.whereStatement();break;case d.PARTITION_BY:this.enterOuterAlt(e,2),this.state=943,this.partitionByStatement();break;case d.ORDER_BY:this.enterOuterAlt(e,3),this.state=944,this.aggregateOrderByStatement();break;case d.LIMIT:this.enterOuterAlt(e,4),this.state=945,this.fieldPropertyLimitStatement();break;default:throw new sn.NoViableAltException(this)}}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}filterClauseList(){let e=new KR(this._ctx,this.state);this.enterRule(e,158,d.RULE_filterClauseList);let r;try{let i;this.enterOuterAlt(e,1);{for(this.state=948,this.fieldExpr(0),this.state=953,this._errHandler.sync(this),i=this.interpreter.adaptivePredict(this._input,94,this._ctx);i!==2&&i!==rn.ATN.INVALID_ALT_NUMBER;)i===1&&(this.state=949,this.match(d.COMMA),this.state=950,this.fieldExpr(0)),this.state=955,this._errHandler.sync(this),i=this.interpreter.adaptivePredict(this._input,94,this._ctx);this.state=957,this._errHandler.sync(this),r=this._input.LA(1),r===d.COMMA&&(this.state=956,this.match(d.COMMA))}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}whereStatement(){let e=new Nd(this._ctx,this.state);this.enterRule(e,160,d.RULE_whereStatement);try{this.enterOuterAlt(e,1),this.state=959,this.match(d.WHERE),this.state=960,this.filterClauseList()}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}havingStatement(){let e=new JR(this._ctx,this.state);this.enterRule(e,162,d.RULE_havingStatement);try{this.enterOuterAlt(e,1),this.state=962,this.match(d.HAVING),this.state=963,this.filterClauseList()}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}subQueryDefList(){let e=new AM(this._ctx,this.state);this.enterRule(e,164,d.RULE_subQueryDefList);let r;try{let i;this.enterOuterAlt(e,1);{for(this.state=965,this.exploreQueryDef(),this.state=972,this._errHandler.sync(this),i=this.interpreter.adaptivePredict(this._input,97,this._ctx);i!==2&&i!==rn.ATN.INVALID_ALT_NUMBER;)i===1&&(this.state=967,this._errHandler.sync(this),r=this._input.LA(1),r===d.COMMA&&(this.state=966,this.match(d.COMMA)),this.state=969,this.exploreQueryDef()),this.state=974,this._errHandler.sync(this),i=this.interpreter.adaptivePredict(this._input,97,this._ctx);this.state=976,this._errHandler.sync(this),r=this._input.LA(1),r===d.COMMA&&(this.state=975,this.match(d.COMMA))}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}exploreQueryNameDef(){let e=new _M(this._ctx,this.state);this.enterRule(e,166,d.RULE_exploreQueryNameDef);try{this.enterOuterAlt(e,1),this.state=978,this.id()}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}exploreQueryDef(){let e=new XR(this._ctx,this.state);this.enterRule(e,168,d.RULE_exploreQueryDef);let r;try{this.enterOuterAlt(e,1);{for(this.state=983,this._errHandler.sync(this),r=this._input.LA(1);r===d.ANNOTATION;)this.state=980,this.match(d.ANNOTATION),this.state=985,this._errHandler.sync(this),r=this._input.LA(1);this.state=986,this.exploreQueryNameDef(),this.state=987,this.isDefine(),this.state=988,this.vExpr()}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}queryStatement(){let e=new ZR(this._ctx,this.state);this.enterRule(e,170,d.RULE_queryStatement);try{switch(this.state=1008,this._errHandler.sync(this),this.interpreter.adaptivePredict(this._input,100,this._ctx)){case 1:this.enterOuterAlt(e,1),this.state=990,this.groupByStatement();break;case 2:this.enterOuterAlt(e,2),this.state=991,this.declareStatement();break;case 3:this.enterOuterAlt(e,3),this.state=992,this.queryJoinStatement();break;case 4:this.enterOuterAlt(e,4),this.state=993,this.queryExtend();break;case 5:this.enterOuterAlt(e,5),this.state=994,this.projectStatement();break;case 6:this.enterOuterAlt(e,6),this.state=995,this.indexStatement();break;case 7:this.enterOuterAlt(e,7),this.state=996,this.aggregateStatement();break;case 8:this.enterOuterAlt(e,8),this.state=997,this.calculateStatement();break;case 9:this.enterOuterAlt(e,9),this.state=998,this.topStatement();break;case 10:this.enterOuterAlt(e,10),this.state=999,this.limitStatement();break;case 11:this.enterOuterAlt(e,11),this.state=1e3,this.orderByStatement();break;case 12:this.enterOuterAlt(e,12),this.state=1001,this.whereStatement();break;case 13:this.enterOuterAlt(e,13),this.state=1002,this.havingStatement();break;case 14:this.enterOuterAlt(e,14),this.state=1003,this.nestStatement();break;case 15:this.enterOuterAlt(e,15),this.state=1004,this.sampleStatement();break;case 16:this.enterOuterAlt(e,16),this.state=1005,this.timezoneStatement();break;case 17:this.enterOuterAlt(e,17),this.state=1006,this.queryAnnotation();break;case 18:this.enterOuterAlt(e,18),this.state=1007,this.ignoredModelAnnotations();break}}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}queryJoinStatement(){let e=new vM(this._ctx,this.state);this.enterRule(e,172,d.RULE_queryJoinStatement);try{this.enterOuterAlt(e,1),this.state=1010,this.joinStatement()}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}groupByStatement(){let e=new CM(this._ctx,this.state);this.enterRule(e,174,d.RULE_groupByStatement);try{this.enterOuterAlt(e,1),this.state=1012,this.tags(),this.state=1013,this.match(d.GROUP_BY),this.state=1014,this.queryFieldList()}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}queryFieldList(){let e=new HE(this._ctx,this.state);this.enterRule(e,176,d.RULE_queryFieldList);let r;try{let i;this.enterOuterAlt(e,1);{for(this.state=1016,this.queryFieldEntry(),this.state=1023,this._errHandler.sync(this),i=this.interpreter.adaptivePredict(this._input,102,this._ctx);i!==2&&i!==rn.ATN.INVALID_ALT_NUMBER;)i===1&&(this.state=1018,this._errHandler.sync(this),r=this._input.LA(1),r===d.COMMA&&(this.state=1017,this.match(d.COMMA)),this.state=1020,this.queryFieldEntry()),this.state=1025,this._errHandler.sync(this),i=this.interpreter.adaptivePredict(this._input,102,this._ctx);this.state=1027,this._errHandler.sync(this),r=this._input.LA(1),r===d.COMMA&&(this.state=1026,this.match(d.COMMA))}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}queryFieldEntry(){let e=new eD(this._ctx,this.state);this.enterRule(e,178,d.RULE_queryFieldEntry);try{switch(this.state=1031,this._errHandler.sync(this),this.interpreter.adaptivePredict(this._input,104,this._ctx)){case 1:this.enterOuterAlt(e,1),this.state=1029,this.taggedRef();break;case 2:this.enterOuterAlt(e,2),this.state=1030,this.fieldDef();break}}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}nestStatement(){let e=new SM(this._ctx,this.state);this.enterRule(e,180,d.RULE_nestStatement);try{this.enterOuterAlt(e,1),this.state=1033,this.tags(),this.state=1034,this.match(d.NEST),this.state=1035,this.nestedQueryList()}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}nestedQueryList(){let e=new bM(this._ctx,this.state);this.enterRule(e,182,d.RULE_nestedQueryList);let r;try{let i;this.enterOuterAlt(e,1);{for(this.state=1037,this.nestEntry(),this.state=1044,this._errHandler.sync(this),i=this.interpreter.adaptivePredict(this._input,106,this._ctx);i!==2&&i!==rn.ATN.INVALID_ALT_NUMBER;)i===1&&(this.state=1039,this._errHandler.sync(this),r=this._input.LA(1),r===d.COMMA&&(this.state=1038,this.match(d.COMMA)),this.state=1041,this.nestEntry()),this.state=1046,this._errHandler.sync(this),i=this.interpreter.adaptivePredict(this._input,106,this._ctx);this.state=1048,this._errHandler.sync(this),r=this._input.LA(1),r===d.COMMA&&(this.state=1047,this.match(d.COMMA))}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}nestEntry(){let e=new QE(this._ctx,this.state);this.enterRule(e,184,d.RULE_nestEntry);try{e=new wfe(e),this.enterOuterAlt(e,1);{switch(this.state=1050,this.tags(),this.state=1054,this._errHandler.sync(this),this.interpreter.adaptivePredict(this._input,108,this._ctx)){case 1:this.state=1051,this.queryName(),this.state=1052,this.isDefine();break}this.state=1056,this.vExpr()}}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}aggregateStatement(){let e=new TM(this._ctx,this.state);this.enterRule(e,186,d.RULE_aggregateStatement);try{this.enterOuterAlt(e,1),this.state=1058,this.tags(),this.state=1059,this.match(d.AGGREGATE),this.state=1060,this.queryFieldList()}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}calculateStatement(){let e=new RM(this._ctx,this.state);this.enterRule(e,188,d.RULE_calculateStatement);try{this.enterOuterAlt(e,1),this.state=1062,this.tags(),this.state=1063,this.match(d.CALCULATE),this.state=1064,this.queryFieldList()}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}projectStatement(){let e=new DM(this._ctx,this.state);this.enterRule(e,190,d.RULE_projectStatement);try{this.enterOuterAlt(e,1),this.state=1066,this.tags(),this.state=1067,this.match(d.SELECT),this.state=1068,this.fieldCollection()}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}partitionByStatement(){let e=new OM(this._ctx,this.state);this.enterRule(e,192,d.RULE_partitionByStatement);let r;try{let i;this.enterOuterAlt(e,1);{for(this.state=1070,this.match(d.PARTITION_BY),this.state=1071,this.id(),this.state=1076,this._errHandler.sync(this),i=this.interpreter.adaptivePredict(this._input,109,this._ctx);i!==2&&i!==rn.ATN.INVALID_ALT_NUMBER;)i===1&&(this.state=1072,this.match(d.COMMA),this.state=1073,this.id()),this.state=1078,this._errHandler.sync(this),i=this.interpreter.adaptivePredict(this._input,109,this._ctx);this.state=1080,this._errHandler.sync(this),r=this._input.LA(1),r===d.COMMA&&(this.state=1079,this.match(d.COMMA))}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}orderByStatement(){let e=new FM(this._ctx,this.state);this.enterRule(e,194,d.RULE_orderByStatement);try{this.enterOuterAlt(e,1),this.state=1082,this.match(d.ORDER_BY),this.state=1083,this.ordering()}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}ordering(){let e=new wM(this._ctx,this.state);this.enterRule(e,196,d.RULE_ordering);let r;try{let i;this.enterOuterAlt(e,1);{for(this.state=1085,this.orderBySpec(),this.state=1092,this._errHandler.sync(this),i=this.interpreter.adaptivePredict(this._input,112,this._ctx);i!==2&&i!==rn.ATN.INVALID_ALT_NUMBER;)i===1&&(this.state=1087,this._errHandler.sync(this),r=this._input.LA(1),r===d.COMMA&&(this.state=1086,this.match(d.COMMA)),this.state=1089,this.orderBySpec()),this.state=1094,this._errHandler.sync(this),i=this.interpreter.adaptivePredict(this._input,112,this._ctx);this.state=1096,this._errHandler.sync(this),r=this._input.LA(1),r===d.COMMA&&(this.state=1095,this.match(d.COMMA))}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}orderBySpec(){let e=new tD(this._ctx,this.state);this.enterRule(e,198,d.RULE_orderBySpec);let r;try{this.enterOuterAlt(e,1);{switch(this.state=1100,this._errHandler.sync(this),this._input.LA(1)){case d.INTEGER_LITERAL:this.state=1098,this.match(d.INTEGER_LITERAL);break;case d.BQ_STRING:case d.IDENTIFIER:this.state=1099,this.fieldName();break;default:throw new sn.NoViableAltException(this)}this.state=1103,this._errHandler.sync(this),r=this._input.LA(1),(r===d.ASC||r===d.DESC)&&(this.state=1102,r=this._input.LA(1),r===d.ASC||r===d.DESC?(this._input.LA(1)===Wn.Token.EOF&&(this.matchedEOF=!0),this._errHandler.reportMatch(this),this.consume()):this._errHandler.recoverInline(this))}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}limitStatement(){let e=new nD(this._ctx,this.state);this.enterRule(e,200,d.RULE_limitStatement);try{this.enterOuterAlt(e,1),this.state=1105,this.match(d.LIMIT),this.state=1106,this.match(d.INTEGER_LITERAL)}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}bySpec(){let e=new Nfe(this._ctx,this.state);this.enterRule(e,202,d.RULE_bySpec);try{switch(this.state=1112,this._errHandler.sync(this),this.interpreter.adaptivePredict(this._input,116,this._ctx)){case 1:this.enterOuterAlt(e,1),this.state=1108,this.match(d.BY),this.state=1109,this.fieldName();break;case 2:this.enterOuterAlt(e,2),this.state=1110,this.match(d.BY),this.state=1111,this.fieldExpr(0);break}}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}topStatement(){let e=new NM(this._ctx,this.state);this.enterRule(e,204,d.RULE_topStatement);try{this.enterOuterAlt(e,1),this.state=1114,this.match(d.TOP),this.state=1115,this.match(d.INTEGER_LITERAL)}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}indexElement(){let e=new rD(this._ctx,this.state);this.enterRule(e,206,d.RULE_indexElement);let r;try{switch(this.state=1123,this._errHandler.sync(this),this._input.LA(1)){case d.BQ_STRING:case d.IDENTIFIER:this.enterOuterAlt(e,1),this.state=1117,this.fieldPath(),this.state=1120,this._errHandler.sync(this),r=this._input.LA(1),r===d.DOT&&(this.state=1118,this.match(d.DOT),this.state=1119,this.match(d.STAR));break;case d.STAR:this.enterOuterAlt(e,2),this.state=1122,this.match(d.STAR);break;default:throw new sn.NoViableAltException(this)}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}indexFields(){let e=new LM(this._ctx,this.state);this.enterRule(e,208,d.RULE_indexFields);let r;try{let i;for(this.enterOuterAlt(e,1),this.state=1125,this.indexElement(),this.state=1132,this._errHandler.sync(this),i=this.interpreter.adaptivePredict(this._input,120,this._ctx);i!==2&&i!==rn.ATN.INVALID_ALT_NUMBER;)i===1&&(this.state=1127,this._errHandler.sync(this),r=this._input.LA(1),r===d.COMMA&&(this.state=1126,this.match(d.COMMA)),this.state=1129,this.indexElement()),this.state=1134,this._errHandler.sync(this),i=this.interpreter.adaptivePredict(this._input,120,this._ctx)}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}indexStatement(){let e=new IM(this._ctx,this.state);this.enterRule(e,210,d.RULE_indexStatement);let r;try{this.enterOuterAlt(e,1),this.state=1135,this.match(d.INDEX),this.state=1136,this.indexFields(),this.state=1139,this._errHandler.sync(this),r=this._input.LA(1),r===d.BY&&(this.state=1137,this.match(d.BY),this.state=1138,this.fieldName())}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}sampleStatement(){let e=new $M(this._ctx,this.state);this.enterRule(e,212,d.RULE_sampleStatement);try{this.enterOuterAlt(e,1),this.state=1141,this.match(d.SAMPLE),this.state=1142,this.sampleSpec()}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}timezoneStatement(){let e=new iD(this._ctx,this.state);this.enterRule(e,214,d.RULE_timezoneStatement);try{this.enterOuterAlt(e,1),this.state=1144,this.match(d.TIMEZONE),this.state=1145,this.string()}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}queryAnnotation(){let e=new BM(this._ctx,this.state);this.enterRule(e,216,d.RULE_queryAnnotation);try{this.enterOuterAlt(e,1),this.state=1147,this.match(d.ANNOTATION)}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}sampleSpec(){let e=new kM(this._ctx,this.state);this.enterRule(e,218,d.RULE_sampleSpec);let r;try{this.enterOuterAlt(e,1),this.state=1149,r=this._input.LA(1),r===d.FALSE||r===d.TRUE||r===d.PERCENT_LITERAL||r===d.INTEGER_LITERAL?(this._input.LA(1)===Wn.Token.EOF&&(this.matchedEOF=!0),this._errHandler.reportMatch(this),this.consume()):this._errHandler.recoverInline(this)}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}aggregate(){let e=new zE(this._ctx,this.state);this.enterRule(e,220,d.RULE_aggregate);let r;try{this.enterOuterAlt(e,1),this.state=1151,r=this._input.LA(1),r===d.AVG||r===d.COUNT||!(r-73&-32)&&1<<r-73&(1<<d.MAX-73|1<<d.MIN-73|1<<d.SUM-73)?(this._input.LA(1)===Wn.Token.EOF&&(this.matchedEOF=!0),this._errHandler.reportMatch(this),this.consume()):this._errHandler.recoverInline(this)}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}malloyType(){let e=new WE(this._ctx,this.state);this.enterRule(e,222,d.RULE_malloyType);let r;try{this.enterOuterAlt(e,1),this.state=1153,r=this._input.LA(1),r===d.BOOLEAN||r===d.DATE||!(r-80&-32)&&1<<r-80&(1<<d.NUMBER-80|1<<d.STRING-80|1<<d.TIMESTAMP-80)?(this._input.LA(1)===Wn.Token.EOF&&(this.matchedEOF=!0),this._errHandler.reportMatch(this),this.consume()):this._errHandler.recoverInline(this)}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}compareOp(){let e=new sD(this._ctx,this.state);this.enterRule(e,224,d.RULE_compareOp);let r;try{this.enterOuterAlt(e,1),this.state=1155,r=this._input.LA(1),!(r-134&-32)&&1<<r-134&(1<<d.LT-134|1<<d.GT-134|1<<d.EQ-134|1<<d.NE-134|1<<d.LTE-134|1<<d.GTE-134|1<<d.NOT_MATCH-134|1<<d.MATCH-134)?(this._input.LA(1)===Wn.Token.EOF&&(this.matchedEOF=!0),this._errHandler.reportMatch(this),this.consume()):this._errHandler.recoverInline(this)}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}string(){let e=new za(this._ctx,this.state);this.enterRule(e,226,d.RULE_string);try{switch(this.state=1159,this._errHandler.sync(this),this._input.LA(1)){case d.SQ_STRING:case d.DQ_STRING:this.enterOuterAlt(e,1),this.state=1157,this.shortString();break;case d.SQL_BEGIN:this.enterOuterAlt(e,2),this.state=1158,this.sqlString();break;default:throw new sn.NoViableAltException(this)}}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}shortString(){let e=new oD(this._ctx,this.state);this.enterRule(e,228,d.RULE_shortString);let r;try{this.enterOuterAlt(e,1),this.state=1161,r=this._input.LA(1),r===d.SQ_STRING||r===d.DQ_STRING?(this._input.LA(1)===Wn.Token.EOF&&(this.matchedEOF=!0),this._errHandler.reportMatch(this),this.consume()):this._errHandler.recoverInline(this)}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}rawString(){let e=new MM(this._ctx,this.state);this.enterRule(e,230,d.RULE_rawString);let r;try{this.enterOuterAlt(e,1),this.state=1163,r=this._input.LA(1),r===d.RAW_SQ||r===d.RAW_DQ?(this._input.LA(1)===Wn.Token.EOF&&(this.matchedEOF=!0),this._errHandler.reportMatch(this),this.consume()):this._errHandler.recoverInline(this)}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}numericLiteral(){let e=new PM(this._ctx,this.state);this.enterRule(e,232,d.RULE_numericLiteral);let r;try{this.enterOuterAlt(e,1),this.state=1165,r=this._input.LA(1),r===d.NUMERIC_LITERAL||r===d.INTEGER_LITERAL?(this._input.LA(1)===Wn.Token.EOF&&(this.matchedEOF=!0),this._errHandler.reportMatch(this),this.consume()):this._errHandler.recoverInline(this)}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}literal(){let e=new Oo(this._ctx,this.state);this.enterRule(e,234,d.RULE_literal);let r;try{switch(this.state=1176,this._errHandler.sync(this),this._input.LA(1)){case d.SQ_STRING:case d.DQ_STRING:case d.SQL_BEGIN:e=new Lfe(e),this.enterOuterAlt(e,1),this.state=1167,this.string();break;case d.RAW_SQ:case d.RAW_DQ:e=new Ife(e),this.enterOuterAlt(e,2),this.state=1168,this.rawString();break;case d.NUMERIC_LITERAL:case d.INTEGER_LITERAL:e=new $fe(e),this.enterOuterAlt(e,3),this.state=1169,this.numericLiteral();break;case d.LITERAL_TIMESTAMP:case d.LITERAL_HOUR:case d.LITERAL_DAY:case d.LITERAL_QUARTER:case d.LITERAL_MONTH:case d.LITERAL_WEEK:case d.LITERAL_YEAR:e=new Bfe(e),this.enterOuterAlt(e,4),this.state=1170,this.dateLiteral();break;case d.NULL:e=new kfe(e),this.enterOuterAlt(e,5),this.state=1171,this.match(d.NULL);break;case d.FALSE:case d.TRUE:e=new Mfe(e),this.enterOuterAlt(e,6),this.state=1172,r=this._input.LA(1),r===d.FALSE||r===d.TRUE?(this._input.LA(1)===Wn.Token.EOF&&(this.matchedEOF=!0),this._errHandler.reportMatch(this),this.consume()):this._errHandler.recoverInline(this);break;case d.HACKY_REGEX:e=new Pfe(e),this.enterOuterAlt(e,7),this.state=1173,this.match(d.HACKY_REGEX);break;case d.SQ3_FILTER:case d.SQ_FILTER:case d.DQ3_FILTER:case d.DQ_FILTER:case d.BQ3_FILTER:case d.BQ_FILTER:e=new Ufe(e),this.enterOuterAlt(e,8),this.state=1174,this.filterString();break;case d.NOW:e=new jfe(e),this.enterOuterAlt(e,9),this.state=1175,this.match(d.NOW);break;default:throw new sn.NoViableAltException(this)}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}dateLiteral(){let e=new Wa(this._ctx,this.state);this.enterRule(e,236,d.RULE_dateLiteral);try{switch(this.state=1185,this._errHandler.sync(this),this._input.LA(1)){case d.LITERAL_TIMESTAMP:e=new qfe(e),this.enterOuterAlt(e,1),this.state=1178,this.match(d.LITERAL_TIMESTAMP);break;case d.LITERAL_HOUR:e=new Hfe(e),this.enterOuterAlt(e,2),this.state=1179,this.match(d.LITERAL_HOUR);break;case d.LITERAL_DAY:e=new Qfe(e),this.enterOuterAlt(e,3),this.state=1180,this.match(d.LITERAL_DAY);break;case d.LITERAL_WEEK:e=new zfe(e),this.enterOuterAlt(e,4),this.state=1181,this.match(d.LITERAL_WEEK);break;case d.LITERAL_MONTH:e=new Wfe(e),this.enterOuterAlt(e,5),this.state=1182,this.match(d.LITERAL_MONTH);break;case d.LITERAL_QUARTER:e=new Gfe(e),this.enterOuterAlt(e,6),this.state=1183,this.match(d.LITERAL_QUARTER);break;case d.LITERAL_YEAR:e=new Vfe(e),this.enterOuterAlt(e,7),this.state=1184,this.match(d.LITERAL_YEAR);break;default:throw new sn.NoViableAltException(this)}}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}tablePath(){let e=new UM(this._ctx,this.state);this.enterRule(e,238,d.RULE_tablePath);try{this.enterOuterAlt(e,1),this.state=1187,this.string()}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}tableURI(){let e=new Yfe(this._ctx,this.state);this.enterRule(e,240,d.RULE_tableURI);try{this.enterOuterAlt(e,1),this.state=1189,this.string()}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}id(){let e=new Nn(this._ctx,this.state);this.enterRule(e,242,d.RULE_id);let r;try{this.enterOuterAlt(e,1),this.state=1191,r=this._input.LA(1),r===d.BQ_STRING||r===d.IDENTIFIER?(this._input.LA(1)===Wn.Token.EOF&&(this.matchedEOF=!0),this._errHandler.reportMatch(this),this.consume()):this._errHandler.recoverInline(this)}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}timeframe(){let e=new Ld(this._ctx,this.state);this.enterRule(e,244,d.RULE_timeframe);let r;try{this.enterOuterAlt(e,1),this.state=1193,r=this._input.LA(1),!(r-49&-32)&&1<<r-49&(1<<d.DAY-49|1<<d.HOUR-49|1<<d.MINUTE-49|1<<d.MONTH-49)||!(r-86&-32)&&1<<r-86&(1<<d.QUARTER-86|1<<d.SECOND-86|1<<d.WEEK-86|1<<d.YEAR-86)?(this._input.LA(1)===Wn.Token.EOF&&(this.matchedEOF=!0),this._errHandler.reportMatch(this),this.consume()):this._errHandler.recoverInline(this)}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}ungroup(){let e=new jM(this._ctx,this.state);this.enterRule(e,246,d.RULE_ungroup);let r;try{this.enterOuterAlt(e,1),this.state=1195,r=this._input.LA(1),r===d.ALL||r===d.EXCLUDE?(this._input.LA(1)===Wn.Token.EOF&&(this.matchedEOF=!0),this._errHandler.reportMatch(this),this.consume()):this._errHandler.recoverInline(this)}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}malloyOrSQLType(){let e=new uD(this._ctx,this.state);this.enterRule(e,248,d.RULE_malloyOrSQLType);try{switch(this.state=1199,this._errHandler.sync(this),this._input.LA(1)){case d.BOOLEAN:case d.DATE:case d.NUMBER:case d.STRING:case d.TIMESTAMP:this.enterOuterAlt(e,1),this.state=1197,this.malloyType();break;case d.SQ_STRING:case d.DQ_STRING:case d.SQL_BEGIN:this.enterOuterAlt(e,2),this.state=1198,this.string();break;default:throw new sn.NoViableAltException(this)}}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}fieldExpr(e){e===void 0&&(e=0);let r=this._ctx,i=this.state,s=new Re(this._ctx,i),o=s,u=250;this.enterRecursionRule(s,250,d.RULE_fieldExpr,e);let a;try{let l;this.enterOuterAlt(s,1);{switch(this.state=1303,this._errHandler.sync(this),this.interpreter.adaptivePredict(this._input,138,this._ctx)){case 1:s=new Kfe(s),this._ctx=s,o=s,this.state=1202,this.fieldPath();break;case 2:s=new Jfe(s),this._ctx=s,o=s,this.state=1203,this.literal();break;case 3:{for(s=new Xfe(s),this._ctx=s,o=s,this.state=1204,this.match(d.OBRACK),this.state=1205,this.fieldExpr(0),this.state=1210,this._errHandler.sync(this),l=this.interpreter.adaptivePredict(this._input,126,this._ctx);l!==2&&l!==rn.ATN.INVALID_ALT_NUMBER;)l===1&&(this.state=1206,this.match(d.COMMA),this.state=1207,this.fieldExpr(0)),this.state=1212,this._errHandler.sync(this),l=this.interpreter.adaptivePredict(this._input,126,this._ctx);this.state=1214,this._errHandler.sync(this),a=this._input.LA(1),a===d.COMMA&&(this.state=1213,this.match(d.COMMA)),this.state=1216,this.match(d.CBRACK)}break;case 4:{for(s=new Zfe(s),this._ctx=s,o=s,this.state=1218,this.match(d.OCURLY),this.state=1219,this.recordElement(),this.state=1224,this._errHandler.sync(this),a=this._input.LA(1);a===d.COMMA;)this.state=1220,this.match(d.COMMA),this.state=1221,this.recordElement(),this.state=1226,this._errHandler.sync(this),a=this._input.LA(1);this.state=1227,this.match(d.CCURLY)}break;case 5:s=new ixe(s),this._ctx=s,o=s,this.state=1229,this.match(d.MINUS),this.state=1230,this.fieldExpr(25);break;case 6:s=new mxe(s),this._ctx=s,o=s,this.state=1231,this.match(d.NOT),this.state=1232,this.fieldExpr(13);break;case 7:s=new qM(s),this._ctx=s,o=s,this.state=1233,this.match(d.CAST),this.state=1234,this.match(d.OPAREN),this.state=1235,this.fieldExpr(0),this.state=1236,this.match(d.AS),this.state=1237,this.malloyOrSQLType(),this.state=1238,this.match(d.CPAREN);break;case 8:s=new Axe(s),this._ctx=s,o=s,this.state=1242,this._errHandler.sync(this),a=this._input.LA(1),a===d.SOURCE_KW&&(this.state=1240,this.match(d.SOURCE_KW),this.state=1241,this.match(d.DOT)),this.state=1244,this.aggregate(),this.state=1245,this.match(d.OPAREN),this.state=1247,this._errHandler.sync(this),a=this._input.LA(1),(!(a-36&-32)&&1<<a-36&(1<<d.ALL-36|1<<d.AVG-36|1<<d.CASE-36|1<<d.CAST-36|1<<d.COUNT-36|1<<d.DAY-36|1<<d.EXCLUDE-36|1<<d.FALSE-36|1<<d.HOUR-36)||!(a-73&-32)&&1<<a-73&(1<<d.MAX-73|1<<d.MIN-73|1<<d.MINUTE-73|1<<d.MONTH-73|1<<d.NOT-73|1<<d.NOW-73|1<<d.NULL-73|1<<d.PICK-73|1<<d.QUARTER-73|1<<d.SECOND-73|1<<d.SOURCE_KW-73|1<<d.SUM-73|1<<d.TRUE-73|1<<d.WEEK-73|1<<d.YEAR-73)||!(a-105&-32)&&1<<a-105&(1<<d.HACKY_REGEX-105|1<<d.RAW_SQ-105|1<<d.RAW_DQ-105|1<<d.SQ3_FILTER-105|1<<d.SQ_FILTER-105|1<<d.DQ3_FILTER-105|1<<d.DQ_FILTER-105|1<<d.BQ3_FILTER-105|1<<d.BQ_FILTER-105|1<<d.SQ_STRING-105|1<<d.DQ_STRING-105|1<<d.BQ_STRING-105|1<<d.OPAREN-105|1<<d.OBRACK-105|1<<d.OCURLY-105)||!(a-141&-32)&&1<<a-141&(1<<d.MINUS-141|1<<d.LITERAL_TIMESTAMP-141|1<<d.LITERAL_HOUR-141|1<<d.LITERAL_DAY-141|1<<d.LITERAL_QUARTER-141|1<<d.LITERAL_MONTH-141|1<<d.LITERAL_WEEK-141|1<<d.LITERAL_YEAR-141|1<<d.IDENTIFIER-141|1<<d.NUMERIC_LITERAL-141|1<<d.INTEGER_LITERAL-141|1<<d.SQL_BEGIN-141))&&(this.state=1246,this.fieldExpr(0)),this.state=1249,this.match(d.CPAREN);break;case 9:s=new _xe(s),this._ctx=s,o=s,this.state=1251,this.fieldPath(),this.state=1252,this.match(d.DOT),this.state=1253,this.aggregate(),this.state=1254,this.match(d.OPAREN),this.state=1256,this._errHandler.sync(this),a=this._input.LA(1),(!(a-36&-32)&&1<<a-36&(1<<d.ALL-36|1<<d.AVG-36|1<<d.CASE-36|1<<d.CAST-36|1<<d.COUNT-36|1<<d.DAY-36|1<<d.EXCLUDE-36|1<<d.FALSE-36|1<<d.HOUR-36)||!(a-73&-32)&&1<<a-73&(1<<d.MAX-73|1<<d.MIN-73|1<<d.MINUTE-73|1<<d.MONTH-73|1<<d.NOT-73|1<<d.NOW-73|1<<d.NULL-73|1<<d.PICK-73|1<<d.QUARTER-73|1<<d.SECOND-73|1<<d.SOURCE_KW-73|1<<d.SUM-73|1<<d.TRUE-73|1<<d.WEEK-73|1<<d.YEAR-73)||!(a-105&-32)&&1<<a-105&(1<<d.HACKY_REGEX-105|1<<d.RAW_SQ-105|1<<d.RAW_DQ-105|1<<d.SQ3_FILTER-105|1<<d.SQ_FILTER-105|1<<d.DQ3_FILTER-105|1<<d.DQ_FILTER-105|1<<d.BQ3_FILTER-105|1<<d.BQ_FILTER-105|1<<d.SQ_STRING-105|1<<d.DQ_STRING-105|1<<d.BQ_STRING-105|1<<d.OPAREN-105|1<<d.OBRACK-105|1<<d.OCURLY-105)||!(a-141&-32)&&1<<a-141&(1<<d.MINUS-141|1<<d.LITERAL_TIMESTAMP-141|1<<d.LITERAL_HOUR-141|1<<d.LITERAL_DAY-141|1<<d.LITERAL_QUARTER-141|1<<d.LITERAL_MONTH-141|1<<d.LITERAL_WEEK-141|1<<d.LITERAL_YEAR-141|1<<d.IDENTIFIER-141|1<<d.NUMERIC_LITERAL-141|1<<d.INTEGER_LITERAL-141|1<<d.SQL_BEGIN-141))&&(this.state=1255,this.fieldExpr(0)),this.state=1258,this.match(d.CPAREN);break;case 10:s=new vxe(s),this._ctx=s,o=s,this.state=1260,this.match(d.OPAREN),this.state=1261,this.fieldExpr(0),this.state=1262,this.match(d.CPAREN);break;case 11:s=new Cxe(s),this._ctx=s,o=s,this.state=1264,this.fieldPath(),this.state=1265,this.match(d.DOT),this.state=1266,this.id(),this.state=1267,this.match(d.OPAREN),this.state=1269,this._errHandler.sync(this),a=this._input.LA(1),(!(a-36&-32)&&1<<a-36&(1<<d.ALL-36|1<<d.AVG-36|1<<d.CASE-36|1<<d.CAST-36|1<<d.COUNT-36|1<<d.DAY-36|1<<d.EXCLUDE-36|1<<d.FALSE-36|1<<d.HOUR-36)||!(a-73&-32)&&1<<a-73&(1<<d.MAX-73|1<<d.MIN-73|1<<d.MINUTE-73|1<<d.MONTH-73|1<<d.NOT-73|1<<d.NOW-73|1<<d.NULL-73|1<<d.PICK-73|1<<d.QUARTER-73|1<<d.SECOND-73|1<<d.SOURCE_KW-73|1<<d.SUM-73|1<<d.TRUE-73|1<<d.WEEK-73|1<<d.YEAR-73)||!(a-105&-32)&&1<<a-105&(1<<d.HACKY_REGEX-105|1<<d.RAW_SQ-105|1<<d.RAW_DQ-105|1<<d.SQ3_FILTER-105|1<<d.SQ_FILTER-105|1<<d.DQ3_FILTER-105|1<<d.DQ_FILTER-105|1<<d.BQ3_FILTER-105|1<<d.BQ_FILTER-105|1<<d.SQ_STRING-105|1<<d.DQ_STRING-105|1<<d.BQ_STRING-105|1<<d.OPAREN-105|1<<d.OBRACK-105|1<<d.OCURLY-105)||!(a-141&-32)&&1<<a-141&(1<<d.MINUS-141|1<<d.LITERAL_TIMESTAMP-141|1<<d.LITERAL_HOUR-141|1<<d.LITERAL_DAY-141|1<<d.LITERAL_QUARTER-141|1<<d.LITERAL_MONTH-141|1<<d.LITERAL_WEEK-141|1<<d.LITERAL_YEAR-141|1<<d.IDENTIFIER-141|1<<d.NUMERIC_LITERAL-141|1<<d.INTEGER_LITERAL-141|1<<d.SQL_BEGIN-141))&&(this.state=1268,this.argumentList()),this.state=1271,this.match(d.CPAREN);break;case 12:{switch(s=new Sxe(s),this._ctx=s,o=s,this.state=1281,this._errHandler.sync(this),this._input.LA(1)){case d.BQ_STRING:case d.IDENTIFIER:this.state=1273,this.id(),this.state=1278,this._errHandler.sync(this),a=this._input.LA(1),a===d.EXCLAM&&(this.state=1274,this.match(d.EXCLAM),this.state=1276,this._errHandler.sync(this),a=this._input.LA(1),(a===d.BOOLEAN||a===d.DATE||!(a-80&-32)&&1<<a-80&(1<<d.NUMBER-80|1<<d.STRING-80|1<<d.TIMESTAMP-80))&&(this.state=1275,this.malloyType()));break;case d.DAY:case d.HOUR:case d.MINUTE:case d.MONTH:case d.QUARTER:case d.SECOND:case d.WEEK:case d.YEAR:this.state=1280,this.timeframe();break;default:throw new sn.NoViableAltException(this)}this.state=1283,this.match(d.OPAREN),this.state=1285,this._errHandler.sync(this),a=this._input.LA(1),(!(a-36&-32)&&1<<a-36&(1<<d.ALL-36|1<<d.AVG-36|1<<d.CASE-36|1<<d.CAST-36|1<<d.COUNT-36|1<<d.DAY-36|1<<d.EXCLUDE-36|1<<d.FALSE-36|1<<d.HOUR-36)||!(a-73&-32)&&1<<a-73&(1<<d.MAX-73|1<<d.MIN-73|1<<d.MINUTE-73|1<<d.MONTH-73|1<<d.NOT-73|1<<d.NOW-73|1<<d.NULL-73|1<<d.PICK-73|1<<d.QUARTER-73|1<<d.SECOND-73|1<<d.SOURCE_KW-73|1<<d.SUM-73|1<<d.TRUE-73|1<<d.WEEK-73|1<<d.YEAR-73)||!(a-105&-32)&&1<<a-105&(1<<d.HACKY_REGEX-105|1<<d.RAW_SQ-105|1<<d.RAW_DQ-105|1<<d.SQ3_FILTER-105|1<<d.SQ_FILTER-105|1<<d.DQ3_FILTER-105|1<<d.DQ_FILTER-105|1<<d.BQ3_FILTER-105|1<<d.BQ_FILTER-105|1<<d.SQ_STRING-105|1<<d.DQ_STRING-105|1<<d.BQ_STRING-105|1<<d.OPAREN-105|1<<d.OBRACK-105|1<<d.OCURLY-105)||!(a-141&-32)&&1<<a-141&(1<<d.MINUS-141|1<<d.LITERAL_TIMESTAMP-141|1<<d.LITERAL_HOUR-141|1<<d.LITERAL_DAY-141|1<<d.LITERAL_QUARTER-141|1<<d.LITERAL_MONTH-141|1<<d.LITERAL_WEEK-141|1<<d.LITERAL_YEAR-141|1<<d.IDENTIFIER-141|1<<d.NUMERIC_LITERAL-141|1<<d.INTEGER_LITERAL-141|1<<d.SQL_BEGIN-141))&&(this.state=1284,this.argumentList()),this.state=1287,this.match(d.CPAREN)}break;case 13:s=new bxe(s),this._ctx=s,o=s,this.state=1289,this.pickStatement();break;case 14:s=new Txe(s),this._ctx=s,o=s,this.state=1290,this.caseStatement();break;case 15:{for(s=new Rxe(s),this._ctx=s,o=s,this.state=1291,this.ungroup(),this.state=1292,this.match(d.OPAREN),this.state=1293,this.fieldExpr(0),this.state=1298,this._errHandler.sync(this),a=this._input.LA(1);a===d.COMMA;)this.state=1294,this.match(d.COMMA),this.state=1295,this.fieldName(),this.state=1300,this._errHandler.sync(this),a=this._input.LA(1);this.state=1301,this.match(d.CPAREN)}break}for(this._ctx._stop=this._input.tryLT(-1),this.state=1377,this._errHandler.sync(this),l=this.interpreter.adaptivePredict(this._input,143,this._ctx);l!==2&&l!==rn.ATN.INVALID_ALT_NUMBER;){if(l===1)switch(this._parseListeners!=null&&this.triggerExitRuleEvent(),o=s,this.state=1375,this._errHandler.sync(this),this.interpreter.adaptivePredict(this._input,142,this._ctx)){case 1:{if(s=new sxe(new Re(r,i)),this.pushNewRecursionContext(s,u,d.RULE_fieldExpr),this.state=1305,!this.precpred(this._ctx,24))throw this.createFailedPredicateException("this.precpred(this._ctx, 24)");this.state=1306,a=this._input.LA(1),!(a-142&-32)&&1<<a-142&(1<<d.STAR-142|1<<d.SLASH-142|1<<d.PERCENT-142)?(this._input.LA(1)===Wn.Token.EOF&&(this.matchedEOF=!0),this._errHandler.reportMatch(this),this.consume()):this._errHandler.recoverInline(this),this.state=1307,this.fieldExpr(25)}break;case 2:{if(s=new oxe(new Re(r,i)),this.pushNewRecursionContext(s,u,d.RULE_fieldExpr),this.state=1308,!this.precpred(this._ctx,23))throw this.createFailedPredicateException("this.precpred(this._ctx, 23)");this.state=1309,a=this._input.LA(1),a===d.PLUS||a===d.MINUS?(this._input.LA(1)===Wn.Token.EOF&&(this.matchedEOF=!0),this._errHandler.reportMatch(this),this.consume()):this._errHandler.recoverInline(this),this.state=1310,this.fieldExpr(24)}break;case 3:{if(s=new uxe(new Re(r,i)),this.pushNewRecursionContext(s,u,d.RULE_fieldExpr),this.state=1311,!this.precpred(this._ctx,22))throw this.createFailedPredicateException("this.precpred(this._ctx, 22)");this.state=1312,this.match(d.TO),this.state=1313,this.fieldExpr(23)}break;case 4:{if(s=new fxe(new Re(r,i)),this.pushNewRecursionContext(s,u,d.RULE_fieldExpr),this.state=1314,!this.precpred(this._ctx,18))throw this.createFailedPredicateException("this.precpred(this._ctx, 18)");this.state=1315,this.compareOp(),this.state=1316,this.fieldExpr(19)}break;case 5:{if(s=new xxe(new Re(r,i)),this.pushNewRecursionContext(s,u,d.RULE_fieldExpr),this.state=1318,!this.precpred(this._ctx,17))throw this.createFailedPredicateException("this.precpred(this._ctx, 17)");this.state=1320,this._errHandler.sync(this),a=this._input.LA(1),a===d.NOT&&(this.state=1319,this.match(d.NOT)),this.state=1322,this.match(d.LIKE),this.state=1323,this.fieldExpr(18)}break;case 6:{if(s=new gxe(new Re(r,i)),this.pushNewRecursionContext(s,u,d.RULE_fieldExpr),this.state=1324,!this.precpred(this._ctx,12))throw this.createFailedPredicateException("this.precpred(this._ctx, 12)");this.state=1325,this.match(d.AND),this.state=1326,this.fieldExpr(13)}break;case 7:{if(s=new yxe(new Re(r,i)),this.pushNewRecursionContext(s,u,d.RULE_fieldExpr),this.state=1327,!this.precpred(this._ctx,11))throw this.createFailedPredicateException("this.precpred(this._ctx, 11)");this.state=1328,this.match(d.OR),this.state=1329,this.fieldExpr(12)}break;case 8:{if(s=new Exe(new Re(r,i)),this.pushNewRecursionContext(s,u,d.RULE_fieldExpr),this.state=1330,!this.precpred(this._ctx,10))throw this.createFailedPredicateException("this.precpred(this._ctx, 10)");this.state=1331,this.match(d.DOUBLE_QMARK),this.state=1332,this.fieldExpr(11)}break;case 9:{if(s=new exe(new Re(r,i)),this.pushNewRecursionContext(s,u,d.RULE_fieldExpr),this.state=1333,!this.precpred(this._ctx,30))throw this.createFailedPredicateException("this.precpred(this._ctx, 30)");this.state=1334,this.fieldProperties()}break;case 10:{if(s=new txe(new Re(r,i)),this.pushNewRecursionContext(s,u,d.RULE_fieldExpr),this.state=1335,!this.precpred(this._ctx,29))throw this.createFailedPredicateException("this.precpred(this._ctx, 29)");this.state=1336,this.timeframe()}break;case 11:{if(s=new nxe(new Re(r,i)),this.pushNewRecursionContext(s,u,d.RULE_fieldExpr),this.state=1337,!this.precpred(this._ctx,28))throw this.createFailedPredicateException("this.precpred(this._ctx, 28)");this.state=1338,this.match(d.DOT),this.state=1339,this.timeframe()}break;case 12:{if(s=new qM(new Re(r,i)),this.pushNewRecursionContext(s,u,d.RULE_fieldExpr),this.state=1340,!this.precpred(this._ctx,27))throw this.createFailedPredicateException("this.precpred(this._ctx, 27)");this.state=1341,this.match(d.DOUBLECOLON),this.state=1342,this.malloyOrSQLType()}break;case 13:{if(s=new rxe(new Re(r,i)),this.pushNewRecursionContext(s,u,d.RULE_fieldExpr),this.state=1343,!this.precpred(this._ctx,26))throw this.createFailedPredicateException("this.precpred(this._ctx, 26)");this.state=1344,this.match(d.TRIPLECOLON),this.state=1345,this.malloyOrSQLType()}break;case 14:{if(s=new axe(new Re(r,i)),s._startAt=o,this.pushNewRecursionContext(s,u,d.RULE_fieldExpr),this.state=1346,!this.precpred(this._ctx,21))throw this.createFailedPredicateException("this.precpred(this._ctx, 21)");this.state=1347,this.match(d.FOR),this.state=1348,s._duration=this.fieldExpr(0),this.state=1349,this.timeframe()}break;case 15:{if(s=new lxe(new Re(r,i)),this.pushNewRecursionContext(s,u,d.RULE_fieldExpr),this.state=1351,!this.precpred(this._ctx,20))throw this.createFailedPredicateException("this.precpred(this._ctx, 20)");this.state=1352,this.match(d.AMPER),this.state=1353,this.partialAllowedFieldExpr()}break;case 16:{if(s=new cxe(new Re(r,i)),this.pushNewRecursionContext(s,u,d.RULE_fieldExpr),this.state=1354,!this.precpred(this._ctx,19))throw this.createFailedPredicateException("this.precpred(this._ctx, 19)");this.state=1355,this.match(d.BAR),this.state=1356,this.partialAllowedFieldExpr()}break;case 17:{if(s=new dxe(new Re(r,i)),this.pushNewRecursionContext(s,u,d.RULE_fieldExpr),this.state=1357,!this.precpred(this._ctx,16))throw this.createFailedPredicateException("this.precpred(this._ctx, 16)");this.state=1358,this.match(d.IS),this.state=1360,this._errHandler.sync(this),a=this._input.LA(1),a===d.NOT&&(this.state=1359,this.match(d.NOT)),this.state=1362,this.match(d.NULL)}break;case 18:{if(s=new hxe(new Re(r,i)),this.pushNewRecursionContext(s,u,d.RULE_fieldExpr),this.state=1363,!this.precpred(this._ctx,15))throw this.createFailedPredicateException("this.precpred(this._ctx, 15)");this.state=1365,this._errHandler.sync(this),a=this._input.LA(1),a===d.NOT&&(this.state=1364,this.match(d.NOT)),this.state=1367,this.match(d.IN),this.state=1368,this.match(d.OPAREN),this.state=1369,this.fieldExprList(),this.state=1370,this.match(d.CPAREN)}break;case 19:{if(s=new pxe(new Re(r,i)),this.pushNewRecursionContext(s,u,d.RULE_fieldExpr),this.state=1372,!this.precpred(this._ctx,14))throw this.createFailedPredicateException("this.precpred(this._ctx, 14)");this.state=1373,this.match(d.QMARK),this.state=1374,this.partialAllowedFieldExpr()}break}this.state=1379,this._errHandler.sync(this),l=this.interpreter.adaptivePredict(this._input,143,this._ctx)}}}catch(l){if(l instanceof ye.RecognitionException)s.exception=l,this._errHandler.reportError(this,l),this._errHandler.recover(this,l);else throw l}finally{this.unrollRecursionContexts(r)}return s}partialCompare(){let e=new HM(this._ctx,this.state);this.enterRule(e,252,d.RULE_partialCompare);try{this.enterOuterAlt(e,1),this.state=1380,this.compareOp(),this.state=1381,this.fieldExpr(0)}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}partialTest(){let e=new QM(this._ctx,this.state);this.enterRule(e,254,d.RULE_partialTest);let r;try{switch(this.state=1389,this._errHandler.sync(this),this._input.LA(1)){case d.LT:case d.GT:case d.EQ:case d.NE:case d.LTE:case d.GTE:case d.NOT_MATCH:case d.MATCH:this.enterOuterAlt(e,1),this.state=1383,this.partialCompare();break;case d.IS:this.enterOuterAlt(e,2),this.state=1384,this.match(d.IS),this.state=1386,this._errHandler.sync(this),r=this._input.LA(1),r===d.NOT&&(this.state=1385,this.match(d.NOT)),this.state=1388,this.match(d.NULL);break;default:throw new sn.NoViableAltException(this)}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}partialAllowedFieldExpr(){let e=new Id(this._ctx,this.state);this.enterRule(e,256,d.RULE_partialAllowedFieldExpr);try{switch(this.state=1397,this._errHandler.sync(this),this.interpreter.adaptivePredict(this._input,146,this._ctx)){case 1:this.enterOuterAlt(e,1),this.state=1391,this.partialTest();break;case 2:this.enterOuterAlt(e,2),this.state=1392,this.match(d.OPAREN),this.state=1393,this.partialTest(),this.state=1394,this.match(d.CPAREN);break;case 3:this.enterOuterAlt(e,3),this.state=1396,this.fieldExpr(0);break}}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}fieldExprList(){let e=new zM(this._ctx,this.state);this.enterRule(e,258,d.RULE_fieldExprList);let r;try{for(this.enterOuterAlt(e,1),this.state=1399,this.fieldExpr(0),this.state=1404,this._errHandler.sync(this),r=this._input.LA(1);r===d.COMMA;)this.state=1400,this.match(d.COMMA),this.state=1401,this.fieldExpr(0),this.state=1406,this._errHandler.sync(this),r=this._input.LA(1)}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}pickStatement(){let e=new WM(this._ctx,this.state);this.enterRule(e,260,d.RULE_pickStatement);try{let r;this.enterOuterAlt(e,1);{this.state=1408,this._errHandler.sync(this),r=1;do{switch(r){case 1:this.state=1407,this.pick();break;default:throw new sn.NoViableAltException(this)}this.state=1410,this._errHandler.sync(this),r=this.interpreter.adaptivePredict(this._input,148,this._ctx)}while(r!==2&&r!==rn.ATN.INVALID_ALT_NUMBER);switch(this.state=1414,this._errHandler.sync(this),this.interpreter.adaptivePredict(this._input,149,this._ctx)){case 1:this.state=1412,this.match(d.ELSE),this.state=1413,e._pickElse=this.fieldExpr(0);break}}}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}pick(){let e=new aD(this._ctx,this.state);this.enterRule(e,262,d.RULE_pick);let r;try{this.enterOuterAlt(e,1),this.state=1416,this.match(d.PICK),this.state=1418,this._errHandler.sync(this),r=this._input.LA(1),(!(r-36&-32)&&1<<r-36&(1<<d.ALL-36|1<<d.AVG-36|1<<d.CASE-36|1<<d.CAST-36|1<<d.COUNT-36|1<<d.DAY-36|1<<d.EXCLUDE-36|1<<d.FALSE-36|1<<d.HOUR-36)||!(r-73&-32)&&1<<r-73&(1<<d.MAX-73|1<<d.MIN-73|1<<d.MINUTE-73|1<<d.MONTH-73|1<<d.NOT-73|1<<d.NOW-73|1<<d.NULL-73|1<<d.PICK-73|1<<d.QUARTER-73|1<<d.SECOND-73|1<<d.SOURCE_KW-73|1<<d.SUM-73|1<<d.TRUE-73|1<<d.WEEK-73|1<<d.YEAR-73)||!(r-105&-32)&&1<<r-105&(1<<d.HACKY_REGEX-105|1<<d.RAW_SQ-105|1<<d.RAW_DQ-105|1<<d.SQ3_FILTER-105|1<<d.SQ_FILTER-105|1<<d.DQ3_FILTER-105|1<<d.DQ_FILTER-105|1<<d.BQ3_FILTER-105|1<<d.BQ_FILTER-105|1<<d.SQ_STRING-105|1<<d.DQ_STRING-105|1<<d.BQ_STRING-105|1<<d.OPAREN-105|1<<d.OBRACK-105|1<<d.OCURLY-105)||!(r-141&-32)&&1<<r-141&(1<<d.MINUS-141|1<<d.LITERAL_TIMESTAMP-141|1<<d.LITERAL_HOUR-141|1<<d.LITERAL_DAY-141|1<<d.LITERAL_QUARTER-141|1<<d.LITERAL_MONTH-141|1<<d.LITERAL_WEEK-141|1<<d.LITERAL_YEAR-141|1<<d.IDENTIFIER-141|1<<d.NUMERIC_LITERAL-141|1<<d.INTEGER_LITERAL-141|1<<d.SQL_BEGIN-141))&&(this.state=1417,e._pickValue=this.fieldExpr(0)),this.state=1420,this.match(d.WHEN),this.state=1421,e._pickWhen=this.partialAllowedFieldExpr()}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}caseStatement(){let e=new GM(this._ctx,this.state);this.enterRule(e,264,d.RULE_caseStatement);let r;try{this.enterOuterAlt(e,1);{this.state=1423,this.match(d.CASE),this.state=1425,this._errHandler.sync(this),r=this._input.LA(1),(!(r-36&-32)&&1<<r-36&(1<<d.ALL-36|1<<d.AVG-36|1<<d.CASE-36|1<<d.CAST-36|1<<d.COUNT-36|1<<d.DAY-36|1<<d.EXCLUDE-36|1<<d.FALSE-36|1<<d.HOUR-36)||!(r-73&-32)&&1<<r-73&(1<<d.MAX-73|1<<d.MIN-73|1<<d.MINUTE-73|1<<d.MONTH-73|1<<d.NOT-73|1<<d.NOW-73|1<<d.NULL-73|1<<d.PICK-73|1<<d.QUARTER-73|1<<d.SECOND-73|1<<d.SOURCE_KW-73|1<<d.SUM-73|1<<d.TRUE-73|1<<d.WEEK-73|1<<d.YEAR-73)||!(r-105&-32)&&1<<r-105&(1<<d.HACKY_REGEX-105|1<<d.RAW_SQ-105|1<<d.RAW_DQ-105|1<<d.SQ3_FILTER-105|1<<d.SQ_FILTER-105|1<<d.DQ3_FILTER-105|1<<d.DQ_FILTER-105|1<<d.BQ3_FILTER-105|1<<d.BQ_FILTER-105|1<<d.SQ_STRING-105|1<<d.DQ_STRING-105|1<<d.BQ_STRING-105|1<<d.OPAREN-105|1<<d.OBRACK-105|1<<d.OCURLY-105)||!(r-141&-32)&&1<<r-141&(1<<d.MINUS-141|1<<d.LITERAL_TIMESTAMP-141|1<<d.LITERAL_HOUR-141|1<<d.LITERAL_DAY-141|1<<d.LITERAL_QUARTER-141|1<<d.LITERAL_MONTH-141|1<<d.LITERAL_WEEK-141|1<<d.LITERAL_YEAR-141|1<<d.IDENTIFIER-141|1<<d.NUMERIC_LITERAL-141|1<<d.INTEGER_LITERAL-141|1<<d.SQL_BEGIN-141))&&(this.state=1424,e._valueExpr=this.fieldExpr(0)),this.state=1428,this._errHandler.sync(this),r=this._input.LA(1);do this.state=1427,this.caseWhen(),this.state=1430,this._errHandler.sync(this),r=this._input.LA(1);while(r===d.WHEN);this.state=1434,this._errHandler.sync(this),r=this._input.LA(1),r===d.ELSE&&(this.state=1432,this.match(d.ELSE),this.state=1433,e._caseElse=this.fieldExpr(0)),this.state=1436,this.match(d.END)}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}caseWhen(){let e=new lD(this._ctx,this.state);this.enterRule(e,266,d.RULE_caseWhen);try{this.enterOuterAlt(e,1),this.state=1438,this.match(d.WHEN),this.state=1439,e._condition=this.fieldExpr(0),this.state=1440,this.match(d.THEN),this.state=1441,e._result=this.fieldExpr(0)}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}recordKey(){let e=new VM(this._ctx,this.state);this.enterRule(e,268,d.RULE_recordKey);try{this.enterOuterAlt(e,1),this.state=1443,this.id()}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}recordElement(){let e=new t1(this._ctx,this.state);this.enterRule(e,270,d.RULE_recordElement);try{switch(this.state=1452,this._errHandler.sync(this),this.interpreter.adaptivePredict(this._input,155,this._ctx)){case 1:e=new Dxe(e),this.enterOuterAlt(e,1),this.state=1445,this.fieldPath();break;case 2:e=new Oxe(e),this.enterOuterAlt(e,2);{switch(this.state=1449,this._errHandler.sync(this),this.interpreter.adaptivePredict(this._input,154,this._ctx)){case 1:this.state=1446,this.recordKey(),this.state=1447,this.match(d.IS);break}this.state=1451,this.fieldExpr(0)}break}}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}argumentList(){let e=new cD(this._ctx,this.state);this.enterRule(e,272,d.RULE_argumentList);let r;try{let i;this.enterOuterAlt(e,1);{for(this.state=1454,this.fieldExpr(0),this.state=1459,this._errHandler.sync(this),i=this.interpreter.adaptivePredict(this._input,156,this._ctx);i!==2&&i!==rn.ATN.INVALID_ALT_NUMBER;)i===1&&(this.state=1455,this.match(d.COMMA),this.state=1456,this.fieldExpr(0)),this.state=1461,this._errHandler.sync(this),i=this.interpreter.adaptivePredict(this._input,156,this._ctx);this.state=1463,this._errHandler.sync(this),r=this._input.LA(1),r===d.COMMA&&(this.state=1462,this.match(d.COMMA))}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}fieldNameList(){let e=new n1(this._ctx,this.state);this.enterRule(e,274,d.RULE_fieldNameList);let r;try{let i;for(this.enterOuterAlt(e,1),this.state=1465,this.fieldName(),this.state=1472,this._errHandler.sync(this),i=this.interpreter.adaptivePredict(this._input,159,this._ctx);i!==2&&i!==rn.ATN.INVALID_ALT_NUMBER;)i===1&&(this.state=1467,this._errHandler.sync(this),r=this._input.LA(1),r===d.COMMA&&(this.state=1466,this.match(d.COMMA)),this.state=1469,this.fieldName()),this.state=1474,this._errHandler.sync(this),i=this.interpreter.adaptivePredict(this._input,159,this._ctx)}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}fieldCollection(){let e=new YM(this._ctx,this.state);this.enterRule(e,276,d.RULE_fieldCollection);let r;try{let i;this.enterOuterAlt(e,1);{for(this.state=1475,this.collectionMember(),this.state=1482,this._errHandler.sync(this),i=this.interpreter.adaptivePredict(this._input,161,this._ctx);i!==2&&i!==rn.ATN.INVALID_ALT_NUMBER;)i===1&&(this.state=1477,this._errHandler.sync(this),r=this._input.LA(1),r===d.COMMA&&(this.state=1476,this.match(d.COMMA)),this.state=1479,this.collectionMember()),this.state=1484,this._errHandler.sync(this),i=this.interpreter.adaptivePredict(this._input,161,this._ctx);this.state=1486,this._errHandler.sync(this),r=this._input.LA(1),r===d.COMMA&&(this.state=1485,this.match(d.COMMA))}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}collectionWildCard(){let e=new GE(this._ctx,this.state);this.enterRule(e,278,d.RULE_collectionWildCard);let r;try{switch(this.enterOuterAlt(e,1),this.state=1491,this._errHandler.sync(this),r=this._input.LA(1),(r===d.BQ_STRING||r===d.IDENTIFIER)&&(this.state=1488,this.fieldPath(),this.state=1489,this.match(d.DOT)),this.state=1493,this.match(d.STAR),this.state=1495,this._errHandler.sync(this),this.interpreter.adaptivePredict(this._input,164,this._ctx)){case 1:this.state=1494,this.starQualified();break}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}starQualified(){let e=new fD(this._ctx,this.state);this.enterRule(e,280,d.RULE_starQualified);let r;try{this.enterOuterAlt(e,1);{this.state=1497,this.match(d.OCURLY),this.state=1501,this._errHandler.sync(this),r=this._input.LA(1);do{switch(this.state=1501,this._errHandler.sync(this),this._input.LA(1)){case d.EXCEPT:this.state=1498,this.match(d.EXCEPT),this.state=1499,this.fieldNameList();break;case d.COMMA:this.state=1500,this.match(d.COMMA);break;default:throw new sn.NoViableAltException(this)}this.state=1503,this._errHandler.sync(this),r=this._input.LA(1)}while(r===d.EXCEPT||r===d.COMMA);this.state=1505,this.match(d.CCURLY)}}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}taggedRef(){let e=new xD(this._ctx,this.state);this.enterRule(e,282,d.RULE_taggedRef);let r;try{this.enterOuterAlt(e,1),this.state=1507,this.tags(),this.state=1508,this.fieldPath(),this.state=1510,this._errHandler.sync(this),r=this._input.LA(1),r===d.DOT&&(this.state=1509,this.refExpr())}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}refExpr(){let e=new KM(this._ctx,this.state);this.enterRule(e,284,d.RULE_refExpr);try{switch(this.state=1519,this._errHandler.sync(this),this.interpreter.adaptivePredict(this._input,168,this._ctx)){case 1:this.enterOuterAlt(e,1),this.state=1512,this.match(d.DOT),this.state=1513,this.timeframe();break;case 2:this.enterOuterAlt(e,2),this.state=1514,this.match(d.DOT),this.state=1515,this.aggregate(),this.state=1516,this.match(d.OPAREN),this.state=1517,this.match(d.CPAREN);break}}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}collectionMember(){let e=new dD(this._ctx,this.state);this.enterRule(e,286,d.RULE_collectionMember);try{switch(this.state=1524,this._errHandler.sync(this),this.interpreter.adaptivePredict(this._input,169,this._ctx)){case 1:this.enterOuterAlt(e,1),this.state=1521,this.taggedRef();break;case 2:this.enterOuterAlt(e,2),this.state=1522,this.collectionWildCard();break;case 3:this.enterOuterAlt(e,3),this.state=1523,this.fieldDef();break}}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}fieldPath(){let e=new Ga(this._ctx,this.state);this.enterRule(e,288,d.RULE_fieldPath);try{let r;for(this.enterOuterAlt(e,1),this.state=1526,this.fieldName(),this.state=1531,this._errHandler.sync(this),r=this.interpreter.adaptivePredict(this._input,170,this._ctx);r!==2&&r!==rn.ATN.INVALID_ALT_NUMBER;)r===1&&(this.state=1527,this.match(d.DOT),this.state=1528,this.fieldName()),this.state=1533,this._errHandler.sync(this),r=this.interpreter.adaptivePredict(this._input,170,this._ctx)}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}joinName(){let e=new Fxe(this._ctx,this.state);this.enterRule(e,290,d.RULE_joinName);try{this.enterOuterAlt(e,1),this.state=1534,this.id()}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}fieldName(){let e=new Gr(this._ctx,this.state);this.enterRule(e,292,d.RULE_fieldName);try{this.enterOuterAlt(e,1),this.state=1536,this.id()}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}sqlExploreNameRef(){let e=new wxe(this._ctx,this.state);this.enterRule(e,294,d.RULE_sqlExploreNameRef);try{this.enterOuterAlt(e,1),this.state=1538,this.id()}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}nameSQLBlock(){let e=new Nxe(this._ctx,this.state);this.enterRule(e,296,d.RULE_nameSQLBlock);try{this.enterOuterAlt(e,1),this.state=1540,this.id()}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}connectionName(){let e=new Lxe(this._ctx,this.state);this.enterRule(e,298,d.RULE_connectionName);try{this.enterOuterAlt(e,1),this.state=1542,this.string()}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}tripFilterString(){let e=new JM(this._ctx,this.state);this.enterRule(e,300,d.RULE_tripFilterString);let r;try{this.enterOuterAlt(e,1),this.state=1544,r=this._input.LA(1),!(r-108&-32)&&1<<r-108&(1<<d.SQ3_FILTER-108|1<<d.DQ3_FILTER-108|1<<d.BQ3_FILTER-108)?(this._input.LA(1)===Wn.Token.EOF&&(this.matchedEOF=!0),this._errHandler.reportMatch(this),this.consume()):this._errHandler.recoverInline(this)}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}tickFilterString(){let e=new XM(this._ctx,this.state);this.enterRule(e,302,d.RULE_tickFilterString);let r;try{this.enterOuterAlt(e,1),this.state=1546,r=this._input.LA(1),!(r-109&-32)&&1<<r-109&(1<<d.SQ_FILTER-109|1<<d.DQ_FILTER-109|1<<d.BQ_FILTER-109)?(this._input.LA(1)===Wn.Token.EOF&&(this.matchedEOF=!0),this._errHandler.reportMatch(this),this.consume()):this._errHandler.recoverInline(this)}catch(i){if(i instanceof ye.RecognitionException)e.exception=i,this._errHandler.reportError(this,i),this._errHandler.recover(this,i);else throw i}finally{this.exitRule()}return e}filterString(){let e=new ZM(this._ctx,this.state);this.enterRule(e,304,d.RULE_filterString);try{switch(this.state=1550,this._errHandler.sync(this),this._input.LA(1)){case d.SQ3_FILTER:case d.DQ3_FILTER:case d.BQ3_FILTER:this.enterOuterAlt(e,1),this.state=1548,this.tripFilterString();break;case d.SQ_FILTER:case d.DQ_FILTER:case d.BQ_FILTER:this.enterOuterAlt(e,2),this.state=1549,this.tickFilterString();break;default:throw new sn.NoViableAltException(this)}}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}debugExpr(){let e=new Ixe(this._ctx,this.state);this.enterRule(e,306,d.RULE_debugExpr);try{this.enterOuterAlt(e,1),this.state=1552,this.fieldExpr(0),this.state=1553,this.match(d.EOF)}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}debugPartial(){let e=new $xe(this._ctx,this.state);this.enterRule(e,308,d.RULE_debugPartial);try{this.enterOuterAlt(e,1),this.state=1555,this.partialAllowedFieldExpr(),this.state=1556,this.match(d.EOF)}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}experimentalStatementForTesting(){let e=new eP(this._ctx,this.state);this.enterRule(e,310,d.RULE_experimentalStatementForTesting);try{this.enterOuterAlt(e,1),this.state=1558,this.match(d.SEMI),this.state=1559,this.match(d.SEMI),this.state=1560,this.match(d.OBRACK),this.state=1561,this.string(),this.state=1562,this.match(d.CBRACK)}catch(r){if(r instanceof ye.RecognitionException)e.exception=r,this._errHandler.reportError(this,r),this._errHandler.recover(this,r);else throw r}finally{this.exitRule()}return e}sempred(e,r,i){switch(r){case 53:return this.sqExpr_sempred(e,i);case 62:return this.segExpr_sempred(e,i);case 125:return this.fieldExpr_sempred(e,i)}return!0}sqExpr_sempred(e,r){switch(r){case 0:return this.precpred(this._ctx,6);case 1:return this.precpred(this._ctx,5);case 2:return this.precpred(this._ctx,4);case 3:return this.precpred(this._ctx,3)}return!0}segExpr_sempred(e,r){switch(r){case 4:return this.precpred(this._ctx,1)}return!0}fieldExpr_sempred(e,r){switch(r){case 5:return this.precpred(this._ctx,24);case 6:return this.precpred(this._ctx,23);case 7:return this.precpred(this._ctx,22);case 8:return this.precpred(this._ctx,18);case 9:return this.precpred(this._ctx,17);case 10:return this.precpred(this._ctx,12);case 11:return this.precpred(this._ctx,11);case 12:return this.precpred(this._ctx,10);case 13:return this.precpred(this._ctx,30);case 14:return this.precpred(this._ctx,29);case 15:return this.precpred(this._ctx,28);case 16:return this.precpred(this._ctx,27);case 17:return this.precpred(this._ctx,26);case 18:return this.precpred(this._ctx,21);case 19:return this.precpred(this._ctx,20);case 20:return this.precpred(this._ctx,19);case 21:return this.precpred(this._ctx,16);case 22:return this.precpred(this._ctx,15);case 23:return this.precpred(this._ctx,14)}return!0}static get _ATN(){return d.__ATN||(d.__ATN=new Zdt.ATNDeserializer().deserialize(Wce.toCharArray(d._serializedATN))),d.__ATN}}I.MalloyParser=d,d.ACCEPT=1,d.AGGREGATE=2,d.CALCULATE=3,d.CALCULATION=4,d.CONNECTION=5,d.DECLARE=6,d.DIMENSION=7,d.EXCEPT=8,d.EXTENDQ=9,d.GROUP_BY=10,d.HAVING=11,d.INDEX=12,d.INTERNAL=13,d.JOIN_CROSS=14,d.JOIN_ONE=15,d.JOIN_MANY=16,d.LIMIT=17,d.MEASURE=18,d.NEST=19,d.ORDER_BY=20,d.PARTITION_BY=21,d.PRIMARY_KEY=22,d.PRIVATE=23,d.PROJECT=24,d.PUBLIC=25,d.QUERY=26,d.RENAME=27,d.RUN=28,d.SAMPLE=29,d.SELECT=30,d.SOURCE=31,d.TOP=32,d.WHERE=33,d.VIEW=34,d.TIMEZONE=35,d.ALL=36,d.AND=37,d.AS=38,d.ASC=39,d.AVG=40,d.BOOLEAN=41,d.BY=42,d.CASE=43,d.CAST=44,d.CONDITION=45,d.COUNT=46,d.COMPOSE=47,d.DATE=48,d.DAY=49,d.DESC=50,d.DISTINCT=51,d.ELSE=52,d.END=53,d.EXCLUDE=54,d.EXTEND=55,d.FALSE=56,d.FILTER=57,d.FULL=58,d.FOR=59,d.FROM=60,d.HAS=61,d.HOUR=62,d.IMPORT=63,d.INCLUDE=64,d.INNER=65,d.IS=66,d.IN=67,d.INTERNAL_KW=68,d.JSON=69,d.LAST=70,d.LEFT=71,d.LIKE=72,d.MAX=73,d.MIN=74,d.MINUTE=75,d.MONTH=76,d.NOT=77,d.NOW=78,d.NULL=79,d.NUMBER=80,d.ON=81,d.OR=82,d.PICK=83,d.PRIVATE_KW=84,d.PUBLIC_KW=85,d.QUARTER=86,d.RIGHT=87,d.SECOND=88,d.STRING=89,d.SOURCE_KW=90,d.SUM=91,d.SQL=92,d.TABLE=93,d.THEN=94,d.THIS=95,d.TIMESTAMP=96,d.TO=97,d.TRUE=98,d.TURTLE=99,d.WEEK=100,d.WHEN=101,d.WITH=102,d.YEAR=103,d.UNGROUPED=104,d.HACKY_REGEX=105,d.RAW_SQ=106,d.RAW_DQ=107,d.SQ3_FILTER=108,d.SQ_FILTER=109,d.DQ3_FILTER=110,d.DQ_FILTER=111,d.BQ3_FILTER=112,d.BQ_FILTER=113,d.SQ_STRING=114,d.DQ_STRING=115,d.BQ_STRING=116,d.DOC_ANNOTATION=117,d.ANNOTATION=118,d.AMPER=119,d.ARROW=120,d.FAT_ARROW=121,d.OPAREN=122,d.CPAREN=123,d.OBRACK=124,d.CBRACK=125,d.OCURLY=126,d.CCURLY=127,d.DOUBLECOLON=128,d.TRIPLECOLON=129,d.EXCLAM=130,d.COLON=131,d.COMMA=132,d.DOT=133,d.LT=134,d.GT=135,d.EQ=136,d.NE=137,d.LTE=138,d.GTE=139,d.PLUS=140,d.MINUS=141,d.STAR=142,d.STARSTAR=143,d.SLASH=144,d.BAR=145,d.SEMI=146,d.NOT_MATCH=147,d.MATCH=148,d.PERCENT=149,d.DOUBLE_QMARK=150,d.QMARK=151,d.LITERAL_TIMESTAMP=152,d.LITERAL_HOUR=153,d.LITERAL_DAY=154,d.LITERAL_QUARTER=155,d.LITERAL_MONTH=156,d.LITERAL_WEEK=157,d.LITERAL_YEAR=158,d.IDENTIFIER=159,d.PERCENT_LITERAL=160,d.NUMERIC_LITERAL=161,d.INTEGER_LITERAL=162,d.BLOCK_COMMENT=163,d.COMMENT_TO_EOL=164,d.WHITE_SPACE=165,d.SQL_BEGIN=166,d.UNWATED_CHARS_TRAILING_NUMBERS=167,d.UNEXPECTED_CHAR=168,d.OPEN_CODE=169,d.SQL_END=170,d.RULE_malloyDocument=0,d.RULE_malloyStatement=1,d.RULE_defineSourceStatement=2,d.RULE_defineQuery=3,d.RULE_topLevelAnonQueryDef=4,d.RULE_tags=5,d.RULE_isDefine=6,d.RULE_runStatement=7,d.RULE_sqlString=8,d.RULE_sqlInterpolation=9,d.RULE_importStatement=10,d.RULE_importSelect=11,d.RULE_importItem=12,d.RULE_importURL=13,d.RULE_docAnnotations=14,d.RULE_ignoredObjectAnnotations=15,d.RULE_ignoredModelAnnotations=16,d.RULE_topLevelQueryDefs=17,d.RULE_topLevelQueryDef=18,d.RULE_refineOperator=19,d.RULE_turtleName=20,d.RULE_sqlSource=21,d.RULE_exploreTable=22,d.RULE_connectionId=23,d.RULE_queryProperties=24,d.RULE_queryName=25,d.RULE_sourcePropertyList=26,d.RULE_sourceDefinition=27,d.RULE_sqExplore=28,d.RULE_sourceParameters=29,d.RULE_legalParamType=30,d.RULE_sourceParameter=31,d.RULE_parameterNameDef=32,d.RULE_sourceNameDef=33,d.RULE_exploreProperties=34,d.RULE_exploreStatement=35,d.RULE_accessLabel=36,d.RULE_accessModifierList=37,d.RULE_defMeasures=38,d.RULE_defDimensions=39,d.RULE_renameList=40,d.RULE_exploreRenameDef=41,d.RULE_defList=42,d.RULE_fieldDef=43,d.RULE_fieldNameDef=44,d.RULE_joinNameDef=45,d.RULE_declareStatement=46,d.RULE_joinStatement=47,d.RULE_queryExtend=48,d.RULE_modEither=49,d.RULE_sourceArguments=50,d.RULE_argumentId=51,d.RULE_sourceArgument=52,d.RULE_sqExpr=53,d.RULE_includeBlock=54,d.RULE_includeItem=55,d.RULE_orphanedAnnotation=56,d.RULE_accessLabelProp=57,d.RULE_includeExceptList=58,d.RULE_includeExceptListItem=59,d.RULE_includeList=60,d.RULE_includeField=61,d.RULE_segExpr=62,d.RULE_vExpr=63,d.RULE_queryExtendStatement=64,d.RULE_queryExtendStatementList=65,d.RULE_joinList=66,d.RULE_isExplore=67,d.RULE_matrixOperation=68,d.RULE_joinFrom=69,d.RULE_joinDef=70,d.RULE_joinExpression=71,d.RULE_filterStatement=72,d.RULE_fieldProperties=73,d.RULE_aggregateOrdering=74,d.RULE_aggregateOrderBySpec=75,d.RULE_aggregateOrderByStatement=76,d.RULE_fieldPropertyLimitStatement=77,d.RULE_fieldPropertyStatement=78,d.RULE_filterClauseList=79,d.RULE_whereStatement=80,d.RULE_havingStatement=81,d.RULE_subQueryDefList=82,d.RULE_exploreQueryNameDef=83,d.RULE_exploreQueryDef=84,d.RULE_queryStatement=85,d.RULE_queryJoinStatement=86,d.RULE_groupByStatement=87,d.RULE_queryFieldList=88,d.RULE_queryFieldEntry=89,d.RULE_nestStatement=90,d.RULE_nestedQueryList=91,d.RULE_nestEntry=92,d.RULE_aggregateStatement=93,d.RULE_calculateStatement=94,d.RULE_projectStatement=95,d.RULE_partitionByStatement=96,d.RULE_orderByStatement=97,d.RULE_ordering=98,d.RULE_orderBySpec=99,d.RULE_limitStatement=100,d.RULE_bySpec=101,d.RULE_topStatement=102,d.RULE_indexElement=103,d.RULE_indexFields=104,d.RULE_indexStatement=105,d.RULE_sampleStatement=106,d.RULE_timezoneStatement=107,d.RULE_queryAnnotation=108,d.RULE_sampleSpec=109,d.RULE_aggregate=110,d.RULE_malloyType=111,d.RULE_compareOp=112,d.RULE_string=113,d.RULE_shortString=114,d.RULE_rawString=115,d.RULE_numericLiteral=116,d.RULE_literal=117,d.RULE_dateLiteral=118,d.RULE_tablePath=119,d.RULE_tableURI=120,d.RULE_id=121,d.RULE_timeframe=122,d.RULE_ungroup=123,d.RULE_malloyOrSQLType=124,d.RULE_fieldExpr=125,d.RULE_partialCompare=126,d.RULE_partialTest=127,d.RULE_partialAllowedFieldExpr=128,d.RULE_fieldExprList=129,d.RULE_pickStatement=130,d.RULE_pick=131,d.RULE_caseStatement=132,d.RULE_caseWhen=133,d.RULE_recordKey=134,d.RULE_recordElement=135,d.RULE_argumentList=136,d.RULE_fieldNameList=137,d.RULE_fieldCollection=138,d.RULE_collectionWildCard=139,d.RULE_starQualified=140,d.RULE_taggedRef=141,d.RULE_refExpr=142,d.RULE_collectionMember=143,d.RULE_fieldPath=144,d.RULE_joinName=145,d.RULE_fieldName=146,d.RULE_sqlExploreNameRef=147,d.RULE_nameSQLBlock=148,d.RULE_connectionName=149,d.RULE_tripFilterString=150,d.RULE_tickFilterString=151,d.RULE_filterString=152,d.RULE_debugExpr=153,d.RULE_debugPartial=154,d.RULE_experimentalStatementForTesting=155,d.ruleNames=["malloyDocument","malloyStatement","defineSourceStatement","defineQuery","topLevelAnonQueryDef","tags","isDefine","runStatement","sqlString","sqlInterpolation","importStatement","importSelect","importItem","importURL","docAnnotations","ignoredObjectAnnotations","ignoredModelAnnotations","topLevelQueryDefs","topLevelQueryDef","refineOperator","turtleName","sqlSource","exploreTable","connectionId","queryProperties","queryName","sourcePropertyList","sourceDefinition","sqExplore","sourceParameters","legalParamType","sourceParameter","parameterNameDef","sourceNameDef","exploreProperties","exploreStatement","accessLabel","accessModifierList","defMeasures","defDimensions","renameList","exploreRenameDef","defList","fieldDef","fieldNameDef","joinNameDef","declareStatement","joinStatement","queryExtend","modEither","sourceArguments","argumentId","sourceArgument","sqExpr","includeBlock","includeItem","orphanedAnnotation","accessLabelProp","includeExceptList","includeExceptListItem","includeList","includeField","segExpr","vExpr","queryExtendStatement","queryExtendStatementList","joinList","isExplore","matrixOperation","joinFrom","joinDef","joinExpression","filterStatement","fieldProperties","aggregateOrdering","aggregateOrderBySpec","aggregateOrderByStatement","fieldPropertyLimitStatement","fieldPropertyStatement","filterClauseList","whereStatement","havingStatement","subQueryDefList","exploreQueryNameDef","exploreQueryDef","queryStatement","queryJoinStatement","groupByStatement","queryFieldList","queryFieldEntry","nestStatement","nestedQueryList","nestEntry","aggregateStatement","calculateStatement","projectStatement","partitionByStatement","orderByStatement","ordering","orderBySpec","limitStatement","bySpec","topStatement","indexElement","indexFields","indexStatement","sampleStatement","timezoneStatement","queryAnnotation","sampleSpec","aggregate","malloyType","compareOp","string","shortString","rawString","numericLiteral","literal","dateLiteral","tablePath","tableURI","id","timeframe","ungroup","malloyOrSQLType","fieldExpr","partialCompare","partialTest","partialAllowedFieldExpr","fieldExprList","pickStatement","pick","caseStatement","caseWhen","recordKey","recordElement","argumentList","fieldNameList","fieldCollection","collectionWildCard","starQualified","taggedRef","refExpr","collectionMember","fieldPath","joinName","fieldName","sqlExploreNameRef","nameSQLBlock","connectionName","tripFilterString","tickFilterString","filterString","debugExpr","debugPartial","experimentalStatementForTesting"],d._LITERAL_NAMES=[void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,"'&'","'->'","'=>'","'('","')'","'['","']'","'{'","'}'","'::'","':::'","'!'","':'","','","'.'","'<'","'>'","'='","'!='","'<='","'>='","'+'","'-'","'*'","'**'","'/'","'|'","';'","'!~'","'~'","'%'","'??'","'?'",void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,`'"""'`],d._SYMBOLIC_NAMES=[void 0,"ACCEPT","AGGREGATE","CALCULATE","CALCULATION","CONNECTION","DECLARE","DIMENSION","EXCEPT","EXTENDQ","GROUP_BY","HAVING","INDEX","INTERNAL","JOIN_CROSS","JOIN_ONE","JOIN_MANY","LIMIT","MEASURE","NEST","ORDER_BY","PARTITION_BY","PRIMARY_KEY","PRIVATE","PROJECT","PUBLIC","QUERY","RENAME","RUN","SAMPLE","SELECT","SOURCE","TOP","WHERE","VIEW","TIMEZONE","ALL","AND","AS","ASC","AVG","BOOLEAN","BY","CASE","CAST","CONDITION","COUNT","COMPOSE","DATE","DAY","DESC","DISTINCT","ELSE","END","EXCLUDE","EXTEND","FALSE","FILTER","FULL","FOR","FROM","HAS","HOUR","IMPORT","INCLUDE","INNER","IS","IN","INTERNAL_KW","JSON","LAST","LEFT","LIKE","MAX","MIN","MINUTE","MONTH","NOT","NOW","NULL","NUMBER","ON","OR","PICK","PRIVATE_KW","PUBLIC_KW","QUARTER","RIGHT","SECOND","STRING","SOURCE_KW","SUM","SQL","TABLE","THEN","THIS","TIMESTAMP","TO","TRUE","TURTLE","WEEK","WHEN","WITH","YEAR","UNGROUPED","HACKY_REGEX","RAW_SQ","RAW_DQ","SQ3_FILTER","SQ_FILTER","DQ3_FILTER","DQ_FILTER","BQ3_FILTER","BQ_FILTER","SQ_STRING","DQ_STRING","BQ_STRING","DOC_ANNOTATION","ANNOTATION","AMPER","ARROW","FAT_ARROW","OPAREN","CPAREN","OBRACK","CBRACK","OCURLY","CCURLY","DOUBLECOLON","TRIPLECOLON","EXCLAM","COLON","COMMA","DOT","LT","GT","EQ","NE","LTE","GTE","PLUS","MINUS","STAR","STARSTAR","SLASH","BAR","SEMI","NOT_MATCH","MATCH","PERCENT","DOUBLE_QMARK","QMARK","LITERAL_TIMESTAMP","LITERAL_HOUR","LITERAL_DAY","LITERAL_QUARTER","LITERAL_MONTH","LITERAL_WEEK","LITERAL_YEAR","IDENTIFIER","PERCENT_LITERAL","NUMERIC_LITERAL","INTEGER_LITERAL","BLOCK_COMMENT","COMMENT_TO_EOL","WHITE_SPACE","SQL_BEGIN","UNWATED_CHARS_TRAILING_NUMBERS","UNEXPECTED_CHAR","OPEN_CODE","SQL_END"],d.VOCABULARY=new rht.VocabularyImpl(d._LITERAL_NAMES,d._SYMBOLIC_NAMES,[]),d._serializedATNSegments=3,d._serializedATNSegment0=`줝쪺֍꾺体؇쉁¬؟ \x07 \x07\b \b
|
|
1676
1676
|
|
|
1677
1677
|
\v \v\f \f\r \r \x1B \x1B ! !" "# #$ $% %& &' '( () )* *+ +, ,- -. ./ /0 01 12 23 34 45 56 67 78 89 9: :; ;< <= => >? ?@ @A AB BC CD DE EF FG GH HI IJ JK KL LM MN NO OP PQ QR RS ST TU UV VW WX XY YZ Z[ [\\ \\] ]^ ^_ _\` \`a ab bc cd de ef fg gh hi ij jk kl lm mn no op pq qr rs st tu uv vw wx xy yz z{ {| |} }~ ~
\x07Ľ
|
|
1678
1678
|
\fŀ\vŋ
|
|
@@ -1853,13 +1853,13 @@ xyyzz{{||}}~~~Ҳ
|
|
|
1853
1853
|
Œ\fŘśşţŬŰŶƂƇƊ Ə"Ɣ$Ƙ&Ƨ(Ƭ*Ʈ,ư.ƺ0ǁ2ǃ4Ǎ6Ǐ8ǜ:Ǥ<dz>ǻ@ǽBȆDȈFȊHȯJȱLȸNȺPɁRɈTɕVəXɦZɫ\\ɭ^ɯ\`ʊbʌdʒfʡhʣjʨl˄n˛p˯r˱t˳v˵ẍz̊|̥~̮͎̽͂̈́͛ͩ͠ΆΈΌΎΘΩΫήδ ζ¢ρ¤τ¦χ¨ϔªϙ¬ϲ®ϴ°϶²Ϻ´Љ¶Ћ¸ЏºМ¼Ф¾ШÀЬÂаÄмÆпÈюÊѓÌњÎќÐѥÒѧÔѱÖѷØѺÚѽÜѿÞҁà҃â҅ä҉æҋèҍêҏìҚîңðҥòҧôҩöҫøҭúұüԙþզĀկĂշĄչĆւĈ֊Ċ֑Č֠Ď֥Đ֮ĒְĔֻĖׅĘוĚכĜץĞױĠĢĤĦĨĪ؆Ĭ؈Į؊İ،IJؐĴؒĶؕĸؘĺĽĻĽ\x07ļĺļĻĽŀľļľĿĿŁŀľŁł\x07łŃŋńŋ\bŅŋ\fņŋ Ňŋňŋ ʼnŋĸŊŃŊńŊŅŊņŊŇŊňŊʼnŋŌō\f\x07ōŎ\x07!Ŏŏ6ŏ\x07Őő$ő Œœ\f\x07œŔl7Ŕ\vŕŗ\x07xŖŕŗŚŘŖŘř`,d._serializedATNSegment1='ř\rŚŘśŜ\f\x07Ŝŝ\x07DŝŞ\f\x07ŞşŠ\f\x07Šš\x07šŢ\nŢţŧ\x07¨ŤŦ\vťŤŦũŧťŧŨŨŪũŧŪū\x07¬ūŬŭ\x07«ŭŮl7Ůů\x07ůŰŲ\x07Aűų\rŲűŲųųŴŴŵŵŶŷ\x07ŷżŸŹ\x07ŹŻźŸŻžżźżŽŽſžżſƀ\x07ƀƁ\x07>ƁƂƅô{ƃƄ\x07DƄƆô{ƅƃƅƆƆ\x1BƇƈäsƈƉƋ\x07wƊƉƋƌƌƊƌƍƍƎƐ\x07xƏƎƐƑƑƏƑƒƒ!Ɠƕ\x07wƔƓƕƖƖƔƖƗƗ#Ƙƙ\f\x07ƙƚ\x07ƚơ&ƛƝ\x07ƜƛƜƝƝƞƞƠ&ƟƜƠƣơƟơƢƢƥƣơƤƦ\x07ƥƤƥƦƦ%Ƨƨ\f\x07ƨƩ4\x1BƩƪ\bƪƫl7ƫ\'Ƭƭ\x07ƭ)ƮƯô{Ư+ưƱ0ƱƲ\x07ƲƳ\x07^Ƴƶ\x07|ƴƷ\nƵƷætƶƴƶƵƷƸƸƹ\x07}ƹ-ƺƻ0ƻƼ\x07Ƽƽ\x07_ƽƾ\x07|ƾƿðyƿǀ\x07}ǀ/ǁǂô{ǂ1ǃLj\x07DŽLJ¬WDžLJ\x07džDŽdžDžLJNJLjdžLjljljNjNJLjNjnj\x07nj3Ǎǎô{ǎ5Ǐǖ8ǐǒ\x07ǑǐǑǒǒǓǓǕ8ǔǑǕǘǖǔǖǗǗǚǘǖǙǛ\x07ǚǙǚǛǛ7ǜǝ\f\x07ǝǟD#ǞǠ<ǟǞǟǠǠǡǡǢ\bǢǣ:ǣ9Ǥǥl7ǥ;Ǧǧ\x07|ǧǴ\x07}Ǩǩ\x07|ǩǮ@!Ǫǫ\x07ǫǭ@!ǬǪǭǰǮǬǮǯǯDZǰǮDZDz\x07}DzǴdzǦdzǨǴ=ǵǼàqǶǷ\x07;ǷǸ\x07ǸǹàqǹǺ\x07ǺǼǻǵǻǶǼ?ǽȀB"Ǿǿ\x07ǿȁ> ȀǾȀȁȁȄȂȃ\x07DȃȅüȄȂȄȅȅAȆȇô{ȇCȈȉô{ȉEȊȏ\x07ȋȎH%ȌȎ\x07ȍȋȍȌȎȑȏȍȏȐȐȒȑȏȒȓ\x07ȓGȔȰP)ȕȰN(ȖȰ`1ȗȰ¢RȘș\x07șȰĦȚȜJ&țȚțȜȜȝȝȞ\x07ȞȰR*ȟȠ ȠȰĔȡȣ\f\x07ȢȤJ&ȣȢȣȤȤȥȥȦ\x07$Ȧȧ¦TȧȰȨȰØmȩȫ\x07xȪȩȫȬȬȪȬȭȭȰȮȰ"ȯȔȯȕȯȖȯȗȯȘȯțȯȟȯȡȯȨȯȪȯȮȰIȱȲ ȲKȳȹĔȴȶ\x07ȵȷĚȶȵȶȷȷȹȸȳȸȴȹMȺȼ\f\x07ȻȽJ&ȼȻȼȽȽȾȾȿ\x07ȿɀV,ɀOɁɃ\f\x07ɂɄJ&ɃɂɃɄɄɅɅɆ\x07 ɆɇV,ɇQɈɏT+ɉɋ\x07ɊɉɊɋɋɌɌɎT+ɍɊɎɑɏɍɏɐɐɓɑɏɒɔ\x07ɓɒɓɔɔSɕɖĦɖɗ\bɗɘĦɘUəɠX-ɚɜ\x07ɛɚɛɜɜɝɝɟX-ɞɛɟɢɠɞɠɡɡɤɢɠɣɥ\x07ɤɣɤɥɥWɦɧ\f\x07ɧɨZ.ɨɩ\bɩɪüɪYɫɬô{ɬ[ɭɮô{ɮ]ɯɱ\x07\bɰɲJ&ɱɰɱɲɲɳɳɴV,ɴ_ɵɷ\f\x07ɶɸJ&ɷɶɷɸɸɹɹɺ\x07ɺɻDɻʋɼɾ\f\x07ɽɿJ&ɾɽɾɿɿʀʀʁ\x07ʁʂDʂʋʃʅ\f\x07ʄʆJ&ʅʄʅʆʆʇʇʈ\x07ʈʉDʉʋʊɵʊɼʊʃʋaʌʍ\x07\vʍʎCʎcʏʓ`1ʐʓ¢Rʑʓ^0ʒʏʒʐʒʑʓeʔʕ\x07|ʕʢ\x07}ʖʗ\x07|ʗʜj6ʘʙ\x07ʙʛj6ʚʘʛʞʜʚʜʝʝʟʞʜʟʠ\x07}ʠʢʡʔʡʖʢgʣʤô{ʤiʥʦh5ʦʧ\x07Dʧʩʨʥʨʩʩʪʪʫüʫkʬʭ\b7ʭʯô{ʮʰf4ʯʮʯʰʰ˅ʱʲ\x07|ʲʳl7ʳʴ\x07}ʴ˅ʵʶ\x071ʶʿ\x07|ʷʼl7ʸʹ\x07ʹʻl7ʺʸʻʾʼʺʼʽʽˀʾʼʿʷʿˀˀˁˁ˅\x07}˂˅.˃˅,˄ʬ˄ʱ˄ʵ˄˂˄˃˅˘ˆˇ\f\bˇˈ\x07ˈ˗~@ˉˊ\f\x07ˊˋ\x07zˋ˗~@ˌˏ\fˍˎ\x07Bˎːn8ˏˍˏːːˑˑ˒\x079˒˗F$˓˔\f˔˕\x07B˕˗n8˖ˆ˖ˉ˖ˌ˖˓˗˚˘˖˘˙˙m˚˘˛ˠ\x07˜˟p9˝˟\x07˞˜˞˝˟ˢˠ˞ˠˡˡˣˢˠˣˤ\x07ˤo˥˦\f\x07˦˧t;˧˨z>˨˰˩˰z>˪˫\f\x07˫ˬ\x07\nˬ˭v<˭˰ˮ˰r:˯˥˯˩˯˪˯ˮ˰q˱˲\x07x˲s˳˴ ˴u˵˼x=˶˸\x07˷˶˷˸˸˹˹˻x=˺˷˻˾˼˺˼˽˽̀˾˼˿́\x07̀˿̀́́ŵ̃\f\x07̃̄Ħ̄̉̅̆\f\x07̆̇Ę̇̉̈̂̈̅̉ẙ̑|?̋̍\x07̌̋̌̍̍̎̎̐|?̖̏̌̐̓̑̏̑̒̒̓̑̔̕\x07̖̖̔̕̕{̛̗\f\x07̘̙Ħ̙̚\b̛̛̜̘̜̜̝̝̞̚Ħ̞̦̟̠\f\x07̡̠Ħ̡̢̦̣\f\x07̣̤Ę̢̤̦̥̗̥̟̥̦}̧̨\b@̨̯Ģ̩̯2̪̫\x07|̫̬A̬̭\x07}̵̧̭̯̮̮̩̮̪̯̰̱\f̱̲\x07̴̲~@̴̷̵̵̶̶̷̵̸̳̰̳̾~@̹̺~@̺̻\x07z̻̼A̸̼̹̾̽̽̾̿̓P)̀̓N(́̓`1͉͂̿͂̀͂́̓̈́\x07͈ͅB͈͆\x07͇͇͈͉͇͉͉͍͆͋͊͊͌͋͌ͅ\x07͍
͎͕H͏͑\x07͐͏͔͐͑͑͒͒H͓͔͕͓͕͖͖͙͕͚͐͗͗͘\x07͙͙͚͚͛͘͜\f\x07͜͝\x07D͝͞\f\x07͟͞l7͟͠͡ ͪ͢͡\\/ͣͤ\\/ͤͥf4ͥͪͦͧ\\/ͧͨEͨͪͩͩͣͩͦͪͫͭ͢\x07xͬͫͭͰͮͬͮͯͯͱͰͮͱͳGͲʹFͳͲͳʹʹ͵͵Ͷ\x07hͶͷüͷ·ͺ\x07xͺͽͻͻͼͼ;ͽͻ;΄GͿFͿ\x07S΅I΄΄΅΅·ΆͮΆͻ·ΈΉüΉΊ¢R¤SΌΊΌΎΓ\x07ΏΒPΐΒ\x07ΑΏΑΐΒΕΓΑΓΔΔΖΕΓΖΗ\x07ΗΘΝMΙΚ\x07ΚΜMΛΙΜΟΝΛΝΞΞΡΟΝΠ\x07ΡΠΡΣΥüΤΦ ΥΤΥΦΦΪΧΪ\x07)ΨΪ\x074ΩΣΩΧΩΨΪΫά\x07άέLέήίÊfίΰε¢RαεÂbβεNγεOδΰδαδβδγεζλüηθ\x07θκüιηκνλιλμμονλξπ\x07οξοππ¡ρς\x07#ςσ Qσ£τυ\x07\rυφ Qφ¥χώªVψϊ\x07ωψωϊϊϋϋύªVόωύϐώόώϏϏϒϐώϑϓ\x07ϒϑϒϓϓ§ϔϕô{ϕ©ϖϘ\x07xϗϖϘϛϙϗϙϚϚϜϛϙϜϝ¨UϝϞ\bϞϟAϟ«Ϡϳ°Yϡϳ^0Ϣϳ®Xϣϳb2ϤϳÀaϥϳÔkϦϳ¼_ϧϳ¾`ϨϳÎhϩϳÊfϪϳÄcϫϳ¢RϬϳ¤Sϭϳ¶\\ϮϳÖlϯϳØmϰϳÚnϱϳ"ϲϠϲϡϲϢϲϣϲϤϲϥϲϦϲϧϲϨϲϩϲϪϲϫϲϬϲϭϲϮϲϯϲϰϲϱϳϴϵ`1ϵ¯϶Ϸ\f\x07Ϸϸ\x07\fϸϹ²ZϹ±ϺЁ´[ϻϽ\x07ϼϻϼϽϽϾϾЀ´[ϿϼЀЃЁϿЁЂЂЅЃЁЄІ\x07ЅЄЅІІ³ЇЊĜЈЊX-ЉЇЉЈЊµЋЌ\f\x07ЌЍ',d._serializedATNSegment2=`\x07ЍЎ¸]Ў·ЏЖº^АВ\x07БАБВВГГЕº^ДБЕИЖДЖЗЗКИЖЙЛ\x07КЙКЛЛ¹МР\f\x07НО4\x1BОП\bПСРНРССТТУAУ»ФХ\f\x07ХЦ\x07ЦЧ²ZЧ½ШЩ\f\x07ЩЪ\x07ЪЫ²ZЫ¿ЬЭ\f\x07ЭЮ\x07 ЮЯĖЯÁаб\x07бжô{вг\x07геô{двеижджззкижйл\x07кйкллÃмн\x07ноÆdоÅпцÈeрт\x07срсттуухÈeфсхшцфцччъшцщы\x07ъщъыыÇья\x07¤эяĦюьюэяёѐђ ёѐёђђÉѓє\x07єѕ\x07¤ѕËії\x07,їћĦјљ\x07,љћüњіњјћÍќѝ\x07"ѝў\x07¤ўÏџѢĢѠѡ\x07ѡѣ\x07ѢѠѢѣѣѦѤѦ\x07ѥџѥѤѦÑѧѮÐiѨѪ\x07ѩѨѩѪѪѫѫѭÐiѬѩѭѰѮѬѮѯѯÓѰѮѱѲ\x07ѲѵÒjѳѴ\x07,ѴѶĦѵѳѵѶѶÕѷѸ\x07ѸѹÜoѹ×Ѻѻ\x07%ѻѼäsѼÙѽѾ\x07xѾÛѿҀ \x07ҀÝҁ҂ \b҂ß҃҄ ҄á҅҆
|
|
1854
1854
|
҆ã҇Ҋæt҈Ҋ
|
|
1855
1855
|
҉҇҉҈ҊåҋҌ \vҌçҍҎ \fҎéҏҐ \rҐëґқäsҒқèuғқêvҔқîxҕқ\x07QҖқ җқ\x07kҘқIJҙқ\x07PҚґҚҒҚғҚҔҚҕҚҖҚҗҚҘҚҙқíҜҤ\x07ҝҤ\x07ҞҤ\x07ҟҤ\x07ҠҤ\x07ҡҤ\x07ҢҤ\x07 ңҜңҝңҞңҟңҠңҡңҢҤïҥҦäsҦñҧҨäsҨóҩҪ ҪõҫҬ Ҭ÷ҭҮ ҮùүҲàqҰҲäsұүұҰҲûҳҴ\bҴԚĢҵԚìwҶҷ\x07~ҷҼüҸҹ\x07ҹһüҺҸһҾҼҺҼҽҽӀҾҼҿӁ\x07ӀҿӀӁӁӂӂӃ\x07ӃԚӄӅ\x07ӅӊĐӆӇ\x07ӇӉĐӈӆӉӌӊӈӊӋӋӍӌӊӍӎ\x07ӎԚӏӐ\x07ӐԚü\x1BӑӒ\x07OӒԚüӓӔ\x07.Ӕӕ\x07|ӕӖüӖӗ\x07(ӗӘú~Әә\x07}әԚӚӛ\x07\\ӛӝ\x07ӜӚӜӝӝӞӞӟÞpӟӡ\x07|ӠӢüӡӠӡӢӢӣӣӤ\x07}ӤԚӥӦĢӦӧ\x07ӧӨÞpӨӪ\x07|өӫüӪөӪӫӫӬӬӭ\x07}ӭԚӮӯ\x07|ӯӰüӰӱ\x07}ӱԚӲӳĢӳӴ\x07Ӵӵô{ӵӷ\x07|ӶӸĒӷӶӷӸӸӹӹӺ\x07}ӺԚӻԀô{ӼӾ\x07ӽӿàqӾӽӾӿӿԁԀӼԀԁԁԄԂԄö|ԃӻԃԂԄԅԅԇ\x07|ԆԈĒԇԆԇԈԈԉԉԊ\x07}ԊԚԋԚĆԌԚĊԍԎø}Ԏԏ\x07|ԏԔüԐԑ\x07ԑԓĦԒԐԓԖԔԒԔԕԕԗԖԔԗԘ\x07}ԘԚԙҳԙҵԙҶԙӄԙӏԙӑԙӓԙӜԙӥԙӮԙӲԙԃԙԋԙԌԙԍԚգԛԜ\fԜԝ ԝբü\x1BԞԟ\fԟԠ ԠբüԡԢ\fԢԣ\x07cԣբüԤԥ\fԥԦârԦԧüԧբԨԪ\fԩԫ\x07OԪԩԪԫԫԬԬԭ\x07JԭբüԮԯ\fԯ\x07'բüԱԲ\f\rԲԳ\x07TԳբüԴԵ\f\fԵԶ\x07Զբü\rԷԸ\f ԸբKԹԺ\fԺբö|ԻԼ\fԼԽ\x07Խբö|ԾԿ\fԿՀ\x07Հբú~ՁՂ\fՂՃ\x07Ճբú~ՄՅ\fՅՆ\x07=ՆՇüՇՈö|ՈբՉՊ\fՊՋ\x07yՋբĂՌՍ\fՍՎ\x07ՎբĂՏՐ\fՐՒ\x07DՑՓ\x07OՒՑՒՓՓՔՔբ\x07QՕ\fՖ\x07OՖՙՙ՚\x07E՚՛\x07|՛՜Ą՜՝\x07}՝բ՞՟\f՟ՠ\x07ՠբĂաԛաԞաԡաԤաԨաԮաԱաԴաԷաԹաԻաԾաՁաՄաՉաՌաՏաՕա՞բեգագդդýեգզէârէըüըÿթհþժլ\x07Dիխ\x07Oլիլխխծծհ\x07QկթկժհāձոĀղճ\x07|ճմĀմյ\x07}յոնոüշձշղշնոăչվüպջ\x07ջսüռպսրվռվտտąրվցփĈ
ւցփքքւքօօֈֆև\x076և։üֈֆֈ։։ć֊\x07U֍ü֍֍֎֎֏\x07g֏Ăĉ֑֓\x07-֒֔ü֖֓֒֓֔֔֕֗Č֖֖֛֚֕֗֘֘֘֙֙֜\x076֛֝ü֚֜֜֝֝֞֞֟\x077֟ċ֠֡\x07g֢֡ü֢֣\x07\`֣֤ü֤č֥֦ô{֦ď֧֯Ģ֨֩Ď֪֩\x07D֪֭֭֬֫֨֫֬֬֯ü֧֮֮֫֯đְֵüֱֲ\x07ֲִüֱֳֳִֵֵֵֶֶַַָֹֺ\x07ָֹֹֺֺēֻׂĦּ־\x07ּֽֽ־־ֿֿׁĦ׀ֽׁׂׄ׀ׂ׃׃ĕׂׅׄĠ׆\x07ׇ׆ׇĠׇאב\x07אאבבėגדĢדה\x07הזוגוזזחחי\x07טךĚיטיךךęכן\x07לם\x07
|
|
1856
|
-
םנĔמנ\x07ןלןמנססןסעעףףפ\x07פěץצ\f\x07צרĢקשĞרקרששĝת\x07ײö|\x07Þpׯ\x07|ׯװ\x07}װײױתױײğ׳Ĝ״ĘX-׳״ġĦ\x07Ħģô{ĥô{ħô{ĩ؆؇ô{؇ī؈؉äs؉ĭ؊؋ ؋į،؍ ؍ı؎ؑĮ؏ؑİؐ؎ؐ؏ؑijؒؓüؓؔ\x07ؔĵؕؖĂؖؗ\x07ؗķؘؙ\x07ؙؚ\x07ؚ؛\x07~؛äs؝\x07؝Ĺ®ļľŊŘŧŲżƅƌƑƖƜơƥƶdžLjǑǖǚǟǮdzǻȀȄȍȏțȣȬȯȶȸȼɃɊɏɓɛɠɤɱɷɾʅʊʒʜʡʨʯʼʿ˄ˏ˖˘˞ˠ˯˷˼̵̛̥̮͇͉͕͙̀̈̌̑̽͂͐ͩͮ̕ͳͻ΄ΆΌΑΓΝΡΥΩδλοωώϒϙϲϼЁЅЉБЖКРжксцъюёњѢѥѩѮѵ҉ҚңұҼӀӊӜӡӪӷӾԀԃԇԔԙԪՒագլկշվքֈֵׇֹֽׂ֮֓֘֜֫אויןסרױؐ`,d._serializedATN=Wce.join([d._serializedATNSegment0,d._serializedATNSegment1,d._serializedATNSegment2],"");class Gce extends ge.ParserRuleContext{EOF(){return this.getToken(d.EOF,0)}malloyStatement(e){return e===void 0?this.getRuleContexts(CR):this.getRuleContext(e,CR)}SEMI(e){return e===void 0?this.getTokens(d.SEMI):this.getToken(d.SEMI,e)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_malloyDocument}enterRule(e){e.enterMalloyDocument&&e.enterMalloyDocument(this)}exitRule(e){e.exitMalloyDocument&&e.exitMalloyDocument(this)}accept(e){return e.visitMalloyDocument?e.visitMalloyDocument(this):e.visitChildren(this)}}I.MalloyDocumentContext=Gce;class CR extends ge.ParserRuleContext{defineSourceStatement(){return this.tryGetRuleContext(0,Pk)}defineQuery(){return this.tryGetRuleContext(0,SR)}importStatement(){return this.tryGetRuleContext(0,qk)}runStatement(){return this.tryGetRuleContext(0,jk)}docAnnotations(){return this.tryGetRuleContext(0,zk)}ignoredObjectAnnotations(){return this.tryGetRuleContext(0,Wk)}experimentalStatementForTesting(){return this.tryGetRuleContext(0,eP)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_malloyStatement}enterRule(e){e.enterMalloyStatement&&e.enterMalloyStatement(this)}exitRule(e){e.exitMalloyStatement&&e.exitMalloyStatement(this)}accept(e){return e.visitMalloyStatement?e.visitMalloyStatement(this):e.visitChildren(this)}}I.MalloyStatementContext=CR;class Pk extends ge.ParserRuleContext{tags(){return this.getRuleContext(0,Xt)}SOURCE(){return this.getToken(d.SOURCE,0)}sourcePropertyList(){return this.getRuleContext(0,Jk)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_defineSourceStatement}enterRule(e){e.enterDefineSourceStatement&&e.enterDefineSourceStatement(this)}exitRule(e){e.exitDefineSourceStatement&&e.exitDefineSourceStatement(this)}accept(e){return e.visitDefineSourceStatement?e.visitDefineSourceStatement(this):e.visitChildren(this)}}I.DefineSourceStatementContext=Pk;class SR extends ge.ParserRuleContext{constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_defineQuery}copyFrom(e){super.copyFrom(e)}}I.DefineQueryContext=SR;class Vce extends SR{topLevelQueryDefs(){return this.getRuleContext(0,Gk)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterUse_top_level_query_defs&&e.enterUse_top_level_query_defs(this)}exitRule(e){e.exitUse_top_level_query_defs&&e.exitUse_top_level_query_defs(this)}accept(e){return e.visitUse_top_level_query_defs?e.visitUse_top_level_query_defs(this):e.visitChildren(this)}}I.Use_top_level_query_defsContext=Vce;class Uk extends ge.ParserRuleContext{tags(){return this.getRuleContext(0,Xt)}sqExpr(){return this.getRuleContext(0,cn)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_topLevelAnonQueryDef}enterRule(e){e.enterTopLevelAnonQueryDef&&e.enterTopLevelAnonQueryDef(this)}exitRule(e){e.exitTopLevelAnonQueryDef&&e.exitTopLevelAnonQueryDef(this)}accept(e){return e.visitTopLevelAnonQueryDef?e.visitTopLevelAnonQueryDef(this):e.visitChildren(this)}}I.TopLevelAnonQueryDefContext=Uk;class Xt extends ge.ParserRuleContext{ANNOTATION(e){return e===void 0?this.getTokens(d.ANNOTATION):this.getToken(d.ANNOTATION,e)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_tags}enterRule(e){e.enterTags&&e.enterTags(this)}exitRule(e){e.exitTags&&e.exitTags(this)}accept(e){return e.visitTags?e.visitTags(this):e.visitChildren(this)}}I.TagsContext=Xt;class v0 extends ge.ParserRuleContext{IS(){return this.getToken(d.IS,0)}tags(e){return e===void 0?this.getRuleContexts(Xt):this.getRuleContext(e,Xt)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_isDefine}enterRule(e){e.enterIsDefine&&e.enterIsDefine(this)}exitRule(e){e.exitIsDefine&&e.exitIsDefine(this)}accept(e){return e.visitIsDefine?e.visitIsDefine(this):e.visitChildren(this)}}I.IsDefineContext=v0;class jk extends ge.ParserRuleContext{tags(){return this.getRuleContext(0,Xt)}RUN(){return this.getToken(d.RUN,0)}topLevelAnonQueryDef(){return this.getRuleContext(0,Uk)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_runStatement}enterRule(e){e.enterRunStatement&&e.enterRunStatement(this)}exitRule(e){e.exitRunStatement&&e.exitRunStatement(this)}accept(e){return e.visitRunStatement?e.visitRunStatement(this):e.visitChildren(this)}}I.RunStatementContext=jk;class bR extends ge.ParserRuleContext{SQL_BEGIN(){return this.getToken(d.SQL_BEGIN,0)}SQL_END(){return this.getToken(d.SQL_END,0)}sqlInterpolation(e){return e===void 0?this.getRuleContexts(TR):this.getRuleContext(e,TR)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_sqlString}enterRule(e){e.enterSqlString&&e.enterSqlString(this)}exitRule(e){e.exitSqlString&&e.exitSqlString(this)}accept(e){return e.visitSqlString?e.visitSqlString(this):e.visitChildren(this)}}I.SqlStringContext=bR;class TR extends ge.ParserRuleContext{OPEN_CODE(){return this.getToken(d.OPEN_CODE,0)}sqExpr(){return this.getRuleContext(0,cn)}CCURLY(){return this.getToken(d.CCURLY,0)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_sqlInterpolation}enterRule(e){e.enterSqlInterpolation&&e.enterSqlInterpolation(this)}exitRule(e){e.exitSqlInterpolation&&e.exitSqlInterpolation(this)}accept(e){return e.visitSqlInterpolation?e.visitSqlInterpolation(this):e.visitChildren(this)}}I.SqlInterpolationContext=TR;class qk extends ge.ParserRuleContext{IMPORT(){return this.getToken(d.IMPORT,0)}importURL(){return this.getRuleContext(0,Qk)}importSelect(){return this.tryGetRuleContext(0,Hk)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_importStatement}enterRule(e){e.enterImportStatement&&e.enterImportStatement(this)}exitRule(e){e.exitImportStatement&&e.exitImportStatement(this)}accept(e){return e.visitImportStatement?e.visitImportStatement(this):e.visitChildren(this)}}I.ImportStatementContext=qk;class Hk extends ge.ParserRuleContext{OCURLY(){return this.getToken(d.OCURLY,0)}importItem(e){return e===void 0?this.getRuleContexts(RR):this.getRuleContext(e,RR)}CCURLY(){return this.getToken(d.CCURLY,0)}FROM(){return this.getToken(d.FROM,0)}COMMA(e){return e===void 0?this.getTokens(d.COMMA):this.getToken(d.COMMA,e)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_importSelect}enterRule(e){e.enterImportSelect&&e.enterImportSelect(this)}exitRule(e){e.exitImportSelect&&e.exitImportSelect(this)}accept(e){return e.visitImportSelect?e.visitImportSelect(this):e.visitChildren(this)}}I.ImportSelectContext=Hk;class RR extends ge.ParserRuleContext{id(e){return e===void 0?this.getRuleContexts(Nn):this.getRuleContext(e,Nn)}IS(){return this.tryGetToken(d.IS,0)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_importItem}enterRule(e){e.enterImportItem&&e.enterImportItem(this)}exitRule(e){e.exitImportItem&&e.exitImportItem(this)}accept(e){return e.visitImportItem?e.visitImportItem(this):e.visitChildren(this)}}I.ImportItemContext=RR;class Qk extends ge.ParserRuleContext{string(){return this.getRuleContext(0,za)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_importURL}enterRule(e){e.enterImportURL&&e.enterImportURL(this)}exitRule(e){e.exitImportURL&&e.exitImportURL(this)}accept(e){return e.visitImportURL?e.visitImportURL(this):e.visitChildren(this)}}I.ImportURLContext=Qk;class zk extends ge.ParserRuleContext{DOC_ANNOTATION(e){return e===void 0?this.getTokens(d.DOC_ANNOTATION):this.getToken(d.DOC_ANNOTATION,e)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_docAnnotations}enterRule(e){e.enterDocAnnotations&&e.enterDocAnnotations(this)}exitRule(e){e.exitDocAnnotations&&e.exitDocAnnotations(this)}accept(e){return e.visitDocAnnotations?e.visitDocAnnotations(this):e.visitChildren(this)}}I.DocAnnotationsContext=zk;class Wk extends ge.ParserRuleContext{ANNOTATION(e){return e===void 0?this.getTokens(d.ANNOTATION):this.getToken(d.ANNOTATION,e)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_ignoredObjectAnnotations}enterRule(e){e.enterIgnoredObjectAnnotations&&e.enterIgnoredObjectAnnotations(this)}exitRule(e){e.exitIgnoredObjectAnnotations&&e.exitIgnoredObjectAnnotations(this)}accept(e){return e.visitIgnoredObjectAnnotations?e.visitIgnoredObjectAnnotations(this):e.visitChildren(this)}}I.IgnoredObjectAnnotationsContext=Wk;class DR extends ge.ParserRuleContext{DOC_ANNOTATION(e){return e===void 0?this.getTokens(d.DOC_ANNOTATION):this.getToken(d.DOC_ANNOTATION,e)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_ignoredModelAnnotations}enterRule(e){e.enterIgnoredModelAnnotations&&e.enterIgnoredModelAnnotations(this)}exitRule(e){e.exitIgnoredModelAnnotations&&e.exitIgnoredModelAnnotations(this)}accept(e){return e.visitIgnoredModelAnnotations?e.visitIgnoredModelAnnotations(this):e.visitChildren(this)}}I.IgnoredModelAnnotationsContext=DR;class Gk extends ge.ParserRuleContext{tags(){return this.getRuleContext(0,Xt)}QUERY(){return this.getToken(d.QUERY,0)}topLevelQueryDef(e){return e===void 0?this.getRuleContexts(FR):this.getRuleContext(e,FR)}COMMA(e){return e===void 0?this.getTokens(d.COMMA):this.getToken(d.COMMA,e)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_topLevelQueryDefs}enterRule(e){e.enterTopLevelQueryDefs&&e.enterTopLevelQueryDefs(this)}exitRule(e){e.exitTopLevelQueryDefs&&e.exitTopLevelQueryDefs(this)}accept(e){return e.visitTopLevelQueryDefs?e.visitTopLevelQueryDefs(this):e.visitChildren(this)}}I.TopLevelQueryDefsContext=Gk;class FR extends ge.ParserRuleContext{tags(){return this.getRuleContext(0,Xt)}queryName(){return this.getRuleContext(0,NR)}isDefine(){return this.getRuleContext(0,v0)}sqExpr(){return this.getRuleContext(0,cn)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_topLevelQueryDef}enterRule(e){e.enterTopLevelQueryDef&&e.enterTopLevelQueryDef(this)}exitRule(e){e.exitTopLevelQueryDef&&e.exitTopLevelQueryDef(this)}accept(e){return e.visitTopLevelQueryDef?e.visitTopLevelQueryDef(this):e.visitChildren(this)}}I.TopLevelQueryDefContext=FR;class Yce extends ge.ParserRuleContext{PLUS(){return this.getToken(d.PLUS,0)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_refineOperator}enterRule(e){e.enterRefineOperator&&e.enterRefineOperator(this)}exitRule(e){e.exitRefineOperator&&e.exitRefineOperator(this)}accept(e){return e.visitRefineOperator?e.visitRefineOperator(this):e.visitChildren(this)}}I.RefineOperatorContext=Yce;class Kce extends ge.ParserRuleContext{id(){return this.getRuleContext(0,Nn)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_turtleName}enterRule(e){e.enterTurtleName&&e.enterTurtleName(this)}exitRule(e){e.exitTurtleName&&e.exitTurtleName(this)}accept(e){return e.visitTurtleName?e.visitTurtleName(this):e.visitChildren(this)}}I.TurtleNameContext=Kce;class Vk extends ge.ParserRuleContext{connectionId(){return this.getRuleContext(0,wR)}DOT(){return this.getToken(d.DOT,0)}SQL(){return this.getToken(d.SQL,0)}OPAREN(){return this.getToken(d.OPAREN,0)}CPAREN(){return this.getToken(d.CPAREN,0)}sqlString(){return this.tryGetRuleContext(0,bR)}shortString(){return this.tryGetRuleContext(0,oD)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_sqlSource}enterRule(e){e.enterSqlSource&&e.enterSqlSource(this)}exitRule(e){e.exitSqlSource&&e.exitSqlSource(this)}accept(e){return e.visitSqlSource?e.visitSqlSource(this):e.visitChildren(this)}}I.SqlSourceContext=Vk;class Yk extends ge.ParserRuleContext{connectionId(){return this.getRuleContext(0,wR)}DOT(){return this.getToken(d.DOT,0)}TABLE(){return this.getToken(d.TABLE,0)}OPAREN(){return this.getToken(d.OPAREN,0)}tablePath(){return this.getRuleContext(0,UM)}CPAREN(){return this.getToken(d.CPAREN,0)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_exploreTable}enterRule(e){e.enterExploreTable&&e.enterExploreTable(this)}exitRule(e){e.exitExploreTable&&e.exitExploreTable(this)}accept(e){return e.visitExploreTable?e.visitExploreTable(this):e.visitChildren(this)}}I.ExploreTableContext=Yk;class wR extends ge.ParserRuleContext{id(){return this.getRuleContext(0,Nn)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_connectionId}enterRule(e){e.enterConnectionId&&e.enterConnectionId(this)}exitRule(e){e.exitConnectionId&&e.exitConnectionId(this)}accept(e){return e.visitConnectionId?e.visitConnectionId(this):e.visitChildren(this)}}I.ConnectionIdContext=wR;class Kk extends ge.ParserRuleContext{OCURLY(){return this.getToken(d.OCURLY,0)}CCURLY(){return this.getToken(d.CCURLY,0)}queryStatement(e){return e===void 0?this.getRuleContexts(ZR):this.getRuleContext(e,ZR)}SEMI(e){return e===void 0?this.getTokens(d.SEMI):this.getToken(d.SEMI,e)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_queryProperties}enterRule(e){e.enterQueryProperties&&e.enterQueryProperties(this)}exitRule(e){e.exitQueryProperties&&e.exitQueryProperties(this)}accept(e){return e.visitQueryProperties?e.visitQueryProperties(this):e.visitChildren(this)}}I.QueryPropertiesContext=Kk;class NR extends ge.ParserRuleContext{id(){return this.getRuleContext(0,Nn)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_queryName}enterRule(e){e.enterQueryName&&e.enterQueryName(this)}exitRule(e){e.exitQueryName&&e.exitQueryName(this)}accept(e){return e.visitQueryName?e.visitQueryName(this):e.visitChildren(this)}}I.QueryNameContext=NR;class Jk extends ge.ParserRuleContext{sourceDefinition(e){return e===void 0?this.getRuleContexts(LR):this.getRuleContext(e,LR)}COMMA(e){return e===void 0?this.getTokens(d.COMMA):this.getToken(d.COMMA,e)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_sourcePropertyList}enterRule(e){e.enterSourcePropertyList&&e.enterSourcePropertyList(this)}exitRule(e){e.exitSourcePropertyList&&e.exitSourcePropertyList(this)}accept(e){return e.visitSourcePropertyList?e.visitSourcePropertyList(this):e.visitChildren(this)}}I.SourcePropertyListContext=Jk;class LR extends ge.ParserRuleContext{tags(){return this.getRuleContext(0,Xt)}sourceNameDef(){return this.getRuleContext(0,nM)}isDefine(){return this.getRuleContext(0,v0)}sqExplore(){return this.getRuleContext(0,Xk)}sourceParameters(){return this.tryGetRuleContext(0,Zk)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_sourceDefinition}enterRule(e){e.enterSourceDefinition&&e.enterSourceDefinition(this)}exitRule(e){e.exitSourceDefinition&&e.exitSourceDefinition(this)}accept(e){return e.visitSourceDefinition?e.visitSourceDefinition(this):e.visitChildren(this)}}I.SourceDefinitionContext=LR;class Xk extends ge.ParserRuleContext{sqExpr(){return this.getRuleContext(0,cn)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_sqExplore}enterRule(e){e.enterSqExplore&&e.enterSqExplore(this)}exitRule(e){e.exitSqExplore&&e.exitSqExplore(this)}accept(e){return e.visitSqExplore?e.visitSqExplore(this):e.visitChildren(this)}}I.SqExploreContext=Xk;class Zk extends ge.ParserRuleContext{OPAREN(){return this.getToken(d.OPAREN,0)}CPAREN(){return this.getToken(d.CPAREN,0)}sourceParameter(e){return e===void 0?this.getRuleContexts(IR):this.getRuleContext(e,IR)}COMMA(e){return e===void 0?this.getTokens(d.COMMA):this.getToken(d.COMMA,e)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_sourceParameters}enterRule(e){e.enterSourceParameters&&e.enterSourceParameters(this)}exitRule(e){e.exitSourceParameters&&e.exitSourceParameters(this)}accept(e){return e.visitSourceParameters?e.visitSourceParameters(this):e.visitChildren(this)}}I.SourceParametersContext=Zk;class eM extends ge.ParserRuleContext{malloyType(){return this.getRuleContext(0,WE)}FILTER(){return this.tryGetToken(d.FILTER,0)}LT(){return this.tryGetToken(d.LT,0)}GT(){return this.tryGetToken(d.GT,0)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_legalParamType}enterRule(e){e.enterLegalParamType&&e.enterLegalParamType(this)}exitRule(e){e.exitLegalParamType&&e.exitLegalParamType(this)}accept(e){return e.visitLegalParamType?e.visitLegalParamType(this):e.visitChildren(this)}}I.LegalParamTypeContext=eM;class IR extends ge.ParserRuleContext{parameterNameDef(){return this.getRuleContext(0,tM)}DOUBLECOLON(){return this.tryGetToken(d.DOUBLECOLON,0)}legalParamType(){return this.tryGetRuleContext(0,eM)}IS(){return this.tryGetToken(d.IS,0)}fieldExpr(){return this.tryGetRuleContext(0,Re)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_sourceParameter}enterRule(e){e.enterSourceParameter&&e.enterSourceParameter(this)}exitRule(e){e.exitSourceParameter&&e.exitSourceParameter(this)}accept(e){return e.visitSourceParameter?e.visitSourceParameter(this):e.visitChildren(this)}}I.SourceParameterContext=IR;class tM extends ge.ParserRuleContext{id(){return this.getRuleContext(0,Nn)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_parameterNameDef}enterRule(e){e.enterParameterNameDef&&e.enterParameterNameDef(this)}exitRule(e){e.exitParameterNameDef&&e.exitParameterNameDef(this)}accept(e){return e.visitParameterNameDef?e.visitParameterNameDef(this):e.visitChildren(this)}}I.ParameterNameDefContext=tM;class nM extends ge.ParserRuleContext{id(){return this.getRuleContext(0,Nn)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_sourceNameDef}enterRule(e){e.enterSourceNameDef&&e.enterSourceNameDef(this)}exitRule(e){e.exitSourceNameDef&&e.exitSourceNameDef(this)}accept(e){return e.visitSourceNameDef?e.visitSourceNameDef(this):e.visitChildren(this)}}I.SourceNameDefContext=nM;class rM extends ge.ParserRuleContext{OCURLY(){return this.getToken(d.OCURLY,0)}CCURLY(){return this.getToken(d.CCURLY,0)}exploreStatement(e){return e===void 0?this.getRuleContexts(Ki):this.getRuleContext(e,Ki)}SEMI(e){return e===void 0?this.getTokens(d.SEMI):this.getToken(d.SEMI,e)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_exploreProperties}enterRule(e){e.enterExploreProperties&&e.enterExploreProperties(this)}exitRule(e){e.exitExploreProperties&&e.exitExploreProperties(this)}accept(e){return e.visitExploreProperties?e.visitExploreProperties(this):e.visitChildren(this)}}I.ExplorePropertiesContext=rM;class Ki extends ge.ParserRuleContext{constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_exploreStatement}copyFrom(e){super.copyFrom(e)}}I.ExploreStatementContext=Ki;class Jce extends Ki{defDimensions(){return this.getRuleContext(0,BR)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterDefExploreDimension_stub&&e.enterDefExploreDimension_stub(this)}exitRule(e){e.exitDefExploreDimension_stub&&e.exitDefExploreDimension_stub(this)}accept(e){return e.visitDefExploreDimension_stub?e.visitDefExploreDimension_stub(this):e.visitChildren(this)}}I.DefExploreDimension_stubContext=Jce;class Xce extends Ki{defMeasures(){return this.getRuleContext(0,$R)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterDefExploreMeasure_stub&&e.enterDefExploreMeasure_stub(this)}exitRule(e){e.exitDefExploreMeasure_stub&&e.exitDefExploreMeasure_stub(this)}accept(e){return e.visitDefExploreMeasure_stub?e.visitDefExploreMeasure_stub(this):e.visitChildren(this)}}I.DefExploreMeasure_stubContext=Xce;class Zce extends Ki{joinStatement(){return this.getRuleContext(0,C0)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterDefJoin_stub&&e.enterDefJoin_stub(this)}exitRule(e){e.exitDefJoin_stub&&e.exitDefJoin_stub(this)}accept(e){return e.visitDefJoin_stub?e.visitDefJoin_stub(this):e.visitChildren(this)}}I.DefJoin_stubContext=Zce;class efe extends Ki{whereStatement(){return this.getRuleContext(0,Nd)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterDefExploreWhere_stub&&e.enterDefExploreWhere_stub(this)}exitRule(e){e.exitDefExploreWhere_stub&&e.exitDefExploreWhere_stub(this)}accept(e){return e.visitDefExploreWhere_stub?e.visitDefExploreWhere_stub(this):e.visitChildren(this)}}I.DefExploreWhere_stubContext=efe;class tfe extends Ki{PRIMARY_KEY(){return this.getToken(d.PRIMARY_KEY,0)}fieldName(){return this.getRuleContext(0,Gr)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterDefExplorePrimaryKey&&e.enterDefExplorePrimaryKey(this)}exitRule(e){e.exitDefExplorePrimaryKey&&e.exitDefExplorePrimaryKey(this)}accept(e){return e.visitDefExplorePrimaryKey?e.visitDefExplorePrimaryKey(this):e.visitChildren(this)}}I.DefExplorePrimaryKeyContext=tfe;class nfe extends Ki{RENAME(){return this.getToken(d.RENAME,0)}renameList(){return this.getRuleContext(0,iM)}accessLabel(){return this.tryGetRuleContext(0,Qa)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterDefExploreRename&&e.enterDefExploreRename(this)}exitRule(e){e.exitDefExploreRename&&e.exitDefExploreRename(this)}accept(e){return e.visitDefExploreRename?e.visitDefExploreRename(this):e.visitChildren(this)}}I.DefExploreRenameContext=nfe;class rfe extends Ki{fieldNameList(){return this.getRuleContext(0,n1)}ACCEPT(){return this.tryGetToken(d.ACCEPT,0)}EXCEPT(){return this.tryGetToken(d.EXCEPT,0)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterDefExploreEditField&&e.enterDefExploreEditField(this)}exitRule(e){e.exitDefExploreEditField&&e.exitDefExploreEditField(this)}accept(e){return e.visitDefExploreEditField?e.visitDefExploreEditField(this):e.visitChildren(this)}}I.DefExploreEditFieldContext=rfe;class ife extends Ki{tags(){return this.getRuleContext(0,Xt)}VIEW(){return this.getToken(d.VIEW,0)}subQueryDefList(){return this.getRuleContext(0,AM)}accessLabel(){return this.tryGetRuleContext(0,Qa)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterDefExploreQuery&&e.enterDefExploreQuery(this)}exitRule(e){e.exitDefExploreQuery&&e.exitDefExploreQuery(this)}accept(e){return e.visitDefExploreQuery?e.visitDefExploreQuery(this):e.visitChildren(this)}}I.DefExploreQueryContext=ife;class sfe extends Ki{timezoneStatement(){return this.getRuleContext(0,iD)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterDefExploreTimezone&&e.enterDefExploreTimezone(this)}exitRule(e){e.exitDefExploreTimezone&&e.exitDefExploreTimezone(this)}accept(e){return e.visitDefExploreTimezone?e.visitDefExploreTimezone(this):e.visitChildren(this)}}I.DefExploreTimezoneContext=sfe;class ofe extends Ki{ANNOTATION(e){return e===void 0?this.getTokens(d.ANNOTATION):this.getToken(d.ANNOTATION,e)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterDefExploreAnnotation&&e.enterDefExploreAnnotation(this)}exitRule(e){e.exitDefExploreAnnotation&&e.exitDefExploreAnnotation(this)}accept(e){return e.visitDefExploreAnnotation?e.visitDefExploreAnnotation(this):e.visitChildren(this)}}I.DefExploreAnnotationContext=ofe;class ufe extends Ki{ignoredModelAnnotations(){return this.getRuleContext(0,DR)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterDefIgnoreModel_stub&&e.enterDefIgnoreModel_stub(this)}exitRule(e){e.exitDefIgnoreModel_stub&&e.exitDefIgnoreModel_stub(this)}accept(e){return e.visitDefIgnoreModel_stub?e.visitDefIgnoreModel_stub(this):e.visitChildren(this)}}I.DefIgnoreModel_stubContext=ufe;class Qa extends ge.ParserRuleContext{PUBLIC_KW(){return this.tryGetToken(d.PUBLIC_KW,0)}PRIVATE_KW(){return this.tryGetToken(d.PRIVATE_KW,0)}INTERNAL_KW(){return this.tryGetToken(d.INTERNAL_KW,0)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_accessLabel}enterRule(e){e.enterAccessLabel&&e.enterAccessLabel(this)}exitRule(e){e.exitAccessLabel&&e.exitAccessLabel(this)}accept(e){return e.visitAccessLabel?e.visitAccessLabel(this):e.visitChildren(this)}}I.AccessLabelContext=Qa;class afe extends ge.ParserRuleContext{fieldNameList(){return this.tryGetRuleContext(0,n1)}STAR(){return this.tryGetToken(d.STAR,0)}starQualified(){return this.tryGetRuleContext(0,fD)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_accessModifierList}enterRule(e){e.enterAccessModifierList&&e.enterAccessModifierList(this)}exitRule(e){e.exitAccessModifierList&&e.exitAccessModifierList(this)}accept(e){return e.visitAccessModifierList?e.visitAccessModifierList(this):e.visitChildren(this)}}I.AccessModifierListContext=afe;class $R extends ge.ParserRuleContext{tags(){return this.getRuleContext(0,Xt)}MEASURE(){return this.getToken(d.MEASURE,0)}defList(){return this.getRuleContext(0,jE)}accessLabel(){return this.tryGetRuleContext(0,Qa)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_defMeasures}enterRule(e){e.enterDefMeasures&&e.enterDefMeasures(this)}exitRule(e){e.exitDefMeasures&&e.exitDefMeasures(this)}accept(e){return e.visitDefMeasures?e.visitDefMeasures(this):e.visitChildren(this)}}I.DefMeasuresContext=$R;class BR extends ge.ParserRuleContext{tags(){return this.getRuleContext(0,Xt)}DIMENSION(){return this.getToken(d.DIMENSION,0)}defList(){return this.getRuleContext(0,jE)}accessLabel(){return this.tryGetRuleContext(0,Qa)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_defDimensions}enterRule(e){e.enterDefDimensions&&e.enterDefDimensions(this)}exitRule(e){e.exitDefDimensions&&e.exitDefDimensions(this)}accept(e){return e.visitDefDimensions?e.visitDefDimensions(this):e.visitChildren(this)}}I.DefDimensionsContext=BR;class iM extends ge.ParserRuleContext{exploreRenameDef(e){return e===void 0?this.getRuleContexts(kR):this.getRuleContext(e,kR)}COMMA(e){return e===void 0?this.getTokens(d.COMMA):this.getToken(d.COMMA,e)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_renameList}enterRule(e){e.enterRenameList&&e.enterRenameList(this)}exitRule(e){e.exitRenameList&&e.exitRenameList(this)}accept(e){return e.visitRenameList?e.visitRenameList(this):e.visitChildren(this)}}I.RenameListContext=iM;class kR extends ge.ParserRuleContext{fieldName(e){return e===void 0?this.getRuleContexts(Gr):this.getRuleContext(e,Gr)}isDefine(){return this.getRuleContext(0,v0)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_exploreRenameDef}enterRule(e){e.enterExploreRenameDef&&e.enterExploreRenameDef(this)}exitRule(e){e.exitExploreRenameDef&&e.exitExploreRenameDef(this)}accept(e){return e.visitExploreRenameDef?e.visitExploreRenameDef(this):e.visitChildren(this)}}I.ExploreRenameDefContext=kR;class jE extends ge.ParserRuleContext{fieldDef(e){return e===void 0?this.getRuleContexts(Z2):this.getRuleContext(e,Z2)}COMMA(e){return e===void 0?this.getTokens(d.COMMA):this.getToken(d.COMMA,e)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_defList}enterRule(e){e.enterDefList&&e.enterDefList(this)}exitRule(e){e.exitDefList&&e.exitDefList(this)}accept(e){return e.visitDefList?e.visitDefList(this):e.visitChildren(this)}}I.DefListContext=jE;class Z2 extends ge.ParserRuleContext{tags(){return this.getRuleContext(0,Xt)}fieldNameDef(){return this.getRuleContext(0,sM)}isDefine(){return this.getRuleContext(0,v0)}fieldExpr(){return this.getRuleContext(0,Re)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_fieldDef}enterRule(e){e.enterFieldDef&&e.enterFieldDef(this)}exitRule(e){e.exitFieldDef&&e.exitFieldDef(this)}accept(e){return e.visitFieldDef?e.visitFieldDef(this):e.visitChildren(this)}}I.FieldDefContext=Z2;class sM extends ge.ParserRuleContext{id(){return this.getRuleContext(0,Nn)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_fieldNameDef}enterRule(e){e.enterFieldNameDef&&e.enterFieldNameDef(this)}exitRule(e){e.exitFieldNameDef&&e.exitFieldNameDef(this)}accept(e){return e.visitFieldNameDef?e.visitFieldNameDef(this):e.visitChildren(this)}}I.FieldNameDefContext=sM;class oM extends ge.ParserRuleContext{id(){return this.getRuleContext(0,Nn)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_joinNameDef}enterRule(e){e.enterJoinNameDef&&e.enterJoinNameDef(this)}exitRule(e){e.exitJoinNameDef&&e.exitJoinNameDef(this)}accept(e){return e.visitJoinNameDef?e.visitJoinNameDef(this):e.visitChildren(this)}}I.JoinNameDefContext=oM;class MR extends ge.ParserRuleContext{DECLARE(){return this.getToken(d.DECLARE,0)}defList(){return this.getRuleContext(0,jE)}accessLabel(){return this.tryGetRuleContext(0,Qa)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_declareStatement}enterRule(e){e.enterDeclareStatement&&e.enterDeclareStatement(this)}exitRule(e){e.exitDeclareStatement&&e.exitDeclareStatement(this)}accept(e){return e.visitDeclareStatement?e.visitDeclareStatement(this):e.visitChildren(this)}}I.DeclareStatementContext=MR;class C0 extends ge.ParserRuleContext{constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_joinStatement}copyFrom(e){super.copyFrom(e)}}I.JoinStatementContext=C0;class lfe extends C0{tags(){return this.getRuleContext(0,Xt)}JOIN_ONE(){return this.getToken(d.JOIN_ONE,0)}joinList(){return this.getRuleContext(0,qE)}accessLabel(){return this.tryGetRuleContext(0,Qa)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterDefJoinOne&&e.enterDefJoinOne(this)}exitRule(e){e.exitDefJoinOne&&e.exitDefJoinOne(this)}accept(e){return e.visitDefJoinOne?e.visitDefJoinOne(this):e.visitChildren(this)}}I.DefJoinOneContext=lfe;class cfe extends C0{tags(){return this.getRuleContext(0,Xt)}JOIN_MANY(){return this.getToken(d.JOIN_MANY,0)}joinList(){return this.getRuleContext(0,qE)}accessLabel(){return this.tryGetRuleContext(0,Qa)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterDefJoinMany&&e.enterDefJoinMany(this)}exitRule(e){e.exitDefJoinMany&&e.exitDefJoinMany(this)}accept(e){return e.visitDefJoinMany?e.visitDefJoinMany(this):e.visitChildren(this)}}I.DefJoinManyContext=cfe;class ffe extends C0{tags(){return this.getRuleContext(0,Xt)}JOIN_CROSS(){return this.getToken(d.JOIN_CROSS,0)}joinList(){return this.getRuleContext(0,qE)}accessLabel(){return this.tryGetRuleContext(0,Qa)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterDefJoinCross&&e.enterDefJoinCross(this)}exitRule(e){e.exitDefJoinCross&&e.exitDefJoinCross(this)}accept(e){return e.visitDefJoinCross?e.visitDefJoinCross(this):e.visitChildren(this)}}I.DefJoinCrossContext=ffe;class uM extends ge.ParserRuleContext{EXTENDQ(){return this.getToken(d.EXTENDQ,0)}queryExtendStatementList(){return this.getRuleContext(0,dM)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_queryExtend}enterRule(e){e.enterQueryExtend&&e.enterQueryExtend(this)}exitRule(e){e.exitQueryExtend&&e.exitQueryExtend(this)}accept(e){return e.visitQueryExtend?e.visitQueryExtend(this):e.visitChildren(this)}}I.QueryExtendContext=uM;class xfe extends ge.ParserRuleContext{joinStatement(){return this.tryGetRuleContext(0,C0)}whereStatement(){return this.tryGetRuleContext(0,Nd)}declareStatement(){return this.tryGetRuleContext(0,MR)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_modEither}enterRule(e){e.enterModEither&&e.enterModEither(this)}exitRule(e){e.exitModEither&&e.exitModEither(this)}accept(e){return e.visitModEither?e.visitModEither(this):e.visitChildren(this)}}I.ModEitherContext=xfe;class PR extends ge.ParserRuleContext{OPAREN(){return this.getToken(d.OPAREN,0)}CPAREN(){return this.getToken(d.CPAREN,0)}sourceArgument(e){return e===void 0?this.getRuleContexts(UR):this.getRuleContext(e,UR)}COMMA(e){return e===void 0?this.getTokens(d.COMMA):this.getToken(d.COMMA,e)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_sourceArguments}enterRule(e){e.enterSourceArguments&&e.enterSourceArguments(this)}exitRule(e){e.exitSourceArguments&&e.exitSourceArguments(this)}accept(e){return e.visitSourceArguments?e.visitSourceArguments(this):e.visitChildren(this)}}I.SourceArgumentsContext=PR;class aM extends ge.ParserRuleContext{id(){return this.getRuleContext(0,Nn)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_argumentId}enterRule(e){e.enterArgumentId&&e.enterArgumentId(this)}exitRule(e){e.exitArgumentId&&e.exitArgumentId(this)}accept(e){return e.visitArgumentId?e.visitArgumentId(this):e.visitChildren(this)}}I.ArgumentIdContext=aM;class UR extends ge.ParserRuleContext{fieldExpr(){return this.getRuleContext(0,Re)}argumentId(){return this.tryGetRuleContext(0,aM)}IS(){return this.tryGetToken(d.IS,0)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_sourceArgument}enterRule(e){e.enterSourceArgument&&e.enterSourceArgument(this)}exitRule(e){e.exitSourceArgument&&e.exitSourceArgument(this)}accept(e){return e.visitSourceArgument?e.visitSourceArgument(this):e.visitChildren(this)}}I.SourceArgumentContext=UR;class cn extends ge.ParserRuleContext{constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_sqExpr}copyFrom(e){super.copyFrom(e)}}I.SqExprContext=cn;class dfe extends cn{id(){return this.getRuleContext(0,Nn)}sourceArguments(){return this.tryGetRuleContext(0,PR)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterSQID&&e.enterSQID(this)}exitRule(e){e.exitSQID&&e.exitSQID(this)}accept(e){return e.visitSQID?e.visitSQID(this):e.visitChildren(this)}}I.SQIDContext=dfe;class hfe extends cn{OPAREN(){return this.getToken(d.OPAREN,0)}sqExpr(){return this.getRuleContext(0,cn)}CPAREN(){return this.getToken(d.CPAREN,0)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterSQParens&&e.enterSQParens(this)}exitRule(e){e.exitSQParens&&e.exitSQParens(this)}accept(e){return e.visitSQParens?e.visitSQParens(this):e.visitChildren(this)}}I.SQParensContext=hfe;class pfe extends cn{COMPOSE(){return this.getToken(d.COMPOSE,0)}OPAREN(){return this.getToken(d.OPAREN,0)}CPAREN(){return this.getToken(d.CPAREN,0)}sqExpr(e){return e===void 0?this.getRuleContexts(cn):this.getRuleContext(e,cn)}COMMA(e){return e===void 0?this.getTokens(d.COMMA):this.getToken(d.COMMA,e)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterSQCompose&&e.enterSQCompose(this)}exitRule(e){e.exitSQCompose&&e.exitSQCompose(this)}accept(e){return e.visitSQCompose?e.visitSQCompose(this):e.visitChildren(this)}}I.SQComposeContext=pfe;class mfe extends cn{sqExpr(){return this.getRuleContext(0,cn)}PLUS(){return this.getToken(d.PLUS,0)}segExpr(){return this.getRuleContext(0,Ws)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterSQRefinedQuery&&e.enterSQRefinedQuery(this)}exitRule(e){e.exitSQRefinedQuery&&e.exitSQRefinedQuery(this)}accept(e){return e.visitSQRefinedQuery?e.visitSQRefinedQuery(this):e.visitChildren(this)}}I.SQRefinedQueryContext=mfe;class gfe extends cn{sqExpr(){return this.getRuleContext(0,cn)}ARROW(){return this.getToken(d.ARROW,0)}segExpr(){return this.getRuleContext(0,Ws)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterSQArrow&&e.enterSQArrow(this)}exitRule(e){e.exitSQArrow&&e.exitSQArrow(this)}accept(e){return e.visitSQArrow?e.visitSQArrow(this):e.visitChildren(this)}}I.SQArrowContext=gfe;class yfe extends cn{sqExpr(){return this.getRuleContext(0,cn)}EXTEND(){return this.getToken(d.EXTEND,0)}exploreProperties(){return this.getRuleContext(0,rM)}INCLUDE(){return this.tryGetToken(d.INCLUDE,0)}includeBlock(){return this.tryGetRuleContext(0,jR)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterSQExtendedSource&&e.enterSQExtendedSource(this)}exitRule(e){e.exitSQExtendedSource&&e.exitSQExtendedSource(this)}accept(e){return e.visitSQExtendedSource?e.visitSQExtendedSource(this):e.visitChildren(this)}}I.SQExtendedSourceContext=yfe;class Efe extends cn{sqExpr(){return this.getRuleContext(0,cn)}INCLUDE(){return this.getToken(d.INCLUDE,0)}includeBlock(){return this.getRuleContext(0,jR)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterSQInclude&&e.enterSQInclude(this)}exitRule(e){e.exitSQInclude&&e.exitSQInclude(this)}accept(e){return e.visitSQInclude?e.visitSQInclude(this):e.visitChildren(this)}}I.SQIncludeContext=Efe;class Afe extends cn{exploreTable(){return this.getRuleContext(0,Yk)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterSQTable&&e.enterSQTable(this)}exitRule(e){e.exitSQTable&&e.exitSQTable(this)}accept(e){return e.visitSQTable?e.visitSQTable(this):e.visitChildren(this)}}I.SQTableContext=Afe;class _fe extends cn{sqlSource(){return this.getRuleContext(0,Vk)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterSQSQL&&e.enterSQSQL(this)}exitRule(e){e.exitSQSQL&&e.exitSQSQL(this)}accept(e){return e.visitSQSQL?e.visitSQSQL(this):e.visitChildren(this)}}I.SQSQLContext=_fe;class jR extends ge.ParserRuleContext{OCURLY(){return this.getToken(d.OCURLY,0)}CCURLY(){return this.getToken(d.CCURLY,0)}includeItem(e){return e===void 0?this.getRuleContexts(qR):this.getRuleContext(e,qR)}SEMI(e){return e===void 0?this.getTokens(d.SEMI):this.getToken(d.SEMI,e)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_includeBlock}enterRule(e){e.enterIncludeBlock&&e.enterIncludeBlock(this)}exitRule(e){e.exitIncludeBlock&&e.exitIncludeBlock(this)}accept(e){return e.visitIncludeBlock?e.visitIncludeBlock(this):e.visitChildren(this)}}I.IncludeBlockContext=jR;class qR extends ge.ParserRuleContext{tags(){return this.tryGetRuleContext(0,Xt)}accessLabelProp(){return this.tryGetRuleContext(0,cM)}includeList(){return this.tryGetRuleContext(0,xM)}EXCEPT(){return this.tryGetToken(d.EXCEPT,0)}includeExceptList(){return this.tryGetRuleContext(0,fM)}orphanedAnnotation(){return this.tryGetRuleContext(0,lM)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_includeItem}enterRule(e){e.enterIncludeItem&&e.enterIncludeItem(this)}exitRule(e){e.exitIncludeItem&&e.exitIncludeItem(this)}accept(e){return e.visitIncludeItem?e.visitIncludeItem(this):e.visitChildren(this)}}I.IncludeItemContext=qR;class lM extends ge.ParserRuleContext{ANNOTATION(){return this.getToken(d.ANNOTATION,0)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_orphanedAnnotation}enterRule(e){e.enterOrphanedAnnotation&&e.enterOrphanedAnnotation(this)}exitRule(e){e.exitOrphanedAnnotation&&e.exitOrphanedAnnotation(this)}accept(e){return e.visitOrphanedAnnotation?e.visitOrphanedAnnotation(this):e.visitChildren(this)}}I.OrphanedAnnotationContext=lM;class cM extends ge.ParserRuleContext{PUBLIC(){return this.tryGetToken(d.PUBLIC,0)}PRIVATE(){return this.tryGetToken(d.PRIVATE,0)}INTERNAL(){return this.tryGetToken(d.INTERNAL,0)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_accessLabelProp}enterRule(e){e.enterAccessLabelProp&&e.enterAccessLabelProp(this)}exitRule(e){e.exitAccessLabelProp&&e.exitAccessLabelProp(this)}accept(e){return e.visitAccessLabelProp?e.visitAccessLabelProp(this):e.visitChildren(this)}}I.AccessLabelPropContext=cM;class fM extends ge.ParserRuleContext{includeExceptListItem(e){return e===void 0?this.getRuleContexts(HR):this.getRuleContext(e,HR)}COMMA(e){return e===void 0?this.getTokens(d.COMMA):this.getToken(d.COMMA,e)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_includeExceptList}enterRule(e){e.enterIncludeExceptList&&e.enterIncludeExceptList(this)}exitRule(e){e.exitIncludeExceptList&&e.exitIncludeExceptList(this)}accept(e){return e.visitIncludeExceptList?e.visitIncludeExceptList(this):e.visitChildren(this)}}I.IncludeExceptListContext=fM;class HR extends ge.ParserRuleContext{tags(){return this.getRuleContext(0,Xt)}fieldName(){return this.tryGetRuleContext(0,Gr)}collectionWildCard(){return this.tryGetRuleContext(0,GE)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_includeExceptListItem}enterRule(e){e.enterIncludeExceptListItem&&e.enterIncludeExceptListItem(this)}exitRule(e){e.exitIncludeExceptListItem&&e.exitIncludeExceptListItem(this)}accept(e){return e.visitIncludeExceptListItem?e.visitIncludeExceptListItem(this):e.visitChildren(this)}}I.IncludeExceptListItemContext=HR;class xM extends ge.ParserRuleContext{includeField(e){return e===void 0?this.getRuleContexts(QR):this.getRuleContext(e,QR)}COMMA(e){return e===void 0?this.getTokens(d.COMMA):this.getToken(d.COMMA,e)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_includeList}enterRule(e){e.enterIncludeList&&e.enterIncludeList(this)}exitRule(e){e.exitIncludeList&&e.exitIncludeList(this)}accept(e){return e.visitIncludeList?e.visitIncludeList(this):e.visitChildren(this)}}I.IncludeListContext=xM;class QR extends ge.ParserRuleContext{tags(){return this.getRuleContext(0,Xt)}fieldName(e){return e===void 0?this.getRuleContexts(Gr):this.getRuleContext(e,Gr)}isDefine(){return this.tryGetRuleContext(0,v0)}collectionWildCard(){return this.tryGetRuleContext(0,GE)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_includeField}enterRule(e){e.enterIncludeField&&e.enterIncludeField(this)}exitRule(e){e.exitIncludeField&&e.exitIncludeField(this)}accept(e){return e.visitIncludeField?e.visitIncludeField(this):e.visitChildren(this)}}I.IncludeFieldContext=QR;class Ws extends ge.ParserRuleContext{constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_segExpr}copyFrom(e){super.copyFrom(e)}}I.SegExprContext=Ws;class vfe extends Ws{fieldPath(){return this.getRuleContext(0,Ga)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterSegField&&e.enterSegField(this)}exitRule(e){e.exitSegField&&e.exitSegField(this)}accept(e){return e.visitSegField?e.visitSegField(this):e.visitChildren(this)}}I.SegFieldContext=vfe;class Cfe extends Ws{queryProperties(){return this.getRuleContext(0,Kk)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterSegOps&&e.enterSegOps(this)}exitRule(e){e.exitSegOps&&e.exitSegOps(this)}accept(e){return e.visitSegOps?e.visitSegOps(this):e.visitChildren(this)}}I.SegOpsContext=Cfe;class Sfe extends Ws{OPAREN(){return this.getToken(d.OPAREN,0)}vExpr(){return this.getRuleContext(0,xf)}CPAREN(){return this.getToken(d.CPAREN,0)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterSegParen&&e.enterSegParen(this)}exitRule(e){e.exitSegParen&&e.exitSegParen(this)}accept(e){return e.visitSegParen?e.visitSegParen(this):e.visitChildren(this)}}I.SegParenContext=Sfe;class bfe extends Ws{PLUS(){return this.getToken(d.PLUS,0)}segExpr(e){return e===void 0?this.getRuleContexts(Ws):this.getRuleContext(e,Ws)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterSegRefine&&e.enterSegRefine(this)}exitRule(e){e.exitSegRefine&&e.exitSegRefine(this)}accept(e){return e.visitSegRefine?e.visitSegRefine(this):e.visitChildren(this)}}I.SegRefineContext=bfe;class xf extends ge.ParserRuleContext{constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_vExpr}copyFrom(e){super.copyFrom(e)}}I.VExprContext=xf;class Tfe extends xf{segExpr(){return this.getRuleContext(0,Ws)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterVSeg&&e.enterVSeg(this)}exitRule(e){e.exitVSeg&&e.exitVSeg(this)}accept(e){return e.visitVSeg?e.visitVSeg(this):e.visitChildren(this)}}I.VSegContext=Tfe;class Rfe extends xf{ARROW(){return this.getToken(d.ARROW,0)}segExpr(){return this.getRuleContext(0,Ws)}vExpr(){return this.getRuleContext(0,xf)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterVArrow&&e.enterVArrow(this)}exitRule(e){e.exitVArrow&&e.exitVArrow(this)}accept(e){return e.visitVArrow?e.visitVArrow(this):e.visitChildren(this)}}I.VArrowContext=Rfe;class zR extends ge.ParserRuleContext{defDimensions(){return this.tryGetRuleContext(0,BR)}defMeasures(){return this.tryGetRuleContext(0,$R)}joinStatement(){return this.tryGetRuleContext(0,C0)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_queryExtendStatement}enterRule(e){e.enterQueryExtendStatement&&e.enterQueryExtendStatement(this)}exitRule(e){e.exitQueryExtendStatement&&e.exitQueryExtendStatement(this)}accept(e){return e.visitQueryExtendStatement?e.visitQueryExtendStatement(this):e.visitChildren(this)}}I.QueryExtendStatementContext=zR;class dM extends ge.ParserRuleContext{OCURLY(){return this.getToken(d.OCURLY,0)}CCURLY(){return this.getToken(d.CCURLY,0)}queryExtendStatement(e){return e===void 0?this.getRuleContexts(zR):this.getRuleContext(e,zR)}SEMI(e){return e===void 0?this.getTokens(d.SEMI):this.getToken(d.SEMI,e)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_queryExtendStatementList}enterRule(e){e.enterQueryExtendStatementList&&e.enterQueryExtendStatementList(this)}exitRule(e){e.exitQueryExtendStatementList&&e.exitQueryExtendStatementList(this)}accept(e){return e.visitQueryExtendStatementList?e.visitQueryExtendStatementList(this):e.visitChildren(this)}}I.QueryExtendStatementListContext=dM;class qE extends ge.ParserRuleContext{joinDef(e){return e===void 0?this.getRuleContexts(e1):this.getRuleContext(e,e1)}COMMA(e){return e===void 0?this.getTokens(d.COMMA):this.getToken(d.COMMA,e)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_joinList}enterRule(e){e.enterJoinList&&e.enterJoinList(this)}exitRule(e){e.exitJoinList&&e.exitJoinList(this)}accept(e){return e.visitJoinList?e.visitJoinList(this):e.visitChildren(this)}}I.JoinListContext=qE;class hM extends ge.ParserRuleContext{IS(){return this.getToken(d.IS,0)}sqExpr(){return this.getRuleContext(0,cn)}tags(e){return e===void 0?this.getRuleContexts(Xt):this.getRuleContext(e,Xt)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_isExplore}enterRule(e){e.enterIsExplore&&e.enterIsExplore(this)}exitRule(e){e.exitIsExplore&&e.exitIsExplore(this)}accept(e){return e.visitIsExplore?e.visitIsExplore(this):e.visitChildren(this)}}I.IsExploreContext=hM;class WR extends ge.ParserRuleContext{LEFT(){return this.tryGetToken(d.LEFT,0)}RIGHT(){return this.tryGetToken(d.RIGHT,0)}FULL(){return this.tryGetToken(d.FULL,0)}INNER(){return this.tryGetToken(d.INNER,0)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_matrixOperation}enterRule(e){e.enterMatrixOperation&&e.enterMatrixOperation(this)}exitRule(e){e.exitMatrixOperation&&e.exitMatrixOperation(this)}accept(e){return e.visitMatrixOperation?e.visitMatrixOperation(this):e.visitChildren(this)}}I.MatrixOperationContext=WR;class GR extends ge.ParserRuleContext{joinNameDef(){return this.getRuleContext(0,oM)}sourceArguments(){return this.tryGetRuleContext(0,PR)}isExplore(){return this.tryGetRuleContext(0,hM)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_joinFrom}enterRule(e){e.enterJoinFrom&&e.enterJoinFrom(this)}exitRule(e){e.exitJoinFrom&&e.exitJoinFrom(this)}accept(e){return e.visitJoinFrom?e.visitJoinFrom(this):e.visitChildren(this)}}I.JoinFromContext=GR;class e1 extends ge.ParserRuleContext{constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_joinDef}copyFrom(e){super.copyFrom(e)}}I.JoinDefContext=e1;class Dfe extends e1{joinFrom(){return this.getRuleContext(0,GR)}WITH(){return this.getToken(d.WITH,0)}fieldExpr(){return this.getRuleContext(0,Re)}ANNOTATION(e){return e===void 0?this.getTokens(d.ANNOTATION):this.getToken(d.ANNOTATION,e)}matrixOperation(){return this.tryGetRuleContext(0,WR)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterJoinWith&&e.enterJoinWith(this)}exitRule(e){e.exitJoinWith&&e.exitJoinWith(this)}accept(e){return e.visitJoinWith?e.visitJoinWith(this):e.visitChildren(this)}}I.JoinWithContext=Dfe;class Ofe extends e1{joinFrom(){return this.getRuleContext(0,GR)}ANNOTATION(e){return e===void 0?this.getTokens(d.ANNOTATION):this.getToken(d.ANNOTATION,e)}ON(){return this.tryGetToken(d.ON,0)}joinExpression(){return this.tryGetRuleContext(0,pM)}matrixOperation(){return this.tryGetRuleContext(0,WR)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterJoinOn&&e.enterJoinOn(this)}exitRule(e){e.exitJoinOn&&e.exitJoinOn(this)}accept(e){return e.visitJoinOn?e.visitJoinOn(this):e.visitChildren(this)}}I.JoinOnContext=Ofe;class pM extends ge.ParserRuleContext{fieldExpr(){return this.getRuleContext(0,Re)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_joinExpression}enterRule(e){e.enterJoinExpression&&e.enterJoinExpression(this)}exitRule(e){e.exitJoinExpression&&e.exitJoinExpression(this)}accept(e){return e.visitJoinExpression?e.visitJoinExpression(this):e.visitChildren(this)}}I.JoinExpressionContext=pM;class Ffe extends ge.ParserRuleContext{whereStatement(){return this.tryGetRuleContext(0,Nd)}havingStatement(){return this.tryGetRuleContext(0,JR)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_filterStatement}enterRule(e){e.enterFilterStatement&&e.enterFilterStatement(this)}exitRule(e){e.exitFilterStatement&&e.exitFilterStatement(this)}accept(e){return e.visitFilterStatement?e.visitFilterStatement(this):e.visitChildren(this)}}I.FilterStatementContext=Ffe;class mM extends ge.ParserRuleContext{OCURLY(){return this.getToken(d.OCURLY,0)}CCURLY(){return this.getToken(d.CCURLY,0)}fieldPropertyStatement(e){return e===void 0?this.getRuleContexts(YR):this.getRuleContext(e,YR)}SEMI(e){return e===void 0?this.getTokens(d.SEMI):this.getToken(d.SEMI,e)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_fieldProperties}enterRule(e){e.enterFieldProperties&&e.enterFieldProperties(this)}exitRule(e){e.exitFieldProperties&&e.exitFieldProperties(this)}accept(e){return e.visitFieldProperties?e.visitFieldProperties(this):e.visitChildren(this)}}I.FieldPropertiesContext=mM;class gM extends ge.ParserRuleContext{aggregateOrderBySpec(e){return e===void 0?this.getRuleContexts(VR):this.getRuleContext(e,VR)}COMMA(e){return e===void 0?this.getTokens(d.COMMA):this.getToken(d.COMMA,e)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_aggregateOrdering}enterRule(e){e.enterAggregateOrdering&&e.enterAggregateOrdering(this)}exitRule(e){e.exitAggregateOrdering&&e.exitAggregateOrdering(this)}accept(e){return e.visitAggregateOrdering?e.visitAggregateOrdering(this):e.visitChildren(this)}}I.AggregateOrderingContext=gM;class VR extends ge.ParserRuleContext{fieldExpr(){return this.tryGetRuleContext(0,Re)}ASC(){return this.tryGetToken(d.ASC,0)}DESC(){return this.tryGetToken(d.DESC,0)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_aggregateOrderBySpec}enterRule(e){e.enterAggregateOrderBySpec&&e.enterAggregateOrderBySpec(this)}exitRule(e){e.exitAggregateOrderBySpec&&e.exitAggregateOrderBySpec(this)}accept(e){return e.visitAggregateOrderBySpec?e.visitAggregateOrderBySpec(this):e.visitChildren(this)}}I.AggregateOrderBySpecContext=VR;class yM extends ge.ParserRuleContext{ORDER_BY(){return this.getToken(d.ORDER_BY,0)}aggregateOrdering(){return this.getRuleContext(0,gM)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_aggregateOrderByStatement}enterRule(e){e.enterAggregateOrderByStatement&&e.enterAggregateOrderByStatement(this)}exitRule(e){e.exitAggregateOrderByStatement&&e.exitAggregateOrderByStatement(this)}accept(e){return e.visitAggregateOrderByStatement?e.visitAggregateOrderByStatement(this):e.visitChildren(this)}}I.AggregateOrderByStatementContext=yM;class EM extends ge.ParserRuleContext{limitStatement(){return this.getRuleContext(0,nD)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_fieldPropertyLimitStatement}enterRule(e){e.enterFieldPropertyLimitStatement&&e.enterFieldPropertyLimitStatement(this)}exitRule(e){e.exitFieldPropertyLimitStatement&&e.exitFieldPropertyLimitStatement(this)}accept(e){return e.visitFieldPropertyLimitStatement?e.visitFieldPropertyLimitStatement(this):e.visitChildren(this)}}I.FieldPropertyLimitStatementContext=EM;class YR extends ge.ParserRuleContext{whereStatement(){return this.tryGetRuleContext(0,Nd)}partitionByStatement(){return this.tryGetRuleContext(0,OM)}aggregateOrderByStatement(){return this.tryGetRuleContext(0,yM)}fieldPropertyLimitStatement(){return this.tryGetRuleContext(0,EM)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_fieldPropertyStatement}enterRule(e){e.enterFieldPropertyStatement&&e.enterFieldPropertyStatement(this)}exitRule(e){e.exitFieldPropertyStatement&&e.exitFieldPropertyStatement(this)}accept(e){return e.visitFieldPropertyStatement?e.visitFieldPropertyStatement(this):e.visitChildren(this)}}I.FieldPropertyStatementContext=YR;class KR extends ge.ParserRuleContext{fieldExpr(e){return e===void 0?this.getRuleContexts(Re):this.getRuleContext(e,Re)}COMMA(e){return e===void 0?this.getTokens(d.COMMA):this.getToken(d.COMMA,e)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_filterClauseList}enterRule(e){e.enterFilterClauseList&&e.enterFilterClauseList(this)}exitRule(e){e.exitFilterClauseList&&e.exitFilterClauseList(this)}accept(e){return e.visitFilterClauseList?e.visitFilterClauseList(this):e.visitChildren(this)}}I.FilterClauseListContext=KR;class Nd extends ge.ParserRuleContext{WHERE(){return this.getToken(d.WHERE,0)}filterClauseList(){return this.getRuleContext(0,KR)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_whereStatement}enterRule(e){e.enterWhereStatement&&e.enterWhereStatement(this)}exitRule(e){e.exitWhereStatement&&e.exitWhereStatement(this)}accept(e){return e.visitWhereStatement?e.visitWhereStatement(this):e.visitChildren(this)}}I.WhereStatementContext=Nd;class JR extends ge.ParserRuleContext{HAVING(){return this.getToken(d.HAVING,0)}filterClauseList(){return this.getRuleContext(0,KR)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_havingStatement}enterRule(e){e.enterHavingStatement&&e.enterHavingStatement(this)}exitRule(e){e.exitHavingStatement&&e.exitHavingStatement(this)}accept(e){return e.visitHavingStatement?e.visitHavingStatement(this):e.visitChildren(this)}}I.HavingStatementContext=JR;class AM extends ge.ParserRuleContext{exploreQueryDef(e){return e===void 0?this.getRuleContexts(XR):this.getRuleContext(e,XR)}COMMA(e){return e===void 0?this.getTokens(d.COMMA):this.getToken(d.COMMA,e)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_subQueryDefList}enterRule(e){e.enterSubQueryDefList&&e.enterSubQueryDefList(this)}exitRule(e){e.exitSubQueryDefList&&e.exitSubQueryDefList(this)}accept(e){return e.visitSubQueryDefList?e.visitSubQueryDefList(this):e.visitChildren(this)}}I.SubQueryDefListContext=AM;class _M extends ge.ParserRuleContext{id(){return this.getRuleContext(0,Nn)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_exploreQueryNameDef}enterRule(e){e.enterExploreQueryNameDef&&e.enterExploreQueryNameDef(this)}exitRule(e){e.exitExploreQueryNameDef&&e.exitExploreQueryNameDef(this)}accept(e){return e.visitExploreQueryNameDef?e.visitExploreQueryNameDef(this):e.visitChildren(this)}}I.ExploreQueryNameDefContext=_M;class XR extends ge.ParserRuleContext{exploreQueryNameDef(){return this.getRuleContext(0,_M)}isDefine(){return this.getRuleContext(0,v0)}vExpr(){return this.getRuleContext(0,xf)}ANNOTATION(e){return e===void 0?this.getTokens(d.ANNOTATION):this.getToken(d.ANNOTATION,e)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_exploreQueryDef}enterRule(e){e.enterExploreQueryDef&&e.enterExploreQueryDef(this)}exitRule(e){e.exitExploreQueryDef&&e.exitExploreQueryDef(this)}accept(e){return e.visitExploreQueryDef?e.visitExploreQueryDef(this):e.visitChildren(this)}}I.ExploreQueryDefContext=XR;class ZR extends ge.ParserRuleContext{groupByStatement(){return this.tryGetRuleContext(0,CM)}declareStatement(){return this.tryGetRuleContext(0,MR)}queryJoinStatement(){return this.tryGetRuleContext(0,vM)}queryExtend(){return this.tryGetRuleContext(0,uM)}projectStatement(){return this.tryGetRuleContext(0,DM)}indexStatement(){return this.tryGetRuleContext(0,IM)}aggregateStatement(){return this.tryGetRuleContext(0,TM)}calculateStatement(){return this.tryGetRuleContext(0,RM)}topStatement(){return this.tryGetRuleContext(0,NM)}limitStatement(){return this.tryGetRuleContext(0,nD)}orderByStatement(){return this.tryGetRuleContext(0,FM)}whereStatement(){return this.tryGetRuleContext(0,Nd)}havingStatement(){return this.tryGetRuleContext(0,JR)}nestStatement(){return this.tryGetRuleContext(0,SM)}sampleStatement(){return this.tryGetRuleContext(0,$M)}timezoneStatement(){return this.tryGetRuleContext(0,iD)}queryAnnotation(){return this.tryGetRuleContext(0,BM)}ignoredModelAnnotations(){return this.tryGetRuleContext(0,DR)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_queryStatement}enterRule(e){e.enterQueryStatement&&e.enterQueryStatement(this)}exitRule(e){e.exitQueryStatement&&e.exitQueryStatement(this)}accept(e){return e.visitQueryStatement?e.visitQueryStatement(this):e.visitChildren(this)}}I.QueryStatementContext=ZR;class vM extends ge.ParserRuleContext{joinStatement(){return this.getRuleContext(0,C0)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_queryJoinStatement}enterRule(e){e.enterQueryJoinStatement&&e.enterQueryJoinStatement(this)}exitRule(e){e.exitQueryJoinStatement&&e.exitQueryJoinStatement(this)}accept(e){return e.visitQueryJoinStatement?e.visitQueryJoinStatement(this):e.visitChildren(this)}}I.QueryJoinStatementContext=vM;class CM extends ge.ParserRuleContext{tags(){return this.getRuleContext(0,Xt)}GROUP_BY(){return this.getToken(d.GROUP_BY,0)}queryFieldList(){return this.getRuleContext(0,HE)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_groupByStatement}enterRule(e){e.enterGroupByStatement&&e.enterGroupByStatement(this)}exitRule(e){e.exitGroupByStatement&&e.exitGroupByStatement(this)}accept(e){return e.visitGroupByStatement?e.visitGroupByStatement(this):e.visitChildren(this)}}I.GroupByStatementContext=CM;class HE extends ge.ParserRuleContext{queryFieldEntry(e){return e===void 0?this.getRuleContexts(eD):this.getRuleContext(e,eD)}COMMA(e){return e===void 0?this.getTokens(d.COMMA):this.getToken(d.COMMA,e)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_queryFieldList}enterRule(e){e.enterQueryFieldList&&e.enterQueryFieldList(this)}exitRule(e){e.exitQueryFieldList&&e.exitQueryFieldList(this)}accept(e){return e.visitQueryFieldList?e.visitQueryFieldList(this):e.visitChildren(this)}}I.QueryFieldListContext=HE;class eD extends ge.ParserRuleContext{taggedRef(){return this.tryGetRuleContext(0,xD)}fieldDef(){return this.tryGetRuleContext(0,Z2)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_queryFieldEntry}enterRule(e){e.enterQueryFieldEntry&&e.enterQueryFieldEntry(this)}exitRule(e){e.exitQueryFieldEntry&&e.exitQueryFieldEntry(this)}accept(e){return e.visitQueryFieldEntry?e.visitQueryFieldEntry(this):e.visitChildren(this)}}I.QueryFieldEntryContext=eD;class SM extends ge.ParserRuleContext{tags(){return this.getRuleContext(0,Xt)}NEST(){return this.getToken(d.NEST,0)}nestedQueryList(){return this.getRuleContext(0,bM)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_nestStatement}enterRule(e){e.enterNestStatement&&e.enterNestStatement(this)}exitRule(e){e.exitNestStatement&&e.exitNestStatement(this)}accept(e){return e.visitNestStatement?e.visitNestStatement(this):e.visitChildren(this)}}I.NestStatementContext=SM;class bM extends ge.ParserRuleContext{nestEntry(e){return e===void 0?this.getRuleContexts(QE):this.getRuleContext(e,QE)}COMMA(e){return e===void 0?this.getTokens(d.COMMA):this.getToken(d.COMMA,e)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_nestedQueryList}enterRule(e){e.enterNestedQueryList&&e.enterNestedQueryList(this)}exitRule(e){e.exitNestedQueryList&&e.exitNestedQueryList(this)}accept(e){return e.visitNestedQueryList?e.visitNestedQueryList(this):e.visitChildren(this)}}I.NestedQueryListContext=bM;class QE extends ge.ParserRuleContext{constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_nestEntry}copyFrom(e){super.copyFrom(e)}}I.NestEntryContext=QE;class wfe extends QE{tags(){return this.getRuleContext(0,Xt)}vExpr(){return this.getRuleContext(0,xf)}queryName(){return this.tryGetRuleContext(0,NR)}isDefine(){return this.tryGetRuleContext(0,v0)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterNestDef&&e.enterNestDef(this)}exitRule(e){e.exitNestDef&&e.exitNestDef(this)}accept(e){return e.visitNestDef?e.visitNestDef(this):e.visitChildren(this)}}I.NestDefContext=wfe;class TM extends ge.ParserRuleContext{tags(){return this.getRuleContext(0,Xt)}AGGREGATE(){return this.getToken(d.AGGREGATE,0)}queryFieldList(){return this.getRuleContext(0,HE)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_aggregateStatement}enterRule(e){e.enterAggregateStatement&&e.enterAggregateStatement(this)}exitRule(e){e.exitAggregateStatement&&e.exitAggregateStatement(this)}accept(e){return e.visitAggregateStatement?e.visitAggregateStatement(this):e.visitChildren(this)}}I.AggregateStatementContext=TM;class RM extends ge.ParserRuleContext{tags(){return this.getRuleContext(0,Xt)}CALCULATE(){return this.getToken(d.CALCULATE,0)}queryFieldList(){return this.getRuleContext(0,HE)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_calculateStatement}enterRule(e){e.enterCalculateStatement&&e.enterCalculateStatement(this)}exitRule(e){e.exitCalculateStatement&&e.exitCalculateStatement(this)}accept(e){return e.visitCalculateStatement?e.visitCalculateStatement(this):e.visitChildren(this)}}I.CalculateStatementContext=RM;class DM extends ge.ParserRuleContext{tags(){return this.getRuleContext(0,Xt)}SELECT(){return this.getToken(d.SELECT,0)}fieldCollection(){return this.getRuleContext(0,YM)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_projectStatement}enterRule(e){e.enterProjectStatement&&e.enterProjectStatement(this)}exitRule(e){e.exitProjectStatement&&e.exitProjectStatement(this)}accept(e){return e.visitProjectStatement?e.visitProjectStatement(this):e.visitChildren(this)}}I.ProjectStatementContext=DM;class OM extends ge.ParserRuleContext{PARTITION_BY(){return this.getToken(d.PARTITION_BY,0)}id(e){return e===void 0?this.getRuleContexts(Nn):this.getRuleContext(e,Nn)}COMMA(e){return e===void 0?this.getTokens(d.COMMA):this.getToken(d.COMMA,e)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_partitionByStatement}enterRule(e){e.enterPartitionByStatement&&e.enterPartitionByStatement(this)}exitRule(e){e.exitPartitionByStatement&&e.exitPartitionByStatement(this)}accept(e){return e.visitPartitionByStatement?e.visitPartitionByStatement(this):e.visitChildren(this)}}I.PartitionByStatementContext=OM;class FM extends ge.ParserRuleContext{ORDER_BY(){return this.getToken(d.ORDER_BY,0)}ordering(){return this.getRuleContext(0,wM)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_orderByStatement}enterRule(e){e.enterOrderByStatement&&e.enterOrderByStatement(this)}exitRule(e){e.exitOrderByStatement&&e.exitOrderByStatement(this)}accept(e){return e.visitOrderByStatement?e.visitOrderByStatement(this):e.visitChildren(this)}}I.OrderByStatementContext=FM;class wM extends ge.ParserRuleContext{orderBySpec(e){return e===void 0?this.getRuleContexts(tD):this.getRuleContext(e,tD)}COMMA(e){return e===void 0?this.getTokens(d.COMMA):this.getToken(d.COMMA,e)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_ordering}enterRule(e){e.enterOrdering&&e.enterOrdering(this)}exitRule(e){e.exitOrdering&&e.exitOrdering(this)}accept(e){return e.visitOrdering?e.visitOrdering(this):e.visitChildren(this)}}I.OrderingContext=wM;class tD extends ge.ParserRuleContext{INTEGER_LITERAL(){return this.tryGetToken(d.INTEGER_LITERAL,0)}fieldName(){return this.tryGetRuleContext(0,Gr)}ASC(){return this.tryGetToken(d.ASC,0)}DESC(){return this.tryGetToken(d.DESC,0)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_orderBySpec}enterRule(e){e.enterOrderBySpec&&e.enterOrderBySpec(this)}exitRule(e){e.exitOrderBySpec&&e.exitOrderBySpec(this)}accept(e){return e.visitOrderBySpec?e.visitOrderBySpec(this):e.visitChildren(this)}}I.OrderBySpecContext=tD;class nD extends ge.ParserRuleContext{LIMIT(){return this.getToken(d.LIMIT,0)}INTEGER_LITERAL(){return this.getToken(d.INTEGER_LITERAL,0)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_limitStatement}enterRule(e){e.enterLimitStatement&&e.enterLimitStatement(this)}exitRule(e){e.exitLimitStatement&&e.exitLimitStatement(this)}accept(e){return e.visitLimitStatement?e.visitLimitStatement(this):e.visitChildren(this)}}I.LimitStatementContext=nD;class Nfe extends ge.ParserRuleContext{BY(){return this.getToken(d.BY,0)}fieldName(){return this.tryGetRuleContext(0,Gr)}fieldExpr(){return this.tryGetRuleContext(0,Re)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_bySpec}enterRule(e){e.enterBySpec&&e.enterBySpec(this)}exitRule(e){e.exitBySpec&&e.exitBySpec(this)}accept(e){return e.visitBySpec?e.visitBySpec(this):e.visitChildren(this)}}I.BySpecContext=Nfe;class NM extends ge.ParserRuleContext{TOP(){return this.getToken(d.TOP,0)}INTEGER_LITERAL(){return this.getToken(d.INTEGER_LITERAL,0)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_topStatement}enterRule(e){e.enterTopStatement&&e.enterTopStatement(this)}exitRule(e){e.exitTopStatement&&e.exitTopStatement(this)}accept(e){return e.visitTopStatement?e.visitTopStatement(this):e.visitChildren(this)}}I.TopStatementContext=NM;class rD extends ge.ParserRuleContext{fieldPath(){return this.tryGetRuleContext(0,Ga)}DOT(){return this.tryGetToken(d.DOT,0)}STAR(){return this.tryGetToken(d.STAR,0)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_indexElement}enterRule(e){e.enterIndexElement&&e.enterIndexElement(this)}exitRule(e){e.exitIndexElement&&e.exitIndexElement(this)}accept(e){return e.visitIndexElement?e.visitIndexElement(this):e.visitChildren(this)}}I.IndexElementContext=rD;class LM extends ge.ParserRuleContext{indexElement(e){return e===void 0?this.getRuleContexts(rD):this.getRuleContext(e,rD)}COMMA(e){return e===void 0?this.getTokens(d.COMMA):this.getToken(d.COMMA,e)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_indexFields}enterRule(e){e.enterIndexFields&&e.enterIndexFields(this)}exitRule(e){e.exitIndexFields&&e.exitIndexFields(this)}accept(e){return e.visitIndexFields?e.visitIndexFields(this):e.visitChildren(this)}}I.IndexFieldsContext=LM;class IM extends ge.ParserRuleContext{INDEX(){return this.getToken(d.INDEX,0)}indexFields(){return this.getRuleContext(0,LM)}BY(){return this.tryGetToken(d.BY,0)}fieldName(){return this.tryGetRuleContext(0,Gr)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_indexStatement}enterRule(e){e.enterIndexStatement&&e.enterIndexStatement(this)}exitRule(e){e.exitIndexStatement&&e.exitIndexStatement(this)}accept(e){return e.visitIndexStatement?e.visitIndexStatement(this):e.visitChildren(this)}}I.IndexStatementContext=IM;class $M extends ge.ParserRuleContext{SAMPLE(){return this.getToken(d.SAMPLE,0)}sampleSpec(){return this.getRuleContext(0,kM)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_sampleStatement}enterRule(e){e.enterSampleStatement&&e.enterSampleStatement(this)}exitRule(e){e.exitSampleStatement&&e.exitSampleStatement(this)}accept(e){return e.visitSampleStatement?e.visitSampleStatement(this):e.visitChildren(this)}}I.SampleStatementContext=$M;class iD extends ge.ParserRuleContext{TIMEZONE(){return this.getToken(d.TIMEZONE,0)}string(){return this.getRuleContext(0,za)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_timezoneStatement}enterRule(e){e.enterTimezoneStatement&&e.enterTimezoneStatement(this)}exitRule(e){e.exitTimezoneStatement&&e.exitTimezoneStatement(this)}accept(e){return e.visitTimezoneStatement?e.visitTimezoneStatement(this):e.visitChildren(this)}}I.TimezoneStatementContext=iD;class BM extends ge.ParserRuleContext{ANNOTATION(){return this.getToken(d.ANNOTATION,0)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_queryAnnotation}enterRule(e){e.enterQueryAnnotation&&e.enterQueryAnnotation(this)}exitRule(e){e.exitQueryAnnotation&&e.exitQueryAnnotation(this)}accept(e){return e.visitQueryAnnotation?e.visitQueryAnnotation(this):e.visitChildren(this)}}I.QueryAnnotationContext=BM;class kM extends ge.ParserRuleContext{PERCENT_LITERAL(){return this.tryGetToken(d.PERCENT_LITERAL,0)}INTEGER_LITERAL(){return this.tryGetToken(d.INTEGER_LITERAL,0)}TRUE(){return this.tryGetToken(d.TRUE,0)}FALSE(){return this.tryGetToken(d.FALSE,0)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_sampleSpec}enterRule(e){e.enterSampleSpec&&e.enterSampleSpec(this)}exitRule(e){e.exitSampleSpec&&e.exitSampleSpec(this)}accept(e){return e.visitSampleSpec?e.visitSampleSpec(this):e.visitChildren(this)}}I.SampleSpecContext=kM;class zE extends ge.ParserRuleContext{SUM(){return this.tryGetToken(d.SUM,0)}COUNT(){return this.tryGetToken(d.COUNT,0)}AVG(){return this.tryGetToken(d.AVG,0)}MIN(){return this.tryGetToken(d.MIN,0)}MAX(){return this.tryGetToken(d.MAX,0)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_aggregate}enterRule(e){e.enterAggregate&&e.enterAggregate(this)}exitRule(e){e.exitAggregate&&e.exitAggregate(this)}accept(e){return e.visitAggregate?e.visitAggregate(this):e.visitChildren(this)}}I.AggregateContext=zE;class WE extends ge.ParserRuleContext{STRING(){return this.tryGetToken(d.STRING,0)}NUMBER(){return this.tryGetToken(d.NUMBER,0)}BOOLEAN(){return this.tryGetToken(d.BOOLEAN,0)}DATE(){return this.tryGetToken(d.DATE,0)}TIMESTAMP(){return this.tryGetToken(d.TIMESTAMP,0)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_malloyType}enterRule(e){e.enterMalloyType&&e.enterMalloyType(this)}exitRule(e){e.exitMalloyType&&e.exitMalloyType(this)}accept(e){return e.visitMalloyType?e.visitMalloyType(this):e.visitChildren(this)}}I.MalloyTypeContext=WE;class sD extends ge.ParserRuleContext{MATCH(){return this.tryGetToken(d.MATCH,0)}NOT_MATCH(){return this.tryGetToken(d.NOT_MATCH,0)}GT(){return this.tryGetToken(d.GT,0)}LT(){return this.tryGetToken(d.LT,0)}GTE(){return this.tryGetToken(d.GTE,0)}LTE(){return this.tryGetToken(d.LTE,0)}EQ(){return this.tryGetToken(d.EQ,0)}NE(){return this.tryGetToken(d.NE,0)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_compareOp}enterRule(e){e.enterCompareOp&&e.enterCompareOp(this)}exitRule(e){e.exitCompareOp&&e.exitCompareOp(this)}accept(e){return e.visitCompareOp?e.visitCompareOp(this):e.visitChildren(this)}}I.CompareOpContext=sD;class za extends ge.ParserRuleContext{shortString(){return this.tryGetRuleContext(0,oD)}sqlString(){return this.tryGetRuleContext(0,bR)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_string}enterRule(e){e.enterString&&e.enterString(this)}exitRule(e){e.exitString&&e.exitString(this)}accept(e){return e.visitString?e.visitString(this):e.visitChildren(this)}}I.StringContext=za;class oD extends ge.ParserRuleContext{SQ_STRING(){return this.tryGetToken(d.SQ_STRING,0)}DQ_STRING(){return this.tryGetToken(d.DQ_STRING,0)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_shortString}enterRule(e){e.enterShortString&&e.enterShortString(this)}exitRule(e){e.exitShortString&&e.exitShortString(this)}accept(e){return e.visitShortString?e.visitShortString(this):e.visitChildren(this)}}I.ShortStringContext=oD;class MM extends ge.ParserRuleContext{RAW_SQ(){return this.tryGetToken(d.RAW_SQ,0)}RAW_DQ(){return this.tryGetToken(d.RAW_DQ,0)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_rawString}enterRule(e){e.enterRawString&&e.enterRawString(this)}exitRule(e){e.exitRawString&&e.exitRawString(this)}accept(e){return e.visitRawString?e.visitRawString(this):e.visitChildren(this)}}I.RawStringContext=MM;class PM extends ge.ParserRuleContext{NUMERIC_LITERAL(){return this.tryGetToken(d.NUMERIC_LITERAL,0)}INTEGER_LITERAL(){return this.tryGetToken(d.INTEGER_LITERAL,0)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_numericLiteral}enterRule(e){e.enterNumericLiteral&&e.enterNumericLiteral(this)}exitRule(e){e.exitNumericLiteral&&e.exitNumericLiteral(this)}accept(e){return e.visitNumericLiteral?e.visitNumericLiteral(this):e.visitChildren(this)}}I.NumericLiteralContext=PM;class Oo extends ge.ParserRuleContext{constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_literal}copyFrom(e){super.copyFrom(e)}}I.LiteralContext=Oo;class Lfe extends Oo{string(){return this.getRuleContext(0,za)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprString&&e.enterExprString(this)}exitRule(e){e.exitExprString&&e.exitExprString(this)}accept(e){return e.visitExprString?e.visitExprString(this):e.visitChildren(this)}}I.ExprStringContext=Lfe;class Ife extends Oo{rawString(){return this.getRuleContext(0,MM)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterStub_rawString&&e.enterStub_rawString(this)}exitRule(e){e.exitStub_rawString&&e.exitStub_rawString(this)}accept(e){return e.visitStub_rawString?e.visitStub_rawString(this):e.visitChildren(this)}}I.Stub_rawStringContext=Ife;class $fe extends Oo{numericLiteral(){return this.getRuleContext(0,PM)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprNumber&&e.enterExprNumber(this)}exitRule(e){e.exitExprNumber&&e.exitExprNumber(this)}accept(e){return e.visitExprNumber?e.visitExprNumber(this):e.visitChildren(this)}}I.ExprNumberContext=$fe;class Bfe extends Oo{dateLiteral(){return this.getRuleContext(0,Wa)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprTime&&e.enterExprTime(this)}exitRule(e){e.exitExprTime&&e.exitExprTime(this)}accept(e){return e.visitExprTime?e.visitExprTime(this):e.visitChildren(this)}}I.ExprTimeContext=Bfe;class kfe extends Oo{NULL(){return this.getToken(d.NULL,0)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprNULL&&e.enterExprNULL(this)}exitRule(e){e.exitExprNULL&&e.exitExprNULL(this)}accept(e){return e.visitExprNULL?e.visitExprNULL(this):e.visitChildren(this)}}I.ExprNULLContext=kfe;class Mfe extends Oo{TRUE(){return this.tryGetToken(d.TRUE,0)}FALSE(){return this.tryGetToken(d.FALSE,0)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprBool&&e.enterExprBool(this)}exitRule(e){e.exitExprBool&&e.exitExprBool(this)}accept(e){return e.visitExprBool?e.visitExprBool(this):e.visitChildren(this)}}I.ExprBoolContext=Mfe;class Pfe extends Oo{HACKY_REGEX(){return this.getToken(d.HACKY_REGEX,0)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprRegex&&e.enterExprRegex(this)}exitRule(e){e.exitExprRegex&&e.exitExprRegex(this)}accept(e){return e.visitExprRegex?e.visitExprRegex(this):e.visitChildren(this)}}I.ExprRegexContext=Pfe;class Ufe extends Oo{filterString(){return this.getRuleContext(0,ZM)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterFilterString_stub&&e.enterFilterString_stub(this)}exitRule(e){e.exitFilterString_stub&&e.exitFilterString_stub(this)}accept(e){return e.visitFilterString_stub?e.visitFilterString_stub(this):e.visitChildren(this)}}I.FilterString_stubContext=Ufe;class jfe extends Oo{NOW(){return this.getToken(d.NOW,0)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprNow&&e.enterExprNow(this)}exitRule(e){e.exitExprNow&&e.exitExprNow(this)}accept(e){return e.visitExprNow?e.visitExprNow(this):e.visitChildren(this)}}I.ExprNowContext=jfe;class Wa extends ge.ParserRuleContext{constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_dateLiteral}copyFrom(e){super.copyFrom(e)}}I.DateLiteralContext=Wa;class qfe extends Wa{LITERAL_TIMESTAMP(){return this.getToken(d.LITERAL_TIMESTAMP,0)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterLiteralTimestamp&&e.enterLiteralTimestamp(this)}exitRule(e){e.exitLiteralTimestamp&&e.exitLiteralTimestamp(this)}accept(e){return e.visitLiteralTimestamp?e.visitLiteralTimestamp(this):e.visitChildren(this)}}I.LiteralTimestampContext=qfe;class Hfe extends Wa{LITERAL_HOUR(){return this.getToken(d.LITERAL_HOUR,0)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterLiteralHour&&e.enterLiteralHour(this)}exitRule(e){e.exitLiteralHour&&e.exitLiteralHour(this)}accept(e){return e.visitLiteralHour?e.visitLiteralHour(this):e.visitChildren(this)}}I.LiteralHourContext=Hfe;class Qfe extends Wa{LITERAL_DAY(){return this.getToken(d.LITERAL_DAY,0)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterLiteralDay&&e.enterLiteralDay(this)}exitRule(e){e.exitLiteralDay&&e.exitLiteralDay(this)}accept(e){return e.visitLiteralDay?e.visitLiteralDay(this):e.visitChildren(this)}}I.LiteralDayContext=Qfe;class zfe extends Wa{LITERAL_WEEK(){return this.getToken(d.LITERAL_WEEK,0)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterLiteralWeek&&e.enterLiteralWeek(this)}exitRule(e){e.exitLiteralWeek&&e.exitLiteralWeek(this)}accept(e){return e.visitLiteralWeek?e.visitLiteralWeek(this):e.visitChildren(this)}}I.LiteralWeekContext=zfe;class Wfe extends Wa{LITERAL_MONTH(){return this.getToken(d.LITERAL_MONTH,0)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterLiteralMonth&&e.enterLiteralMonth(this)}exitRule(e){e.exitLiteralMonth&&e.exitLiteralMonth(this)}accept(e){return e.visitLiteralMonth?e.visitLiteralMonth(this):e.visitChildren(this)}}I.LiteralMonthContext=Wfe;class Gfe extends Wa{LITERAL_QUARTER(){return this.getToken(d.LITERAL_QUARTER,0)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterLiteralQuarter&&e.enterLiteralQuarter(this)}exitRule(e){e.exitLiteralQuarter&&e.exitLiteralQuarter(this)}accept(e){return e.visitLiteralQuarter?e.visitLiteralQuarter(this):e.visitChildren(this)}}I.LiteralQuarterContext=Gfe;class Vfe extends Wa{LITERAL_YEAR(){return this.getToken(d.LITERAL_YEAR,0)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterLiteralYear&&e.enterLiteralYear(this)}exitRule(e){e.exitLiteralYear&&e.exitLiteralYear(this)}accept(e){return e.visitLiteralYear?e.visitLiteralYear(this):e.visitChildren(this)}}I.LiteralYearContext=Vfe;class UM extends ge.ParserRuleContext{string(){return this.getRuleContext(0,za)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_tablePath}enterRule(e){e.enterTablePath&&e.enterTablePath(this)}exitRule(e){e.exitTablePath&&e.exitTablePath(this)}accept(e){return e.visitTablePath?e.visitTablePath(this):e.visitChildren(this)}}I.TablePathContext=UM;class Yfe extends ge.ParserRuleContext{string(){return this.getRuleContext(0,za)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_tableURI}enterRule(e){e.enterTableURI&&e.enterTableURI(this)}exitRule(e){e.exitTableURI&&e.exitTableURI(this)}accept(e){return e.visitTableURI?e.visitTableURI(this):e.visitChildren(this)}}I.TableURIContext=Yfe;class Nn extends ge.ParserRuleContext{IDENTIFIER(){return this.tryGetToken(d.IDENTIFIER,0)}BQ_STRING(){return this.tryGetToken(d.BQ_STRING,0)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_id}enterRule(e){e.enterId&&e.enterId(this)}exitRule(e){e.exitId&&e.exitId(this)}accept(e){return e.visitId?e.visitId(this):e.visitChildren(this)}}I.IdContext=Nn;class Ld extends ge.ParserRuleContext{SECOND(){return this.tryGetToken(d.SECOND,0)}MINUTE(){return this.tryGetToken(d.MINUTE,0)}HOUR(){return this.tryGetToken(d.HOUR,0)}DAY(){return this.tryGetToken(d.DAY,0)}WEEK(){return this.tryGetToken(d.WEEK,0)}MONTH(){return this.tryGetToken(d.MONTH,0)}QUARTER(){return this.tryGetToken(d.QUARTER,0)}YEAR(){return this.tryGetToken(d.YEAR,0)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_timeframe}enterRule(e){e.enterTimeframe&&e.enterTimeframe(this)}exitRule(e){e.exitTimeframe&&e.exitTimeframe(this)}accept(e){return e.visitTimeframe?e.visitTimeframe(this):e.visitChildren(this)}}I.TimeframeContext=Ld;class jM extends ge.ParserRuleContext{ALL(){return this.tryGetToken(d.ALL,0)}EXCLUDE(){return this.tryGetToken(d.EXCLUDE,0)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_ungroup}enterRule(e){e.enterUngroup&&e.enterUngroup(this)}exitRule(e){e.exitUngroup&&e.exitUngroup(this)}accept(e){return e.visitUngroup?e.visitUngroup(this):e.visitChildren(this)}}I.UngroupContext=jM;class uD extends ge.ParserRuleContext{malloyType(){return this.tryGetRuleContext(0,WE)}string(){return this.tryGetRuleContext(0,za)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_malloyOrSQLType}enterRule(e){e.enterMalloyOrSQLType&&e.enterMalloyOrSQLType(this)}exitRule(e){e.exitMalloyOrSQLType&&e.exitMalloyOrSQLType(this)}accept(e){return e.visitMalloyOrSQLType?e.visitMalloyOrSQLType(this):e.visitChildren(this)}}I.MalloyOrSQLTypeContext=uD;class Re extends ge.ParserRuleContext{constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_fieldExpr}copyFrom(e){super.copyFrom(e)}}I.FieldExprContext=Re;class Kfe extends Re{fieldPath(){return this.getRuleContext(0,Ga)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprFieldPath&&e.enterExprFieldPath(this)}exitRule(e){e.exitExprFieldPath&&e.exitExprFieldPath(this)}accept(e){return e.visitExprFieldPath?e.visitExprFieldPath(this):e.visitChildren(this)}}I.ExprFieldPathContext=Kfe;class Jfe extends Re{literal(){return this.getRuleContext(0,Oo)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprLiteral&&e.enterExprLiteral(this)}exitRule(e){e.exitExprLiteral&&e.exitExprLiteral(this)}accept(e){return e.visitExprLiteral?e.visitExprLiteral(this):e.visitChildren(this)}}I.ExprLiteralContext=Jfe;class Xfe extends Re{OBRACK(){return this.getToken(d.OBRACK,0)}fieldExpr(e){return e===void 0?this.getRuleContexts(Re):this.getRuleContext(e,Re)}CBRACK(){return this.getToken(d.CBRACK,0)}COMMA(e){return e===void 0?this.getTokens(d.COMMA):this.getToken(d.COMMA,e)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprArrayLiteral&&e.enterExprArrayLiteral(this)}exitRule(e){e.exitExprArrayLiteral&&e.exitExprArrayLiteral(this)}accept(e){return e.visitExprArrayLiteral?e.visitExprArrayLiteral(this):e.visitChildren(this)}}I.ExprArrayLiteralContext=Xfe;class Zfe extends Re{OCURLY(){return this.getToken(d.OCURLY,0)}recordElement(e){return e===void 0?this.getRuleContexts(t1):this.getRuleContext(e,t1)}CCURLY(){return this.getToken(d.CCURLY,0)}COMMA(e){return e===void 0?this.getTokens(d.COMMA):this.getToken(d.COMMA,e)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprLiteralRecord&&e.enterExprLiteralRecord(this)}exitRule(e){e.exitExprLiteralRecord&&e.exitExprLiteralRecord(this)}accept(e){return e.visitExprLiteralRecord?e.visitExprLiteralRecord(this):e.visitChildren(this)}}I.ExprLiteralRecordContext=Zfe;class exe extends Re{fieldExpr(){return this.getRuleContext(0,Re)}fieldProperties(){return this.getRuleContext(0,mM)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprFieldProps&&e.enterExprFieldProps(this)}exitRule(e){e.exitExprFieldProps&&e.exitExprFieldProps(this)}accept(e){return e.visitExprFieldProps?e.visitExprFieldProps(this):e.visitChildren(this)}}I.ExprFieldPropsContext=exe;class txe extends Re{fieldExpr(){return this.getRuleContext(0,Re)}timeframe(){return this.getRuleContext(0,Ld)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprDuration&&e.enterExprDuration(this)}exitRule(e){e.exitExprDuration&&e.exitExprDuration(this)}accept(e){return e.visitExprDuration?e.visitExprDuration(this):e.visitChildren(this)}}I.ExprDurationContext=txe;class nxe extends Re{fieldExpr(){return this.getRuleContext(0,Re)}DOT(){return this.getToken(d.DOT,0)}timeframe(){return this.getRuleContext(0,Ld)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprTimeTrunc&&e.enterExprTimeTrunc(this)}exitRule(e){e.exitExprTimeTrunc&&e.exitExprTimeTrunc(this)}accept(e){return e.visitExprTimeTrunc?e.visitExprTimeTrunc(this):e.visitChildren(this)}}I.ExprTimeTruncContext=nxe;class qM extends Re{fieldExpr(){return this.getRuleContext(0,Re)}DOUBLECOLON(){return this.tryGetToken(d.DOUBLECOLON,0)}malloyOrSQLType(){return this.getRuleContext(0,uD)}CAST(){return this.tryGetToken(d.CAST,0)}OPAREN(){return this.tryGetToken(d.OPAREN,0)}AS(){return this.tryGetToken(d.AS,0)}CPAREN(){return this.tryGetToken(d.CPAREN,0)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprCast&&e.enterExprCast(this)}exitRule(e){e.exitExprCast&&e.exitExprCast(this)}accept(e){return e.visitExprCast?e.visitExprCast(this):e.visitChildren(this)}}I.ExprCastContext=qM;class rxe extends Re{fieldExpr(){return this.getRuleContext(0,Re)}TRIPLECOLON(){return this.getToken(d.TRIPLECOLON,0)}malloyOrSQLType(){return this.getRuleContext(0,uD)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprSafeCast&&e.enterExprSafeCast(this)}exitRule(e){e.exitExprSafeCast&&e.exitExprSafeCast(this)}accept(e){return e.visitExprSafeCast?e.visitExprSafeCast(this):e.visitChildren(this)}}I.ExprSafeCastContext=rxe;class ixe extends Re{MINUS(){return this.getToken(d.MINUS,0)}fieldExpr(){return this.getRuleContext(0,Re)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprMinus&&e.enterExprMinus(this)}exitRule(e){e.exitExprMinus&&e.exitExprMinus(this)}accept(e){return e.visitExprMinus?e.visitExprMinus(this):e.visitChildren(this)}}I.ExprMinusContext=ixe;class sxe extends Re{fieldExpr(e){return e===void 0?this.getRuleContexts(Re):this.getRuleContext(e,Re)}STAR(){return this.tryGetToken(d.STAR,0)}SLASH(){return this.tryGetToken(d.SLASH,0)}PERCENT(){return this.tryGetToken(d.PERCENT,0)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprMulDiv&&e.enterExprMulDiv(this)}exitRule(e){e.exitExprMulDiv&&e.exitExprMulDiv(this)}accept(e){return e.visitExprMulDiv?e.visitExprMulDiv(this):e.visitChildren(this)}}I.ExprMulDivContext=sxe;class oxe extends Re{fieldExpr(e){return e===void 0?this.getRuleContexts(Re):this.getRuleContext(e,Re)}PLUS(){return this.tryGetToken(d.PLUS,0)}MINUS(){return this.tryGetToken(d.MINUS,0)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprAddSub&&e.enterExprAddSub(this)}exitRule(e){e.exitExprAddSub&&e.exitExprAddSub(this)}accept(e){return e.visitExprAddSub?e.visitExprAddSub(this):e.visitChildren(this)}}I.ExprAddSubContext=oxe;class uxe extends Re{fieldExpr(e){return e===void 0?this.getRuleContexts(Re):this.getRuleContext(e,Re)}TO(){return this.getToken(d.TO,0)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprRange&&e.enterExprRange(this)}exitRule(e){e.exitExprRange&&e.exitExprRange(this)}accept(e){return e.visitExprRange?e.visitExprRange(this):e.visitChildren(this)}}I.ExprRangeContext=uxe;class axe extends Re{FOR(){return this.getToken(d.FOR,0)}timeframe(){return this.getRuleContext(0,Ld)}fieldExpr(e){return e===void 0?this.getRuleContexts(Re):this.getRuleContext(e,Re)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprForRange&&e.enterExprForRange(this)}exitRule(e){e.exitExprForRange&&e.exitExprForRange(this)}accept(e){return e.visitExprForRange?e.visitExprForRange(this):e.visitChildren(this)}}I.ExprForRangeContext=axe;class lxe extends Re{fieldExpr(){return this.getRuleContext(0,Re)}AMPER(){return this.getToken(d.AMPER,0)}partialAllowedFieldExpr(){return this.getRuleContext(0,Id)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprAndTree&&e.enterExprAndTree(this)}exitRule(e){e.exitExprAndTree&&e.exitExprAndTree(this)}accept(e){return e.visitExprAndTree?e.visitExprAndTree(this):e.visitChildren(this)}}I.ExprAndTreeContext=lxe;class cxe extends Re{fieldExpr(){return this.getRuleContext(0,Re)}BAR(){return this.getToken(d.BAR,0)}partialAllowedFieldExpr(){return this.getRuleContext(0,Id)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprOrTree&&e.enterExprOrTree(this)}exitRule(e){e.exitExprOrTree&&e.exitExprOrTree(this)}accept(e){return e.visitExprOrTree?e.visitExprOrTree(this):e.visitChildren(this)}}I.ExprOrTreeContext=cxe;class fxe extends Re{fieldExpr(e){return e===void 0?this.getRuleContexts(Re):this.getRuleContext(e,Re)}compareOp(){return this.getRuleContext(0,sD)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprCompare&&e.enterExprCompare(this)}exitRule(e){e.exitExprCompare&&e.exitExprCompare(this)}accept(e){return e.visitExprCompare?e.visitExprCompare(this):e.visitChildren(this)}}I.ExprCompareContext=fxe;class xxe extends Re{fieldExpr(e){return e===void 0?this.getRuleContexts(Re):this.getRuleContext(e,Re)}LIKE(){return this.getToken(d.LIKE,0)}NOT(){return this.tryGetToken(d.NOT,0)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprWarnLike&&e.enterExprWarnLike(this)}exitRule(e){e.exitExprWarnLike&&e.exitExprWarnLike(this)}accept(e){return e.visitExprWarnLike?e.visitExprWarnLike(this):e.visitChildren(this)}}I.ExprWarnLikeContext=xxe;class dxe extends Re{fieldExpr(){return this.getRuleContext(0,Re)}IS(){return this.getToken(d.IS,0)}NULL(){return this.getToken(d.NULL,0)}NOT(){return this.tryGetToken(d.NOT,0)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprNullCheck&&e.enterExprNullCheck(this)}exitRule(e){e.exitExprNullCheck&&e.exitExprNullCheck(this)}accept(e){return e.visitExprNullCheck?e.visitExprNullCheck(this):e.visitChildren(this)}}I.ExprNullCheckContext=dxe;class hxe extends Re{fieldExpr(){return this.getRuleContext(0,Re)}IN(){return this.getToken(d.IN,0)}OPAREN(){return this.getToken(d.OPAREN,0)}fieldExprList(){return this.getRuleContext(0,zM)}CPAREN(){return this.getToken(d.CPAREN,0)}NOT(){return this.tryGetToken(d.NOT,0)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprWarnIn&&e.enterExprWarnIn(this)}exitRule(e){e.exitExprWarnIn&&e.exitExprWarnIn(this)}accept(e){return e.visitExprWarnIn?e.visitExprWarnIn(this):e.visitChildren(this)}}I.ExprWarnInContext=hxe;class pxe extends Re{fieldExpr(){return this.getRuleContext(0,Re)}QMARK(){return this.getToken(d.QMARK,0)}partialAllowedFieldExpr(){return this.getRuleContext(0,Id)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprApply&&e.enterExprApply(this)}exitRule(e){e.exitExprApply&&e.exitExprApply(this)}accept(e){return e.visitExprApply?e.visitExprApply(this):e.visitChildren(this)}}I.ExprApplyContext=pxe;class mxe extends Re{NOT(){return this.getToken(d.NOT,0)}fieldExpr(){return this.getRuleContext(0,Re)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprNot&&e.enterExprNot(this)}exitRule(e){e.exitExprNot&&e.exitExprNot(this)}accept(e){return e.visitExprNot?e.visitExprNot(this):e.visitChildren(this)}}I.ExprNotContext=mxe;class gxe extends Re{fieldExpr(e){return e===void 0?this.getRuleContexts(Re):this.getRuleContext(e,Re)}AND(){return this.getToken(d.AND,0)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprLogicalAnd&&e.enterExprLogicalAnd(this)}exitRule(e){e.exitExprLogicalAnd&&e.exitExprLogicalAnd(this)}accept(e){return e.visitExprLogicalAnd?e.visitExprLogicalAnd(this):e.visitChildren(this)}}I.ExprLogicalAndContext=gxe;class yxe extends Re{fieldExpr(e){return e===void 0?this.getRuleContexts(Re):this.getRuleContext(e,Re)}OR(){return this.getToken(d.OR,0)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprLogicalOr&&e.enterExprLogicalOr(this)}exitRule(e){e.exitExprLogicalOr&&e.exitExprLogicalOr(this)}accept(e){return e.visitExprLogicalOr?e.visitExprLogicalOr(this):e.visitChildren(this)}}I.ExprLogicalOrContext=yxe;class Exe extends Re{fieldExpr(e){return e===void 0?this.getRuleContexts(Re):this.getRuleContext(e,Re)}DOUBLE_QMARK(){return this.getToken(d.DOUBLE_QMARK,0)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprCoalesce&&e.enterExprCoalesce(this)}exitRule(e){e.exitExprCoalesce&&e.exitExprCoalesce(this)}accept(e){return e.visitExprCoalesce?e.visitExprCoalesce(this):e.visitChildren(this)}}I.ExprCoalesceContext=Exe;class Axe extends Re{aggregate(){return this.getRuleContext(0,zE)}OPAREN(){return this.getToken(d.OPAREN,0)}CPAREN(){return this.getToken(d.CPAREN,0)}SOURCE_KW(){return this.tryGetToken(d.SOURCE_KW,0)}DOT(){return this.tryGetToken(d.DOT,0)}fieldExpr(){return this.tryGetRuleContext(0,Re)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprPathlessAggregate&&e.enterExprPathlessAggregate(this)}exitRule(e){e.exitExprPathlessAggregate&&e.exitExprPathlessAggregate(this)}accept(e){return e.visitExprPathlessAggregate?e.visitExprPathlessAggregate(this):e.visitChildren(this)}}I.ExprPathlessAggregateContext=Axe;class _xe extends Re{fieldPath(){return this.getRuleContext(0,Ga)}DOT(){return this.getToken(d.DOT,0)}aggregate(){return this.getRuleContext(0,zE)}OPAREN(){return this.getToken(d.OPAREN,0)}CPAREN(){return this.getToken(d.CPAREN,0)}fieldExpr(){return this.tryGetRuleContext(0,Re)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprAggregate&&e.enterExprAggregate(this)}exitRule(e){e.exitExprAggregate&&e.exitExprAggregate(this)}accept(e){return e.visitExprAggregate?e.visitExprAggregate(this):e.visitChildren(this)}}I.ExprAggregateContext=_xe;class vxe extends Re{OPAREN(){return this.getToken(d.OPAREN,0)}fieldExpr(){return this.getRuleContext(0,Re)}CPAREN(){return this.getToken(d.CPAREN,0)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprExpr&&e.enterExprExpr(this)}exitRule(e){e.exitExprExpr&&e.exitExprExpr(this)}accept(e){return e.visitExprExpr?e.visitExprExpr(this):e.visitChildren(this)}}I.ExprExprContext=vxe;class Cxe extends Re{fieldPath(){return this.getRuleContext(0,Ga)}DOT(){return this.getToken(d.DOT,0)}id(){return this.getRuleContext(0,Nn)}OPAREN(){return this.getToken(d.OPAREN,0)}CPAREN(){return this.getToken(d.CPAREN,0)}argumentList(){return this.tryGetRuleContext(0,cD)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprAggFunc&&e.enterExprAggFunc(this)}exitRule(e){e.exitExprAggFunc&&e.exitExprAggFunc(this)}accept(e){return e.visitExprAggFunc?e.visitExprAggFunc(this):e.visitChildren(this)}}I.ExprAggFuncContext=Cxe;class Sxe extends Re{OPAREN(){return this.getToken(d.OPAREN,0)}CPAREN(){return this.getToken(d.CPAREN,0)}timeframe(){return this.tryGetRuleContext(0,Ld)}id(){return this.tryGetRuleContext(0,Nn)}argumentList(){return this.tryGetRuleContext(0,cD)}EXCLAM(){return this.tryGetToken(d.EXCLAM,0)}malloyType(){return this.tryGetRuleContext(0,WE)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprFunc&&e.enterExprFunc(this)}exitRule(e){e.exitExprFunc&&e.exitExprFunc(this)}accept(e){return e.visitExprFunc?e.visitExprFunc(this):e.visitChildren(this)}}I.ExprFuncContext=Sxe;class bxe extends Re{pickStatement(){return this.getRuleContext(0,WM)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprPick&&e.enterExprPick(this)}exitRule(e){e.exitExprPick&&e.exitExprPick(this)}accept(e){return e.visitExprPick?e.visitExprPick(this):e.visitChildren(this)}}I.ExprPickContext=bxe;class Txe extends Re{caseStatement(){return this.getRuleContext(0,GM)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprCase&&e.enterExprCase(this)}exitRule(e){e.exitExprCase&&e.exitExprCase(this)}accept(e){return e.visitExprCase?e.visitExprCase(this):e.visitChildren(this)}}I.ExprCaseContext=Txe;class Rxe extends Re{ungroup(){return this.getRuleContext(0,jM)}OPAREN(){return this.getToken(d.OPAREN,0)}fieldExpr(){return this.getRuleContext(0,Re)}CPAREN(){return this.getToken(d.CPAREN,0)}COMMA(e){return e===void 0?this.getTokens(d.COMMA):this.getToken(d.COMMA,e)}fieldName(e){return e===void 0?this.getRuleContexts(Gr):this.getRuleContext(e,Gr)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprUngroup&&e.enterExprUngroup(this)}exitRule(e){e.exitExprUngroup&&e.exitExprUngroup(this)}accept(e){return e.visitExprUngroup?e.visitExprUngroup(this):e.visitChildren(this)}}I.ExprUngroupContext=Rxe;class HM extends ge.ParserRuleContext{compareOp(){return this.getRuleContext(0,sD)}fieldExpr(){return this.getRuleContext(0,Re)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_partialCompare}enterRule(e){e.enterPartialCompare&&e.enterPartialCompare(this)}exitRule(e){e.exitPartialCompare&&e.exitPartialCompare(this)}accept(e){return e.visitPartialCompare?e.visitPartialCompare(this):e.visitChildren(this)}}I.PartialCompareContext=HM;class QM extends ge.ParserRuleContext{partialCompare(){return this.tryGetRuleContext(0,HM)}IS(){return this.tryGetToken(d.IS,0)}NULL(){return this.tryGetToken(d.NULL,0)}NOT(){return this.tryGetToken(d.NOT,0)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_partialTest}enterRule(e){e.enterPartialTest&&e.enterPartialTest(this)}exitRule(e){e.exitPartialTest&&e.exitPartialTest(this)}accept(e){return e.visitPartialTest?e.visitPartialTest(this):e.visitChildren(this)}}I.PartialTestContext=QM;class Id extends ge.ParserRuleContext{partialTest(){return this.tryGetRuleContext(0,QM)}OPAREN(){return this.tryGetToken(d.OPAREN,0)}CPAREN(){return this.tryGetToken(d.CPAREN,0)}fieldExpr(){return this.tryGetRuleContext(0,Re)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_partialAllowedFieldExpr}enterRule(e){e.enterPartialAllowedFieldExpr&&e.enterPartialAllowedFieldExpr(this)}exitRule(e){e.exitPartialAllowedFieldExpr&&e.exitPartialAllowedFieldExpr(this)}accept(e){return e.visitPartialAllowedFieldExpr?e.visitPartialAllowedFieldExpr(this):e.visitChildren(this)}}I.PartialAllowedFieldExprContext=Id;class zM extends ge.ParserRuleContext{fieldExpr(e){return e===void 0?this.getRuleContexts(Re):this.getRuleContext(e,Re)}COMMA(e){return e===void 0?this.getTokens(d.COMMA):this.getToken(d.COMMA,e)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_fieldExprList}enterRule(e){e.enterFieldExprList&&e.enterFieldExprList(this)}exitRule(e){e.exitFieldExprList&&e.exitFieldExprList(this)}accept(e){return e.visitFieldExprList?e.visitFieldExprList(this):e.visitChildren(this)}}I.FieldExprListContext=zM;class WM extends ge.ParserRuleContext{pick(e){return e===void 0?this.getRuleContexts(aD):this.getRuleContext(e,aD)}ELSE(){return this.tryGetToken(d.ELSE,0)}fieldExpr(){return this.tryGetRuleContext(0,Re)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_pickStatement}enterRule(e){e.enterPickStatement&&e.enterPickStatement(this)}exitRule(e){e.exitPickStatement&&e.exitPickStatement(this)}accept(e){return e.visitPickStatement?e.visitPickStatement(this):e.visitChildren(this)}}I.PickStatementContext=WM;class aD extends ge.ParserRuleContext{PICK(){return this.getToken(d.PICK,0)}WHEN(){return this.getToken(d.WHEN,0)}partialAllowedFieldExpr(){return this.getRuleContext(0,Id)}fieldExpr(){return this.tryGetRuleContext(0,Re)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_pick}enterRule(e){e.enterPick&&e.enterPick(this)}exitRule(e){e.exitPick&&e.exitPick(this)}accept(e){return e.visitPick?e.visitPick(this):e.visitChildren(this)}}I.PickContext=aD;class GM extends ge.ParserRuleContext{CASE(){return this.getToken(d.CASE,0)}END(){return this.getToken(d.END,0)}caseWhen(e){return e===void 0?this.getRuleContexts(lD):this.getRuleContext(e,lD)}ELSE(){return this.tryGetToken(d.ELSE,0)}fieldExpr(e){return e===void 0?this.getRuleContexts(Re):this.getRuleContext(e,Re)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_caseStatement}enterRule(e){e.enterCaseStatement&&e.enterCaseStatement(this)}exitRule(e){e.exitCaseStatement&&e.exitCaseStatement(this)}accept(e){return e.visitCaseStatement?e.visitCaseStatement(this):e.visitChildren(this)}}I.CaseStatementContext=GM;class lD extends ge.ParserRuleContext{WHEN(){return this.getToken(d.WHEN,0)}THEN(){return this.getToken(d.THEN,0)}fieldExpr(e){return e===void 0?this.getRuleContexts(Re):this.getRuleContext(e,Re)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_caseWhen}enterRule(e){e.enterCaseWhen&&e.enterCaseWhen(this)}exitRule(e){e.exitCaseWhen&&e.exitCaseWhen(this)}accept(e){return e.visitCaseWhen?e.visitCaseWhen(this):e.visitChildren(this)}}I.CaseWhenContext=lD;class VM extends ge.ParserRuleContext{id(){return this.getRuleContext(0,Nn)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_recordKey}enterRule(e){e.enterRecordKey&&e.enterRecordKey(this)}exitRule(e){e.exitRecordKey&&e.exitRecordKey(this)}accept(e){return e.visitRecordKey?e.visitRecordKey(this):e.visitChildren(this)}}I.RecordKeyContext=VM;class t1 extends ge.ParserRuleContext{constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_recordElement}copyFrom(e){super.copyFrom(e)}}I.RecordElementContext=t1;class Dxe extends t1{fieldPath(){return this.getRuleContext(0,Ga)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterRecordRef&&e.enterRecordRef(this)}exitRule(e){e.exitRecordRef&&e.exitRecordRef(this)}accept(e){return e.visitRecordRef?e.visitRecordRef(this):e.visitChildren(this)}}I.RecordRefContext=Dxe;class Oxe extends t1{fieldExpr(){return this.getRuleContext(0,Re)}recordKey(){return this.tryGetRuleContext(0,VM)}IS(){return this.tryGetToken(d.IS,0)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterRecordExpr&&e.enterRecordExpr(this)}exitRule(e){e.exitRecordExpr&&e.exitRecordExpr(this)}accept(e){return e.visitRecordExpr?e.visitRecordExpr(this):e.visitChildren(this)}}I.RecordExprContext=Oxe;class cD extends ge.ParserRuleContext{fieldExpr(e){return e===void 0?this.getRuleContexts(Re):this.getRuleContext(e,Re)}COMMA(e){return e===void 0?this.getTokens(d.COMMA):this.getToken(d.COMMA,e)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_argumentList}enterRule(e){e.enterArgumentList&&e.enterArgumentList(this)}exitRule(e){e.exitArgumentList&&e.exitArgumentList(this)}accept(e){return e.visitArgumentList?e.visitArgumentList(this):e.visitChildren(this)}}I.ArgumentListContext=cD;class n1 extends ge.ParserRuleContext{fieldName(e){return e===void 0?this.getRuleContexts(Gr):this.getRuleContext(e,Gr)}COMMA(e){return e===void 0?this.getTokens(d.COMMA):this.getToken(d.COMMA,e)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_fieldNameList}enterRule(e){e.enterFieldNameList&&e.enterFieldNameList(this)}exitRule(e){e.exitFieldNameList&&e.exitFieldNameList(this)}accept(e){return e.visitFieldNameList?e.visitFieldNameList(this):e.visitChildren(this)}}I.FieldNameListContext=n1;class YM extends ge.ParserRuleContext{collectionMember(e){return e===void 0?this.getRuleContexts(dD):this.getRuleContext(e,dD)}COMMA(e){return e===void 0?this.getTokens(d.COMMA):this.getToken(d.COMMA,e)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_fieldCollection}enterRule(e){e.enterFieldCollection&&e.enterFieldCollection(this)}exitRule(e){e.exitFieldCollection&&e.exitFieldCollection(this)}accept(e){return e.visitFieldCollection?e.visitFieldCollection(this):e.visitChildren(this)}}I.FieldCollectionContext=YM;class GE extends ge.ParserRuleContext{STAR(){return this.getToken(d.STAR,0)}fieldPath(){return this.tryGetRuleContext(0,Ga)}DOT(){return this.tryGetToken(d.DOT,0)}starQualified(){return this.tryGetRuleContext(0,fD)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_collectionWildCard}enterRule(e){e.enterCollectionWildCard&&e.enterCollectionWildCard(this)}exitRule(e){e.exitCollectionWildCard&&e.exitCollectionWildCard(this)}accept(e){return e.visitCollectionWildCard?e.visitCollectionWildCard(this):e.visitChildren(this)}}I.CollectionWildCardContext=GE;class fD extends ge.ParserRuleContext{OCURLY(){return this.getToken(d.OCURLY,0)}CCURLY(){return this.getToken(d.CCURLY,0)}COMMA(e){return e===void 0?this.getTokens(d.COMMA):this.getToken(d.COMMA,e)}EXCEPT(e){return e===void 0?this.getTokens(d.EXCEPT):this.getToken(d.EXCEPT,e)}fieldNameList(e){return e===void 0?this.getRuleContexts(n1):this.getRuleContext(e,n1)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_starQualified}enterRule(e){e.enterStarQualified&&e.enterStarQualified(this)}exitRule(e){e.exitStarQualified&&e.exitStarQualified(this)}accept(e){return e.visitStarQualified?e.visitStarQualified(this):e.visitChildren(this)}}I.StarQualifiedContext=fD;class xD extends ge.ParserRuleContext{tags(){return this.getRuleContext(0,Xt)}fieldPath(){return this.getRuleContext(0,Ga)}refExpr(){return this.tryGetRuleContext(0,KM)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_taggedRef}enterRule(e){e.enterTaggedRef&&e.enterTaggedRef(this)}exitRule(e){e.exitTaggedRef&&e.exitTaggedRef(this)}accept(e){return e.visitTaggedRef?e.visitTaggedRef(this):e.visitChildren(this)}}I.TaggedRefContext=xD;class KM extends ge.ParserRuleContext{DOT(){return this.getToken(d.DOT,0)}timeframe(){return this.tryGetRuleContext(0,Ld)}aggregate(){return this.tryGetRuleContext(0,zE)}OPAREN(){return this.tryGetToken(d.OPAREN,0)}CPAREN(){return this.tryGetToken(d.CPAREN,0)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_refExpr}enterRule(e){e.enterRefExpr&&e.enterRefExpr(this)}exitRule(e){e.exitRefExpr&&e.exitRefExpr(this)}accept(e){return e.visitRefExpr?e.visitRefExpr(this):e.visitChildren(this)}}I.RefExprContext=KM;class dD extends ge.ParserRuleContext{taggedRef(){return this.tryGetRuleContext(0,xD)}collectionWildCard(){return this.tryGetRuleContext(0,GE)}fieldDef(){return this.tryGetRuleContext(0,Z2)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_collectionMember}enterRule(e){e.enterCollectionMember&&e.enterCollectionMember(this)}exitRule(e){e.exitCollectionMember&&e.exitCollectionMember(this)}accept(e){return e.visitCollectionMember?e.visitCollectionMember(this):e.visitChildren(this)}}I.CollectionMemberContext=dD;class Ga extends ge.ParserRuleContext{fieldName(e){return e===void 0?this.getRuleContexts(Gr):this.getRuleContext(e,Gr)}DOT(e){return e===void 0?this.getTokens(d.DOT):this.getToken(d.DOT,e)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_fieldPath}enterRule(e){e.enterFieldPath&&e.enterFieldPath(this)}exitRule(e){e.exitFieldPath&&e.exitFieldPath(this)}accept(e){return e.visitFieldPath?e.visitFieldPath(this):e.visitChildren(this)}}I.FieldPathContext=Ga;class Fxe extends ge.ParserRuleContext{id(){return this.getRuleContext(0,Nn)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_joinName}enterRule(e){e.enterJoinName&&e.enterJoinName(this)}exitRule(e){e.exitJoinName&&e.exitJoinName(this)}accept(e){return e.visitJoinName?e.visitJoinName(this):e.visitChildren(this)}}I.JoinNameContext=Fxe;class Gr extends ge.ParserRuleContext{id(){return this.getRuleContext(0,Nn)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_fieldName}enterRule(e){e.enterFieldName&&e.enterFieldName(this)}exitRule(e){e.exitFieldName&&e.exitFieldName(this)}accept(e){return e.visitFieldName?e.visitFieldName(this):e.visitChildren(this)}}I.FieldNameContext=Gr;class wxe extends ge.ParserRuleContext{id(){return this.getRuleContext(0,Nn)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_sqlExploreNameRef}enterRule(e){e.enterSqlExploreNameRef&&e.enterSqlExploreNameRef(this)}exitRule(e){e.exitSqlExploreNameRef&&e.exitSqlExploreNameRef(this)}accept(e){return e.visitSqlExploreNameRef?e.visitSqlExploreNameRef(this):e.visitChildren(this)}}I.SqlExploreNameRefContext=wxe;class Nxe extends ge.ParserRuleContext{id(){return this.getRuleContext(0,Nn)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_nameSQLBlock}enterRule(e){e.enterNameSQLBlock&&e.enterNameSQLBlock(this)}exitRule(e){e.exitNameSQLBlock&&e.exitNameSQLBlock(this)}accept(e){return e.visitNameSQLBlock?e.visitNameSQLBlock(this):e.visitChildren(this)}}I.NameSQLBlockContext=Nxe;class Lxe extends ge.ParserRuleContext{string(){return this.getRuleContext(0,za)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_connectionName}enterRule(e){e.enterConnectionName&&e.enterConnectionName(this)}exitRule(e){e.exitConnectionName&&e.exitConnectionName(this)}accept(e){return e.visitConnectionName?e.visitConnectionName(this):e.visitChildren(this)}}I.ConnectionNameContext=Lxe;class JM extends ge.ParserRuleContext{SQ3_FILTER(){return this.tryGetToken(d.SQ3_FILTER,0)}BQ3_FILTER(){return this.tryGetToken(d.BQ3_FILTER,0)}DQ3_FILTER(){return this.tryGetToken(d.DQ3_FILTER,0)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_tripFilterString}enterRule(e){e.enterTripFilterString&&e.enterTripFilterString(this)}exitRule(e){e.exitTripFilterString&&e.exitTripFilterString(this)}accept(e){return e.visitTripFilterString?e.visitTripFilterString(this):e.visitChildren(this)}}I.TripFilterStringContext=JM;class XM extends ge.ParserRuleContext{SQ_FILTER(){return this.tryGetToken(d.SQ_FILTER,0)}BQ_FILTER(){return this.tryGetToken(d.BQ_FILTER,0)}DQ_FILTER(){return this.tryGetToken(d.DQ_FILTER,0)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_tickFilterString}enterRule(e){e.enterTickFilterString&&e.enterTickFilterString(this)}exitRule(e){e.exitTickFilterString&&e.exitTickFilterString(this)}accept(e){return e.visitTickFilterString?e.visitTickFilterString(this):e.visitChildren(this)}}I.TickFilterStringContext=XM;class ZM extends ge.ParserRuleContext{tripFilterString(){return this.tryGetRuleContext(0,JM)}tickFilterString(){return this.tryGetRuleContext(0,XM)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_filterString}enterRule(e){e.enterFilterString&&e.enterFilterString(this)}exitRule(e){e.exitFilterString&&e.exitFilterString(this)}accept(e){return e.visitFilterString?e.visitFilterString(this):e.visitChildren(this)}}I.FilterStringContext=ZM;class Ixe extends ge.ParserRuleContext{fieldExpr(){return this.getRuleContext(0,Re)}EOF(){return this.getToken(d.EOF,0)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_debugExpr}enterRule(e){e.enterDebugExpr&&e.enterDebugExpr(this)}exitRule(e){e.exitDebugExpr&&e.exitDebugExpr(this)}accept(e){return e.visitDebugExpr?e.visitDebugExpr(this):e.visitChildren(this)}}I.DebugExprContext=Ixe;class $xe extends ge.ParserRuleContext{partialAllowedFieldExpr(){return this.getRuleContext(0,Id)}EOF(){return this.getToken(d.EOF,0)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_debugPartial}enterRule(e){e.enterDebugPartial&&e.enterDebugPartial(this)}exitRule(e){e.exitDebugPartial&&e.exitDebugPartial(this)}accept(e){return e.visitDebugPartial?e.visitDebugPartial(this):e.visitChildren(this)}}I.DebugPartialContext=$xe;class eP extends ge.ParserRuleContext{SEMI(e){return e===void 0?this.getTokens(d.SEMI):this.getToken(d.SEMI,e)}OBRACK(){return this.getToken(d.OBRACK,0)}string(){return this.getRuleContext(0,za)}CBRACK(){return this.getToken(d.CBRACK,0)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_experimentalStatementForTesting}enterRule(e){e.enterExperimentalStatementForTesting&&e.enterExperimentalStatementForTesting(this)}exitRule(e){e.exitExperimentalStatementForTesting&&e.exitExperimentalStatementForTesting(this)}accept(e){return e.visitExperimentalStatementForTesting?e.visitExperimentalStatementForTesting(this):e.visitChildren(this)}}I.ExperimentalStatementForTestingContext=eP;var hD={};Object.defineProperty(hD,"__esModule",{value:!0}),hD.MalloyErrorStrategy=void 0;const nht=ng;class rht extends nht.DefaultErrorStrategy{}hD.MalloyErrorStrategy=rht;var Bxe={},pD={},kxe={exports:{}};(function(t,e){(function(r){function i(o,u){for(var a in u)u.hasOwnProperty(a)&&(o[a]=u[a]);return o}function s(o,u,a){var l=0,c={caseSensitive:!0},f=i(c,a),x,h;if(o.length===0||u.length===0)return 0;if(f.caseSensitive||(o=o.toUpperCase(),u=u.toUpperCase()),o===u)return 1;var p=Math.floor(Math.max(o.length,u.length)/2)-1,m=new Array(o.length),g=new Array(u.length);for(x=0;x<o.length;x++){var y=x>=p?x-p:0,E=x+p<=u.length-1?x+p:u.length-1;for(h=y;h<=E;h++)if(m[x]!==!0&&g[h]!==!0&&o[x]===u[h]){++l,m[x]=g[h]=!0;break}}if(l===0)return 0;var A=0,_=0;for(x=0;x<o.length;x++)if(m[x]===!0){for(h=A;h<u.length;h++)if(g[h]===!0){A=h+1;break}o[x]!==u[h]&&++_}var v=(l/o.length+l/u.length+(l-_/2)/l)/3,C=0,S=.1;if(v>.7){for(;o[C]===u[C]&&C<4;)++C;v=v+C*S*(1-v)}return v}t.exports=s})()})(kxe);var iht=kxe.exports,sht=T&&T.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(pD,"__esModule",{value:!0}),pD.checkCustomErrorMessage=void 0;const Mxe=sht(iht),oht=(t,e,r)=>{var i,s;const o=t.getRuleInvocationStack()[0],u=t.currentToken;for(const a of r){const l=!a.currentToken||u.type===a.currentToken,c=!a.offendingSymbol||(e==null?void 0:e.type)===a.offendingSymbol,f=!a.ruleContextOptions||a.ruleContextOptions.includes(o),x=!a.offendingSymbolTextOptions||a.offendingSymbolTextOptions.includes(((i=e==null?void 0:e.text)===null||i===void 0?void 0:i.toLowerCase())||"");if(l&&c&&f&&x){if(a.lookbackSiblingRuleOptions){const m=t.ruleContext.children;if(!m)continue;const g=m[m.length-1];if(!a.lookbackSiblingRuleOptions.includes(g.ruleIndex))continue}if(a.precedingTokenOptions&&!a.precedingTokenOptions.some(g=>Uxe(t,g,"lookback",e==null?void 0:e.tokenIndex))||a.lookAheadOptions&&!a.lookAheadOptions.some(g=>Uxe(t,g,"lookahead",e==null?void 0:e.tokenIndex)))continue;if(a.predecessorHasAncestorRule){const m=(s=t.ruleContext.children)===null||s===void 0?void 0:s[0];if(!m||!Pxe(m,a.predecessorHasAncestorRule))continue}const h=m=>{const g=m.replace("${currentToken}",u.text||"").replace("${offendingSymbol}",(e==null?void 0:e.text)||"");try{const y=t.inputStream.LT(-1);return g.replace("${previousToken}",y.text||"")}catch{}return g};let p=h(a.errorMessage);if(a.alternatives){const m=h(a.alternatives.replace);let g=a.alternatives.with[0],y=(0,Mxe.default)(g,m);for(const E of a.alternatives.with.slice(1)){const A=(0,Mxe.default)(E,m);A>y&&(y=A,g=E)}p+=` Did you mean '${g}'?`}return p}}return""};pD.checkCustomErrorMessage=oht;const Pxe=(t,e,r=20)=>{var i;if(t.ruleIndex===e)return!0;if(r<=0)return!1;const s=((i=t.children)===null||i===void 0?void 0:i.length)||0;if(t.children&&s>0){const o=t.children[t.children.length-1];return Pxe(o,e,r-1)}return!1},Uxe=(t,e,r,i)=>{var s;try{for(let o=0;o<e.length;o++){let u;if(typeof i=="number"){const a=r==="lookahead"?o+1:-1*(o+1);u=t.inputStream.get(i+a)}else{const a=r==="lookahead"?o+2:-1*(o+1);u=t.inputStream.LT(a)}if(typeof e[o]=="number"){const a=e[o];if(a>=-1&&u.type!==a||a<-1&&u.type===-1*a)return!1}else if(typeof e[o]=="string"&&e[o]!==((s=u.text)===null||s===void 0?void 0:s.toLowerCase()))return!1}return!0}catch{return!1}};(function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.MalloyParserErrorListener=t.malloyCustomErrorCases=void 0;const e=I,r=pD,i=T2,s=Jn;t.malloyCustomErrorCases=[{errorMessage:"'view:' must be followed by '<identifier> is {'",ruleContextOptions:["exploreQueryDef"],offendingSymbol:e.MalloyParser.OCURLY,precedingTokenOptions:[[e.MalloyParser.VIEW],[e.MalloyParser.COLON]]},{errorMessage:"Missing '}' at '${offendingSymbol}'",ruleContextOptions:["vExpr"],offendingSymbol:e.MalloyParser.VIEW,currentToken:e.MalloyParser.OCURLY},{errorMessage:"Missing '}' at '${currentToken}'",ruleContextOptions:["exploreProperties","queryProperties","exploreStatement"],offendingSymbolTextOptions:["<eof>","run:","source:"]},{errorMessage:"'aggregate:' entries must include a name (ex: `some_name is count()`)",precedingTokenOptions:[[e.MalloyParser.AGGREGATE]],lookAheadOptions:[[-e.MalloyParser.IS]]},{errorMessage:"Expected ':' following 'source'",offendingSymbol:e.MalloyParser.SOURCE_KW,ruleContextOptions:["malloyDocument"]},{errorMessage:"Expected ':' following '${offendingSymbol}'",offendingSymbolTextOptions:["dimension","measure","where","declare","join_one","join_many","join_cross","primary_key"],ruleContextOptions:["exploreStatement"]},{errorMessage:"Expected 'is' or '(' following identifier '${previousToken}'",ruleContextOptions:["sourceDefinition"],lookbackSiblingRuleOptions:[e.MalloyParser.RULE_sourceNameDef,e.MalloyParser.RULE_sourceParameters]},{errorMessage:"Unexpected '{' following source expression. Expected: 'extend', 'include', '+' or '->'",offendingSymbol:e.MalloyParser.OCURLY,ruleContextOptions:["malloyDocument"],predecessorHasAncestorRule:e.MalloyParser.RULE_sqExplore},{errorMessage:"Unexpected 'join:'. Did you mean 'join_one:', 'join_many:' or 'join_cross:'?",ruleContextOptions:["exploreStatement"],offendingSymbolTextOptions:["join"],lookAheadOptions:[[e.MalloyParser.COLON]]},{errorMessage:"Unexpected '${offendingSymbol}'. Did you mean 'primary_key:'?",ruleContextOptions:["exploreStatement"],offendingSymbolTextOptions:["primarykey","primary"],lookAheadOptions:[[e.MalloyParser.COLON],["key",e.MalloyParser.COLON],["key",e.MalloyParser.IDENTIFIER]]},{errorMessage:"Unexpected '${offendingSymbol}'. Did you mean 'group_by:'?",ruleContextOptions:["queryStatement"],offendingSymbolTextOptions:["groupby","group"],lookAheadOptions:[[e.MalloyParser.COLON],["by",e.MalloyParser.COLON],["by",e.MalloyParser.IDENTIFIER]]},{errorMessage:"Unexpected '${offendingSymbol}'. Did you mean 'order_by:'?",ruleContextOptions:["queryStatement"],offendingSymbolTextOptions:["orderby","order"],lookAheadOptions:[[e.MalloyParser.COLON],["by",e.MalloyParser.COLON],["by",e.MalloyParser.IDENTIFIER]]},{errorMessage:"Expected ':' following '${offendingSymbol}'",offendingSymbolTextOptions:["group_by","declare","join_one","join_many","join_cross","extend","select","project","index","aggregate","calculate","top","limit","order_by","where","having","nest","sample","timezone"],ruleContextOptions:["queryStatement"]},{errorMessage:"Expected a query statement, '${offendingSymbol}:' is not a keyword.",ruleContextOptions:["queryStatement"],offendingSymbol:e.MalloyParser.IDENTIFIER,lookAheadOptions:[[e.MalloyParser.COLON,e.MalloyParser.IDENTIFIER]],alternatives:{replace:"${offendingSymbol}:",with:["group_by:","select:","aggregate:","calculate:","nest:"]}},{errorMessage:"Expected a source statement, '${offendingSymbol}:' is not a keyword.",ruleContextOptions:["exploreStatement"],offendingSymbol:e.MalloyParser.IDENTIFIER,lookAheadOptions:[[e.MalloyParser.COLON,e.MalloyParser.IDENTIFIER]],alternatives:{replace:"${offendingSymbol}:",with:["dimension:","measure:","primary_key:","view:","join:"]}},{errorMessage:"Expected a statement, '${offendingSymbol}:' is not a keyword.",ruleContextOptions:["malloyDocument"],offendingSymbol:e.MalloyParser.IDENTIFIER,lookAheadOptions:[[e.MalloyParser.COLON,e.MalloyParser.IDENTIFIER]],alternatives:{replace:"${offendingSymbol}:",with:["run:","query:","source:"]}}];class o{constructor(a,l,c){this.messages=a,this.sourceURL=l,this.sourceInfo=c}logError(a,l,c){return this.messages.log((0,i.makeLogMessage)(a,l,{severity:"error",...c})),a}syntaxError(a,l,c,f,x,h){const p={line:c-1,character:f},m=l?(0,s.rangeFromToken)(this.sourceInfo,l):{start:p,end:p},g=(0,r.checkCustomErrorMessage)(a,l,t.malloyCustomErrorCases);g&&(x=g),this.logError("syntax-error",{message:x},{at:{url:this.sourceURL,range:m}})}}t.MalloyParserErrorListener=o})(Bxe),Object.defineProperty(UE,"__esModule",{value:!0}),UE.runMalloyParser=void 0;const jxe=ng,uht=vR,aht=I,lht=hD,cht=Bxe;class fht extends uht.MalloyLexer{popMode(){return this._modeStack.isEmpty?this._mode:super.popMode()}}function xht(t,e,r,i,s="malloyDocument"){const o=jxe.CharStreams.fromString(t),u=new fht(o),a=new jxe.CommonTokenStream(u),l=new aht.MalloyParser(a);l.removeErrorListeners(),l.addErrorListener(new cht.MalloyParserErrorListener(i,e,r)),l.errorHandler=new lht.MalloyErrorStrategy;const c=l[s];if(!c)throw new Error(`No such parse rule as ${s}`);return{root:c.call(l),tokenStream:a,sourceStream:o,sourceInfo:r,sourceURL:e,malloyVersion:"4.0.0"}}UE.runMalloyParser=xht;var dht=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),hht=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),pht=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&dht(e,t,r);return hht(e,t),e};Object.defineProperty(Wc,"__esModule",{value:!0}),Wc.MalloyTranslator=Wc.MalloyChildTranslator=Wc.MalloyTranslation=void 0;const mht=et,qxe=pht(P4),ght=xR,Hxe=T2,yht=_0,tP=hR,Eht=pR,Aht=mR,_ht=gR,vht=yR,mD=ER,nP=Jn,Cht=$o,Sht=AR,bht=_R,Tht=mi,Rht=UE;class Dht{step(e){if(this.response)return this.response;if(!e.urlIsFullPath)return e.fatalResponse();const r=e.root.importZone.getEntry(e.sourceURL);if(r.status!=="present"){if(r.status==="error"){const o=r.firstReference||e.defaultLocation();return e.root.logError("import-error",{message:r.message,url:e.sourceURL},{at:o}),this.response=e.fatalResponse(),this.response}return{urls:[e.sourceURL]}}const i=r.value===""?`
|
|
1857
|
-
`:r.value;this.sourceInfo=(0,nP.getSourceInfo)(i);let s;try{s=this.runParser(i,this.sourceInfo,e)}catch(o){e.root.logError("parse-exception",{message:o.message}),s=void 0}return e.root.logger.hasErrors()?this.response={parse:s,...e.fatalResponse()}:this.response={parse:s},this.response}runParser(e,r,i){return{...(0,
|
|
1856
|
+
םנĔמנ\x07ןלןמנססןסעעףףפ\x07פěץצ\f\x07צרĢקשĞרקרששĝת\x07ײö|\x07Þpׯ\x07|ׯװ\x07}װײױתױײğ׳Ĝ״ĘX-׳״ġĦ\x07Ħģô{ĥô{ħô{ĩ؆؇ô{؇ī؈؉äs؉ĭ؊؋ ؋į،؍ ؍ı؎ؑĮ؏ؑİؐ؎ؐ؏ؑijؒؓüؓؔ\x07ؔĵؕؖĂؖؗ\x07ؗķؘؙ\x07ؙؚ\x07ؚ؛\x07~؛äs؝\x07؝Ĺ®ļľŊŘŧŲżƅƌƑƖƜơƥƶdžLjǑǖǚǟǮdzǻȀȄȍȏțȣȬȯȶȸȼɃɊɏɓɛɠɤɱɷɾʅʊʒʜʡʨʯʼʿ˄ˏ˖˘˞ˠ˯˷˼̵̛̥̮͇͉͕͙̀̈̌̑̽͂͐ͩͮ̕ͳͻ΄ΆΌΑΓΝΡΥΩδλοωώϒϙϲϼЁЅЉБЖКРжксцъюёњѢѥѩѮѵ҉ҚңұҼӀӊӜӡӪӷӾԀԃԇԔԙԪՒագլկշվքֈֵׇֹֽׂ֮֓֘֜֫אויןסרױؐ`,d._serializedATN=Wce.join([d._serializedATNSegment0,d._serializedATNSegment1,d._serializedATNSegment2],"");class Gce extends ge.ParserRuleContext{EOF(){return this.getToken(d.EOF,0)}malloyStatement(e){return e===void 0?this.getRuleContexts(CR):this.getRuleContext(e,CR)}SEMI(e){return e===void 0?this.getTokens(d.SEMI):this.getToken(d.SEMI,e)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_malloyDocument}enterRule(e){e.enterMalloyDocument&&e.enterMalloyDocument(this)}exitRule(e){e.exitMalloyDocument&&e.exitMalloyDocument(this)}accept(e){return e.visitMalloyDocument?e.visitMalloyDocument(this):e.visitChildren(this)}}I.MalloyDocumentContext=Gce;class CR extends ge.ParserRuleContext{defineSourceStatement(){return this.tryGetRuleContext(0,Pk)}defineQuery(){return this.tryGetRuleContext(0,SR)}importStatement(){return this.tryGetRuleContext(0,qk)}runStatement(){return this.tryGetRuleContext(0,jk)}docAnnotations(){return this.tryGetRuleContext(0,zk)}ignoredObjectAnnotations(){return this.tryGetRuleContext(0,Wk)}experimentalStatementForTesting(){return this.tryGetRuleContext(0,eP)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_malloyStatement}enterRule(e){e.enterMalloyStatement&&e.enterMalloyStatement(this)}exitRule(e){e.exitMalloyStatement&&e.exitMalloyStatement(this)}accept(e){return e.visitMalloyStatement?e.visitMalloyStatement(this):e.visitChildren(this)}}I.MalloyStatementContext=CR;class Pk extends ge.ParserRuleContext{tags(){return this.getRuleContext(0,Xt)}SOURCE(){return this.getToken(d.SOURCE,0)}sourcePropertyList(){return this.getRuleContext(0,Jk)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_defineSourceStatement}enterRule(e){e.enterDefineSourceStatement&&e.enterDefineSourceStatement(this)}exitRule(e){e.exitDefineSourceStatement&&e.exitDefineSourceStatement(this)}accept(e){return e.visitDefineSourceStatement?e.visitDefineSourceStatement(this):e.visitChildren(this)}}I.DefineSourceStatementContext=Pk;class SR extends ge.ParserRuleContext{constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_defineQuery}copyFrom(e){super.copyFrom(e)}}I.DefineQueryContext=SR;class Vce extends SR{topLevelQueryDefs(){return this.getRuleContext(0,Gk)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterUse_top_level_query_defs&&e.enterUse_top_level_query_defs(this)}exitRule(e){e.exitUse_top_level_query_defs&&e.exitUse_top_level_query_defs(this)}accept(e){return e.visitUse_top_level_query_defs?e.visitUse_top_level_query_defs(this):e.visitChildren(this)}}I.Use_top_level_query_defsContext=Vce;class Uk extends ge.ParserRuleContext{tags(){return this.getRuleContext(0,Xt)}sqExpr(){return this.getRuleContext(0,cn)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_topLevelAnonQueryDef}enterRule(e){e.enterTopLevelAnonQueryDef&&e.enterTopLevelAnonQueryDef(this)}exitRule(e){e.exitTopLevelAnonQueryDef&&e.exitTopLevelAnonQueryDef(this)}accept(e){return e.visitTopLevelAnonQueryDef?e.visitTopLevelAnonQueryDef(this):e.visitChildren(this)}}I.TopLevelAnonQueryDefContext=Uk;class Xt extends ge.ParserRuleContext{ANNOTATION(e){return e===void 0?this.getTokens(d.ANNOTATION):this.getToken(d.ANNOTATION,e)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_tags}enterRule(e){e.enterTags&&e.enterTags(this)}exitRule(e){e.exitTags&&e.exitTags(this)}accept(e){return e.visitTags?e.visitTags(this):e.visitChildren(this)}}I.TagsContext=Xt;class v0 extends ge.ParserRuleContext{IS(){return this.getToken(d.IS,0)}tags(e){return e===void 0?this.getRuleContexts(Xt):this.getRuleContext(e,Xt)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_isDefine}enterRule(e){e.enterIsDefine&&e.enterIsDefine(this)}exitRule(e){e.exitIsDefine&&e.exitIsDefine(this)}accept(e){return e.visitIsDefine?e.visitIsDefine(this):e.visitChildren(this)}}I.IsDefineContext=v0;class jk extends ge.ParserRuleContext{tags(){return this.getRuleContext(0,Xt)}RUN(){return this.getToken(d.RUN,0)}topLevelAnonQueryDef(){return this.getRuleContext(0,Uk)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_runStatement}enterRule(e){e.enterRunStatement&&e.enterRunStatement(this)}exitRule(e){e.exitRunStatement&&e.exitRunStatement(this)}accept(e){return e.visitRunStatement?e.visitRunStatement(this):e.visitChildren(this)}}I.RunStatementContext=jk;class bR extends ge.ParserRuleContext{SQL_BEGIN(){return this.getToken(d.SQL_BEGIN,0)}SQL_END(){return this.getToken(d.SQL_END,0)}sqlInterpolation(e){return e===void 0?this.getRuleContexts(TR):this.getRuleContext(e,TR)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_sqlString}enterRule(e){e.enterSqlString&&e.enterSqlString(this)}exitRule(e){e.exitSqlString&&e.exitSqlString(this)}accept(e){return e.visitSqlString?e.visitSqlString(this):e.visitChildren(this)}}I.SqlStringContext=bR;class TR extends ge.ParserRuleContext{OPEN_CODE(){return this.getToken(d.OPEN_CODE,0)}sqExpr(){return this.getRuleContext(0,cn)}CCURLY(){return this.getToken(d.CCURLY,0)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_sqlInterpolation}enterRule(e){e.enterSqlInterpolation&&e.enterSqlInterpolation(this)}exitRule(e){e.exitSqlInterpolation&&e.exitSqlInterpolation(this)}accept(e){return e.visitSqlInterpolation?e.visitSqlInterpolation(this):e.visitChildren(this)}}I.SqlInterpolationContext=TR;class qk extends ge.ParserRuleContext{IMPORT(){return this.getToken(d.IMPORT,0)}importURL(){return this.getRuleContext(0,Qk)}importSelect(){return this.tryGetRuleContext(0,Hk)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_importStatement}enterRule(e){e.enterImportStatement&&e.enterImportStatement(this)}exitRule(e){e.exitImportStatement&&e.exitImportStatement(this)}accept(e){return e.visitImportStatement?e.visitImportStatement(this):e.visitChildren(this)}}I.ImportStatementContext=qk;class Hk extends ge.ParserRuleContext{OCURLY(){return this.getToken(d.OCURLY,0)}importItem(e){return e===void 0?this.getRuleContexts(RR):this.getRuleContext(e,RR)}CCURLY(){return this.getToken(d.CCURLY,0)}FROM(){return this.getToken(d.FROM,0)}COMMA(e){return e===void 0?this.getTokens(d.COMMA):this.getToken(d.COMMA,e)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_importSelect}enterRule(e){e.enterImportSelect&&e.enterImportSelect(this)}exitRule(e){e.exitImportSelect&&e.exitImportSelect(this)}accept(e){return e.visitImportSelect?e.visitImportSelect(this):e.visitChildren(this)}}I.ImportSelectContext=Hk;class RR extends ge.ParserRuleContext{id(e){return e===void 0?this.getRuleContexts(Nn):this.getRuleContext(e,Nn)}IS(){return this.tryGetToken(d.IS,0)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_importItem}enterRule(e){e.enterImportItem&&e.enterImportItem(this)}exitRule(e){e.exitImportItem&&e.exitImportItem(this)}accept(e){return e.visitImportItem?e.visitImportItem(this):e.visitChildren(this)}}I.ImportItemContext=RR;class Qk extends ge.ParserRuleContext{string(){return this.getRuleContext(0,za)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_importURL}enterRule(e){e.enterImportURL&&e.enterImportURL(this)}exitRule(e){e.exitImportURL&&e.exitImportURL(this)}accept(e){return e.visitImportURL?e.visitImportURL(this):e.visitChildren(this)}}I.ImportURLContext=Qk;class zk extends ge.ParserRuleContext{DOC_ANNOTATION(e){return e===void 0?this.getTokens(d.DOC_ANNOTATION):this.getToken(d.DOC_ANNOTATION,e)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_docAnnotations}enterRule(e){e.enterDocAnnotations&&e.enterDocAnnotations(this)}exitRule(e){e.exitDocAnnotations&&e.exitDocAnnotations(this)}accept(e){return e.visitDocAnnotations?e.visitDocAnnotations(this):e.visitChildren(this)}}I.DocAnnotationsContext=zk;class Wk extends ge.ParserRuleContext{ANNOTATION(e){return e===void 0?this.getTokens(d.ANNOTATION):this.getToken(d.ANNOTATION,e)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_ignoredObjectAnnotations}enterRule(e){e.enterIgnoredObjectAnnotations&&e.enterIgnoredObjectAnnotations(this)}exitRule(e){e.exitIgnoredObjectAnnotations&&e.exitIgnoredObjectAnnotations(this)}accept(e){return e.visitIgnoredObjectAnnotations?e.visitIgnoredObjectAnnotations(this):e.visitChildren(this)}}I.IgnoredObjectAnnotationsContext=Wk;class DR extends ge.ParserRuleContext{DOC_ANNOTATION(e){return e===void 0?this.getTokens(d.DOC_ANNOTATION):this.getToken(d.DOC_ANNOTATION,e)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_ignoredModelAnnotations}enterRule(e){e.enterIgnoredModelAnnotations&&e.enterIgnoredModelAnnotations(this)}exitRule(e){e.exitIgnoredModelAnnotations&&e.exitIgnoredModelAnnotations(this)}accept(e){return e.visitIgnoredModelAnnotations?e.visitIgnoredModelAnnotations(this):e.visitChildren(this)}}I.IgnoredModelAnnotationsContext=DR;class Gk extends ge.ParserRuleContext{tags(){return this.getRuleContext(0,Xt)}QUERY(){return this.getToken(d.QUERY,0)}topLevelQueryDef(e){return e===void 0?this.getRuleContexts(FR):this.getRuleContext(e,FR)}COMMA(e){return e===void 0?this.getTokens(d.COMMA):this.getToken(d.COMMA,e)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_topLevelQueryDefs}enterRule(e){e.enterTopLevelQueryDefs&&e.enterTopLevelQueryDefs(this)}exitRule(e){e.exitTopLevelQueryDefs&&e.exitTopLevelQueryDefs(this)}accept(e){return e.visitTopLevelQueryDefs?e.visitTopLevelQueryDefs(this):e.visitChildren(this)}}I.TopLevelQueryDefsContext=Gk;class FR extends ge.ParserRuleContext{tags(){return this.getRuleContext(0,Xt)}queryName(){return this.getRuleContext(0,NR)}isDefine(){return this.getRuleContext(0,v0)}sqExpr(){return this.getRuleContext(0,cn)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_topLevelQueryDef}enterRule(e){e.enterTopLevelQueryDef&&e.enterTopLevelQueryDef(this)}exitRule(e){e.exitTopLevelQueryDef&&e.exitTopLevelQueryDef(this)}accept(e){return e.visitTopLevelQueryDef?e.visitTopLevelQueryDef(this):e.visitChildren(this)}}I.TopLevelQueryDefContext=FR;class Yce extends ge.ParserRuleContext{PLUS(){return this.getToken(d.PLUS,0)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_refineOperator}enterRule(e){e.enterRefineOperator&&e.enterRefineOperator(this)}exitRule(e){e.exitRefineOperator&&e.exitRefineOperator(this)}accept(e){return e.visitRefineOperator?e.visitRefineOperator(this):e.visitChildren(this)}}I.RefineOperatorContext=Yce;class Kce extends ge.ParserRuleContext{id(){return this.getRuleContext(0,Nn)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_turtleName}enterRule(e){e.enterTurtleName&&e.enterTurtleName(this)}exitRule(e){e.exitTurtleName&&e.exitTurtleName(this)}accept(e){return e.visitTurtleName?e.visitTurtleName(this):e.visitChildren(this)}}I.TurtleNameContext=Kce;class Vk extends ge.ParserRuleContext{connectionId(){return this.getRuleContext(0,wR)}DOT(){return this.getToken(d.DOT,0)}SQL(){return this.getToken(d.SQL,0)}OPAREN(){return this.getToken(d.OPAREN,0)}CPAREN(){return this.getToken(d.CPAREN,0)}sqlString(){return this.tryGetRuleContext(0,bR)}shortString(){return this.tryGetRuleContext(0,oD)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_sqlSource}enterRule(e){e.enterSqlSource&&e.enterSqlSource(this)}exitRule(e){e.exitSqlSource&&e.exitSqlSource(this)}accept(e){return e.visitSqlSource?e.visitSqlSource(this):e.visitChildren(this)}}I.SqlSourceContext=Vk;class Yk extends ge.ParserRuleContext{connectionId(){return this.getRuleContext(0,wR)}DOT(){return this.getToken(d.DOT,0)}TABLE(){return this.getToken(d.TABLE,0)}OPAREN(){return this.getToken(d.OPAREN,0)}tablePath(){return this.getRuleContext(0,UM)}CPAREN(){return this.getToken(d.CPAREN,0)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_exploreTable}enterRule(e){e.enterExploreTable&&e.enterExploreTable(this)}exitRule(e){e.exitExploreTable&&e.exitExploreTable(this)}accept(e){return e.visitExploreTable?e.visitExploreTable(this):e.visitChildren(this)}}I.ExploreTableContext=Yk;class wR extends ge.ParserRuleContext{id(){return this.getRuleContext(0,Nn)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_connectionId}enterRule(e){e.enterConnectionId&&e.enterConnectionId(this)}exitRule(e){e.exitConnectionId&&e.exitConnectionId(this)}accept(e){return e.visitConnectionId?e.visitConnectionId(this):e.visitChildren(this)}}I.ConnectionIdContext=wR;class Kk extends ge.ParserRuleContext{OCURLY(){return this.getToken(d.OCURLY,0)}CCURLY(){return this.getToken(d.CCURLY,0)}queryStatement(e){return e===void 0?this.getRuleContexts(ZR):this.getRuleContext(e,ZR)}SEMI(e){return e===void 0?this.getTokens(d.SEMI):this.getToken(d.SEMI,e)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_queryProperties}enterRule(e){e.enterQueryProperties&&e.enterQueryProperties(this)}exitRule(e){e.exitQueryProperties&&e.exitQueryProperties(this)}accept(e){return e.visitQueryProperties?e.visitQueryProperties(this):e.visitChildren(this)}}I.QueryPropertiesContext=Kk;class NR extends ge.ParserRuleContext{id(){return this.getRuleContext(0,Nn)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_queryName}enterRule(e){e.enterQueryName&&e.enterQueryName(this)}exitRule(e){e.exitQueryName&&e.exitQueryName(this)}accept(e){return e.visitQueryName?e.visitQueryName(this):e.visitChildren(this)}}I.QueryNameContext=NR;class Jk extends ge.ParserRuleContext{sourceDefinition(e){return e===void 0?this.getRuleContexts(LR):this.getRuleContext(e,LR)}COMMA(e){return e===void 0?this.getTokens(d.COMMA):this.getToken(d.COMMA,e)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_sourcePropertyList}enterRule(e){e.enterSourcePropertyList&&e.enterSourcePropertyList(this)}exitRule(e){e.exitSourcePropertyList&&e.exitSourcePropertyList(this)}accept(e){return e.visitSourcePropertyList?e.visitSourcePropertyList(this):e.visitChildren(this)}}I.SourcePropertyListContext=Jk;class LR extends ge.ParserRuleContext{tags(){return this.getRuleContext(0,Xt)}sourceNameDef(){return this.getRuleContext(0,nM)}isDefine(){return this.getRuleContext(0,v0)}sqExplore(){return this.getRuleContext(0,Xk)}sourceParameters(){return this.tryGetRuleContext(0,Zk)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_sourceDefinition}enterRule(e){e.enterSourceDefinition&&e.enterSourceDefinition(this)}exitRule(e){e.exitSourceDefinition&&e.exitSourceDefinition(this)}accept(e){return e.visitSourceDefinition?e.visitSourceDefinition(this):e.visitChildren(this)}}I.SourceDefinitionContext=LR;class Xk extends ge.ParserRuleContext{sqExpr(){return this.getRuleContext(0,cn)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_sqExplore}enterRule(e){e.enterSqExplore&&e.enterSqExplore(this)}exitRule(e){e.exitSqExplore&&e.exitSqExplore(this)}accept(e){return e.visitSqExplore?e.visitSqExplore(this):e.visitChildren(this)}}I.SqExploreContext=Xk;class Zk extends ge.ParserRuleContext{OPAREN(){return this.getToken(d.OPAREN,0)}CPAREN(){return this.getToken(d.CPAREN,0)}sourceParameter(e){return e===void 0?this.getRuleContexts(IR):this.getRuleContext(e,IR)}COMMA(e){return e===void 0?this.getTokens(d.COMMA):this.getToken(d.COMMA,e)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_sourceParameters}enterRule(e){e.enterSourceParameters&&e.enterSourceParameters(this)}exitRule(e){e.exitSourceParameters&&e.exitSourceParameters(this)}accept(e){return e.visitSourceParameters?e.visitSourceParameters(this):e.visitChildren(this)}}I.SourceParametersContext=Zk;class eM extends ge.ParserRuleContext{malloyType(){return this.getRuleContext(0,WE)}FILTER(){return this.tryGetToken(d.FILTER,0)}LT(){return this.tryGetToken(d.LT,0)}GT(){return this.tryGetToken(d.GT,0)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_legalParamType}enterRule(e){e.enterLegalParamType&&e.enterLegalParamType(this)}exitRule(e){e.exitLegalParamType&&e.exitLegalParamType(this)}accept(e){return e.visitLegalParamType?e.visitLegalParamType(this):e.visitChildren(this)}}I.LegalParamTypeContext=eM;class IR extends ge.ParserRuleContext{parameterNameDef(){return this.getRuleContext(0,tM)}DOUBLECOLON(){return this.tryGetToken(d.DOUBLECOLON,0)}legalParamType(){return this.tryGetRuleContext(0,eM)}IS(){return this.tryGetToken(d.IS,0)}fieldExpr(){return this.tryGetRuleContext(0,Re)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_sourceParameter}enterRule(e){e.enterSourceParameter&&e.enterSourceParameter(this)}exitRule(e){e.exitSourceParameter&&e.exitSourceParameter(this)}accept(e){return e.visitSourceParameter?e.visitSourceParameter(this):e.visitChildren(this)}}I.SourceParameterContext=IR;class tM extends ge.ParserRuleContext{id(){return this.getRuleContext(0,Nn)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_parameterNameDef}enterRule(e){e.enterParameterNameDef&&e.enterParameterNameDef(this)}exitRule(e){e.exitParameterNameDef&&e.exitParameterNameDef(this)}accept(e){return e.visitParameterNameDef?e.visitParameterNameDef(this):e.visitChildren(this)}}I.ParameterNameDefContext=tM;class nM extends ge.ParserRuleContext{id(){return this.getRuleContext(0,Nn)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_sourceNameDef}enterRule(e){e.enterSourceNameDef&&e.enterSourceNameDef(this)}exitRule(e){e.exitSourceNameDef&&e.exitSourceNameDef(this)}accept(e){return e.visitSourceNameDef?e.visitSourceNameDef(this):e.visitChildren(this)}}I.SourceNameDefContext=nM;class rM extends ge.ParserRuleContext{OCURLY(){return this.getToken(d.OCURLY,0)}CCURLY(){return this.getToken(d.CCURLY,0)}exploreStatement(e){return e===void 0?this.getRuleContexts(Ki):this.getRuleContext(e,Ki)}SEMI(e){return e===void 0?this.getTokens(d.SEMI):this.getToken(d.SEMI,e)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_exploreProperties}enterRule(e){e.enterExploreProperties&&e.enterExploreProperties(this)}exitRule(e){e.exitExploreProperties&&e.exitExploreProperties(this)}accept(e){return e.visitExploreProperties?e.visitExploreProperties(this):e.visitChildren(this)}}I.ExplorePropertiesContext=rM;class Ki extends ge.ParserRuleContext{constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_exploreStatement}copyFrom(e){super.copyFrom(e)}}I.ExploreStatementContext=Ki;class Jce extends Ki{defDimensions(){return this.getRuleContext(0,BR)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterDefExploreDimension_stub&&e.enterDefExploreDimension_stub(this)}exitRule(e){e.exitDefExploreDimension_stub&&e.exitDefExploreDimension_stub(this)}accept(e){return e.visitDefExploreDimension_stub?e.visitDefExploreDimension_stub(this):e.visitChildren(this)}}I.DefExploreDimension_stubContext=Jce;class Xce extends Ki{defMeasures(){return this.getRuleContext(0,$R)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterDefExploreMeasure_stub&&e.enterDefExploreMeasure_stub(this)}exitRule(e){e.exitDefExploreMeasure_stub&&e.exitDefExploreMeasure_stub(this)}accept(e){return e.visitDefExploreMeasure_stub?e.visitDefExploreMeasure_stub(this):e.visitChildren(this)}}I.DefExploreMeasure_stubContext=Xce;class Zce extends Ki{joinStatement(){return this.getRuleContext(0,C0)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterDefJoin_stub&&e.enterDefJoin_stub(this)}exitRule(e){e.exitDefJoin_stub&&e.exitDefJoin_stub(this)}accept(e){return e.visitDefJoin_stub?e.visitDefJoin_stub(this):e.visitChildren(this)}}I.DefJoin_stubContext=Zce;class efe extends Ki{whereStatement(){return this.getRuleContext(0,Nd)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterDefExploreWhere_stub&&e.enterDefExploreWhere_stub(this)}exitRule(e){e.exitDefExploreWhere_stub&&e.exitDefExploreWhere_stub(this)}accept(e){return e.visitDefExploreWhere_stub?e.visitDefExploreWhere_stub(this):e.visitChildren(this)}}I.DefExploreWhere_stubContext=efe;class tfe extends Ki{PRIMARY_KEY(){return this.getToken(d.PRIMARY_KEY,0)}fieldName(){return this.getRuleContext(0,Gr)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterDefExplorePrimaryKey&&e.enterDefExplorePrimaryKey(this)}exitRule(e){e.exitDefExplorePrimaryKey&&e.exitDefExplorePrimaryKey(this)}accept(e){return e.visitDefExplorePrimaryKey?e.visitDefExplorePrimaryKey(this):e.visitChildren(this)}}I.DefExplorePrimaryKeyContext=tfe;class nfe extends Ki{RENAME(){return this.getToken(d.RENAME,0)}renameList(){return this.getRuleContext(0,iM)}accessLabel(){return this.tryGetRuleContext(0,Qa)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterDefExploreRename&&e.enterDefExploreRename(this)}exitRule(e){e.exitDefExploreRename&&e.exitDefExploreRename(this)}accept(e){return e.visitDefExploreRename?e.visitDefExploreRename(this):e.visitChildren(this)}}I.DefExploreRenameContext=nfe;class rfe extends Ki{fieldNameList(){return this.getRuleContext(0,n1)}ACCEPT(){return this.tryGetToken(d.ACCEPT,0)}EXCEPT(){return this.tryGetToken(d.EXCEPT,0)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterDefExploreEditField&&e.enterDefExploreEditField(this)}exitRule(e){e.exitDefExploreEditField&&e.exitDefExploreEditField(this)}accept(e){return e.visitDefExploreEditField?e.visitDefExploreEditField(this):e.visitChildren(this)}}I.DefExploreEditFieldContext=rfe;class ife extends Ki{tags(){return this.getRuleContext(0,Xt)}VIEW(){return this.getToken(d.VIEW,0)}subQueryDefList(){return this.getRuleContext(0,AM)}accessLabel(){return this.tryGetRuleContext(0,Qa)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterDefExploreQuery&&e.enterDefExploreQuery(this)}exitRule(e){e.exitDefExploreQuery&&e.exitDefExploreQuery(this)}accept(e){return e.visitDefExploreQuery?e.visitDefExploreQuery(this):e.visitChildren(this)}}I.DefExploreQueryContext=ife;class sfe extends Ki{timezoneStatement(){return this.getRuleContext(0,iD)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterDefExploreTimezone&&e.enterDefExploreTimezone(this)}exitRule(e){e.exitDefExploreTimezone&&e.exitDefExploreTimezone(this)}accept(e){return e.visitDefExploreTimezone?e.visitDefExploreTimezone(this):e.visitChildren(this)}}I.DefExploreTimezoneContext=sfe;class ofe extends Ki{ANNOTATION(e){return e===void 0?this.getTokens(d.ANNOTATION):this.getToken(d.ANNOTATION,e)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterDefExploreAnnotation&&e.enterDefExploreAnnotation(this)}exitRule(e){e.exitDefExploreAnnotation&&e.exitDefExploreAnnotation(this)}accept(e){return e.visitDefExploreAnnotation?e.visitDefExploreAnnotation(this):e.visitChildren(this)}}I.DefExploreAnnotationContext=ofe;class ufe extends Ki{ignoredModelAnnotations(){return this.getRuleContext(0,DR)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterDefIgnoreModel_stub&&e.enterDefIgnoreModel_stub(this)}exitRule(e){e.exitDefIgnoreModel_stub&&e.exitDefIgnoreModel_stub(this)}accept(e){return e.visitDefIgnoreModel_stub?e.visitDefIgnoreModel_stub(this):e.visitChildren(this)}}I.DefIgnoreModel_stubContext=ufe;class Qa extends ge.ParserRuleContext{PUBLIC_KW(){return this.tryGetToken(d.PUBLIC_KW,0)}PRIVATE_KW(){return this.tryGetToken(d.PRIVATE_KW,0)}INTERNAL_KW(){return this.tryGetToken(d.INTERNAL_KW,0)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_accessLabel}enterRule(e){e.enterAccessLabel&&e.enterAccessLabel(this)}exitRule(e){e.exitAccessLabel&&e.exitAccessLabel(this)}accept(e){return e.visitAccessLabel?e.visitAccessLabel(this):e.visitChildren(this)}}I.AccessLabelContext=Qa;class afe extends ge.ParserRuleContext{fieldNameList(){return this.tryGetRuleContext(0,n1)}STAR(){return this.tryGetToken(d.STAR,0)}starQualified(){return this.tryGetRuleContext(0,fD)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_accessModifierList}enterRule(e){e.enterAccessModifierList&&e.enterAccessModifierList(this)}exitRule(e){e.exitAccessModifierList&&e.exitAccessModifierList(this)}accept(e){return e.visitAccessModifierList?e.visitAccessModifierList(this):e.visitChildren(this)}}I.AccessModifierListContext=afe;class $R extends ge.ParserRuleContext{tags(){return this.getRuleContext(0,Xt)}MEASURE(){return this.getToken(d.MEASURE,0)}defList(){return this.getRuleContext(0,jE)}accessLabel(){return this.tryGetRuleContext(0,Qa)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_defMeasures}enterRule(e){e.enterDefMeasures&&e.enterDefMeasures(this)}exitRule(e){e.exitDefMeasures&&e.exitDefMeasures(this)}accept(e){return e.visitDefMeasures?e.visitDefMeasures(this):e.visitChildren(this)}}I.DefMeasuresContext=$R;class BR extends ge.ParserRuleContext{tags(){return this.getRuleContext(0,Xt)}DIMENSION(){return this.getToken(d.DIMENSION,0)}defList(){return this.getRuleContext(0,jE)}accessLabel(){return this.tryGetRuleContext(0,Qa)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_defDimensions}enterRule(e){e.enterDefDimensions&&e.enterDefDimensions(this)}exitRule(e){e.exitDefDimensions&&e.exitDefDimensions(this)}accept(e){return e.visitDefDimensions?e.visitDefDimensions(this):e.visitChildren(this)}}I.DefDimensionsContext=BR;class iM extends ge.ParserRuleContext{exploreRenameDef(e){return e===void 0?this.getRuleContexts(kR):this.getRuleContext(e,kR)}COMMA(e){return e===void 0?this.getTokens(d.COMMA):this.getToken(d.COMMA,e)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_renameList}enterRule(e){e.enterRenameList&&e.enterRenameList(this)}exitRule(e){e.exitRenameList&&e.exitRenameList(this)}accept(e){return e.visitRenameList?e.visitRenameList(this):e.visitChildren(this)}}I.RenameListContext=iM;class kR extends ge.ParserRuleContext{fieldName(e){return e===void 0?this.getRuleContexts(Gr):this.getRuleContext(e,Gr)}isDefine(){return this.getRuleContext(0,v0)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_exploreRenameDef}enterRule(e){e.enterExploreRenameDef&&e.enterExploreRenameDef(this)}exitRule(e){e.exitExploreRenameDef&&e.exitExploreRenameDef(this)}accept(e){return e.visitExploreRenameDef?e.visitExploreRenameDef(this):e.visitChildren(this)}}I.ExploreRenameDefContext=kR;class jE extends ge.ParserRuleContext{fieldDef(e){return e===void 0?this.getRuleContexts(Z2):this.getRuleContext(e,Z2)}COMMA(e){return e===void 0?this.getTokens(d.COMMA):this.getToken(d.COMMA,e)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_defList}enterRule(e){e.enterDefList&&e.enterDefList(this)}exitRule(e){e.exitDefList&&e.exitDefList(this)}accept(e){return e.visitDefList?e.visitDefList(this):e.visitChildren(this)}}I.DefListContext=jE;class Z2 extends ge.ParserRuleContext{tags(){return this.getRuleContext(0,Xt)}fieldNameDef(){return this.getRuleContext(0,sM)}isDefine(){return this.getRuleContext(0,v0)}fieldExpr(){return this.getRuleContext(0,Re)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_fieldDef}enterRule(e){e.enterFieldDef&&e.enterFieldDef(this)}exitRule(e){e.exitFieldDef&&e.exitFieldDef(this)}accept(e){return e.visitFieldDef?e.visitFieldDef(this):e.visitChildren(this)}}I.FieldDefContext=Z2;class sM extends ge.ParserRuleContext{id(){return this.getRuleContext(0,Nn)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_fieldNameDef}enterRule(e){e.enterFieldNameDef&&e.enterFieldNameDef(this)}exitRule(e){e.exitFieldNameDef&&e.exitFieldNameDef(this)}accept(e){return e.visitFieldNameDef?e.visitFieldNameDef(this):e.visitChildren(this)}}I.FieldNameDefContext=sM;class oM extends ge.ParserRuleContext{id(){return this.getRuleContext(0,Nn)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_joinNameDef}enterRule(e){e.enterJoinNameDef&&e.enterJoinNameDef(this)}exitRule(e){e.exitJoinNameDef&&e.exitJoinNameDef(this)}accept(e){return e.visitJoinNameDef?e.visitJoinNameDef(this):e.visitChildren(this)}}I.JoinNameDefContext=oM;class MR extends ge.ParserRuleContext{DECLARE(){return this.getToken(d.DECLARE,0)}defList(){return this.getRuleContext(0,jE)}accessLabel(){return this.tryGetRuleContext(0,Qa)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_declareStatement}enterRule(e){e.enterDeclareStatement&&e.enterDeclareStatement(this)}exitRule(e){e.exitDeclareStatement&&e.exitDeclareStatement(this)}accept(e){return e.visitDeclareStatement?e.visitDeclareStatement(this):e.visitChildren(this)}}I.DeclareStatementContext=MR;class C0 extends ge.ParserRuleContext{constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_joinStatement}copyFrom(e){super.copyFrom(e)}}I.JoinStatementContext=C0;class lfe extends C0{tags(){return this.getRuleContext(0,Xt)}JOIN_ONE(){return this.getToken(d.JOIN_ONE,0)}joinList(){return this.getRuleContext(0,qE)}accessLabel(){return this.tryGetRuleContext(0,Qa)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterDefJoinOne&&e.enterDefJoinOne(this)}exitRule(e){e.exitDefJoinOne&&e.exitDefJoinOne(this)}accept(e){return e.visitDefJoinOne?e.visitDefJoinOne(this):e.visitChildren(this)}}I.DefJoinOneContext=lfe;class cfe extends C0{tags(){return this.getRuleContext(0,Xt)}JOIN_MANY(){return this.getToken(d.JOIN_MANY,0)}joinList(){return this.getRuleContext(0,qE)}accessLabel(){return this.tryGetRuleContext(0,Qa)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterDefJoinMany&&e.enterDefJoinMany(this)}exitRule(e){e.exitDefJoinMany&&e.exitDefJoinMany(this)}accept(e){return e.visitDefJoinMany?e.visitDefJoinMany(this):e.visitChildren(this)}}I.DefJoinManyContext=cfe;class ffe extends C0{tags(){return this.getRuleContext(0,Xt)}JOIN_CROSS(){return this.getToken(d.JOIN_CROSS,0)}joinList(){return this.getRuleContext(0,qE)}accessLabel(){return this.tryGetRuleContext(0,Qa)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterDefJoinCross&&e.enterDefJoinCross(this)}exitRule(e){e.exitDefJoinCross&&e.exitDefJoinCross(this)}accept(e){return e.visitDefJoinCross?e.visitDefJoinCross(this):e.visitChildren(this)}}I.DefJoinCrossContext=ffe;class uM extends ge.ParserRuleContext{EXTENDQ(){return this.getToken(d.EXTENDQ,0)}queryExtendStatementList(){return this.getRuleContext(0,dM)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_queryExtend}enterRule(e){e.enterQueryExtend&&e.enterQueryExtend(this)}exitRule(e){e.exitQueryExtend&&e.exitQueryExtend(this)}accept(e){return e.visitQueryExtend?e.visitQueryExtend(this):e.visitChildren(this)}}I.QueryExtendContext=uM;class xfe extends ge.ParserRuleContext{joinStatement(){return this.tryGetRuleContext(0,C0)}whereStatement(){return this.tryGetRuleContext(0,Nd)}declareStatement(){return this.tryGetRuleContext(0,MR)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_modEither}enterRule(e){e.enterModEither&&e.enterModEither(this)}exitRule(e){e.exitModEither&&e.exitModEither(this)}accept(e){return e.visitModEither?e.visitModEither(this):e.visitChildren(this)}}I.ModEitherContext=xfe;class PR extends ge.ParserRuleContext{OPAREN(){return this.getToken(d.OPAREN,0)}CPAREN(){return this.getToken(d.CPAREN,0)}sourceArgument(e){return e===void 0?this.getRuleContexts(UR):this.getRuleContext(e,UR)}COMMA(e){return e===void 0?this.getTokens(d.COMMA):this.getToken(d.COMMA,e)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_sourceArguments}enterRule(e){e.enterSourceArguments&&e.enterSourceArguments(this)}exitRule(e){e.exitSourceArguments&&e.exitSourceArguments(this)}accept(e){return e.visitSourceArguments?e.visitSourceArguments(this):e.visitChildren(this)}}I.SourceArgumentsContext=PR;class aM extends ge.ParserRuleContext{id(){return this.getRuleContext(0,Nn)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_argumentId}enterRule(e){e.enterArgumentId&&e.enterArgumentId(this)}exitRule(e){e.exitArgumentId&&e.exitArgumentId(this)}accept(e){return e.visitArgumentId?e.visitArgumentId(this):e.visitChildren(this)}}I.ArgumentIdContext=aM;class UR extends ge.ParserRuleContext{fieldExpr(){return this.getRuleContext(0,Re)}argumentId(){return this.tryGetRuleContext(0,aM)}IS(){return this.tryGetToken(d.IS,0)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_sourceArgument}enterRule(e){e.enterSourceArgument&&e.enterSourceArgument(this)}exitRule(e){e.exitSourceArgument&&e.exitSourceArgument(this)}accept(e){return e.visitSourceArgument?e.visitSourceArgument(this):e.visitChildren(this)}}I.SourceArgumentContext=UR;class cn extends ge.ParserRuleContext{constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_sqExpr}copyFrom(e){super.copyFrom(e)}}I.SqExprContext=cn;class dfe extends cn{id(){return this.getRuleContext(0,Nn)}sourceArguments(){return this.tryGetRuleContext(0,PR)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterSQID&&e.enterSQID(this)}exitRule(e){e.exitSQID&&e.exitSQID(this)}accept(e){return e.visitSQID?e.visitSQID(this):e.visitChildren(this)}}I.SQIDContext=dfe;class hfe extends cn{OPAREN(){return this.getToken(d.OPAREN,0)}sqExpr(){return this.getRuleContext(0,cn)}CPAREN(){return this.getToken(d.CPAREN,0)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterSQParens&&e.enterSQParens(this)}exitRule(e){e.exitSQParens&&e.exitSQParens(this)}accept(e){return e.visitSQParens?e.visitSQParens(this):e.visitChildren(this)}}I.SQParensContext=hfe;class pfe extends cn{COMPOSE(){return this.getToken(d.COMPOSE,0)}OPAREN(){return this.getToken(d.OPAREN,0)}CPAREN(){return this.getToken(d.CPAREN,0)}sqExpr(e){return e===void 0?this.getRuleContexts(cn):this.getRuleContext(e,cn)}COMMA(e){return e===void 0?this.getTokens(d.COMMA):this.getToken(d.COMMA,e)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterSQCompose&&e.enterSQCompose(this)}exitRule(e){e.exitSQCompose&&e.exitSQCompose(this)}accept(e){return e.visitSQCompose?e.visitSQCompose(this):e.visitChildren(this)}}I.SQComposeContext=pfe;class mfe extends cn{sqExpr(){return this.getRuleContext(0,cn)}PLUS(){return this.getToken(d.PLUS,0)}segExpr(){return this.getRuleContext(0,Ws)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterSQRefinedQuery&&e.enterSQRefinedQuery(this)}exitRule(e){e.exitSQRefinedQuery&&e.exitSQRefinedQuery(this)}accept(e){return e.visitSQRefinedQuery?e.visitSQRefinedQuery(this):e.visitChildren(this)}}I.SQRefinedQueryContext=mfe;class gfe extends cn{sqExpr(){return this.getRuleContext(0,cn)}ARROW(){return this.getToken(d.ARROW,0)}segExpr(){return this.getRuleContext(0,Ws)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterSQArrow&&e.enterSQArrow(this)}exitRule(e){e.exitSQArrow&&e.exitSQArrow(this)}accept(e){return e.visitSQArrow?e.visitSQArrow(this):e.visitChildren(this)}}I.SQArrowContext=gfe;class yfe extends cn{sqExpr(){return this.getRuleContext(0,cn)}EXTEND(){return this.getToken(d.EXTEND,0)}exploreProperties(){return this.getRuleContext(0,rM)}INCLUDE(){return this.tryGetToken(d.INCLUDE,0)}includeBlock(){return this.tryGetRuleContext(0,jR)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterSQExtendedSource&&e.enterSQExtendedSource(this)}exitRule(e){e.exitSQExtendedSource&&e.exitSQExtendedSource(this)}accept(e){return e.visitSQExtendedSource?e.visitSQExtendedSource(this):e.visitChildren(this)}}I.SQExtendedSourceContext=yfe;class Efe extends cn{sqExpr(){return this.getRuleContext(0,cn)}INCLUDE(){return this.getToken(d.INCLUDE,0)}includeBlock(){return this.getRuleContext(0,jR)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterSQInclude&&e.enterSQInclude(this)}exitRule(e){e.exitSQInclude&&e.exitSQInclude(this)}accept(e){return e.visitSQInclude?e.visitSQInclude(this):e.visitChildren(this)}}I.SQIncludeContext=Efe;class Afe extends cn{exploreTable(){return this.getRuleContext(0,Yk)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterSQTable&&e.enterSQTable(this)}exitRule(e){e.exitSQTable&&e.exitSQTable(this)}accept(e){return e.visitSQTable?e.visitSQTable(this):e.visitChildren(this)}}I.SQTableContext=Afe;class _fe extends cn{sqlSource(){return this.getRuleContext(0,Vk)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterSQSQL&&e.enterSQSQL(this)}exitRule(e){e.exitSQSQL&&e.exitSQSQL(this)}accept(e){return e.visitSQSQL?e.visitSQSQL(this):e.visitChildren(this)}}I.SQSQLContext=_fe;class jR extends ge.ParserRuleContext{OCURLY(){return this.getToken(d.OCURLY,0)}CCURLY(){return this.getToken(d.CCURLY,0)}includeItem(e){return e===void 0?this.getRuleContexts(qR):this.getRuleContext(e,qR)}SEMI(e){return e===void 0?this.getTokens(d.SEMI):this.getToken(d.SEMI,e)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_includeBlock}enterRule(e){e.enterIncludeBlock&&e.enterIncludeBlock(this)}exitRule(e){e.exitIncludeBlock&&e.exitIncludeBlock(this)}accept(e){return e.visitIncludeBlock?e.visitIncludeBlock(this):e.visitChildren(this)}}I.IncludeBlockContext=jR;class qR extends ge.ParserRuleContext{tags(){return this.tryGetRuleContext(0,Xt)}accessLabelProp(){return this.tryGetRuleContext(0,cM)}includeList(){return this.tryGetRuleContext(0,xM)}EXCEPT(){return this.tryGetToken(d.EXCEPT,0)}includeExceptList(){return this.tryGetRuleContext(0,fM)}orphanedAnnotation(){return this.tryGetRuleContext(0,lM)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_includeItem}enterRule(e){e.enterIncludeItem&&e.enterIncludeItem(this)}exitRule(e){e.exitIncludeItem&&e.exitIncludeItem(this)}accept(e){return e.visitIncludeItem?e.visitIncludeItem(this):e.visitChildren(this)}}I.IncludeItemContext=qR;class lM extends ge.ParserRuleContext{ANNOTATION(){return this.getToken(d.ANNOTATION,0)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_orphanedAnnotation}enterRule(e){e.enterOrphanedAnnotation&&e.enterOrphanedAnnotation(this)}exitRule(e){e.exitOrphanedAnnotation&&e.exitOrphanedAnnotation(this)}accept(e){return e.visitOrphanedAnnotation?e.visitOrphanedAnnotation(this):e.visitChildren(this)}}I.OrphanedAnnotationContext=lM;class cM extends ge.ParserRuleContext{PUBLIC(){return this.tryGetToken(d.PUBLIC,0)}PRIVATE(){return this.tryGetToken(d.PRIVATE,0)}INTERNAL(){return this.tryGetToken(d.INTERNAL,0)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_accessLabelProp}enterRule(e){e.enterAccessLabelProp&&e.enterAccessLabelProp(this)}exitRule(e){e.exitAccessLabelProp&&e.exitAccessLabelProp(this)}accept(e){return e.visitAccessLabelProp?e.visitAccessLabelProp(this):e.visitChildren(this)}}I.AccessLabelPropContext=cM;class fM extends ge.ParserRuleContext{includeExceptListItem(e){return e===void 0?this.getRuleContexts(HR):this.getRuleContext(e,HR)}COMMA(e){return e===void 0?this.getTokens(d.COMMA):this.getToken(d.COMMA,e)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_includeExceptList}enterRule(e){e.enterIncludeExceptList&&e.enterIncludeExceptList(this)}exitRule(e){e.exitIncludeExceptList&&e.exitIncludeExceptList(this)}accept(e){return e.visitIncludeExceptList?e.visitIncludeExceptList(this):e.visitChildren(this)}}I.IncludeExceptListContext=fM;class HR extends ge.ParserRuleContext{tags(){return this.getRuleContext(0,Xt)}fieldName(){return this.tryGetRuleContext(0,Gr)}collectionWildCard(){return this.tryGetRuleContext(0,GE)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_includeExceptListItem}enterRule(e){e.enterIncludeExceptListItem&&e.enterIncludeExceptListItem(this)}exitRule(e){e.exitIncludeExceptListItem&&e.exitIncludeExceptListItem(this)}accept(e){return e.visitIncludeExceptListItem?e.visitIncludeExceptListItem(this):e.visitChildren(this)}}I.IncludeExceptListItemContext=HR;class xM extends ge.ParserRuleContext{includeField(e){return e===void 0?this.getRuleContexts(QR):this.getRuleContext(e,QR)}COMMA(e){return e===void 0?this.getTokens(d.COMMA):this.getToken(d.COMMA,e)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_includeList}enterRule(e){e.enterIncludeList&&e.enterIncludeList(this)}exitRule(e){e.exitIncludeList&&e.exitIncludeList(this)}accept(e){return e.visitIncludeList?e.visitIncludeList(this):e.visitChildren(this)}}I.IncludeListContext=xM;class QR extends ge.ParserRuleContext{tags(){return this.getRuleContext(0,Xt)}fieldName(e){return e===void 0?this.getRuleContexts(Gr):this.getRuleContext(e,Gr)}isDefine(){return this.tryGetRuleContext(0,v0)}collectionWildCard(){return this.tryGetRuleContext(0,GE)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_includeField}enterRule(e){e.enterIncludeField&&e.enterIncludeField(this)}exitRule(e){e.exitIncludeField&&e.exitIncludeField(this)}accept(e){return e.visitIncludeField?e.visitIncludeField(this):e.visitChildren(this)}}I.IncludeFieldContext=QR;class Ws extends ge.ParserRuleContext{constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_segExpr}copyFrom(e){super.copyFrom(e)}}I.SegExprContext=Ws;class vfe extends Ws{fieldPath(){return this.getRuleContext(0,Ga)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterSegField&&e.enterSegField(this)}exitRule(e){e.exitSegField&&e.exitSegField(this)}accept(e){return e.visitSegField?e.visitSegField(this):e.visitChildren(this)}}I.SegFieldContext=vfe;class Cfe extends Ws{queryProperties(){return this.getRuleContext(0,Kk)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterSegOps&&e.enterSegOps(this)}exitRule(e){e.exitSegOps&&e.exitSegOps(this)}accept(e){return e.visitSegOps?e.visitSegOps(this):e.visitChildren(this)}}I.SegOpsContext=Cfe;class Sfe extends Ws{OPAREN(){return this.getToken(d.OPAREN,0)}vExpr(){return this.getRuleContext(0,xf)}CPAREN(){return this.getToken(d.CPAREN,0)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterSegParen&&e.enterSegParen(this)}exitRule(e){e.exitSegParen&&e.exitSegParen(this)}accept(e){return e.visitSegParen?e.visitSegParen(this):e.visitChildren(this)}}I.SegParenContext=Sfe;class bfe extends Ws{PLUS(){return this.getToken(d.PLUS,0)}segExpr(e){return e===void 0?this.getRuleContexts(Ws):this.getRuleContext(e,Ws)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterSegRefine&&e.enterSegRefine(this)}exitRule(e){e.exitSegRefine&&e.exitSegRefine(this)}accept(e){return e.visitSegRefine?e.visitSegRefine(this):e.visitChildren(this)}}I.SegRefineContext=bfe;class xf extends ge.ParserRuleContext{constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_vExpr}copyFrom(e){super.copyFrom(e)}}I.VExprContext=xf;class Tfe extends xf{segExpr(){return this.getRuleContext(0,Ws)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterVSeg&&e.enterVSeg(this)}exitRule(e){e.exitVSeg&&e.exitVSeg(this)}accept(e){return e.visitVSeg?e.visitVSeg(this):e.visitChildren(this)}}I.VSegContext=Tfe;class Rfe extends xf{ARROW(){return this.getToken(d.ARROW,0)}segExpr(){return this.getRuleContext(0,Ws)}vExpr(){return this.getRuleContext(0,xf)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterVArrow&&e.enterVArrow(this)}exitRule(e){e.exitVArrow&&e.exitVArrow(this)}accept(e){return e.visitVArrow?e.visitVArrow(this):e.visitChildren(this)}}I.VArrowContext=Rfe;class zR extends ge.ParserRuleContext{defDimensions(){return this.tryGetRuleContext(0,BR)}defMeasures(){return this.tryGetRuleContext(0,$R)}joinStatement(){return this.tryGetRuleContext(0,C0)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_queryExtendStatement}enterRule(e){e.enterQueryExtendStatement&&e.enterQueryExtendStatement(this)}exitRule(e){e.exitQueryExtendStatement&&e.exitQueryExtendStatement(this)}accept(e){return e.visitQueryExtendStatement?e.visitQueryExtendStatement(this):e.visitChildren(this)}}I.QueryExtendStatementContext=zR;class dM extends ge.ParserRuleContext{OCURLY(){return this.getToken(d.OCURLY,0)}CCURLY(){return this.getToken(d.CCURLY,0)}queryExtendStatement(e){return e===void 0?this.getRuleContexts(zR):this.getRuleContext(e,zR)}SEMI(e){return e===void 0?this.getTokens(d.SEMI):this.getToken(d.SEMI,e)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_queryExtendStatementList}enterRule(e){e.enterQueryExtendStatementList&&e.enterQueryExtendStatementList(this)}exitRule(e){e.exitQueryExtendStatementList&&e.exitQueryExtendStatementList(this)}accept(e){return e.visitQueryExtendStatementList?e.visitQueryExtendStatementList(this):e.visitChildren(this)}}I.QueryExtendStatementListContext=dM;class qE extends ge.ParserRuleContext{joinDef(e){return e===void 0?this.getRuleContexts(e1):this.getRuleContext(e,e1)}COMMA(e){return e===void 0?this.getTokens(d.COMMA):this.getToken(d.COMMA,e)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_joinList}enterRule(e){e.enterJoinList&&e.enterJoinList(this)}exitRule(e){e.exitJoinList&&e.exitJoinList(this)}accept(e){return e.visitJoinList?e.visitJoinList(this):e.visitChildren(this)}}I.JoinListContext=qE;class hM extends ge.ParserRuleContext{IS(){return this.getToken(d.IS,0)}sqExpr(){return this.getRuleContext(0,cn)}tags(e){return e===void 0?this.getRuleContexts(Xt):this.getRuleContext(e,Xt)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_isExplore}enterRule(e){e.enterIsExplore&&e.enterIsExplore(this)}exitRule(e){e.exitIsExplore&&e.exitIsExplore(this)}accept(e){return e.visitIsExplore?e.visitIsExplore(this):e.visitChildren(this)}}I.IsExploreContext=hM;class WR extends ge.ParserRuleContext{LEFT(){return this.tryGetToken(d.LEFT,0)}RIGHT(){return this.tryGetToken(d.RIGHT,0)}FULL(){return this.tryGetToken(d.FULL,0)}INNER(){return this.tryGetToken(d.INNER,0)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_matrixOperation}enterRule(e){e.enterMatrixOperation&&e.enterMatrixOperation(this)}exitRule(e){e.exitMatrixOperation&&e.exitMatrixOperation(this)}accept(e){return e.visitMatrixOperation?e.visitMatrixOperation(this):e.visitChildren(this)}}I.MatrixOperationContext=WR;class GR extends ge.ParserRuleContext{joinNameDef(){return this.getRuleContext(0,oM)}sourceArguments(){return this.tryGetRuleContext(0,PR)}isExplore(){return this.tryGetRuleContext(0,hM)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_joinFrom}enterRule(e){e.enterJoinFrom&&e.enterJoinFrom(this)}exitRule(e){e.exitJoinFrom&&e.exitJoinFrom(this)}accept(e){return e.visitJoinFrom?e.visitJoinFrom(this):e.visitChildren(this)}}I.JoinFromContext=GR;class e1 extends ge.ParserRuleContext{constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_joinDef}copyFrom(e){super.copyFrom(e)}}I.JoinDefContext=e1;class Dfe extends e1{joinFrom(){return this.getRuleContext(0,GR)}WITH(){return this.getToken(d.WITH,0)}fieldExpr(){return this.getRuleContext(0,Re)}ANNOTATION(e){return e===void 0?this.getTokens(d.ANNOTATION):this.getToken(d.ANNOTATION,e)}matrixOperation(){return this.tryGetRuleContext(0,WR)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterJoinWith&&e.enterJoinWith(this)}exitRule(e){e.exitJoinWith&&e.exitJoinWith(this)}accept(e){return e.visitJoinWith?e.visitJoinWith(this):e.visitChildren(this)}}I.JoinWithContext=Dfe;class Ofe extends e1{joinFrom(){return this.getRuleContext(0,GR)}ANNOTATION(e){return e===void 0?this.getTokens(d.ANNOTATION):this.getToken(d.ANNOTATION,e)}ON(){return this.tryGetToken(d.ON,0)}joinExpression(){return this.tryGetRuleContext(0,pM)}matrixOperation(){return this.tryGetRuleContext(0,WR)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterJoinOn&&e.enterJoinOn(this)}exitRule(e){e.exitJoinOn&&e.exitJoinOn(this)}accept(e){return e.visitJoinOn?e.visitJoinOn(this):e.visitChildren(this)}}I.JoinOnContext=Ofe;class pM extends ge.ParserRuleContext{fieldExpr(){return this.getRuleContext(0,Re)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_joinExpression}enterRule(e){e.enterJoinExpression&&e.enterJoinExpression(this)}exitRule(e){e.exitJoinExpression&&e.exitJoinExpression(this)}accept(e){return e.visitJoinExpression?e.visitJoinExpression(this):e.visitChildren(this)}}I.JoinExpressionContext=pM;class Ffe extends ge.ParserRuleContext{whereStatement(){return this.tryGetRuleContext(0,Nd)}havingStatement(){return this.tryGetRuleContext(0,JR)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_filterStatement}enterRule(e){e.enterFilterStatement&&e.enterFilterStatement(this)}exitRule(e){e.exitFilterStatement&&e.exitFilterStatement(this)}accept(e){return e.visitFilterStatement?e.visitFilterStatement(this):e.visitChildren(this)}}I.FilterStatementContext=Ffe;class mM extends ge.ParserRuleContext{OCURLY(){return this.getToken(d.OCURLY,0)}CCURLY(){return this.getToken(d.CCURLY,0)}fieldPropertyStatement(e){return e===void 0?this.getRuleContexts(YR):this.getRuleContext(e,YR)}SEMI(e){return e===void 0?this.getTokens(d.SEMI):this.getToken(d.SEMI,e)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_fieldProperties}enterRule(e){e.enterFieldProperties&&e.enterFieldProperties(this)}exitRule(e){e.exitFieldProperties&&e.exitFieldProperties(this)}accept(e){return e.visitFieldProperties?e.visitFieldProperties(this):e.visitChildren(this)}}I.FieldPropertiesContext=mM;class gM extends ge.ParserRuleContext{aggregateOrderBySpec(e){return e===void 0?this.getRuleContexts(VR):this.getRuleContext(e,VR)}COMMA(e){return e===void 0?this.getTokens(d.COMMA):this.getToken(d.COMMA,e)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_aggregateOrdering}enterRule(e){e.enterAggregateOrdering&&e.enterAggregateOrdering(this)}exitRule(e){e.exitAggregateOrdering&&e.exitAggregateOrdering(this)}accept(e){return e.visitAggregateOrdering?e.visitAggregateOrdering(this):e.visitChildren(this)}}I.AggregateOrderingContext=gM;class VR extends ge.ParserRuleContext{fieldExpr(){return this.tryGetRuleContext(0,Re)}ASC(){return this.tryGetToken(d.ASC,0)}DESC(){return this.tryGetToken(d.DESC,0)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_aggregateOrderBySpec}enterRule(e){e.enterAggregateOrderBySpec&&e.enterAggregateOrderBySpec(this)}exitRule(e){e.exitAggregateOrderBySpec&&e.exitAggregateOrderBySpec(this)}accept(e){return e.visitAggregateOrderBySpec?e.visitAggregateOrderBySpec(this):e.visitChildren(this)}}I.AggregateOrderBySpecContext=VR;class yM extends ge.ParserRuleContext{ORDER_BY(){return this.getToken(d.ORDER_BY,0)}aggregateOrdering(){return this.getRuleContext(0,gM)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_aggregateOrderByStatement}enterRule(e){e.enterAggregateOrderByStatement&&e.enterAggregateOrderByStatement(this)}exitRule(e){e.exitAggregateOrderByStatement&&e.exitAggregateOrderByStatement(this)}accept(e){return e.visitAggregateOrderByStatement?e.visitAggregateOrderByStatement(this):e.visitChildren(this)}}I.AggregateOrderByStatementContext=yM;class EM extends ge.ParserRuleContext{limitStatement(){return this.getRuleContext(0,nD)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_fieldPropertyLimitStatement}enterRule(e){e.enterFieldPropertyLimitStatement&&e.enterFieldPropertyLimitStatement(this)}exitRule(e){e.exitFieldPropertyLimitStatement&&e.exitFieldPropertyLimitStatement(this)}accept(e){return e.visitFieldPropertyLimitStatement?e.visitFieldPropertyLimitStatement(this):e.visitChildren(this)}}I.FieldPropertyLimitStatementContext=EM;class YR extends ge.ParserRuleContext{whereStatement(){return this.tryGetRuleContext(0,Nd)}partitionByStatement(){return this.tryGetRuleContext(0,OM)}aggregateOrderByStatement(){return this.tryGetRuleContext(0,yM)}fieldPropertyLimitStatement(){return this.tryGetRuleContext(0,EM)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_fieldPropertyStatement}enterRule(e){e.enterFieldPropertyStatement&&e.enterFieldPropertyStatement(this)}exitRule(e){e.exitFieldPropertyStatement&&e.exitFieldPropertyStatement(this)}accept(e){return e.visitFieldPropertyStatement?e.visitFieldPropertyStatement(this):e.visitChildren(this)}}I.FieldPropertyStatementContext=YR;class KR extends ge.ParserRuleContext{fieldExpr(e){return e===void 0?this.getRuleContexts(Re):this.getRuleContext(e,Re)}COMMA(e){return e===void 0?this.getTokens(d.COMMA):this.getToken(d.COMMA,e)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_filterClauseList}enterRule(e){e.enterFilterClauseList&&e.enterFilterClauseList(this)}exitRule(e){e.exitFilterClauseList&&e.exitFilterClauseList(this)}accept(e){return e.visitFilterClauseList?e.visitFilterClauseList(this):e.visitChildren(this)}}I.FilterClauseListContext=KR;class Nd extends ge.ParserRuleContext{WHERE(){return this.getToken(d.WHERE,0)}filterClauseList(){return this.getRuleContext(0,KR)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_whereStatement}enterRule(e){e.enterWhereStatement&&e.enterWhereStatement(this)}exitRule(e){e.exitWhereStatement&&e.exitWhereStatement(this)}accept(e){return e.visitWhereStatement?e.visitWhereStatement(this):e.visitChildren(this)}}I.WhereStatementContext=Nd;class JR extends ge.ParserRuleContext{HAVING(){return this.getToken(d.HAVING,0)}filterClauseList(){return this.getRuleContext(0,KR)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_havingStatement}enterRule(e){e.enterHavingStatement&&e.enterHavingStatement(this)}exitRule(e){e.exitHavingStatement&&e.exitHavingStatement(this)}accept(e){return e.visitHavingStatement?e.visitHavingStatement(this):e.visitChildren(this)}}I.HavingStatementContext=JR;class AM extends ge.ParserRuleContext{exploreQueryDef(e){return e===void 0?this.getRuleContexts(XR):this.getRuleContext(e,XR)}COMMA(e){return e===void 0?this.getTokens(d.COMMA):this.getToken(d.COMMA,e)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_subQueryDefList}enterRule(e){e.enterSubQueryDefList&&e.enterSubQueryDefList(this)}exitRule(e){e.exitSubQueryDefList&&e.exitSubQueryDefList(this)}accept(e){return e.visitSubQueryDefList?e.visitSubQueryDefList(this):e.visitChildren(this)}}I.SubQueryDefListContext=AM;class _M extends ge.ParserRuleContext{id(){return this.getRuleContext(0,Nn)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_exploreQueryNameDef}enterRule(e){e.enterExploreQueryNameDef&&e.enterExploreQueryNameDef(this)}exitRule(e){e.exitExploreQueryNameDef&&e.exitExploreQueryNameDef(this)}accept(e){return e.visitExploreQueryNameDef?e.visitExploreQueryNameDef(this):e.visitChildren(this)}}I.ExploreQueryNameDefContext=_M;class XR extends ge.ParserRuleContext{exploreQueryNameDef(){return this.getRuleContext(0,_M)}isDefine(){return this.getRuleContext(0,v0)}vExpr(){return this.getRuleContext(0,xf)}ANNOTATION(e){return e===void 0?this.getTokens(d.ANNOTATION):this.getToken(d.ANNOTATION,e)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_exploreQueryDef}enterRule(e){e.enterExploreQueryDef&&e.enterExploreQueryDef(this)}exitRule(e){e.exitExploreQueryDef&&e.exitExploreQueryDef(this)}accept(e){return e.visitExploreQueryDef?e.visitExploreQueryDef(this):e.visitChildren(this)}}I.ExploreQueryDefContext=XR;class ZR extends ge.ParserRuleContext{groupByStatement(){return this.tryGetRuleContext(0,CM)}declareStatement(){return this.tryGetRuleContext(0,MR)}queryJoinStatement(){return this.tryGetRuleContext(0,vM)}queryExtend(){return this.tryGetRuleContext(0,uM)}projectStatement(){return this.tryGetRuleContext(0,DM)}indexStatement(){return this.tryGetRuleContext(0,IM)}aggregateStatement(){return this.tryGetRuleContext(0,TM)}calculateStatement(){return this.tryGetRuleContext(0,RM)}topStatement(){return this.tryGetRuleContext(0,NM)}limitStatement(){return this.tryGetRuleContext(0,nD)}orderByStatement(){return this.tryGetRuleContext(0,FM)}whereStatement(){return this.tryGetRuleContext(0,Nd)}havingStatement(){return this.tryGetRuleContext(0,JR)}nestStatement(){return this.tryGetRuleContext(0,SM)}sampleStatement(){return this.tryGetRuleContext(0,$M)}timezoneStatement(){return this.tryGetRuleContext(0,iD)}queryAnnotation(){return this.tryGetRuleContext(0,BM)}ignoredModelAnnotations(){return this.tryGetRuleContext(0,DR)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_queryStatement}enterRule(e){e.enterQueryStatement&&e.enterQueryStatement(this)}exitRule(e){e.exitQueryStatement&&e.exitQueryStatement(this)}accept(e){return e.visitQueryStatement?e.visitQueryStatement(this):e.visitChildren(this)}}I.QueryStatementContext=ZR;class vM extends ge.ParserRuleContext{joinStatement(){return this.getRuleContext(0,C0)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_queryJoinStatement}enterRule(e){e.enterQueryJoinStatement&&e.enterQueryJoinStatement(this)}exitRule(e){e.exitQueryJoinStatement&&e.exitQueryJoinStatement(this)}accept(e){return e.visitQueryJoinStatement?e.visitQueryJoinStatement(this):e.visitChildren(this)}}I.QueryJoinStatementContext=vM;class CM extends ge.ParserRuleContext{tags(){return this.getRuleContext(0,Xt)}GROUP_BY(){return this.getToken(d.GROUP_BY,0)}queryFieldList(){return this.getRuleContext(0,HE)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_groupByStatement}enterRule(e){e.enterGroupByStatement&&e.enterGroupByStatement(this)}exitRule(e){e.exitGroupByStatement&&e.exitGroupByStatement(this)}accept(e){return e.visitGroupByStatement?e.visitGroupByStatement(this):e.visitChildren(this)}}I.GroupByStatementContext=CM;class HE extends ge.ParserRuleContext{queryFieldEntry(e){return e===void 0?this.getRuleContexts(eD):this.getRuleContext(e,eD)}COMMA(e){return e===void 0?this.getTokens(d.COMMA):this.getToken(d.COMMA,e)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_queryFieldList}enterRule(e){e.enterQueryFieldList&&e.enterQueryFieldList(this)}exitRule(e){e.exitQueryFieldList&&e.exitQueryFieldList(this)}accept(e){return e.visitQueryFieldList?e.visitQueryFieldList(this):e.visitChildren(this)}}I.QueryFieldListContext=HE;class eD extends ge.ParserRuleContext{taggedRef(){return this.tryGetRuleContext(0,xD)}fieldDef(){return this.tryGetRuleContext(0,Z2)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_queryFieldEntry}enterRule(e){e.enterQueryFieldEntry&&e.enterQueryFieldEntry(this)}exitRule(e){e.exitQueryFieldEntry&&e.exitQueryFieldEntry(this)}accept(e){return e.visitQueryFieldEntry?e.visitQueryFieldEntry(this):e.visitChildren(this)}}I.QueryFieldEntryContext=eD;class SM extends ge.ParserRuleContext{tags(){return this.getRuleContext(0,Xt)}NEST(){return this.getToken(d.NEST,0)}nestedQueryList(){return this.getRuleContext(0,bM)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_nestStatement}enterRule(e){e.enterNestStatement&&e.enterNestStatement(this)}exitRule(e){e.exitNestStatement&&e.exitNestStatement(this)}accept(e){return e.visitNestStatement?e.visitNestStatement(this):e.visitChildren(this)}}I.NestStatementContext=SM;class bM extends ge.ParserRuleContext{nestEntry(e){return e===void 0?this.getRuleContexts(QE):this.getRuleContext(e,QE)}COMMA(e){return e===void 0?this.getTokens(d.COMMA):this.getToken(d.COMMA,e)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_nestedQueryList}enterRule(e){e.enterNestedQueryList&&e.enterNestedQueryList(this)}exitRule(e){e.exitNestedQueryList&&e.exitNestedQueryList(this)}accept(e){return e.visitNestedQueryList?e.visitNestedQueryList(this):e.visitChildren(this)}}I.NestedQueryListContext=bM;class QE extends ge.ParserRuleContext{constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_nestEntry}copyFrom(e){super.copyFrom(e)}}I.NestEntryContext=QE;class wfe extends QE{tags(){return this.getRuleContext(0,Xt)}vExpr(){return this.getRuleContext(0,xf)}queryName(){return this.tryGetRuleContext(0,NR)}isDefine(){return this.tryGetRuleContext(0,v0)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterNestDef&&e.enterNestDef(this)}exitRule(e){e.exitNestDef&&e.exitNestDef(this)}accept(e){return e.visitNestDef?e.visitNestDef(this):e.visitChildren(this)}}I.NestDefContext=wfe;class TM extends ge.ParserRuleContext{tags(){return this.getRuleContext(0,Xt)}AGGREGATE(){return this.getToken(d.AGGREGATE,0)}queryFieldList(){return this.getRuleContext(0,HE)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_aggregateStatement}enterRule(e){e.enterAggregateStatement&&e.enterAggregateStatement(this)}exitRule(e){e.exitAggregateStatement&&e.exitAggregateStatement(this)}accept(e){return e.visitAggregateStatement?e.visitAggregateStatement(this):e.visitChildren(this)}}I.AggregateStatementContext=TM;class RM extends ge.ParserRuleContext{tags(){return this.getRuleContext(0,Xt)}CALCULATE(){return this.getToken(d.CALCULATE,0)}queryFieldList(){return this.getRuleContext(0,HE)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_calculateStatement}enterRule(e){e.enterCalculateStatement&&e.enterCalculateStatement(this)}exitRule(e){e.exitCalculateStatement&&e.exitCalculateStatement(this)}accept(e){return e.visitCalculateStatement?e.visitCalculateStatement(this):e.visitChildren(this)}}I.CalculateStatementContext=RM;class DM extends ge.ParserRuleContext{tags(){return this.getRuleContext(0,Xt)}SELECT(){return this.getToken(d.SELECT,0)}fieldCollection(){return this.getRuleContext(0,YM)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_projectStatement}enterRule(e){e.enterProjectStatement&&e.enterProjectStatement(this)}exitRule(e){e.exitProjectStatement&&e.exitProjectStatement(this)}accept(e){return e.visitProjectStatement?e.visitProjectStatement(this):e.visitChildren(this)}}I.ProjectStatementContext=DM;class OM extends ge.ParserRuleContext{PARTITION_BY(){return this.getToken(d.PARTITION_BY,0)}id(e){return e===void 0?this.getRuleContexts(Nn):this.getRuleContext(e,Nn)}COMMA(e){return e===void 0?this.getTokens(d.COMMA):this.getToken(d.COMMA,e)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_partitionByStatement}enterRule(e){e.enterPartitionByStatement&&e.enterPartitionByStatement(this)}exitRule(e){e.exitPartitionByStatement&&e.exitPartitionByStatement(this)}accept(e){return e.visitPartitionByStatement?e.visitPartitionByStatement(this):e.visitChildren(this)}}I.PartitionByStatementContext=OM;class FM extends ge.ParserRuleContext{ORDER_BY(){return this.getToken(d.ORDER_BY,0)}ordering(){return this.getRuleContext(0,wM)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_orderByStatement}enterRule(e){e.enterOrderByStatement&&e.enterOrderByStatement(this)}exitRule(e){e.exitOrderByStatement&&e.exitOrderByStatement(this)}accept(e){return e.visitOrderByStatement?e.visitOrderByStatement(this):e.visitChildren(this)}}I.OrderByStatementContext=FM;class wM extends ge.ParserRuleContext{orderBySpec(e){return e===void 0?this.getRuleContexts(tD):this.getRuleContext(e,tD)}COMMA(e){return e===void 0?this.getTokens(d.COMMA):this.getToken(d.COMMA,e)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_ordering}enterRule(e){e.enterOrdering&&e.enterOrdering(this)}exitRule(e){e.exitOrdering&&e.exitOrdering(this)}accept(e){return e.visitOrdering?e.visitOrdering(this):e.visitChildren(this)}}I.OrderingContext=wM;class tD extends ge.ParserRuleContext{INTEGER_LITERAL(){return this.tryGetToken(d.INTEGER_LITERAL,0)}fieldName(){return this.tryGetRuleContext(0,Gr)}ASC(){return this.tryGetToken(d.ASC,0)}DESC(){return this.tryGetToken(d.DESC,0)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_orderBySpec}enterRule(e){e.enterOrderBySpec&&e.enterOrderBySpec(this)}exitRule(e){e.exitOrderBySpec&&e.exitOrderBySpec(this)}accept(e){return e.visitOrderBySpec?e.visitOrderBySpec(this):e.visitChildren(this)}}I.OrderBySpecContext=tD;class nD extends ge.ParserRuleContext{LIMIT(){return this.getToken(d.LIMIT,0)}INTEGER_LITERAL(){return this.getToken(d.INTEGER_LITERAL,0)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_limitStatement}enterRule(e){e.enterLimitStatement&&e.enterLimitStatement(this)}exitRule(e){e.exitLimitStatement&&e.exitLimitStatement(this)}accept(e){return e.visitLimitStatement?e.visitLimitStatement(this):e.visitChildren(this)}}I.LimitStatementContext=nD;class Nfe extends ge.ParserRuleContext{BY(){return this.getToken(d.BY,0)}fieldName(){return this.tryGetRuleContext(0,Gr)}fieldExpr(){return this.tryGetRuleContext(0,Re)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_bySpec}enterRule(e){e.enterBySpec&&e.enterBySpec(this)}exitRule(e){e.exitBySpec&&e.exitBySpec(this)}accept(e){return e.visitBySpec?e.visitBySpec(this):e.visitChildren(this)}}I.BySpecContext=Nfe;class NM extends ge.ParserRuleContext{TOP(){return this.getToken(d.TOP,0)}INTEGER_LITERAL(){return this.getToken(d.INTEGER_LITERAL,0)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_topStatement}enterRule(e){e.enterTopStatement&&e.enterTopStatement(this)}exitRule(e){e.exitTopStatement&&e.exitTopStatement(this)}accept(e){return e.visitTopStatement?e.visitTopStatement(this):e.visitChildren(this)}}I.TopStatementContext=NM;class rD extends ge.ParserRuleContext{fieldPath(){return this.tryGetRuleContext(0,Ga)}DOT(){return this.tryGetToken(d.DOT,0)}STAR(){return this.tryGetToken(d.STAR,0)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_indexElement}enterRule(e){e.enterIndexElement&&e.enterIndexElement(this)}exitRule(e){e.exitIndexElement&&e.exitIndexElement(this)}accept(e){return e.visitIndexElement?e.visitIndexElement(this):e.visitChildren(this)}}I.IndexElementContext=rD;class LM extends ge.ParserRuleContext{indexElement(e){return e===void 0?this.getRuleContexts(rD):this.getRuleContext(e,rD)}COMMA(e){return e===void 0?this.getTokens(d.COMMA):this.getToken(d.COMMA,e)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_indexFields}enterRule(e){e.enterIndexFields&&e.enterIndexFields(this)}exitRule(e){e.exitIndexFields&&e.exitIndexFields(this)}accept(e){return e.visitIndexFields?e.visitIndexFields(this):e.visitChildren(this)}}I.IndexFieldsContext=LM;class IM extends ge.ParserRuleContext{INDEX(){return this.getToken(d.INDEX,0)}indexFields(){return this.getRuleContext(0,LM)}BY(){return this.tryGetToken(d.BY,0)}fieldName(){return this.tryGetRuleContext(0,Gr)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_indexStatement}enterRule(e){e.enterIndexStatement&&e.enterIndexStatement(this)}exitRule(e){e.exitIndexStatement&&e.exitIndexStatement(this)}accept(e){return e.visitIndexStatement?e.visitIndexStatement(this):e.visitChildren(this)}}I.IndexStatementContext=IM;class $M extends ge.ParserRuleContext{SAMPLE(){return this.getToken(d.SAMPLE,0)}sampleSpec(){return this.getRuleContext(0,kM)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_sampleStatement}enterRule(e){e.enterSampleStatement&&e.enterSampleStatement(this)}exitRule(e){e.exitSampleStatement&&e.exitSampleStatement(this)}accept(e){return e.visitSampleStatement?e.visitSampleStatement(this):e.visitChildren(this)}}I.SampleStatementContext=$M;class iD extends ge.ParserRuleContext{TIMEZONE(){return this.getToken(d.TIMEZONE,0)}string(){return this.getRuleContext(0,za)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_timezoneStatement}enterRule(e){e.enterTimezoneStatement&&e.enterTimezoneStatement(this)}exitRule(e){e.exitTimezoneStatement&&e.exitTimezoneStatement(this)}accept(e){return e.visitTimezoneStatement?e.visitTimezoneStatement(this):e.visitChildren(this)}}I.TimezoneStatementContext=iD;class BM extends ge.ParserRuleContext{ANNOTATION(){return this.getToken(d.ANNOTATION,0)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_queryAnnotation}enterRule(e){e.enterQueryAnnotation&&e.enterQueryAnnotation(this)}exitRule(e){e.exitQueryAnnotation&&e.exitQueryAnnotation(this)}accept(e){return e.visitQueryAnnotation?e.visitQueryAnnotation(this):e.visitChildren(this)}}I.QueryAnnotationContext=BM;class kM extends ge.ParserRuleContext{PERCENT_LITERAL(){return this.tryGetToken(d.PERCENT_LITERAL,0)}INTEGER_LITERAL(){return this.tryGetToken(d.INTEGER_LITERAL,0)}TRUE(){return this.tryGetToken(d.TRUE,0)}FALSE(){return this.tryGetToken(d.FALSE,0)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_sampleSpec}enterRule(e){e.enterSampleSpec&&e.enterSampleSpec(this)}exitRule(e){e.exitSampleSpec&&e.exitSampleSpec(this)}accept(e){return e.visitSampleSpec?e.visitSampleSpec(this):e.visitChildren(this)}}I.SampleSpecContext=kM;class zE extends ge.ParserRuleContext{SUM(){return this.tryGetToken(d.SUM,0)}COUNT(){return this.tryGetToken(d.COUNT,0)}AVG(){return this.tryGetToken(d.AVG,0)}MIN(){return this.tryGetToken(d.MIN,0)}MAX(){return this.tryGetToken(d.MAX,0)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_aggregate}enterRule(e){e.enterAggregate&&e.enterAggregate(this)}exitRule(e){e.exitAggregate&&e.exitAggregate(this)}accept(e){return e.visitAggregate?e.visitAggregate(this):e.visitChildren(this)}}I.AggregateContext=zE;class WE extends ge.ParserRuleContext{STRING(){return this.tryGetToken(d.STRING,0)}NUMBER(){return this.tryGetToken(d.NUMBER,0)}BOOLEAN(){return this.tryGetToken(d.BOOLEAN,0)}DATE(){return this.tryGetToken(d.DATE,0)}TIMESTAMP(){return this.tryGetToken(d.TIMESTAMP,0)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_malloyType}enterRule(e){e.enterMalloyType&&e.enterMalloyType(this)}exitRule(e){e.exitMalloyType&&e.exitMalloyType(this)}accept(e){return e.visitMalloyType?e.visitMalloyType(this):e.visitChildren(this)}}I.MalloyTypeContext=WE;class sD extends ge.ParserRuleContext{MATCH(){return this.tryGetToken(d.MATCH,0)}NOT_MATCH(){return this.tryGetToken(d.NOT_MATCH,0)}GT(){return this.tryGetToken(d.GT,0)}LT(){return this.tryGetToken(d.LT,0)}GTE(){return this.tryGetToken(d.GTE,0)}LTE(){return this.tryGetToken(d.LTE,0)}EQ(){return this.tryGetToken(d.EQ,0)}NE(){return this.tryGetToken(d.NE,0)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_compareOp}enterRule(e){e.enterCompareOp&&e.enterCompareOp(this)}exitRule(e){e.exitCompareOp&&e.exitCompareOp(this)}accept(e){return e.visitCompareOp?e.visitCompareOp(this):e.visitChildren(this)}}I.CompareOpContext=sD;class za extends ge.ParserRuleContext{shortString(){return this.tryGetRuleContext(0,oD)}sqlString(){return this.tryGetRuleContext(0,bR)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_string}enterRule(e){e.enterString&&e.enterString(this)}exitRule(e){e.exitString&&e.exitString(this)}accept(e){return e.visitString?e.visitString(this):e.visitChildren(this)}}I.StringContext=za;class oD extends ge.ParserRuleContext{SQ_STRING(){return this.tryGetToken(d.SQ_STRING,0)}DQ_STRING(){return this.tryGetToken(d.DQ_STRING,0)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_shortString}enterRule(e){e.enterShortString&&e.enterShortString(this)}exitRule(e){e.exitShortString&&e.exitShortString(this)}accept(e){return e.visitShortString?e.visitShortString(this):e.visitChildren(this)}}I.ShortStringContext=oD;class MM extends ge.ParserRuleContext{RAW_SQ(){return this.tryGetToken(d.RAW_SQ,0)}RAW_DQ(){return this.tryGetToken(d.RAW_DQ,0)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_rawString}enterRule(e){e.enterRawString&&e.enterRawString(this)}exitRule(e){e.exitRawString&&e.exitRawString(this)}accept(e){return e.visitRawString?e.visitRawString(this):e.visitChildren(this)}}I.RawStringContext=MM;class PM extends ge.ParserRuleContext{NUMERIC_LITERAL(){return this.tryGetToken(d.NUMERIC_LITERAL,0)}INTEGER_LITERAL(){return this.tryGetToken(d.INTEGER_LITERAL,0)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_numericLiteral}enterRule(e){e.enterNumericLiteral&&e.enterNumericLiteral(this)}exitRule(e){e.exitNumericLiteral&&e.exitNumericLiteral(this)}accept(e){return e.visitNumericLiteral?e.visitNumericLiteral(this):e.visitChildren(this)}}I.NumericLiteralContext=PM;class Oo extends ge.ParserRuleContext{constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_literal}copyFrom(e){super.copyFrom(e)}}I.LiteralContext=Oo;class Lfe extends Oo{string(){return this.getRuleContext(0,za)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprString&&e.enterExprString(this)}exitRule(e){e.exitExprString&&e.exitExprString(this)}accept(e){return e.visitExprString?e.visitExprString(this):e.visitChildren(this)}}I.ExprStringContext=Lfe;class Ife extends Oo{rawString(){return this.getRuleContext(0,MM)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterStub_rawString&&e.enterStub_rawString(this)}exitRule(e){e.exitStub_rawString&&e.exitStub_rawString(this)}accept(e){return e.visitStub_rawString?e.visitStub_rawString(this):e.visitChildren(this)}}I.Stub_rawStringContext=Ife;class $fe extends Oo{numericLiteral(){return this.getRuleContext(0,PM)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprNumber&&e.enterExprNumber(this)}exitRule(e){e.exitExprNumber&&e.exitExprNumber(this)}accept(e){return e.visitExprNumber?e.visitExprNumber(this):e.visitChildren(this)}}I.ExprNumberContext=$fe;class Bfe extends Oo{dateLiteral(){return this.getRuleContext(0,Wa)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprTime&&e.enterExprTime(this)}exitRule(e){e.exitExprTime&&e.exitExprTime(this)}accept(e){return e.visitExprTime?e.visitExprTime(this):e.visitChildren(this)}}I.ExprTimeContext=Bfe;class kfe extends Oo{NULL(){return this.getToken(d.NULL,0)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprNULL&&e.enterExprNULL(this)}exitRule(e){e.exitExprNULL&&e.exitExprNULL(this)}accept(e){return e.visitExprNULL?e.visitExprNULL(this):e.visitChildren(this)}}I.ExprNULLContext=kfe;class Mfe extends Oo{TRUE(){return this.tryGetToken(d.TRUE,0)}FALSE(){return this.tryGetToken(d.FALSE,0)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprBool&&e.enterExprBool(this)}exitRule(e){e.exitExprBool&&e.exitExprBool(this)}accept(e){return e.visitExprBool?e.visitExprBool(this):e.visitChildren(this)}}I.ExprBoolContext=Mfe;class Pfe extends Oo{HACKY_REGEX(){return this.getToken(d.HACKY_REGEX,0)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprRegex&&e.enterExprRegex(this)}exitRule(e){e.exitExprRegex&&e.exitExprRegex(this)}accept(e){return e.visitExprRegex?e.visitExprRegex(this):e.visitChildren(this)}}I.ExprRegexContext=Pfe;class Ufe extends Oo{filterString(){return this.getRuleContext(0,ZM)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterFilterString_stub&&e.enterFilterString_stub(this)}exitRule(e){e.exitFilterString_stub&&e.exitFilterString_stub(this)}accept(e){return e.visitFilterString_stub?e.visitFilterString_stub(this):e.visitChildren(this)}}I.FilterString_stubContext=Ufe;class jfe extends Oo{NOW(){return this.getToken(d.NOW,0)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprNow&&e.enterExprNow(this)}exitRule(e){e.exitExprNow&&e.exitExprNow(this)}accept(e){return e.visitExprNow?e.visitExprNow(this):e.visitChildren(this)}}I.ExprNowContext=jfe;class Wa extends ge.ParserRuleContext{constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_dateLiteral}copyFrom(e){super.copyFrom(e)}}I.DateLiteralContext=Wa;class qfe extends Wa{LITERAL_TIMESTAMP(){return this.getToken(d.LITERAL_TIMESTAMP,0)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterLiteralTimestamp&&e.enterLiteralTimestamp(this)}exitRule(e){e.exitLiteralTimestamp&&e.exitLiteralTimestamp(this)}accept(e){return e.visitLiteralTimestamp?e.visitLiteralTimestamp(this):e.visitChildren(this)}}I.LiteralTimestampContext=qfe;class Hfe extends Wa{LITERAL_HOUR(){return this.getToken(d.LITERAL_HOUR,0)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterLiteralHour&&e.enterLiteralHour(this)}exitRule(e){e.exitLiteralHour&&e.exitLiteralHour(this)}accept(e){return e.visitLiteralHour?e.visitLiteralHour(this):e.visitChildren(this)}}I.LiteralHourContext=Hfe;class Qfe extends Wa{LITERAL_DAY(){return this.getToken(d.LITERAL_DAY,0)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterLiteralDay&&e.enterLiteralDay(this)}exitRule(e){e.exitLiteralDay&&e.exitLiteralDay(this)}accept(e){return e.visitLiteralDay?e.visitLiteralDay(this):e.visitChildren(this)}}I.LiteralDayContext=Qfe;class zfe extends Wa{LITERAL_WEEK(){return this.getToken(d.LITERAL_WEEK,0)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterLiteralWeek&&e.enterLiteralWeek(this)}exitRule(e){e.exitLiteralWeek&&e.exitLiteralWeek(this)}accept(e){return e.visitLiteralWeek?e.visitLiteralWeek(this):e.visitChildren(this)}}I.LiteralWeekContext=zfe;class Wfe extends Wa{LITERAL_MONTH(){return this.getToken(d.LITERAL_MONTH,0)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterLiteralMonth&&e.enterLiteralMonth(this)}exitRule(e){e.exitLiteralMonth&&e.exitLiteralMonth(this)}accept(e){return e.visitLiteralMonth?e.visitLiteralMonth(this):e.visitChildren(this)}}I.LiteralMonthContext=Wfe;class Gfe extends Wa{LITERAL_QUARTER(){return this.getToken(d.LITERAL_QUARTER,0)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterLiteralQuarter&&e.enterLiteralQuarter(this)}exitRule(e){e.exitLiteralQuarter&&e.exitLiteralQuarter(this)}accept(e){return e.visitLiteralQuarter?e.visitLiteralQuarter(this):e.visitChildren(this)}}I.LiteralQuarterContext=Gfe;class Vfe extends Wa{LITERAL_YEAR(){return this.getToken(d.LITERAL_YEAR,0)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterLiteralYear&&e.enterLiteralYear(this)}exitRule(e){e.exitLiteralYear&&e.exitLiteralYear(this)}accept(e){return e.visitLiteralYear?e.visitLiteralYear(this):e.visitChildren(this)}}I.LiteralYearContext=Vfe;class UM extends ge.ParserRuleContext{string(){return this.getRuleContext(0,za)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_tablePath}enterRule(e){e.enterTablePath&&e.enterTablePath(this)}exitRule(e){e.exitTablePath&&e.exitTablePath(this)}accept(e){return e.visitTablePath?e.visitTablePath(this):e.visitChildren(this)}}I.TablePathContext=UM;class Yfe extends ge.ParserRuleContext{string(){return this.getRuleContext(0,za)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_tableURI}enterRule(e){e.enterTableURI&&e.enterTableURI(this)}exitRule(e){e.exitTableURI&&e.exitTableURI(this)}accept(e){return e.visitTableURI?e.visitTableURI(this):e.visitChildren(this)}}I.TableURIContext=Yfe;class Nn extends ge.ParserRuleContext{IDENTIFIER(){return this.tryGetToken(d.IDENTIFIER,0)}BQ_STRING(){return this.tryGetToken(d.BQ_STRING,0)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_id}enterRule(e){e.enterId&&e.enterId(this)}exitRule(e){e.exitId&&e.exitId(this)}accept(e){return e.visitId?e.visitId(this):e.visitChildren(this)}}I.IdContext=Nn;class Ld extends ge.ParserRuleContext{SECOND(){return this.tryGetToken(d.SECOND,0)}MINUTE(){return this.tryGetToken(d.MINUTE,0)}HOUR(){return this.tryGetToken(d.HOUR,0)}DAY(){return this.tryGetToken(d.DAY,0)}WEEK(){return this.tryGetToken(d.WEEK,0)}MONTH(){return this.tryGetToken(d.MONTH,0)}QUARTER(){return this.tryGetToken(d.QUARTER,0)}YEAR(){return this.tryGetToken(d.YEAR,0)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_timeframe}enterRule(e){e.enterTimeframe&&e.enterTimeframe(this)}exitRule(e){e.exitTimeframe&&e.exitTimeframe(this)}accept(e){return e.visitTimeframe?e.visitTimeframe(this):e.visitChildren(this)}}I.TimeframeContext=Ld;class jM extends ge.ParserRuleContext{ALL(){return this.tryGetToken(d.ALL,0)}EXCLUDE(){return this.tryGetToken(d.EXCLUDE,0)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_ungroup}enterRule(e){e.enterUngroup&&e.enterUngroup(this)}exitRule(e){e.exitUngroup&&e.exitUngroup(this)}accept(e){return e.visitUngroup?e.visitUngroup(this):e.visitChildren(this)}}I.UngroupContext=jM;class uD extends ge.ParserRuleContext{malloyType(){return this.tryGetRuleContext(0,WE)}string(){return this.tryGetRuleContext(0,za)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_malloyOrSQLType}enterRule(e){e.enterMalloyOrSQLType&&e.enterMalloyOrSQLType(this)}exitRule(e){e.exitMalloyOrSQLType&&e.exitMalloyOrSQLType(this)}accept(e){return e.visitMalloyOrSQLType?e.visitMalloyOrSQLType(this):e.visitChildren(this)}}I.MalloyOrSQLTypeContext=uD;class Re extends ge.ParserRuleContext{constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_fieldExpr}copyFrom(e){super.copyFrom(e)}}I.FieldExprContext=Re;class Kfe extends Re{fieldPath(){return this.getRuleContext(0,Ga)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprFieldPath&&e.enterExprFieldPath(this)}exitRule(e){e.exitExprFieldPath&&e.exitExprFieldPath(this)}accept(e){return e.visitExprFieldPath?e.visitExprFieldPath(this):e.visitChildren(this)}}I.ExprFieldPathContext=Kfe;class Jfe extends Re{literal(){return this.getRuleContext(0,Oo)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprLiteral&&e.enterExprLiteral(this)}exitRule(e){e.exitExprLiteral&&e.exitExprLiteral(this)}accept(e){return e.visitExprLiteral?e.visitExprLiteral(this):e.visitChildren(this)}}I.ExprLiteralContext=Jfe;class Xfe extends Re{OBRACK(){return this.getToken(d.OBRACK,0)}fieldExpr(e){return e===void 0?this.getRuleContexts(Re):this.getRuleContext(e,Re)}CBRACK(){return this.getToken(d.CBRACK,0)}COMMA(e){return e===void 0?this.getTokens(d.COMMA):this.getToken(d.COMMA,e)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprArrayLiteral&&e.enterExprArrayLiteral(this)}exitRule(e){e.exitExprArrayLiteral&&e.exitExprArrayLiteral(this)}accept(e){return e.visitExprArrayLiteral?e.visitExprArrayLiteral(this):e.visitChildren(this)}}I.ExprArrayLiteralContext=Xfe;class Zfe extends Re{OCURLY(){return this.getToken(d.OCURLY,0)}recordElement(e){return e===void 0?this.getRuleContexts(t1):this.getRuleContext(e,t1)}CCURLY(){return this.getToken(d.CCURLY,0)}COMMA(e){return e===void 0?this.getTokens(d.COMMA):this.getToken(d.COMMA,e)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprLiteralRecord&&e.enterExprLiteralRecord(this)}exitRule(e){e.exitExprLiteralRecord&&e.exitExprLiteralRecord(this)}accept(e){return e.visitExprLiteralRecord?e.visitExprLiteralRecord(this):e.visitChildren(this)}}I.ExprLiteralRecordContext=Zfe;class exe extends Re{fieldExpr(){return this.getRuleContext(0,Re)}fieldProperties(){return this.getRuleContext(0,mM)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprFieldProps&&e.enterExprFieldProps(this)}exitRule(e){e.exitExprFieldProps&&e.exitExprFieldProps(this)}accept(e){return e.visitExprFieldProps?e.visitExprFieldProps(this):e.visitChildren(this)}}I.ExprFieldPropsContext=exe;class txe extends Re{fieldExpr(){return this.getRuleContext(0,Re)}timeframe(){return this.getRuleContext(0,Ld)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprDuration&&e.enterExprDuration(this)}exitRule(e){e.exitExprDuration&&e.exitExprDuration(this)}accept(e){return e.visitExprDuration?e.visitExprDuration(this):e.visitChildren(this)}}I.ExprDurationContext=txe;class nxe extends Re{fieldExpr(){return this.getRuleContext(0,Re)}DOT(){return this.getToken(d.DOT,0)}timeframe(){return this.getRuleContext(0,Ld)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprTimeTrunc&&e.enterExprTimeTrunc(this)}exitRule(e){e.exitExprTimeTrunc&&e.exitExprTimeTrunc(this)}accept(e){return e.visitExprTimeTrunc?e.visitExprTimeTrunc(this):e.visitChildren(this)}}I.ExprTimeTruncContext=nxe;class qM extends Re{fieldExpr(){return this.getRuleContext(0,Re)}DOUBLECOLON(){return this.tryGetToken(d.DOUBLECOLON,0)}malloyOrSQLType(){return this.getRuleContext(0,uD)}CAST(){return this.tryGetToken(d.CAST,0)}OPAREN(){return this.tryGetToken(d.OPAREN,0)}AS(){return this.tryGetToken(d.AS,0)}CPAREN(){return this.tryGetToken(d.CPAREN,0)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprCast&&e.enterExprCast(this)}exitRule(e){e.exitExprCast&&e.exitExprCast(this)}accept(e){return e.visitExprCast?e.visitExprCast(this):e.visitChildren(this)}}I.ExprCastContext=qM;class rxe extends Re{fieldExpr(){return this.getRuleContext(0,Re)}TRIPLECOLON(){return this.getToken(d.TRIPLECOLON,0)}malloyOrSQLType(){return this.getRuleContext(0,uD)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprSafeCast&&e.enterExprSafeCast(this)}exitRule(e){e.exitExprSafeCast&&e.exitExprSafeCast(this)}accept(e){return e.visitExprSafeCast?e.visitExprSafeCast(this):e.visitChildren(this)}}I.ExprSafeCastContext=rxe;class ixe extends Re{MINUS(){return this.getToken(d.MINUS,0)}fieldExpr(){return this.getRuleContext(0,Re)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprMinus&&e.enterExprMinus(this)}exitRule(e){e.exitExprMinus&&e.exitExprMinus(this)}accept(e){return e.visitExprMinus?e.visitExprMinus(this):e.visitChildren(this)}}I.ExprMinusContext=ixe;class sxe extends Re{fieldExpr(e){return e===void 0?this.getRuleContexts(Re):this.getRuleContext(e,Re)}STAR(){return this.tryGetToken(d.STAR,0)}SLASH(){return this.tryGetToken(d.SLASH,0)}PERCENT(){return this.tryGetToken(d.PERCENT,0)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprMulDiv&&e.enterExprMulDiv(this)}exitRule(e){e.exitExprMulDiv&&e.exitExprMulDiv(this)}accept(e){return e.visitExprMulDiv?e.visitExprMulDiv(this):e.visitChildren(this)}}I.ExprMulDivContext=sxe;class oxe extends Re{fieldExpr(e){return e===void 0?this.getRuleContexts(Re):this.getRuleContext(e,Re)}PLUS(){return this.tryGetToken(d.PLUS,0)}MINUS(){return this.tryGetToken(d.MINUS,0)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprAddSub&&e.enterExprAddSub(this)}exitRule(e){e.exitExprAddSub&&e.exitExprAddSub(this)}accept(e){return e.visitExprAddSub?e.visitExprAddSub(this):e.visitChildren(this)}}I.ExprAddSubContext=oxe;class uxe extends Re{fieldExpr(e){return e===void 0?this.getRuleContexts(Re):this.getRuleContext(e,Re)}TO(){return this.getToken(d.TO,0)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprRange&&e.enterExprRange(this)}exitRule(e){e.exitExprRange&&e.exitExprRange(this)}accept(e){return e.visitExprRange?e.visitExprRange(this):e.visitChildren(this)}}I.ExprRangeContext=uxe;class axe extends Re{FOR(){return this.getToken(d.FOR,0)}timeframe(){return this.getRuleContext(0,Ld)}fieldExpr(e){return e===void 0?this.getRuleContexts(Re):this.getRuleContext(e,Re)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprForRange&&e.enterExprForRange(this)}exitRule(e){e.exitExprForRange&&e.exitExprForRange(this)}accept(e){return e.visitExprForRange?e.visitExprForRange(this):e.visitChildren(this)}}I.ExprForRangeContext=axe;class lxe extends Re{fieldExpr(){return this.getRuleContext(0,Re)}AMPER(){return this.getToken(d.AMPER,0)}partialAllowedFieldExpr(){return this.getRuleContext(0,Id)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprAndTree&&e.enterExprAndTree(this)}exitRule(e){e.exitExprAndTree&&e.exitExprAndTree(this)}accept(e){return e.visitExprAndTree?e.visitExprAndTree(this):e.visitChildren(this)}}I.ExprAndTreeContext=lxe;class cxe extends Re{fieldExpr(){return this.getRuleContext(0,Re)}BAR(){return this.getToken(d.BAR,0)}partialAllowedFieldExpr(){return this.getRuleContext(0,Id)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprOrTree&&e.enterExprOrTree(this)}exitRule(e){e.exitExprOrTree&&e.exitExprOrTree(this)}accept(e){return e.visitExprOrTree?e.visitExprOrTree(this):e.visitChildren(this)}}I.ExprOrTreeContext=cxe;class fxe extends Re{fieldExpr(e){return e===void 0?this.getRuleContexts(Re):this.getRuleContext(e,Re)}compareOp(){return this.getRuleContext(0,sD)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprCompare&&e.enterExprCompare(this)}exitRule(e){e.exitExprCompare&&e.exitExprCompare(this)}accept(e){return e.visitExprCompare?e.visitExprCompare(this):e.visitChildren(this)}}I.ExprCompareContext=fxe;class xxe extends Re{fieldExpr(e){return e===void 0?this.getRuleContexts(Re):this.getRuleContext(e,Re)}LIKE(){return this.getToken(d.LIKE,0)}NOT(){return this.tryGetToken(d.NOT,0)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprWarnLike&&e.enterExprWarnLike(this)}exitRule(e){e.exitExprWarnLike&&e.exitExprWarnLike(this)}accept(e){return e.visitExprWarnLike?e.visitExprWarnLike(this):e.visitChildren(this)}}I.ExprWarnLikeContext=xxe;class dxe extends Re{fieldExpr(){return this.getRuleContext(0,Re)}IS(){return this.getToken(d.IS,0)}NULL(){return this.getToken(d.NULL,0)}NOT(){return this.tryGetToken(d.NOT,0)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprNullCheck&&e.enterExprNullCheck(this)}exitRule(e){e.exitExprNullCheck&&e.exitExprNullCheck(this)}accept(e){return e.visitExprNullCheck?e.visitExprNullCheck(this):e.visitChildren(this)}}I.ExprNullCheckContext=dxe;class hxe extends Re{fieldExpr(){return this.getRuleContext(0,Re)}IN(){return this.getToken(d.IN,0)}OPAREN(){return this.getToken(d.OPAREN,0)}fieldExprList(){return this.getRuleContext(0,zM)}CPAREN(){return this.getToken(d.CPAREN,0)}NOT(){return this.tryGetToken(d.NOT,0)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprWarnIn&&e.enterExprWarnIn(this)}exitRule(e){e.exitExprWarnIn&&e.exitExprWarnIn(this)}accept(e){return e.visitExprWarnIn?e.visitExprWarnIn(this):e.visitChildren(this)}}I.ExprWarnInContext=hxe;class pxe extends Re{fieldExpr(){return this.getRuleContext(0,Re)}QMARK(){return this.getToken(d.QMARK,0)}partialAllowedFieldExpr(){return this.getRuleContext(0,Id)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprApply&&e.enterExprApply(this)}exitRule(e){e.exitExprApply&&e.exitExprApply(this)}accept(e){return e.visitExprApply?e.visitExprApply(this):e.visitChildren(this)}}I.ExprApplyContext=pxe;class mxe extends Re{NOT(){return this.getToken(d.NOT,0)}fieldExpr(){return this.getRuleContext(0,Re)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprNot&&e.enterExprNot(this)}exitRule(e){e.exitExprNot&&e.exitExprNot(this)}accept(e){return e.visitExprNot?e.visitExprNot(this):e.visitChildren(this)}}I.ExprNotContext=mxe;class gxe extends Re{fieldExpr(e){return e===void 0?this.getRuleContexts(Re):this.getRuleContext(e,Re)}AND(){return this.getToken(d.AND,0)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprLogicalAnd&&e.enterExprLogicalAnd(this)}exitRule(e){e.exitExprLogicalAnd&&e.exitExprLogicalAnd(this)}accept(e){return e.visitExprLogicalAnd?e.visitExprLogicalAnd(this):e.visitChildren(this)}}I.ExprLogicalAndContext=gxe;class yxe extends Re{fieldExpr(e){return e===void 0?this.getRuleContexts(Re):this.getRuleContext(e,Re)}OR(){return this.getToken(d.OR,0)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprLogicalOr&&e.enterExprLogicalOr(this)}exitRule(e){e.exitExprLogicalOr&&e.exitExprLogicalOr(this)}accept(e){return e.visitExprLogicalOr?e.visitExprLogicalOr(this):e.visitChildren(this)}}I.ExprLogicalOrContext=yxe;class Exe extends Re{fieldExpr(e){return e===void 0?this.getRuleContexts(Re):this.getRuleContext(e,Re)}DOUBLE_QMARK(){return this.getToken(d.DOUBLE_QMARK,0)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprCoalesce&&e.enterExprCoalesce(this)}exitRule(e){e.exitExprCoalesce&&e.exitExprCoalesce(this)}accept(e){return e.visitExprCoalesce?e.visitExprCoalesce(this):e.visitChildren(this)}}I.ExprCoalesceContext=Exe;class Axe extends Re{aggregate(){return this.getRuleContext(0,zE)}OPAREN(){return this.getToken(d.OPAREN,0)}CPAREN(){return this.getToken(d.CPAREN,0)}SOURCE_KW(){return this.tryGetToken(d.SOURCE_KW,0)}DOT(){return this.tryGetToken(d.DOT,0)}fieldExpr(){return this.tryGetRuleContext(0,Re)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprPathlessAggregate&&e.enterExprPathlessAggregate(this)}exitRule(e){e.exitExprPathlessAggregate&&e.exitExprPathlessAggregate(this)}accept(e){return e.visitExprPathlessAggregate?e.visitExprPathlessAggregate(this):e.visitChildren(this)}}I.ExprPathlessAggregateContext=Axe;class _xe extends Re{fieldPath(){return this.getRuleContext(0,Ga)}DOT(){return this.getToken(d.DOT,0)}aggregate(){return this.getRuleContext(0,zE)}OPAREN(){return this.getToken(d.OPAREN,0)}CPAREN(){return this.getToken(d.CPAREN,0)}fieldExpr(){return this.tryGetRuleContext(0,Re)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprAggregate&&e.enterExprAggregate(this)}exitRule(e){e.exitExprAggregate&&e.exitExprAggregate(this)}accept(e){return e.visitExprAggregate?e.visitExprAggregate(this):e.visitChildren(this)}}I.ExprAggregateContext=_xe;class vxe extends Re{OPAREN(){return this.getToken(d.OPAREN,0)}fieldExpr(){return this.getRuleContext(0,Re)}CPAREN(){return this.getToken(d.CPAREN,0)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprExpr&&e.enterExprExpr(this)}exitRule(e){e.exitExprExpr&&e.exitExprExpr(this)}accept(e){return e.visitExprExpr?e.visitExprExpr(this):e.visitChildren(this)}}I.ExprExprContext=vxe;class Cxe extends Re{fieldPath(){return this.getRuleContext(0,Ga)}DOT(){return this.getToken(d.DOT,0)}id(){return this.getRuleContext(0,Nn)}OPAREN(){return this.getToken(d.OPAREN,0)}CPAREN(){return this.getToken(d.CPAREN,0)}argumentList(){return this.tryGetRuleContext(0,cD)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprAggFunc&&e.enterExprAggFunc(this)}exitRule(e){e.exitExprAggFunc&&e.exitExprAggFunc(this)}accept(e){return e.visitExprAggFunc?e.visitExprAggFunc(this):e.visitChildren(this)}}I.ExprAggFuncContext=Cxe;class Sxe extends Re{OPAREN(){return this.getToken(d.OPAREN,0)}CPAREN(){return this.getToken(d.CPAREN,0)}timeframe(){return this.tryGetRuleContext(0,Ld)}id(){return this.tryGetRuleContext(0,Nn)}argumentList(){return this.tryGetRuleContext(0,cD)}EXCLAM(){return this.tryGetToken(d.EXCLAM,0)}malloyType(){return this.tryGetRuleContext(0,WE)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprFunc&&e.enterExprFunc(this)}exitRule(e){e.exitExprFunc&&e.exitExprFunc(this)}accept(e){return e.visitExprFunc?e.visitExprFunc(this):e.visitChildren(this)}}I.ExprFuncContext=Sxe;class bxe extends Re{pickStatement(){return this.getRuleContext(0,WM)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprPick&&e.enterExprPick(this)}exitRule(e){e.exitExprPick&&e.exitExprPick(this)}accept(e){return e.visitExprPick?e.visitExprPick(this):e.visitChildren(this)}}I.ExprPickContext=bxe;class Txe extends Re{caseStatement(){return this.getRuleContext(0,GM)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprCase&&e.enterExprCase(this)}exitRule(e){e.exitExprCase&&e.exitExprCase(this)}accept(e){return e.visitExprCase?e.visitExprCase(this):e.visitChildren(this)}}I.ExprCaseContext=Txe;class Rxe extends Re{ungroup(){return this.getRuleContext(0,jM)}OPAREN(){return this.getToken(d.OPAREN,0)}fieldExpr(){return this.getRuleContext(0,Re)}CPAREN(){return this.getToken(d.CPAREN,0)}COMMA(e){return e===void 0?this.getTokens(d.COMMA):this.getToken(d.COMMA,e)}fieldName(e){return e===void 0?this.getRuleContexts(Gr):this.getRuleContext(e,Gr)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterExprUngroup&&e.enterExprUngroup(this)}exitRule(e){e.exitExprUngroup&&e.exitExprUngroup(this)}accept(e){return e.visitExprUngroup?e.visitExprUngroup(this):e.visitChildren(this)}}I.ExprUngroupContext=Rxe;class HM extends ge.ParserRuleContext{compareOp(){return this.getRuleContext(0,sD)}fieldExpr(){return this.getRuleContext(0,Re)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_partialCompare}enterRule(e){e.enterPartialCompare&&e.enterPartialCompare(this)}exitRule(e){e.exitPartialCompare&&e.exitPartialCompare(this)}accept(e){return e.visitPartialCompare?e.visitPartialCompare(this):e.visitChildren(this)}}I.PartialCompareContext=HM;class QM extends ge.ParserRuleContext{partialCompare(){return this.tryGetRuleContext(0,HM)}IS(){return this.tryGetToken(d.IS,0)}NULL(){return this.tryGetToken(d.NULL,0)}NOT(){return this.tryGetToken(d.NOT,0)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_partialTest}enterRule(e){e.enterPartialTest&&e.enterPartialTest(this)}exitRule(e){e.exitPartialTest&&e.exitPartialTest(this)}accept(e){return e.visitPartialTest?e.visitPartialTest(this):e.visitChildren(this)}}I.PartialTestContext=QM;class Id extends ge.ParserRuleContext{partialTest(){return this.tryGetRuleContext(0,QM)}OPAREN(){return this.tryGetToken(d.OPAREN,0)}CPAREN(){return this.tryGetToken(d.CPAREN,0)}fieldExpr(){return this.tryGetRuleContext(0,Re)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_partialAllowedFieldExpr}enterRule(e){e.enterPartialAllowedFieldExpr&&e.enterPartialAllowedFieldExpr(this)}exitRule(e){e.exitPartialAllowedFieldExpr&&e.exitPartialAllowedFieldExpr(this)}accept(e){return e.visitPartialAllowedFieldExpr?e.visitPartialAllowedFieldExpr(this):e.visitChildren(this)}}I.PartialAllowedFieldExprContext=Id;class zM extends ge.ParserRuleContext{fieldExpr(e){return e===void 0?this.getRuleContexts(Re):this.getRuleContext(e,Re)}COMMA(e){return e===void 0?this.getTokens(d.COMMA):this.getToken(d.COMMA,e)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_fieldExprList}enterRule(e){e.enterFieldExprList&&e.enterFieldExprList(this)}exitRule(e){e.exitFieldExprList&&e.exitFieldExprList(this)}accept(e){return e.visitFieldExprList?e.visitFieldExprList(this):e.visitChildren(this)}}I.FieldExprListContext=zM;class WM extends ge.ParserRuleContext{pick(e){return e===void 0?this.getRuleContexts(aD):this.getRuleContext(e,aD)}ELSE(){return this.tryGetToken(d.ELSE,0)}fieldExpr(){return this.tryGetRuleContext(0,Re)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_pickStatement}enterRule(e){e.enterPickStatement&&e.enterPickStatement(this)}exitRule(e){e.exitPickStatement&&e.exitPickStatement(this)}accept(e){return e.visitPickStatement?e.visitPickStatement(this):e.visitChildren(this)}}I.PickStatementContext=WM;class aD extends ge.ParserRuleContext{PICK(){return this.getToken(d.PICK,0)}WHEN(){return this.getToken(d.WHEN,0)}partialAllowedFieldExpr(){return this.getRuleContext(0,Id)}fieldExpr(){return this.tryGetRuleContext(0,Re)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_pick}enterRule(e){e.enterPick&&e.enterPick(this)}exitRule(e){e.exitPick&&e.exitPick(this)}accept(e){return e.visitPick?e.visitPick(this):e.visitChildren(this)}}I.PickContext=aD;class GM extends ge.ParserRuleContext{CASE(){return this.getToken(d.CASE,0)}END(){return this.getToken(d.END,0)}caseWhen(e){return e===void 0?this.getRuleContexts(lD):this.getRuleContext(e,lD)}ELSE(){return this.tryGetToken(d.ELSE,0)}fieldExpr(e){return e===void 0?this.getRuleContexts(Re):this.getRuleContext(e,Re)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_caseStatement}enterRule(e){e.enterCaseStatement&&e.enterCaseStatement(this)}exitRule(e){e.exitCaseStatement&&e.exitCaseStatement(this)}accept(e){return e.visitCaseStatement?e.visitCaseStatement(this):e.visitChildren(this)}}I.CaseStatementContext=GM;class lD extends ge.ParserRuleContext{WHEN(){return this.getToken(d.WHEN,0)}THEN(){return this.getToken(d.THEN,0)}fieldExpr(e){return e===void 0?this.getRuleContexts(Re):this.getRuleContext(e,Re)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_caseWhen}enterRule(e){e.enterCaseWhen&&e.enterCaseWhen(this)}exitRule(e){e.exitCaseWhen&&e.exitCaseWhen(this)}accept(e){return e.visitCaseWhen?e.visitCaseWhen(this):e.visitChildren(this)}}I.CaseWhenContext=lD;class VM extends ge.ParserRuleContext{id(){return this.getRuleContext(0,Nn)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_recordKey}enterRule(e){e.enterRecordKey&&e.enterRecordKey(this)}exitRule(e){e.exitRecordKey&&e.exitRecordKey(this)}accept(e){return e.visitRecordKey?e.visitRecordKey(this):e.visitChildren(this)}}I.RecordKeyContext=VM;class t1 extends ge.ParserRuleContext{constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_recordElement}copyFrom(e){super.copyFrom(e)}}I.RecordElementContext=t1;class Dxe extends t1{fieldPath(){return this.getRuleContext(0,Ga)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterRecordRef&&e.enterRecordRef(this)}exitRule(e){e.exitRecordRef&&e.exitRecordRef(this)}accept(e){return e.visitRecordRef?e.visitRecordRef(this):e.visitChildren(this)}}I.RecordRefContext=Dxe;class Oxe extends t1{fieldExpr(){return this.getRuleContext(0,Re)}recordKey(){return this.tryGetRuleContext(0,VM)}IS(){return this.tryGetToken(d.IS,0)}constructor(e){super(e.parent,e.invokingState),this.copyFrom(e)}enterRule(e){e.enterRecordExpr&&e.enterRecordExpr(this)}exitRule(e){e.exitRecordExpr&&e.exitRecordExpr(this)}accept(e){return e.visitRecordExpr?e.visitRecordExpr(this):e.visitChildren(this)}}I.RecordExprContext=Oxe;class cD extends ge.ParserRuleContext{fieldExpr(e){return e===void 0?this.getRuleContexts(Re):this.getRuleContext(e,Re)}COMMA(e){return e===void 0?this.getTokens(d.COMMA):this.getToken(d.COMMA,e)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_argumentList}enterRule(e){e.enterArgumentList&&e.enterArgumentList(this)}exitRule(e){e.exitArgumentList&&e.exitArgumentList(this)}accept(e){return e.visitArgumentList?e.visitArgumentList(this):e.visitChildren(this)}}I.ArgumentListContext=cD;class n1 extends ge.ParserRuleContext{fieldName(e){return e===void 0?this.getRuleContexts(Gr):this.getRuleContext(e,Gr)}COMMA(e){return e===void 0?this.getTokens(d.COMMA):this.getToken(d.COMMA,e)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_fieldNameList}enterRule(e){e.enterFieldNameList&&e.enterFieldNameList(this)}exitRule(e){e.exitFieldNameList&&e.exitFieldNameList(this)}accept(e){return e.visitFieldNameList?e.visitFieldNameList(this):e.visitChildren(this)}}I.FieldNameListContext=n1;class YM extends ge.ParserRuleContext{collectionMember(e){return e===void 0?this.getRuleContexts(dD):this.getRuleContext(e,dD)}COMMA(e){return e===void 0?this.getTokens(d.COMMA):this.getToken(d.COMMA,e)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_fieldCollection}enterRule(e){e.enterFieldCollection&&e.enterFieldCollection(this)}exitRule(e){e.exitFieldCollection&&e.exitFieldCollection(this)}accept(e){return e.visitFieldCollection?e.visitFieldCollection(this):e.visitChildren(this)}}I.FieldCollectionContext=YM;class GE extends ge.ParserRuleContext{STAR(){return this.getToken(d.STAR,0)}fieldPath(){return this.tryGetRuleContext(0,Ga)}DOT(){return this.tryGetToken(d.DOT,0)}starQualified(){return this.tryGetRuleContext(0,fD)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_collectionWildCard}enterRule(e){e.enterCollectionWildCard&&e.enterCollectionWildCard(this)}exitRule(e){e.exitCollectionWildCard&&e.exitCollectionWildCard(this)}accept(e){return e.visitCollectionWildCard?e.visitCollectionWildCard(this):e.visitChildren(this)}}I.CollectionWildCardContext=GE;class fD extends ge.ParserRuleContext{OCURLY(){return this.getToken(d.OCURLY,0)}CCURLY(){return this.getToken(d.CCURLY,0)}COMMA(e){return e===void 0?this.getTokens(d.COMMA):this.getToken(d.COMMA,e)}EXCEPT(e){return e===void 0?this.getTokens(d.EXCEPT):this.getToken(d.EXCEPT,e)}fieldNameList(e){return e===void 0?this.getRuleContexts(n1):this.getRuleContext(e,n1)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_starQualified}enterRule(e){e.enterStarQualified&&e.enterStarQualified(this)}exitRule(e){e.exitStarQualified&&e.exitStarQualified(this)}accept(e){return e.visitStarQualified?e.visitStarQualified(this):e.visitChildren(this)}}I.StarQualifiedContext=fD;class xD extends ge.ParserRuleContext{tags(){return this.getRuleContext(0,Xt)}fieldPath(){return this.getRuleContext(0,Ga)}refExpr(){return this.tryGetRuleContext(0,KM)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_taggedRef}enterRule(e){e.enterTaggedRef&&e.enterTaggedRef(this)}exitRule(e){e.exitTaggedRef&&e.exitTaggedRef(this)}accept(e){return e.visitTaggedRef?e.visitTaggedRef(this):e.visitChildren(this)}}I.TaggedRefContext=xD;class KM extends ge.ParserRuleContext{DOT(){return this.getToken(d.DOT,0)}timeframe(){return this.tryGetRuleContext(0,Ld)}aggregate(){return this.tryGetRuleContext(0,zE)}OPAREN(){return this.tryGetToken(d.OPAREN,0)}CPAREN(){return this.tryGetToken(d.CPAREN,0)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_refExpr}enterRule(e){e.enterRefExpr&&e.enterRefExpr(this)}exitRule(e){e.exitRefExpr&&e.exitRefExpr(this)}accept(e){return e.visitRefExpr?e.visitRefExpr(this):e.visitChildren(this)}}I.RefExprContext=KM;class dD extends ge.ParserRuleContext{taggedRef(){return this.tryGetRuleContext(0,xD)}collectionWildCard(){return this.tryGetRuleContext(0,GE)}fieldDef(){return this.tryGetRuleContext(0,Z2)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_collectionMember}enterRule(e){e.enterCollectionMember&&e.enterCollectionMember(this)}exitRule(e){e.exitCollectionMember&&e.exitCollectionMember(this)}accept(e){return e.visitCollectionMember?e.visitCollectionMember(this):e.visitChildren(this)}}I.CollectionMemberContext=dD;class Ga extends ge.ParserRuleContext{fieldName(e){return e===void 0?this.getRuleContexts(Gr):this.getRuleContext(e,Gr)}DOT(e){return e===void 0?this.getTokens(d.DOT):this.getToken(d.DOT,e)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_fieldPath}enterRule(e){e.enterFieldPath&&e.enterFieldPath(this)}exitRule(e){e.exitFieldPath&&e.exitFieldPath(this)}accept(e){return e.visitFieldPath?e.visitFieldPath(this):e.visitChildren(this)}}I.FieldPathContext=Ga;class Fxe extends ge.ParserRuleContext{id(){return this.getRuleContext(0,Nn)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_joinName}enterRule(e){e.enterJoinName&&e.enterJoinName(this)}exitRule(e){e.exitJoinName&&e.exitJoinName(this)}accept(e){return e.visitJoinName?e.visitJoinName(this):e.visitChildren(this)}}I.JoinNameContext=Fxe;class Gr extends ge.ParserRuleContext{id(){return this.getRuleContext(0,Nn)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_fieldName}enterRule(e){e.enterFieldName&&e.enterFieldName(this)}exitRule(e){e.exitFieldName&&e.exitFieldName(this)}accept(e){return e.visitFieldName?e.visitFieldName(this):e.visitChildren(this)}}I.FieldNameContext=Gr;class wxe extends ge.ParserRuleContext{id(){return this.getRuleContext(0,Nn)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_sqlExploreNameRef}enterRule(e){e.enterSqlExploreNameRef&&e.enterSqlExploreNameRef(this)}exitRule(e){e.exitSqlExploreNameRef&&e.exitSqlExploreNameRef(this)}accept(e){return e.visitSqlExploreNameRef?e.visitSqlExploreNameRef(this):e.visitChildren(this)}}I.SqlExploreNameRefContext=wxe;class Nxe extends ge.ParserRuleContext{id(){return this.getRuleContext(0,Nn)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_nameSQLBlock}enterRule(e){e.enterNameSQLBlock&&e.enterNameSQLBlock(this)}exitRule(e){e.exitNameSQLBlock&&e.exitNameSQLBlock(this)}accept(e){return e.visitNameSQLBlock?e.visitNameSQLBlock(this):e.visitChildren(this)}}I.NameSQLBlockContext=Nxe;class Lxe extends ge.ParserRuleContext{string(){return this.getRuleContext(0,za)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_connectionName}enterRule(e){e.enterConnectionName&&e.enterConnectionName(this)}exitRule(e){e.exitConnectionName&&e.exitConnectionName(this)}accept(e){return e.visitConnectionName?e.visitConnectionName(this):e.visitChildren(this)}}I.ConnectionNameContext=Lxe;class JM extends ge.ParserRuleContext{SQ3_FILTER(){return this.tryGetToken(d.SQ3_FILTER,0)}BQ3_FILTER(){return this.tryGetToken(d.BQ3_FILTER,0)}DQ3_FILTER(){return this.tryGetToken(d.DQ3_FILTER,0)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_tripFilterString}enterRule(e){e.enterTripFilterString&&e.enterTripFilterString(this)}exitRule(e){e.exitTripFilterString&&e.exitTripFilterString(this)}accept(e){return e.visitTripFilterString?e.visitTripFilterString(this):e.visitChildren(this)}}I.TripFilterStringContext=JM;class XM extends ge.ParserRuleContext{SQ_FILTER(){return this.tryGetToken(d.SQ_FILTER,0)}BQ_FILTER(){return this.tryGetToken(d.BQ_FILTER,0)}DQ_FILTER(){return this.tryGetToken(d.DQ_FILTER,0)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_tickFilterString}enterRule(e){e.enterTickFilterString&&e.enterTickFilterString(this)}exitRule(e){e.exitTickFilterString&&e.exitTickFilterString(this)}accept(e){return e.visitTickFilterString?e.visitTickFilterString(this):e.visitChildren(this)}}I.TickFilterStringContext=XM;class ZM extends ge.ParserRuleContext{tripFilterString(){return this.tryGetRuleContext(0,JM)}tickFilterString(){return this.tryGetRuleContext(0,XM)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_filterString}enterRule(e){e.enterFilterString&&e.enterFilterString(this)}exitRule(e){e.exitFilterString&&e.exitFilterString(this)}accept(e){return e.visitFilterString?e.visitFilterString(this):e.visitChildren(this)}}I.FilterStringContext=ZM;class Ixe extends ge.ParserRuleContext{fieldExpr(){return this.getRuleContext(0,Re)}EOF(){return this.getToken(d.EOF,0)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_debugExpr}enterRule(e){e.enterDebugExpr&&e.enterDebugExpr(this)}exitRule(e){e.exitDebugExpr&&e.exitDebugExpr(this)}accept(e){return e.visitDebugExpr?e.visitDebugExpr(this):e.visitChildren(this)}}I.DebugExprContext=Ixe;class $xe extends ge.ParserRuleContext{partialAllowedFieldExpr(){return this.getRuleContext(0,Id)}EOF(){return this.getToken(d.EOF,0)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_debugPartial}enterRule(e){e.enterDebugPartial&&e.enterDebugPartial(this)}exitRule(e){e.exitDebugPartial&&e.exitDebugPartial(this)}accept(e){return e.visitDebugPartial?e.visitDebugPartial(this):e.visitChildren(this)}}I.DebugPartialContext=$xe;class eP extends ge.ParserRuleContext{SEMI(e){return e===void 0?this.getTokens(d.SEMI):this.getToken(d.SEMI,e)}OBRACK(){return this.getToken(d.OBRACK,0)}string(){return this.getRuleContext(0,za)}CBRACK(){return this.getToken(d.CBRACK,0)}constructor(e,r){super(e,r)}get ruleIndex(){return d.RULE_experimentalStatementForTesting}enterRule(e){e.enterExperimentalStatementForTesting&&e.enterExperimentalStatementForTesting(this)}exitRule(e){e.exitExperimentalStatementForTesting&&e.exitExperimentalStatementForTesting(this)}accept(e){return e.visitExperimentalStatementForTesting?e.visitExperimentalStatementForTesting(this):e.visitChildren(this)}}I.ExperimentalStatementForTestingContext=eP;var hD={};Object.defineProperty(hD,"__esModule",{value:!0}),hD.MalloyErrorStrategy=void 0;const iht=ng;class sht extends iht.DefaultErrorStrategy{}hD.MalloyErrorStrategy=sht;var Bxe={},pD={},kxe={exports:{}};(function(t,e){(function(r){function i(o,u){for(var a in u)u.hasOwnProperty(a)&&(o[a]=u[a]);return o}function s(o,u,a){var l=0,c={caseSensitive:!0},f=i(c,a),x,h;if(o.length===0||u.length===0)return 0;if(f.caseSensitive||(o=o.toUpperCase(),u=u.toUpperCase()),o===u)return 1;var p=Math.floor(Math.max(o.length,u.length)/2)-1,m=new Array(o.length),g=new Array(u.length);for(x=0;x<o.length;x++){var y=x>=p?x-p:0,E=x+p<=u.length-1?x+p:u.length-1;for(h=y;h<=E;h++)if(m[x]!==!0&&g[h]!==!0&&o[x]===u[h]){++l,m[x]=g[h]=!0;break}}if(l===0)return 0;var A=0,_=0;for(x=0;x<o.length;x++)if(m[x]===!0){for(h=A;h<u.length;h++)if(g[h]===!0){A=h+1;break}o[x]!==u[h]&&++_}var v=(l/o.length+l/u.length+(l-_/2)/l)/3,C=0,S=.1;if(v>.7){for(;o[C]===u[C]&&C<4;)++C;v=v+C*S*(1-v)}return v}t.exports=s})()})(kxe);var oht=kxe.exports,uht=T&&T.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(pD,"__esModule",{value:!0}),pD.checkCustomErrorMessage=void 0;const Mxe=uht(oht),aht=(t,e,r)=>{var i,s;const o=t.getRuleInvocationStack()[0],u=t.currentToken;for(const a of r){const l=!a.currentToken||u.type===a.currentToken,c=!a.offendingSymbol||(e==null?void 0:e.type)===a.offendingSymbol,f=!a.ruleContextOptions||a.ruleContextOptions.includes(o),x=!a.offendingSymbolTextOptions||a.offendingSymbolTextOptions.includes(((i=e==null?void 0:e.text)===null||i===void 0?void 0:i.toLowerCase())||"");if(l&&c&&f&&x){if(a.lookbackSiblingRuleOptions){const m=t.ruleContext.children;if(!m)continue;const g=m[m.length-1];if(!a.lookbackSiblingRuleOptions.includes(g.ruleIndex))continue}if(a.precedingTokenOptions&&!a.precedingTokenOptions.some(g=>Uxe(t,g,"lookback",e==null?void 0:e.tokenIndex))||a.lookAheadOptions&&!a.lookAheadOptions.some(g=>Uxe(t,g,"lookahead",e==null?void 0:e.tokenIndex)))continue;if(a.predecessorHasAncestorRule){const m=(s=t.ruleContext.children)===null||s===void 0?void 0:s[0];if(!m||!Pxe(m,a.predecessorHasAncestorRule))continue}const h=m=>{const g=m.replace("${currentToken}",u.text||"").replace("${offendingSymbol}",(e==null?void 0:e.text)||"");try{const y=t.inputStream.LT(-1);return g.replace("${previousToken}",y.text||"")}catch{}return g};let p=h(a.errorMessage);if(a.alternatives){const m=h(a.alternatives.replace);let g=a.alternatives.with[0],y=(0,Mxe.default)(g,m);for(const E of a.alternatives.with.slice(1)){const A=(0,Mxe.default)(E,m);A>y&&(y=A,g=E)}p+=` Did you mean '${g}'?`}return p}}return""};pD.checkCustomErrorMessage=aht;const Pxe=(t,e,r=20)=>{var i;if(t.ruleIndex===e)return!0;if(r<=0)return!1;const s=((i=t.children)===null||i===void 0?void 0:i.length)||0;if(t.children&&s>0){const o=t.children[t.children.length-1];return Pxe(o,e,r-1)}return!1},Uxe=(t,e,r,i)=>{var s;try{for(let o=0;o<e.length;o++){let u;if(typeof i=="number"){const a=r==="lookahead"?o+1:-1*(o+1);u=t.inputStream.get(i+a)}else{const a=r==="lookahead"?o+2:-1*(o+1);u=t.inputStream.LT(a)}if(typeof e[o]=="number"){const a=e[o];if(a>=-1&&u.type!==a||a<-1&&u.type===-1*a)return!1}else if(typeof e[o]=="string"&&e[o]!==((s=u.text)===null||s===void 0?void 0:s.toLowerCase()))return!1}return!0}catch{return!1}};(function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.MalloyParserErrorListener=t.malloyCustomErrorCases=void 0;const e=I,r=pD,i=T2,s=Jn;t.malloyCustomErrorCases=[{errorMessage:"'view:' must be followed by '<identifier> is {'",ruleContextOptions:["exploreQueryDef"],offendingSymbol:e.MalloyParser.OCURLY,precedingTokenOptions:[[e.MalloyParser.VIEW],[e.MalloyParser.COLON]]},{errorMessage:"Missing '}' at '${offendingSymbol}'",ruleContextOptions:["vExpr"],offendingSymbol:e.MalloyParser.VIEW,currentToken:e.MalloyParser.OCURLY},{errorMessage:"Missing '}' at '${currentToken}'",ruleContextOptions:["exploreProperties","queryProperties","exploreStatement"],offendingSymbolTextOptions:["<eof>","run:","source:"]},{errorMessage:"'aggregate:' entries must include a name (ex: `some_name is count()`)",precedingTokenOptions:[[e.MalloyParser.AGGREGATE]],lookAheadOptions:[[-e.MalloyParser.IS]]},{errorMessage:"Expected ':' following 'source'",offendingSymbol:e.MalloyParser.SOURCE_KW,ruleContextOptions:["malloyDocument"]},{errorMessage:"Expected ':' following '${offendingSymbol}'",offendingSymbolTextOptions:["dimension","measure","where","declare","join_one","join_many","join_cross","primary_key"],ruleContextOptions:["exploreStatement"]},{errorMessage:"Expected 'is' or '(' following identifier '${previousToken}'",ruleContextOptions:["sourceDefinition"],lookbackSiblingRuleOptions:[e.MalloyParser.RULE_sourceNameDef,e.MalloyParser.RULE_sourceParameters]},{errorMessage:"Unexpected '{' following source expression. Expected: 'extend', 'include', '+' or '->'",offendingSymbol:e.MalloyParser.OCURLY,ruleContextOptions:["malloyDocument"],predecessorHasAncestorRule:e.MalloyParser.RULE_sqExplore},{errorMessage:"Unexpected 'join:'. Did you mean 'join_one:', 'join_many:' or 'join_cross:'?",ruleContextOptions:["exploreStatement"],offendingSymbolTextOptions:["join"],lookAheadOptions:[[e.MalloyParser.COLON]]},{errorMessage:"Unexpected '${offendingSymbol}'. Did you mean 'primary_key:'?",ruleContextOptions:["exploreStatement"],offendingSymbolTextOptions:["primarykey","primary"],lookAheadOptions:[[e.MalloyParser.COLON],["key",e.MalloyParser.COLON],["key",e.MalloyParser.IDENTIFIER]]},{errorMessage:"Unexpected '${offendingSymbol}'. Did you mean 'group_by:'?",ruleContextOptions:["queryStatement"],offendingSymbolTextOptions:["groupby","group"],lookAheadOptions:[[e.MalloyParser.COLON],["by",e.MalloyParser.COLON],["by",e.MalloyParser.IDENTIFIER]]},{errorMessage:"Unexpected '${offendingSymbol}'. Did you mean 'order_by:'?",ruleContextOptions:["queryStatement"],offendingSymbolTextOptions:["orderby","order"],lookAheadOptions:[[e.MalloyParser.COLON],["by",e.MalloyParser.COLON],["by",e.MalloyParser.IDENTIFIER]]},{errorMessage:"Expected ':' following '${offendingSymbol}'",offendingSymbolTextOptions:["group_by","declare","join_one","join_many","join_cross","extend","select","project","index","aggregate","calculate","top","limit","order_by","where","having","nest","sample","timezone"],ruleContextOptions:["queryStatement"]},{errorMessage:"Expected a query statement, '${offendingSymbol}:' is not a keyword.",ruleContextOptions:["queryStatement"],offendingSymbol:e.MalloyParser.IDENTIFIER,lookAheadOptions:[[e.MalloyParser.COLON,e.MalloyParser.IDENTIFIER]],alternatives:{replace:"${offendingSymbol}:",with:["group_by:","select:","aggregate:","calculate:","nest:"]}},{errorMessage:"Expected a source statement, '${offendingSymbol}:' is not a keyword.",ruleContextOptions:["exploreStatement"],offendingSymbol:e.MalloyParser.IDENTIFIER,lookAheadOptions:[[e.MalloyParser.COLON,e.MalloyParser.IDENTIFIER]],alternatives:{replace:"${offendingSymbol}:",with:["dimension:","measure:","primary_key:","view:","join:"]}},{errorMessage:"Expected a statement, '${offendingSymbol}:' is not a keyword.",ruleContextOptions:["malloyDocument"],offendingSymbol:e.MalloyParser.IDENTIFIER,lookAheadOptions:[[e.MalloyParser.COLON,e.MalloyParser.IDENTIFIER]],alternatives:{replace:"${offendingSymbol}:",with:["run:","query:","source:"]}}];class o{constructor(a,l,c){this.messages=a,this.sourceURL=l,this.sourceInfo=c}logError(a,l,c){return this.messages.log((0,i.makeLogMessage)(a,l,{severity:"error",...c})),a}syntaxError(a,l,c,f,x,h){const p={line:c-1,character:f},m=l?(0,s.rangeFromToken)(this.sourceInfo,l):{start:p,end:p},g=(0,r.checkCustomErrorMessage)(a,l,t.malloyCustomErrorCases);g&&(x=g),this.logError("syntax-error",{message:x},{at:{url:this.sourceURL,range:m}})}}t.MalloyParserErrorListener=o})(Bxe),Object.defineProperty(UE,"__esModule",{value:!0}),UE.runMalloyParser=void 0;const jxe=ng,lht=vR,cht=I,fht=hD,xht=Bxe;class dht extends lht.MalloyLexer{popMode(){return this._modeStack.isEmpty?this._mode:super.popMode()}}function hht(t,e,r,i,s="malloyDocument"){const o=jxe.CharStreams.fromString(t),u=new dht(o),a=new jxe.CommonTokenStream(u),l=new cht.MalloyParser(a);l.removeErrorListeners(),l.addErrorListener(new xht.MalloyParserErrorListener(i,e,r)),l.errorHandler=new fht.MalloyErrorStrategy;const c=l[s];if(!c)throw new Error(`No such parse rule as ${s}`);return{root:c.call(l),tokenStream:a,sourceStream:o,sourceInfo:r,sourceURL:e,malloyVersion:"4.0.0"}}UE.runMalloyParser=hht;var pht=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),mht=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),ght=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&pht(e,t,r);return mht(e,t),e};Object.defineProperty(Wc,"__esModule",{value:!0}),Wc.MalloyTranslator=Wc.MalloyChildTranslator=Wc.MalloyTranslation=void 0;const yht=et,qxe=ght(P4),Eht=xR,Hxe=T2,Aht=_0,tP=hR,_ht=pR,vht=mR,Cht=gR,Sht=yR,mD=ER,nP=Jn,bht=$o,Tht=AR,Rht=_R,Dht=mi,Oht=UE;class Fht{step(e){if(this.response)return this.response;if(!e.urlIsFullPath)return e.fatalResponse();const r=e.root.importZone.getEntry(e.sourceURL);if(r.status!=="present"){if(r.status==="error"){const o=r.firstReference||e.defaultLocation();return e.root.logError("import-error",{message:r.message,url:e.sourceURL},{at:o}),this.response=e.fatalResponse(),this.response}return{urls:[e.sourceURL]}}const i=r.value===""?`
|
|
1857
|
+
`:r.value;this.sourceInfo=(0,nP.getSourceInfo)(i);let s;try{s=this.runParser(i,this.sourceInfo,e)}catch(o){e.root.logError("parse-exception",{message:o.message}),s=void 0}return e.root.logger.hasErrors()?this.response={parse:s,...e.fatalResponse()}:this.response={parse:s},this.response}runParser(e,r,i){return{...(0,Oht.runMalloyParser)(e,i.sourceURL,r,i.root.logger,i.grammarRule),importBaseURL:i.importBaseURL||i.sourceURL}}}class wht{constructor(e){this.parseStep=e,this.parseReferences=void 0}step(e){var r;const i=this.parseStep.step(e);if(i.parse===void 0)return i;if(!this.parseReferences){this.parseReferences=(0,Aht.findReferences)(e,i.parse.tokenStream,i.parse.root);for(const a in this.parseReferences.tables)e.root.schemaZone.reference(a,{url:e.sourceURL,range:this.parseReferences.tables[a].firstReference});for(const a in this.parseReferences.urls){const l=this.parseReferences.urls[a];try{const c=decodeURI(new URL(a,e.importBaseURL||e.sourceURL).toString());e.addChild(c),e.imports.push({importURL:c,location:{url:e.sourceURL,range:l}}),e.root.importZone.reference(c,{url:e.sourceURL,range:l})}catch{e.root.logError("invalid-import-url",`Malformed URL '${a}'"`,{at:{url:e.sourceURL,range:l}})}}}if(e.root.logger.hasErrors())return null;let s={};const o=e.root.schemaZone.getUndefined();if(o){const a={};for(const l of o){const c=this.parseReferences.tables[l];a[l]={connectionName:c.connectionName,tablePath:c.tablePath}}s={tables:a}}const u=((r=e.root.importZone.getUndefined())!==null&&r!==void 0?r:[]).filter(a=>e.root.pretranslatedModels.get(a)===void 0);if(u.length>0&&(s={...s,urls:u}),(0,mD.isNeedResponse)(s))return s;for(const a of e.childTranslators.values()){if(e.root.pretranslatedModels.get(a.sourceURL))continue;const l=a.importsAndTablesStep.step(a);if((0,mD.isNeedResponse)(l))return l}return null}}class Nht{constructor(e){this.importStep=e,this.walked=!1}step(e){if(this.response)return this.response;const r=this.importStep.step(e);if(r)return r;const i=e.parseStep.response;if(e.root.logger.hasErrors())return this.response=e.fatalResponse(),this.response;const s=i==null?void 0:i.parse;if(!s)throw new Error("TRANSLATOR INTERNAL ERROR: Translator parse response had no errors, but also no parser");const o=new Eht.MalloyToAST(s,e.root.logger,e.compilerFlags),u=o.visit(s.root);if(e.compilerFlags=o.compilerFlags,u.elementType==="unimplemented"&&u.logError("untranslated-parse-node","INTERNAL COMPILER ERROR: Untranslated parse node"),!this.walked){for(const a of u.walk())a instanceof qxe.Unimplemented&&a.logError("untranslated-parse-node","INTERNAL COMPILER ERROR: Untranslated parse node");this.walked=!0}if(e.root.logger.hasErrors())return this.response=e.fatalResponse(),this.response;for(const a of e.childTranslators.values()){if(e.root.pretranslatedModels.get(a.sourceURL))continue;const l=a.astStep.step(a);if((0,mD.isNeedResponse)(l))return l}return u.setTranslator(e),this.response={...e.problemResponse(),ast:u,final:!0},this.response}}class Lht{constructor(e){this.parseStep=e}step(e){if(!this.response){const r=this.parseStep.step(e);if(r.parse){let i;try{i=(0,_ht.walkForDocumentSymbols)(e,r.parse.tokenStream,r.parse.root)}catch{}this.response={symbols:i,final:!0}}else return r}return this.response}}class Iht{constructor(e){this.parseStep=e}step(e,r){const i=this.parseStep.step(e);if(i.parse){let s=[];if(r!==void 0)try{s=(0,vht.walkForDocumentCompletions)(i.parse.tokenStream,i.parse.root,r)}catch{}return{...i,completions:s}}else return i}}class $ht{constructor(e){this.parseStep=e}step(e,r){const i=this.parseStep.step(e);if(i.parse){let s;if(r!==void 0)try{s=(0,Cht.walkForDocumentHelpContext)(i.parse.root,r)}catch{}return{...i,helpContext:s}}else return i}}class Bht{constructor(e){this.parseStep=e}step(e,r){if(!this.response){const i=this.parseStep.step(e);if(!i.parse||i.final)return i;{const s=(0,Tht.walkForModelAnnotation)(e,i.parse.tokenStream,i.parse);this.response={modelAnnotation:{...s,inherits:r==null?void 0:r.annotation}}}}return this.response}}class kht{constructor(e){this.parseStep=e}step(e){if(!this.response){const r=this.parseStep.step(e);if(r.parse){const i=(0,Rht.walkForTablePath)(e,r.parse.tokenStream,r.parse);this.response={pathInfo:i}}else return r}return this.response}}class Mht{constructor(e){this.astStep=e,this.importedAnnotations=!1}step(e,r){if(this.response)return this.response;const i=e.root.pretranslatedModels.get(e.sourceURL);if(i!==void 0)return e.modelDef=i,{modelDef:i,final:!0,fromSources:e.getDependencies()};if(r&&!this.importedAnnotations){const o=(0,Dht.annotationToTag)(r.annotation,{prefix:/^##! /});e.compilerFlags=o.tag,this.importedAnnotations=!0}const s=this.astStep.step(e);if((0,mD.isNeedResponse)(s))return s;if(!s.ast)return this.response=s,this.response;if(e.grammarRule==="malloyDocument")if(s.ast instanceof qxe.Document){const o=s.ast;for(o.initModelDef(r);;){const u=o.compile();if(u.needs)return u.needs;e.modelDef=u.modelDef;break}}else e.root.logError("parsed-non-malloy-document",{url:e.sourceURL},{at:e.defaultLocation()});return e.root.logger.hasErrors()?this.response={fromSources:e.getDependencies(),...e.fatalResponse()}:this.response={modelDef:{...e.modelDef,dependencies:e.getDependencyTree()},fromSources:e.getDependencies(),...e.problemResponse(),final:!0},this.response}}class rP{constructor(e,r=null,i="malloyDocument"){this.sourceURL=e,this.importBaseURL=r,this.grammarRule=i,this.sqlSources=[],this.imports=[],this.compilerFlags=new bht.Tag,this._urlIsFullPath=void 0,this.dialectAlreadyChecked={},this.allDialectsEnabled=!1,this.childTranslators=new Map,this.modelDef={name:e,exports:[],contents:{},queryList:[],dependencies:{}},this.parseStep=new Fht,this.modelAnnotationStep=new Bht(this.parseStep),this.metadataStep=new Lht(this.parseStep),this.completionsStep=new Iht(this.parseStep),this.helpContextStep=new $ht(this.parseStep),this.importsAndTablesStep=new wht(this.parseStep),this.astStep=new Nht(this.importsAndTablesStep),this.tablePathInfoStep=new kht(this.parseStep),this.translateStep=new Mht(this.astStep),this.references=new Sht.ReferenceList(e)}get urlIsFullPath(){if(this._urlIsFullPath===void 0)try{const e=new URL(this.sourceURL);this._urlIsFullPath=!0}catch(e){const r=e instanceof Error?e.message:"";this._urlIsFullPath=!1,this.root.logError("failed-to-compute-absolute-import-url",`Could not compute full path URL: ${r}`)}return this._urlIsFullPath}addChild(e){this.childTranslators.get(e)||this.childTranslators.set(e,new Qxe(e,this.root))}getDependencies(){const e=this.getDependencyTree();return[this.sourceURL,...zxe(e)]}getDependencyTree(){const e=this.root.pretranslatedModels.get(this.sourceURL);if(e!==void 0)return e.dependencies;const r={};for(const[i,s]of this.childTranslators)r[i]=s.getDependencyTree();return r}newlyTranslatedDependencies(){if(this.root.pretranslatedModels.get(this.sourceURL)!==void 0)return[];const r=[];for(const[i,s]of this.childTranslators){if(this.root.pretranslatedModels.get(i)!==void 0)continue;const u=s.translate();u.modelDef&&(r.push({url:i,modelDef:u.modelDef}),r.push(...s.newlyTranslatedDependencies()))}return r}addReference(e){this.references.add(e)}referenceAt(e){return this.references.find(e)}fatalResponse(){return{final:!0,...this.problemResponse()}}problemResponse(){return{problems:this.problems()}}problems(){return[...this.root.logger.getLog()]}getLineMap(e){var r,i;if(e===this.sourceURL)return(r=this.parseStep.sourceInfo)===null||r===void 0?void 0:r.lines;const s=this.childTranslators.get(e);if(s)return(i=s.parseStep.sourceInfo)===null||i===void 0?void 0:i.lines}codeAtLocation(e){const r=this.getLineMap(e.url)||[];if(e.range.start.line===e.range.end.line)return r[e.range.start.line].slice(e.range.start.character,e.range.end.character);let i="";i+=r[e.range.start.line].slice(e.range.start.character);for(let s=e.range.start.line+1;s<e.range.end.line;s++)i+=r[s];return i+=r[e.range.end.line].slice(0,e.range.end.character),i}prettyErrors(){let e="",r="";for(const i of this.root.logger.getLog()){let s=i.message,o=this.sourceURL;if(i.at){o=i.at.url;const u=i.at.range.start.line,a=i.at.range.start.character,l=this.getLineMap(i.at.url);if(l){const c=l[u];s=`line ${u+1}: ${i.message}
|
|
1858
1858
|
| ${c}`,a>0&&(s=s+`
|
|
1859
1859
|
| ${" ".repeat(a)}^`)}else s=`line ${u+1}: char ${a}: ${i.message}`}r!==o&&(s=`FILE: ${o}
|
|
1860
1860
|
`+s,r=o),e!==""?e=`${e}
|
|
1861
|
-
${s}`:e=s}return e}childRequest(e){var r;const i=decodeURI(new URL(e,this.sourceURL).toString()),s=(r=this.childTranslators.get(i))===null||r===void 0?void 0:r.translate();if(s!=null&&s.compileSQL)return{compileSQL:s.compileSQL}}getChildExports(e){const r={},i=decodeURI(new URL(e,this.sourceURL).toString()),s=this.childTranslators.get(i);if(s&&s.translate().modelDef)for(const u of s.modelDef.exports){const a=s.modelDef.contents[u];((0,mht.isSourceDef)(a)||a.type==="query")&&(r[u]=a)}return r}translate(e){if(this.finalAnswer)return this.finalAnswer;const r=this.translateStep.step(this,e);return r.final&&(this.finalAnswer=r),r}translatorForDependency(e){return this.childTranslators.get(e)}importAt(e){for(let r=0;r<this.imports.length;r++){const i=this.imports[r];if((0,nP.locationContainsPosition)(i.location,e))return i}}metadata(){return this.metadataStep.step(this)}modelAnnotation(e){return this.modelAnnotationStep.step(this,e)}tablePathInfo(){return this.tablePathInfoStep.step(this)}completions(e){return this.completionsStep.step(this,e)}helpContext(e){return this.helpContextStep.step(this,e)}defaultLocation(){return{url:this.sourceURL,range:{start:{line:0,character:0},end:{line:0,character:0}}}}rangeFromContext(e){return(0,nP.rangeFromContext)(this.parseStep.sourceInfo,e)}firstReferenceToDialect(e){return this.dialectAlreadyChecked[e]?!1:(this.dialectAlreadyChecked[e]=!0,!0)}experimentalDialectEnabled(e){if(this.allDialectsEnabled)return!0;const r=this.compilerFlags.tag("experimental");return r!==void 0&&(r.bare()||r.has("dialect",e))}}Wc.MalloyTranslation=rP;class Qxe extends rP{constructor(e,r){super(e),this.root=r}}Wc.MalloyChildTranslator=Qxe;class kht extends rP{constructor(e,r=null,i=null,s=null){super(e,r),this.eventStream=s,this.schemaZone=new tP.Zone,this.importZone=new tP.Zone,this.pretranslatedModels=new Map,this.sqlQueryZone=new tP.Zone,this.root=this,this.logger=new Hxe.BaseMessageLogger(s),i&&this.update(i)}update(e){var r,i,s;this.schemaZone.updateFrom(e.tables,(r=e.errors)===null||r===void 0?void 0:r.tables),this.importZone.updateFrom(e.urls,(i=e.errors)===null||i===void 0?void 0:i.urls),this.sqlQueryZone.updateFrom(e.compileSQL,(s=e.errors)===null||s===void 0?void 0:s.compileSQL);for(const o in e.translations)this.pretranslatedModels.set(o,e.translations[o])}logError(e,r,i){return this.logger.log((0,Hxe.makeLogMessage)(e,r,{severity:"error",...i})),e}}Wc.MalloyTranslator=kht;function zxe(t){return[...Object.keys(t),...Object.keys(t).map(e=>zxe(t[e])).flat()]}var r1={};Object.defineProperty(r1,"__esModule",{value:!0}),r1.exploreQueryWalkerBuilder=r1.ExploreQueryWalker=void 0;const Mht=T0;class Wxe{constructor(e){this.inDocument=!1,this.exploreClauseRefs=[],this.tokens=e}exploreQueryAtOffset(e){return this.exploreClauseRefs.find(r=>r.range[0]===void 0||r.range[1]===void 0?!1:r.range[0]<=e&&r.range[1]>=e)}filterAtOffset(e){const r=this.exploreQueryAtOffset(e);if(r)return r.filterRefs.find(i=>i.range[0]===void 0||i.range[1]===void 0?!1:i.range[0]<=e&&i.range[1]>=e)}hasFilterListAtOffset(e){const r=this.exploreQueryAtOffset(e);return r?!!r.filterLists.find(i=>i.range[0]===void 0||i.range[1]===void 0?!1:i.range[0]<=e&&i.range[1]>=e):!1}enterMalloyDocument(){this.inDocument=!0}}r1.ExploreQueryWalker=Wxe;function Pht(t,e){const r=new Wxe(t),i=r;return Mht.ParseTreeWalker.DEFAULT.walk(i,e),r}r1.exploreQueryWalkerBuilder=Pht;var i1={},VE={},Va={};Object.defineProperty(Va,"__esModule",{value:!0}),Va.getResultStructMetadataAnnotation=Va.convertFieldInfos=Va.modelDefToModelInfo=void 0;const Ya=Gi,iP=js,sP=mi,Gxe=$o;function Uht(t){const e={entries:[],anonymous_queries:[]};for(const[r,i]of Object.entries(t.contents))if(t.exports.includes(r)){if((0,Ya.isSourceDef)(i)){const s=i.parameters&&Object.entries(i.parameters).length>0?Object.entries(i.parameters).map(([u,a])=>(0,Ya.isAtomic)(a)?{name:u,type:yD(a),default_value:Vxe(a.value)}:{name:u,type:{kind:"filter_expression_type"},default_value:Vxe(a.value)}):void 0,o={kind:"source",name:r,schema:{fields:s1(i,i.fields)},parameters:s,annotations:oP(i)};e.entries.push(o)}else if(i.type==="query"){const s=(0,iP.getResultStructDefForQuery)(t,i),o=oP(i),u=s.resultMetadata?gD(s,s.resultMetadata):void 0,a=[...o??[],...u?[u]:[]],l={kind:"source",name:r,schema:{fields:s1(s,s.fields)},annotations:a.length>0?a:void 0};e.entries.push(l)}}for(const r of t.queryList){const i=(0,iP.getResultStructDefForQuery)(t,r),s=oP(r),o=i.resultMetadata?gD(i,i.resultMetadata):void 0,u=[...s??[],...o?[o]:[]],a={schema:{fields:s1(i,i.fields)},annotations:u.length>0?u:void 0};e.anonymous_queries.push(a)}return e}Va.modelDefToModelInfo=Uht;function Vxe(t){if(t!==null)switch(t.node){case"numberLiteral":return{kind:"number_literal",number_value:parseFloat(t.literal)};case"stringLiteral":return{kind:"string_literal",string_value:t.literal};case"filterLiteral":return{kind:"filter_expression_literal",filter_expression_value:t.filterSrc};case"timeLiteral":return{kind:"timestamp_literal",timestamp_value:t.literal};case"true":return{kind:"boolean_literal",boolean_value:!0};case"false":return{kind:"boolean_literal",boolean_value:!1};case"null":return{kind:"null_literal"};default:throw new Error("Invalid parameter default value")}}function oP(t){return(0,sP.annotationToTaglines)(t.annotation).map(r=>({value:r}))}function s1(t,e){var r,i,s;const o=[];for(const u of e){if(!(u.accessModifier===void 0))continue;const c=(0,sP.annotationToTaglines)(u.annotation).map(x=>({value:x})),f=c.length>0?c:void 0;if((0,Ya.isTurtle)(u)){const x=(0,iP.getResultStructDefForView)(t,u),h=x.resultMetadata?gD(x,x.resultMetadata):void 0,p=[...f??[],...h?[h]:[]],m={kind:"view",name:(r=u.as)!==null&&r!==void 0?r:u.name,annotations:p.length>0?p:void 0,schema:{fields:s1(x,x.fields)}};o.push(m)}else if((0,Ya.isAtomic)(u)){const x=(0,Ya.expressionIsAggregate)(u.expressionType),h=(0,Ya.expressionIsScalar)(u.expressionType);if(!x&&!h||u.type==="error")continue;const p=u.resultMetadata?Yxe(u,u.resultMetadata):void 0,m=[...f??[],...p?[p]:[]],g={kind:x?"measure":"dimension",name:(i=u.as)!==null&&i!==void 0?i:u.name,type:yD(u),annotations:m.length>0?m:void 0};o.push(g)}else if((0,Ya.isJoinedSource)(u)){const x={kind:"join",name:(s=u.as)!==null&&s!==void 0?s:u.name,annotations:f,schema:{fields:s1(u,u.fields)},relationship:u.join};o.push(x)}}return o}Va.convertFieldInfos=s1;function Yxe(t,e){const r=Gxe.Tag.withPrefix("#(malloy) ");let i=!1;if(e.referenceId!==void 0&&(r.set(["reference_id"],e.referenceId),i=!0),e.fieldKind==="measure"&&(r.set(["calculation"]),i=!0),e.filterList){const s=e.filterList.filter(o=>o.expressionType==="scalar").map(o=>o.code);r.set(["drill_filters"],s),i=!0}if(e.fieldKind==="dimension"){const o=(e==null?void 0:e.sourceExpression)||(e!=null&&e.sourceField.includes(".")?e==null?void 0:e.sourceField:qht(t.name));r.set(["drill_expression"],o),i=!0}return i?{value:r.toString()}:void 0}function jht(t){return t.replace(/\\/g,"\\\\").replace(/`/g,"\\`")}function qht(t){return t.match(/^[A-Za-z_][0-9A-Za-z_]*$/)?t:`\`${jht(t)}\``}function gD(t,e){var r,i;const s=Gxe.Tag.withPrefix("#(malloy) ");let o=!1;if(e.limit!==void 0&&(s.set(["limit"],e.limit),o=!0),e.filterList){const u=e.filterList.filter(a=>a.expressionType==="scalar").map(a=>a.code);u.length>0&&(s.set(["drill_filters"],u),o=!0)}if(e.orderBy){for(let u=0;u<e.orderBy.length;u++){const a=e.orderBy[u],l=typeof a.field=="number"?(r=t.fields[a.field-1].as)!==null&&r!==void 0?r:t.fields[a.field-1].name:a.field,c=(i=a.dir)!==null&&i!==void 0?i:null;s.set(["ordered_by",u,l],c)}o=!0}return o?{value:s.toString()}:void 0}Va.getResultStructMetadataAnnotation=gD;function yD(t){if((0,Ya.isBasicAtomic)(t))switch(t.type){case"string":return{kind:"string_type"};case"number":return{kind:"number_type",subtype:t.numberType==="float"?"decimal":t.numberType==="integer"?"integer":void 0};case"boolean":return{kind:"boolean_type"};case"date":{const e=t.timeframe;return e&&!Hht(e)?{kind:"timestamp_type",timeframe:t.timeframe}:{kind:"date_type",timeframe:Qht(t.timeframe)}}case"timestamp":return{kind:"timestamp_type",timeframe:t.timeframe};case"json":return{kind:"json_type"};case"sql native":return{kind:"sql_native_type",sql_type:t.rawType};case"error":throw new Error("Error type is not supported in stable interface")}else{if((0,Ya.isRepeatedRecord)(t))return{kind:"array_type",element_type:Kxe(t)};if(t.type==="record")return Kxe(t);if(t.type==="array")return{kind:"array_type",element_type:yD(t.elementTypeDef)}}throw new Error("Unexpected field type")}function Kxe(t){return{kind:"record_type",fields:t.fields.map(e=>{const r=[];if("resultMetadata"in e&&e.resultMetadata){const i=Yxe(e,e.resultMetadata);i&&r.push(i)}if(e.annotation){const i=(0,sP.annotationToTaglines)(e.annotation);r.push(...i.map(s=>({value:s})))}if((0,Ya.isAtomic)(e))return{name:e.name,annotations:r.length>0?r:void 0,type:yD(e)};throw new Error("Expected record type to not have a table as its child")})}}function Hht(t){switch(t){case"day":case"week":case"month":case"year":case"quarter":return!0;default:return!1}}function Qht(t){switch(t){case void 0:return;case"day":case"week":case"month":case"year":case"quarter":return t;default:throw new Error(`Invalid date timeframe ${t}`)}}function u1t(t){return t}function a1t(t){return t}(function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.mapLogs=t.DEFAULT_LOG_RANGE=t.wrapResult=t.mapData=t.wrapLegacyConnection=t.wrapLegacyInfoConnection=void 0;const e=$o,r=mi,i=Va,s=qr;function o(x){return{get dialectName(){return x.dialectName},async fetchSchemaForSQLQuery(h){const p=await x.fetchSchemaForSQLStruct({connection:x.name,selectStr:h},{}),m=p.structDef;if(m===void 0)throw new Error(p.error);return{fields:(0,i.convertFieldInfos)(m,m.fields)}},async fetchSchemaForTable(h){const p=`${x.name}:${h}`,m=await x.fetchSchemaForTables({[p]:h},{}),g=m.schemas[p];if(g===void 0)throw new Error(m.errors[p]);return{fields:(0,i.convertFieldInfos)(g,g.fields)}}}}t.wrapLegacyInfoConnection=o;function u(x){return{...o(x),runSQL:async(h,p)=>{const m=await x.runSQL(h);return l(m.rows,p)}}}t.wrapLegacyConnection=u;function a(x){if(x instanceof Date)return x;if(x.constructor.name==="Date")return new Date(x);if(typeof x=="number")return new Date(x);if(typeof x!="string")return new Date(x.value);{let p=s.DateTime.fromISO(x,{zone:"UTC"});return p.isValid||(p=s.DateTime.fromSQL(x,{zone:"UTC"})),p.toJSDate()}}function l(x,h){function p(y,E){if(y===null)return{kind:"null_cell"};if(E.type.kind==="date_type"||E.type.kind==="timestamp_type"){const A=a(y).toISOString();return E.type.kind==="date_type"?{kind:"date_cell",date_value:A}:{kind:"timestamp_cell",timestamp_value:A}}else if(E.type.kind==="boolean_type"){if(typeof y=="number")return{kind:"boolean_cell",boolean_value:y!==0};if(typeof y!="boolean")throw new Error(`Invalid boolean ${y}`);return{kind:"boolean_cell",boolean_value:y}}else if(E.type.kind==="number_type"){if(typeof y!="number")throw new Error(`Invalid number ${y}`);return{kind:"number_cell",number_value:y}}else if(E.type.kind==="string_type"){if(typeof y!="string")throw new Error(`Invalid string ${y}`);return{kind:"string_cell",string_value:y}}else if(E.type.kind==="array_type"){if(!Array.isArray(y))throw new Error(`Invalid array ${y}`);return{kind:"array_cell",array_value:y.map(A=>p(A,{name:"array_element",type:E.type.element_type}))}}else{if(E.type.kind==="json_type")return{kind:"json_cell",json_value:JSON.stringify(y)};if(E.type.kind==="sql_native_type")return{kind:"sql_native_cell",sql_native_value:JSON.stringify(y)};{const A=E.type;if(A.kind!=="record_type")throw new Error(`Invalid record in result ${JSON.stringify(E)}, ${JSON.stringify(y)}`);return m(y,{kind:"join",relationship:"many",name:"array_element",schema:{fields:A.fields.map(_=>({kind:"dimension",..._}))}})}}}function m(y,E){const A=[];for(const _ of E.schema.fields){const v=y[_.name];if(_.kind!=="dimension")throw new Error("Invalid result -- expected all fields to be dimensions");const C=p(v,_);A.push(C)}return{kind:"record_cell",record_value:A}}const g={kind:"join",schema:h,name:"root",relationship:"one"};return{kind:"array_cell",array_value:x.map(y=>m(y,g))}}t.mapData=l;function c(x){const h=x._queryResult.structs,p=h[h.length-1],m={fields:(0,i.convertFieldInfos)(p,p.fields)},g=(0,r.annotationToTaglines)(x.annotation).map(E=>({value:E})),y=p.resultMetadata?(0,i.getResultStructMetadataAnnotation)(p,p.resultMetadata):void 0;return y&&g.push(y),g.push(...p.resultMetadata?[]:[]),x.sourceExplore&&g.push({value:e.Tag.withPrefix("#(malloy) ").set(["source_name"],x.sourceExplore.name).toString()}),g.push({value:e.Tag.withPrefix("#(malloy) ").set(["query_name"],x.resultExplore.name).toString()}),{schema:m,data:l(x.data.toObject(),m),connection_name:x.connectionName,annotations:g.length>0?g:void 0,query_timezone:x.data.field.queryTimezone,sql:x.sql}}t.wrapResult=c,t.DEFAULT_LOG_RANGE={start:{line:0,character:0},end:{line:0,character:0}};function f(x,h){return x.map(p=>{var m,g,y,E;return{severity:p.severity,message:p.message,range:(g=(m=p.at)===null||m===void 0?void 0:m.range)!==null&&g!==void 0?g:t.DEFAULT_LOG_RANGE,url:(E=(y=p.at)===null||y===void 0?void 0:y.url)!==null&&E!==void 0?E:h}})}t.mapLogs=f})(VE);var zht=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),Wht=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),Ght=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&zht(e,t,r);return Wht(e,t),e};Object.defineProperty(i1,"__esModule",{value:!0}),i1.malloyToQuery=i1.MalloyToQuery=void 0;const Vht=qd,Ln=Ght(I),Jxe=T2,YE=Pn,Yht=et,Kht=UE,Xxe=Jn,Jht=VE,uP="Malloy query documents";class Zxe extends Vht.AbstractParseTreeVisitor{constructor(e,r){super(),this.parseInfo=e,this.msgLog=r}internalError(e,r){return this.contextError(e,"internal-translator-error",{message:r}),new Error(`Internal Translator Error: ${r}`)}getLocation(e){return{url:this.parseInfo.sourceURL,range:(0,Xxe.rangeFromContext)(this.parseInfo.sourceInfo,e)}}contextError(e,r,i,s){this.msgLog.log((0,Jxe.makeLogMessage)(r,i,{at:this.getLocation(e),...s}))}getNumber(e){return Number.parseInt(e.text)}defaultResult(){return null}getAnnotations(e){const r=e.ANNOTATION().map(i=>({value:i.text}));return r.length>0?r:void 0}getIsAnnotations(e){var r,i;if(e===void 0)return;const o=((r=this.getAnnotations(e._beforeIs))!==null&&r!==void 0?r:[]).concat((i=this.getAnnotations(e._afterIs))!==null&&i!==void 0?i:[]);return o.length>0?o:void 0}notAllowed(e,r){this.illegal(e,`${r} are not allowed in ${uP}`)}illegal(e,r){this.contextError(e,"invalid-malloy-query-document",r)}visitMalloyDocument(e){const r=e.malloyStatement();let i;for(const s of r)s.defineSourceStatement()?this.notAllowed(s,"Source definitions"):s.defineQuery()?this.notAllowed(s,"Query definitions"):s.importStatement()?this.notAllowed(s,"Import statements"):s.docAnnotations()?this.notAllowed(s,"Model annotations"):s.ignoredObjectAnnotations()?this.notAllowed(s,"Detatched object annotations"):s.experimentalStatementForTesting()?this.notAllowed(s,"Experimental testing statements"):i===void 0?i=s.runStatement():this.illegal(s,`${uP} may only have one run statement`);return i===void 0?(this.illegal(e,`${uP} must have a run statement`),null):this.visitRunStatement(i)}visitRunStatement(e){const r=e.topLevelAnonQueryDef(),i=this.getQueryDefinition(r.sqExpr()),s=this.getAnnotations(e.topLevelAnonQueryDef().tags());return i!==null?{annotations:s,definition:i}:null}getQueryReference(e){if(e.sourceArguments())this.illegal(e,"Queries do not support parameters");else return{name:(0,YE.getId)(e)};return null}getQueryDefinition(e){if(e instanceof Ln.SQIDContext){const r=this.getQueryReference(e);if(r!==null)return{kind:"query_reference",...r}}else{if(e instanceof Ln.SQParensContext)return this.getQueryDefinition(e.sqExpr());if(e instanceof Ln.SQComposeContext)this.notAllowed(e,"Source compositions");else if(e instanceof Ln.SQRefinedQueryContext){const r=e.sqExpr(),i=this.getQueryDefinition(r),s=this.getRefinementSegment(e.segExpr());return s===null||i===null?null:(s.kind==="arrow"&&this.notAllowed(e,"Queries against refined queries"),{kind:"refinement",base:i,refinement:s})}else if(e instanceof Ln.SQExtendedSourceContext)this.notAllowed(e,"Source extensions");else if(e instanceof Ln.SQIncludeContext)this.notAllowed(e,"Source inclusions");else if(e instanceof Ln.SQTableContext)this.notAllowed(e,"Table statements");else if(e instanceof Ln.SQSQLContext)this.notAllowed(e,"SQL statements");else if(e instanceof Ln.SQArrowContext){const r=e.sqExpr(),i=this.getQueryDefinition(r),s=this.getRefinementSegment(e.segExpr());return s===null||i===null?null:i.kind==="query_reference"?{kind:"arrow",source:{...i,kind:"source_reference"},view:s}:i.kind==="arrow"?{kind:"arrow",source:i.source,view:{kind:"arrow",source:i.view,view:s}}:{kind:"arrow",source:i,view:s}}}return null}getRefinementSegment(e){if(e instanceof Ln.SegOpsContext){const r=e.queryProperties().queryStatement().flatMap(i=>this.getSegmentOperation(i));return r.some(i=>i===null)?null:{kind:"segment",operations:r}}else if(e instanceof Ln.SegFieldContext){const{name:r,path:i}=this.getFieldPath(e.fieldPath());return{kind:"view_reference",name:r,path:i}}else{if(e instanceof Ln.SegParenContext)return this.getViewExpression(e.vExpr());if(e instanceof Ln.SegRefineContext){const r=this.getRefinementSegment(e._lhs),i=this.getRefinementSegment(e._rhs);return r===null||i===null?null:{kind:"refinement",base:r,refinement:i}}}return null}getGroupByStatement(e){const r=this.getAnnotations(e.tags()),s=e.queryFieldList().queryFieldEntry().map(o=>this.getQueryField(o));return s.some(o=>o===null)||s===null?null:s.map(o=>{var u;const a=[...r??[],...(u=o.field.annotations)!==null&&u!==void 0?u:[]];return{kind:"group_by",name:o.name,field:{...o.field,annotations:a.length>0?a:void 0}}})}getAggregateStatement(e){const r=this.getAnnotations(e.tags()),s=e.queryFieldList().queryFieldEntry().map(o=>this.getQueryField(o));return s.some(o=>o===null)||s===null?null:s.map(o=>{var u;const a=[...r??[],...(u=o.field.annotations)!==null&&u!==void 0?u:[]];return{kind:"aggregate",name:o.name,field:{...o.field,annotations:a.length>0?a:void 0}}})}getOrderByStatement(e){const r=e.ordering().orderBySpec(),i=[];for(const s of r)if(s.INTEGER_LITERAL())this.notAllowed(s,"Indexed order by statements");else if(s.fieldName()){const o=(0,YE.getId)(s.fieldName()),u=s.ASC()?"asc":s.DESC()?"desc":void 0;i.push({kind:"order_by",direction:u,field_reference:{name:o}})}else return null;return i}getNestStatement(e){const r=this.getAnnotations(e.tags()),i=e.nestedQueryList().nestEntry(),s=[];for(const o of i){if(!(o instanceof Ln.NestDefContext))return this.internalError(o,"Expected nestDef"),null;const u=this.getAnnotations(o.tags()),a=this.getIsAnnotations(o.isDefine()),l=o.queryName(),c=l?(0,YE.getId)(l):void 0,f=this.getViewExpression(o.vExpr());if(f===null)return null;s.push({kind:"nest",name:c,view:{definition:f,annotations:this.combineAnnotations(r,u,a)}})}return s}getViewExpression(e){if(e instanceof Ln.VSegContext)return this.getRefinementSegment(e.segExpr());if(e instanceof Ln.VArrowContext){const r=this.getRefinementSegment(e),i=this.getViewExpression(e._rhs);return r===null||i===null?null:{kind:"arrow",source:r,view:i}}else return this.internalError(e,"Unexpected VExpr node"),null}getLimitStatement(e){return{kind:"limit",limit:this.getNumber(e.INTEGER_LITERAL())}}getSegmentOperation(e){if(e.groupByStatement()){const r=e.groupByStatement();return this.getGroupByStatement(r)}else if(e.aggregateStatement()){const r=e.aggregateStatement();return this.getAggregateStatement(r)}else if(e.limitStatement()){const r=e.limitStatement(),i=this.getLimitStatement(r);return i===null?null:[i]}else if(e.declareStatement())this.notAllowed(e,"Declare statements");else if(e.queryJoinStatement())this.notAllowed(e,"Query join statements");else if(e.queryExtend())this.notAllowed(e,"Query extend statements");else if(e.projectStatement())this.notAllowed(e,"Select statements");else if(e.indexStatement())this.notAllowed(e,"Index statements");else if(e.calculateStatement())this.notAllowed(e,"Calculate statements");else if(e.topStatement())this.notAllowed(e,"Top statements");else if(e.orderByStatement()){const r=e.orderByStatement();return this.getOrderByStatement(r)}else if(e.whereStatement()){const r=e.whereStatement(),i=this.getWhere(r);return i===null?null:i.map(s=>({kind:"where",...s}))}else if(e.havingStatement()){const r=e.havingStatement(),i=this.getHaving(r);return i===null?null:i.map(s=>({kind:"having",...s}))}else if(e.nestStatement()){const r=e.nestStatement();return this.getNestStatement(r)}else e.sampleStatement()?this.notAllowed(e,"Sample statements"):e.timezoneStatement()?this.notAllowed(e,"Timezone statements"):(e.queryAnnotation()||e.ignoredModelAnnotations())&&this.notAllowed(e,"Detached annotation statements");return null}getFieldPath(e){const r=e.fieldName().map(o=>(0,YE.getId)(o)),i=r[0],s=r.slice(1);return{name:i,path:s.length>0?s:void 0}}getTimeframe(e){const r=e.text;return(0,Yht.isTimestampUnit)(r)?r:(this.illegal(e,`Invalid timeframe ${r}`),null)}getQueryField(e){if(e.taggedRef()){const r=e.taggedRef(),i=this.getAnnotations(r.tags()),{name:s,path:o}=this.getFieldPath(r.fieldPath());if(r.refExpr()){const u=r.refExpr();if(u.timeframe()){const a=this.getTimeframe(u.timeframe());return a===null?null:{name:void 0,field:{annotations:i,expression:{kind:"time_truncation",field_reference:{name:s,path:o},truncation:a}}}}else u.aggregate()&&this.notAllowed(u,"Aggregate expressions")}else return{name:void 0,field:{annotations:i,expression:{kind:"field_reference",name:s,path:o}}}}else if(e.fieldDef()){const r=e.fieldDef(),i=this.getAnnotations(r.tags()),s=this.getIsAnnotations(r.isDefine()),o=(0,YE.getId)(r.fieldNameDef()),u=this.getFieldExpression(r.fieldExpr());return u===null?null:{name:o,field:{expression:u,annotations:this.combineAnnotations(i,s)}}}return null}getFieldExpression(e){if(e instanceof Ln.ExprFieldPathContext){const{name:r,path:i}=this.getFieldPath(e.fieldPath());return{kind:"field_reference",name:r,path:i}}else if(e instanceof Ln.ExprTimeTruncContext){const r=this.getTimeframe(e.timeframe()),i=e.fieldExpr(),s=this.getFieldExpression(i);return s===null||r===null?null:s.kind!=="field_reference"?(this.illegal(i,"Left hand side of time truncation must be a field reference"),null):{kind:"time_truncation",truncation:r,field_reference:{name:s.name,path:s.path,parameters:s.parameters}}}else if(e instanceof Ln.ExprFieldPropsContext){const r=e.fieldExpr(),i=this.getFieldExpression(r);if(i===null)return null;if(i.kind!=="field_reference")return this.illegal(r,"Left hand side of filtered field must be a field reference"),null;const s=e.fieldProperties().fieldPropertyStatement(),o=[];for(const u of s){const a=u.whereStatement();if(a){const l=this.getWhere(a);if(l===null)return null;o.push(...l)}}return{kind:"filtered_field",field_reference:{name:i.name,path:i.path,parameters:i.parameters},where:o}}return null}stripQuote(e,r){return e.slice(e.indexOf(r)+r.length,e.lastIndexOf(r))}getFilterString(e){const r=e.tripFilterString(),i=e.tickFilterString();if(r){const s=r.BQ3_FILTER(),o=r.DQ3_FILTER(),u=r.SQ3_FILTER();if(s)return this.stripQuote(s.text,"```");if(o)return this.stripQuote(o.text,'"""');if(u)return this.stripQuote(u.text,"'''")}else if(i){const s=i.BQ_FILTER(),o=i.DQ_FILTER(),u=i.SQ_FILTER();if(s)return this.stripQuote(s.text,"`");if(o)return this.stripQuote(o.text,'"');if(u)return this.stripQuote(u.text,"'")}return null}getFilterExpr(e){if(e instanceof Ln.ExprCompareContext&&e.compareOp().MATCH()){const r=e.fieldExpr()[0],i=e.fieldExpr()[1];if(r instanceof Ln.ExprFieldPathContext&&i instanceof Ln.ExprLiteralContext){const{path:s,name:o}=this.getFieldPath(r.fieldPath()),u=i.literal();if(u instanceof Ln.FilterString_stubContext){const a=this.getFilterString(u.filterString());return a===null?null:{filter:{kind:"filter_string",field_reference:{name:o,path:s},filter:a}}}}}return this.notAllowed(e,"Filters other than comparisons with filter strings"),null}getWhere(e){const i=e.filterClauseList().fieldExpr().map(s=>this.getFilterExpr(s));return i.some(s=>s===null)?null:i}getHaving(e){const i=e.filterClauseList().fieldExpr().map(s=>this.getFilterExpr(s));return i.some(s=>s===null)?null:i}combineAnnotations(...e){const r=e.flatMap(i=>i??[]);return r.length>0?r:void 0}}i1.MalloyToQuery=Zxe;function Xht(t){const e=(0,Xxe.getSourceInfo)(t),r=new Jxe.BaseMessageLogger(null),i="internal://query.malloy",s=(0,Kht.runMalloyParser)(t,i,e,r),u=new Zxe(s,r).visit(s.root),a=(0,Jht.mapLogs)(r.getLog(),i);if(u===null)return{logs:a};if(!("definition"in u))throw new Error("Expected a query");return{query:u,logs:a}}i1.malloyToQuery=Xht,function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.malloyToQuery=t.exploreQueryWalkerBuilder=t.MalloyTranslation=t.MalloyTranslator=void 0;var e=Wc;Object.defineProperty(t,"MalloyTranslator",{enumerable:!0,get:function(){return e.MalloyTranslator}}),Object.defineProperty(t,"MalloyTranslation",{enumerable:!0,get:function(){return e.MalloyTranslation}});var r=r1;Object.defineProperty(t,"exploreQueryWalkerBuilder",{enumerable:!0,get:function(){return r.exploreQueryWalkerBuilder}});var i=i1;Object.defineProperty(t,"malloyToQuery",{enumerable:!0,get:function(){return i.malloyToQuery}})}(M4);var Ie={},ED={};Object.defineProperty(ED,"__esModule",{value:!0}),ED.MALLOY_VERSION=void 0,ED.MALLOY_VERSION="0.0.265",Object.defineProperty(Ie,"__esModule",{value:!0}),Ie.InMemoryModelCache=Ie.CacheManager=Ie.CSVWriter=Ie.JSONWriter=Ie.DataWriter=Ie.DataRecord=Ie.DataArray=Ie.Result=Ie.ExploreMaterializer=Ie.PreparedResultMaterializer=Ie.QueryMaterializer=Ie.ModelMaterializer=Ie.SingleConnectionRuntime=Ie.ConnectionRuntime=Ie.Runtime=Ie.ExploreField=Ie.JoinRelationship=Ie.QueryField=Ie.Query=Ie.StringField=Ie.UnsupportedField=Ie.JSONField=Ie.BooleanField=Ie.NumberField=Ie.TimestampField=Ie.DateField=Ie.TimestampTimeframe=Ie.DateTimeframe=Ie.AtomicField=Ie.AtomicFieldType=Ie.Explore=Ie.SourceRelationship=Ie.FixedConnectionMap=Ie.InMemoryURLReader=Ie.EmptyURLReader=Ie.PreparedResult=Ie.DocumentCompletion=Ie.DocumentSymbol=Ie.DocumentPosition=Ie.DocumentRange=Ie.DocumentTablePath=Ie.Parse=Ie.PreparedQuery=Ie.Model=Ie.MalloyError=Ie.Malloy=void 0;const ede=M4,yi=Gi,tde=qr,aP=h2,Zht=ED,ept=m2,Un=mi,tpt=g0,nde="internal://internal.malloy";let S0=class WD{static get version(){return Zht.MALLOY_VERSION}static _parse(e,r,i,s,o){r===void 0&&(r=new URL(nde));let u=r;s!=null&&s.importBaseURL&&(u=s==null?void 0:s.importBaseURL);const a=new ede.MalloyTranslator(r.toString(),u.toString(),{urls:{[r.toString()]:e}},i);return s!=null&&s.testEnvironment&&(a.allDialectsEnabled=!0),new ide(a,o)}static parse({url:e,urlReader:r,source:i,eventStream:s,options:o}){if(i!==void 0)return WD._parse(i,e,s,o);if(r===void 0)throw new Error("Internal Error: urlReader is required.");if(e===void 0)throw new Error("Internal Error: url is required if source not present.");return RD(r,e).then(({contents:u,invalidationKey:a})=>WD._parse(u,e,s,o,a))}static async compile({url:e,source:r,parse:i,urlReader:s,connections:o,model:u,refreshSchemaCache:a,noThrowOnError:l,eventStream:c,importBaseURL:f,cacheManager:x}){var h,p,m,g,y;let E;if(a&&(E=typeof a=="number"?a:Date.now()),e===void 0&&r===void 0&&i===void 0)throw new Error("Internal Error: url, source, or parse required.");e===void 0&&(i!==void 0?e=new URL(i._translator.sourceURL):e=new URL(nde));const A={};if(r===void 0&&x!==void 0){const C=await x.getCachedModelDef(s,e.toString());if(C)return new o1(C.modelDef,[],[e.toString(),...TD(C.modelDef.dependencies)])}f??(f=e);let _;const v=e.toString();if(i!==void 0){_=i._translator;const C=(h=i._invalidationKey)!==null&&h!==void 0?h:await _P(s,e);A[v]=C}else{if(r===void 0){const{contents:C,invalidationKey:S}=await RD(s,e);A[v]=S,r=C}else{const C=await _P(s,e);A[v]=C}_=new ede.MalloyTranslator(v,f.toString(),{urls:{[v]:r}},c)}for(;;){const C=_.translate(u==null?void 0:u._modelDef);if(C.final)if(C.modelDef){await(x==null?void 0:x.setCachedModelDef(e.toString(),{modelDef:C.modelDef,invalidationKeys:A}));for(const S of _.newlyTranslatedDependencies())await(x==null?void 0:x.setCachedModelDef(S.url,{modelDef:S.modelDef,invalidationKeys:A}));return new o1(C.modelDef,C.problems||[],[...(p=u==null?void 0:u.fromSources)!==null&&p!==void 0?p:[],...(m=C.fromSources)!==null&&m!==void 0?m:[]],S=>_.referenceAt(S),S=>_.importAt(S))}else if(l){const S={name:"modelDidNotCompile",exports:[],contents:{},dependencies:{},queryList:[]},b=(u==null?void 0:u._modelDef)||S;return new o1(b,C.problems||[],[...(g=u==null?void 0:u.fromSources)!==null&&g!==void 0?g:[],...(y=C.fromSources)!==null&&y!==void 0?y:[]],R=>_.referenceAt(R),R=>_.importAt(R))}else{const S=C.problems||[],b=_.prettyErrors();throw new rde(`Error(s) compiling model:
|
|
1862
|
-
${b}`,S)}else{if(C.urls)for(const b of C.urls)try{if(DD(b))throw new Error("In order to use relative imports, you must compile a file via a URL.");if(x!==void 0){const D=await x.getCachedModelDef(s,b);if(D){for(const $ in D.invalidationKeys)A[$]=D.invalidationKeys[$];_.update({translations:{[b]:D.modelDef}});continue}}const{contents:R,invalidationKey:O}=await RD(s,new URL(b)),B={[b]:R};A[b]=O,_.update({urls:B})}catch(R){_.update({errors:{urls:{[b]:R.message}}})}const{modelAnnotation:S}=_.modelAnnotation(u==null?void 0:u._modelDef);if(C.tables){const b=new Map;for(const R in C.tables){const{connectionName:O,tablePath:B}=C.tables[R],D=b.get(O);D===void 0?b.set(O,{[R]:B}):D[R]=B}for(const[R,O]of b)try{const B=await o.lookupConnection(R),{schemas:D,errors:$}=await WD.safelyFetchTableSchema(B,O,{refreshTimestamp:E,modelAnnotation:S});_.update({tables:D,errors:{tables:$}})}catch(B){const D={},$={};for(const U in O)$[U]=B.toString();_.update({tables:D,errors:{tables:$}})}}if(C.compileSQL){const b=C.compileSQL,R=b.connection,O=(0,tpt.sqlKey)(b.connection,b.selectStr);try{const D=await(await o.lookupConnection(R)).fetchSchemaForSQLStruct(b,{refreshTimestamp:E,modelAnnotation:S});D.error&&_.update({errors:{compileSQL:{[O]:D.error}}}),D.structDef&&_.update({compileSQL:{[O]:D.structDef}})}catch(B){const D={};D[O]=B.toString(),_.update({errors:{compileSQL:D}})}}}}}static async safelyFetchTableSchema(e,r,i){const s=await e.fetchSchemaForTables(r,i);for(const o of Object.keys(r))if(s.schemas[o]===void 0&&s.errors[o]===void 0)throw new Error(`Schema fetch error for ${e.name}, no response for ${o} from ${e.dialectName}`);return s}static async run({connections:e,preparedResult:r,sqlStruct:i,connection:s,options:o}){if(!s){if(!e)throw new Error("Internal Error: Connection or LookupConnection<Connection> must be provided.");const u=(i==null?void 0:i.connection)||(r==null?void 0:r.connectionName);s=await e.lookupConnection(u)}if(i){const u=await s.runSQL(i.selectStr);return new XE({structs:[i],sql:i.selectStr,result:u.rows,totalRows:u.totalRows,runStats:u.runStats,lastStageName:i.name,malloy:"",connectionName:i.connection,sourceExplore:"",sourceFilters:[],profilingUrl:u.profilingUrl},{name:"empty_model",exports:[],contents:{},queryList:[],dependencies:{}})}else if(r){const u=await s.runSQL(r.sql,o);return new XE({...r._rawQuery,result:u.rows,totalRows:u.totalRows,runStats:u.runStats,profilingUrl:u.profilingUrl},r._modelDef)}else throw new Error("Internal error: sqlStruct or preparedResult must be provided.")}static async*runStream({connections:e,preparedResult:r,sqlStruct:i,connection:s,options:o}){if(i===void 0&&r===void 0)throw new Error("Internal error: sqlBlock or preparedResult must be provided.");const u=(i==null?void 0:i.connection)||(r==null?void 0:r.connectionName);if(s===void 0){if(e===void 0)throw new Error("Internal Error: Connection or LookupConnection<Connection> must be provided.");s=await e.lookupConnection(u)}if(!s.canStream())throw new Error(`Connection '${u}' cannot stream results.`);let a,l;if(i)l=new Gs(i),a=i.selectStr;else if(r!==void 0)l=r.resultExplore,a=r.sql;else throw new Error("Internal error: sqlStruct or preparedResult must be provided.");let c=0;for await(const f of s.runSQLStream(a,o))yield new Bd(f,c,l,void 0,void 0),c+=1}static async estimateQueryCost({connections:e,preparedResult:r,sqlStruct:i}){if(!e)throw new Error("Internal Error: Connection or LookupConnection<Connection> must be provided.");const s=(i==null?void 0:i.connection)||(r==null?void 0:r.connectionName),o=await e.lookupConnection(s);if(i)return await o.estimateQueryCost(i.selectStr);if(r)return await o.estimateQueryCost(r.sql);throw new Error("Internal error: sqlStruct or preparedResult must be provided.")}};Ie.Malloy=S0;class rde extends Error{constructor(e,r=[]){super(e),this.problems=r}}Ie.MalloyError=rde;class o1{constructor(e,r,i,s=()=>{},o=()=>{}){this.modelDef=e,this.problems=r,this.fromSources=i,this._referenceAt=s,this._importAt=o}tagParse(e){return(0,Un.annotationToTag)(this.modelDef.annotation,e)}getTaglines(e){return(0,Un.annotationToTaglines)(this.modelDef.annotation,e)}getReference(e){return this._referenceAt(e)}getImport(e){return this._importAt(e)}getPreparedQueryByName(e){const r=this.modelDef.contents[e];if((r==null?void 0:r.type)==="query")return new u1(r,this.modelDef,this.problems,e);throw new Error("Given query name does not refer to a named query.")}getPreparedQueryByIndex(e){if(e<0)throw new Error(`Invalid index ${e}.`);if(e>=this.modelDef.queryList.length)throw new Error(`Query index ${e} is out of bounds.`);return new u1(this.modelDef.queryList[e],this.modelDef,this.problems)}get preparedQuery(){return this.getPreparedQuery()}getPreparedQuery(){if(this.modelDef.queryList.length===0)throw new Error("Model has no queries.");return new u1(this.modelDef.queryList[this.modelDef.queryList.length-1],this.modelDef,this.problems)}getExploreByName(e){const r=this.modelDef.contents[e];if((0,yi.isSourceDef)(r))return new Gs(r);throw new Error("'name' is not an explore")}get explores(){return Object.values(this.modelDef.contents).filter(yi.isSourceDef).map(e=>new Gs(e))}get namedQueries(){const e=r=>r.type==="query";return Object.values(this.modelDef.contents).filter(e)}get exportedExplores(){return this.explores.filter(e=>this.modelDef.exports.includes(e.name))}get _modelDef(){return this.modelDef}}Ie.Model=o1;class u1{constructor(e,r,i,s){this.problems=i,this.name=s,this._query=e,this._modelDef=r}tagParse(e){const r=(0,Un.annotationToTag)(this._modelDef.annotation).tag;return e=(0,Un.addModelScope)(e,r),(0,Un.annotationToTag)(this._query.annotation,e)}getTaglines(e){return(0,Un.annotationToTaglines)(this._query.annotation,e)}get preparedResult(){return this.getPreparedResult()}getPreparedResult(e){const i=new yi.QueryModel(this._modelDef,e==null?void 0:e.eventStream).compileQuery(this._query,e);return new KE({...i,queryName:this.name||i.queryName},this._modelDef)}get dialect(){const e=this._query.structRef,r=typeof e=="string"?this._modelDef.contents[e]:e;if(!(0,yi.isSourceDef)(r))throw new Error("Invalid source for query");return r.dialect}getFlattenedQuery(e){return this}}Ie.PreparedQuery=u1;class ide{constructor(e,r){this.translator=e,this.invalidationKey=r}get symbols(){return(this.translator.metadata().symbols||[]).map(e=>new AD(e))}get tablePathInfo(){var e;return((e=this.translator.tablePathInfo().pathInfo)!==null&&e!==void 0?e:[]).map(i=>new sde(i))}get _translator(){return this.translator}get _invalidationKey(){return this.invalidationKey}completions(e){return(this.translator.completions(e).completions||[]).map(r=>new ode(r))}helpContext(e){return this.translator.helpContext(e).helpContext}}Ie.Parse=ide;class sde{constructor(e){this._range=a1.fromJSON(e.range),this._connectionId=e.connectionId,this._tablePath=e.tablePath}get range(){return this._range}get connectionId(){return this._connectionId}get tablePath(){return this._tablePath}}Ie.DocumentTablePath=sde;class a1{constructor(e,r){this._start=e,this._end=r}get start(){return this._start}get end(){return this._end}toJSON(){return{start:this.start.toJSON(),end:this.end.toJSON()}}static fromJSON(e){return new a1(new lP(e.start.line,e.start.character),new lP(e.end.line,e.end.character))}}Ie.DocumentRange=a1;class lP{constructor(e,r){this._line=e,this._character=r}get line(){return this._line}get character(){return this._character}toJSON(){return{line:this.line,character:this.character}}}Ie.DocumentPosition=lP;class AD{constructor(e){this._range=a1.fromJSON(e.range),this._lensRange=e.lensRange?a1.fromJSON(e.lensRange):void 0,this._type=e.type,this._name=e.name,this._children=e.children.map(r=>new AD(r))}get range(){return this._range}get lensRange(){var e;return(e=this._lensRange)!==null&&e!==void 0?e:this._range}get type(){return this._type}get name(){return this._name}get children(){return this._children}}Ie.DocumentSymbol=AD;class ode{constructor(e){this.type=e.type,this.text=e.text}}Ie.DocumentCompletion=ode;class KE{constructor(e,r){this.modelDef=r,this.inner=e}static fromJson({query:e,modelDef:r}){if(!e||!r)throw new Error("Missing required properties in JSON data");return new KE(e,r)}tagParse(e){const r=(0,Un.annotationToTag)(this.modelDef.annotation).tag;return e=(0,Un.addModelScope)(e,r),(0,Un.annotationToTag)(this.inner.annotation,e)}getTaglines(e){return(0,Un.annotationToTaglines)(this.inner.annotation,e)}get annotation(){return this.inner.annotation}get modelAnnotation(){return this.modelDef.annotation}get modelTag(){return(0,Un.annotationToTag)(this.modelDef.annotation).tag}get connectionName(){return this.inner.connectionName}get _rawQuery(){return this.inner}get _modelDef(){return this.modelDef}get sql(){return this.inner.sql}get dependenciesToMaterialize(){return this.inner.dependenciesToMaterialize}get materialization(){return this.inner.materialization}get resultExplore(){if(this.inner.structs.length===0)throw new Error("Malformed query result.");const e=this.inner.structs[this.inner.structs.length-1],r={...e,annotation:this.inner.annotation,name:this.inner.queryName||e.name};try{return new Gs(r,this.sourceExplore)}catch{return new Gs(r)}}get sourceExplore(){const e=this.inner.sourceExplore,r=this.modelDef.contents[e];if(r&&(0,yi.isSourceDef)(r))return new Gs(r)}get _sourceExploreName(){return this.inner.sourceExplore}get _sourceFilters(){return this.inner.sourceFilters||[]}}Ie.PreparedResult=KE;class ude{async readURL(e){throw new Error("No files.")}async getInvalidationKey(e){throw new Error("No files.")}}Ie.EmptyURLReader=ude;class npt{constructor(e){this.files=e}async readURL(e){const r=this.files.get(e.toString());if(r!==void 0)return Promise.resolve({contents:r,invalidationKey:this.invalidationKey(e,r)});throw new Error(`File not found '${e}'`)}async getInvalidationKey(e){const r=this.files.get(e.toString());if(r!==void 0)return Promise.resolve(this.invalidationKey(e,r));throw new Error(`File not found '${e}'`)}invalidationKey(e,r){return DD(e.toString())?null:vde(r)}}Ie.InMemoryURLReader=npt;class _D{constructor(e,r){this.connections=e,this.defaultConnectionName=r}async getConnection(e){if(e===void 0)if(this.defaultConnectionName!==void 0)e=this.defaultConnectionName;else throw new Error("No default connection.");const r=this.connections.get(e);if(r!==void 0)return Promise.resolve(r);throw new Error(`No connection found with name ${e}.`)}listConnections(){return Array.from(this.connections.values())}async lookupConnection(e){return this.getConnection(e)}static fromArray(e){return new _D(new Map(e.map(r=>[r.name,r])))}}Ie.FixedConnectionMap=_D;var ade;(function(t){t.Nested="nested",t.BaseTable="base_table",t.Cross="cross",t.One="one",t.Many="many",t.Inline="inline"})(ade||(Ie.SourceRelationship=ade={}));class cP{constructor(e,r,i){this._name=e,this._parent=r,this._source=i}get source(){return this.source}get name(){return this._name}get sourceClasses(){const e=[];return this.source&&e.push(this.source.name),e.push(this.name),e}get fieldPath(){const e=[this.name];let r=this._parent;for(;r;)e.unshift(r.name),r=r._parent;return e}hasParentExplore(){return this._parent!==void 0}isExplore(){return this instanceof Gs}isQuery(){return this instanceof gP}}class Gs extends cP{constructor(e,r,i){super(e.as||e.name,r,i),this._structDef=e,this._parentExplore=r,this.sourceExplore=i}get source(){return this.sourceExplore}isIntrinsic(){return(0,yi.isAtomicFieldType)(this._structDef.type)?!("e"in this._structDef):!1}isExploreField(){return!1}tagParse(e){return(0,Un.annotationToTag)(this._structDef.annotation,e)}getTaglines(e){return(0,Un.annotationToTaglines)(this._structDef.annotation,e)}get modelTag(){return this.parsedModelTag||(this.parsedModelTag=(0,Un.annotationToTag)(this._structDef.modelAnnotation).tag),this.parsedModelTag}get name(){return this.structDef.as||this.structDef.name}getQueryByName(e){const r=this.sourceStructDef;if(!r)throw new Error(`Cannot get query by name from a struct of type ${this.structDef.type}`);const i={type:"query",structRef:r,pipeline:[{type:"reduce",queryFields:[{type:"fieldref",path:[e]}]}]};return new u1(i,this.modelDef,[],e)}get modelDef(){if(!(0,yi.isSourceDef)(this.structDef))throw new Error(`Cannot create pseudo model for struct type ${this.structDef.type}`);return{name:"generated_model",exports:[],contents:{[this.structDef.name]:this.structDef},queryList:[],dependencies:{}}}getSingleExploreModel(){return new o1(this.modelDef,[],[])}get fieldMap(){var e;if(this._fieldMap===void 0){const r=((e=this.source)===null||e===void 0?void 0:e.fieldMap)||new Map;this._fieldMap=new Map(this.structDef.fields.map(i=>{const s=i.as||i.name,o=r.get(i.name);if((0,yi.isJoined)(i))return[s,new yP(i,this,o)];if(i.type==="turtle")return[s,new gP(i,this,o)];if(i.type==="string")return[s,new mP(i,this,o)];if(i.type==="number")return[s,new vD(i,this,o)];if(i.type==="date")return i.timeframe&&["day_of_month","day_of_week","day_of_year"].includes(i.timeframe)?[s,new vD({...i,type:"number"},this,o)]:[s,new fP(i,this,o)];if(i.type==="timestamp")return[s,new xP(i,this,o)];if(i.type==="boolean")return[s,new dP(i,this,o)];if(i.type==="json")return[s,new hP(i,this,o)];if(i.type==="sql native")return[s,new pP(i,this,o)]}))}return this._fieldMap}get allFields(){return[...this.fieldMap.values()]}get allFieldsWithOrder(){var e,r,i;if(!this._allFieldsWithOrder){const s=[...((i=(r=(e=this.sourceStructDef)===null||e===void 0?void 0:e.resultMetadata)===null||r===void 0?void 0:r.orderBy)===null||i===void 0?void 0:i.map(u=>{if(typeof u.field=="string")return{field:this.fieldMap.get(u.field),dir:u.dir};throw new Error("Does not support mapping order by from number.")}))||[]],o=new Set(s.map(u=>u.field.name));this._allFieldsWithOrder=[...s,...this.allFields.filter(u=>!o.has(u.name)).map(u=>({field:u,dir:"asc"}))]}return this._allFieldsWithOrder}get intrinsicFields(){return[...this.fieldMap.values()].filter(e=>e.isIntrinsic())}get dimensions(){return[...this.allFieldsWithOrder].filter(e=>e.field.isAtomicField()&&e.field.sourceWasDimension())}getFieldByName(e){const r=this.fieldMap.get(e);if(r===void 0)throw new Error(`No such field ${e}.`);return r}getFieldByNameIfExists(e){return this.fieldMap.get(e)}get primaryKey(){var e;return(e=this.sourceStructDef)===null||e===void 0?void 0:e.primaryKey}get parentExplore(){return this._parentExplore}hasParentExplore(){return this instanceof yP}get filters(){var e;return(0,yi.isSourceDef)(this.structDef)?((e=this.structDef.resultMetadata)===null||e===void 0?void 0:e.filterList)||[]:[]}get limit(){var e,r;return(r=(e=this.sourceStructDef)===null||e===void 0?void 0:e.resultMetadata)===null||r===void 0?void 0:r.limit}get structDef(){return this._structDef}get queryTimezone(){var e;return(e=this.sourceStructDef)===null||e===void 0?void 0:e.queryTimezone}get sourceStructDef(){if((0,yi.isSourceDef)(this.structDef))return this.structDef}toJSON(){var e,r;return{_structDef:this._structDef,sourceExplore:(e=this.sourceExplore)===null||e===void 0?void 0:e.toJSON(),_parentExplore:(r=this._parentExplore)===null||r===void 0?void 0:r.toJSON()}}static fromJSON(e){const r=e._parentExplore!==void 0?Gs.fromJSON(e._parentExplore):void 0,i=e.sourceExplore!==void 0?Gs.fromJSON(e.sourceExplore):void 0;return new Gs(e._structDef,r,i)}get location(){return this.structDef.location}}Ie.Explore=Gs;var Ka;(function(t){t.String="string",t.Number="number",t.Boolean="boolean",t.Date="date",t.Timestamp="timestamp",t.Json="json",t.NativeUnsupported="sql native",t.Error="error"})(Ka||(Ie.AtomicFieldType=Ka={}));class df extends cP{constructor(e,r,i){super(e.as||e.name,r,i),this.fieldTypeDef=e,this.parent=r}get type(){switch(this.fieldTypeDef.type){case"string":return Ka.String;case"boolean":return Ka.Boolean;case"date":return Ka.Date;case"timestamp":return Ka.Timestamp;case"number":return Ka.Number;case"json":return Ka.Json;case"sql native":return Ka.NativeUnsupported;case"error":return Ka.Error;case"record":case"array":throw new Error(`MTOY TODO IMPLEMENT Atomic ${this.fieldTypeDef.type}`);default:{const e=this.fieldTypeDef;throw new Error(`Can't make an atomic field from ${e}`)}}}tagParse(e){return e=(0,Un.addModelScope)(e,this.parent.modelTag),(0,Un.annotationToTag)(this.fieldTypeDef.annotation,e)}getTaglines(e){return(0,Un.annotationToTaglines)(this.fieldTypeDef.annotation,e)}isIntrinsic(){return(0,yi.fieldIsIntrinsic)(this.fieldTypeDef)}isQueryField(){return!1}isExploreField(){return!1}isAtomicField(){return!0}isCalculation(){return(0,yi.expressionIsCalculation)(this.fieldTypeDef.expressionType)}get sourceField(){throw new Error}get sourceClasses(){const e=this.fieldTypeDef.name||this.fieldTypeDef.as;return e?[e]:[]}get referenceId(){var e;return(e=this.fieldTypeDef.resultMetadata)===null||e===void 0?void 0:e.referenceId}sourceWasMeasure(){var e;return((e=this.fieldTypeDef.resultMetadata)===null||e===void 0?void 0:e.fieldKind)==="measure"}sourceWasMeasureLike(){var e,r;return((e=this.fieldTypeDef.resultMetadata)===null||e===void 0?void 0:e.fieldKind)==="measure"||((r=this.fieldTypeDef.resultMetadata)===null||r===void 0?void 0:r.fieldKind)==="struct"}sourceWasDimension(){var e;return((e=this.fieldTypeDef.resultMetadata)===null||e===void 0?void 0:e.fieldKind)==="dimension"}hasParentExplore(){return!0}isString(){return this instanceof mP}isNumber(){return this instanceof vD}isDate(){return this instanceof fP}isBoolean(){return this instanceof dP}isJSON(){return this instanceof hP}isTimestamp(){return this instanceof xP}isUnsupported(){return this instanceof pP}get parentExplore(){return this.parent}get expression(){const e=".",r=this.fieldTypeDef.resultMetadata;return(r==null?void 0:r.sourceExpression)||(r!=null&&r.sourceField.includes(e)?r==null?void 0:r.sourceField:this.name)}get location(){return this.fieldTypeDef.location}}Ie.AtomicField=df;var $d;(function(t){t.Day="day",t.Week="week",t.Month="month",t.Quarter="quarter",t.Year="year"})($d||(Ie.DateTimeframe=$d={}));var Ja;(function(t){t.Day="day",t.Week="week",t.Month="month",t.Quarter="quarter",t.Year="year",t.Second="second",t.Hour="hour",t.Minute="minute"})(Ja||(Ie.TimestampTimeframe=Ja={}));class fP extends df{constructor(e,r,i){super(e,r,i),this.fieldDateDef=e}get timeframe(){if(this.fieldDateDef.timeframe!==void 0)switch(this.fieldDateDef.timeframe){case"day":return $d.Day;case"week":return $d.Week;case"month":return $d.Month;case"quarter":return $d.Quarter;case"year":return $d.Year}}}Ie.DateField=fP;class xP extends df{constructor(e,r,i){super(e,r,i),this.fieldTimestampDef=e}get timeframe(){if(this.fieldTimestampDef.timeframe!==void 0)switch(this.fieldTimestampDef.timeframe){case"day":return Ja.Day;case"week":return Ja.Week;case"month":return Ja.Month;case"quarter":return Ja.Quarter;case"year":return Ja.Year;case"second":return Ja.Second;case"hour":return Ja.Hour;case"minute":return Ja.Minute}}}Ie.TimestampField=xP;class vD extends df{constructor(e,r,i){super(e,r,i),this.fieldNumberDef=e}}Ie.NumberField=vD;class dP extends df{constructor(e,r,i){super(e,r,i),this.fieldBooleanDef=e}}Ie.BooleanField=dP;class hP extends df{constructor(e,r,i){super(e,r,i),this.fieldJSONDef=e}}Ie.JSONField=hP;class pP extends df{constructor(e,r,i){super(e,r,i),this.fieldUnsupportedDef=e}get rawType(){return this.fieldUnsupportedDef.rawType}}Ie.UnsupportedField=pP;class mP extends df{constructor(e,r,i){super(e,r,i),this.fieldStringDef=e}}Ie.StringField=mP;class lde extends cP{constructor(e,r,i){super(e.as||e.name,r,i),this.turtleDef=e}get source(){return this.sourceQuery}isIntrinsic(){return!1}get location(){return this.turtleDef.location}}Ie.Query=lde;class gP extends lde{constructor(e,r,i){super(e,r,i),this.parent=r}tagParse(e){return e=(0,Un.addModelScope)(e,this.parent.modelTag),(0,Un.annotationToTag)(this.turtleDef.annotation,e)}getTaglines(e){return(0,Un.annotationToTaglines)(this.turtleDef.annotation,e)}isQueryField(){return!0}isExploreField(){return!1}isAtomicField(){return!1}get sourceClasses(){const e=this.turtleDef.name||this.turtleDef.as;return e?[e]:[]}hasParentExplore(){return!0}get parentExplore(){return this.parent}get expression(){return this.name}}Ie.QueryField=gP;var l1;(function(t){t.OneToOne="one_to_one",t.OneToMany="one_to_many",t.ManyToOne="many_to_one"})(l1||(Ie.JoinRelationship=l1={}));class yP extends Gs{constructor(e,r,i){super(e,r,i),this._parentExplore=r}get joinRelationship(){if((0,yi.isJoined)(this.structDef))switch(this.structDef.join){case"one":return l1.OneToOne;case"many":case"cross":return l1.ManyToOne}throw new Error("A source field must have a join relationship.")}get isRecord(){return this.joinRelationship===l1.OneToOne}get isArray(){return this.joinRelationship!==l1.OneToOne}tagParse(e){return e=(0,Un.addModelScope)(e,this._parentExplore.modelTag),(0,Un.annotationToTag)(this._structDef.annotation,e)}isQueryField(){return!1}isExploreField(){return!0}isAtomicField(){return!1}get parentExplore(){return this._parentExplore}get sourceClasses(){const e=this.structDef.name||this.structDef.as;return e?[e]:[]}}Ie.ExploreField=yP;class EP{constructor({urlReader:e,connections:r,connection:i,eventStream:s,cacheManager:o}){if(this.isTestRuntime=!1,r===void 0){if(i===void 0)throw new Error("A LookupConnection<Connection> or Connection is required.");r={lookupConnection:()=>Promise.resolve(i)}}e===void 0&&(e=new ude),this._urlReader=e,this._connections=r,this._eventStream=s,this._cacheManager=o}get cacheManager(){return this._cacheManager}get urlReader(){return this._urlReader}get connections(){return this._connections}get eventStream(){return this._eventStream}loadModel(e,r){const{refreshSchemaCache:i,noThrowOnError:s}=r||{};this.isTestRuntime&&(r===void 0?r={testEnvironment:!0}:r={...r,testEnvironment:!0});const o=e instanceof URL?{url:e}:{source:e};return new JE(this,async()=>S0.compile({...o,urlReader:this.urlReader,connections:this.connections,refreshSchemaCache:i,noThrowOnError:s,eventStream:this.eventStream,replaceMaterializedReferences:r==null?void 0:r.replaceMaterializedReferences,materializedTablePrefix:r==null?void 0:r.materializedTablePrefix,importBaseURL:r==null?void 0:r.importBaseURL,testEnvironment:r==null?void 0:r.testEnvironment,cacheManager:this.cacheManager}),r)}_loadModelFromModelDef(e,r){return new JE(this,async()=>new o1(e,[],[]),r)}loadQuery(e,r){return this.loadModel(e,r).loadFinalQuery()}loadQueryByIndex(e,r,i){return this.loadModel(e,i).loadQueryByIndex(r,i)}loadQueryByName(e,r,i){return this.loadModel(e,i).loadQueryByName(r,i)}getModel(e,r){return this.loadModel(e,r).getModel()}getQuery(e,r){return this.loadQuery(e,r).getPreparedQuery()}getQueryByIndex(e,r,i){return this.loadQueryByIndex(e,r,i).getPreparedQuery()}getQueryByName(e,r,i){return this.loadQueryByName(e,r,i).getPreparedQuery()}}Ie.Runtime=EP;class rpt extends EP{constructor({urlReader:e,connections:r}){super({connections:_D.fromArray(r),urlReader:e}),this.rawConnections=r}}Ie.ConnectionRuntime=rpt;class ipt extends EP{constructor({urlReader:e,connection:r,eventStream:i,cacheManager:s}){super({urlReader:e,eventStream:i,cacheManager:s,connection:r}),this.connection=r}get supportsNesting(){return(0,aP.getDialect)(this.connection.dialectName).supportsNesting}quote(e){return(0,aP.getDialect)(this.connection.dialectName).sqlMaybeQuoteIdentifier(e)}get dialect(){return(0,aP.getDialect)(this.connection.dialectName)}getQuoter(){return e=>this.quote(e.toString())}}Ie.SingleConnectionRuntime=ipt;class CD{constructor(e,r){this.runtime=e,this._materialize=r}materialize(){return this.materialized===void 0?this.rematerialize():this.materialized}rematerialize(){return this.materialized=this._materialize(),this.materialized}makeQueryMaterializer(e,r){return new cde(this.runtime,e,r)}makeExploreMaterializer(e,r){return new xde(this.runtime,e,r)}makePreparedResultMaterializer(e){return new fde(this.runtime,e)}}class JE extends CD{constructor(e,r,i){super(e,r),this.runtime=e,this.compileQueryOptions=i}loadFinalQuery(e){return this.makeQueryMaterializer(async()=>(await this.materialize()).getPreparedQuery(),{...this.compileQueryOptions,...e})}loadQueryByIndex(e,r){return this.makeQueryMaterializer(async()=>(await this.materialize()).getPreparedQueryByIndex(e),{...this.compileQueryOptions,...r})}loadQueryByName(e,r){return this.makeQueryMaterializer(async()=>(await this.materialize()).getPreparedQueryByName(e),{...this.compileQueryOptions,...r})}loadQuery(e,r){const{refreshSchemaCache:i,noThrowOnError:s}=r||{};return this.makeQueryMaterializer(async()=>{const o=this.runtime.urlReader,u=this.runtime.connections;this.runtime.isTestRuntime&&(r===void 0?r={testEnvironment:!0}:r={...r,testEnvironment:!0});const a=e instanceof URL?{url:e}:{source:e},l=await this.getModel();return(await S0.compile({...a,urlReader:o,connections:u,model:l,refreshSchemaCache:i,noThrowOnError:s,importBaseURL:r==null?void 0:r.importBaseURL,testEnvironment:r==null?void 0:r.testEnvironment,...this.compileQueryOptions})).preparedQuery})}extendModel(e,r){return this.runtime.isTestRuntime&&(r===void 0?r={testEnvironment:!0}:r={...r,testEnvironment:!0}),new JE(this.runtime,async()=>{const i=this.runtime.urlReader,s=this.runtime.connections,o=e instanceof URL?{url:e}:{source:e},u=await this.getModel();return await S0.compile({...o,urlReader:i,connections:s,model:u,refreshSchemaCache:r==null?void 0:r.refreshSchemaCache,noThrowOnError:r==null?void 0:r.noThrowOnError,importBaseURL:r==null?void 0:r.importBaseURL,testEnvironment:r==null?void 0:r.testEnvironment,...this.compileQueryOptions})},r)}async search(e,r,i=1e3,s=void 0,o){const u=await this.materialize(),a=new yi.QueryModel(u._modelDef,o),l=u.getExploreByName(e).structDef;if(!(0,yi.isSourceDef)(l))throw new Error("Source to be searched was unexpectedly, not a source");const c=l.connection,f=await this.runtime.connections.lookupConnection(c);return await a.searchIndex(f,e,r,i,s)}async searchValueMap(e,r=10,i){const o=(await this.materialize()).getExploreByName(e);if(!(0,yi.isSourceDef)(o.structDef))throw new Error("Source to be searched was unexpectedly, not a source");let u="{index: *}";o.getFieldByNameIfExists("search_index")&&(u="search_index");const a=`
|
|
1861
|
+
${s}`:e=s}return e}childRequest(e){var r;const i=decodeURI(new URL(e,this.sourceURL).toString()),s=(r=this.childTranslators.get(i))===null||r===void 0?void 0:r.translate();if(s!=null&&s.compileSQL)return{compileSQL:s.compileSQL}}getChildExports(e){const r={},i=decodeURI(new URL(e,this.sourceURL).toString()),s=this.childTranslators.get(i);if(s&&s.translate().modelDef)for(const u of s.modelDef.exports){const a=s.modelDef.contents[u];((0,yht.isSourceDef)(a)||a.type==="query")&&(r[u]=a)}return r}translate(e){if(this.finalAnswer)return this.finalAnswer;const r=this.translateStep.step(this,e);return r.final&&(this.finalAnswer=r),r}translatorForDependency(e){return this.childTranslators.get(e)}importAt(e){for(let r=0;r<this.imports.length;r++){const i=this.imports[r];if((0,nP.locationContainsPosition)(i.location,e))return i}}metadata(){return this.metadataStep.step(this)}modelAnnotation(e){return this.modelAnnotationStep.step(this,e)}tablePathInfo(){return this.tablePathInfoStep.step(this)}completions(e){return this.completionsStep.step(this,e)}helpContext(e){return this.helpContextStep.step(this,e)}defaultLocation(){return{url:this.sourceURL,range:{start:{line:0,character:0},end:{line:0,character:0}}}}rangeFromContext(e){return(0,nP.rangeFromContext)(this.parseStep.sourceInfo,e)}firstReferenceToDialect(e){return this.dialectAlreadyChecked[e]?!1:(this.dialectAlreadyChecked[e]=!0,!0)}experimentalDialectEnabled(e){if(this.allDialectsEnabled)return!0;const r=this.compilerFlags.tag("experimental");return r!==void 0&&(r.bare()||r.has("dialect",e))}}Wc.MalloyTranslation=rP;class Qxe extends rP{constructor(e,r){super(e),this.root=r}}Wc.MalloyChildTranslator=Qxe;class Pht extends rP{constructor(e,r=null,i=null,s=null){super(e,r),this.eventStream=s,this.schemaZone=new tP.Zone,this.importZone=new tP.Zone,this.pretranslatedModels=new Map,this.sqlQueryZone=new tP.Zone,this.root=this,this.logger=new Hxe.BaseMessageLogger(s),i&&this.update(i)}update(e){var r,i,s;this.schemaZone.updateFrom(e.tables,(r=e.errors)===null||r===void 0?void 0:r.tables),this.importZone.updateFrom(e.urls,(i=e.errors)===null||i===void 0?void 0:i.urls),this.sqlQueryZone.updateFrom(e.compileSQL,(s=e.errors)===null||s===void 0?void 0:s.compileSQL);for(const o in e.translations)this.pretranslatedModels.set(o,e.translations[o])}logError(e,r,i){return this.logger.log((0,Hxe.makeLogMessage)(e,r,{severity:"error",...i})),e}}Wc.MalloyTranslator=Pht;function zxe(t){return[...Object.keys(t),...Object.keys(t).map(e=>zxe(t[e])).flat()]}var r1={};Object.defineProperty(r1,"__esModule",{value:!0}),r1.exploreQueryWalkerBuilder=r1.ExploreQueryWalker=void 0;const Uht=T0;class Wxe{constructor(e){this.inDocument=!1,this.exploreClauseRefs=[],this.tokens=e}exploreQueryAtOffset(e){return this.exploreClauseRefs.find(r=>r.range[0]===void 0||r.range[1]===void 0?!1:r.range[0]<=e&&r.range[1]>=e)}filterAtOffset(e){const r=this.exploreQueryAtOffset(e);if(r)return r.filterRefs.find(i=>i.range[0]===void 0||i.range[1]===void 0?!1:i.range[0]<=e&&i.range[1]>=e)}hasFilterListAtOffset(e){const r=this.exploreQueryAtOffset(e);return r?!!r.filterLists.find(i=>i.range[0]===void 0||i.range[1]===void 0?!1:i.range[0]<=e&&i.range[1]>=e):!1}enterMalloyDocument(){this.inDocument=!0}}r1.ExploreQueryWalker=Wxe;function jht(t,e){const r=new Wxe(t),i=r;return Uht.ParseTreeWalker.DEFAULT.walk(i,e),r}r1.exploreQueryWalkerBuilder=jht;var i1={},VE={},Va={};Object.defineProperty(Va,"__esModule",{value:!0}),Va.getResultStructMetadataAnnotation=Va.convertFieldInfos=Va.modelDefToModelInfo=void 0;const Ya=Gi,iP=js,sP=mi,Gxe=$o;function qht(t){const e={entries:[],anonymous_queries:[]};for(const[r,i]of Object.entries(t.contents))if(t.exports.includes(r)){if((0,Ya.isSourceDef)(i)){const s=i.parameters&&Object.entries(i.parameters).length>0?Object.entries(i.parameters).map(([u,a])=>(0,Ya.isAtomic)(a)?{name:u,type:yD(a),default_value:Vxe(a.value)}:{name:u,type:{kind:"filter_expression_type"},default_value:Vxe(a.value)}):void 0,o={kind:"source",name:r,schema:{fields:s1(i,i.fields)},parameters:s,annotations:oP(i)};e.entries.push(o)}else if(i.type==="query"){const s=(0,iP.getResultStructDefForQuery)(t,i),o=oP(i),u=s.resultMetadata?gD(s,s.resultMetadata):void 0,a=[...o??[],...u?[u]:[]],l={kind:"source",name:r,schema:{fields:s1(s,s.fields)},annotations:a.length>0?a:void 0};e.entries.push(l)}}for(const r of t.queryList){const i=(0,iP.getResultStructDefForQuery)(t,r),s=oP(r),o=i.resultMetadata?gD(i,i.resultMetadata):void 0,u=[...s??[],...o?[o]:[]],a={schema:{fields:s1(i,i.fields)},annotations:u.length>0?u:void 0};e.anonymous_queries.push(a)}return e}Va.modelDefToModelInfo=qht;function Vxe(t){if(t!==null)switch(t.node){case"numberLiteral":return{kind:"number_literal",number_value:parseFloat(t.literal)};case"stringLiteral":return{kind:"string_literal",string_value:t.literal};case"filterLiteral":return{kind:"filter_expression_literal",filter_expression_value:t.filterSrc};case"timeLiteral":return{kind:"timestamp_literal",timestamp_value:t.literal};case"true":return{kind:"boolean_literal",boolean_value:!0};case"false":return{kind:"boolean_literal",boolean_value:!1};case"null":return{kind:"null_literal"};default:throw new Error("Invalid parameter default value")}}function oP(t){return(0,sP.annotationToTaglines)(t.annotation).map(r=>({value:r}))}function s1(t,e){var r,i,s;const o=[];for(const u of e){if(!(u.accessModifier===void 0))continue;const c=(0,sP.annotationToTaglines)(u.annotation).map(x=>({value:x})),f=c.length>0?c:void 0;if((0,Ya.isTurtle)(u)){const x=(0,iP.getResultStructDefForView)(t,u),h=x.resultMetadata?gD(x,x.resultMetadata):void 0,p=[...f??[],...h?[h]:[]],m={kind:"view",name:(r=u.as)!==null&&r!==void 0?r:u.name,annotations:p.length>0?p:void 0,schema:{fields:s1(x,x.fields)}};o.push(m)}else if((0,Ya.isAtomic)(u)){const x=(0,Ya.expressionIsAggregate)(u.expressionType),h=(0,Ya.expressionIsScalar)(u.expressionType);if(!x&&!h||u.type==="error")continue;const p=u.resultMetadata?Yxe(u,u.resultMetadata):void 0,m=[...f??[],...p?[p]:[]],g={kind:x?"measure":"dimension",name:(i=u.as)!==null&&i!==void 0?i:u.name,type:yD(u),annotations:m.length>0?m:void 0};o.push(g)}else if((0,Ya.isJoinedSource)(u)){const x={kind:"join",name:(s=u.as)!==null&&s!==void 0?s:u.name,annotations:f,schema:{fields:s1(u,u.fields)},relationship:u.join};o.push(x)}}return o}Va.convertFieldInfos=s1;function Yxe(t,e){const r=Gxe.Tag.withPrefix("#(malloy) ");let i=!1;if(e.referenceId!==void 0&&(r.set(["reference_id"],e.referenceId),i=!0),e.fieldKind==="measure"&&(r.set(["calculation"]),i=!0),e.filterList){const s=e.filterList.filter(o=>o.expressionType==="scalar").map(o=>o.code);r.set(["drill_filters"],s),i=!0}if(e.fieldKind==="dimension"){const o=(e==null?void 0:e.sourceExpression)||(e!=null&&e.sourceField.includes(".")?e==null?void 0:e.sourceField:Qht(t.name));r.set(["drill_expression"],o),i=!0}return i?{value:r.toString()}:void 0}function Hht(t){return t.replace(/\\/g,"\\\\").replace(/`/g,"\\`")}function Qht(t){return t.match(/^[A-Za-z_][0-9A-Za-z_]*$/)?t:`\`${Hht(t)}\``}function gD(t,e){var r,i;const s=Gxe.Tag.withPrefix("#(malloy) ");let o=!1;if(e.limit!==void 0&&(s.set(["limit"],e.limit),o=!0),e.filterList){const u=e.filterList.filter(a=>a.expressionType==="scalar").map(a=>a.code);u.length>0&&(s.set(["drill_filters"],u),o=!0)}if(e.orderBy){for(let u=0;u<e.orderBy.length;u++){const a=e.orderBy[u],l=typeof a.field=="number"?(r=t.fields[a.field-1].as)!==null&&r!==void 0?r:t.fields[a.field-1].name:a.field,c=(i=a.dir)!==null&&i!==void 0?i:null;s.set(["ordered_by",u,l],c)}o=!0}return o?{value:s.toString()}:void 0}Va.getResultStructMetadataAnnotation=gD;function yD(t){if((0,Ya.isBasicAtomic)(t))switch(t.type){case"string":return{kind:"string_type"};case"number":return{kind:"number_type",subtype:t.numberType==="float"?"decimal":t.numberType==="integer"?"integer":void 0};case"boolean":return{kind:"boolean_type"};case"date":{const e=t.timeframe;return e&&!zht(e)?{kind:"timestamp_type",timeframe:t.timeframe}:{kind:"date_type",timeframe:Wht(t.timeframe)}}case"timestamp":return{kind:"timestamp_type",timeframe:t.timeframe};case"json":return{kind:"json_type"};case"sql native":return{kind:"sql_native_type",sql_type:t.rawType};case"error":throw new Error("Error type is not supported in stable interface")}else{if((0,Ya.isRepeatedRecord)(t))return{kind:"array_type",element_type:Kxe(t)};if(t.type==="record")return Kxe(t);if(t.type==="array")return{kind:"array_type",element_type:yD(t.elementTypeDef)}}throw new Error("Unexpected field type")}function Kxe(t){return{kind:"record_type",fields:t.fields.map(e=>{const r=[];if("resultMetadata"in e&&e.resultMetadata){const i=Yxe(e,e.resultMetadata);i&&r.push(i)}if(e.annotation){const i=(0,sP.annotationToTaglines)(e.annotation);r.push(...i.map(s=>({value:s})))}if((0,Ya.isAtomic)(e))return{name:e.name,annotations:r.length>0?r:void 0,type:yD(e)};throw new Error("Expected record type to not have a table as its child")})}}function zht(t){switch(t){case"day":case"week":case"month":case"year":case"quarter":return!0;default:return!1}}function Wht(t){switch(t){case void 0:return;case"day":case"week":case"month":case"year":case"quarter":return t;default:throw new Error(`Invalid date timeframe ${t}`)}}function l1t(t){return t}function c1t(t){return t}(function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.mapLogs=t.DEFAULT_LOG_RANGE=t.wrapResult=t.mapData=t.wrapLegacyConnection=t.wrapLegacyInfoConnection=void 0;const e=$o,r=mi,i=Va,s=qr;function o(x){return{get dialectName(){return x.dialectName},async fetchSchemaForSQLQuery(h){const p=await x.fetchSchemaForSQLStruct({connection:x.name,selectStr:h},{}),m=p.structDef;if(m===void 0)throw new Error(p.error);return{fields:(0,i.convertFieldInfos)(m,m.fields)}},async fetchSchemaForTable(h){const p=`${x.name}:${h}`,m=await x.fetchSchemaForTables({[p]:h},{}),g=m.schemas[p];if(g===void 0)throw new Error(m.errors[p]);return{fields:(0,i.convertFieldInfos)(g,g.fields)}}}}t.wrapLegacyInfoConnection=o;function u(x){return{...o(x),runSQL:async(h,p)=>{const m=await x.runSQL(h);return l(m.rows,p)}}}t.wrapLegacyConnection=u;function a(x){if(x instanceof Date)return x;if(x.constructor.name==="Date")return new Date(x);if(typeof x=="number")return new Date(x);if(typeof x!="string")return new Date(x.value);{let p=s.DateTime.fromISO(x,{zone:"UTC"});return p.isValid||(p=s.DateTime.fromSQL(x,{zone:"UTC"})),p.toJSDate()}}function l(x,h){function p(y,E){if(y===null)return{kind:"null_cell"};if(E.type.kind==="date_type"||E.type.kind==="timestamp_type"){const A=a(y).toISOString();return E.type.kind==="date_type"?{kind:"date_cell",date_value:A}:{kind:"timestamp_cell",timestamp_value:A}}else if(E.type.kind==="boolean_type"){if(typeof y=="number")return{kind:"boolean_cell",boolean_value:y!==0};if(typeof y!="boolean")throw new Error(`Invalid boolean ${y}`);return{kind:"boolean_cell",boolean_value:y}}else if(E.type.kind==="number_type"){if(typeof y!="number")throw new Error(`Invalid number ${y}`);return{kind:"number_cell",number_value:y}}else if(E.type.kind==="string_type"){if(typeof y!="string")throw new Error(`Invalid string ${y}`);return{kind:"string_cell",string_value:y}}else if(E.type.kind==="array_type"){if(!Array.isArray(y))throw new Error(`Invalid array ${y}`);return{kind:"array_cell",array_value:y.map(A=>p(A,{name:"array_element",type:E.type.element_type}))}}else{if(E.type.kind==="json_type")return{kind:"json_cell",json_value:JSON.stringify(y)};if(E.type.kind==="sql_native_type")return{kind:"sql_native_cell",sql_native_value:JSON.stringify(y)};{const A=E.type;if(A.kind!=="record_type")throw new Error(`Invalid record in result ${JSON.stringify(E)}, ${JSON.stringify(y)}`);return m(y,{kind:"join",relationship:"many",name:"array_element",schema:{fields:A.fields.map(_=>({kind:"dimension",..._}))}})}}}function m(y,E){const A=[];for(const _ of E.schema.fields){const v=y[_.name];if(_.kind!=="dimension")throw new Error("Invalid result -- expected all fields to be dimensions");const C=p(v,_);A.push(C)}return{kind:"record_cell",record_value:A}}const g={kind:"join",schema:h,name:"root",relationship:"one"};return{kind:"array_cell",array_value:x.map(y=>m(y,g))}}t.mapData=l;function c(x){const h=x._queryResult.structs,p=h[h.length-1],m={fields:(0,i.convertFieldInfos)(p,p.fields)},g=(0,r.annotationToTaglines)(x.annotation).map(E=>({value:E})),y=p.resultMetadata?(0,i.getResultStructMetadataAnnotation)(p,p.resultMetadata):void 0;return y&&g.push(y),g.push(...p.resultMetadata?[]:[]),x.sourceExplore&&g.push({value:e.Tag.withPrefix("#(malloy) ").set(["source_name"],x.sourceExplore.name).toString()}),g.push({value:e.Tag.withPrefix("#(malloy) ").set(["query_name"],x.resultExplore.name).toString()}),{schema:m,data:l(x.data.toObject(),m),connection_name:x.connectionName,annotations:g.length>0?g:void 0,query_timezone:x.data.field.queryTimezone,sql:x.sql}}t.wrapResult=c,t.DEFAULT_LOG_RANGE={start:{line:0,character:0},end:{line:0,character:0}};function f(x,h){return x.map(p=>{var m,g,y,E;return{severity:p.severity,message:p.message,range:(g=(m=p.at)===null||m===void 0?void 0:m.range)!==null&&g!==void 0?g:t.DEFAULT_LOG_RANGE,url:(E=(y=p.at)===null||y===void 0?void 0:y.url)!==null&&E!==void 0?E:h}})}t.mapLogs=f})(VE);var Ght=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),Vht=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),Yht=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&Ght(e,t,r);return Vht(e,t),e};Object.defineProperty(i1,"__esModule",{value:!0}),i1.malloyToQuery=i1.MalloyToQuery=void 0;const Kht=qd,Ln=Yht(I),Jxe=T2,YE=Pn,Jht=et,Xht=UE,Xxe=Jn,Zht=VE,uP="Malloy query documents";class Zxe extends Kht.AbstractParseTreeVisitor{constructor(e,r){super(),this.parseInfo=e,this.msgLog=r}internalError(e,r){return this.contextError(e,"internal-translator-error",{message:r}),new Error(`Internal Translator Error: ${r}`)}getLocation(e){return{url:this.parseInfo.sourceURL,range:(0,Xxe.rangeFromContext)(this.parseInfo.sourceInfo,e)}}contextError(e,r,i,s){this.msgLog.log((0,Jxe.makeLogMessage)(r,i,{at:this.getLocation(e),...s}))}getNumber(e){return Number.parseInt(e.text)}defaultResult(){return null}getAnnotations(e){const r=e.ANNOTATION().map(i=>({value:i.text}));return r.length>0?r:void 0}getIsAnnotations(e){var r,i;if(e===void 0)return;const o=((r=this.getAnnotations(e._beforeIs))!==null&&r!==void 0?r:[]).concat((i=this.getAnnotations(e._afterIs))!==null&&i!==void 0?i:[]);return o.length>0?o:void 0}notAllowed(e,r){this.illegal(e,`${r} are not allowed in ${uP}`)}illegal(e,r){this.contextError(e,"invalid-malloy-query-document",r)}visitMalloyDocument(e){const r=e.malloyStatement();let i;for(const s of r)s.defineSourceStatement()?this.notAllowed(s,"Source definitions"):s.defineQuery()?this.notAllowed(s,"Query definitions"):s.importStatement()?this.notAllowed(s,"Import statements"):s.docAnnotations()?this.notAllowed(s,"Model annotations"):s.ignoredObjectAnnotations()?this.notAllowed(s,"Detatched object annotations"):s.experimentalStatementForTesting()?this.notAllowed(s,"Experimental testing statements"):i===void 0?i=s.runStatement():this.illegal(s,`${uP} may only have one run statement`);return i===void 0?(this.illegal(e,`${uP} must have a run statement`),null):this.visitRunStatement(i)}visitRunStatement(e){const r=e.topLevelAnonQueryDef(),i=this.getQueryDefinition(r.sqExpr()),s=this.getAnnotations(e.topLevelAnonQueryDef().tags());return i!==null?{annotations:s,definition:i}:null}getQueryReference(e){if(e.sourceArguments())this.illegal(e,"Queries do not support parameters");else return{name:(0,YE.getId)(e)};return null}getQueryDefinition(e){if(e instanceof Ln.SQIDContext){const r=this.getQueryReference(e);if(r!==null)return{kind:"query_reference",...r}}else{if(e instanceof Ln.SQParensContext)return this.getQueryDefinition(e.sqExpr());if(e instanceof Ln.SQComposeContext)this.notAllowed(e,"Source compositions");else if(e instanceof Ln.SQRefinedQueryContext){const r=e.sqExpr(),i=this.getQueryDefinition(r),s=this.getRefinementSegment(e.segExpr());return s===null||i===null?null:(s.kind==="arrow"&&this.notAllowed(e,"Queries against refined queries"),{kind:"refinement",base:i,refinement:s})}else if(e instanceof Ln.SQExtendedSourceContext)this.notAllowed(e,"Source extensions");else if(e instanceof Ln.SQIncludeContext)this.notAllowed(e,"Source inclusions");else if(e instanceof Ln.SQTableContext)this.notAllowed(e,"Table statements");else if(e instanceof Ln.SQSQLContext)this.notAllowed(e,"SQL statements");else if(e instanceof Ln.SQArrowContext){const r=e.sqExpr(),i=this.getQueryDefinition(r),s=this.getRefinementSegment(e.segExpr());return s===null||i===null?null:i.kind==="query_reference"?{kind:"arrow",source:{...i,kind:"source_reference"},view:s}:i.kind==="arrow"?{kind:"arrow",source:i.source,view:{kind:"arrow",source:i.view,view:s}}:{kind:"arrow",source:i,view:s}}}return null}getRefinementSegment(e){if(e instanceof Ln.SegOpsContext){const r=e.queryProperties().queryStatement().flatMap(i=>this.getSegmentOperation(i));return r.some(i=>i===null)?null:{kind:"segment",operations:r}}else if(e instanceof Ln.SegFieldContext){const{name:r,path:i}=this.getFieldPath(e.fieldPath());return{kind:"view_reference",name:r,path:i}}else{if(e instanceof Ln.SegParenContext)return this.getViewExpression(e.vExpr());if(e instanceof Ln.SegRefineContext){const r=this.getRefinementSegment(e._lhs),i=this.getRefinementSegment(e._rhs);return r===null||i===null?null:{kind:"refinement",base:r,refinement:i}}}return null}getGroupByStatement(e){const r=this.getAnnotations(e.tags()),s=e.queryFieldList().queryFieldEntry().map(o=>this.getQueryField(o));return s.some(o=>o===null)||s===null?null:s.map(o=>{var u;const a=[...r??[],...(u=o.field.annotations)!==null&&u!==void 0?u:[]];return{kind:"group_by",name:o.name,field:{...o.field,annotations:a.length>0?a:void 0}}})}getAggregateStatement(e){const r=this.getAnnotations(e.tags()),s=e.queryFieldList().queryFieldEntry().map(o=>this.getQueryField(o));return s.some(o=>o===null)||s===null?null:s.map(o=>{var u;const a=[...r??[],...(u=o.field.annotations)!==null&&u!==void 0?u:[]];return{kind:"aggregate",name:o.name,field:{...o.field,annotations:a.length>0?a:void 0}}})}getOrderByStatement(e){const r=e.ordering().orderBySpec(),i=[];for(const s of r)if(s.INTEGER_LITERAL())this.notAllowed(s,"Indexed order by statements");else if(s.fieldName()){const o=(0,YE.getId)(s.fieldName()),u=s.ASC()?"asc":s.DESC()?"desc":void 0;i.push({kind:"order_by",direction:u,field_reference:{name:o}})}else return null;return i}getNestStatement(e){const r=this.getAnnotations(e.tags()),i=e.nestedQueryList().nestEntry(),s=[];for(const o of i){if(!(o instanceof Ln.NestDefContext))return this.internalError(o,"Expected nestDef"),null;const u=this.getAnnotations(o.tags()),a=this.getIsAnnotations(o.isDefine()),l=o.queryName(),c=l?(0,YE.getId)(l):void 0,f=this.getViewExpression(o.vExpr());if(f===null)return null;s.push({kind:"nest",name:c,view:{definition:f,annotations:this.combineAnnotations(r,u,a)}})}return s}getViewExpression(e){if(e instanceof Ln.VSegContext)return this.getRefinementSegment(e.segExpr());if(e instanceof Ln.VArrowContext){const r=this.getRefinementSegment(e),i=this.getViewExpression(e._rhs);return r===null||i===null?null:{kind:"arrow",source:r,view:i}}else return this.internalError(e,"Unexpected VExpr node"),null}getLimitStatement(e){return{kind:"limit",limit:this.getNumber(e.INTEGER_LITERAL())}}getSegmentOperation(e){if(e.groupByStatement()){const r=e.groupByStatement();return this.getGroupByStatement(r)}else if(e.aggregateStatement()){const r=e.aggregateStatement();return this.getAggregateStatement(r)}else if(e.limitStatement()){const r=e.limitStatement(),i=this.getLimitStatement(r);return i===null?null:[i]}else if(e.declareStatement())this.notAllowed(e,"Declare statements");else if(e.queryJoinStatement())this.notAllowed(e,"Query join statements");else if(e.queryExtend())this.notAllowed(e,"Query extend statements");else if(e.projectStatement())this.notAllowed(e,"Select statements");else if(e.indexStatement())this.notAllowed(e,"Index statements");else if(e.calculateStatement())this.notAllowed(e,"Calculate statements");else if(e.topStatement())this.notAllowed(e,"Top statements");else if(e.orderByStatement()){const r=e.orderByStatement();return this.getOrderByStatement(r)}else if(e.whereStatement()){const r=e.whereStatement(),i=this.getWhere(r);return i===null?null:i.map(s=>({kind:"where",...s}))}else if(e.havingStatement()){const r=e.havingStatement(),i=this.getHaving(r);return i===null?null:i.map(s=>({kind:"having",...s}))}else if(e.nestStatement()){const r=e.nestStatement();return this.getNestStatement(r)}else e.sampleStatement()?this.notAllowed(e,"Sample statements"):e.timezoneStatement()?this.notAllowed(e,"Timezone statements"):(e.queryAnnotation()||e.ignoredModelAnnotations())&&this.notAllowed(e,"Detached annotation statements");return null}getFieldPath(e){const r=e.fieldName().map(o=>(0,YE.getId)(o)),i=r[0],s=r.slice(1);return{name:i,path:s.length>0?s:void 0}}getTimeframe(e){const r=e.text;return(0,Jht.isTimestampUnit)(r)?r:(this.illegal(e,`Invalid timeframe ${r}`),null)}getQueryField(e){if(e.taggedRef()){const r=e.taggedRef(),i=this.getAnnotations(r.tags()),{name:s,path:o}=this.getFieldPath(r.fieldPath());if(r.refExpr()){const u=r.refExpr();if(u.timeframe()){const a=this.getTimeframe(u.timeframe());return a===null?null:{name:void 0,field:{annotations:i,expression:{kind:"time_truncation",field_reference:{name:s,path:o},truncation:a}}}}else u.aggregate()&&this.notAllowed(u,"Aggregate expressions")}else return{name:void 0,field:{annotations:i,expression:{kind:"field_reference",name:s,path:o}}}}else if(e.fieldDef()){const r=e.fieldDef(),i=this.getAnnotations(r.tags()),s=this.getIsAnnotations(r.isDefine()),o=(0,YE.getId)(r.fieldNameDef()),u=this.getFieldExpression(r.fieldExpr());return u===null?null:{name:o,field:{expression:u,annotations:this.combineAnnotations(i,s)}}}return null}getFieldExpression(e){if(e instanceof Ln.ExprFieldPathContext){const{name:r,path:i}=this.getFieldPath(e.fieldPath());return{kind:"field_reference",name:r,path:i}}else if(e instanceof Ln.ExprTimeTruncContext){const r=this.getTimeframe(e.timeframe()),i=e.fieldExpr(),s=this.getFieldExpression(i);return s===null||r===null?null:s.kind!=="field_reference"?(this.illegal(i,"Left hand side of time truncation must be a field reference"),null):{kind:"time_truncation",truncation:r,field_reference:{name:s.name,path:s.path,parameters:s.parameters}}}else if(e instanceof Ln.ExprFieldPropsContext){const r=e.fieldExpr(),i=this.getFieldExpression(r);if(i===null)return null;if(i.kind!=="field_reference")return this.illegal(r,"Left hand side of filtered field must be a field reference"),null;const s=e.fieldProperties().fieldPropertyStatement(),o=[];for(const u of s){const a=u.whereStatement();if(a){const l=this.getWhere(a);if(l===null)return null;o.push(...l)}}return{kind:"filtered_field",field_reference:{name:i.name,path:i.path,parameters:i.parameters},where:o}}return null}stripQuote(e,r){return e.slice(e.indexOf(r)+r.length,e.lastIndexOf(r))}getFilterString(e){const r=e.tripFilterString(),i=e.tickFilterString();if(r){const s=r.BQ3_FILTER(),o=r.DQ3_FILTER(),u=r.SQ3_FILTER();if(s)return this.stripQuote(s.text,"```");if(o)return this.stripQuote(o.text,'"""');if(u)return this.stripQuote(u.text,"'''")}else if(i){const s=i.BQ_FILTER(),o=i.DQ_FILTER(),u=i.SQ_FILTER();if(s)return this.stripQuote(s.text,"`");if(o)return this.stripQuote(o.text,'"');if(u)return this.stripQuote(u.text,"'")}return null}getFilterExpr(e){if(e instanceof Ln.ExprCompareContext&&e.compareOp().MATCH()){const r=e.fieldExpr()[0],i=e.fieldExpr()[1];if(r instanceof Ln.ExprFieldPathContext&&i instanceof Ln.ExprLiteralContext){const{path:s,name:o}=this.getFieldPath(r.fieldPath()),u=i.literal();if(u instanceof Ln.FilterString_stubContext){const a=this.getFilterString(u.filterString());return a===null?null:{filter:{kind:"filter_string",field_reference:{name:o,path:s},filter:a}}}}}return this.notAllowed(e,"Filters other than comparisons with filter strings"),null}getWhere(e){const i=e.filterClauseList().fieldExpr().map(s=>this.getFilterExpr(s));return i.some(s=>s===null)?null:i}getHaving(e){const i=e.filterClauseList().fieldExpr().map(s=>this.getFilterExpr(s));return i.some(s=>s===null)?null:i}combineAnnotations(...e){const r=e.flatMap(i=>i??[]);return r.length>0?r:void 0}}i1.MalloyToQuery=Zxe;function ept(t){const e=(0,Xxe.getSourceInfo)(t),r=new Jxe.BaseMessageLogger(null),i="internal://query.malloy",s=(0,Xht.runMalloyParser)(t,i,e,r),u=new Zxe(s,r).visit(s.root),a=(0,Zht.mapLogs)(r.getLog(),i);if(u===null)return{logs:a};if(!("definition"in u))throw new Error("Expected a query");return{query:u,logs:a}}i1.malloyToQuery=ept,function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.malloyToQuery=t.exploreQueryWalkerBuilder=t.MalloyTranslation=t.MalloyTranslator=void 0;var e=Wc;Object.defineProperty(t,"MalloyTranslator",{enumerable:!0,get:function(){return e.MalloyTranslator}}),Object.defineProperty(t,"MalloyTranslation",{enumerable:!0,get:function(){return e.MalloyTranslation}});var r=r1;Object.defineProperty(t,"exploreQueryWalkerBuilder",{enumerable:!0,get:function(){return r.exploreQueryWalkerBuilder}});var i=i1;Object.defineProperty(t,"malloyToQuery",{enumerable:!0,get:function(){return i.malloyToQuery}})}(M4);var Ie={},ED={};Object.defineProperty(ED,"__esModule",{value:!0}),ED.MALLOY_VERSION=void 0,ED.MALLOY_VERSION="0.0.265",Object.defineProperty(Ie,"__esModule",{value:!0}),Ie.InMemoryModelCache=Ie.CacheManager=Ie.CSVWriter=Ie.JSONWriter=Ie.DataWriter=Ie.DataRecord=Ie.DataArray=Ie.Result=Ie.ExploreMaterializer=Ie.PreparedResultMaterializer=Ie.QueryMaterializer=Ie.ModelMaterializer=Ie.SingleConnectionRuntime=Ie.ConnectionRuntime=Ie.Runtime=Ie.ExploreField=Ie.JoinRelationship=Ie.QueryField=Ie.Query=Ie.StringField=Ie.UnsupportedField=Ie.JSONField=Ie.BooleanField=Ie.NumberField=Ie.TimestampField=Ie.DateField=Ie.TimestampTimeframe=Ie.DateTimeframe=Ie.AtomicField=Ie.AtomicFieldType=Ie.Explore=Ie.SourceRelationship=Ie.FixedConnectionMap=Ie.InMemoryURLReader=Ie.EmptyURLReader=Ie.PreparedResult=Ie.DocumentCompletion=Ie.DocumentSymbol=Ie.DocumentPosition=Ie.DocumentRange=Ie.DocumentTablePath=Ie.Parse=Ie.PreparedQuery=Ie.Model=Ie.MalloyError=Ie.Malloy=void 0;const ede=M4,yi=Gi,tde=qr,aP=h2,tpt=ED,npt=m2,Un=mi,rpt=g0,nde="internal://internal.malloy";let S0=class WD{static get version(){return tpt.MALLOY_VERSION}static _parse(e,r,i,s,o){r===void 0&&(r=new URL(nde));let u=r;s!=null&&s.importBaseURL&&(u=s==null?void 0:s.importBaseURL);const a=new ede.MalloyTranslator(r.toString(),u.toString(),{urls:{[r.toString()]:e}},i);return s!=null&&s.testEnvironment&&(a.allDialectsEnabled=!0),new ide(a,o)}static parse({url:e,urlReader:r,source:i,eventStream:s,options:o}){if(i!==void 0)return WD._parse(i,e,s,o);if(r===void 0)throw new Error("Internal Error: urlReader is required.");if(e===void 0)throw new Error("Internal Error: url is required if source not present.");return RD(r,e).then(({contents:u,invalidationKey:a})=>WD._parse(u,e,s,o,a))}static async compile({url:e,source:r,parse:i,urlReader:s,connections:o,model:u,refreshSchemaCache:a,noThrowOnError:l,eventStream:c,importBaseURL:f,cacheManager:x}){var h,p,m,g,y;let E;if(a&&(E=typeof a=="number"?a:Date.now()),e===void 0&&r===void 0&&i===void 0)throw new Error("Internal Error: url, source, or parse required.");e===void 0&&(i!==void 0?e=new URL(i._translator.sourceURL):e=new URL(nde));const A={};if(r===void 0&&x!==void 0){const C=await x.getCachedModelDef(s,e.toString());if(C)return new o1(C.modelDef,[],[e.toString(),...TD(C.modelDef.dependencies)])}f??(f=e);let _;const v=e.toString();if(i!==void 0){_=i._translator;const C=(h=i._invalidationKey)!==null&&h!==void 0?h:await _P(s,e);A[v]=C}else{if(r===void 0){const{contents:C,invalidationKey:S}=await RD(s,e);A[v]=S,r=C}else{const C=await _P(s,e);A[v]=C}_=new ede.MalloyTranslator(v,f.toString(),{urls:{[v]:r}},c)}for(;;){const C=_.translate(u==null?void 0:u._modelDef);if(C.final)if(C.modelDef){await(x==null?void 0:x.setCachedModelDef(e.toString(),{modelDef:C.modelDef,invalidationKeys:A}));for(const S of _.newlyTranslatedDependencies())await(x==null?void 0:x.setCachedModelDef(S.url,{modelDef:S.modelDef,invalidationKeys:A}));return new o1(C.modelDef,C.problems||[],[...(p=u==null?void 0:u.fromSources)!==null&&p!==void 0?p:[],...(m=C.fromSources)!==null&&m!==void 0?m:[]],S=>_.referenceAt(S),S=>_.importAt(S))}else if(l){const S={name:"modelDidNotCompile",exports:[],contents:{},dependencies:{},queryList:[]},b=(u==null?void 0:u._modelDef)||S;return new o1(b,C.problems||[],[...(g=u==null?void 0:u.fromSources)!==null&&g!==void 0?g:[],...(y=C.fromSources)!==null&&y!==void 0?y:[]],R=>_.referenceAt(R),R=>_.importAt(R))}else{const S=C.problems||[],b=_.prettyErrors();throw new rde(`Error(s) compiling model:
|
|
1862
|
+
${b}`,S)}else{if(C.urls)for(const b of C.urls)try{if(DD(b))throw new Error("In order to use relative imports, you must compile a file via a URL.");if(x!==void 0){const D=await x.getCachedModelDef(s,b);if(D){for(const $ in D.invalidationKeys)A[$]=D.invalidationKeys[$];_.update({translations:{[b]:D.modelDef}});continue}}const{contents:R,invalidationKey:O}=await RD(s,new URL(b)),B={[b]:R};A[b]=O,_.update({urls:B})}catch(R){_.update({errors:{urls:{[b]:R.message}}})}const{modelAnnotation:S}=_.modelAnnotation(u==null?void 0:u._modelDef);if(C.tables){const b=new Map;for(const R in C.tables){const{connectionName:O,tablePath:B}=C.tables[R],D=b.get(O);D===void 0?b.set(O,{[R]:B}):D[R]=B}for(const[R,O]of b)try{const B=await o.lookupConnection(R),{schemas:D,errors:$}=await WD.safelyFetchTableSchema(B,O,{refreshTimestamp:E,modelAnnotation:S});_.update({tables:D,errors:{tables:$}})}catch(B){const D={},$={};for(const U in O)$[U]=B.toString();_.update({tables:D,errors:{tables:$}})}}if(C.compileSQL){const b=C.compileSQL,R=b.connection,O=(0,rpt.sqlKey)(b.connection,b.selectStr);try{const D=await(await o.lookupConnection(R)).fetchSchemaForSQLStruct(b,{refreshTimestamp:E,modelAnnotation:S});D.error&&_.update({errors:{compileSQL:{[O]:D.error}}}),D.structDef&&_.update({compileSQL:{[O]:D.structDef}})}catch(B){const D={};D[O]=B.toString(),_.update({errors:{compileSQL:D}})}}}}}static async safelyFetchTableSchema(e,r,i){const s=await e.fetchSchemaForTables(r,i);for(const o of Object.keys(r))if(s.schemas[o]===void 0&&s.errors[o]===void 0)throw new Error(`Schema fetch error for ${e.name}, no response for ${o} from ${e.dialectName}`);return s}static async run({connections:e,preparedResult:r,sqlStruct:i,connection:s,options:o}){if(!s){if(!e)throw new Error("Internal Error: Connection or LookupConnection<Connection> must be provided.");const u=(i==null?void 0:i.connection)||(r==null?void 0:r.connectionName);s=await e.lookupConnection(u)}if(i){const u=await s.runSQL(i.selectStr);return new XE({structs:[i],sql:i.selectStr,result:u.rows,totalRows:u.totalRows,runStats:u.runStats,lastStageName:i.name,malloy:"",connectionName:i.connection,sourceExplore:"",sourceFilters:[],profilingUrl:u.profilingUrl},{name:"empty_model",exports:[],contents:{},queryList:[],dependencies:{}})}else if(r){const u=await s.runSQL(r.sql,o);return new XE({...r._rawQuery,result:u.rows,totalRows:u.totalRows,runStats:u.runStats,profilingUrl:u.profilingUrl},r._modelDef)}else throw new Error("Internal error: sqlStruct or preparedResult must be provided.")}static async*runStream({connections:e,preparedResult:r,sqlStruct:i,connection:s,options:o}){if(i===void 0&&r===void 0)throw new Error("Internal error: sqlBlock or preparedResult must be provided.");const u=(i==null?void 0:i.connection)||(r==null?void 0:r.connectionName);if(s===void 0){if(e===void 0)throw new Error("Internal Error: Connection or LookupConnection<Connection> must be provided.");s=await e.lookupConnection(u)}if(!s.canStream())throw new Error(`Connection '${u}' cannot stream results.`);let a,l;if(i)l=new Gs(i),a=i.selectStr;else if(r!==void 0)l=r.resultExplore,a=r.sql;else throw new Error("Internal error: sqlStruct or preparedResult must be provided.");let c=0;for await(const f of s.runSQLStream(a,o))yield new Bd(f,c,l,void 0,void 0),c+=1}static async estimateQueryCost({connections:e,preparedResult:r,sqlStruct:i}){if(!e)throw new Error("Internal Error: Connection or LookupConnection<Connection> must be provided.");const s=(i==null?void 0:i.connection)||(r==null?void 0:r.connectionName),o=await e.lookupConnection(s);if(i)return await o.estimateQueryCost(i.selectStr);if(r)return await o.estimateQueryCost(r.sql);throw new Error("Internal error: sqlStruct or preparedResult must be provided.")}};Ie.Malloy=S0;class rde extends Error{constructor(e,r=[]){super(e),this.problems=r}}Ie.MalloyError=rde;class o1{constructor(e,r,i,s=()=>{},o=()=>{}){this.modelDef=e,this.problems=r,this.fromSources=i,this._referenceAt=s,this._importAt=o}tagParse(e){return(0,Un.annotationToTag)(this.modelDef.annotation,e)}getTaglines(e){return(0,Un.annotationToTaglines)(this.modelDef.annotation,e)}getReference(e){return this._referenceAt(e)}getImport(e){return this._importAt(e)}getPreparedQueryByName(e){const r=this.modelDef.contents[e];if((r==null?void 0:r.type)==="query")return new u1(r,this.modelDef,this.problems,e);throw new Error("Given query name does not refer to a named query.")}getPreparedQueryByIndex(e){if(e<0)throw new Error(`Invalid index ${e}.`);if(e>=this.modelDef.queryList.length)throw new Error(`Query index ${e} is out of bounds.`);return new u1(this.modelDef.queryList[e],this.modelDef,this.problems)}get preparedQuery(){return this.getPreparedQuery()}getPreparedQuery(){if(this.modelDef.queryList.length===0)throw new Error("Model has no queries.");return new u1(this.modelDef.queryList[this.modelDef.queryList.length-1],this.modelDef,this.problems)}getExploreByName(e){const r=this.modelDef.contents[e];if((0,yi.isSourceDef)(r))return new Gs(r);throw new Error("'name' is not an explore")}get explores(){return Object.values(this.modelDef.contents).filter(yi.isSourceDef).map(e=>new Gs(e))}get namedQueries(){const e=r=>r.type==="query";return Object.values(this.modelDef.contents).filter(e)}get exportedExplores(){return this.explores.filter(e=>this.modelDef.exports.includes(e.name))}get _modelDef(){return this.modelDef}}Ie.Model=o1;class u1{constructor(e,r,i,s){this.problems=i,this.name=s,this._query=e,this._modelDef=r}tagParse(e){const r=(0,Un.annotationToTag)(this._modelDef.annotation).tag;return e=(0,Un.addModelScope)(e,r),(0,Un.annotationToTag)(this._query.annotation,e)}getTaglines(e){return(0,Un.annotationToTaglines)(this._query.annotation,e)}get preparedResult(){return this.getPreparedResult()}getPreparedResult(e){const i=new yi.QueryModel(this._modelDef,e==null?void 0:e.eventStream).compileQuery(this._query,e);return new KE({...i,queryName:this.name||i.queryName},this._modelDef)}get dialect(){const e=this._query.structRef,r=typeof e=="string"?this._modelDef.contents[e]:e;if(!(0,yi.isSourceDef)(r))throw new Error("Invalid source for query");return r.dialect}getFlattenedQuery(e){return this}}Ie.PreparedQuery=u1;class ide{constructor(e,r){this.translator=e,this.invalidationKey=r}get symbols(){return(this.translator.metadata().symbols||[]).map(e=>new AD(e))}get tablePathInfo(){var e;return((e=this.translator.tablePathInfo().pathInfo)!==null&&e!==void 0?e:[]).map(i=>new sde(i))}get _translator(){return this.translator}get _invalidationKey(){return this.invalidationKey}completions(e){return(this.translator.completions(e).completions||[]).map(r=>new ode(r))}helpContext(e){return this.translator.helpContext(e).helpContext}}Ie.Parse=ide;class sde{constructor(e){this._range=a1.fromJSON(e.range),this._connectionId=e.connectionId,this._tablePath=e.tablePath}get range(){return this._range}get connectionId(){return this._connectionId}get tablePath(){return this._tablePath}}Ie.DocumentTablePath=sde;class a1{constructor(e,r){this._start=e,this._end=r}get start(){return this._start}get end(){return this._end}toJSON(){return{start:this.start.toJSON(),end:this.end.toJSON()}}static fromJSON(e){return new a1(new lP(e.start.line,e.start.character),new lP(e.end.line,e.end.character))}}Ie.DocumentRange=a1;class lP{constructor(e,r){this._line=e,this._character=r}get line(){return this._line}get character(){return this._character}toJSON(){return{line:this.line,character:this.character}}}Ie.DocumentPosition=lP;class AD{constructor(e){this._range=a1.fromJSON(e.range),this._lensRange=e.lensRange?a1.fromJSON(e.lensRange):void 0,this._type=e.type,this._name=e.name,this._children=e.children.map(r=>new AD(r))}get range(){return this._range}get lensRange(){var e;return(e=this._lensRange)!==null&&e!==void 0?e:this._range}get type(){return this._type}get name(){return this._name}get children(){return this._children}}Ie.DocumentSymbol=AD;class ode{constructor(e){this.type=e.type,this.text=e.text}}Ie.DocumentCompletion=ode;class KE{constructor(e,r){this.modelDef=r,this.inner=e}static fromJson({query:e,modelDef:r}){if(!e||!r)throw new Error("Missing required properties in JSON data");return new KE(e,r)}tagParse(e){const r=(0,Un.annotationToTag)(this.modelDef.annotation).tag;return e=(0,Un.addModelScope)(e,r),(0,Un.annotationToTag)(this.inner.annotation,e)}getTaglines(e){return(0,Un.annotationToTaglines)(this.inner.annotation,e)}get annotation(){return this.inner.annotation}get modelAnnotation(){return this.modelDef.annotation}get modelTag(){return(0,Un.annotationToTag)(this.modelDef.annotation).tag}get connectionName(){return this.inner.connectionName}get _rawQuery(){return this.inner}get _modelDef(){return this.modelDef}get sql(){return this.inner.sql}get dependenciesToMaterialize(){return this.inner.dependenciesToMaterialize}get materialization(){return this.inner.materialization}get resultExplore(){if(this.inner.structs.length===0)throw new Error("Malformed query result.");const e=this.inner.structs[this.inner.structs.length-1],r={...e,annotation:this.inner.annotation,name:this.inner.queryName||e.name};try{return new Gs(r,this.sourceExplore)}catch{return new Gs(r)}}get sourceExplore(){const e=this.inner.sourceExplore,r=this.modelDef.contents[e];if(r&&(0,yi.isSourceDef)(r))return new Gs(r)}get _sourceExploreName(){return this.inner.sourceExplore}get _sourceFilters(){return this.inner.sourceFilters||[]}}Ie.PreparedResult=KE;class ude{async readURL(e){throw new Error("No files.")}async getInvalidationKey(e){throw new Error("No files.")}}Ie.EmptyURLReader=ude;class ipt{constructor(e){this.files=e}async readURL(e){const r=this.files.get(e.toString());if(r!==void 0)return Promise.resolve({contents:r,invalidationKey:this.invalidationKey(e,r)});throw new Error(`File not found '${e}'`)}async getInvalidationKey(e){const r=this.files.get(e.toString());if(r!==void 0)return Promise.resolve(this.invalidationKey(e,r));throw new Error(`File not found '${e}'`)}invalidationKey(e,r){return DD(e.toString())?null:vde(r)}}Ie.InMemoryURLReader=ipt;class _D{constructor(e,r){this.connections=e,this.defaultConnectionName=r}async getConnection(e){if(e===void 0)if(this.defaultConnectionName!==void 0)e=this.defaultConnectionName;else throw new Error("No default connection.");const r=this.connections.get(e);if(r!==void 0)return Promise.resolve(r);throw new Error(`No connection found with name ${e}.`)}listConnections(){return Array.from(this.connections.values())}async lookupConnection(e){return this.getConnection(e)}static fromArray(e){return new _D(new Map(e.map(r=>[r.name,r])))}}Ie.FixedConnectionMap=_D;var ade;(function(t){t.Nested="nested",t.BaseTable="base_table",t.Cross="cross",t.One="one",t.Many="many",t.Inline="inline"})(ade||(Ie.SourceRelationship=ade={}));class cP{constructor(e,r,i){this._name=e,this._parent=r,this._source=i}get source(){return this.source}get name(){return this._name}get sourceClasses(){const e=[];return this.source&&e.push(this.source.name),e.push(this.name),e}get fieldPath(){const e=[this.name];let r=this._parent;for(;r;)e.unshift(r.name),r=r._parent;return e}hasParentExplore(){return this._parent!==void 0}isExplore(){return this instanceof Gs}isQuery(){return this instanceof gP}}class Gs extends cP{constructor(e,r,i){super(e.as||e.name,r,i),this._structDef=e,this._parentExplore=r,this.sourceExplore=i}get source(){return this.sourceExplore}isIntrinsic(){return(0,yi.isAtomicFieldType)(this._structDef.type)?!("e"in this._structDef):!1}isExploreField(){return!1}tagParse(e){return(0,Un.annotationToTag)(this._structDef.annotation,e)}getTaglines(e){return(0,Un.annotationToTaglines)(this._structDef.annotation,e)}get modelTag(){return this.parsedModelTag||(this.parsedModelTag=(0,Un.annotationToTag)(this._structDef.modelAnnotation).tag),this.parsedModelTag}get name(){return this.structDef.as||this.structDef.name}getQueryByName(e){const r=this.sourceStructDef;if(!r)throw new Error(`Cannot get query by name from a struct of type ${this.structDef.type}`);const i={type:"query",structRef:r,pipeline:[{type:"reduce",queryFields:[{type:"fieldref",path:[e]}]}]};return new u1(i,this.modelDef,[],e)}get modelDef(){if(!(0,yi.isSourceDef)(this.structDef))throw new Error(`Cannot create pseudo model for struct type ${this.structDef.type}`);return{name:"generated_model",exports:[],contents:{[this.structDef.name]:this.structDef},queryList:[],dependencies:{}}}getSingleExploreModel(){return new o1(this.modelDef,[],[])}get fieldMap(){var e;if(this._fieldMap===void 0){const r=((e=this.source)===null||e===void 0?void 0:e.fieldMap)||new Map;this._fieldMap=new Map(this.structDef.fields.map(i=>{const s=i.as||i.name,o=r.get(i.name);if((0,yi.isJoined)(i))return[s,new yP(i,this,o)];if(i.type==="turtle")return[s,new gP(i,this,o)];if(i.type==="string")return[s,new mP(i,this,o)];if(i.type==="number")return[s,new vD(i,this,o)];if(i.type==="date")return i.timeframe&&["day_of_month","day_of_week","day_of_year"].includes(i.timeframe)?[s,new vD({...i,type:"number"},this,o)]:[s,new fP(i,this,o)];if(i.type==="timestamp")return[s,new xP(i,this,o)];if(i.type==="boolean")return[s,new dP(i,this,o)];if(i.type==="json")return[s,new hP(i,this,o)];if(i.type==="sql native")return[s,new pP(i,this,o)]}))}return this._fieldMap}get allFields(){return[...this.fieldMap.values()]}get allFieldsWithOrder(){var e,r,i;if(!this._allFieldsWithOrder){const s=[...((i=(r=(e=this.sourceStructDef)===null||e===void 0?void 0:e.resultMetadata)===null||r===void 0?void 0:r.orderBy)===null||i===void 0?void 0:i.map(u=>{if(typeof u.field=="string")return{field:this.fieldMap.get(u.field),dir:u.dir};throw new Error("Does not support mapping order by from number.")}))||[]],o=new Set(s.map(u=>u.field.name));this._allFieldsWithOrder=[...s,...this.allFields.filter(u=>!o.has(u.name)).map(u=>({field:u,dir:"asc"}))]}return this._allFieldsWithOrder}get intrinsicFields(){return[...this.fieldMap.values()].filter(e=>e.isIntrinsic())}get dimensions(){return[...this.allFieldsWithOrder].filter(e=>e.field.isAtomicField()&&e.field.sourceWasDimension())}getFieldByName(e){const r=this.fieldMap.get(e);if(r===void 0)throw new Error(`No such field ${e}.`);return r}getFieldByNameIfExists(e){return this.fieldMap.get(e)}get primaryKey(){var e;return(e=this.sourceStructDef)===null||e===void 0?void 0:e.primaryKey}get parentExplore(){return this._parentExplore}hasParentExplore(){return this instanceof yP}get filters(){var e;return(0,yi.isSourceDef)(this.structDef)?((e=this.structDef.resultMetadata)===null||e===void 0?void 0:e.filterList)||[]:[]}get limit(){var e,r;return(r=(e=this.sourceStructDef)===null||e===void 0?void 0:e.resultMetadata)===null||r===void 0?void 0:r.limit}get structDef(){return this._structDef}get queryTimezone(){var e;return(e=this.sourceStructDef)===null||e===void 0?void 0:e.queryTimezone}get sourceStructDef(){if((0,yi.isSourceDef)(this.structDef))return this.structDef}toJSON(){var e,r;return{_structDef:this._structDef,sourceExplore:(e=this.sourceExplore)===null||e===void 0?void 0:e.toJSON(),_parentExplore:(r=this._parentExplore)===null||r===void 0?void 0:r.toJSON()}}static fromJSON(e){const r=e._parentExplore!==void 0?Gs.fromJSON(e._parentExplore):void 0,i=e.sourceExplore!==void 0?Gs.fromJSON(e.sourceExplore):void 0;return new Gs(e._structDef,r,i)}get location(){return this.structDef.location}}Ie.Explore=Gs;var Ka;(function(t){t.String="string",t.Number="number",t.Boolean="boolean",t.Date="date",t.Timestamp="timestamp",t.Json="json",t.NativeUnsupported="sql native",t.Error="error"})(Ka||(Ie.AtomicFieldType=Ka={}));class df extends cP{constructor(e,r,i){super(e.as||e.name,r,i),this.fieldTypeDef=e,this.parent=r}get type(){switch(this.fieldTypeDef.type){case"string":return Ka.String;case"boolean":return Ka.Boolean;case"date":return Ka.Date;case"timestamp":return Ka.Timestamp;case"number":return Ka.Number;case"json":return Ka.Json;case"sql native":return Ka.NativeUnsupported;case"error":return Ka.Error;case"record":case"array":throw new Error(`MTOY TODO IMPLEMENT Atomic ${this.fieldTypeDef.type}`);default:{const e=this.fieldTypeDef;throw new Error(`Can't make an atomic field from ${e}`)}}}tagParse(e){return e=(0,Un.addModelScope)(e,this.parent.modelTag),(0,Un.annotationToTag)(this.fieldTypeDef.annotation,e)}getTaglines(e){return(0,Un.annotationToTaglines)(this.fieldTypeDef.annotation,e)}isIntrinsic(){return(0,yi.fieldIsIntrinsic)(this.fieldTypeDef)}isQueryField(){return!1}isExploreField(){return!1}isAtomicField(){return!0}isCalculation(){return(0,yi.expressionIsCalculation)(this.fieldTypeDef.expressionType)}get sourceField(){throw new Error}get sourceClasses(){const e=this.fieldTypeDef.name||this.fieldTypeDef.as;return e?[e]:[]}get referenceId(){var e;return(e=this.fieldTypeDef.resultMetadata)===null||e===void 0?void 0:e.referenceId}sourceWasMeasure(){var e;return((e=this.fieldTypeDef.resultMetadata)===null||e===void 0?void 0:e.fieldKind)==="measure"}sourceWasMeasureLike(){var e,r;return((e=this.fieldTypeDef.resultMetadata)===null||e===void 0?void 0:e.fieldKind)==="measure"||((r=this.fieldTypeDef.resultMetadata)===null||r===void 0?void 0:r.fieldKind)==="struct"}sourceWasDimension(){var e;return((e=this.fieldTypeDef.resultMetadata)===null||e===void 0?void 0:e.fieldKind)==="dimension"}hasParentExplore(){return!0}isString(){return this instanceof mP}isNumber(){return this instanceof vD}isDate(){return this instanceof fP}isBoolean(){return this instanceof dP}isJSON(){return this instanceof hP}isTimestamp(){return this instanceof xP}isUnsupported(){return this instanceof pP}get parentExplore(){return this.parent}get expression(){const e=".",r=this.fieldTypeDef.resultMetadata;return(r==null?void 0:r.sourceExpression)||(r!=null&&r.sourceField.includes(e)?r==null?void 0:r.sourceField:this.name)}get location(){return this.fieldTypeDef.location}}Ie.AtomicField=df;var $d;(function(t){t.Day="day",t.Week="week",t.Month="month",t.Quarter="quarter",t.Year="year"})($d||(Ie.DateTimeframe=$d={}));var Ja;(function(t){t.Day="day",t.Week="week",t.Month="month",t.Quarter="quarter",t.Year="year",t.Second="second",t.Hour="hour",t.Minute="minute"})(Ja||(Ie.TimestampTimeframe=Ja={}));class fP extends df{constructor(e,r,i){super(e,r,i),this.fieldDateDef=e}get timeframe(){if(this.fieldDateDef.timeframe!==void 0)switch(this.fieldDateDef.timeframe){case"day":return $d.Day;case"week":return $d.Week;case"month":return $d.Month;case"quarter":return $d.Quarter;case"year":return $d.Year}}}Ie.DateField=fP;class xP extends df{constructor(e,r,i){super(e,r,i),this.fieldTimestampDef=e}get timeframe(){if(this.fieldTimestampDef.timeframe!==void 0)switch(this.fieldTimestampDef.timeframe){case"day":return Ja.Day;case"week":return Ja.Week;case"month":return Ja.Month;case"quarter":return Ja.Quarter;case"year":return Ja.Year;case"second":return Ja.Second;case"hour":return Ja.Hour;case"minute":return Ja.Minute}}}Ie.TimestampField=xP;class vD extends df{constructor(e,r,i){super(e,r,i),this.fieldNumberDef=e}}Ie.NumberField=vD;class dP extends df{constructor(e,r,i){super(e,r,i),this.fieldBooleanDef=e}}Ie.BooleanField=dP;class hP extends df{constructor(e,r,i){super(e,r,i),this.fieldJSONDef=e}}Ie.JSONField=hP;class pP extends df{constructor(e,r,i){super(e,r,i),this.fieldUnsupportedDef=e}get rawType(){return this.fieldUnsupportedDef.rawType}}Ie.UnsupportedField=pP;class mP extends df{constructor(e,r,i){super(e,r,i),this.fieldStringDef=e}}Ie.StringField=mP;class lde extends cP{constructor(e,r,i){super(e.as||e.name,r,i),this.turtleDef=e}get source(){return this.sourceQuery}isIntrinsic(){return!1}get location(){return this.turtleDef.location}}Ie.Query=lde;class gP extends lde{constructor(e,r,i){super(e,r,i),this.parent=r}tagParse(e){return e=(0,Un.addModelScope)(e,this.parent.modelTag),(0,Un.annotationToTag)(this.turtleDef.annotation,e)}getTaglines(e){return(0,Un.annotationToTaglines)(this.turtleDef.annotation,e)}isQueryField(){return!0}isExploreField(){return!1}isAtomicField(){return!1}get sourceClasses(){const e=this.turtleDef.name||this.turtleDef.as;return e?[e]:[]}hasParentExplore(){return!0}get parentExplore(){return this.parent}get expression(){return this.name}}Ie.QueryField=gP;var l1;(function(t){t.OneToOne="one_to_one",t.OneToMany="one_to_many",t.ManyToOne="many_to_one"})(l1||(Ie.JoinRelationship=l1={}));class yP extends Gs{constructor(e,r,i){super(e,r,i),this._parentExplore=r}get joinRelationship(){if((0,yi.isJoined)(this.structDef))switch(this.structDef.join){case"one":return l1.OneToOne;case"many":case"cross":return l1.ManyToOne}throw new Error("A source field must have a join relationship.")}get isRecord(){return this.joinRelationship===l1.OneToOne}get isArray(){return this.joinRelationship!==l1.OneToOne}tagParse(e){return e=(0,Un.addModelScope)(e,this._parentExplore.modelTag),(0,Un.annotationToTag)(this._structDef.annotation,e)}isQueryField(){return!1}isExploreField(){return!0}isAtomicField(){return!1}get parentExplore(){return this._parentExplore}get sourceClasses(){const e=this.structDef.name||this.structDef.as;return e?[e]:[]}}Ie.ExploreField=yP;class EP{constructor({urlReader:e,connections:r,connection:i,eventStream:s,cacheManager:o}){if(this.isTestRuntime=!1,r===void 0){if(i===void 0)throw new Error("A LookupConnection<Connection> or Connection is required.");r={lookupConnection:()=>Promise.resolve(i)}}e===void 0&&(e=new ude),this._urlReader=e,this._connections=r,this._eventStream=s,this._cacheManager=o}get cacheManager(){return this._cacheManager}get urlReader(){return this._urlReader}get connections(){return this._connections}get eventStream(){return this._eventStream}loadModel(e,r){const{refreshSchemaCache:i,noThrowOnError:s}=r||{};this.isTestRuntime&&(r===void 0?r={testEnvironment:!0}:r={...r,testEnvironment:!0});const o=e instanceof URL?{url:e}:{source:e};return new JE(this,async()=>S0.compile({...o,urlReader:this.urlReader,connections:this.connections,refreshSchemaCache:i,noThrowOnError:s,eventStream:this.eventStream,replaceMaterializedReferences:r==null?void 0:r.replaceMaterializedReferences,materializedTablePrefix:r==null?void 0:r.materializedTablePrefix,importBaseURL:r==null?void 0:r.importBaseURL,testEnvironment:r==null?void 0:r.testEnvironment,cacheManager:this.cacheManager}),r)}_loadModelFromModelDef(e,r){return new JE(this,async()=>new o1(e,[],[]),r)}loadQuery(e,r){return this.loadModel(e,r).loadFinalQuery()}loadQueryByIndex(e,r,i){return this.loadModel(e,i).loadQueryByIndex(r,i)}loadQueryByName(e,r,i){return this.loadModel(e,i).loadQueryByName(r,i)}getModel(e,r){return this.loadModel(e,r).getModel()}getQuery(e,r){return this.loadQuery(e,r).getPreparedQuery()}getQueryByIndex(e,r,i){return this.loadQueryByIndex(e,r,i).getPreparedQuery()}getQueryByName(e,r,i){return this.loadQueryByName(e,r,i).getPreparedQuery()}}Ie.Runtime=EP;class spt extends EP{constructor({urlReader:e,connections:r}){super({connections:_D.fromArray(r),urlReader:e}),this.rawConnections=r}}Ie.ConnectionRuntime=spt;class opt extends EP{constructor({urlReader:e,connection:r,eventStream:i,cacheManager:s}){super({urlReader:e,eventStream:i,cacheManager:s,connection:r}),this.connection=r}get supportsNesting(){return(0,aP.getDialect)(this.connection.dialectName).supportsNesting}quote(e){return(0,aP.getDialect)(this.connection.dialectName).sqlMaybeQuoteIdentifier(e)}get dialect(){return(0,aP.getDialect)(this.connection.dialectName)}getQuoter(){return e=>this.quote(e.toString())}}Ie.SingleConnectionRuntime=opt;class CD{constructor(e,r){this.runtime=e,this._materialize=r}materialize(){return this.materialized===void 0?this.rematerialize():this.materialized}rematerialize(){return this.materialized=this._materialize(),this.materialized}makeQueryMaterializer(e,r){return new cde(this.runtime,e,r)}makeExploreMaterializer(e,r){return new xde(this.runtime,e,r)}makePreparedResultMaterializer(e){return new fde(this.runtime,e)}}class JE extends CD{constructor(e,r,i){super(e,r),this.runtime=e,this.compileQueryOptions=i}loadFinalQuery(e){return this.makeQueryMaterializer(async()=>(await this.materialize()).getPreparedQuery(),{...this.compileQueryOptions,...e})}loadQueryByIndex(e,r){return this.makeQueryMaterializer(async()=>(await this.materialize()).getPreparedQueryByIndex(e),{...this.compileQueryOptions,...r})}loadQueryByName(e,r){return this.makeQueryMaterializer(async()=>(await this.materialize()).getPreparedQueryByName(e),{...this.compileQueryOptions,...r})}loadQuery(e,r){const{refreshSchemaCache:i,noThrowOnError:s}=r||{};return this.makeQueryMaterializer(async()=>{const o=this.runtime.urlReader,u=this.runtime.connections;this.runtime.isTestRuntime&&(r===void 0?r={testEnvironment:!0}:r={...r,testEnvironment:!0});const a=e instanceof URL?{url:e}:{source:e},l=await this.getModel();return(await S0.compile({...a,urlReader:o,connections:u,model:l,refreshSchemaCache:i,noThrowOnError:s,importBaseURL:r==null?void 0:r.importBaseURL,testEnvironment:r==null?void 0:r.testEnvironment,...this.compileQueryOptions})).preparedQuery})}extendModel(e,r){return this.runtime.isTestRuntime&&(r===void 0?r={testEnvironment:!0}:r={...r,testEnvironment:!0}),new JE(this.runtime,async()=>{const i=this.runtime.urlReader,s=this.runtime.connections,o=e instanceof URL?{url:e}:{source:e},u=await this.getModel();return await S0.compile({...o,urlReader:i,connections:s,model:u,refreshSchemaCache:r==null?void 0:r.refreshSchemaCache,noThrowOnError:r==null?void 0:r.noThrowOnError,importBaseURL:r==null?void 0:r.importBaseURL,testEnvironment:r==null?void 0:r.testEnvironment,...this.compileQueryOptions})},r)}async search(e,r,i=1e3,s=void 0,o){const u=await this.materialize(),a=new yi.QueryModel(u._modelDef,o),l=u.getExploreByName(e).structDef;if(!(0,yi.isSourceDef)(l))throw new Error("Source to be searched was unexpectedly, not a source");const c=l.connection,f=await this.runtime.connections.lookupConnection(c);return await a.searchIndex(f,e,r,i,s)}async searchValueMap(e,r=10,i){const o=(await this.materialize()).getExploreByName(e);if(!(0,yi.isSourceDef)(o.structDef))throw new Error("Source to be searched was unexpectedly, not a source");let u="{index: *}";o.getFieldByNameIfExists("search_index")&&(u="search_index");const a=`
|
|
1863
1863
|
run: ${e}
|
|
1864
1864
|
-> ${u}
|
|
1865
1865
|
-> {
|
|
@@ -1873,16 +1873,16 @@ ${b}`,S)}else{if(C.urls)for(const b of C.urls)try{if(DD(b))throw new Error("In o
|
|
|
1873
1873
|
}
|
|
1874
1874
|
limit: 1000
|
|
1875
1875
|
}
|
|
1876
|
-
`;return(await this.loadQuery(a,i).run({rowLimit:1e3}))._queryResult.result}getFinalQuery(){return this.loadFinalQuery().getPreparedQuery()}getQueryByIndex(e){return this.loadQueryByIndex(e).getPreparedQuery()}getQueryByName(e){return this.loadQueryByName(e).getPreparedQuery()}getQuery(e,r){return this.loadQuery(e,r).getPreparedQuery()}_loadQueryFromQueryDef(e,r){return this.makeQueryMaterializer(async()=>{const i=await this.materialize();return new u1(e,i._modelDef,i.problems)},{...this.compileQueryOptions,...r})}loadExploreByName(e){return this.makeExploreMaterializer(async()=>(await this.materialize()).getExploreByName(e),this.compileQueryOptions)}getExploreByName(e){return this.loadExploreByName(e).getExplore()}getModel(){return this.materialize()}}Ie.ModelMaterializer=JE;class cde extends CD{constructor(e,r,i){super(e,r),this.runtime=e,this.compileQueryOptions=i}async run(e){const r=this.runtime.connections,i=await this.getPreparedResult(e),s=SD(i,e);return S0.run({connections:r,preparedResult:i,options:s})}async*runStream(e){const r=await this.getPreparedResult(e),i=this.runtime.connections,s=SD(r,e),o=S0.runStream({connections:i,preparedResult:r,options:s});for await(const u of o)yield u}loadPreparedResult(e){return this.makePreparedResultMaterializer(async()=>(await this.materialize()).getPreparedResult({eventStream:this.eventStream,...this.compileQueryOptions,...e}))}getPreparedResult(e){return this.loadPreparedResult(e).getPreparedResult()}async getSQL(e){return(await this.getPreparedResult(e)).sql}getPreparedQuery(){return this.materialize()}async estimateQueryCost(e){const r=this.runtime.connections,i=await this.getPreparedResult(e);return S0.estimateQueryCost({connections:r,preparedResult:i})}get eventStream(){return this.runtime.eventStream}}Ie.QueryMaterializer=cde;function SD(t,e){return{queryAnnotation:t.annotation,modelAnnotation:t.modelAnnotation,...e}}class fde extends CD{async run(e){const r=await this.getPreparedResult(),i=this.runtime.connections,s=SD(r,e);return S0.run({connections:i,preparedResult:r,options:s})}async*runStream(e){const r=await this.getPreparedResult(),i=this.runtime.connections,s=SD(r,e),o=S0.runStream({connections:i,preparedResult:r,options:s});for await(const u of o)yield u}getPreparedResult(){return this.materialize()}async getSQL(){return(await this.getPreparedResult()).sql}}Ie.PreparedResultMaterializer=fde;class xde extends CD{constructor(e,r,i){var s;super(e,r),this.runtime=e,this.replaceMaterializedReferences=(s=i==null?void 0:i.replaceMaterializedReferences)!==null&&s!==void 0?s:!1}loadQueryByName(e,r){return this.makeQueryMaterializer(async()=>(await this.materialize()).getQueryByName(e),r)}getQueryByName(e){return this.loadQueryByName(e).getPreparedQuery()}getExplore(){return this.materialize()}}Ie.ExploreMaterializer=xde;class XE extends KE{constructor(e,r){super(e,r),this.inner=e}get _queryResult(){return this.inner}get data(){return new ZE(this.inner.result,this.resultExplore,void 0,void 0)}get totalRows(){return this.inner.totalRows}get runStats(){return this.inner.runStats}get profilingUrl(){return this.inner.profilingUrl}toJSON(){return{queryResult:this.inner,modelDef:this._modelDef}}static fromJSON({queryResult:e,modelDef:r}){return new XE(e,r)}}Ie.Result=XE;class bD{constructor(e,r,i){this.parent=r,this.parentRecord=i,this._field=e}get field(){return this._field}isString(){return this instanceof dde}get string(){if(this.isString())return this;throw new Error("Not a string.")}isBoolean(){return this instanceof pde}get boolean(){if(this.isBoolean())return this;throw new Error("Not a boolean.")}isNumber(){return this instanceof mde}get number(){if(this.isNumber())return this;throw new Error("Not a number.")}isTimestamp(){return this instanceof yde}get timestamp(){if(this.isTimestamp())return this;throw new Error("Not a timestamp.")}isDate(){return this instanceof Ede}get date(){if(this.isDate())return this;throw new Error("Not a date.")}isNull(){return this instanceof Ade}isBytes(){return this instanceof
|
|
1876
|
+
`;return(await this.loadQuery(a,i).run({rowLimit:1e3}))._queryResult.result}getFinalQuery(){return this.loadFinalQuery().getPreparedQuery()}getQueryByIndex(e){return this.loadQueryByIndex(e).getPreparedQuery()}getQueryByName(e){return this.loadQueryByName(e).getPreparedQuery()}getQuery(e,r){return this.loadQuery(e,r).getPreparedQuery()}_loadQueryFromQueryDef(e,r){return this.makeQueryMaterializer(async()=>{const i=await this.materialize();return new u1(e,i._modelDef,i.problems)},{...this.compileQueryOptions,...r})}loadExploreByName(e){return this.makeExploreMaterializer(async()=>(await this.materialize()).getExploreByName(e),this.compileQueryOptions)}getExploreByName(e){return this.loadExploreByName(e).getExplore()}getModel(){return this.materialize()}}Ie.ModelMaterializer=JE;class cde extends CD{constructor(e,r,i){super(e,r),this.runtime=e,this.compileQueryOptions=i}async run(e){const r=this.runtime.connections,i=await this.getPreparedResult(e),s=SD(i,e);return S0.run({connections:r,preparedResult:i,options:s})}async*runStream(e){const r=await this.getPreparedResult(e),i=this.runtime.connections,s=SD(r,e),o=S0.runStream({connections:i,preparedResult:r,options:s});for await(const u of o)yield u}loadPreparedResult(e){return this.makePreparedResultMaterializer(async()=>(await this.materialize()).getPreparedResult({eventStream:this.eventStream,...this.compileQueryOptions,...e}))}getPreparedResult(e){return this.loadPreparedResult(e).getPreparedResult()}async getSQL(e){return(await this.getPreparedResult(e)).sql}getPreparedQuery(){return this.materialize()}async estimateQueryCost(e){const r=this.runtime.connections,i=await this.getPreparedResult(e);return S0.estimateQueryCost({connections:r,preparedResult:i})}get eventStream(){return this.runtime.eventStream}}Ie.QueryMaterializer=cde;function SD(t,e){return{queryAnnotation:t.annotation,modelAnnotation:t.modelAnnotation,...e}}class fde extends CD{async run(e){const r=await this.getPreparedResult(),i=this.runtime.connections,s=SD(r,e);return S0.run({connections:i,preparedResult:r,options:s})}async*runStream(e){const r=await this.getPreparedResult(),i=this.runtime.connections,s=SD(r,e),o=S0.runStream({connections:i,preparedResult:r,options:s});for await(const u of o)yield u}getPreparedResult(){return this.materialize()}async getSQL(){return(await this.getPreparedResult()).sql}}Ie.PreparedResultMaterializer=fde;class xde extends CD{constructor(e,r,i){var s;super(e,r),this.runtime=e,this.replaceMaterializedReferences=(s=i==null?void 0:i.replaceMaterializedReferences)!==null&&s!==void 0?s:!1}loadQueryByName(e,r){return this.makeQueryMaterializer(async()=>(await this.materialize()).getQueryByName(e),r)}getQueryByName(e){return this.loadQueryByName(e).getPreparedQuery()}getExplore(){return this.materialize()}}Ie.ExploreMaterializer=xde;class XE extends KE{constructor(e,r){super(e,r),this.inner=e}get _queryResult(){return this.inner}get data(){return new ZE(this.inner.result,this.resultExplore,void 0,void 0)}get totalRows(){return this.inner.totalRows}get runStats(){return this.inner.runStats}get profilingUrl(){return this.inner.profilingUrl}toJSON(){return{queryResult:this.inner,modelDef:this._modelDef}}static fromJSON({queryResult:e,modelDef:r}){return new XE(e,r)}}Ie.Result=XE;class bD{constructor(e,r,i){this.parent=r,this.parentRecord=i,this._field=e}get field(){return this._field}isString(){return this instanceof dde}get string(){if(this.isString())return this;throw new Error("Not a string.")}isBoolean(){return this instanceof pde}get boolean(){if(this.isBoolean())return this;throw new Error("Not a boolean.")}isNumber(){return this instanceof mde}get number(){if(this.isNumber())return this;throw new Error("Not a number.")}isTimestamp(){return this instanceof yde}get timestamp(){if(this.isTimestamp())return this;throw new Error("Not a timestamp.")}isDate(){return this instanceof Ede}get date(){if(this.isDate())return this;throw new Error("Not a date.")}isNull(){return this instanceof Ade}isBytes(){return this instanceof apt}get bytes(){if(this.isBytes())return this;throw new Error("Not bytes.")}isRecord(){return this instanceof Bd}get record(){if(this.isRecord())return this;throw new Error("Not a record.")}isUnsupported(){return this instanceof hde}get unsupported(){if(this.isUnsupported())return this;throw new Error("Not unsupported.")}isArray(){return this instanceof ZE}get array(){if(this.isArray())return this;throw new Error("Not an array.")}isArrayOrRecord(){if(this instanceof ZE||this instanceof Bd)return this;throw new Error("No Array or Record")}isScalar(){return!0}}class Xa extends bD{constructor(e,r,i,s){super(r,i,s),this._value=e,this._field=r}get value(){return this._value}get field(){return this._field}isScalar(){return this instanceof Xa}}class dde extends Xa{constructor(e,r,i,s){super(e,r,i,s),this._field=r}get field(){return this._field}get key(){return this.value}compareTo(e){return this.value.toLocaleLowerCase().localeCompare(e.value.toLocaleLowerCase())}}class hde extends Xa{constructor(e,r,i,s){super(e,r,i,s),this._field=r}get field(){return this._field}get key(){return"<unsupported>"}compareTo(e){return 0}}class pde extends Xa{constructor(e,r,i,s){super(e,r,i,s),this._field=r}get field(){return this._field}get key(){return`${this.value}`}compareTo(e){return this.value===e.value?0:this.value?1:-1}}class upt extends Xa{constructor(e,r,i,s){super(e,r,i,s),this._field=r}get field(){return this._field}get key(){return this.value}compareTo(e){const r=this.value.toString(),i=e.toString();return r===i?0:r>i?1:-1}}class mde extends Xa{constructor(e,r,i,s){super(e,r,i,s),this._field=r}get field(){return this._field}get key(){return`${this.value}`}compareTo(e){const r=this.value-e.value;return r>0?1:r===0?0:-1}}function gde(t){if(t instanceof Date)return t;if(t.constructor.name==="Date")return new Date(t);if(typeof t=="number")return new Date(t);if(typeof t!="string")return new Date(t.value);{let r=tde.DateTime.fromISO(t,{zone:"UTC"});return r.isValid||(r=tde.DateTime.fromSQL(t,{zone:"UTC"})),r.toJSDate()}}class yde extends Xa{constructor(e,r,i,s){super(e,r,i,s),this._field=r}get value(){return gde(this._value)}get field(){return this._field}get key(){return`${this.value.toLocaleString()}`}compareTo(e){return this.value>e.value?1:this.value<e.value?-1:0}}class Ede extends Xa{constructor(e,r,i,s){super(e,r,i,s),this._field=r}get value(){return gde(this._value)}get field(){return this._field}get key(){return`${this.value.toLocaleString()}`}compareTo(e){return this.value>e.value?1:this.value<e.value?-1:0}}class apt extends Xa{get key(){return this.value.toString()}compareTo(e){const r=this.value.toString(),i=e.toString();return r===i?0:r>i?1:-1}}class Ade extends bD{get value(){return null}get key(){return"<null>"}}class ZE extends bD{constructor(e,r,i,s){super(r,i,s),this.rowCache=new Map,this.queryData=e,this._field=r}get field(){return this._field}toObject(){return this.queryData}path(...e){return _de(this,e)}row(e){let r=this.rowCache.get(e);return r||(r=new Bd(this.queryData[e],e,this.field,this,this.parentRecord),this.rowCache.set(e,r)),r}get rowCount(){return this.queryData.length}get value(){return this.toObject()}[Symbol.iterator](){let e=0;const r=this.queryData,i=s=>this.row(s);return{next(){return e<r.length?{value:i(e++),done:!1}:{value:void 0,done:!0}}}}async*inMemoryStream(){for(let e=0;e<this.queryData.length;e++)yield this.row(e)}}Ie.DataArray=ZE;function _de(t,e){for(const r of e)typeof r=="number"?t=t.array.row(r):t=t.record.cell(r);return t}class Bd extends bD{constructor(e,r,i,s,o){super(i,s,o),this.cellCache=new Map,this.queryDataRow=e,this._field=i,this.index=r}toObject(){return this.queryDataRow}path(...e){return _de(this,e)}cell(e){const r=typeof e=="string"?e:e.name,i=this._field.getFieldByName(r);let s=this.cellCache.get(r);if(!s){const o=this.queryDataRow[r];o===null?s=new Ade(i,this,this):i.isAtomicField()?i.isBoolean()?s=new pde(o,i,this,this):i.isDate()?s=new Ede(o,i,this,this):i.isJSON()?s=new upt(o,i,this,this):i.isTimestamp()?s=new yde(o,i,this,this):i.isNumber()?s=new mde(o,i,this,this):i.isString()?s=new dde(o,i,this,this):i.isUnsupported()&&(s=new hde(o,i,this,this)):i.isExploreField()&&(Array.isArray(o)?s=new ZE(o,i,this,this):s=new Bd(o,void 0,i,this,this)),s&&this.cellCache.set(r,s)}if(s)return s;throw new Error(`Internal Error: could not construct data column for field '${r}'.`)}get value(){throw new Error("Not implemented;")}get field(){return this._field}[Symbol.iterator](){let e=!1;const r=()=>this;return{next(){return e?{value:void 0,done:!0}:(e=!0,{value:r(),done:!1})}}}}Ie.DataRecord=Bd;class AP{constructor(e){this.stream=e}}Ie.DataWriter=AP;class lpt extends AP{async process(e){this.stream.write(`[
|
|
1877
1877
|
`);for await(const r of e){r.index!==void 0&&r.index>0&&this.stream.write(`,
|
|
1878
1878
|
`);const s=JSON.stringify(r.toObject(),null,2).split(`
|
|
1879
1879
|
`);for(let o=0;o<s.length;o++){const u=s[o];this.stream.write(` ${u}`),o<s.length-1&&this.stream.write(`
|
|
1880
1880
|
`)}}this.stream.write(`
|
|
1881
1881
|
]
|
|
1882
|
-
`),this.stream.close()}}Ie.JSONWriter=
|
|
1883
|
-
`,this.quoteCharacter='"',this.includeHeader=!0,this.emptyCell=""}escape(e){const r=e.includes(this.quoteCharacter),i=e.includes(this.columnSeparator),s=e.includes(this.rowSeparator),o=i||r||s;return r&&(e=e.replace(new RegExp(this.quoteCharacter,"g"),this.quoteCharacter+this.quoteCharacter)),o&&(e=this.quoteCharacter+e+this.quoteCharacter),e}stringify(e){return e===null?this.emptyCell:e instanceof Date?e.toISOString():typeof e=="boolean"||typeof e=="number"?JSON.stringify(e):`${e}`}getColWeight(e){let r=e;Array.isArray(e)&&(r=e[0]);let i=0;for(const s in r){i=i+1;const o=r[s];if(Array.isArray(o)){const u=this.getColWeight(o)-1;i=i+u}}return i}getHeaderRow(e){const r=[];let i=0;for(const s in e){r.push(this.escape(s));const o=e[s];if(i++,Array.isArray(o)){const u=this.getColWeight(o)-1;i=i+u;for(let a=0;a<u;a++)r.push(this.emptyCell)}}return{rows:[r.join(this.columnSeparator)],length:1,width:i}}mergeMatrices(e){const r=Math.max(...e.map(o=>o.length)),i=e.reduce((o,u)=>o+u.width,0),s=[];for(let o=0;o<r;o++){const u=[];for(const a of e)if(o<a.length)u.push(a.rows[o]);else{const l=Array(a.width).fill(this.emptyCell);u.push(...l)}s.push(u.join(this.columnSeparator))}return{rows:s,length:r,width:i}}getChildMatrix(e){if(Array.isArray(e)){if(e.length===0)return{rows:[""],length:1,width:1}}else return{rows:["Invalid data found, value is not an array"],length:1,width:1};const r=[],i=this.getHeaderRow(e[0]);r.push(...i.rows);const s=i.width;let o=1;for(const u of e){const a=this.getRowMatrix(u);o=o+a.length,r.push(...a.rows)}return{rows:r,length:o,width:s}}getRowMatrix(e){const r=[];for(const i in e){const s=e[i];if(Array.isArray(s)){const o=this.getChildMatrix(s);r.push(o)}else{const o={rows:[this.stringify(s)],length:1,width:1};r.push(o)}}return this.mergeMatrices(r)}async process(e){let r=!1;for await(const i of e){if(!r&&this.includeHeader){const o=this.getHeaderRow(i.toObject());this.stream.write(o.rows[0]),this.stream.write(this.rowSeparator),r=!0}const s=this.getRowMatrix(i.toObject());for(const o of s.rows)this.stream.write(o),this.stream.write(this.rowSeparator)}this.stream.close()}}Ie.CSVWriter=apt;class lpt{constructor(e){this.modelCache=e,this.modelDependencies=new Map,this.modelInvalidationKeys=new Map}async getCachedModelDef(e,r){const i=this.modelDependencies.get(r);if(i===void 0)return;const s=[r,...TD(i)],o={};for(const a of s){const l=this.modelInvalidationKeys.get(a);if(l==null)return;o[a]=l}for(const a of s)if(await _P(e,new URL(a))!==o[a])return;const u=await this.modelCache.getModel(new URL(r));if(u!==void 0){for(const a of s)if(u.invalidationKeys[a]!==o[a])return;return{modelDef:u.modelDef,invalidationKeys:o}}}async setCachedModelDef(e,r){this.modelDependencies.set(e,r.modelDef.dependencies);const i={};for(const o of[e,...TD(r.modelDef.dependencies)]){if(r.invalidationKeys[o]===null)return!1;if(r.invalidationKeys[o]===void 0)throw new Error(`Missing invalidation key for dependency ${o}`);this.modelInvalidationKeys.set(o,r.invalidationKeys[o]),i[o]=r.invalidationKeys[o]}return!!await this.modelCache.setModel(new URL(e),{modelDef:r.modelDef,invalidationKeys:i})}}Ie.CacheManager=lpt;function TD(t){return[...Object.keys(t),...Object.values(t).map(TD).flat()]}class cpt{constructor(){this.models=new Map}async getModel(e){return Promise.resolve(this.models.get(e.toString()))}async setModel(e,r){return this.models.set(e.toString(),r),Promise.resolve(!0)}}Ie.InMemoryModelCache=cpt;function vde(t){return(0,ept.v5)(t,"76c17e9d-f3ce-5f2d-bfde-98ad3d2a37f6")}async function RD(t,e){const r=await t.readURL(e),{contents:i,invalidationKey:s}=typeof r=="string"?{contents:r,invalidationKey:void 0}:r;return{contents:i,invalidationKey:DD(e.toString())?null:s??vde(i)}}async function _P(t,e){return DD(e.toString())?null:t.getInvalidationKey!==void 0?await t.getInvalidationKey(e):(await RD(t,e)).invalidationKey}function DD(t){return t.startsWith("internal://")}var OD={};Object.defineProperty(OD,"__esModule",{value:!0}),OD.toAsyncGenerator=void 0;async function*fpt(t){let e=!1;function r(s){let o;const u=new Promise(a=>{o=a});return s(a=>{o({done:!0,isError:!0,error:a})},a=>{o({done:!1,value:a,isError:!1,next:new Promise(l=>{o=l})})},()=>{o({done:!0,isError:!1})}),u}let i=r(t);for(;!e;){const s=await i;if(s.done){if(e=!0,s.isError)throw s.error;break}else i=s.next,yield s.value}}OD.toAsyncGenerator=fpt;var Cde={},hf={},vP={},eA={};Object.defineProperty(eA,"__esModule",{value:!0}),eA.MALLOY_INTERFACE_TYPES=void 0,eA.MALLOY_INTERFACE_TYPES={Aggregate:{type:"struct",name:"Aggregate",fields:{name:{type:"string",optional:!0,array:!1},field:{type:"Field",optional:!1,array:!1}}},Annotation:{type:"struct",name:"Annotation",fields:{value:{type:"string",optional:!1,array:!1}}},AnonymousQueryInfo:{type:"struct",name:"AnonymousQueryInfo",fields:{schema:{type:"Schema",optional:!1,array:!1},annotations:{type:"Annotation",array:!0,optional:!0},definition:{type:"Query",optional:!0,array:!1},code:{type:"string",optional:!0,array:!1},location:{type:"Location",optional:!0,array:!1}}},ArrayCell:{type:"struct",name:"ArrayCell",fields:{array_value:{type:"Cell",array:!0,optional:!1}}},ArrayType:{type:"struct",name:"ArrayType",fields:{element_type:{type:"AtomicType",optional:!1,array:!1}}},AtomicType:{type:"union",name:"AtomicType",options:{string_type:"StringType",boolean_type:"BooleanType",number_type:"NumberType",json_type:"JSONType",sql_native_type:"SQLNativeType",date_type:"DateType",timestamp_type:"TimestampType",array_type:"ArrayType",record_type:"RecordType"}},BooleanCell:{type:"struct",name:"BooleanCell",fields:{boolean_value:{type:"boolean",optional:!1,array:!1}}},BooleanLiteral:{type:"struct",name:"BooleanLiteral",fields:{boolean_value:{type:"boolean",optional:!1,array:!1}}},BooleanType:{type:"struct",name:"BooleanType",fields:{}},Cell:{type:"union",name:"Cell",options:{string_cell:"StringCell",boolean_cell:"BooleanCell",date_cell:"DateCell",timestamp_cell:"TimestampCell",number_cell:"NumberCell",json_cell:"JSONCell",record_cell:"RecordCell",array_cell:"ArrayCell",null_cell:"NullCell",sql_native_cell:"SQLNativeCell"}},CompileModelRequest:{type:"struct",name:"CompileModelRequest",fields:{model_url:{type:"string",optional:!1,array:!1},extend_model_url:{type:"string",optional:!0,array:!1},compiler_needs:{type:"CompilerNeeds",optional:!0,array:!1}}},CompileModelResponse:{type:"struct",name:"CompileModelResponse",fields:{model:{type:"ModelInfo",optional:!0,array:!1},logs:{type:"LogMessage",array:!0,optional:!0},compiler_needs:{type:"CompilerNeeds",optional:!0,array:!1},translations:{type:"Translation",array:!0,optional:!0}}},CompileQueryRequest:{type:"struct",name:"CompileQueryRequest",fields:{model_url:{type:"string",optional:!1,array:!1},query:{type:"Query",optional:!1,array:!1},default_row_limit:{type:"number",optional:!0,array:!1},compiler_needs:{type:"CompilerNeeds",optional:!0,array:!1}}},CompileQueryResponse:{type:"struct",name:"CompileQueryResponse",fields:{result:{type:"Result",optional:!0,array:!1},default_row_limit_added:{type:"number",optional:!0,array:!1},logs:{type:"LogMessage",array:!0,optional:!0},compiler_needs:{type:"CompilerNeeds",optional:!0,array:!1},translations:{type:"Translation",array:!0,optional:!0}}},CompileSourceRequest:{type:"struct",name:"CompileSourceRequest",fields:{model_url:{type:"string",optional:!1,array:!1},name:{type:"string",optional:!1,array:!1},extend_model_url:{type:"string",optional:!0,array:!1},compiler_needs:{type:"CompilerNeeds",optional:!0,array:!1}}},CompileSourceResponse:{type:"struct",name:"CompileSourceResponse",fields:{source:{type:"SourceInfo",optional:!0,array:!1},logs:{type:"LogMessage",array:!0,optional:!0},compiler_needs:{type:"CompilerNeeds",optional:!0,array:!1}}},CompilerNeeds:{type:"struct",name:"CompilerNeeds",fields:{table_schemas:{type:"SQLTable",array:!0,optional:!0},sql_schemas:{type:"SQLQuery",array:!0,optional:!0},files:{type:"File",array:!0,optional:!0},connections:{type:"Connection",array:!0,optional:!0},translations:{type:"Translation",array:!0,optional:!0}}},Connection:{type:"struct",name:"Connection",fields:{name:{type:"string",optional:!1,array:!1},dialect:{type:"string",optional:!0,array:!1}}},Data:{type:"union",name:"Data",options:{record_cell:"RecordCell",array_cell:"ArrayCell"}},DateCell:{type:"struct",name:"DateCell",fields:{date_value:{type:"string",optional:!1,array:!1}}},DateLiteral:{type:"struct",name:"DateLiteral",fields:{date_value:{type:"string",optional:!1,array:!1},granularity:{type:"DateTimeframe",optional:!0,array:!1}}},DateTimeframe:{type:"enum",name:"DateTimeframe",values:{year:1,quarter:2,month:3,week:4,day:5}},DateType:{type:"struct",name:"DateType",fields:{timeframe:{type:"DateTimeframe",optional:!0,array:!1}}},DimensionInfo:{type:"struct",name:"DimensionInfo",fields:{name:{type:"string",optional:!1,array:!1},type:{type:"AtomicType",optional:!1,array:!1},annotations:{type:"Annotation",array:!0,optional:!0}}},DocumentPosition:{type:"struct",name:"DocumentPosition",fields:{line:{type:"number",optional:!1,array:!1},character:{type:"number",optional:!1,array:!1}}},DocumentRange:{type:"struct",name:"DocumentRange",fields:{start:{type:"DocumentPosition",optional:!1,array:!1},end:{type:"DocumentPosition",optional:!1,array:!1}}},Expression:{type:"union",name:"Expression",options:{field_reference:"Reference",time_truncation:"TimeTruncationFieldReference",filtered_field:"FilteredField"}},Field:{type:"struct",name:"Field",fields:{expression:{type:"Expression",optional:!1,array:!1},annotations:{type:"Annotation",array:!0,optional:!0}}},FieldInfo:{type:"union",name:"FieldInfo",options:{dimension:"DimensionInfo",measure:"MeasureInfo",join:"JoinInfo",view:"ViewInfo"}},File:{type:"struct",name:"File",fields:{url:{type:"string",optional:!1,array:!1},contents:{type:"string",optional:!0,array:!1},invalidation_key:{type:"string",optional:!0,array:!1}}},Filter:{type:"union",name:"Filter",options:{filter_string:"FilterStringApplication"}},FilterExpressionLiteral:{type:"struct",name:"FilterExpressionLiteral",fields:{filter_expression_value:{type:"string",optional:!1,array:!1}}},FilterExpressionType:{type:"struct",name:"FilterExpressionType",fields:{}},FilterOperation:{type:"struct",name:"FilterOperation",fields:{filter:{type:"Filter",optional:!1,array:!1}}},FilterStringApplication:{type:"struct",name:"FilterStringApplication",fields:{field_reference:{type:"Reference",optional:!1,array:!1},filter:{type:"string",optional:!1,array:!1}}},FilteredField:{type:"struct",name:"FilteredField",fields:{field_reference:{type:"Reference",optional:!1,array:!1},where:{type:"FilterOperation",array:!0,optional:!1}}},GroupBy:{type:"struct",name:"GroupBy",fields:{name:{type:"string",optional:!0,array:!1},field:{type:"Field",optional:!1,array:!1}}},JSONCell:{type:"struct",name:"JSONCell",fields:{json_value:{type:"string",optional:!1,array:!1}}},JSONType:{type:"struct",name:"JSONType",fields:{}},JoinInfo:{type:"struct",name:"JoinInfo",fields:{name:{type:"string",optional:!1,array:!1},schema:{type:"Schema",optional:!1,array:!1},annotations:{type:"Annotation",array:!0,optional:!0},relationship:{type:"Relationship",optional:!1,array:!1}}},Limit:{type:"struct",name:"Limit",fields:{limit:{type:"number",optional:!1,array:!1}}},LiteralValue:{type:"union",name:"LiteralValue",options:{string_literal:"StringLiteral",number_literal:"NumberLiteral",date_literal:"DateLiteral",timestamp_literal:"TimestampLiteral",boolean_literal:"BooleanLiteral",null_literal:"NullLiteral",filter_expression_literal:"FilterExpressionLiteral"}},Location:{type:"struct",name:"Location",fields:{url:{type:"string",optional:!1,array:!1},range:{type:"Range",optional:!1,array:!1}}},LogMessage:{type:"struct",name:"LogMessage",fields:{url:{type:"string",optional:!1,array:!1},range:{type:"DocumentRange",optional:!1,array:!1},severity:{type:"LogSeverity",optional:!1,array:!1},message:{type:"string",optional:!1,array:!1}}},LogSeverity:{type:"enum",name:"LogSeverity",values:{debug:1,info:2,warn:3,error:4}},MeasureInfo:{type:"struct",name:"MeasureInfo",fields:{name:{type:"string",optional:!1,array:!1},type:{type:"AtomicType",optional:!1,array:!1},annotations:{type:"Annotation",array:!0,optional:!0}}},ModelEntryValue:{type:"union",name:"ModelEntryValue",options:{source:"SourceInfo",query:"QueryInfo"}},ModelInfo:{type:"struct",name:"ModelInfo",fields:{entries:{type:"ModelEntryValue",array:!0,optional:!1},annotations:{type:"Annotation",array:!0,optional:!0},anonymous_queries:{type:"AnonymousQueryInfo",array:!0,optional:!1}}},Nest:{type:"struct",name:"Nest",fields:{name:{type:"string",optional:!0,array:!1},view:{type:"View",optional:!1,array:!1}}},NullCell:{type:"struct",name:"NullCell",fields:{}},NullLiteral:{type:"struct",name:"NullLiteral",fields:{}},NumberCell:{type:"struct",name:"NumberCell",fields:{number_value:{type:"number",optional:!1,array:!1}}},NumberLiteral:{type:"struct",name:"NumberLiteral",fields:{number_value:{type:"number",optional:!1,array:!1}}},NumberSubtype:{type:"enum",name:"NumberSubtype",values:{integer:1,decimal:2}},NumberType:{type:"struct",name:"NumberType",fields:{subtype:{type:"NumberSubtype",optional:!0,array:!1}}},OrderBy:{type:"struct",name:"OrderBy",fields:{field_reference:{type:"Reference",optional:!1,array:!1},direction:{type:"OrderByDirection",optional:!0,array:!1}}},OrderByDirection:{type:"enum",name:"OrderByDirection",values:{asc:1,desc:2}},ParameterInfo:{type:"struct",name:"ParameterInfo",fields:{name:{type:"string",optional:!1,array:!1},type:{type:"ParameterType",optional:!1,array:!1},default_value:{type:"LiteralValue",optional:!0,array:!1}}},ParameterType:{type:"union",name:"ParameterType",options:{string_type:"StringType",boolean_type:"BooleanType",number_type:"NumberType",json_type:"JSONType",sql_native_type:"SQLNativeType",date_type:"DateType",timestamp_type:"TimestampType",array_type:"ArrayType",record_type:"RecordType",filter_expression_type:"FilterExpressionType"}},ParameterValue:{type:"struct",name:"ParameterValue",fields:{name:{type:"string",optional:!1,array:!1},value:{type:"LiteralValue",optional:!1,array:!1}}},Position:{type:"struct",name:"Position",fields:{line:{type:"number",optional:!1,array:!1},character:{type:"number",optional:!1,array:!1}}},Query:{type:"struct",name:"Query",fields:{definition:{type:"QueryDefinition",optional:!1,array:!1},annotations:{type:"Annotation",array:!0,optional:!0}}},QueryArrow:{type:"struct",name:"QueryArrow",fields:{source:{type:"QueryArrowSource",optional:!1,array:!1},view:{type:"ViewDefinition",optional:!1,array:!1}}},QueryArrowSource:{type:"union",name:"QueryArrowSource",options:{refinement:"QueryRefinement",source_reference:"Reference"}},QueryDefinition:{type:"union",name:"QueryDefinition",options:{arrow:"QueryArrow",query_reference:"Reference",refinement:"QueryRefinement"}},QueryInfo:{type:"struct",name:"QueryInfo",fields:{name:{type:"string",optional:!1,array:!1},schema:{type:"Schema",optional:!1,array:!1},annotations:{type:"Annotation",array:!0,optional:!0},definition:{type:"Query",optional:!0,array:!1},code:{type:"string",optional:!0,array:!1},location:{type:"Location",optional:!0,array:!1}}},QueryRefinement:{type:"struct",name:"QueryRefinement",fields:{base:{type:"QueryDefinition",optional:!1,array:!1},refinement:{type:"ViewDefinition",optional:!1,array:!1}}},Range:{type:"struct",name:"Range",fields:{start:{type:"Position",optional:!1,array:!1},end:{type:"Position",optional:!1,array:!1}}},RecordCell:{type:"struct",name:"RecordCell",fields:{record_value:{type:"Cell",array:!0,optional:!1}}},RecordType:{type:"struct",name:"RecordType",fields:{fields:{type:"DimensionInfo",array:!0,optional:!1}}},Reference:{type:"struct",name:"Reference",fields:{name:{type:"string",optional:!1,array:!1},path:{type:"string",array:!0,optional:!0},parameters:{type:"ParameterValue",array:!0,optional:!0}}},Relationship:{type:"enum",name:"Relationship",values:{one:1,many:2,cross:3}},Result:{type:"struct",name:"Result",fields:{data:{type:"Data",optional:!0,array:!1},schema:{type:"Schema",optional:!1,array:!1},sql:{type:"string",optional:!0,array:!1},connection_name:{type:"string",optional:!1,array:!1},annotations:{type:"Annotation",array:!0,optional:!0},model_annotations:{type:"Annotation",array:!0,optional:!0},query_timezone:{type:"string",optional:!0,array:!1}}},RunIndexQueryRequest:{type:"struct",name:"RunIndexQueryRequest",fields:{model_url:{type:"string",optional:!1,array:!1},source_name:{type:"string",optional:!1,array:!1},compiler_needs:{type:"CompilerNeeds",optional:!0,array:!1}}},RunIndexQueryResponse:{type:"struct",name:"RunIndexQueryResponse",fields:{result:{type:"Result",optional:!0,array:!1},compiler_needs:{type:"CompilerNeeds",optional:!0,array:!1}}},RunQueryRequest:{type:"struct",name:"RunQueryRequest",fields:{model_url:{type:"string",optional:!1,array:!1},query:{type:"Query",optional:!1,array:!1},default_row_limit:{type:"number",optional:!0,array:!1},compiler_needs:{type:"CompilerNeeds",optional:!0,array:!1}}},RunQueryResponse:{type:"struct",name:"RunQueryResponse",fields:{result:{type:"Result",optional:!0,array:!1},default_row_limit_added:{type:"number",optional:!0,array:!1},logs:{type:"LogMessage",array:!0,optional:!0},compiler_needs:{type:"CompilerNeeds",optional:!0,array:!1}}},SQLNativeCell:{type:"struct",name:"SQLNativeCell",fields:{sql_native_value:{type:"string",optional:!1,array:!1}}},SQLNativeType:{type:"struct",name:"SQLNativeType",fields:{sql_type:{type:"string",optional:!0,array:!1}}},SQLQuery:{type:"struct",name:"SQLQuery",fields:{sql:{type:"string",optional:!1,array:!1},schema:{type:"Schema",optional:!0,array:!1},connection_name:{type:"string",optional:!1,array:!1}}},SQLTable:{type:"struct",name:"SQLTable",fields:{name:{type:"string",optional:!1,array:!1},schema:{type:"Schema",optional:!0,array:!1},connection_name:{type:"string",optional:!1,array:!1}}},Schema:{type:"struct",name:"Schema",fields:{fields:{type:"FieldInfo",array:!0,optional:!1}}},SourceInfo:{type:"struct",name:"SourceInfo",fields:{name:{type:"string",optional:!1,array:!1},schema:{type:"Schema",optional:!1,array:!1},annotations:{type:"Annotation",array:!0,optional:!0},parameters:{type:"ParameterInfo",array:!0,optional:!0}}},StringCell:{type:"struct",name:"StringCell",fields:{string_value:{type:"string",optional:!1,array:!1}}},StringLiteral:{type:"struct",name:"StringLiteral",fields:{string_value:{type:"string",optional:!1,array:!1}}},StringType:{type:"struct",name:"StringType",fields:{}},TimeTruncationFieldReference:{type:"struct",name:"TimeTruncationFieldReference",fields:{field_reference:{type:"Reference",optional:!1,array:!1},truncation:{type:"TimestampTimeframe",optional:!1,array:!1}}},TimestampCell:{type:"struct",name:"TimestampCell",fields:{timestamp_value:{type:"string",optional:!1,array:!1}}},TimestampLiteral:{type:"struct",name:"TimestampLiteral",fields:{timestamp_value:{type:"string",optional:!1,array:!1},granularity:{type:"TimestampTimeframe",optional:!0,array:!1}}},TimestampTimeframe:{type:"enum",name:"TimestampTimeframe",values:{year:1,quarter:2,month:3,week:4,day:5,hour:6,minute:7,second:8}},TimestampType:{type:"struct",name:"TimestampType",fields:{timeframe:{type:"TimestampTimeframe",optional:!0,array:!1}}},Translation:{type:"struct",name:"Translation",fields:{url:{type:"string",optional:!1,array:!1},compiled_model_json:{type:"string",optional:!0,array:!1}}},View:{type:"struct",name:"View",fields:{definition:{type:"ViewDefinition",optional:!1,array:!1},annotations:{type:"Annotation",array:!0,optional:!0}}},ViewArrow:{type:"struct",name:"ViewArrow",fields:{source:{type:"ViewDefinition",optional:!1,array:!1},view:{type:"ViewDefinition",optional:!1,array:!1}}},ViewDefinition:{type:"union",name:"ViewDefinition",options:{arrow:"ViewArrow",view_reference:"Reference",refinement:"ViewRefinement",segment:"ViewSegment"}},ViewInfo:{type:"struct",name:"ViewInfo",fields:{name:{type:"string",optional:!1,array:!1},schema:{type:"Schema",optional:!1,array:!1},annotations:{type:"Annotation",array:!0,optional:!0},definition:{type:"View",optional:!0,array:!1}}},ViewOperation:{type:"union",name:"ViewOperation",options:{group_by:"GroupBy",aggregate:"Aggregate",order_by:"OrderBy",limit:"Limit",where:"FilterOperation",nest:"Nest",having:"FilterOperation"}},ViewRefinement:{type:"struct",name:"ViewRefinement",fields:{base:{type:"ViewDefinition",optional:!1,array:!1},refinement:{type:"ViewDefinition",optional:!1,array:!1}}},ViewSegment:{type:"struct",name:"ViewSegment",fields:{operations:{type:"ViewOperation",array:!0,optional:!1}}}};var FD={},wD={},ND={};Object.defineProperty(ND,"__esModule",{value:!0}),ND.RESERVED_WORDS=void 0,ND.RESERVED_WORDS=["accept","aggregate","declare","dimension","except","explore","group_by","having","index","join_cross","join_one","join_many","limit","measure","nest","order_by","primary_key","project","query","rename","sample","source","sql","turduck","top","where","all","as","asc","avg","boolean","by","case","cast","condition","count","date","day","days","desc","distinct","else","end","exclude","false","for","from","from_sql","has","hour","hours","import","is","json","last","max","min","minute","minutes","month","months","not","now","null","number","on","or","pick","quarter","quarters","second","seconds","string","sum","table","then","this","timestamp","to","true","turtle","week","weeks","when","with","year","years","ungrouped"],Object.defineProperty(wD,"__esModule",{value:!0}),wD.maybeQuoteIdentifier=void 0;const xpt=ND;function dpt(t){const e=!t.match(/^[A-Za-z_][A-Za-z_0-9]*$/),r=xpt.RESERVED_WORDS.includes(t.toLowerCase());return e||r}function hpt(t){const e=t.split(".");for(let r=0;r<e.length;r++)dpt(e[r])&&(e[r]=`\`${e[r]}\``);return e.join(".")}wD.maybeQuoteIdentifier=hpt,Object.defineProperty(FD,"__esModule",{value:!0}),FD.queryToMalloy=void 0;const tA=wD;function ppt(t,{tabWidth:e}={tabWidth:2}){const r=Apt(t);return gpt(r,{tabWidth:e})}FD.queryToMalloy=ppt;const CP=Symbol("indent"),Fu=Symbol("newline"),SP=Symbol("outdent"),mpt=Symbol("optional_newline_indent");function gpt(t,{tabWidth:e}={tabWidth:2}){let r="",i=0,s=!0;for(const o of t)if(o===Fu)r+=`
|
|
1884
|
-
`,s=!0;else if(o===SP)i--;else if(o===CP)i++;else{if(o===mpt)continue;s&&(r+=" ".repeat(i*e),s=!1),r+=o}return r}function LD(t,e,r,i){var s;if(e.includes(Fu))return[t,Fu,CP,...e,Fu,SP,r];const u=((s=i==null?void 0:i.spaces)!==null&&s!==void 0?s:!0)?" ":"";return[t,u,...e,u,r]}function ypt(t){return{contents:t,quoteCharacter:'"'}}function Ept(t){var e,r;switch(t.kind){case"filter_expression_literal":return[Dde(t.filter_expression_value)];case"boolean_literal":return[t.boolean_value.toString()];case"string_literal":{const{contents:i,quoteCharacter:s}=ypt(t.string_value);return[s,i,s]}case"number_literal":return[t.number_value.toString()];case"null_literal":return["null"];case"date_literal":return[bde(Sde(t.date_value),(e=t.granularity)!==null&&e!==void 0?e:"day")];case"timestamp_literal":return[bde(Sde(t.timestamp_value),(r=t.granularity)!==null&&r!==void 0?r:"second")]}}function Sde(t){return new Date(t)}function An(t,e){return t.toString().padStart(e,"0")}function bde(t,e){switch(e){case"year":return`@${An(t.getUTCFullYear(),4)}`;case"quarter":{const r=An(t.getUTCFullYear(),4),i=Math.floor(t.getUTCMonth()/3)+1;return`@${r}-Q${i}`}case"month":{const r=An(t.getUTCFullYear(),2),i=An(t.getUTCMonth()+1,2);return`@${r}-${i}`}case"week":{const r=An(t.getUTCFullYear(),2),i=An(t.getUTCMonth()+1,2),s=An(t.getUTCDate(),2);return`@WK${r}-${i}-${s}`}case"day":{const r=An(t.getUTCFullYear(),2),i=An(t.getUTCMonth()+1,2),s=An(t.getUTCDate(),2);return`@${r}-${i}-${s}`}case"hour":{const r=An(t.getUTCFullYear(),2),i=An(t.getUTCMonth()+1,2),s=An(t.getUTCDate(),2),o=An(t.getUTCHours(),2);return`@${r}-${i}-${s} ${o}`}case"minute":{const r=An(t.getUTCFullYear(),2),i=An(t.getUTCMonth()+1,2),s=An(t.getUTCDate(),2),o=An(t.getUTCHours(),2),u=An(t.getUTCMinutes(),2);return`@${r}-${i}-${s} ${o}:${u}`}case"second":{const r=An(t.getUTCFullYear(),2),i=An(t.getUTCMonth()+1,2),s=An(t.getUTCDate(),2),o=An(t.getUTCHours(),2),u=An(t.getUTCMinutes(),2),a=An(t.getUTCSeconds(),2);return`@${r}-${i}-${s} ${o}:${u}:${a}`}default:throw new Error("Unknown timeframe.")}}function pf(t){var e;const r=[];for(const i of(e=t.path)!==null&&e!==void 0?e:[])r.push((0,tA.maybeQuoteIdentifier)(i)),r.push(".");if(r.push((0,tA.maybeQuoteIdentifier)(t.name)),t.parameters){const i=[];for(let s=0;s<t.parameters.length;s++){const o=t.parameters[s];i.push((0,tA.maybeQuoteIdentifier)(o.name)),i.push(" is "),i.push(...Ept(o.value)),s<t.parameters.length-1&&i.push(",",Fu)}r.push(...LD("(",i,")",{spaces:!1}))}return r}function Apt(t){const e=[];return e.push(...f1(t.annotations)),e.push("run: "),e.push(...bP(t.definition)),e}function _pt(t){const e=[];switch(t.kind){case"source_reference":{e.push(...pf(t));break}case"refinement":e.push(...bP(t));break}return e}function bP(t){const e=[];switch(t.kind){case"arrow":{e.push(..._pt(t.source)),e.push(" -> "),e.push(...kd(t.view));break}case"query_reference":{e.push(...pf(t));break}case"refinement":{const r=bP(t.base);t.base.kind==="arrow"?e.push(...LD("(",r,")",{spaces:!1})):e.push(...r),e.push(" + "),e.push(...kd(t.refinement));break}}return e}function kd(t){const e=[];switch(t.kind){case"arrow":{e.push(...kd(t.source)),e.push(" -> "),e.push(...kd(t.view));break}case"view_reference":{e.push(...pf(t));break}case"refinement":{e.push(...kd(t.base)),e.push(" + "),e.push(...kd(t.refinement));break}case"segment":{e.push(...vpt(t));break}}return e}function vpt(t){if(t.operations.length===0)return["{ }"];const e=t.operations.length>1,r=[];for(let i=0;i<t.operations.length;i++){const s=t.operations[i],o=[s];for(;i<t.operations.length-1;){const u=t.operations[i+1];if(u.kind===s.kind)o.push(u),i++;else break}r.push(...Cpt(o)),e&&i<t.operations.length-1&&r.push(Fu)}return LD("{",r,"}")}function Cpt(t){switch(t[0].kind){case"aggregate":return Rpt(t);case"group_by":return Tpt(t);case"order_by":return Dpt(t);case"nest":return Fpt(t);case"limit":return Ipt(t);case"where":return Rde(t);case"having":return $pt(t)}}function c1(t,e,r=""){const i=[];i.push(`${t}:`);const s=e.length>1||e.some(o=>o.includes(Fu));s?i.push(Fu,CP):i.push(" ");for(let o=0;o<e.length;o++){const u=e[o];i.push(...u),e.length>1&&o<e.length-1&&i.push(r),s&&o<e.length-1&&i.push(Fu)}return s&&i.push(SP),i}function Spt(t){const e=[];return e.push(...bpt(t.expression)),e}function l1t(t){return t}function bpt(t){switch(t.kind){case"field_reference":return pf(t);case"time_truncation":return[...pf(t.field_reference),".",t.truncation];case"filtered_field":return[...pf(t.field_reference),...LD(" {",Rde(t.where),"}")]}}function Tde(t,e=!1){const r=[];return e||r.push(...f1(t.field.annotations)),t.name&&(r.push((0,tA.maybeQuoteIdentifier)(t.name)),r.push(" is ")),r.push(...Spt(t.field)),r}function Tpt(t){const e=[],r=t.length===1;return r&&e.push(...f1(t[0].field.annotations)),e.push(...c1("group_by",t.map(i=>Tde(i,r)))),e}function Rpt(t){const e=[],r=t.length===1;return r&&e.push(...f1(t[0].field.annotations)),e.push(...c1("aggregate",t.map(i=>Tde(i,r)))),e}function Dpt(t){return c1("order_by",t.map(Opt),",")}function Opt(t){const e=[];return e.push(...pf(t.field_reference)),t.direction&&(e.push(" "),e.push(t.direction)),e}function Fpt(t){const e=[],r=t.length===1;return r&&e.push(...f1(t[0].view.annotations)),e.push(...c1("nest",t.map(i=>wpt(i,r)))),e}function wpt(t,e=!1){const r=[];return e||r.push(...f1(t.view.annotations)),t.name&&(r.push((0,tA.maybeQuoteIdentifier)(t.name)),r.push(" is ")),r.push(...Npt(t.view)),r}function Npt(t){return kd(t.definition)}function Lpt(t){return[`limit: ${t.limit}`]}function Ipt(t){const e=[];for(let r=0;r<t.length;r++)r!==0&&e.push(Fu),e.push(...Lpt(t[r]));return e}function Rde(t){return c1("where",t.map(Ode),",")}function $pt(t){return c1("having",t.map(Ode),",")}const Bpt=["`","'",'"'];function Dde(t){let e,r;for(const i of Bpt){const s=kpt(t,i);if(s===t)return`f${i}${t}${i}`;(r===void 0||s.length<r.length)&&(e=i,r=s)}return`f${e}${r}${e}`}function kpt(t,e){let r="";for(let i=0;i<t.length;i++)t.slice(i).startsWith(e)?(r+="\\"+e,i+=e.length):(r+=t[i],t[i]==="\\"&&(r+=t[++i]));return r}function Ode(t){switch(t.filter.kind){case"filter_string":return[...pf(t.filter.field_reference)," ~ ",Dde(t.filter.filter)]}}function f1(t){return t?t.flatMap(Mpt):[]}function Mpt(t){return[t.value.trim(),Fu]}var Za={};Object.defineProperty(Za,"__esModule",{value:!0}),Za.convertToThrift=Za.convertFromThrift=Za.unnestUnions=Za.nestUnions=void 0;const Ppt=eA;function TP(t){if(t==null)return t;if(typeof t=="string"||typeof t=="number"||typeof t=="boolean")return t;if(Array.isArray(t))return t.map(TP);{const e={};let r;for(const i in t)i==="kind"?r=t[i]:e[i]=TP(t[i]);return r===void 0?e:{[r]:e}}}Za.nestUnions=TP;function ID(t,e){if(t==null)return t;if(typeof t=="string"||typeof t=="number"||typeof t=="boolean")return t;if(Array.isArray(t))return t.map(r=>ID(r,e));{const r=x1(e);if(r.type==="union"){for(const i in r.options)if(t[i]!==void 0){const s=ID(t[i],r.options[i]);if(typeof s=="object")return{kind:i,...s}}}else if(r.type==="struct"){const i={};for(const s in t){const o=r.fields[s];if(o===void 0)throw new Error(`Unknown field ${s} in ${e}`);i[s]=ID(t[s],o.type)}return i}else throw new Error(`Cannot unnest unions in an enum type ${e}`)}}Za.unnestUnions=ID;function $D(t,e){if(t==null)return t;if(typeof t=="string"||typeof t=="boolean")return t;if(typeof t=="number"){if(e==="number")return t;const r=x1(e);if(r.type!=="enum")throw new Error(`Found a number where a ${e} was expected`);const i=Object.entries(r.values).find(([,s])=>s===t);if(i===void 0)throw new Error(`${t} is not a valid enum value for ${e}`);return i[0]}else{if(Array.isArray(t))return t.map(r=>$D(r,e));{const r=x1(e);if(r.type==="union"){for(const i in r.options)if(t[i]!==void 0){const s=$D(t[i],r.options[i]);if(typeof s=="object")return{kind:i,...s}}}else if(r.type==="struct"){const i={};for(const s in t){const o=r.fields[s];if(o===void 0)throw new Error(`Unknown field ${s} in ${e}`);i[s]=$D(t[s],o.type)}return i}else throw new Error(`Cannot unnest unions in an enum type ${e}`)}}}Za.convertFromThrift=$D;function x1(t){const e=Ppt.MALLOY_INTERFACE_TYPES[t];if(e===void 0)throw new Error(`Unknown Malloy interface type ${t}`);return e}function BD(t,e){if(t==null)return t;if(typeof t=="number"||typeof t=="boolean")return t;if(typeof t=="string"){if(e==="string")return t;const r=x1(e);if(r.type==="enum"){const i=r.values[t];if(i===void 0)throw new Error(`${t} is not a valid enum value for ${e}`);return i}}else{if(Array.isArray(t))return t.map(r=>BD(r,e));{const r=x1(e);if(r.type==="union"){const i=t.kind,s=r.options[i];if(s===void 0)throw new Error(`${i} is not a valid union of ${e}`);const o=x1(s);if(o.type!=="struct")throw new Error("Union fields must be structs");const u={};for(const a in t){if(a==="kind")continue;const l=o.fields[a];u[a]=BD(t[a],l.type)}return{[i]:u}}else if(r.type==="struct"){const i={};for(const s in t){const o=r.fields[s];if(o===void 0)throw new Error(`Unknown field ${s} in ${e}`);i[s]=BD(t[s],o.type)}return i}}}}Za.convertToThrift=BD,function(t){var e=T&&T.__createBinding||(Object.create?function(o,u,a,l){l===void 0&&(l=a);var c=Object.getOwnPropertyDescriptor(u,a);(!c||("get"in c?!u.__esModule:c.writable||c.configurable))&&(c={enumerable:!0,get:function(){return u[a]}}),Object.defineProperty(o,l,c)}:function(o,u,a,l){l===void 0&&(l=a),o[l]=u[a]}),r=T&&T.__exportStar||function(o,u){for(var a in o)a!=="default"&&!Object.prototype.hasOwnProperty.call(u,a)&&e(u,o,a)};Object.defineProperty(t,"__esModule",{value:!0}),t.thingy4sddfdfsd=t.thingy4sdfsd=t.thingy4dfdsfs=t.thingy4asdfas=t.thingy4asdfasdf=t.thingy3dfdf=t.thingy3=t.thingy2asdf=t.thingyssdfg=t.thingy123r=t.thingy1=t.res=t.test=t.convertToThrift=t.convertFromThrift=t.unnestUnions=t.nestUnions=t.queryToMalloy=void 0,r(eA,t);var i=FD;Object.defineProperty(t,"queryToMalloy",{enumerable:!0,get:function(){return i.queryToMalloy}});var s=Za;Object.defineProperty(t,"nestUnions",{enumerable:!0,get:function(){return s.nestUnions}}),Object.defineProperty(t,"unnestUnions",{enumerable:!0,get:function(){return s.unnestUnions}}),Object.defineProperty(t,"convertFromThrift",{enumerable:!0,get:function(){return s.convertFromThrift}}),Object.defineProperty(t,"convertToThrift",{enumerable:!0,get:function(){return s.convertToThrift}}),t.test={entries:[{kind:"source",name:"flights",schema:{fields:[{kind:"dimension",name:"carrier",type:{kind:"boolean_type"},annotations:[{value:"# foo=1"}]},{kind:"dimension",name:"arr",type:{kind:"array_type",element_type:{kind:"boolean_type"}}},{kind:"dimension",name:"arr_rec",type:{kind:"array_type",element_type:{kind:"record_type",fields:[{name:"arr",type:{kind:"array_type",element_type:{kind:"boolean_type"}}}]}}},{kind:"dimension",name:"rec",type:{kind:"record_type",fields:[{name:"arr",type:{kind:"array_type",element_type:{kind:"boolean_type"}}}]}},{kind:"join",name:"carriers",relationship:"one",schema:{fields:[{kind:"dimension",name:"code",type:{kind:"string_type"}}]}},{kind:"view",name:"by_carrier",schema:{fields:[{kind:"dimension",name:"carrier",type:{kind:"string_type"}},{kind:"dimension",name:"flight_count",type:{kind:"number_type"}}]}}]},parameters:[{name:"param",type:{kind:"number_type"},default_value:{kind:"number_literal",number_value:7}}]}],anonymous_queries:[]},t.res={connection_name:"foo",data:{kind:"array_cell",array_value:[{kind:"record_cell",record_value:[{kind:"string_cell",string_value:"UA"},{kind:"number_cell",number_value:12341234}]},{kind:"record_cell",record_value:[{kind:"string_cell",string_value:"AA"},{kind:"number_cell",number_value:2343}]}]},schema:{fields:[{kind:"dimension",name:"carrier",type:{kind:"string_type"}},{kind:"dimension",name:"flight_count",type:{kind:"number_type"}}]},sql:"SELECT * ..."},t.thingy1={definition:{kind:"query_reference",name:"flights_by_carrier"}},t.thingy123r={definition:{kind:"arrow",source:{kind:"source_reference",name:"flights"},view:{kind:"view_reference",name:"by_carrier"}}},t.thingyssdfg={definition:{kind:"refinement",base:{kind:"query_reference",name:"flights"},refinement:{kind:"view_reference",name:"by_carrier"}}},t.thingy2asdf={definition:{kind:"arrow",source:{kind:"source_reference",name:"flights"},view:{kind:"refinement",base:{kind:"view_reference",name:"by_carrier"},refinement:{kind:"segment",operations:[{kind:"where",filter:{kind:"filter_string",field_reference:{name:"carrier"},filter:"WN"}}]}}}},t.thingy3={definition:{kind:"arrow",source:{kind:"source_reference",name:"flights"},view:{kind:"refinement",base:{kind:"view_reference",name:"by_carrier"},refinement:{kind:"segment",operations:[{kind:"group_by",field:{expression:{kind:"field_reference",name:"carrier"}}},{kind:"group_by",field:{expression:{kind:"field_reference",name:"foo"}}}]}}}},t.thingy3dfdf={definition:{kind:"arrow",source:{kind:"source_reference",name:"flights"},view:{kind:"refinement",base:{kind:"view_reference",name:"by_carrier"},refinement:{kind:"view_reference",name:"top10"}}}},t.thingy4asdfasdf={definition:{kind:"arrow",source:{kind:"source_reference",name:"flights"},view:{kind:"segment",operations:[{kind:"group_by",field:{expression:{kind:"field_reference",name:"carrier"}}},{kind:"group_by",field:{expression:{kind:"field_reference",name:"foo"}}}]}}},t.thingy4asdfas={definition:{kind:"arrow",source:{kind:"source_reference",name:"flights"},view:{kind:"view_reference",name:"by_carrier"}}},t.thingy4dfdsfs={definition:{kind:"arrow",source:{kind:"source_reference",name:"flights"},view:{kind:"refinement",base:{kind:"view_reference",name:"by_carrier"},refinement:{kind:"segment",operations:[{kind:"limit",limit:10}]}}}},t.thingy4sdfsd={definition:{kind:"arrow",source:{kind:"source_reference",name:"flights"},view:{kind:"segment",operations:[{kind:"group_by",field:{expression:{kind:"field_reference",name:"carrier"}}},{kind:"limit",limit:10}]}}},t.thingy4sddfdfsd={definition:{kind:"arrow",source:{kind:"source_reference",name:"flights"},view:{kind:"segment",operations:[]}}}}(vP);var on={},Upt=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),jpt=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),qpt=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&Upt(e,t,r);return jpt(e,t),e};Object.defineProperty(on,"__esModule",{value:!0}),on.statedCompileQuery=on.newCompileQueryState=on.hasErrors=on.compileSource=on.compileModel=on._statedCompileModel=on.statedCompileSource=on.statedCompileModel=on.newCompileSourceState=on.newCompileModelState=on.updateCompileModelState=on.compileQuery=void 0;const Hpt=qpt(vP),Qpt=M4,Fde=Gi,zpt=Va,wde=g0,Wpt=mi,Nde=$o,Md=VE;function Lde(t,e){return`${t}:${e}`}function Gpt(t,e){return{type:"sql_select",selectStr:t.sql,connection:t.connection_name,dialect:e,fields:t.schema?$de(t.schema):[],name:(0,wde.sqlKey)(t.connection_name,t.sql)}}function Vpt(t,e){return{type:"table",tablePath:t.name,connection:t.connection_name,dialect:e,fields:t.schema?$de(t.schema):[],name:Lde(t.connection_name,t.name)}}function Ypt(t){if(t!==void 0)return t==="decimal"?"float":"integer"}function Ide(t){switch(t.kind){case"string_type":return{type:"string"};case"number_type":return{type:"number",numberType:Ypt(t.subtype)};case"boolean_type":return{type:"boolean"};case"timestamp_type":return{type:"timestamp",timeframe:t.timeframe};case"date_type":return{type:"date",timeframe:t.timeframe};case"sql_native_type":return{type:"sql native",rawType:t.sql_type};case"json_type":return{type:"json"};case"array_type":{if(t.element_type.kind==="record_type")return{type:"array",elementTypeDef:{type:"record_element"},fields:t.element_type.fields.map(RP)};{const e=Ide(t.element_type);if(e.type==="record")throw new Error("Arrays of records should be a repeated record type");return{type:"array",elementTypeDef:e}}}case"record_type":return{type:"record",fields:t.fields.map(RP)}}}function RP(t){var e;const r=Ide(t.type);return{...(0,Fde.mkFieldDef)(r,t.name),annotation:t.annotations&&t.annotations.length?{notes:(e=t.annotations)===null||e===void 0?void 0:e.map(i=>({text:i.value,at:{url:"~internal~",range:Md.DEFAULT_LOG_RANGE}}))}:void 0}}function Kpt(t){if(t.kind!=="dimension")throw new Error("Table schemas must only have dimension fields");return RP(t)}function $de(t){const e=[];for(const r of t.fields)e.push(Kpt(r));return e}function Bde(t){var e,r,i,s,o,u;const a={urls:{},tables:{},compileSQL:{},translations:{}};if(t){for(const l of(e=t.files)!==null&&e!==void 0?e:[])l.contents!==void 0&&(a.urls[l.url]=l.contents);for(const l of(r=t.table_schemas)!==null&&r!==void 0?r:[]){const c=(i=t.connections)===null||i===void 0?void 0:i.find(f=>f.name===l.connection_name);c&&l.schema&&c.dialect&&(a.tables[Lde(l.connection_name,l.name)]=Vpt(l,c.dialect))}for(const l of(s=t.sql_schemas)!==null&&s!==void 0?s:[]){const c=(o=t.connections)===null||o===void 0?void 0:o.find(f=>f.name===l.connection_name);c&&c.dialect&&(a.compileSQL[(0,wde.sqlKey)(l.connection_name,l.sql)]=Gpt(l,c.dialect))}for(const l of(u=t.translations)!==null&&u!==void 0?u:[])if(l.compiled_model_json){const c=JSON.parse(l.compiled_model_json);a.translations[l.url]=c}}return a}function kde(t,e,r){var i,s,o;const u={},a=new Set;if(t!==void 0&&(u.sql_schemas=[{sql:t.selectStr,connection_name:t.connection}],a.add(t.connection)),e!==void 0)for(const l of e)(i=u.files)!==null&&i!==void 0||(u.files=[]),u.files.push({url:l});if(r!==void 0)for(const l in r){const c=r[l],f=(s=c.connectionName)!==null&&s!==void 0?s:"__default__";(o=u.table_schemas)!==null&&o!==void 0||(u.table_schemas=[]),u.table_schemas.push({name:c.tablePath,connection_name:f}),a.add(f)}return a.size>0&&(u.connections=Array.from(a).map(l=>({name:l}))),u}function Jpt(t,e){return e??(e=qde(t)),Hde(e)}on.compileQuery=Jpt;function Xpt(t,e){function r(s,o){var u,a,l,c;s.translator.update(o),s.extending&&r(s.extending,o),s.hasSource||(s.hasSource=((a=(u=e==null?void 0:e.files)===null||u===void 0?void 0:u.some(f=>f.url===s.translator.sourceURL))!==null&&a!==void 0?a:!1)||((c=(l=e==null?void 0:e.translations)===null||l===void 0?void 0:l.some(f=>f.url===s.translator.sourceURL))!==null&&c!==void 0?c:!1))}const i=Bde(e);r(t,i)}on.updateCompileModelState=Xpt;function kD(t,e,r){var i,s,o,u;const a=new Qpt.MalloyTranslator(t,null,Bde(e)),l=((s=(i=e==null?void 0:e.files)===null||i===void 0?void 0:i.some(c=>c.url===t))!==null&&s!==void 0?s:!1)||((u=(o=e==null?void 0:e.translations)===null||o===void 0?void 0:o.some(c=>c.url===t))!==null&&u!==void 0?u:!1);return r?{extending:kD(r,e),translator:a,done:!1,hasSource:l}:{translator:a,done:!1,hasSource:l}}function Mde(t){return kD(t.model_url,t.compiler_needs,t.extend_model_url)}on.newCompileModelState=Mde;function Pde(t){return kD(t.model_url,t.compiler_needs,t.extend_model_url)}on.newCompileSourceState=Pde;function Ude(t){return Zpt(nA(t),t.translator.sourceURL)}on.statedCompileModel=Ude;function jde(t,e){return n2t(nA(t),e,t.translator.sourceURL)}on.statedCompileSource=jde;function nA(t){let e;if(t.extending){if(!t.extending.done){const i=nA(t.extending);if(!t.extending.done)return i}e=t.extending.translator.modelDef}if(!t.hasSource)return{compilerNeeds:kde(void 0,[t.translator.sourceURL],void 0)};const r=t.translator.translate(e);if(r.final){if(t.done=!0,r.modelDef)return{model:(0,zpt.modelDefToModelInfo)(r.modelDef),modelDef:r.modelDef};if(r.problems===void 0||r.problems.length===0)throw new Error("No problems found, but no model either");return{logs:r.problems}}else return{compilerNeeds:kde(r.compileSQL,r.urls,r.tables),logs:r.problems}}on._statedCompileModel=nA;function Zpt(t,e){const r=t.logs?(0,Md.mapLogs)(t.logs,e):void 0;if(t.compilerNeeds)return{compiler_needs:t.compilerNeeds,logs:r};{let i;return t.modelDef&&(i=[{url:e,compiled_model_json:JSON.stringify(t.modelDef)}]),{model:t.model,logs:r,translations:i}}}function e2t(t,e){return e??(e=Mde(t)),Ude(e)}on.compileModel=e2t;function t2t(t){const e=Pde(t);return jde(e,t.name)}on.compileSource=t2t;function n2t(t,e,r){const i=t.logs?(0,Md.mapLogs)(t.logs,r):void 0;if(t.model){const s=t.model.entries.find(o=>o.name===e);return s===void 0?{logs:[...i??[],{url:r,severity:"error",message:`Model does not contain a source named ${e}`,range:Md.DEFAULT_LOG_RANGE}]}:{source:s,logs:i}}else return{compiler_needs:t.compilerNeeds,logs:i}}function r2t(t){var e;return(e=t==null?void 0:t.some(r=>r.severity==="error"))!==null&&e!==void 0?e:!1}on.hasErrors=r2t;function qde(t){var e,r;const i=Hpt.queryToMalloy(t.query),s={...(e=t.compiler_needs)!==null&&e!==void 0?e:{}},o="internal://query.malloy";return s.files=[{url:o,contents:i},...(r=s.files)!==null&&r!==void 0?r:[]],{...kD(o,s,t.model_url),defaultRowLimit:t.default_row_limit}}on.newCompileQueryState=qde;function Hde(t){var e;const r=nA(t),i=t.translator.sourceURL,s=r.logs?(0,Md.mapLogs)(r.logs,i):void 0;if(r.model){const o=r.modelDef.queryList;if(o.length===0)return{logs:[...s??[],{url:i,severity:"error",message:"Internal error: No queries found",range:Md.DEFAULT_LOG_RANGE}]};const u=o.length-1,a=r.modelDef.queryList[u],l=r.model.anonymous_queries[u].schema,c=(e=r.model.anonymous_queries[u].annotations)!==null&&e!==void 0?e:[];try{const x=new Fde.QueryModel(r.modelDef).compileQuery(a,{defaultRowLimit:t.defaultRowLimit}),h=(0,Wpt.annotationToTaglines)(r.modelDef.annotation).map(p=>({value:p}));return c.push({value:Nde.Tag.withPrefix("#(malloy) ").set(["source_name"],x.sourceExplore).toString()}),x.queryName&&c.push({value:Nde.Tag.withPrefix("#(malloy) ").set(["query_name"],x.queryName).toString()}),{result:{sql:x.sql,schema:l,connection_name:x.connectionName,annotations:c.length>0?c:void 0,model_annotations:h.length>0?h:void 0,query_timezone:x.queryTimezone},default_row_limit_added:x.defaultRowLimitAdded}}catch(f){return{logs:[...s??[],{url:i,severity:"error",message:`Internal compiler error: ${f.message}`,range:Md.DEFAULT_LOG_RANGE}]}}}else return{compiler_needs:r.compilerNeeds,logs:s}}on.statedCompileQuery=Hde;var i2t=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),s2t=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),Qde=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&i2t(e,t,r);return s2t(e,t),e};Object.defineProperty(hf,"__esModule",{value:!0}),hf.compileQuery=hf.compileSource=hf.compileModel=void 0;const o2t=Qde(vP),el=Qde(on),u2t=m2;function a2t(t,e){return t.type==="compile_model"?e.type!=="compile_model"?!1:t.modelURL===e.modelURL&&t.extendModelURL===e.extendModelURL:t.type==="compile_source"?e.type!=="compile_source"?!1:t.modelURL===e.modelURL&&t.extendModelURL===e.extendModelURL&&t.name===e.name:e.type!=="compile_query"?!1:t.modelURL===e.modelURL&&t.queryString===e.queryString}class l2t{constructor(){this.sessions=new Map}purgeExpired(e){const r=new Date;for(const i of this.sessions.values())i.sessionId!==(e==null?void 0:e.except)&&i.expires&&i.expires<r&&this.sessions.delete(i.sessionId)}findSession(e,r){const i=this.sessions.get(e);if(i&&a2t(i.sessionInfo,r))return i}getExpires(e){return e instanceof Date?e:new Date(Date.now()+e.seconds*1e3)}newSessionId(){let e;do e=(0,u2t.v4)();while(this.sessions.has(e));return e}newCompileModelSession(e,r,i){const s=i!=null&&i.ttl?this.getExpires(i.ttl):void 0,o=el.newCompileModelState(e);return{type:"compile_model",sessionInfo:r,state:o,expires:s,sessionId:this.newSessionId()}}newCompileSourceSession(e,r,i){const s=i!=null&&i.ttl?this.getExpires(i.ttl):void 0,o=el.newCompileSourceState(e);return{type:"compile_source",sessionInfo:r,state:o,expires:s,sessionId:this.newSessionId()}}newCompileQuerySession(e,r,i){const s=i!=null&&i.ttl?this.getExpires(i.ttl):void 0,o=el.newCompileQueryState(e);return{type:"compile_query",sessionInfo:r,state:o,expires:s,sessionId:this.newSessionId()}}findCompileModelSession(e,r){const i=this.findSession(e,r);if((i==null?void 0:i.type)==="compile_model")return i}killSession(e){this.sessions.delete(e)}hasErrors(e){return el.hasErrors(e)}compileModel(e,r){const i={type:"compile_model",modelURL:e.model_url,extendModelURL:e.extend_model_url};let s=(r==null?void 0:r.session_id)&&this.findCompileModelSession(r.session_id,i);this.purgeExpired({except:r==null?void 0:r.session_id}),s?(r!=null&&r.ttl&&(s.expires=this.getExpires(r.ttl)),el.updateCompileModelState(s.state,e.compiler_needs)):(s=this.newCompileModelSession(e,i,r),this.sessions.set(s.sessionId,s));const o=el.statedCompileModel(s.state);return(o.model||this.hasErrors(o.logs))&&this.killSession(s.sessionId),{...o,session_id:s.sessionId}}findCompileSourceSession(e,r){const i=this.findSession(e,r);if((i==null?void 0:i.type)==="compile_source")return i}compileSource(e,r){const i={type:"compile_source",modelURL:e.model_url,name:e.name,extendModelURL:e.extend_model_url};let s=(r==null?void 0:r.session_id)&&this.findCompileSourceSession(r.session_id,i);this.purgeExpired({except:r==null?void 0:r.session_id}),s?(r!=null&&r.ttl&&(s.expires=this.getExpires(r.ttl)),el.updateCompileModelState(s.state,e.compiler_needs)):(s=this.newCompileSourceSession(e,i,r),this.sessions.set(s.sessionId,s));const o=el.statedCompileSource(s.state,e.name);return(o.source||this.hasErrors(o.logs))&&this.killSession(s.sessionId),{...o,session_id:s.sessionId}}findCompileQuerySession(e,r){const i=this.findSession(e,r);if((i==null?void 0:i.type)==="compile_query")return i}compileQuery(e,r){const i=o2t.queryToMalloy(e.query),s={type:"compile_query",modelURL:e.model_url,queryString:i,query:e.query};let o=(r==null?void 0:r.session_id)&&this.findCompileQuerySession(r.session_id,s);this.purgeExpired({except:r==null?void 0:r.session_id}),o?(r!=null&&r.ttl&&(o.expires=this.getExpires(r.ttl)),el.updateCompileModelState(o.state,e.compiler_needs)):(o=this.newCompileQuerySession(e,s,r),this.sessions.set(o.sessionId,o));const u=el.statedCompileQuery(o.state);return(u.result||this.hasErrors(u.logs))&&this.killSession(o.sessionId),{...u,session_id:o.sessionId}}}const DP=new l2t;function c2t(t,e){return DP.compileModel(t,e)}hf.compileModel=c2t;function f2t(t,e){return DP.compileSource(t,e)}hf.compileSource=f2t;function x2t(t,e){return DP.compileQuery(t,e)}hf.compileQuery=x2t;var mf={},d2t=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),h2t=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),p2t=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&d2t(e,t,r);return h2t(e,t),e};Object.defineProperty(mf,"__esModule",{value:!0}),mf.compileQuery=mf.compileSource=mf.compileModel=void 0;const OP=p2t(on);function m2t(t){return OP.compileModel(t)}mf.compileModel=m2t;function g2t(t){return OP.compileSource(t)}mf.compileSource=g2t;function y2t(t){return OP.compileQuery(t)}mf.compileQuery=y2t;var tl={},E2t=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),A2t=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),_2t=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&E2t(e,t,r);return A2t(e,t),e};Object.defineProperty(tl,"__esModule",{value:!0}),tl.runQuery=tl.compileQuery=tl.compileSource=tl.compileModel=void 0;const Fo=_2t(on),zde=VE;async function FP(t,e){var r,i,s,o,u,a,l,c,f;if(t===void 0)throw new Error("Expected compiler to have needs because it didn't return a result");const x={};if(t.connections)for(const h of t.connections){const p=await e.connections.lookupConnection(h.name);(r=x.connections)!==null&&r!==void 0||(x.connections=[]),x.connections.push({...h,dialect:p.dialectName})}if(t.files)for(const h of t.files){const p=await e.urls.readURL(new URL(h.url));(i=x.files)!==null&&i!==void 0||(x.files=[]),typeof p=="string"?x.files.push({...h,contents:p}):x.files.push({...h,contents:p.contents,invalidation_key:(s=p.invalidationKey)===null||s===void 0?void 0:s.toString()})}if(t.table_schemas){const h={};for(const p of t.table_schemas)(o=h[c=p.connection_name])!==null&&o!==void 0||(h[c]=[]),h[p.connection_name].push(p);for(const p in h){const m=await e.connections.lookupConnection(p),g=h[p].map(E=>E.name),y=await Promise.all(g.map(async E=>({name:E,schema:await m.fetchSchemaForTable(E)})));(u=x.table_schemas)!==null&&u!==void 0||(x.table_schemas=[]);for(const E of y)x.table_schemas.push({connection_name:p,name:E.name,schema:E.schema})}}if(t.sql_schemas){const h={};for(const p of t.sql_schemas)(a=h[f=p.connection_name])!==null&&a!==void 0||(h[f]=[]),h[p.connection_name].push(p);for(const p in h){const m=await e.connections.lookupConnection(p),g=h[p].map(E=>E.sql),y=await Promise.all(g.map(async E=>({sql:E,schema:await m.fetchSchemaForSQLQuery(E)})));(l=x.sql_schemas)!==null&&l!==void 0||(x.sql_schemas=[]);for(const E of y)x.sql_schemas.push({connection_name:p,sql:E.sql,schema:E.schema})}}return x}async function v2t(t,e){const r=Fo.newCompileModelState(t);for(;;){const i=Fo.statedCompileModel(r);if(i.model||Fo.hasErrors(i.logs))return i;const s=await FP(i.compiler_needs,e);Fo.updateCompileModelState(r,s)}}tl.compileModel=v2t;async function C2t(t,e){const r=Fo.newCompileSourceState(t);for(;;){const i=Fo.statedCompileSource(r,t.name);if(i.source||Fo.hasErrors(i.logs))return i;const s=await FP(i.compiler_needs,e);Fo.updateCompileModelState(r,s)}}tl.compileSource=C2t;async function Wde(t,e){const r=Fo.newCompileQueryState(t);for(;;){const i=Fo.statedCompileQuery(r);if(i.result||Fo.hasErrors(i.logs))return i;const s=await FP(i.compiler_needs,e);Fo.updateCompileModelState(r,s)}}tl.compileQuery=Wde;async function S2t(t,e){var r,i;const s=await Wde(t,e);if(s.result===void 0)return s;const o=t.model_url;if(s.result.sql===void 0)return{logs:[...(r=s.logs)!==null&&r!==void 0?r:[],{url:o,severity:"error",message:"Internal error: Compiler did not generate SQL",range:zde.DEFAULT_LOG_RANGE}]};try{const a=await(await e.connections.lookupConnection(s.result.connection_name)).runSQL(s.result.sql,s.result.schema);return{...s,result:{...s.result,data:a}}}catch(u){return{...s,logs:[...(i=s.logs)!==null&&i!==void 0?i:[],{url:o,severity:"error",message:`Error running SQL: ${u.message}`,range:zde.DEFAULT_LOG_RANGE}]}}}tl.runQuery=S2t;var Gde={};Object.defineProperty(Gde,"__esModule",{value:!0}),function(t){var e=T&&T.__createBinding||(Object.create?function(o,u,a,l){l===void 0&&(l=a);var c=Object.getOwnPropertyDescriptor(u,a);(!c||("get"in c?!u.__esModule:c.writable||c.configurable))&&(c={enumerable:!0,get:function(){return u[a]}}),Object.defineProperty(o,l,c)}:function(o,u,a,l){l===void 0&&(l=a),o[l]=u[a]}),r=T&&T.__setModuleDefault||(Object.create?function(o,u){Object.defineProperty(o,"default",{enumerable:!0,value:u})}:function(o,u){o.default=u}),i=T&&T.__importStar||function(o){if(o&&o.__esModule)return o;var u={};if(o!=null)for(var a in o)a!=="default"&&Object.prototype.hasOwnProperty.call(o,a)&&e(u,o,a);return r(u,o),u},s=T&&T.__exportStar||function(o,u){for(var a in o)a!=="default"&&!Object.prototype.hasOwnProperty.call(u,a)&&e(u,o,a)};Object.defineProperty(t,"__esModule",{value:!0}),t.util=t.asynchronous=t.stateless=t.sessioned=void 0,t.sessioned=i(hf),t.stateless=i(mf),t.asynchronous=i(tl),s(Gde,t),t.util=i(VE)}(Cde),function(t){var e=T&&T.__createBinding||(Object.create?function(h,p,m,g){g===void 0&&(g=m);var y=Object.getOwnPropertyDescriptor(p,m);(!y||("get"in y?!p.__esModule:y.writable||y.configurable))&&(y={enumerable:!0,get:function(){return p[m]}}),Object.defineProperty(h,g,y)}:function(h,p,m,g){g===void 0&&(g=m),h[g]=p[m]}),r=T&&T.__setModuleDefault||(Object.create?function(h,p){Object.defineProperty(h,"default",{enumerable:!0,value:p})}:function(h,p){h.default=p}),i=T&&T.__importStar||function(h){if(h&&h.__esModule)return h;var p={};if(h!=null)for(var m in h)m!=="default"&&Object.prototype.hasOwnProperty.call(h,m)&&e(p,h,m);return r(p,h),p};Object.defineProperty(t,"__esModule",{value:!0}),t.EmptyURLReader=t.SingleConnectionRuntime=t.ConnectionRuntime=t.AtomicFieldType=t.Runtime=t.Malloy=t.Model=t.MalloyTranslator=t.malloyToQuery=t.composeSQLExpr=t.indent=t.expressionIsUngroupedAggregate=t.expressionIsScalar=t.expressionIsCalculation=t.expressionIsAnalytic=t.expressionIsAggregate=t.mkFieldDef=t.mkArrayDef=t.isBasicArray=t.isRepeatedRecord=t.isSamplingRows=t.isSamplingPercent=t.isSamplingEnable=t.isJoinedSource=t.isJoined=t.isBasicAtomic=t.Segment=t.isSourceDef=t.TinyParser=t.Dialect=t.spread=t.literal=t.variadicParam=t.param=t.makeParam=t.sql=t.maxScalar=t.minAggregate=t.anyExprType=t.minScalar=t.overload=t.qtz=t.arg=t.registerDialect=t.MySQLDialect=t.SnowflakeDialect=t.PostgresDialect=t.TrinoDialect=t.StandardSQLDialect=t.DuckDBDialect=void 0,t.annotationToTaglines=t.annotationToTag=t.sqlKey=t.API=t.modelDefToModelInfo=t.toAsyncGenerator=t.CacheManager=t.InMemoryModelCache=t.Explore=t.DataWriter=t.Parse=t.JSONWriter=t.CSVWriter=t.QueryMaterializer=t.Result=t.PreparedResult=t.TimestampTimeframe=t.DateTimeframe=t.SourceRelationship=t.JoinRelationship=t.MalloyError=t.FixedConnectionMap=t.InMemoryURLReader=void 0;var s=h2;Object.defineProperty(t,"DuckDBDialect",{enumerable:!0,get:function(){return s.DuckDBDialect}}),Object.defineProperty(t,"StandardSQLDialect",{enumerable:!0,get:function(){return s.StandardSQLDialect}}),Object.defineProperty(t,"TrinoDialect",{enumerable:!0,get:function(){return s.TrinoDialect}}),Object.defineProperty(t,"PostgresDialect",{enumerable:!0,get:function(){return s.PostgresDialect}}),Object.defineProperty(t,"SnowflakeDialect",{enumerable:!0,get:function(){return s.SnowflakeDialect}}),Object.defineProperty(t,"MySQLDialect",{enumerable:!0,get:function(){return s.MySQLDialect}}),Object.defineProperty(t,"registerDialect",{enumerable:!0,get:function(){return s.registerDialect}}),Object.defineProperty(t,"arg",{enumerable:!0,get:function(){return s.arg}}),Object.defineProperty(t,"qtz",{enumerable:!0,get:function(){return s.qtz}}),Object.defineProperty(t,"overload",{enumerable:!0,get:function(){return s.overload}}),Object.defineProperty(t,"minScalar",{enumerable:!0,get:function(){return s.minScalar}}),Object.defineProperty(t,"anyExprType",{enumerable:!0,get:function(){return s.anyExprType}}),Object.defineProperty(t,"minAggregate",{enumerable:!0,get:function(){return s.minAggregate}}),Object.defineProperty(t,"maxScalar",{enumerable:!0,get:function(){return s.maxScalar}}),Object.defineProperty(t,"sql",{enumerable:!0,get:function(){return s.sql}}),Object.defineProperty(t,"makeParam",{enumerable:!0,get:function(){return s.makeParam}}),Object.defineProperty(t,"param",{enumerable:!0,get:function(){return s.param}}),Object.defineProperty(t,"variadicParam",{enumerable:!0,get:function(){return s.variadicParam}}),Object.defineProperty(t,"literal",{enumerable:!0,get:function(){return s.literal}}),Object.defineProperty(t,"spread",{enumerable:!0,get:function(){return s.spread}}),Object.defineProperty(t,"Dialect",{enumerable:!0,get:function(){return s.Dialect}}),Object.defineProperty(t,"TinyParser",{enumerable:!0,get:function(){return s.TinyParser}});var o=Gi;Object.defineProperty(t,"isSourceDef",{enumerable:!0,get:function(){return o.isSourceDef}}),Object.defineProperty(t,"Segment",{enumerable:!0,get:function(){return o.Segment}}),Object.defineProperty(t,"isBasicAtomic",{enumerable:!0,get:function(){return o.isBasicAtomic}}),Object.defineProperty(t,"isJoined",{enumerable:!0,get:function(){return o.isJoined}}),Object.defineProperty(t,"isJoinedSource",{enumerable:!0,get:function(){return o.isJoinedSource}}),Object.defineProperty(t,"isSamplingEnable",{enumerable:!0,get:function(){return o.isSamplingEnable}}),Object.defineProperty(t,"isSamplingPercent",{enumerable:!0,get:function(){return o.isSamplingPercent}}),Object.defineProperty(t,"isSamplingRows",{enumerable:!0,get:function(){return o.isSamplingRows}}),Object.defineProperty(t,"isRepeatedRecord",{enumerable:!0,get:function(){return o.isRepeatedRecord}}),Object.defineProperty(t,"isBasicArray",{enumerable:!0,get:function(){return o.isBasicArray}}),Object.defineProperty(t,"mkArrayDef",{enumerable:!0,get:function(){return o.mkArrayDef}}),Object.defineProperty(t,"mkFieldDef",{enumerable:!0,get:function(){return o.mkFieldDef}}),Object.defineProperty(t,"expressionIsAggregate",{enumerable:!0,get:function(){return o.expressionIsAggregate}}),Object.defineProperty(t,"expressionIsAnalytic",{enumerable:!0,get:function(){return o.expressionIsAnalytic}}),Object.defineProperty(t,"expressionIsCalculation",{enumerable:!0,get:function(){return o.expressionIsCalculation}}),Object.defineProperty(t,"expressionIsScalar",{enumerable:!0,get:function(){return o.expressionIsScalar}}),Object.defineProperty(t,"expressionIsUngroupedAggregate",{enumerable:!0,get:function(){return o.expressionIsUngroupedAggregate}}),Object.defineProperty(t,"indent",{enumerable:!0,get:function(){return o.indent}}),Object.defineProperty(t,"composeSQLExpr",{enumerable:!0,get:function(){return o.composeSQLExpr}});var u=M4;Object.defineProperty(t,"malloyToQuery",{enumerable:!0,get:function(){return u.malloyToQuery}}),Object.defineProperty(t,"MalloyTranslator",{enumerable:!0,get:function(){return u.MalloyTranslator}});var a=Ie;Object.defineProperty(t,"Model",{enumerable:!0,get:function(){return a.Model}}),Object.defineProperty(t,"Malloy",{enumerable:!0,get:function(){return a.Malloy}}),Object.defineProperty(t,"Runtime",{enumerable:!0,get:function(){return a.Runtime}}),Object.defineProperty(t,"AtomicFieldType",{enumerable:!0,get:function(){return a.AtomicFieldType}}),Object.defineProperty(t,"ConnectionRuntime",{enumerable:!0,get:function(){return a.ConnectionRuntime}}),Object.defineProperty(t,"SingleConnectionRuntime",{enumerable:!0,get:function(){return a.SingleConnectionRuntime}}),Object.defineProperty(t,"EmptyURLReader",{enumerable:!0,get:function(){return a.EmptyURLReader}}),Object.defineProperty(t,"InMemoryURLReader",{enumerable:!0,get:function(){return a.InMemoryURLReader}}),Object.defineProperty(t,"FixedConnectionMap",{enumerable:!0,get:function(){return a.FixedConnectionMap}}),Object.defineProperty(t,"MalloyError",{enumerable:!0,get:function(){return a.MalloyError}}),Object.defineProperty(t,"JoinRelationship",{enumerable:!0,get:function(){return a.JoinRelationship}}),Object.defineProperty(t,"SourceRelationship",{enumerable:!0,get:function(){return a.SourceRelationship}}),Object.defineProperty(t,"DateTimeframe",{enumerable:!0,get:function(){return a.DateTimeframe}}),Object.defineProperty(t,"TimestampTimeframe",{enumerable:!0,get:function(){return a.TimestampTimeframe}}),Object.defineProperty(t,"PreparedResult",{enumerable:!0,get:function(){return a.PreparedResult}}),Object.defineProperty(t,"Result",{enumerable:!0,get:function(){return a.Result}}),Object.defineProperty(t,"QueryMaterializer",{enumerable:!0,get:function(){return a.QueryMaterializer}}),Object.defineProperty(t,"CSVWriter",{enumerable:!0,get:function(){return a.CSVWriter}}),Object.defineProperty(t,"JSONWriter",{enumerable:!0,get:function(){return a.JSONWriter}}),Object.defineProperty(t,"Parse",{enumerable:!0,get:function(){return a.Parse}}),Object.defineProperty(t,"DataWriter",{enumerable:!0,get:function(){return a.DataWriter}}),Object.defineProperty(t,"Explore",{enumerable:!0,get:function(){return a.Explore}}),Object.defineProperty(t,"InMemoryModelCache",{enumerable:!0,get:function(){return a.InMemoryModelCache}}),Object.defineProperty(t,"CacheManager",{enumerable:!0,get:function(){return a.CacheManager}});var l=OD;Object.defineProperty(t,"toAsyncGenerator",{enumerable:!0,get:function(){return l.toAsyncGenerator}});var c=Va;Object.defineProperty(t,"modelDefToModelInfo",{enumerable:!0,get:function(){return c.modelDefToModelInfo}}),t.API=i(Cde);var f=g0;Object.defineProperty(t,"sqlKey",{enumerable:!0,get:function(){return f.sqlKey}});var x=mi;Object.defineProperty(t,"annotationToTag",{enumerable:!0,get:function(){return x.annotationToTag}}),Object.defineProperty(t,"annotationToTaglines",{enumerable:!0,get:function(){return x.annotationToTaglines}})}(j$);var b2t=St("<div class=malloy-copied-modal>Copied query to clipboard!");const Vde=JD(),wo=()=>{const t=XD(Vde);if(!t)throw new Error("ConfigContext missing a value; did you provide a ConfigProvider?");return t};function T2t(t,{element:e}){const r=cr(()=>{if(t.malloyResult)return t.malloyResult;const c=t.result??(t.queryResult&&t.modelDef?new j$.Result(t.queryResult,t.modelDef):null);return c?j$.API.util.wrapResult(c):null}),i=new CSSStyleSheet;e.renderRoot instanceof ShadowRoot&&e.renderRoot.adoptedStyleSheets.push(i);const s=new Set;function o(c){var x;if(!(e.renderRoot instanceof ShadowRoot)){console.warn("Couldn't add CSS to render element, it is not rendering in a ShadowRoot");return}if(!s.has(c)){const h=[];for(let p=0;p<i.cssRules.length;p++){const m=(x=i.cssRules.item(p))==null?void 0:x.cssText;m&&h.push(m)}h.push(c),i.replaceSync(h.join(`
|
|
1885
|
-
`)),s.add(c)}}function u(c,f){if(!document.getElementById(c)){const x=document.createElement("style");x.id=c,x.textContent=f,document.head.appendChild(x)}}o(aXe);const a=()=>Object.assign({disableVirtualization:!1,rowLimit:1/0,shouldFillWidth:!1,enableDrill:!1},t.tableConfig),l=()=>Object.assign({disableVirtualization:!1},t.dashboardConfig);return Ve(Yr,{get when(){return r()},get children(){return Ve(Vde.Provider,{get value(){return{onClick:t.onClick,onDrill:t.onDrill,vegaConfigOverride:t.vegaConfigOverride,element:e,stylesheet:i,addCSSToShadowRoot:o,addCSSToDocument:u,tableConfig:a,dashboardConfig:l,modalElement:t.modalElement}},get children(){return Ve(
|
|
1882
|
+
`),this.stream.close()}}Ie.JSONWriter=lpt;class cpt extends AP{constructor(){super(...arguments),this.columnSeparator=",",this.rowSeparator=`
|
|
1883
|
+
`,this.quoteCharacter='"',this.includeHeader=!0,this.emptyCell=""}escape(e){const r=e.includes(this.quoteCharacter),i=e.includes(this.columnSeparator),s=e.includes(this.rowSeparator),o=i||r||s;return r&&(e=e.replace(new RegExp(this.quoteCharacter,"g"),this.quoteCharacter+this.quoteCharacter)),o&&(e=this.quoteCharacter+e+this.quoteCharacter),e}stringify(e){return e===null?this.emptyCell:e instanceof Date?e.toISOString():typeof e=="boolean"||typeof e=="number"?JSON.stringify(e):`${e}`}getColWeight(e){let r=e;Array.isArray(e)&&(r=e[0]);let i=0;for(const s in r){i=i+1;const o=r[s];if(Array.isArray(o)){const u=this.getColWeight(o)-1;i=i+u}}return i}getHeaderRow(e){const r=[];let i=0;for(const s in e){r.push(this.escape(s));const o=e[s];if(i++,Array.isArray(o)){const u=this.getColWeight(o)-1;i=i+u;for(let a=0;a<u;a++)r.push(this.emptyCell)}}return{rows:[r.join(this.columnSeparator)],length:1,width:i}}mergeMatrices(e){const r=Math.max(...e.map(o=>o.length)),i=e.reduce((o,u)=>o+u.width,0),s=[];for(let o=0;o<r;o++){const u=[];for(const a of e)if(o<a.length)u.push(a.rows[o]);else{const l=Array(a.width).fill(this.emptyCell);u.push(...l)}s.push(u.join(this.columnSeparator))}return{rows:s,length:r,width:i}}getChildMatrix(e){if(Array.isArray(e)){if(e.length===0)return{rows:[""],length:1,width:1}}else return{rows:["Invalid data found, value is not an array"],length:1,width:1};const r=[],i=this.getHeaderRow(e[0]);r.push(...i.rows);const s=i.width;let o=1;for(const u of e){const a=this.getRowMatrix(u);o=o+a.length,r.push(...a.rows)}return{rows:r,length:o,width:s}}getRowMatrix(e){const r=[];for(const i in e){const s=e[i];if(Array.isArray(s)){const o=this.getChildMatrix(s);r.push(o)}else{const o={rows:[this.stringify(s)],length:1,width:1};r.push(o)}}return this.mergeMatrices(r)}async process(e){let r=!1;for await(const i of e){if(!r&&this.includeHeader){const o=this.getHeaderRow(i.toObject());this.stream.write(o.rows[0]),this.stream.write(this.rowSeparator),r=!0}const s=this.getRowMatrix(i.toObject());for(const o of s.rows)this.stream.write(o),this.stream.write(this.rowSeparator)}this.stream.close()}}Ie.CSVWriter=cpt;class fpt{constructor(e){this.modelCache=e,this.modelDependencies=new Map,this.modelInvalidationKeys=new Map}async getCachedModelDef(e,r){const i=this.modelDependencies.get(r);if(i===void 0)return;const s=[r,...TD(i)],o={};for(const a of s){const l=this.modelInvalidationKeys.get(a);if(l==null)return;o[a]=l}for(const a of s)if(await _P(e,new URL(a))!==o[a])return;const u=await this.modelCache.getModel(new URL(r));if(u!==void 0){for(const a of s)if(u.invalidationKeys[a]!==o[a])return;return{modelDef:u.modelDef,invalidationKeys:o}}}async setCachedModelDef(e,r){this.modelDependencies.set(e,r.modelDef.dependencies);const i={};for(const o of[e,...TD(r.modelDef.dependencies)]){if(r.invalidationKeys[o]===null)return!1;if(r.invalidationKeys[o]===void 0)throw new Error(`Missing invalidation key for dependency ${o}`);this.modelInvalidationKeys.set(o,r.invalidationKeys[o]),i[o]=r.invalidationKeys[o]}return!!await this.modelCache.setModel(new URL(e),{modelDef:r.modelDef,invalidationKeys:i})}}Ie.CacheManager=fpt;function TD(t){return[...Object.keys(t),...Object.values(t).map(TD).flat()]}class xpt{constructor(){this.models=new Map}async getModel(e){return Promise.resolve(this.models.get(e.toString()))}async setModel(e,r){return this.models.set(e.toString(),r),Promise.resolve(!0)}}Ie.InMemoryModelCache=xpt;function vde(t){return(0,npt.v5)(t,"76c17e9d-f3ce-5f2d-bfde-98ad3d2a37f6")}async function RD(t,e){const r=await t.readURL(e),{contents:i,invalidationKey:s}=typeof r=="string"?{contents:r,invalidationKey:void 0}:r;return{contents:i,invalidationKey:DD(e.toString())?null:s??vde(i)}}async function _P(t,e){return DD(e.toString())?null:t.getInvalidationKey!==void 0?await t.getInvalidationKey(e):(await RD(t,e)).invalidationKey}function DD(t){return t.startsWith("internal://")}var OD={};Object.defineProperty(OD,"__esModule",{value:!0}),OD.toAsyncGenerator=void 0;async function*dpt(t){let e=!1;function r(s){let o;const u=new Promise(a=>{o=a});return s(a=>{o({done:!0,isError:!0,error:a})},a=>{o({done:!1,value:a,isError:!1,next:new Promise(l=>{o=l})})},()=>{o({done:!0,isError:!1})}),u}let i=r(t);for(;!e;){const s=await i;if(s.done){if(e=!0,s.isError)throw s.error;break}else i=s.next,yield s.value}}OD.toAsyncGenerator=dpt;var Cde={},hf={},vP={},eA={};Object.defineProperty(eA,"__esModule",{value:!0}),eA.MALLOY_INTERFACE_TYPES=void 0,eA.MALLOY_INTERFACE_TYPES={Aggregate:{type:"struct",name:"Aggregate",fields:{name:{type:"string",optional:!0,array:!1},field:{type:"Field",optional:!1,array:!1}}},Annotation:{type:"struct",name:"Annotation",fields:{value:{type:"string",optional:!1,array:!1}}},AnonymousQueryInfo:{type:"struct",name:"AnonymousQueryInfo",fields:{schema:{type:"Schema",optional:!1,array:!1},annotations:{type:"Annotation",array:!0,optional:!0},definition:{type:"Query",optional:!0,array:!1},code:{type:"string",optional:!0,array:!1},location:{type:"Location",optional:!0,array:!1}}},ArrayCell:{type:"struct",name:"ArrayCell",fields:{array_value:{type:"Cell",array:!0,optional:!1}}},ArrayType:{type:"struct",name:"ArrayType",fields:{element_type:{type:"AtomicType",optional:!1,array:!1}}},AtomicType:{type:"union",name:"AtomicType",options:{string_type:"StringType",boolean_type:"BooleanType",number_type:"NumberType",json_type:"JSONType",sql_native_type:"SQLNativeType",date_type:"DateType",timestamp_type:"TimestampType",array_type:"ArrayType",record_type:"RecordType"}},BooleanCell:{type:"struct",name:"BooleanCell",fields:{boolean_value:{type:"boolean",optional:!1,array:!1}}},BooleanLiteral:{type:"struct",name:"BooleanLiteral",fields:{boolean_value:{type:"boolean",optional:!1,array:!1}}},BooleanType:{type:"struct",name:"BooleanType",fields:{}},Cell:{type:"union",name:"Cell",options:{string_cell:"StringCell",boolean_cell:"BooleanCell",date_cell:"DateCell",timestamp_cell:"TimestampCell",number_cell:"NumberCell",json_cell:"JSONCell",record_cell:"RecordCell",array_cell:"ArrayCell",null_cell:"NullCell",sql_native_cell:"SQLNativeCell"}},CompileModelRequest:{type:"struct",name:"CompileModelRequest",fields:{model_url:{type:"string",optional:!1,array:!1},extend_model_url:{type:"string",optional:!0,array:!1},compiler_needs:{type:"CompilerNeeds",optional:!0,array:!1}}},CompileModelResponse:{type:"struct",name:"CompileModelResponse",fields:{model:{type:"ModelInfo",optional:!0,array:!1},logs:{type:"LogMessage",array:!0,optional:!0},compiler_needs:{type:"CompilerNeeds",optional:!0,array:!1},translations:{type:"Translation",array:!0,optional:!0}}},CompileQueryRequest:{type:"struct",name:"CompileQueryRequest",fields:{model_url:{type:"string",optional:!1,array:!1},query:{type:"Query",optional:!1,array:!1},default_row_limit:{type:"number",optional:!0,array:!1},compiler_needs:{type:"CompilerNeeds",optional:!0,array:!1}}},CompileQueryResponse:{type:"struct",name:"CompileQueryResponse",fields:{result:{type:"Result",optional:!0,array:!1},default_row_limit_added:{type:"number",optional:!0,array:!1},logs:{type:"LogMessage",array:!0,optional:!0},compiler_needs:{type:"CompilerNeeds",optional:!0,array:!1},translations:{type:"Translation",array:!0,optional:!0}}},CompileSourceRequest:{type:"struct",name:"CompileSourceRequest",fields:{model_url:{type:"string",optional:!1,array:!1},name:{type:"string",optional:!1,array:!1},extend_model_url:{type:"string",optional:!0,array:!1},compiler_needs:{type:"CompilerNeeds",optional:!0,array:!1}}},CompileSourceResponse:{type:"struct",name:"CompileSourceResponse",fields:{source:{type:"SourceInfo",optional:!0,array:!1},logs:{type:"LogMessage",array:!0,optional:!0},compiler_needs:{type:"CompilerNeeds",optional:!0,array:!1}}},CompilerNeeds:{type:"struct",name:"CompilerNeeds",fields:{table_schemas:{type:"SQLTable",array:!0,optional:!0},sql_schemas:{type:"SQLQuery",array:!0,optional:!0},files:{type:"File",array:!0,optional:!0},connections:{type:"Connection",array:!0,optional:!0},translations:{type:"Translation",array:!0,optional:!0}}},Connection:{type:"struct",name:"Connection",fields:{name:{type:"string",optional:!1,array:!1},dialect:{type:"string",optional:!0,array:!1}}},Data:{type:"union",name:"Data",options:{record_cell:"RecordCell",array_cell:"ArrayCell"}},DateCell:{type:"struct",name:"DateCell",fields:{date_value:{type:"string",optional:!1,array:!1}}},DateLiteral:{type:"struct",name:"DateLiteral",fields:{date_value:{type:"string",optional:!1,array:!1},granularity:{type:"DateTimeframe",optional:!0,array:!1}}},DateTimeframe:{type:"enum",name:"DateTimeframe",values:{year:1,quarter:2,month:3,week:4,day:5}},DateType:{type:"struct",name:"DateType",fields:{timeframe:{type:"DateTimeframe",optional:!0,array:!1}}},DimensionInfo:{type:"struct",name:"DimensionInfo",fields:{name:{type:"string",optional:!1,array:!1},type:{type:"AtomicType",optional:!1,array:!1},annotations:{type:"Annotation",array:!0,optional:!0}}},DocumentPosition:{type:"struct",name:"DocumentPosition",fields:{line:{type:"number",optional:!1,array:!1},character:{type:"number",optional:!1,array:!1}}},DocumentRange:{type:"struct",name:"DocumentRange",fields:{start:{type:"DocumentPosition",optional:!1,array:!1},end:{type:"DocumentPosition",optional:!1,array:!1}}},Expression:{type:"union",name:"Expression",options:{field_reference:"Reference",time_truncation:"TimeTruncationFieldReference",filtered_field:"FilteredField"}},Field:{type:"struct",name:"Field",fields:{expression:{type:"Expression",optional:!1,array:!1},annotations:{type:"Annotation",array:!0,optional:!0}}},FieldInfo:{type:"union",name:"FieldInfo",options:{dimension:"DimensionInfo",measure:"MeasureInfo",join:"JoinInfo",view:"ViewInfo"}},File:{type:"struct",name:"File",fields:{url:{type:"string",optional:!1,array:!1},contents:{type:"string",optional:!0,array:!1},invalidation_key:{type:"string",optional:!0,array:!1}}},Filter:{type:"union",name:"Filter",options:{filter_string:"FilterStringApplication"}},FilterExpressionLiteral:{type:"struct",name:"FilterExpressionLiteral",fields:{filter_expression_value:{type:"string",optional:!1,array:!1}}},FilterExpressionType:{type:"struct",name:"FilterExpressionType",fields:{}},FilterOperation:{type:"struct",name:"FilterOperation",fields:{filter:{type:"Filter",optional:!1,array:!1}}},FilterStringApplication:{type:"struct",name:"FilterStringApplication",fields:{field_reference:{type:"Reference",optional:!1,array:!1},filter:{type:"string",optional:!1,array:!1}}},FilteredField:{type:"struct",name:"FilteredField",fields:{field_reference:{type:"Reference",optional:!1,array:!1},where:{type:"FilterOperation",array:!0,optional:!1}}},GroupBy:{type:"struct",name:"GroupBy",fields:{name:{type:"string",optional:!0,array:!1},field:{type:"Field",optional:!1,array:!1}}},JSONCell:{type:"struct",name:"JSONCell",fields:{json_value:{type:"string",optional:!1,array:!1}}},JSONType:{type:"struct",name:"JSONType",fields:{}},JoinInfo:{type:"struct",name:"JoinInfo",fields:{name:{type:"string",optional:!1,array:!1},schema:{type:"Schema",optional:!1,array:!1},annotations:{type:"Annotation",array:!0,optional:!0},relationship:{type:"Relationship",optional:!1,array:!1}}},Limit:{type:"struct",name:"Limit",fields:{limit:{type:"number",optional:!1,array:!1}}},LiteralValue:{type:"union",name:"LiteralValue",options:{string_literal:"StringLiteral",number_literal:"NumberLiteral",date_literal:"DateLiteral",timestamp_literal:"TimestampLiteral",boolean_literal:"BooleanLiteral",null_literal:"NullLiteral",filter_expression_literal:"FilterExpressionLiteral"}},Location:{type:"struct",name:"Location",fields:{url:{type:"string",optional:!1,array:!1},range:{type:"Range",optional:!1,array:!1}}},LogMessage:{type:"struct",name:"LogMessage",fields:{url:{type:"string",optional:!1,array:!1},range:{type:"DocumentRange",optional:!1,array:!1},severity:{type:"LogSeverity",optional:!1,array:!1},message:{type:"string",optional:!1,array:!1}}},LogSeverity:{type:"enum",name:"LogSeverity",values:{debug:1,info:2,warn:3,error:4}},MeasureInfo:{type:"struct",name:"MeasureInfo",fields:{name:{type:"string",optional:!1,array:!1},type:{type:"AtomicType",optional:!1,array:!1},annotations:{type:"Annotation",array:!0,optional:!0}}},ModelEntryValue:{type:"union",name:"ModelEntryValue",options:{source:"SourceInfo",query:"QueryInfo"}},ModelInfo:{type:"struct",name:"ModelInfo",fields:{entries:{type:"ModelEntryValue",array:!0,optional:!1},annotations:{type:"Annotation",array:!0,optional:!0},anonymous_queries:{type:"AnonymousQueryInfo",array:!0,optional:!1}}},Nest:{type:"struct",name:"Nest",fields:{name:{type:"string",optional:!0,array:!1},view:{type:"View",optional:!1,array:!1}}},NullCell:{type:"struct",name:"NullCell",fields:{}},NullLiteral:{type:"struct",name:"NullLiteral",fields:{}},NumberCell:{type:"struct",name:"NumberCell",fields:{number_value:{type:"number",optional:!1,array:!1}}},NumberLiteral:{type:"struct",name:"NumberLiteral",fields:{number_value:{type:"number",optional:!1,array:!1}}},NumberSubtype:{type:"enum",name:"NumberSubtype",values:{integer:1,decimal:2}},NumberType:{type:"struct",name:"NumberType",fields:{subtype:{type:"NumberSubtype",optional:!0,array:!1}}},OrderBy:{type:"struct",name:"OrderBy",fields:{field_reference:{type:"Reference",optional:!1,array:!1},direction:{type:"OrderByDirection",optional:!0,array:!1}}},OrderByDirection:{type:"enum",name:"OrderByDirection",values:{asc:1,desc:2}},ParameterInfo:{type:"struct",name:"ParameterInfo",fields:{name:{type:"string",optional:!1,array:!1},type:{type:"ParameterType",optional:!1,array:!1},default_value:{type:"LiteralValue",optional:!0,array:!1}}},ParameterType:{type:"union",name:"ParameterType",options:{string_type:"StringType",boolean_type:"BooleanType",number_type:"NumberType",json_type:"JSONType",sql_native_type:"SQLNativeType",date_type:"DateType",timestamp_type:"TimestampType",array_type:"ArrayType",record_type:"RecordType",filter_expression_type:"FilterExpressionType"}},ParameterValue:{type:"struct",name:"ParameterValue",fields:{name:{type:"string",optional:!1,array:!1},value:{type:"LiteralValue",optional:!1,array:!1}}},Position:{type:"struct",name:"Position",fields:{line:{type:"number",optional:!1,array:!1},character:{type:"number",optional:!1,array:!1}}},Query:{type:"struct",name:"Query",fields:{definition:{type:"QueryDefinition",optional:!1,array:!1},annotations:{type:"Annotation",array:!0,optional:!0}}},QueryArrow:{type:"struct",name:"QueryArrow",fields:{source:{type:"QueryArrowSource",optional:!1,array:!1},view:{type:"ViewDefinition",optional:!1,array:!1}}},QueryArrowSource:{type:"union",name:"QueryArrowSource",options:{refinement:"QueryRefinement",source_reference:"Reference"}},QueryDefinition:{type:"union",name:"QueryDefinition",options:{arrow:"QueryArrow",query_reference:"Reference",refinement:"QueryRefinement"}},QueryInfo:{type:"struct",name:"QueryInfo",fields:{name:{type:"string",optional:!1,array:!1},schema:{type:"Schema",optional:!1,array:!1},annotations:{type:"Annotation",array:!0,optional:!0},definition:{type:"Query",optional:!0,array:!1},code:{type:"string",optional:!0,array:!1},location:{type:"Location",optional:!0,array:!1}}},QueryRefinement:{type:"struct",name:"QueryRefinement",fields:{base:{type:"QueryDefinition",optional:!1,array:!1},refinement:{type:"ViewDefinition",optional:!1,array:!1}}},Range:{type:"struct",name:"Range",fields:{start:{type:"Position",optional:!1,array:!1},end:{type:"Position",optional:!1,array:!1}}},RecordCell:{type:"struct",name:"RecordCell",fields:{record_value:{type:"Cell",array:!0,optional:!1}}},RecordType:{type:"struct",name:"RecordType",fields:{fields:{type:"DimensionInfo",array:!0,optional:!1}}},Reference:{type:"struct",name:"Reference",fields:{name:{type:"string",optional:!1,array:!1},path:{type:"string",array:!0,optional:!0},parameters:{type:"ParameterValue",array:!0,optional:!0}}},Relationship:{type:"enum",name:"Relationship",values:{one:1,many:2,cross:3}},Result:{type:"struct",name:"Result",fields:{data:{type:"Data",optional:!0,array:!1},schema:{type:"Schema",optional:!1,array:!1},sql:{type:"string",optional:!0,array:!1},connection_name:{type:"string",optional:!1,array:!1},annotations:{type:"Annotation",array:!0,optional:!0},model_annotations:{type:"Annotation",array:!0,optional:!0},query_timezone:{type:"string",optional:!0,array:!1}}},RunIndexQueryRequest:{type:"struct",name:"RunIndexQueryRequest",fields:{model_url:{type:"string",optional:!1,array:!1},source_name:{type:"string",optional:!1,array:!1},compiler_needs:{type:"CompilerNeeds",optional:!0,array:!1}}},RunIndexQueryResponse:{type:"struct",name:"RunIndexQueryResponse",fields:{result:{type:"Result",optional:!0,array:!1},compiler_needs:{type:"CompilerNeeds",optional:!0,array:!1}}},RunQueryRequest:{type:"struct",name:"RunQueryRequest",fields:{model_url:{type:"string",optional:!1,array:!1},query:{type:"Query",optional:!1,array:!1},default_row_limit:{type:"number",optional:!0,array:!1},compiler_needs:{type:"CompilerNeeds",optional:!0,array:!1}}},RunQueryResponse:{type:"struct",name:"RunQueryResponse",fields:{result:{type:"Result",optional:!0,array:!1},default_row_limit_added:{type:"number",optional:!0,array:!1},logs:{type:"LogMessage",array:!0,optional:!0},compiler_needs:{type:"CompilerNeeds",optional:!0,array:!1}}},SQLNativeCell:{type:"struct",name:"SQLNativeCell",fields:{sql_native_value:{type:"string",optional:!1,array:!1}}},SQLNativeType:{type:"struct",name:"SQLNativeType",fields:{sql_type:{type:"string",optional:!0,array:!1}}},SQLQuery:{type:"struct",name:"SQLQuery",fields:{sql:{type:"string",optional:!1,array:!1},schema:{type:"Schema",optional:!0,array:!1},connection_name:{type:"string",optional:!1,array:!1}}},SQLTable:{type:"struct",name:"SQLTable",fields:{name:{type:"string",optional:!1,array:!1},schema:{type:"Schema",optional:!0,array:!1},connection_name:{type:"string",optional:!1,array:!1}}},Schema:{type:"struct",name:"Schema",fields:{fields:{type:"FieldInfo",array:!0,optional:!1}}},SourceInfo:{type:"struct",name:"SourceInfo",fields:{name:{type:"string",optional:!1,array:!1},schema:{type:"Schema",optional:!1,array:!1},annotations:{type:"Annotation",array:!0,optional:!0},parameters:{type:"ParameterInfo",array:!0,optional:!0}}},StringCell:{type:"struct",name:"StringCell",fields:{string_value:{type:"string",optional:!1,array:!1}}},StringLiteral:{type:"struct",name:"StringLiteral",fields:{string_value:{type:"string",optional:!1,array:!1}}},StringType:{type:"struct",name:"StringType",fields:{}},TimeTruncationFieldReference:{type:"struct",name:"TimeTruncationFieldReference",fields:{field_reference:{type:"Reference",optional:!1,array:!1},truncation:{type:"TimestampTimeframe",optional:!1,array:!1}}},TimestampCell:{type:"struct",name:"TimestampCell",fields:{timestamp_value:{type:"string",optional:!1,array:!1}}},TimestampLiteral:{type:"struct",name:"TimestampLiteral",fields:{timestamp_value:{type:"string",optional:!1,array:!1},granularity:{type:"TimestampTimeframe",optional:!0,array:!1}}},TimestampTimeframe:{type:"enum",name:"TimestampTimeframe",values:{year:1,quarter:2,month:3,week:4,day:5,hour:6,minute:7,second:8}},TimestampType:{type:"struct",name:"TimestampType",fields:{timeframe:{type:"TimestampTimeframe",optional:!0,array:!1}}},Translation:{type:"struct",name:"Translation",fields:{url:{type:"string",optional:!1,array:!1},compiled_model_json:{type:"string",optional:!0,array:!1}}},View:{type:"struct",name:"View",fields:{definition:{type:"ViewDefinition",optional:!1,array:!1},annotations:{type:"Annotation",array:!0,optional:!0}}},ViewArrow:{type:"struct",name:"ViewArrow",fields:{source:{type:"ViewDefinition",optional:!1,array:!1},view:{type:"ViewDefinition",optional:!1,array:!1}}},ViewDefinition:{type:"union",name:"ViewDefinition",options:{arrow:"ViewArrow",view_reference:"Reference",refinement:"ViewRefinement",segment:"ViewSegment"}},ViewInfo:{type:"struct",name:"ViewInfo",fields:{name:{type:"string",optional:!1,array:!1},schema:{type:"Schema",optional:!1,array:!1},annotations:{type:"Annotation",array:!0,optional:!0},definition:{type:"View",optional:!0,array:!1}}},ViewOperation:{type:"union",name:"ViewOperation",options:{group_by:"GroupBy",aggregate:"Aggregate",order_by:"OrderBy",limit:"Limit",where:"FilterOperation",nest:"Nest",having:"FilterOperation"}},ViewRefinement:{type:"struct",name:"ViewRefinement",fields:{base:{type:"ViewDefinition",optional:!1,array:!1},refinement:{type:"ViewDefinition",optional:!1,array:!1}}},ViewSegment:{type:"struct",name:"ViewSegment",fields:{operations:{type:"ViewOperation",array:!0,optional:!1}}}};var FD={},wD={},ND={};Object.defineProperty(ND,"__esModule",{value:!0}),ND.RESERVED_WORDS=void 0,ND.RESERVED_WORDS=["accept","aggregate","declare","dimension","except","explore","group_by","having","index","join_cross","join_one","join_many","limit","measure","nest","order_by","primary_key","project","query","rename","sample","source","sql","turduck","top","where","all","as","asc","avg","boolean","by","case","cast","condition","count","date","day","days","desc","distinct","else","end","exclude","false","for","from","from_sql","has","hour","hours","import","is","json","last","max","min","minute","minutes","month","months","not","now","null","number","on","or","pick","quarter","quarters","second","seconds","string","sum","table","then","this","timestamp","to","true","turtle","week","weeks","when","with","year","years","ungrouped"],Object.defineProperty(wD,"__esModule",{value:!0}),wD.maybeQuoteIdentifier=void 0;const hpt=ND;function ppt(t){const e=!t.match(/^[A-Za-z_][A-Za-z_0-9]*$/),r=hpt.RESERVED_WORDS.includes(t.toLowerCase());return e||r}function mpt(t){const e=t.split(".");for(let r=0;r<e.length;r++)ppt(e[r])&&(e[r]=`\`${e[r]}\``);return e.join(".")}wD.maybeQuoteIdentifier=mpt,Object.defineProperty(FD,"__esModule",{value:!0}),FD.queryToMalloy=void 0;const tA=wD;function gpt(t,{tabWidth:e}={tabWidth:2}){const r=vpt(t);return Ept(r,{tabWidth:e})}FD.queryToMalloy=gpt;const CP=Symbol("indent"),Fu=Symbol("newline"),SP=Symbol("outdent"),ypt=Symbol("optional_newline_indent");function Ept(t,{tabWidth:e}={tabWidth:2}){let r="",i=0,s=!0;for(const o of t)if(o===Fu)r+=`
|
|
1884
|
+
`,s=!0;else if(o===SP)i--;else if(o===CP)i++;else{if(o===ypt)continue;s&&(r+=" ".repeat(i*e),s=!1),r+=o}return r}function LD(t,e,r,i){var s;if(e.includes(Fu))return[t,Fu,CP,...e,Fu,SP,r];const u=((s=i==null?void 0:i.spaces)!==null&&s!==void 0?s:!0)?" ":"";return[t,u,...e,u,r]}function Apt(t){return{contents:t,quoteCharacter:'"'}}function _pt(t){var e,r;switch(t.kind){case"filter_expression_literal":return[Dde(t.filter_expression_value)];case"boolean_literal":return[t.boolean_value.toString()];case"string_literal":{const{contents:i,quoteCharacter:s}=Apt(t.string_value);return[s,i,s]}case"number_literal":return[t.number_value.toString()];case"null_literal":return["null"];case"date_literal":return[bde(Sde(t.date_value),(e=t.granularity)!==null&&e!==void 0?e:"day")];case"timestamp_literal":return[bde(Sde(t.timestamp_value),(r=t.granularity)!==null&&r!==void 0?r:"second")]}}function Sde(t){return new Date(t)}function An(t,e){return t.toString().padStart(e,"0")}function bde(t,e){switch(e){case"year":return`@${An(t.getUTCFullYear(),4)}`;case"quarter":{const r=An(t.getUTCFullYear(),4),i=Math.floor(t.getUTCMonth()/3)+1;return`@${r}-Q${i}`}case"month":{const r=An(t.getUTCFullYear(),2),i=An(t.getUTCMonth()+1,2);return`@${r}-${i}`}case"week":{const r=An(t.getUTCFullYear(),2),i=An(t.getUTCMonth()+1,2),s=An(t.getUTCDate(),2);return`@WK${r}-${i}-${s}`}case"day":{const r=An(t.getUTCFullYear(),2),i=An(t.getUTCMonth()+1,2),s=An(t.getUTCDate(),2);return`@${r}-${i}-${s}`}case"hour":{const r=An(t.getUTCFullYear(),2),i=An(t.getUTCMonth()+1,2),s=An(t.getUTCDate(),2),o=An(t.getUTCHours(),2);return`@${r}-${i}-${s} ${o}`}case"minute":{const r=An(t.getUTCFullYear(),2),i=An(t.getUTCMonth()+1,2),s=An(t.getUTCDate(),2),o=An(t.getUTCHours(),2),u=An(t.getUTCMinutes(),2);return`@${r}-${i}-${s} ${o}:${u}`}case"second":{const r=An(t.getUTCFullYear(),2),i=An(t.getUTCMonth()+1,2),s=An(t.getUTCDate(),2),o=An(t.getUTCHours(),2),u=An(t.getUTCMinutes(),2),a=An(t.getUTCSeconds(),2);return`@${r}-${i}-${s} ${o}:${u}:${a}`}default:throw new Error("Unknown timeframe.")}}function pf(t){var e;const r=[];for(const i of(e=t.path)!==null&&e!==void 0?e:[])r.push((0,tA.maybeQuoteIdentifier)(i)),r.push(".");if(r.push((0,tA.maybeQuoteIdentifier)(t.name)),t.parameters){const i=[];for(let s=0;s<t.parameters.length;s++){const o=t.parameters[s];i.push((0,tA.maybeQuoteIdentifier)(o.name)),i.push(" is "),i.push(..._pt(o.value)),s<t.parameters.length-1&&i.push(",",Fu)}r.push(...LD("(",i,")",{spaces:!1}))}return r}function vpt(t){const e=[];return e.push(...f1(t.annotations)),e.push("run: "),e.push(...bP(t.definition)),e}function Cpt(t){const e=[];switch(t.kind){case"source_reference":{e.push(...pf(t));break}case"refinement":e.push(...bP(t));break}return e}function bP(t){const e=[];switch(t.kind){case"arrow":{e.push(...Cpt(t.source)),e.push(" -> "),e.push(...kd(t.view));break}case"query_reference":{e.push(...pf(t));break}case"refinement":{const r=bP(t.base);t.base.kind==="arrow"?e.push(...LD("(",r,")",{spaces:!1})):e.push(...r),e.push(" + "),e.push(...kd(t.refinement));break}}return e}function kd(t){const e=[];switch(t.kind){case"arrow":{e.push(...kd(t.source)),e.push(" -> "),e.push(...kd(t.view));break}case"view_reference":{e.push(...pf(t));break}case"refinement":{e.push(...kd(t.base)),e.push(" + "),e.push(...kd(t.refinement));break}case"segment":{e.push(...Spt(t));break}}return e}function Spt(t){if(t.operations.length===0)return["{ }"];const e=t.operations.length>1,r=[];for(let i=0;i<t.operations.length;i++){const s=t.operations[i],o=[s];for(;i<t.operations.length-1;){const u=t.operations[i+1];if(u.kind===s.kind)o.push(u),i++;else break}r.push(...bpt(o)),e&&i<t.operations.length-1&&r.push(Fu)}return LD("{",r,"}")}function bpt(t){switch(t[0].kind){case"aggregate":return Opt(t);case"group_by":return Dpt(t);case"order_by":return Fpt(t);case"nest":return Npt(t);case"limit":return Bpt(t);case"where":return Rde(t);case"having":return kpt(t)}}function c1(t,e,r=""){const i=[];i.push(`${t}:`);const s=e.length>1||e.some(o=>o.includes(Fu));s?i.push(Fu,CP):i.push(" ");for(let o=0;o<e.length;o++){const u=e[o];i.push(...u),e.length>1&&o<e.length-1&&i.push(r),s&&o<e.length-1&&i.push(Fu)}return s&&i.push(SP),i}function Tpt(t){const e=[];return e.push(...Rpt(t.expression)),e}function f1t(t){return t}function Rpt(t){switch(t.kind){case"field_reference":return pf(t);case"time_truncation":return[...pf(t.field_reference),".",t.truncation];case"filtered_field":return[...pf(t.field_reference),...LD(" {",Rde(t.where),"}")]}}function Tde(t,e=!1){const r=[];return e||r.push(...f1(t.field.annotations)),t.name&&(r.push((0,tA.maybeQuoteIdentifier)(t.name)),r.push(" is ")),r.push(...Tpt(t.field)),r}function Dpt(t){const e=[],r=t.length===1;return r&&e.push(...f1(t[0].field.annotations)),e.push(...c1("group_by",t.map(i=>Tde(i,r)))),e}function Opt(t){const e=[],r=t.length===1;return r&&e.push(...f1(t[0].field.annotations)),e.push(...c1("aggregate",t.map(i=>Tde(i,r)))),e}function Fpt(t){return c1("order_by",t.map(wpt),",")}function wpt(t){const e=[];return e.push(...pf(t.field_reference)),t.direction&&(e.push(" "),e.push(t.direction)),e}function Npt(t){const e=[],r=t.length===1;return r&&e.push(...f1(t[0].view.annotations)),e.push(...c1("nest",t.map(i=>Lpt(i,r)))),e}function Lpt(t,e=!1){const r=[];return e||r.push(...f1(t.view.annotations)),t.name&&(r.push((0,tA.maybeQuoteIdentifier)(t.name)),r.push(" is ")),r.push(...Ipt(t.view)),r}function Ipt(t){return kd(t.definition)}function $pt(t){return[`limit: ${t.limit}`]}function Bpt(t){const e=[];for(let r=0;r<t.length;r++)r!==0&&e.push(Fu),e.push(...$pt(t[r]));return e}function Rde(t){return c1("where",t.map(Ode),",")}function kpt(t){return c1("having",t.map(Ode),",")}const Mpt=["`","'",'"'];function Dde(t){let e,r;for(const i of Mpt){const s=Ppt(t,i);if(s===t)return`f${i}${t}${i}`;(r===void 0||s.length<r.length)&&(e=i,r=s)}return`f${e}${r}${e}`}function Ppt(t,e){let r="";for(let i=0;i<t.length;i++)t.slice(i).startsWith(e)?(r+="\\"+e,i+=e.length):(r+=t[i],t[i]==="\\"&&(r+=t[++i]));return r}function Ode(t){switch(t.filter.kind){case"filter_string":return[...pf(t.filter.field_reference)," ~ ",Dde(t.filter.filter)]}}function f1(t){return t?t.flatMap(Upt):[]}function Upt(t){return[t.value.trim(),Fu]}var Za={};Object.defineProperty(Za,"__esModule",{value:!0}),Za.convertToThrift=Za.convertFromThrift=Za.unnestUnions=Za.nestUnions=void 0;const jpt=eA;function TP(t){if(t==null)return t;if(typeof t=="string"||typeof t=="number"||typeof t=="boolean")return t;if(Array.isArray(t))return t.map(TP);{const e={};let r;for(const i in t)i==="kind"?r=t[i]:e[i]=TP(t[i]);return r===void 0?e:{[r]:e}}}Za.nestUnions=TP;function ID(t,e){if(t==null)return t;if(typeof t=="string"||typeof t=="number"||typeof t=="boolean")return t;if(Array.isArray(t))return t.map(r=>ID(r,e));{const r=x1(e);if(r.type==="union"){for(const i in r.options)if(t[i]!==void 0){const s=ID(t[i],r.options[i]);if(typeof s=="object")return{kind:i,...s}}}else if(r.type==="struct"){const i={};for(const s in t){const o=r.fields[s];if(o===void 0)throw new Error(`Unknown field ${s} in ${e}`);i[s]=ID(t[s],o.type)}return i}else throw new Error(`Cannot unnest unions in an enum type ${e}`)}}Za.unnestUnions=ID;function $D(t,e){if(t==null)return t;if(typeof t=="string"||typeof t=="boolean")return t;if(typeof t=="number"){if(e==="number")return t;const r=x1(e);if(r.type!=="enum")throw new Error(`Found a number where a ${e} was expected`);const i=Object.entries(r.values).find(([,s])=>s===t);if(i===void 0)throw new Error(`${t} is not a valid enum value for ${e}`);return i[0]}else{if(Array.isArray(t))return t.map(r=>$D(r,e));{const r=x1(e);if(r.type==="union"){for(const i in r.options)if(t[i]!==void 0){const s=$D(t[i],r.options[i]);if(typeof s=="object")return{kind:i,...s}}}else if(r.type==="struct"){const i={};for(const s in t){const o=r.fields[s];if(o===void 0)throw new Error(`Unknown field ${s} in ${e}`);i[s]=$D(t[s],o.type)}return i}else throw new Error(`Cannot unnest unions in an enum type ${e}`)}}}Za.convertFromThrift=$D;function x1(t){const e=jpt.MALLOY_INTERFACE_TYPES[t];if(e===void 0)throw new Error(`Unknown Malloy interface type ${t}`);return e}function BD(t,e){if(t==null)return t;if(typeof t=="number"||typeof t=="boolean")return t;if(typeof t=="string"){if(e==="string")return t;const r=x1(e);if(r.type==="enum"){const i=r.values[t];if(i===void 0)throw new Error(`${t} is not a valid enum value for ${e}`);return i}}else{if(Array.isArray(t))return t.map(r=>BD(r,e));{const r=x1(e);if(r.type==="union"){const i=t.kind,s=r.options[i];if(s===void 0)throw new Error(`${i} is not a valid union of ${e}`);const o=x1(s);if(o.type!=="struct")throw new Error("Union fields must be structs");const u={};for(const a in t){if(a==="kind")continue;const l=o.fields[a];u[a]=BD(t[a],l.type)}return{[i]:u}}else if(r.type==="struct"){const i={};for(const s in t){const o=r.fields[s];if(o===void 0)throw new Error(`Unknown field ${s} in ${e}`);i[s]=BD(t[s],o.type)}return i}}}}Za.convertToThrift=BD,function(t){var e=T&&T.__createBinding||(Object.create?function(o,u,a,l){l===void 0&&(l=a);var c=Object.getOwnPropertyDescriptor(u,a);(!c||("get"in c?!u.__esModule:c.writable||c.configurable))&&(c={enumerable:!0,get:function(){return u[a]}}),Object.defineProperty(o,l,c)}:function(o,u,a,l){l===void 0&&(l=a),o[l]=u[a]}),r=T&&T.__exportStar||function(o,u){for(var a in o)a!=="default"&&!Object.prototype.hasOwnProperty.call(u,a)&&e(u,o,a)};Object.defineProperty(t,"__esModule",{value:!0}),t.thingy4sddfdfsd=t.thingy4sdfsd=t.thingy4dfdsfs=t.thingy4asdfas=t.thingy4asdfasdf=t.thingy3dfdf=t.thingy3=t.thingy2asdf=t.thingyssdfg=t.thingy123r=t.thingy1=t.res=t.test=t.convertToThrift=t.convertFromThrift=t.unnestUnions=t.nestUnions=t.queryToMalloy=void 0,r(eA,t);var i=FD;Object.defineProperty(t,"queryToMalloy",{enumerable:!0,get:function(){return i.queryToMalloy}});var s=Za;Object.defineProperty(t,"nestUnions",{enumerable:!0,get:function(){return s.nestUnions}}),Object.defineProperty(t,"unnestUnions",{enumerable:!0,get:function(){return s.unnestUnions}}),Object.defineProperty(t,"convertFromThrift",{enumerable:!0,get:function(){return s.convertFromThrift}}),Object.defineProperty(t,"convertToThrift",{enumerable:!0,get:function(){return s.convertToThrift}}),t.test={entries:[{kind:"source",name:"flights",schema:{fields:[{kind:"dimension",name:"carrier",type:{kind:"boolean_type"},annotations:[{value:"# foo=1"}]},{kind:"dimension",name:"arr",type:{kind:"array_type",element_type:{kind:"boolean_type"}}},{kind:"dimension",name:"arr_rec",type:{kind:"array_type",element_type:{kind:"record_type",fields:[{name:"arr",type:{kind:"array_type",element_type:{kind:"boolean_type"}}}]}}},{kind:"dimension",name:"rec",type:{kind:"record_type",fields:[{name:"arr",type:{kind:"array_type",element_type:{kind:"boolean_type"}}}]}},{kind:"join",name:"carriers",relationship:"one",schema:{fields:[{kind:"dimension",name:"code",type:{kind:"string_type"}}]}},{kind:"view",name:"by_carrier",schema:{fields:[{kind:"dimension",name:"carrier",type:{kind:"string_type"}},{kind:"dimension",name:"flight_count",type:{kind:"number_type"}}]}}]},parameters:[{name:"param",type:{kind:"number_type"},default_value:{kind:"number_literal",number_value:7}}]}],anonymous_queries:[]},t.res={connection_name:"foo",data:{kind:"array_cell",array_value:[{kind:"record_cell",record_value:[{kind:"string_cell",string_value:"UA"},{kind:"number_cell",number_value:12341234}]},{kind:"record_cell",record_value:[{kind:"string_cell",string_value:"AA"},{kind:"number_cell",number_value:2343}]}]},schema:{fields:[{kind:"dimension",name:"carrier",type:{kind:"string_type"}},{kind:"dimension",name:"flight_count",type:{kind:"number_type"}}]},sql:"SELECT * ..."},t.thingy1={definition:{kind:"query_reference",name:"flights_by_carrier"}},t.thingy123r={definition:{kind:"arrow",source:{kind:"source_reference",name:"flights"},view:{kind:"view_reference",name:"by_carrier"}}},t.thingyssdfg={definition:{kind:"refinement",base:{kind:"query_reference",name:"flights"},refinement:{kind:"view_reference",name:"by_carrier"}}},t.thingy2asdf={definition:{kind:"arrow",source:{kind:"source_reference",name:"flights"},view:{kind:"refinement",base:{kind:"view_reference",name:"by_carrier"},refinement:{kind:"segment",operations:[{kind:"where",filter:{kind:"filter_string",field_reference:{name:"carrier"},filter:"WN"}}]}}}},t.thingy3={definition:{kind:"arrow",source:{kind:"source_reference",name:"flights"},view:{kind:"refinement",base:{kind:"view_reference",name:"by_carrier"},refinement:{kind:"segment",operations:[{kind:"group_by",field:{expression:{kind:"field_reference",name:"carrier"}}},{kind:"group_by",field:{expression:{kind:"field_reference",name:"foo"}}}]}}}},t.thingy3dfdf={definition:{kind:"arrow",source:{kind:"source_reference",name:"flights"},view:{kind:"refinement",base:{kind:"view_reference",name:"by_carrier"},refinement:{kind:"view_reference",name:"top10"}}}},t.thingy4asdfasdf={definition:{kind:"arrow",source:{kind:"source_reference",name:"flights"},view:{kind:"segment",operations:[{kind:"group_by",field:{expression:{kind:"field_reference",name:"carrier"}}},{kind:"group_by",field:{expression:{kind:"field_reference",name:"foo"}}}]}}},t.thingy4asdfas={definition:{kind:"arrow",source:{kind:"source_reference",name:"flights"},view:{kind:"view_reference",name:"by_carrier"}}},t.thingy4dfdsfs={definition:{kind:"arrow",source:{kind:"source_reference",name:"flights"},view:{kind:"refinement",base:{kind:"view_reference",name:"by_carrier"},refinement:{kind:"segment",operations:[{kind:"limit",limit:10}]}}}},t.thingy4sdfsd={definition:{kind:"arrow",source:{kind:"source_reference",name:"flights"},view:{kind:"segment",operations:[{kind:"group_by",field:{expression:{kind:"field_reference",name:"carrier"}}},{kind:"limit",limit:10}]}}},t.thingy4sddfdfsd={definition:{kind:"arrow",source:{kind:"source_reference",name:"flights"},view:{kind:"segment",operations:[]}}}}(vP);var on={},qpt=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),Hpt=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),Qpt=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&qpt(e,t,r);return Hpt(e,t),e};Object.defineProperty(on,"__esModule",{value:!0}),on.statedCompileQuery=on.newCompileQueryState=on.hasErrors=on.compileSource=on.compileModel=on._statedCompileModel=on.statedCompileSource=on.statedCompileModel=on.newCompileSourceState=on.newCompileModelState=on.updateCompileModelState=on.compileQuery=void 0;const zpt=Qpt(vP),Wpt=M4,Fde=Gi,Gpt=Va,wde=g0,Vpt=mi,Nde=$o,Md=VE;function Lde(t,e){return`${t}:${e}`}function Ypt(t,e){return{type:"sql_select",selectStr:t.sql,connection:t.connection_name,dialect:e,fields:t.schema?$de(t.schema):[],name:(0,wde.sqlKey)(t.connection_name,t.sql)}}function Kpt(t,e){return{type:"table",tablePath:t.name,connection:t.connection_name,dialect:e,fields:t.schema?$de(t.schema):[],name:Lde(t.connection_name,t.name)}}function Jpt(t){if(t!==void 0)return t==="decimal"?"float":"integer"}function Ide(t){switch(t.kind){case"string_type":return{type:"string"};case"number_type":return{type:"number",numberType:Jpt(t.subtype)};case"boolean_type":return{type:"boolean"};case"timestamp_type":return{type:"timestamp",timeframe:t.timeframe};case"date_type":return{type:"date",timeframe:t.timeframe};case"sql_native_type":return{type:"sql native",rawType:t.sql_type};case"json_type":return{type:"json"};case"array_type":{if(t.element_type.kind==="record_type")return{type:"array",elementTypeDef:{type:"record_element"},fields:t.element_type.fields.map(RP)};{const e=Ide(t.element_type);if(e.type==="record")throw new Error("Arrays of records should be a repeated record type");return{type:"array",elementTypeDef:e}}}case"record_type":return{type:"record",fields:t.fields.map(RP)}}}function RP(t){var e;const r=Ide(t.type);return{...(0,Fde.mkFieldDef)(r,t.name),annotation:t.annotations&&t.annotations.length?{notes:(e=t.annotations)===null||e===void 0?void 0:e.map(i=>({text:i.value,at:{url:"~internal~",range:Md.DEFAULT_LOG_RANGE}}))}:void 0}}function Xpt(t){if(t.kind!=="dimension")throw new Error("Table schemas must only have dimension fields");return RP(t)}function $de(t){const e=[];for(const r of t.fields)e.push(Xpt(r));return e}function Bde(t){var e,r,i,s,o,u;const a={urls:{},tables:{},compileSQL:{},translations:{}};if(t){for(const l of(e=t.files)!==null&&e!==void 0?e:[])l.contents!==void 0&&(a.urls[l.url]=l.contents);for(const l of(r=t.table_schemas)!==null&&r!==void 0?r:[]){const c=(i=t.connections)===null||i===void 0?void 0:i.find(f=>f.name===l.connection_name);c&&l.schema&&c.dialect&&(a.tables[Lde(l.connection_name,l.name)]=Kpt(l,c.dialect))}for(const l of(s=t.sql_schemas)!==null&&s!==void 0?s:[]){const c=(o=t.connections)===null||o===void 0?void 0:o.find(f=>f.name===l.connection_name);c&&c.dialect&&(a.compileSQL[(0,wde.sqlKey)(l.connection_name,l.sql)]=Ypt(l,c.dialect))}for(const l of(u=t.translations)!==null&&u!==void 0?u:[])if(l.compiled_model_json){const c=JSON.parse(l.compiled_model_json);a.translations[l.url]=c}}return a}function kde(t,e,r){var i,s,o;const u={},a=new Set;if(t!==void 0&&(u.sql_schemas=[{sql:t.selectStr,connection_name:t.connection}],a.add(t.connection)),e!==void 0)for(const l of e)(i=u.files)!==null&&i!==void 0||(u.files=[]),u.files.push({url:l});if(r!==void 0)for(const l in r){const c=r[l],f=(s=c.connectionName)!==null&&s!==void 0?s:"__default__";(o=u.table_schemas)!==null&&o!==void 0||(u.table_schemas=[]),u.table_schemas.push({name:c.tablePath,connection_name:f}),a.add(f)}return a.size>0&&(u.connections=Array.from(a).map(l=>({name:l}))),u}function Zpt(t,e){return e??(e=qde(t)),Hde(e)}on.compileQuery=Zpt;function e2t(t,e){function r(s,o){var u,a,l,c;s.translator.update(o),s.extending&&r(s.extending,o),s.hasSource||(s.hasSource=((a=(u=e==null?void 0:e.files)===null||u===void 0?void 0:u.some(f=>f.url===s.translator.sourceURL))!==null&&a!==void 0?a:!1)||((c=(l=e==null?void 0:e.translations)===null||l===void 0?void 0:l.some(f=>f.url===s.translator.sourceURL))!==null&&c!==void 0?c:!1))}const i=Bde(e);r(t,i)}on.updateCompileModelState=e2t;function kD(t,e,r){var i,s,o,u;const a=new Wpt.MalloyTranslator(t,null,Bde(e)),l=((s=(i=e==null?void 0:e.files)===null||i===void 0?void 0:i.some(c=>c.url===t))!==null&&s!==void 0?s:!1)||((u=(o=e==null?void 0:e.translations)===null||o===void 0?void 0:o.some(c=>c.url===t))!==null&&u!==void 0?u:!1);return r?{extending:kD(r,e),translator:a,done:!1,hasSource:l}:{translator:a,done:!1,hasSource:l}}function Mde(t){return kD(t.model_url,t.compiler_needs,t.extend_model_url)}on.newCompileModelState=Mde;function Pde(t){return kD(t.model_url,t.compiler_needs,t.extend_model_url)}on.newCompileSourceState=Pde;function Ude(t){return t2t(nA(t),t.translator.sourceURL)}on.statedCompileModel=Ude;function jde(t,e){return i2t(nA(t),e,t.translator.sourceURL)}on.statedCompileSource=jde;function nA(t){let e;if(t.extending){if(!t.extending.done){const i=nA(t.extending);if(!t.extending.done)return i}e=t.extending.translator.modelDef}if(!t.hasSource)return{compilerNeeds:kde(void 0,[t.translator.sourceURL],void 0)};const r=t.translator.translate(e);if(r.final){if(t.done=!0,r.modelDef)return{model:(0,Gpt.modelDefToModelInfo)(r.modelDef),modelDef:r.modelDef};if(r.problems===void 0||r.problems.length===0)throw new Error("No problems found, but no model either");return{logs:r.problems}}else return{compilerNeeds:kde(r.compileSQL,r.urls,r.tables),logs:r.problems}}on._statedCompileModel=nA;function t2t(t,e){const r=t.logs?(0,Md.mapLogs)(t.logs,e):void 0;if(t.compilerNeeds)return{compiler_needs:t.compilerNeeds,logs:r};{let i;return t.modelDef&&(i=[{url:e,compiled_model_json:JSON.stringify(t.modelDef)}]),{model:t.model,logs:r,translations:i}}}function n2t(t,e){return e??(e=Mde(t)),Ude(e)}on.compileModel=n2t;function r2t(t){const e=Pde(t);return jde(e,t.name)}on.compileSource=r2t;function i2t(t,e,r){const i=t.logs?(0,Md.mapLogs)(t.logs,r):void 0;if(t.model){const s=t.model.entries.find(o=>o.name===e);return s===void 0?{logs:[...i??[],{url:r,severity:"error",message:`Model does not contain a source named ${e}`,range:Md.DEFAULT_LOG_RANGE}]}:{source:s,logs:i}}else return{compiler_needs:t.compilerNeeds,logs:i}}function s2t(t){var e;return(e=t==null?void 0:t.some(r=>r.severity==="error"))!==null&&e!==void 0?e:!1}on.hasErrors=s2t;function qde(t){var e,r;const i=zpt.queryToMalloy(t.query),s={...(e=t.compiler_needs)!==null&&e!==void 0?e:{}},o="internal://query.malloy";return s.files=[{url:o,contents:i},...(r=s.files)!==null&&r!==void 0?r:[]],{...kD(o,s,t.model_url),defaultRowLimit:t.default_row_limit}}on.newCompileQueryState=qde;function Hde(t){var e;const r=nA(t),i=t.translator.sourceURL,s=r.logs?(0,Md.mapLogs)(r.logs,i):void 0;if(r.model){const o=r.modelDef.queryList;if(o.length===0)return{logs:[...s??[],{url:i,severity:"error",message:"Internal error: No queries found",range:Md.DEFAULT_LOG_RANGE}]};const u=o.length-1,a=r.modelDef.queryList[u],l=r.model.anonymous_queries[u].schema,c=(e=r.model.anonymous_queries[u].annotations)!==null&&e!==void 0?e:[];try{const x=new Fde.QueryModel(r.modelDef).compileQuery(a,{defaultRowLimit:t.defaultRowLimit}),h=(0,Vpt.annotationToTaglines)(r.modelDef.annotation).map(p=>({value:p}));return c.push({value:Nde.Tag.withPrefix("#(malloy) ").set(["source_name"],x.sourceExplore).toString()}),x.queryName&&c.push({value:Nde.Tag.withPrefix("#(malloy) ").set(["query_name"],x.queryName).toString()}),{result:{sql:x.sql,schema:l,connection_name:x.connectionName,annotations:c.length>0?c:void 0,model_annotations:h.length>0?h:void 0,query_timezone:x.queryTimezone},default_row_limit_added:x.defaultRowLimitAdded}}catch(f){return{logs:[...s??[],{url:i,severity:"error",message:`Internal compiler error: ${f.message}`,range:Md.DEFAULT_LOG_RANGE}]}}}else return{compiler_needs:r.compilerNeeds,logs:s}}on.statedCompileQuery=Hde;var o2t=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),u2t=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),Qde=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&o2t(e,t,r);return u2t(e,t),e};Object.defineProperty(hf,"__esModule",{value:!0}),hf.compileQuery=hf.compileSource=hf.compileModel=void 0;const a2t=Qde(vP),el=Qde(on),l2t=m2;function c2t(t,e){return t.type==="compile_model"?e.type!=="compile_model"?!1:t.modelURL===e.modelURL&&t.extendModelURL===e.extendModelURL:t.type==="compile_source"?e.type!=="compile_source"?!1:t.modelURL===e.modelURL&&t.extendModelURL===e.extendModelURL&&t.name===e.name:e.type!=="compile_query"?!1:t.modelURL===e.modelURL&&t.queryString===e.queryString}class f2t{constructor(){this.sessions=new Map}purgeExpired(e){const r=new Date;for(const i of this.sessions.values())i.sessionId!==(e==null?void 0:e.except)&&i.expires&&i.expires<r&&this.sessions.delete(i.sessionId)}findSession(e,r){const i=this.sessions.get(e);if(i&&c2t(i.sessionInfo,r))return i}getExpires(e){return e instanceof Date?e:new Date(Date.now()+e.seconds*1e3)}newSessionId(){let e;do e=(0,l2t.v4)();while(this.sessions.has(e));return e}newCompileModelSession(e,r,i){const s=i!=null&&i.ttl?this.getExpires(i.ttl):void 0,o=el.newCompileModelState(e);return{type:"compile_model",sessionInfo:r,state:o,expires:s,sessionId:this.newSessionId()}}newCompileSourceSession(e,r,i){const s=i!=null&&i.ttl?this.getExpires(i.ttl):void 0,o=el.newCompileSourceState(e);return{type:"compile_source",sessionInfo:r,state:o,expires:s,sessionId:this.newSessionId()}}newCompileQuerySession(e,r,i){const s=i!=null&&i.ttl?this.getExpires(i.ttl):void 0,o=el.newCompileQueryState(e);return{type:"compile_query",sessionInfo:r,state:o,expires:s,sessionId:this.newSessionId()}}findCompileModelSession(e,r){const i=this.findSession(e,r);if((i==null?void 0:i.type)==="compile_model")return i}killSession(e){this.sessions.delete(e)}hasErrors(e){return el.hasErrors(e)}compileModel(e,r){const i={type:"compile_model",modelURL:e.model_url,extendModelURL:e.extend_model_url};let s=(r==null?void 0:r.session_id)&&this.findCompileModelSession(r.session_id,i);this.purgeExpired({except:r==null?void 0:r.session_id}),s?(r!=null&&r.ttl&&(s.expires=this.getExpires(r.ttl)),el.updateCompileModelState(s.state,e.compiler_needs)):(s=this.newCompileModelSession(e,i,r),this.sessions.set(s.sessionId,s));const o=el.statedCompileModel(s.state);return(o.model||this.hasErrors(o.logs))&&this.killSession(s.sessionId),{...o,session_id:s.sessionId}}findCompileSourceSession(e,r){const i=this.findSession(e,r);if((i==null?void 0:i.type)==="compile_source")return i}compileSource(e,r){const i={type:"compile_source",modelURL:e.model_url,name:e.name,extendModelURL:e.extend_model_url};let s=(r==null?void 0:r.session_id)&&this.findCompileSourceSession(r.session_id,i);this.purgeExpired({except:r==null?void 0:r.session_id}),s?(r!=null&&r.ttl&&(s.expires=this.getExpires(r.ttl)),el.updateCompileModelState(s.state,e.compiler_needs)):(s=this.newCompileSourceSession(e,i,r),this.sessions.set(s.sessionId,s));const o=el.statedCompileSource(s.state,e.name);return(o.source||this.hasErrors(o.logs))&&this.killSession(s.sessionId),{...o,session_id:s.sessionId}}findCompileQuerySession(e,r){const i=this.findSession(e,r);if((i==null?void 0:i.type)==="compile_query")return i}compileQuery(e,r){const i=a2t.queryToMalloy(e.query),s={type:"compile_query",modelURL:e.model_url,queryString:i,query:e.query};let o=(r==null?void 0:r.session_id)&&this.findCompileQuerySession(r.session_id,s);this.purgeExpired({except:r==null?void 0:r.session_id}),o?(r!=null&&r.ttl&&(o.expires=this.getExpires(r.ttl)),el.updateCompileModelState(o.state,e.compiler_needs)):(o=this.newCompileQuerySession(e,s,r),this.sessions.set(o.sessionId,o));const u=el.statedCompileQuery(o.state);return(u.result||this.hasErrors(u.logs))&&this.killSession(o.sessionId),{...u,session_id:o.sessionId}}}const DP=new f2t;function x2t(t,e){return DP.compileModel(t,e)}hf.compileModel=x2t;function d2t(t,e){return DP.compileSource(t,e)}hf.compileSource=d2t;function h2t(t,e){return DP.compileQuery(t,e)}hf.compileQuery=h2t;var mf={},p2t=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),m2t=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),g2t=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&p2t(e,t,r);return m2t(e,t),e};Object.defineProperty(mf,"__esModule",{value:!0}),mf.compileQuery=mf.compileSource=mf.compileModel=void 0;const OP=g2t(on);function y2t(t){return OP.compileModel(t)}mf.compileModel=y2t;function E2t(t){return OP.compileSource(t)}mf.compileSource=E2t;function A2t(t){return OP.compileQuery(t)}mf.compileQuery=A2t;var tl={},_2t=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),v2t=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),C2t=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&_2t(e,t,r);return v2t(e,t),e};Object.defineProperty(tl,"__esModule",{value:!0}),tl.runQuery=tl.compileQuery=tl.compileSource=tl.compileModel=void 0;const Fo=C2t(on),zde=VE;async function FP(t,e){var r,i,s,o,u,a,l,c,f;if(t===void 0)throw new Error("Expected compiler to have needs because it didn't return a result");const x={};if(t.connections)for(const h of t.connections){const p=await e.connections.lookupConnection(h.name);(r=x.connections)!==null&&r!==void 0||(x.connections=[]),x.connections.push({...h,dialect:p.dialectName})}if(t.files)for(const h of t.files){const p=await e.urls.readURL(new URL(h.url));(i=x.files)!==null&&i!==void 0||(x.files=[]),typeof p=="string"?x.files.push({...h,contents:p}):x.files.push({...h,contents:p.contents,invalidation_key:(s=p.invalidationKey)===null||s===void 0?void 0:s.toString()})}if(t.table_schemas){const h={};for(const p of t.table_schemas)(o=h[c=p.connection_name])!==null&&o!==void 0||(h[c]=[]),h[p.connection_name].push(p);for(const p in h){const m=await e.connections.lookupConnection(p),g=h[p].map(E=>E.name),y=await Promise.all(g.map(async E=>({name:E,schema:await m.fetchSchemaForTable(E)})));(u=x.table_schemas)!==null&&u!==void 0||(x.table_schemas=[]);for(const E of y)x.table_schemas.push({connection_name:p,name:E.name,schema:E.schema})}}if(t.sql_schemas){const h={};for(const p of t.sql_schemas)(a=h[f=p.connection_name])!==null&&a!==void 0||(h[f]=[]),h[p.connection_name].push(p);for(const p in h){const m=await e.connections.lookupConnection(p),g=h[p].map(E=>E.sql),y=await Promise.all(g.map(async E=>({sql:E,schema:await m.fetchSchemaForSQLQuery(E)})));(l=x.sql_schemas)!==null&&l!==void 0||(x.sql_schemas=[]);for(const E of y)x.sql_schemas.push({connection_name:p,sql:E.sql,schema:E.schema})}}return x}async function S2t(t,e){const r=Fo.newCompileModelState(t);for(;;){const i=Fo.statedCompileModel(r);if(i.model||Fo.hasErrors(i.logs))return i;const s=await FP(i.compiler_needs,e);Fo.updateCompileModelState(r,s)}}tl.compileModel=S2t;async function b2t(t,e){const r=Fo.newCompileSourceState(t);for(;;){const i=Fo.statedCompileSource(r,t.name);if(i.source||Fo.hasErrors(i.logs))return i;const s=await FP(i.compiler_needs,e);Fo.updateCompileModelState(r,s)}}tl.compileSource=b2t;async function Wde(t,e){const r=Fo.newCompileQueryState(t);for(;;){const i=Fo.statedCompileQuery(r);if(i.result||Fo.hasErrors(i.logs))return i;const s=await FP(i.compiler_needs,e);Fo.updateCompileModelState(r,s)}}tl.compileQuery=Wde;async function T2t(t,e){var r,i;const s=await Wde(t,e);if(s.result===void 0)return s;const o=t.model_url;if(s.result.sql===void 0)return{logs:[...(r=s.logs)!==null&&r!==void 0?r:[],{url:o,severity:"error",message:"Internal error: Compiler did not generate SQL",range:zde.DEFAULT_LOG_RANGE}]};try{const a=await(await e.connections.lookupConnection(s.result.connection_name)).runSQL(s.result.sql,s.result.schema);return{...s,result:{...s.result,data:a}}}catch(u){return{...s,logs:[...(i=s.logs)!==null&&i!==void 0?i:[],{url:o,severity:"error",message:`Error running SQL: ${u.message}`,range:zde.DEFAULT_LOG_RANGE}]}}}tl.runQuery=T2t;var Gde={};Object.defineProperty(Gde,"__esModule",{value:!0}),function(t){var e=T&&T.__createBinding||(Object.create?function(o,u,a,l){l===void 0&&(l=a);var c=Object.getOwnPropertyDescriptor(u,a);(!c||("get"in c?!u.__esModule:c.writable||c.configurable))&&(c={enumerable:!0,get:function(){return u[a]}}),Object.defineProperty(o,l,c)}:function(o,u,a,l){l===void 0&&(l=a),o[l]=u[a]}),r=T&&T.__setModuleDefault||(Object.create?function(o,u){Object.defineProperty(o,"default",{enumerable:!0,value:u})}:function(o,u){o.default=u}),i=T&&T.__importStar||function(o){if(o&&o.__esModule)return o;var u={};if(o!=null)for(var a in o)a!=="default"&&Object.prototype.hasOwnProperty.call(o,a)&&e(u,o,a);return r(u,o),u},s=T&&T.__exportStar||function(o,u){for(var a in o)a!=="default"&&!Object.prototype.hasOwnProperty.call(u,a)&&e(u,o,a)};Object.defineProperty(t,"__esModule",{value:!0}),t.util=t.asynchronous=t.stateless=t.sessioned=void 0,t.sessioned=i(hf),t.stateless=i(mf),t.asynchronous=i(tl),s(Gde,t),t.util=i(VE)}(Cde),function(t){var e=T&&T.__createBinding||(Object.create?function(h,p,m,g){g===void 0&&(g=m);var y=Object.getOwnPropertyDescriptor(p,m);(!y||("get"in y?!p.__esModule:y.writable||y.configurable))&&(y={enumerable:!0,get:function(){return p[m]}}),Object.defineProperty(h,g,y)}:function(h,p,m,g){g===void 0&&(g=m),h[g]=p[m]}),r=T&&T.__setModuleDefault||(Object.create?function(h,p){Object.defineProperty(h,"default",{enumerable:!0,value:p})}:function(h,p){h.default=p}),i=T&&T.__importStar||function(h){if(h&&h.__esModule)return h;var p={};if(h!=null)for(var m in h)m!=="default"&&Object.prototype.hasOwnProperty.call(h,m)&&e(p,h,m);return r(p,h),p};Object.defineProperty(t,"__esModule",{value:!0}),t.EmptyURLReader=t.SingleConnectionRuntime=t.ConnectionRuntime=t.AtomicFieldType=t.Runtime=t.Malloy=t.Model=t.MalloyTranslator=t.malloyToQuery=t.composeSQLExpr=t.indent=t.expressionIsUngroupedAggregate=t.expressionIsScalar=t.expressionIsCalculation=t.expressionIsAnalytic=t.expressionIsAggregate=t.mkFieldDef=t.mkArrayDef=t.isBasicArray=t.isRepeatedRecord=t.isSamplingRows=t.isSamplingPercent=t.isSamplingEnable=t.isJoinedSource=t.isJoined=t.isBasicAtomic=t.Segment=t.isSourceDef=t.TinyParser=t.Dialect=t.spread=t.literal=t.variadicParam=t.param=t.makeParam=t.sql=t.maxScalar=t.minAggregate=t.anyExprType=t.minScalar=t.overload=t.qtz=t.arg=t.registerDialect=t.MySQLDialect=t.SnowflakeDialect=t.PostgresDialect=t.TrinoDialect=t.StandardSQLDialect=t.DuckDBDialect=void 0,t.annotationToTaglines=t.annotationToTag=t.sqlKey=t.API=t.modelDefToModelInfo=t.toAsyncGenerator=t.CacheManager=t.InMemoryModelCache=t.Explore=t.DataWriter=t.Parse=t.JSONWriter=t.CSVWriter=t.QueryMaterializer=t.Result=t.PreparedResult=t.TimestampTimeframe=t.DateTimeframe=t.SourceRelationship=t.JoinRelationship=t.MalloyError=t.FixedConnectionMap=t.InMemoryURLReader=void 0;var s=h2;Object.defineProperty(t,"DuckDBDialect",{enumerable:!0,get:function(){return s.DuckDBDialect}}),Object.defineProperty(t,"StandardSQLDialect",{enumerable:!0,get:function(){return s.StandardSQLDialect}}),Object.defineProperty(t,"TrinoDialect",{enumerable:!0,get:function(){return s.TrinoDialect}}),Object.defineProperty(t,"PostgresDialect",{enumerable:!0,get:function(){return s.PostgresDialect}}),Object.defineProperty(t,"SnowflakeDialect",{enumerable:!0,get:function(){return s.SnowflakeDialect}}),Object.defineProperty(t,"MySQLDialect",{enumerable:!0,get:function(){return s.MySQLDialect}}),Object.defineProperty(t,"registerDialect",{enumerable:!0,get:function(){return s.registerDialect}}),Object.defineProperty(t,"arg",{enumerable:!0,get:function(){return s.arg}}),Object.defineProperty(t,"qtz",{enumerable:!0,get:function(){return s.qtz}}),Object.defineProperty(t,"overload",{enumerable:!0,get:function(){return s.overload}}),Object.defineProperty(t,"minScalar",{enumerable:!0,get:function(){return s.minScalar}}),Object.defineProperty(t,"anyExprType",{enumerable:!0,get:function(){return s.anyExprType}}),Object.defineProperty(t,"minAggregate",{enumerable:!0,get:function(){return s.minAggregate}}),Object.defineProperty(t,"maxScalar",{enumerable:!0,get:function(){return s.maxScalar}}),Object.defineProperty(t,"sql",{enumerable:!0,get:function(){return s.sql}}),Object.defineProperty(t,"makeParam",{enumerable:!0,get:function(){return s.makeParam}}),Object.defineProperty(t,"param",{enumerable:!0,get:function(){return s.param}}),Object.defineProperty(t,"variadicParam",{enumerable:!0,get:function(){return s.variadicParam}}),Object.defineProperty(t,"literal",{enumerable:!0,get:function(){return s.literal}}),Object.defineProperty(t,"spread",{enumerable:!0,get:function(){return s.spread}}),Object.defineProperty(t,"Dialect",{enumerable:!0,get:function(){return s.Dialect}}),Object.defineProperty(t,"TinyParser",{enumerable:!0,get:function(){return s.TinyParser}});var o=Gi;Object.defineProperty(t,"isSourceDef",{enumerable:!0,get:function(){return o.isSourceDef}}),Object.defineProperty(t,"Segment",{enumerable:!0,get:function(){return o.Segment}}),Object.defineProperty(t,"isBasicAtomic",{enumerable:!0,get:function(){return o.isBasicAtomic}}),Object.defineProperty(t,"isJoined",{enumerable:!0,get:function(){return o.isJoined}}),Object.defineProperty(t,"isJoinedSource",{enumerable:!0,get:function(){return o.isJoinedSource}}),Object.defineProperty(t,"isSamplingEnable",{enumerable:!0,get:function(){return o.isSamplingEnable}}),Object.defineProperty(t,"isSamplingPercent",{enumerable:!0,get:function(){return o.isSamplingPercent}}),Object.defineProperty(t,"isSamplingRows",{enumerable:!0,get:function(){return o.isSamplingRows}}),Object.defineProperty(t,"isRepeatedRecord",{enumerable:!0,get:function(){return o.isRepeatedRecord}}),Object.defineProperty(t,"isBasicArray",{enumerable:!0,get:function(){return o.isBasicArray}}),Object.defineProperty(t,"mkArrayDef",{enumerable:!0,get:function(){return o.mkArrayDef}}),Object.defineProperty(t,"mkFieldDef",{enumerable:!0,get:function(){return o.mkFieldDef}}),Object.defineProperty(t,"expressionIsAggregate",{enumerable:!0,get:function(){return o.expressionIsAggregate}}),Object.defineProperty(t,"expressionIsAnalytic",{enumerable:!0,get:function(){return o.expressionIsAnalytic}}),Object.defineProperty(t,"expressionIsCalculation",{enumerable:!0,get:function(){return o.expressionIsCalculation}}),Object.defineProperty(t,"expressionIsScalar",{enumerable:!0,get:function(){return o.expressionIsScalar}}),Object.defineProperty(t,"expressionIsUngroupedAggregate",{enumerable:!0,get:function(){return o.expressionIsUngroupedAggregate}}),Object.defineProperty(t,"indent",{enumerable:!0,get:function(){return o.indent}}),Object.defineProperty(t,"composeSQLExpr",{enumerable:!0,get:function(){return o.composeSQLExpr}});var u=M4;Object.defineProperty(t,"malloyToQuery",{enumerable:!0,get:function(){return u.malloyToQuery}}),Object.defineProperty(t,"MalloyTranslator",{enumerable:!0,get:function(){return u.MalloyTranslator}});var a=Ie;Object.defineProperty(t,"Model",{enumerable:!0,get:function(){return a.Model}}),Object.defineProperty(t,"Malloy",{enumerable:!0,get:function(){return a.Malloy}}),Object.defineProperty(t,"Runtime",{enumerable:!0,get:function(){return a.Runtime}}),Object.defineProperty(t,"AtomicFieldType",{enumerable:!0,get:function(){return a.AtomicFieldType}}),Object.defineProperty(t,"ConnectionRuntime",{enumerable:!0,get:function(){return a.ConnectionRuntime}}),Object.defineProperty(t,"SingleConnectionRuntime",{enumerable:!0,get:function(){return a.SingleConnectionRuntime}}),Object.defineProperty(t,"EmptyURLReader",{enumerable:!0,get:function(){return a.EmptyURLReader}}),Object.defineProperty(t,"InMemoryURLReader",{enumerable:!0,get:function(){return a.InMemoryURLReader}}),Object.defineProperty(t,"FixedConnectionMap",{enumerable:!0,get:function(){return a.FixedConnectionMap}}),Object.defineProperty(t,"MalloyError",{enumerable:!0,get:function(){return a.MalloyError}}),Object.defineProperty(t,"JoinRelationship",{enumerable:!0,get:function(){return a.JoinRelationship}}),Object.defineProperty(t,"SourceRelationship",{enumerable:!0,get:function(){return a.SourceRelationship}}),Object.defineProperty(t,"DateTimeframe",{enumerable:!0,get:function(){return a.DateTimeframe}}),Object.defineProperty(t,"TimestampTimeframe",{enumerable:!0,get:function(){return a.TimestampTimeframe}}),Object.defineProperty(t,"PreparedResult",{enumerable:!0,get:function(){return a.PreparedResult}}),Object.defineProperty(t,"Result",{enumerable:!0,get:function(){return a.Result}}),Object.defineProperty(t,"QueryMaterializer",{enumerable:!0,get:function(){return a.QueryMaterializer}}),Object.defineProperty(t,"CSVWriter",{enumerable:!0,get:function(){return a.CSVWriter}}),Object.defineProperty(t,"JSONWriter",{enumerable:!0,get:function(){return a.JSONWriter}}),Object.defineProperty(t,"Parse",{enumerable:!0,get:function(){return a.Parse}}),Object.defineProperty(t,"DataWriter",{enumerable:!0,get:function(){return a.DataWriter}}),Object.defineProperty(t,"Explore",{enumerable:!0,get:function(){return a.Explore}}),Object.defineProperty(t,"InMemoryModelCache",{enumerable:!0,get:function(){return a.InMemoryModelCache}}),Object.defineProperty(t,"CacheManager",{enumerable:!0,get:function(){return a.CacheManager}});var l=OD;Object.defineProperty(t,"toAsyncGenerator",{enumerable:!0,get:function(){return l.toAsyncGenerator}});var c=Va;Object.defineProperty(t,"modelDefToModelInfo",{enumerable:!0,get:function(){return c.modelDefToModelInfo}}),t.API=i(Cde);var f=g0;Object.defineProperty(t,"sqlKey",{enumerable:!0,get:function(){return f.sqlKey}});var x=mi;Object.defineProperty(t,"annotationToTag",{enumerable:!0,get:function(){return x.annotationToTag}}),Object.defineProperty(t,"annotationToTaglines",{enumerable:!0,get:function(){return x.annotationToTaglines}})}(j$);var R2t=St("<div class=malloy-copied-modal>Copied query to clipboard!");const Vde=JD(),wo=()=>{const t=XD(Vde);if(!t)throw new Error("ConfigContext missing a value; did you provide a ConfigProvider?");return t};function D2t(t,{element:e}){const r=cr(()=>{if(t.malloyResult)return t.malloyResult;const c=t.result??(t.queryResult&&t.modelDef?new j$.Result(t.queryResult,t.modelDef):null);return c?j$.API.util.wrapResult(c):null}),i=new CSSStyleSheet;e.renderRoot instanceof ShadowRoot&&e.renderRoot.adoptedStyleSheets.push(i);const s=new Set;function o(c){var x;if(!(e.renderRoot instanceof ShadowRoot)){console.warn("Couldn't add CSS to render element, it is not rendering in a ShadowRoot");return}if(!s.has(c)){const h=[];for(let p=0;p<i.cssRules.length;p++){const m=(x=i.cssRules.item(p))==null?void 0:x.cssText;m&&h.push(m)}h.push(c),i.replaceSync(h.join(`
|
|
1885
|
+
`)),s.add(c)}}function u(c,f){if(!document.getElementById(c)){const x=document.createElement("style");x.id=c,x.textContent=f,document.head.appendChild(x)}}o(aXe);const a=()=>Object.assign({disableVirtualization:!1,rowLimit:1/0,shouldFillWidth:!1,enableDrill:!1},t.tableConfig),l=()=>Object.assign({disableVirtualization:!1},t.dashboardConfig);return Ve(Yr,{get when(){return r()},get children(){return Ve(Vde.Provider,{get value(){return{onClick:t.onClick,onDrill:t.onDrill,vegaConfigOverride:t.vegaConfigOverride,element:e,stylesheet:i,addCSSToShadowRoot:o,addCSSToDocument:u,tableConfig:a,dashboardConfig:l,modalElement:t.modalElement}},get children(){return Ve(O2t,{get result(){return r()},element:e,get scrollEl(){return t.scrollEl},get vegaConfigOverride(){return t.vegaConfigOverride}})}})}})}function O2t(t){const e=cr(()=>g3e(t.result)),r=cr(()=>iXe(e(),{getVegaConfigOverride:t.vegaConfigOverride})),i=()=>{const u=e().field.modelTag,a=e().field.tag,l=u.tag("theme"),c=a.tag("theme");return{modelTag:u,resultTag:a,modelTheme:l,localTheme:c}},s=wo();Js(()=>{if(t.element){const u=F2t(i().modelTheme,i().localTheme);s.addCSSToShadowRoot(u)}});const o=()=>{const u=e();return Uc({dataColumn:u,tag:u.field.tag,customProps:{table:{scrollEl:t.scrollEl},dashboard:{scrollEl:t.scrollEl}}})};return[Ve(gte.Provider,{get value(){return r()},get children(){return o().renderValue}}),Ve(Yr,{get when(){return r().store.store.showCopiedModal},get children(){return R2t()}})]}function No(t,...e){let r;for(const i of e)if(r=i==null?void 0:i.text(t),typeof r<"u")break;return r??`var(--malloy-theme--${t.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()})`}function F2t(t,e){const r=No("tableRowHeight",e,t),i=No("tableBodyColor",e,t),s=No("tableFontSize",e,t),o=No("tableHeaderColor",e,t),u=No("tableHeaderWeight",e,t),a=No("tableBodyWeight",e,t),l=No("tableBorder",e,t),c=No("tableBackground",e,t),f=No("tableGutterSize",e,t),x=No("tablePinnedBackground",e,t),h=No("tablePinnedBorder",e,t),p=No("fontFamily",e,t);return`
|
|
1886
1886
|
:host {
|
|
1887
1887
|
--malloy-render--table-row-height: ${r};
|
|
1888
1888
|
--malloy-render--table-body-color: ${i};
|
|
@@ -1897,4 +1897,4 @@ ${b}`,S)}else{if(C.urls)for(const b of C.urls)try{if(DD(b))throw new Error("In o
|
|
|
1897
1897
|
--malloy-render--table-pinned-background: ${x};
|
|
1898
1898
|
--malloy-render--table-pinned-border: ${h};
|
|
1899
1899
|
}
|
|
1900
|
-
`}var
|
|
1900
|
+
`}var w2t=St("<div>");function N2t(t,{element:e}){const r=e.renderRoot;r instanceof ShadowRoot&&t.stylesheet&&r.adoptedStyleSheets.push(t.stylesheet);const i=[...e.childNodes];return(()=>{var s=w2t();return tt(s,i),s})()}function L2t({customElements:t=window.customElements,HTMLElement:e=window.HTMLElement}){t.get("malloy-render")?console.warn("The custom element 'malloy-render' has already been defined. Make sure you are not loading multiple versions of the malloy-render package as they could conflict."):MP(PP("malloy-render",{malloyResult:void 0,result:void 0,queryResult:void 0,modelDef:void 0,scrollEl:void 0,onClick:void 0,onDrill:void 0,vegaConfigOverride:void 0,tableConfig:void 0,dashboardConfig:void 0,modalElement:void 0},{customElements:t,BaseElement:e}),nU)(D2t),t.get("malloy-modal")||MP(PP("malloy-modal",{stylesheet:void 0},{customElements:t,BaseElement:e}),nU)(N2t)}L2t({})});
|