@malloydata/malloy 0.0.205-dev241028163321 → 0.0.205-dev241028173215

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.
Files changed (88) hide show
  1. package/dist/dialect/functions/util.d.ts +16 -16
  2. package/dist/dialect/functions/util.js +16 -48
  3. package/dist/index.d.ts +1 -1
  4. package/dist/lang/ast/ast-utils.js +1 -1
  5. package/dist/lang/ast/expressions/binary-boolean.js +27 -4
  6. package/dist/lang/ast/expressions/binary-numeric.js +25 -2
  7. package/dist/lang/ast/expressions/boolean.js +25 -2
  8. package/dist/lang/ast/expressions/case.js +41 -20
  9. package/dist/lang/ast/expressions/expr-aggregate-function.d.ts +2 -2
  10. package/dist/lang/ast/expressions/expr-aggregate-function.js +30 -10
  11. package/dist/lang/ast/expressions/expr-alternation-tree.js +2 -2
  12. package/dist/lang/ast/expressions/expr-asymmetric.d.ts +2 -0
  13. package/dist/lang/ast/expressions/expr-asymmetric.js +3 -0
  14. package/dist/lang/ast/expressions/expr-cast.js +4 -6
  15. package/dist/lang/ast/expressions/expr-coalesce.js +30 -7
  16. package/dist/lang/ast/expressions/expr-compare.js +33 -10
  17. package/dist/lang/ast/expressions/expr-count-distinct.d.ts +2 -0
  18. package/dist/lang/ast/expressions/expr-count-distinct.js +34 -2
  19. package/dist/lang/ast/expressions/expr-count.d.ts +1 -0
  20. package/dist/lang/ast/expressions/expr-count.js +11 -1
  21. package/dist/lang/ast/expressions/expr-func.d.ts +3 -3
  22. package/dist/lang/ast/expressions/expr-func.js +41 -15
  23. package/dist/lang/ast/expressions/expr-granular-time.js +36 -14
  24. package/dist/lang/ast/expressions/expr-logical-op.js +25 -2
  25. package/dist/lang/ast/expressions/expr-max.d.ts +3 -4
  26. package/dist/lang/ast/expressions/expr-max.js +27 -4
  27. package/dist/lang/ast/expressions/expr-min.d.ts +3 -4
  28. package/dist/lang/ast/expressions/expr-min.js +27 -4
  29. package/dist/lang/ast/expressions/expr-minus.js +27 -4
  30. package/dist/lang/ast/expressions/expr-not.js +26 -3
  31. package/dist/lang/ast/expressions/expr-now.js +1 -1
  32. package/dist/lang/ast/expressions/expr-null.js +1 -1
  33. package/dist/lang/ast/expressions/expr-number.js +5 -1
  34. package/dist/lang/ast/expressions/expr-props.js +25 -2
  35. package/dist/lang/ast/expressions/expr-regex.js +1 -1
  36. package/dist/lang/ast/expressions/expr-string.js +1 -1
  37. package/dist/lang/ast/expressions/expr-time-extract.js +18 -18
  38. package/dist/lang/ast/expressions/expr-time.js +4 -4
  39. package/dist/lang/ast/expressions/expr-ungroup.d.ts +0 -2
  40. package/dist/lang/ast/expressions/expr-ungroup.js +26 -6
  41. package/dist/lang/ast/expressions/for-range.js +32 -9
  42. package/dist/lang/ast/expressions/pick-when.js +46 -25
  43. package/dist/lang/ast/expressions/range.js +1 -1
  44. package/dist/lang/ast/expressions/time-literal.js +9 -4
  45. package/dist/lang/ast/field-space/index-field-space.js +1 -3
  46. package/dist/lang/ast/field-space/project-field-space.d.ts +1 -1
  47. package/dist/lang/ast/field-space/project-field-space.js +2 -1
  48. package/dist/lang/ast/field-space/query-spaces.d.ts +1 -1
  49. package/dist/lang/ast/field-space/query-spaces.js +4 -3
  50. package/dist/lang/ast/field-space/reference-field.js +43 -10
  51. package/dist/lang/ast/field-space/rename-space-field.d.ts +2 -2
  52. package/dist/lang/ast/field-space/static-space.js +1 -1
  53. package/dist/lang/ast/field-space/struct-space-field-base.d.ts +2 -2
  54. package/dist/lang/ast/field-space/struct-space-field-base.js +40 -8
  55. package/dist/lang/ast/field-space/view-field.d.ts +2 -2
  56. package/dist/lang/ast/field-space/view-field.js +25 -1
  57. package/dist/lang/ast/parameters/has-parameter.d.ts +1 -1
  58. package/dist/lang/ast/parameters/has-parameter.js +8 -8
  59. package/dist/lang/ast/query-items/field-declaration.d.ts +2 -1
  60. package/dist/lang/ast/query-items/field-declaration.js +34 -9
  61. package/dist/lang/ast/query-items/typecheck_utils.js +11 -13
  62. package/dist/lang/ast/query-properties/filters.js +1 -1
  63. package/dist/lang/ast/source-elements/named-source.js +2 -2
  64. package/dist/lang/ast/source-properties/join.js +3 -3
  65. package/dist/lang/ast/time-utils.d.ts +2 -2
  66. package/dist/lang/ast/time-utils.js +6 -1
  67. package/dist/lang/ast/typedesc-utils.d.ts +48 -0
  68. package/dist/lang/ast/typedesc-utils.js +157 -0
  69. package/dist/lang/ast/types/expr-result.d.ts +2 -1
  70. package/dist/lang/ast/types/expr-value.d.ts +11 -36
  71. package/dist/lang/ast/types/expr-value.js +27 -13
  72. package/dist/lang/ast/types/expression-def.d.ts +3 -2
  73. package/dist/lang/ast/types/expression-def.js +84 -60
  74. package/dist/lang/ast/types/global-name-space.js +2 -2
  75. package/dist/lang/ast/types/granular-result.d.ts +2 -2
  76. package/dist/lang/ast/types/granular-result.js +1 -1
  77. package/dist/lang/ast/types/space-field.js +2 -13
  78. package/dist/lang/ast/types/space-param.d.ts +3 -1
  79. package/dist/lang/ast/types/space-param.js +36 -4
  80. package/dist/lang/ast/types/time-result.d.ts +3 -4
  81. package/dist/lang/parse-log.d.ts +15 -15
  82. package/dist/lang/test/literals.spec.js +1 -1
  83. package/dist/lang/test/parse-expects.js +2 -2
  84. package/dist/model/malloy_types.d.ts +30 -32
  85. package/dist/model/malloy_types.js +25 -16
  86. package/package.json +1 -1
  87. package/dist/lang/ast/fragtype-utils.d.ts +0 -46
  88. package/dist/lang/ast/fragtype-utils.js +0 -115
@@ -21,10 +21,33 @@
21
21
  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
22
  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
23
  */
24
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
25
+ if (k2 === undefined) k2 = k;
26
+ var desc = Object.getOwnPropertyDescriptor(m, k);
27
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
28
+ desc = { enumerable: true, get: function() { return m[k]; } };
29
+ }
30
+ Object.defineProperty(o, k2, desc);
31
+ }) : (function(o, m, k, k2) {
32
+ if (k2 === undefined) k2 = k;
33
+ o[k2] = m[k];
34
+ }));
35
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
36
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
37
+ }) : function(o, v) {
38
+ o["default"] = v;
39
+ });
40
+ var __importStar = (this && this.__importStar) || function (mod) {
41
+ if (mod && mod.__esModule) return mod;
42
+ var result = {};
43
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
44
+ __setModuleDefault(result, mod);
45
+ return result;
46
+ };
24
47
  Object.defineProperty(exports, "__esModule", { value: true });
25
48
  exports.ExprCoalesce = void 0;
26
49
  const model_1 = require("../../../model");
27
- const fragtype_utils_1 = require("../fragtype-utils");
50
+ const TDU = __importStar(require("../typedesc-utils"));
28
51
  const expression_def_1 = require("../types/expression-def");
29
52
  class ExprCoalesce extends expression_def_1.ExpressionDef {
30
53
  constructor(expr, altExpr) {
@@ -32,12 +55,12 @@ class ExprCoalesce extends expression_def_1.ExpressionDef {
32
55
  this.expr = expr;
33
56
  this.altExpr = altExpr;
34
57
  this.elementType = 'coalesce expression';
35
- this.legalChildTypes = fragtype_utils_1.FT.anyAtomicT;
58
+ this.legalChildTypes = TDU.anyAtomicT;
36
59
  }
37
60
  getExpression(fs) {
38
61
  const maybeNull = this.expr.getExpression(fs);
39
62
  const whenNull = this.altExpr.getExpression(fs);
40
- if (maybeNull.dataType === 'null') {
63
+ if (maybeNull.type === 'null') {
41
64
  return whenNull;
42
65
  }
43
66
  /**
@@ -48,12 +71,12 @@ class ExprCoalesce extends expression_def_1.ExpressionDef {
48
71
  * SQL, but I decided that is will happen when the "expressions are true
49
72
  * trees" rewrite happens.
50
73
  */
51
- if (!fragtype_utils_1.FT.typeEq(maybeNull, whenNull)) {
52
- this.logError('mismatched-coalesce-types', `Mismatched types for coalesce (${maybeNull.dataType}, ${whenNull.dataType})`);
74
+ if (!TDU.typeEq(maybeNull, whenNull)) {
75
+ this.logError('mismatched-coalesce-types', `Mismatched types for coalesce (${maybeNull.type}, ${whenNull.type})`);
53
76
  }
77
+ const srcForType = maybeNull.type === 'error' ? whenNull : maybeNull;
54
78
  return {
55
- ...whenNull,
56
- dataType: maybeNull.dataType === 'error' ? whenNull.dataType : maybeNull.dataType,
79
+ ...srcForType,
57
80
  expressionType: (0, model_1.maxExpressionType)(maybeNull.expressionType, whenNull.expressionType),
58
81
  value: {
59
82
  node: 'coalesce',
@@ -21,21 +21,44 @@
21
21
  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
22
  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
23
  */
24
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
25
+ if (k2 === undefined) k2 = k;
26
+ var desc = Object.getOwnPropertyDescriptor(m, k);
27
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
28
+ desc = { enumerable: true, get: function() { return m[k]; } };
29
+ }
30
+ Object.defineProperty(o, k2, desc);
31
+ }) : (function(o, m, k, k2) {
32
+ if (k2 === undefined) k2 = k;
33
+ o[k2] = m[k];
34
+ }));
35
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
36
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
37
+ }) : function(o, v) {
38
+ o["default"] = v;
39
+ });
40
+ var __importStar = (this && this.__importStar) || function (mod) {
41
+ if (mod && mod.__esModule) return mod;
42
+ var result = {};
43
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
44
+ __setModuleDefault(result, mod);
45
+ return result;
46
+ };
24
47
  Object.defineProperty(exports, "__esModule", { value: true });
25
48
  exports.ExprLegacyIn = exports.ExprEquality = exports.ExprCompare = void 0;
26
49
  const model_1 = require("../../../model");
27
- const fragtype_utils_1 = require("../fragtype-utils");
50
+ const TDU = __importStar(require("../typedesc-utils"));
28
51
  const expression_def_1 = require("../types/expression-def");
29
52
  const binary_boolean_1 = require("./binary-boolean");
30
53
  const compareTypes = {
31
- '~': [fragtype_utils_1.FT.stringT],
32
- '!~': [fragtype_utils_1.FT.stringT],
33
- '<': [fragtype_utils_1.FT.numberT, fragtype_utils_1.FT.stringT, fragtype_utils_1.FT.dateT, fragtype_utils_1.FT.timestampT],
34
- '<=': [fragtype_utils_1.FT.numberT, fragtype_utils_1.FT.stringT, fragtype_utils_1.FT.dateT, fragtype_utils_1.FT.timestampT],
35
- '=': [fragtype_utils_1.FT.numberT, fragtype_utils_1.FT.stringT, fragtype_utils_1.FT.dateT, fragtype_utils_1.FT.timestampT],
36
- '!=': [fragtype_utils_1.FT.numberT, fragtype_utils_1.FT.stringT, fragtype_utils_1.FT.dateT, fragtype_utils_1.FT.timestampT],
37
- '>=': [fragtype_utils_1.FT.numberT, fragtype_utils_1.FT.stringT, fragtype_utils_1.FT.dateT, fragtype_utils_1.FT.timestampT],
38
- '>': [fragtype_utils_1.FT.numberT, fragtype_utils_1.FT.stringT, fragtype_utils_1.FT.dateT, fragtype_utils_1.FT.timestampT],
54
+ '~': [TDU.stringT],
55
+ '!~': [TDU.stringT],
56
+ '<': [TDU.numberT, TDU.stringT, TDU.dateT, TDU.timestampT],
57
+ '<=': [TDU.numberT, TDU.stringT, TDU.dateT, TDU.timestampT],
58
+ '=': [TDU.numberT, TDU.stringT, TDU.dateT, TDU.timestampT],
59
+ '!=': [TDU.numberT, TDU.stringT, TDU.dateT, TDU.timestampT],
60
+ '>=': [TDU.numberT, TDU.stringT, TDU.dateT, TDU.timestampT],
61
+ '>': [TDU.numberT, TDU.stringT, TDU.dateT, TDU.timestampT],
39
62
  };
40
63
  class ExprCompare extends binary_boolean_1.BinaryBoolean {
41
64
  constructor(left, op, right) {
@@ -86,7 +109,7 @@ class ExprLegacyIn extends expression_def_1.ExpressionDef {
86
109
  return choice.value;
87
110
  });
88
111
  return {
89
- dataType: 'boolean',
112
+ type: 'boolean',
90
113
  expressionType,
91
114
  evalSpace,
92
115
  value: {
@@ -1,6 +1,8 @@
1
1
  import { ExprAggregateFunction } from './expr-aggregate-function';
2
2
  import { ExpressionDef } from '../types/expression-def';
3
+ import { ExprValue } from '../types/expr-value';
3
4
  export declare class ExprCountDistinct extends ExprAggregateFunction {
4
5
  legalChildTypes: import("../../..").TypeDesc[];
5
6
  constructor(expr: ExpressionDef);
7
+ returns(ev: ExprValue): ExprValue;
6
8
  }
@@ -21,14 +21,46 @@
21
21
  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
22
  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
23
  */
24
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
25
+ if (k2 === undefined) k2 = k;
26
+ var desc = Object.getOwnPropertyDescriptor(m, k);
27
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
28
+ desc = { enumerable: true, get: function() { return m[k]; } };
29
+ }
30
+ Object.defineProperty(o, k2, desc);
31
+ }) : (function(o, m, k, k2) {
32
+ if (k2 === undefined) k2 = k;
33
+ o[k2] = m[k];
34
+ }));
35
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
36
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
37
+ }) : function(o, v) {
38
+ o["default"] = v;
39
+ });
40
+ var __importStar = (this && this.__importStar) || function (mod) {
41
+ if (mod && mod.__esModule) return mod;
42
+ var result = {};
43
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
44
+ __setModuleDefault(result, mod);
45
+ return result;
46
+ };
24
47
  Object.defineProperty(exports, "__esModule", { value: true });
25
48
  exports.ExprCountDistinct = void 0;
26
- const fragtype_utils_1 = require("../fragtype-utils");
49
+ const TDU = __importStar(require("../typedesc-utils"));
27
50
  const expr_aggregate_function_1 = require("./expr-aggregate-function");
28
51
  class ExprCountDistinct extends expr_aggregate_function_1.ExprAggregateFunction {
29
52
  constructor(expr) {
30
53
  super('distinct', expr);
31
- this.legalChildTypes = [fragtype_utils_1.FT.numberT, fragtype_utils_1.FT.stringT, fragtype_utils_1.FT.dateT, fragtype_utils_1.FT.timestampT];
54
+ this.legalChildTypes = [TDU.numberT, TDU.stringT, TDU.dateT, TDU.timestampT];
55
+ }
56
+ returns(ev) {
57
+ return {
58
+ type: 'number',
59
+ numberType: 'integer',
60
+ evalSpace: ev.evalSpace,
61
+ expressionType: 'aggregate',
62
+ value: ev.value,
63
+ };
32
64
  }
33
65
  }
34
66
  exports.ExprCountDistinct = ExprCountDistinct;
@@ -7,5 +7,6 @@ export declare class ExprCount extends ExprAggregateFunction {
7
7
  elementType: string;
8
8
  constructor(source?: FieldReference | undefined);
9
9
  defaultFieldName(): string | undefined;
10
+ returns(ev: ExprValue): ExprValue;
10
11
  getExpression(_fs: FieldSpace): ExprValue;
11
12
  }
@@ -37,6 +37,15 @@ class ExprCount extends expr_aggregate_function_1.ExprAggregateFunction {
37
37
  }
38
38
  return undefined;
39
39
  }
40
+ returns(ev) {
41
+ return {
42
+ type: 'number',
43
+ numberType: 'integer',
44
+ evalSpace: ev.evalSpace,
45
+ expressionType: 'aggregate',
46
+ value: ev.value,
47
+ };
48
+ }
40
49
  getExpression(_fs) {
41
50
  const ret = {
42
51
  node: 'aggregate',
@@ -47,7 +56,8 @@ class ExprCount extends expr_aggregate_function_1.ExprAggregateFunction {
47
56
  ret.structPath = this.source.path;
48
57
  }
49
58
  return {
50
- dataType: 'number',
59
+ type: 'number',
60
+ numberType: 'integer',
51
61
  expressionType: 'aggregate',
52
62
  value: ret,
53
63
  evalSpace: 'output',
@@ -1,4 +1,4 @@
1
- import { FieldValueType } from '../../../model/malloy_types';
1
+ import { CastType } from '../../../model/malloy_types';
2
2
  import { FieldReference } from '../query-items/field-references';
3
3
  import { FunctionOrdering } from './function-ordering';
4
4
  import { Limit } from '../query-properties/limit';
@@ -10,10 +10,10 @@ export declare class ExprFunc extends ExpressionDef {
10
10
  readonly name: string;
11
11
  readonly args: ExpressionDef[];
12
12
  readonly isRaw: boolean;
13
- readonly rawType: FieldValueType | undefined;
13
+ readonly rawType: CastType | undefined;
14
14
  readonly source?: FieldReference | undefined;
15
15
  elementType: string;
16
- constructor(name: string, args: ExpressionDef[], isRaw: boolean, rawType: FieldValueType | undefined, source?: FieldReference | undefined);
16
+ constructor(name: string, args: ExpressionDef[], isRaw: boolean, rawType: CastType | undefined, source?: FieldReference | undefined);
17
17
  canSupportPartitionBy(): boolean;
18
18
  canSupportOrderBy(): boolean;
19
19
  canSupportLimit(): boolean;
@@ -21,6 +21,29 @@
21
21
  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
22
  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
23
  */
24
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
25
+ if (k2 === undefined) k2 = k;
26
+ var desc = Object.getOwnPropertyDescriptor(m, k);
27
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
28
+ desc = { enumerable: true, get: function() { return m[k]; } };
29
+ }
30
+ Object.defineProperty(o, k2, desc);
31
+ }) : (function(o, m, k, k2) {
32
+ if (k2 === undefined) k2 = k;
33
+ o[k2] = m[k];
34
+ }));
35
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
36
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
37
+ }) : function(o, v) {
38
+ o["default"] = v;
39
+ });
40
+ var __importStar = (this && this.__importStar) || function (mod) {
41
+ if (mod && mod.__esModule) return mod;
42
+ var result = {};
43
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
44
+ __setModuleDefault(result, mod);
45
+ return result;
46
+ };
24
47
  Object.defineProperty(exports, "__esModule", { value: true });
25
48
  exports.ExprFunc = void 0;
26
49
  const malloy_types_1 = require("../../../model/malloy_types");
@@ -30,6 +53,7 @@ const expr_value_1 = require("../types/expr-value");
30
53
  const expression_def_1 = require("../types/expression-def");
31
54
  const field_space_1 = require("../types/field-space");
32
55
  const utils_1 = require("../../../model/utils");
56
+ const TDU = __importStar(require("../typedesc-utils"));
33
57
  class ExprFunc extends expression_def_1.ExpressionDef {
34
58
  constructor(name, args, isRaw, rawType, source) {
35
59
  super({ args: args });
@@ -86,14 +110,16 @@ class ExprFunc extends expression_def_1.ExpressionDef {
86
110
  funcCall.push(',');
87
111
  }
88
112
  else {
89
- collectType = expr.dataType;
113
+ if ((0, malloy_types_1.isCastType)(expr.type)) {
114
+ collectType = expr.type;
115
+ }
90
116
  }
91
117
  funcCall.push(expr.value);
92
118
  }
93
119
  funcCall.push(')');
94
120
  const dataType = (_b = (_a = this.rawType) !== null && _a !== void 0 ? _a : collectType) !== null && _b !== void 0 ? _b : 'number';
95
121
  return (0, expr_value_1.computedExprValue)({
96
- dataType,
122
+ dataType: { type: dataType },
97
123
  value: (0, utils_1.composeSQLExpr)(funcCall),
98
124
  from: argExprsWithoutImplicit,
99
125
  });
@@ -112,9 +138,9 @@ class ExprFunc extends expression_def_1.ExpressionDef {
112
138
  const sourceFoot = lookup.found;
113
139
  if (sourceFoot) {
114
140
  const footType = sourceFoot.typeDesc();
115
- if ((0, malloy_types_1.isAtomicFieldType)(footType.dataType)) {
141
+ if ((0, malloy_types_1.isAtomicFieldType)(footType.type)) {
116
142
  implicitExpr = {
117
- dataType: footType.dataType,
143
+ ...TDU.atomicDef(footType),
118
144
  expressionType: footType.expressionType,
119
145
  value: { node: 'field', path: this.source.path },
120
146
  evalSpace: footType.evalSpace,
@@ -123,7 +149,7 @@ class ExprFunc extends expression_def_1.ExpressionDef {
123
149
  }
124
150
  else {
125
151
  if (!(sourceFoot instanceof struct_space_field_base_1.StructSpaceFieldBase)) {
126
- return this.loggedErrorExpr('invalid-aggregate-source', `Aggregate source cannot be a ${footType.dataType}`);
152
+ return this.loggedErrorExpr('invalid-aggregate-source', `Aggregate source cannot be a ${footType.type}`);
127
153
  }
128
154
  }
129
155
  }
@@ -139,7 +165,7 @@ class ExprFunc extends expression_def_1.ExpressionDef {
139
165
  const result = findOverload(func, argExprs);
140
166
  if (result === undefined) {
141
167
  return this.loggedErrorExpr('no-matching-function-overload', `No matching overload for function ${this.name}(${argExprs
142
- .map(e => e.dataType)
168
+ .map(e => e.type)
143
169
  .join(', ')})`);
144
170
  }
145
171
  const { overload, expressionTypeErrors, evalSpaceErrors, nullabilityErrors } = result;
@@ -177,7 +203,7 @@ class ExprFunc extends expression_def_1.ExpressionDef {
177
203
  if (!(0, malloy_types_1.expressionIsAggregate)(overload.returnType.expressionType) &&
178
204
  this.source !== undefined) {
179
205
  return this.loggedErrorExpr('non-aggregate-function-with-source', `Cannot call function ${this.name}(${argExprs
180
- .map(e => e.dataType)
206
+ .map(e => e.type)
181
207
  .join(', ')}) with source`);
182
208
  }
183
209
  const frag = {
@@ -291,8 +317,8 @@ class ExprFunc extends expression_def_1.ExpressionDef {
291
317
  funcCall = (0, utils_1.composeSQLExpr)(expr);
292
318
  }
293
319
  }
294
- if (type.dataType === 'any') {
295
- return this.loggedErrorExpr('function-returns-any', `Invalid return type ${type.dataType} for function '${this.name}'`);
320
+ if (type.type === 'any') {
321
+ return this.loggedErrorExpr('function-returns-any', `Invalid return type ${type.type} for function '${this.name}'`);
296
322
  }
297
323
  const maxEvalSpace = (0, malloy_types_1.mergeEvalSpaces)(...argExprs.map(e => e.evalSpace));
298
324
  // If the merged eval space of all args is constant, the result is constant.
@@ -308,7 +334,7 @@ class ExprFunc extends expression_def_1.ExpressionDef {
308
334
  // TODO consider if I can use `computedExprValue` here...
309
335
  // seems like the rules for the evalSpace is a bit different from normal though
310
336
  return {
311
- dataType: type.dataType,
337
+ ...TDU.atomicDef(type),
312
338
  expressionType,
313
339
  value: funcCall,
314
340
  evalSpace,
@@ -334,13 +360,13 @@ function findOverload(func, args) {
334
360
  const argOk = param.allowedTypes.some(paramT => {
335
361
  // Check whether types match (allowing for nullability errors, expression type errors,
336
362
  // eval space errors, and unknown types due to prior errors in args)
337
- const dataTypeMatch = paramT.dataType === arg.dataType ||
338
- paramT.dataType === 'any' ||
363
+ const dataTypeMatch = malloy_types_1.TD.eq(paramT, arg) ||
364
+ paramT.type === 'any' ||
339
365
  // TODO We should consider whether `nulls` should always be allowed. It probably
340
366
  // does not make sense to limit function calls to not allow nulls, since have
341
367
  // so little control over nullability.
342
- arg.dataType === 'null' ||
343
- arg.dataType === 'error';
368
+ arg.type === 'null' ||
369
+ arg.type === 'error';
344
370
  // Check expression type errors
345
371
  if (paramT.expressionType) {
346
372
  const expressionTypeMatch = (0, malloy_types_1.isExpressionTypeLEQ)(arg.expressionType, paramT.expressionType);
@@ -374,7 +400,7 @@ function findOverload(func, args) {
374
400
  // Check nullability errors. For now we only require that literal arguments must be
375
401
  // non-null, but in the future we may allow parameters to say whether they can accept literal
376
402
  // nulls.
377
- if (paramT.evalSpace === 'literal' && arg.dataType === 'null') {
403
+ if (paramT.evalSpace === 'literal' && arg.type === 'null') {
378
404
  nullabilityErrors.push({
379
405
  argIndex,
380
406
  param,
@@ -21,11 +21,34 @@
21
21
  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
22
  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
23
  */
24
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
25
+ if (k2 === undefined) k2 = k;
26
+ var desc = Object.getOwnPropertyDescriptor(m, k);
27
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
28
+ desc = { enumerable: true, get: function() { return m[k]; } };
29
+ }
30
+ Object.defineProperty(o, k2, desc);
31
+ }) : (function(o, m, k, k2) {
32
+ if (k2 === undefined) k2 = k;
33
+ o[k2] = m[k];
34
+ }));
35
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
36
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
37
+ }) : function(o, v) {
38
+ o["default"] = v;
39
+ });
40
+ var __importStar = (this && this.__importStar) || function (mod) {
41
+ if (mod && mod.__esModule) return mod;
42
+ var result = {};
43
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
44
+ __setModuleDefault(result, mod);
45
+ return result;
46
+ };
24
47
  Object.defineProperty(exports, "__esModule", { value: true });
25
48
  exports.ExprGranularTime = void 0;
26
49
  const malloy_types_1 = require("../../../model/malloy_types");
27
50
  const ast_utils_1 = require("../ast-utils");
28
- const fragtype_utils_1 = require("../fragtype-utils");
51
+ const TDU = __importStar(require("../typedesc-utils"));
29
52
  const time_utils_1 = require("../time-utils");
30
53
  const expression_def_1 = require("../types/expression-def");
31
54
  const expr_time_1 = require("./expr-time");
@@ -44,7 +67,7 @@ class ExprGranularTime extends expression_def_1.ExpressionDef {
44
67
  this.units = units;
45
68
  this.truncate = truncate;
46
69
  this.elementType = 'granularTime';
47
- this.legalChildTypes = [fragtype_utils_1.FT.timestampT, fragtype_utils_1.FT.dateT];
70
+ this.legalChildTypes = [TDU.timestampT, TDU.dateT];
48
71
  }
49
72
  granular() {
50
73
  return true;
@@ -52,32 +75,31 @@ class ExprGranularTime extends expression_def_1.ExpressionDef {
52
75
  getExpression(fs) {
53
76
  const timeframe = this.units;
54
77
  const exprVal = this.expr.getExpression(fs);
55
- if ((0, malloy_types_1.isTemporalField)(exprVal.dataType)) {
78
+ if (malloy_types_1.TD.isTemporal(exprVal)) {
56
79
  const tsVal = {
57
80
  ...exprVal,
58
- dataType: exprVal.dataType,
59
81
  timeframe: timeframe,
60
82
  };
61
83
  if (this.truncate) {
62
84
  tsVal.value = {
63
85
  node: 'trunc',
64
- e: (0, malloy_types_1.mkTemporal)(exprVal.value, exprVal.dataType),
86
+ e: (0, malloy_types_1.mkTemporal)(exprVal.value, exprVal.type),
65
87
  units: timeframe,
66
88
  };
67
89
  }
68
90
  return tsVal;
69
91
  }
70
- if (exprVal.dataType !== 'error') {
71
- this.logError('unsupported-type-for-time-truncation', `Cannot do time truncation on type '${exprVal.dataType}'`);
92
+ if (exprVal.type !== 'error') {
93
+ this.logError('unsupported-type-for-time-truncation', `Cannot do time truncation on type '${exprVal.type}'`);
72
94
  }
73
- const returnType = exprVal.dataType === 'error'
74
- ? (0, malloy_types_1.isDateUnit)(timeframe)
95
+ const returnType = { ...exprVal };
96
+ if (exprVal.type === 'error') {
97
+ returnType.type = (0, malloy_types_1.isDateUnit)(timeframe)
75
98
  ? 'date'
76
- : 'timestamp'
77
- : exprVal.dataType;
99
+ : 'timestamp';
100
+ }
78
101
  return {
79
- ...exprVal,
80
- dataType: returnType,
102
+ ...returnType,
81
103
  value: (0, ast_utils_1.errorFor)('granularity typecheck').value,
82
104
  evalSpace: 'constant',
83
105
  };
@@ -100,7 +122,7 @@ class ExprGranularTime extends expression_def_1.ExpressionDef {
100
122
  toRange(fs) {
101
123
  const begin = this.getExpression(fs);
102
124
  const one = { node: 'numberLiteral', literal: '1' };
103
- if (begin.dataType === 'timestamp') {
125
+ if (begin.type === 'timestamp') {
104
126
  const beginTS = expr_time_1.ExprTime.fromValue('timestamp', begin);
105
127
  const endTS = new expr_time_1.ExprTime('timestamp', (0, time_utils_1.timeOffset)('timestamp', begin.value, '+', one, this.units), [begin]);
106
128
  return new range_1.Range(beginTS, endTS);
@@ -21,15 +21,38 @@
21
21
  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
22
  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
23
  */
24
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
25
+ if (k2 === undefined) k2 = k;
26
+ var desc = Object.getOwnPropertyDescriptor(m, k);
27
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
28
+ desc = { enumerable: true, get: function() { return m[k]; } };
29
+ }
30
+ Object.defineProperty(o, k2, desc);
31
+ }) : (function(o, m, k, k2) {
32
+ if (k2 === undefined) k2 = k;
33
+ o[k2] = m[k];
34
+ }));
35
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
36
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
37
+ }) : function(o, v) {
38
+ o["default"] = v;
39
+ });
40
+ var __importStar = (this && this.__importStar) || function (mod) {
41
+ if (mod && mod.__esModule) return mod;
42
+ var result = {};
43
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
44
+ __setModuleDefault(result, mod);
45
+ return result;
46
+ };
24
47
  Object.defineProperty(exports, "__esModule", { value: true });
25
48
  exports.ExprLogicalOp = void 0;
26
49
  const binary_boolean_1 = require("./binary-boolean");
27
- const fragtype_utils_1 = require("../fragtype-utils");
50
+ const TDU = __importStar(require("../typedesc-utils"));
28
51
  class ExprLogicalOp extends binary_boolean_1.BinaryBoolean {
29
52
  constructor() {
30
53
  super(...arguments);
31
54
  this.elementType = 'logical operator';
32
- this.legalChildTypes = [fragtype_utils_1.FT.boolT, fragtype_utils_1.FT.aggregateBoolT];
55
+ this.legalChildTypes = [TDU.boolT, TDU.aggregateBoolT];
33
56
  }
34
57
  }
35
58
  exports.ExprLogicalOp = ExprLogicalOp;
@@ -1,9 +1,8 @@
1
- import { ExprValue } from '../types/expr-value';
2
- import { FieldValueType } from '../../../model';
3
1
  import { ExprAggregateFunction } from './expr-aggregate-function';
4
2
  import { ExpressionDef } from '../types/expression-def';
3
+ import { ExprValue } from '../types/expr-value';
5
4
  export declare class ExprMax extends ExprAggregateFunction {
6
- legalChildTypes: import("../../../model").TypeDesc[];
5
+ legalChildTypes: import("../../..").TypeDesc[];
7
6
  constructor(expr: ExpressionDef);
8
- returns(forExpression: ExprValue): FieldValueType;
7
+ returns(ev: ExprValue): ExprValue;
9
8
  }
@@ -21,17 +21,40 @@
21
21
  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
22
  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
23
  */
24
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
25
+ if (k2 === undefined) k2 = k;
26
+ var desc = Object.getOwnPropertyDescriptor(m, k);
27
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
28
+ desc = { enumerable: true, get: function() { return m[k]; } };
29
+ }
30
+ Object.defineProperty(o, k2, desc);
31
+ }) : (function(o, m, k, k2) {
32
+ if (k2 === undefined) k2 = k;
33
+ o[k2] = m[k];
34
+ }));
35
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
36
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
37
+ }) : function(o, v) {
38
+ o["default"] = v;
39
+ });
40
+ var __importStar = (this && this.__importStar) || function (mod) {
41
+ if (mod && mod.__esModule) return mod;
42
+ var result = {};
43
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
44
+ __setModuleDefault(result, mod);
45
+ return result;
46
+ };
24
47
  Object.defineProperty(exports, "__esModule", { value: true });
25
48
  exports.ExprMax = void 0;
26
- const fragtype_utils_1 = require("../fragtype-utils");
49
+ const TDU = __importStar(require("../typedesc-utils"));
27
50
  const expr_aggregate_function_1 = require("./expr-aggregate-function");
28
51
  class ExprMax extends expr_aggregate_function_1.ExprAggregateFunction {
29
52
  constructor(expr) {
30
53
  super('max', expr);
31
- this.legalChildTypes = [fragtype_utils_1.FT.numberT, fragtype_utils_1.FT.stringT, fragtype_utils_1.FT.dateT, fragtype_utils_1.FT.timestampT];
54
+ this.legalChildTypes = [TDU.numberT, TDU.stringT, TDU.dateT, TDU.timestampT];
32
55
  }
33
- returns(forExpression) {
34
- return forExpression.dataType;
56
+ returns(ev) {
57
+ return ev;
35
58
  }
36
59
  }
37
60
  exports.ExprMax = ExprMax;
@@ -1,9 +1,8 @@
1
- import { ExprValue } from '../types/expr-value';
2
- import { FieldValueType } from '../../../model';
3
1
  import { ExprAggregateFunction } from './expr-aggregate-function';
4
2
  import { ExpressionDef } from '../types/expression-def';
3
+ import { ExprValue } from '../types/expr-value';
5
4
  export declare class ExprMin extends ExprAggregateFunction {
6
- legalChildTypes: import("../../../model").TypeDesc[];
5
+ legalChildTypes: import("../../..").TypeDesc[];
7
6
  constructor(expr: ExpressionDef);
8
- returns(forExpression: ExprValue): FieldValueType;
7
+ returns(ev: ExprValue): ExprValue;
9
8
  }
@@ -21,17 +21,40 @@
21
21
  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
22
  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
23
  */
24
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
25
+ if (k2 === undefined) k2 = k;
26
+ var desc = Object.getOwnPropertyDescriptor(m, k);
27
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
28
+ desc = { enumerable: true, get: function() { return m[k]; } };
29
+ }
30
+ Object.defineProperty(o, k2, desc);
31
+ }) : (function(o, m, k, k2) {
32
+ if (k2 === undefined) k2 = k;
33
+ o[k2] = m[k];
34
+ }));
35
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
36
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
37
+ }) : function(o, v) {
38
+ o["default"] = v;
39
+ });
40
+ var __importStar = (this && this.__importStar) || function (mod) {
41
+ if (mod && mod.__esModule) return mod;
42
+ var result = {};
43
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
44
+ __setModuleDefault(result, mod);
45
+ return result;
46
+ };
24
47
  Object.defineProperty(exports, "__esModule", { value: true });
25
48
  exports.ExprMin = void 0;
26
- const fragtype_utils_1 = require("../fragtype-utils");
49
+ const TDU = __importStar(require("../typedesc-utils"));
27
50
  const expr_aggregate_function_1 = require("./expr-aggregate-function");
28
51
  class ExprMin extends expr_aggregate_function_1.ExprAggregateFunction {
29
52
  constructor(expr) {
30
53
  super('min', expr);
31
- this.legalChildTypes = [fragtype_utils_1.FT.numberT, fragtype_utils_1.FT.stringT, fragtype_utils_1.FT.dateT, fragtype_utils_1.FT.timestampT];
54
+ this.legalChildTypes = [TDU.numberT, TDU.stringT, TDU.dateT, TDU.timestampT];
32
55
  }
33
- returns(forExpression) {
34
- return forExpression.dataType;
56
+ returns(ev) {
57
+ return ev;
35
58
  }
36
59
  }
37
60
  exports.ExprMin = ExprMin;