@malloydata/malloy 0.0.1 → 0.0.2
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/dialect/dialect.d.ts +1 -1
- package/dist/dialect/dialect.js +13 -0
- package/dist/lang/ast/apply-expr.d.ts +2 -2
- package/dist/lang/ast/apply-expr.js +19 -3
- package/dist/lang/ast/ast-expr.d.ts +37 -37
- package/dist/lang/ast/ast-expr.js +22 -27
- package/dist/lang/ast/ast-main.d.ts +12 -12
- package/dist/lang/ast/ast-main.js +34 -44
- package/dist/lang/ast/ast-time-expr.d.ts +19 -19
- package/dist/lang/ast/ast-time-expr.js +6 -7
- package/dist/lang/ast/time-utils.d.ts +1 -0
- package/dist/lang/ast/time-utils.js +12 -1
- package/dist/lang/field-space.d.ts +37 -37
- package/dist/lang/field-space.js +108 -130
- package/dist/lang/space-field.d.ts +10 -7
- package/dist/lang/space-field.js +11 -4
- package/dist/lang/test/parse.spec.js +1 -1
- package/dist/model/malloy_query.js +6 -0
- package/dist/model/malloy_types.d.ts +12 -1
- package/package.json +2 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AtomicFieldTypeInner, TimeFieldType, TimestampUnit, ExtractUnit, DialectFragment, TimeValue } from "..";
|
|
2
|
-
import { Expr, Sampling, StructDef, TypecastFragment } from "../model";
|
|
2
|
+
import { Expr, Sampling, StructDef, TypecastFragment } from "../model/malloy_types";
|
|
3
3
|
interface DialectField {
|
|
4
4
|
type: string;
|
|
5
5
|
sqlExpression: string;
|
package/dist/dialect/dialect.js
CHANGED
|
@@ -13,6 +13,11 @@
|
|
|
13
13
|
*/
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.Dialect = void 0;
|
|
16
|
+
// Can't get these from "../model" because model includes this file
|
|
17
|
+
// and that can create a circular reference problem. This is a patch
|
|
18
|
+
// and really indicates a problem in the relationship between
|
|
19
|
+
// dialect and model, it's going to come up again some time.
|
|
20
|
+
const malloy_types_1 = require("../model/malloy_types");
|
|
16
21
|
class Dialect {
|
|
17
22
|
sqlFinalStage(_lastStageName, _fields) {
|
|
18
23
|
throw new Error("Dialect has no final Stage but called Anyway");
|
|
@@ -45,6 +50,14 @@ class Dialect {
|
|
|
45
50
|
return this.sqlCast(df);
|
|
46
51
|
case "regexpMatch":
|
|
47
52
|
return this.sqlRegexpMatch(df.expr, df.regexp);
|
|
53
|
+
case "div": {
|
|
54
|
+
if (this.divisionIsInteger) {
|
|
55
|
+
return (0, malloy_types_1.mkExpr) `${df.numerator}*1.0/${df.denominator}`;
|
|
56
|
+
}
|
|
57
|
+
return (0, malloy_types_1.mkExpr) `${df.numerator}/${df.denominator}`;
|
|
58
|
+
}
|
|
59
|
+
case "timeLiteral":
|
|
60
|
+
return [this.sqlLiteralTime(df.literal, df.literalType, df.timezone)];
|
|
48
61
|
}
|
|
49
62
|
}
|
|
50
63
|
sqlSumDistinct(_key, _value) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Expr } from "../../model/malloy_types";
|
|
2
|
-
import {
|
|
2
|
+
import { FieldSpace } from "../field-space";
|
|
3
3
|
import { ExprValue, ExpressionDef, Equality } from "./index";
|
|
4
4
|
/**
|
|
5
5
|
* All of the magic of malloy expressions eventually flows to here,
|
|
@@ -12,5 +12,5 @@ import { ExprValue, ExpressionDef, Equality } from "./index";
|
|
|
12
12
|
* @param right Right Value
|
|
13
13
|
* @returns ExprValue of the expression
|
|
14
14
|
*/
|
|
15
|
-
export declare function applyBinary(fs:
|
|
15
|
+
export declare function applyBinary(fs: FieldSpace, left: ExpressionDef, op: string, right: ExpressionDef): ExprValue;
|
|
16
16
|
export declare function nullsafeNot(expr: Expr, op?: Equality): Expr;
|
|
@@ -40,12 +40,28 @@ function applyBinary(fs, left, op, right) {
|
|
|
40
40
|
return numeric(fs, left, op, right);
|
|
41
41
|
}
|
|
42
42
|
if (oneOf(op, "/")) {
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
const num = left.getExpression(fs);
|
|
44
|
+
const denom = right.getExpression(fs);
|
|
45
|
+
if (num.dataType != "number") {
|
|
46
|
+
left.log("Numerator for division mus tbe a number");
|
|
47
|
+
}
|
|
48
|
+
else if (denom.dataType != "number") {
|
|
49
|
+
right.log("Denominator for division mus tbe a number");
|
|
45
50
|
}
|
|
46
51
|
else {
|
|
47
|
-
|
|
52
|
+
const div = {
|
|
53
|
+
type: "dialect",
|
|
54
|
+
function: "div",
|
|
55
|
+
numerator: num.value,
|
|
56
|
+
denominator: denom.value,
|
|
57
|
+
};
|
|
58
|
+
return {
|
|
59
|
+
dataType: "number",
|
|
60
|
+
aggregate: num.aggregate || denom.aggregate,
|
|
61
|
+
value: [div],
|
|
62
|
+
};
|
|
48
63
|
}
|
|
64
|
+
return (0, index_1.errorFor)("divide type mismatch");
|
|
49
65
|
}
|
|
50
66
|
left.log(`Canot use ${op} operator here`);
|
|
51
67
|
return (0, index_1.errorFor)("applybinary bad operator");
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { By, AtomicFieldType, FieldTypeDef, Fragment, TimeFieldType } from "../../model/malloy_types";
|
|
2
|
-
import {
|
|
2
|
+
import { FieldSpace } from "../field-space";
|
|
3
3
|
import { Filter, MalloyElement, ExprValue, FieldValueType, FragType } from "./index";
|
|
4
4
|
import { FieldName, FieldReference } from "./ast-main";
|
|
5
5
|
/**
|
|
@@ -17,7 +17,7 @@ export declare abstract class ExpressionDef extends MalloyElement {
|
|
|
17
17
|
* the translation code a chance to convert to match your expectations
|
|
18
18
|
* @param space Namespace for looking up field references
|
|
19
19
|
*/
|
|
20
|
-
abstract getExpression(fs:
|
|
20
|
+
abstract getExpression(fs: FieldSpace): ExprValue;
|
|
21
21
|
legalChildTypes: FragType[];
|
|
22
22
|
/**
|
|
23
23
|
* Some operators want to give the right hand value a chance to
|
|
@@ -26,7 +26,7 @@ export declare abstract class ExpressionDef extends MalloyElement {
|
|
|
26
26
|
* @param fs FieldSpace
|
|
27
27
|
* @returns Translated expression or undefined
|
|
28
28
|
*/
|
|
29
|
-
requestExpression(fs:
|
|
29
|
+
requestExpression(fs: FieldSpace): ExprValue | undefined;
|
|
30
30
|
defaultFieldName(): string | undefined;
|
|
31
31
|
/**
|
|
32
32
|
* Check an expression for type compatibility
|
|
@@ -44,19 +44,19 @@ export declare abstract class ExpressionDef extends MalloyElement {
|
|
|
44
44
|
* @param expr The "other" (besdies 'this') value
|
|
45
45
|
* @returns The translated expression
|
|
46
46
|
*/
|
|
47
|
-
apply(fs:
|
|
47
|
+
apply(fs: FieldSpace, op: string, left: ExpressionDef): ExprValue;
|
|
48
48
|
}
|
|
49
49
|
export declare class ConstantSubExpression extends ExpressionDef {
|
|
50
50
|
readonly expr: ExpressionDef;
|
|
51
51
|
elementType: string;
|
|
52
52
|
private cfs?;
|
|
53
53
|
constructor(expr: ExpressionDef);
|
|
54
|
-
getExpression(_fs:
|
|
54
|
+
getExpression(_fs: FieldSpace): ExprValue;
|
|
55
55
|
private get constantFs();
|
|
56
56
|
constantValue(): ExprValue;
|
|
57
57
|
constantCondition(type: AtomicFieldType): ExprValue;
|
|
58
|
-
apply(fs:
|
|
59
|
-
requestExpression(fs:
|
|
58
|
+
apply(fs: FieldSpace, op: string, expr: ExpressionDef): ExprValue;
|
|
59
|
+
requestExpression(fs: FieldSpace): ExprValue | undefined;
|
|
60
60
|
}
|
|
61
61
|
export declare class FieldDeclaration extends MalloyElement {
|
|
62
62
|
readonly expr: ExpressionDef;
|
|
@@ -66,7 +66,7 @@ export declare class FieldDeclaration extends MalloyElement {
|
|
|
66
66
|
isMeasure?: boolean;
|
|
67
67
|
constructor(expr: ExpressionDef, defineName: string, exprSrc?: string | undefined);
|
|
68
68
|
fieldDef(fs: FieldSpace, exprName: string): FieldTypeDef;
|
|
69
|
-
queryFieldDef(exprFS:
|
|
69
|
+
queryFieldDef(exprFS: FieldSpace, exprName: string): FieldTypeDef;
|
|
70
70
|
}
|
|
71
71
|
export declare class TypeMistmatch extends Error {
|
|
72
72
|
}
|
|
@@ -74,13 +74,13 @@ export declare class ExprString extends ExpressionDef {
|
|
|
74
74
|
readonly value: string;
|
|
75
75
|
elementType: string;
|
|
76
76
|
constructor(value: string);
|
|
77
|
-
getExpression(_fs:
|
|
77
|
+
getExpression(_fs: FieldSpace): ExprValue;
|
|
78
78
|
}
|
|
79
79
|
export declare class ExprNumber extends ExpressionDef {
|
|
80
80
|
readonly n: string;
|
|
81
81
|
elementType: string;
|
|
82
82
|
constructor(n: string);
|
|
83
|
-
getExpression(_fs:
|
|
83
|
+
getExpression(_fs: FieldSpace): ExprValue;
|
|
84
84
|
constantExpression(): ExprValue;
|
|
85
85
|
}
|
|
86
86
|
export declare class ExprRegEx extends ExpressionDef {
|
|
@@ -93,7 +93,7 @@ export declare class ExprTime extends ExpressionDef {
|
|
|
93
93
|
elementType: string;
|
|
94
94
|
readonly translationValue: ExprValue;
|
|
95
95
|
constructor(timeType: TimeFieldType, value: Fragment[] | string, aggregate?: boolean);
|
|
96
|
-
getExpression(_fs:
|
|
96
|
+
getExpression(_fs: FieldSpace): ExprValue;
|
|
97
97
|
static fromValue(timeType: TimeFieldType, expr: ExprValue): ExprTime;
|
|
98
98
|
}
|
|
99
99
|
declare abstract class Unary extends ExpressionDef {
|
|
@@ -104,7 +104,7 @@ export declare class ExprNot extends Unary {
|
|
|
104
104
|
elementType: string;
|
|
105
105
|
legalChildTypes: FragType[];
|
|
106
106
|
constructor(expr: ExpressionDef);
|
|
107
|
-
getExpression(fs:
|
|
107
|
+
getExpression(fs: FieldSpace): ExprValue;
|
|
108
108
|
}
|
|
109
109
|
export declare class Boolean extends ExpressionDef {
|
|
110
110
|
readonly value: "true" | "false";
|
|
@@ -119,7 +119,7 @@ export declare abstract class BinaryBoolean<opType extends string> extends Expre
|
|
|
119
119
|
elementType: string;
|
|
120
120
|
legalChildTypes: FragType[];
|
|
121
121
|
constructor(left: ExpressionDef, op: opType, right: ExpressionDef);
|
|
122
|
-
getExpression(fs:
|
|
122
|
+
getExpression(fs: FieldSpace): ExprValue;
|
|
123
123
|
}
|
|
124
124
|
export declare class ExprLogicalOp extends BinaryBoolean<"and" | "or"> {
|
|
125
125
|
elementType: string;
|
|
@@ -130,8 +130,8 @@ export declare class ExprIdReference extends ExpressionDef {
|
|
|
130
130
|
elementType: string;
|
|
131
131
|
constructor(fieldReference: FieldReference);
|
|
132
132
|
get refString(): string;
|
|
133
|
-
getExpression(fs:
|
|
134
|
-
apply(fs:
|
|
133
|
+
getExpression(fs: FieldSpace): ExprValue;
|
|
134
|
+
apply(fs: FieldSpace, op: string, expr: ExpressionDef): ExprValue;
|
|
135
135
|
}
|
|
136
136
|
export declare class ExprNULL extends ExpressionDef {
|
|
137
137
|
elementType: string;
|
|
@@ -141,15 +141,15 @@ export declare class ExprParens extends ExpressionDef {
|
|
|
141
141
|
readonly expr: ExpressionDef;
|
|
142
142
|
elementType: string;
|
|
143
143
|
constructor(expr: ExpressionDef);
|
|
144
|
-
apply(fs:
|
|
145
|
-
requestExpression(fs:
|
|
146
|
-
getExpression(fs:
|
|
144
|
+
apply(fs: FieldSpace, op: string, expr: ExpressionDef): ExprValue;
|
|
145
|
+
requestExpression(fs: FieldSpace): ExprValue | undefined;
|
|
146
|
+
getExpression(fs: FieldSpace): ExprValue;
|
|
147
147
|
}
|
|
148
148
|
export declare class ExprMinus extends ExpressionDef {
|
|
149
149
|
readonly expr: ExpressionDef;
|
|
150
150
|
elementType: string;
|
|
151
151
|
constructor(expr: ExpressionDef);
|
|
152
|
-
getExpression(fs:
|
|
152
|
+
getExpression(fs: FieldSpace): ExprValue;
|
|
153
153
|
}
|
|
154
154
|
export declare abstract class BinaryNumeric<opType extends string> extends ExpressionDef {
|
|
155
155
|
readonly left: ExpressionDef;
|
|
@@ -157,7 +157,7 @@ export declare abstract class BinaryNumeric<opType extends string> extends Expre
|
|
|
157
157
|
readonly right: ExpressionDef;
|
|
158
158
|
elementType: string;
|
|
159
159
|
constructor(left: ExpressionDef, op: opType, right: ExpressionDef);
|
|
160
|
-
getExpression(fs:
|
|
160
|
+
getExpression(fs: FieldSpace): ExprValue;
|
|
161
161
|
}
|
|
162
162
|
export declare class ExprAddSub extends BinaryNumeric<"+" | "-"> {
|
|
163
163
|
elementType: string;
|
|
@@ -168,9 +168,9 @@ export declare class ExprMulDiv extends BinaryNumeric<"*" | "/"> {
|
|
|
168
168
|
export declare class ExprAlternationTree extends BinaryBoolean<"|" | "&"> {
|
|
169
169
|
elementType: string;
|
|
170
170
|
constructor(left: ExpressionDef, op: "|" | "&", right: ExpressionDef);
|
|
171
|
-
apply(fs:
|
|
172
|
-
requestExpression(_fs:
|
|
173
|
-
getExpression(_fs:
|
|
171
|
+
apply(fs: FieldSpace, applyOp: string, expr: ExpressionDef): ExprValue;
|
|
172
|
+
requestExpression(_fs: FieldSpace): ExprValue | undefined;
|
|
173
|
+
getExpression(_fs: FieldSpace): ExprValue;
|
|
174
174
|
}
|
|
175
175
|
declare abstract class ExprAggregateFunction extends ExpressionDef {
|
|
176
176
|
readonly func: string;
|
|
@@ -180,7 +180,7 @@ declare abstract class ExprAggregateFunction extends ExpressionDef {
|
|
|
180
180
|
legalChildTypes: FragType[];
|
|
181
181
|
constructor(func: string, expr?: ExpressionDef);
|
|
182
182
|
returns(_forExpression: ExprValue): FieldValueType;
|
|
183
|
-
getExpression(fs:
|
|
183
|
+
getExpression(fs: FieldSpace): ExprValue;
|
|
184
184
|
}
|
|
185
185
|
export declare class ExprMin extends ExprAggregateFunction {
|
|
186
186
|
legalChildTypes: FragType[];
|
|
@@ -208,7 +208,7 @@ export declare class ExprCount extends ExprAggregateFunction {
|
|
|
208
208
|
elementType: string;
|
|
209
209
|
constructor(source?: FieldReference | undefined);
|
|
210
210
|
defaultFieldName(): string | undefined;
|
|
211
|
-
getExpression(_fs:
|
|
211
|
+
getExpression(_fs: FieldSpace): ExprValue;
|
|
212
212
|
}
|
|
213
213
|
export declare class ExprAvg extends ExprAsymmetric {
|
|
214
214
|
constructor(expr: ExpressionDef | undefined, source?: FieldReference);
|
|
@@ -224,21 +224,21 @@ export declare class ExprUngroup extends ExpressionDef {
|
|
|
224
224
|
elementType: string;
|
|
225
225
|
constructor(control: "all" | "exclude", expr: ExpressionDef, fields: FieldName[]);
|
|
226
226
|
returns(_forExpression: ExprValue): FieldValueType;
|
|
227
|
-
getExpression(fs:
|
|
227
|
+
getExpression(fs: FieldSpace): ExprValue;
|
|
228
228
|
}
|
|
229
229
|
export declare class WhenClause extends ExpressionDef {
|
|
230
230
|
readonly whenThis: ExpressionDef;
|
|
231
231
|
readonly thenThis: ExpressionDef;
|
|
232
232
|
elementType: string;
|
|
233
233
|
constructor(whenThis: ExpressionDef, thenThis: ExpressionDef);
|
|
234
|
-
getExpression(_fs:
|
|
234
|
+
getExpression(_fs: FieldSpace): ExprValue;
|
|
235
235
|
}
|
|
236
236
|
export declare class ExprCase extends ExpressionDef {
|
|
237
237
|
readonly when: WhenClause[];
|
|
238
238
|
readonly elseClause?: ExpressionDef | undefined;
|
|
239
239
|
elementType: string;
|
|
240
240
|
constructor(when: WhenClause[], elseClause?: ExpressionDef | undefined);
|
|
241
|
-
getExpression(fs:
|
|
241
|
+
getExpression(fs: FieldSpace): ExprValue;
|
|
242
242
|
}
|
|
243
243
|
export declare class ExprFilter extends ExpressionDef {
|
|
244
244
|
readonly expr: ExpressionDef;
|
|
@@ -246,7 +246,7 @@ export declare class ExprFilter extends ExpressionDef {
|
|
|
246
246
|
elementType: string;
|
|
247
247
|
legalChildTypes: FragType[];
|
|
248
248
|
constructor(expr: ExpressionDef, filter: Filter);
|
|
249
|
-
getExpression(fs:
|
|
249
|
+
getExpression(fs: FieldSpace): ExprValue;
|
|
250
250
|
}
|
|
251
251
|
declare type CastType = "string" | "number" | "boolean" | "date" | "timestamp";
|
|
252
252
|
export declare function isCastType(t: string): t is CastType;
|
|
@@ -256,22 +256,22 @@ export declare class ExprCast extends ExpressionDef {
|
|
|
256
256
|
readonly safe: boolean;
|
|
257
257
|
elementType: string;
|
|
258
258
|
constructor(expr: ExpressionDef, castType: CastType, safe?: boolean);
|
|
259
|
-
getExpression(fs:
|
|
259
|
+
getExpression(fs: FieldSpace): ExprValue;
|
|
260
260
|
}
|
|
261
261
|
export declare class TopBy extends MalloyElement {
|
|
262
262
|
readonly by: string | ExpressionDef;
|
|
263
263
|
elementType: string;
|
|
264
264
|
constructor(by: string | ExpressionDef);
|
|
265
|
-
getBy(fs:
|
|
265
|
+
getBy(fs: FieldSpace): By;
|
|
266
266
|
}
|
|
267
267
|
export declare class Range extends ExpressionDef {
|
|
268
268
|
readonly first: ExpressionDef;
|
|
269
269
|
readonly last: ExpressionDef;
|
|
270
270
|
elementType: string;
|
|
271
271
|
constructor(first: ExpressionDef, last: ExpressionDef);
|
|
272
|
-
apply(fs:
|
|
273
|
-
requestExpression(_fs:
|
|
274
|
-
getExpression(_fs:
|
|
272
|
+
apply(fs: FieldSpace, op: string, expr: ExpressionDef): ExprValue;
|
|
273
|
+
requestExpression(_fs: FieldSpace): ExprValue | undefined;
|
|
274
|
+
getExpression(_fs: FieldSpace): ExprValue;
|
|
275
275
|
}
|
|
276
276
|
export declare class PickWhen extends MalloyElement {
|
|
277
277
|
readonly pick: ExpressionDef | undefined;
|
|
@@ -284,8 +284,8 @@ export declare class Pick extends ExpressionDef {
|
|
|
284
284
|
readonly elsePick?: ExpressionDef | undefined;
|
|
285
285
|
elementType: string;
|
|
286
286
|
constructor(choices: PickWhen[], elsePick?: ExpressionDef | undefined);
|
|
287
|
-
requestExpression(fs:
|
|
288
|
-
apply(fs:
|
|
289
|
-
getExpression(fs:
|
|
287
|
+
requestExpression(fs: FieldSpace): ExprValue | undefined;
|
|
288
|
+
apply(fs: FieldSpace, op: string, expr: ExpressionDef): ExprValue;
|
|
289
|
+
getExpression(fs: FieldSpace): ExprValue;
|
|
290
290
|
}
|
|
291
291
|
export {};
|
|
@@ -117,11 +117,8 @@ class ConstantFieldSpace {
|
|
|
117
117
|
found: undefined,
|
|
118
118
|
};
|
|
119
119
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
// but since this is only used for parameters which are also wrong and
|
|
123
|
-
// broken and stupid and useless, this will do for now
|
|
124
|
-
throw new Error("I just put this line of code here to make things compile");
|
|
120
|
+
dialectObj() {
|
|
121
|
+
return undefined;
|
|
125
122
|
}
|
|
126
123
|
whenComplete(step) {
|
|
127
124
|
step();
|
|
@@ -140,10 +137,7 @@ class ConstantSubExpression extends ExpressionDef {
|
|
|
140
137
|
if (!this.cfs) {
|
|
141
138
|
this.cfs = new ConstantFieldSpace();
|
|
142
139
|
}
|
|
143
|
-
return
|
|
144
|
-
in: this.cfs,
|
|
145
|
-
out: this.cfs,
|
|
146
|
-
};
|
|
140
|
+
return this.cfs;
|
|
147
141
|
}
|
|
148
142
|
constantValue() {
|
|
149
143
|
return this.expr.getExpression(this.constantFs);
|
|
@@ -179,11 +173,7 @@ class FieldDeclaration extends index_1.MalloyElement {
|
|
|
179
173
|
* a refactor of QueryFieldSpace might someday be the place where this should
|
|
180
174
|
* happen.
|
|
181
175
|
*/
|
|
182
|
-
|
|
183
|
-
in: new field_space_1.DefSpace(fs, this),
|
|
184
|
-
out: fs,
|
|
185
|
-
};
|
|
186
|
-
return this.queryFieldDef(defPair, exprName);
|
|
176
|
+
return this.queryFieldDef(new field_space_1.DefSpace(fs, this), exprName);
|
|
187
177
|
}
|
|
188
178
|
queryFieldDef(exprFS, exprName) {
|
|
189
179
|
let exprValue;
|
|
@@ -391,7 +381,7 @@ class ExprIdReference extends ExpressionDef {
|
|
|
391
381
|
return this.fieldReference.refString;
|
|
392
382
|
}
|
|
393
383
|
getExpression(fs) {
|
|
394
|
-
const def = this.fieldReference.getField(fs
|
|
384
|
+
const def = this.fieldReference.getField(fs);
|
|
395
385
|
if (def.found) {
|
|
396
386
|
// TODO if type is a query or a struct this should fail nicely
|
|
397
387
|
const typeMixin = def.found.type();
|
|
@@ -404,7 +394,7 @@ class ExprIdReference extends ExpressionDef {
|
|
|
404
394
|
return (0, index_1.errorFor)(def.error);
|
|
405
395
|
}
|
|
406
396
|
apply(fs, op, expr) {
|
|
407
|
-
const entry = this.fieldReference.getField(fs
|
|
397
|
+
const entry = this.fieldReference.getField(fs).found;
|
|
408
398
|
if (entry instanceof space_field_1.SpaceParam) {
|
|
409
399
|
const cParam = entry.parameter();
|
|
410
400
|
if ((0, malloy_types_1.isConditionParameter)(cParam)) {
|
|
@@ -548,7 +538,7 @@ class ExprAggregateFunction extends ExpressionDef {
|
|
|
548
538
|
let exprVal = (_a = this.expr) === null || _a === void 0 ? void 0 : _a.getExpression(fs);
|
|
549
539
|
let structPath = (_b = this.source) === null || _b === void 0 ? void 0 : _b.refString;
|
|
550
540
|
if (this.source) {
|
|
551
|
-
const sourceFoot = this.source.getField(fs
|
|
541
|
+
const sourceFoot = this.source.getField(fs).found;
|
|
552
542
|
if (sourceFoot) {
|
|
553
543
|
const footType = sourceFoot.type();
|
|
554
544
|
if ((0, malloy_types_1.isAtomicFieldType)(footType.type)) {
|
|
@@ -705,19 +695,24 @@ class ExprUngroup extends ExpressionDef {
|
|
|
705
695
|
}
|
|
706
696
|
const ungroup = { type: this.control, e: exprVal.value };
|
|
707
697
|
if (this.typeCheck(this.expr, { ...exprVal, aggregate: false })) {
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
698
|
+
if (this.fields.length > 0) {
|
|
699
|
+
let qs = fs;
|
|
700
|
+
if (fs instanceof field_space_1.DefSpace) {
|
|
701
|
+
qs = fs.realFS;
|
|
702
|
+
}
|
|
703
|
+
if (!(qs instanceof field_space_1.QuerySpace)) {
|
|
704
|
+
this.log(`${this.control}() must be in a query -- weird internal error`);
|
|
705
|
+
return (0, index_1.errorFor)("ungroup query check");
|
|
706
|
+
}
|
|
707
|
+
const output = qs.result;
|
|
708
|
+
const dstFields = [];
|
|
711
709
|
const isExclude = this.control == "exclude";
|
|
712
|
-
const
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
resultSpace.checkUngroup(mustBeInOutput, isExclude);
|
|
710
|
+
for (const mustBeInOutput of this.fields) {
|
|
711
|
+
output.whenComplete(() => {
|
|
712
|
+
output.checkUngroup(mustBeInOutput, isExclude);
|
|
716
713
|
});
|
|
717
|
-
dstFields.push(
|
|
714
|
+
dstFields.push(mustBeInOutput.refString);
|
|
718
715
|
}
|
|
719
|
-
}
|
|
720
|
-
if (dstFields.length > 0) {
|
|
721
716
|
ungroup.fields = dstFields;
|
|
722
717
|
}
|
|
723
718
|
return {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as model from "../../model/malloy_types";
|
|
2
|
-
import { FieldSpace,
|
|
2
|
+
import { FieldSpace, QuerySpace, LookupResult } from "../field-space";
|
|
3
3
|
import { MalloyTranslation } from "../parse-malloy";
|
|
4
4
|
import { ConstantSubExpression, ExpressionDef, FieldDeclaration } from "./index";
|
|
5
5
|
import { SQLBlockRequest } from "../../model/sql_block";
|
|
@@ -149,7 +149,7 @@ export declare class QuerySource extends Mallobj {
|
|
|
149
149
|
export declare abstract class Join extends MalloyElement {
|
|
150
150
|
abstract name: ModelEntryReference;
|
|
151
151
|
abstract structDef(): model.StructDef;
|
|
152
|
-
abstract fixupJoinOn(outer:
|
|
152
|
+
abstract fixupJoinOn(outer: FieldSpace, inStruct: model.StructDef): void;
|
|
153
153
|
}
|
|
154
154
|
export declare class KeyJoin extends Join {
|
|
155
155
|
readonly name: ModelEntryReference;
|
|
@@ -158,7 +158,7 @@ export declare class KeyJoin extends Join {
|
|
|
158
158
|
elementType: string;
|
|
159
159
|
constructor(name: ModelEntryReference, source: Mallobj, keyExpr: ExpressionDef);
|
|
160
160
|
structDef(): model.StructDef;
|
|
161
|
-
fixupJoinOn(outer:
|
|
161
|
+
fixupJoinOn(outer: FieldSpace, inStruct: model.StructDef): void;
|
|
162
162
|
}
|
|
163
163
|
declare type ExpressionJoinType = "many" | "one" | "cross";
|
|
164
164
|
export declare class ExpressionJoin extends Join {
|
|
@@ -170,7 +170,7 @@ export declare class ExpressionJoin extends Join {
|
|
|
170
170
|
constructor(name: ModelEntryReference, source: Mallobj);
|
|
171
171
|
set joinOn(joinExpr: ExpressionDef | undefined);
|
|
172
172
|
get joinOn(): ExpressionDef | undefined;
|
|
173
|
-
fixupJoinOn(outer:
|
|
173
|
+
fixupJoinOn(outer: FieldSpace, inStruct: model.StructDef): model.Expr | undefined;
|
|
174
174
|
structDef(): model.StructDef;
|
|
175
175
|
}
|
|
176
176
|
export declare class Joins extends ListOf<Join> {
|
|
@@ -188,14 +188,14 @@ export declare class FilterElement extends MalloyElement {
|
|
|
188
188
|
readonly exprSrc: string;
|
|
189
189
|
elementType: string;
|
|
190
190
|
constructor(expr: ExpressionDef, exprSrc: string);
|
|
191
|
-
filterExpression(fs:
|
|
191
|
+
filterExpression(fs: FieldSpace): model.FilterExpression;
|
|
192
192
|
}
|
|
193
193
|
export declare class Filter extends ListOf<FilterElement> {
|
|
194
194
|
elementType: string;
|
|
195
195
|
private havingClause?;
|
|
196
196
|
constructor(elements?: FilterElement[]);
|
|
197
197
|
set having(isHaving: boolean);
|
|
198
|
-
getFilterList(fs:
|
|
198
|
+
getFilterList(fs: FieldSpace): model.FilterExpression[];
|
|
199
199
|
}
|
|
200
200
|
export declare class DeclareFields extends ListOf<FieldDeclaration> {
|
|
201
201
|
constructor(fields: FieldDeclaration[], fieldType?: string);
|
|
@@ -215,7 +215,7 @@ export declare class FieldName extends MalloyElement {
|
|
|
215
215
|
constructor(name: string);
|
|
216
216
|
get refString(): string;
|
|
217
217
|
toString(): string;
|
|
218
|
-
getField(fs:
|
|
218
|
+
getField(fs: FieldSpace): LookupResult;
|
|
219
219
|
}
|
|
220
220
|
export declare class FieldReference extends ListOf<FieldName> {
|
|
221
221
|
elementType: string;
|
|
@@ -307,11 +307,11 @@ export declare class OrderBy extends MalloyElement {
|
|
|
307
307
|
elementType: string;
|
|
308
308
|
constructor(field: number | FieldName, dir?: "asc" | "desc" | undefined);
|
|
309
309
|
get modelField(): string | number;
|
|
310
|
-
getOrderBy(_fs:
|
|
310
|
+
getOrderBy(_fs: FieldSpace): model.OrderBy;
|
|
311
311
|
}
|
|
312
312
|
export declare class Ordering extends ListOf<OrderBy> {
|
|
313
313
|
constructor(list: OrderBy[]);
|
|
314
|
-
getOrderBy(fs:
|
|
314
|
+
getOrderBy(fs: FieldSpace): model.OrderBy[];
|
|
315
315
|
}
|
|
316
316
|
export declare class Limit extends MalloyElement {
|
|
317
317
|
readonly limit: number;
|
|
@@ -376,8 +376,8 @@ export declare class FullQuery extends TurtleHeadedPipe {
|
|
|
376
376
|
export declare class TurtleDecl extends TurtleHeadedPipe {
|
|
377
377
|
readonly name: string;
|
|
378
378
|
constructor(name: string);
|
|
379
|
-
getPipeline(fs:
|
|
380
|
-
getFieldDef(
|
|
379
|
+
getPipeline(fs: FieldSpace): model.Pipeline;
|
|
380
|
+
getFieldDef(fs: FieldSpace, nestParent: QuerySpace | undefined): model.TurtleDef;
|
|
381
381
|
}
|
|
382
382
|
export declare class NestReference extends FieldReference {
|
|
383
383
|
readonly name: FieldName;
|
|
@@ -422,7 +422,7 @@ export declare class Top extends MalloyElement {
|
|
|
422
422
|
readonly by?: TopInit | undefined;
|
|
423
423
|
elementType: string;
|
|
424
424
|
constructor(limit: number, by?: TopInit | undefined);
|
|
425
|
-
getBy(fs:
|
|
425
|
+
getBy(fs: FieldSpace): model.By | undefined;
|
|
426
426
|
}
|
|
427
427
|
export declare class JSONElement extends MalloyElement {
|
|
428
428
|
elementType: string;
|