@malloydata/malloy 0.0.204 → 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 (90) 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/dist/version.d.ts +1 -1
  87. package/dist/version.js +1 -1
  88. package/package.json +1 -1
  89. package/dist/lang/ast/fragtype-utils.d.ts +0 -46
  90. package/dist/lang/ast/fragtype-utils.js +0 -115
@@ -1,4 +1,4 @@
1
- import { FunctionParameterDef, FieldValueType, TypeDesc, Expr, FunctionParamTypeDesc, ExpressionValueType } from '../../model/malloy_types';
1
+ import { FunctionParameterDef, TypeDesc, Expr, FunctionParamTypeDesc, LeafExpressionType } from '../../model/malloy_types';
2
2
  import { SQLExprElement } from '../../model/utils';
3
3
  export interface DialectFunctionOverloadDef {
4
4
  returnType: TypeDesc;
@@ -29,14 +29,14 @@ export declare function makeParam(name: string, ...allowedTypes: FunctionParamTy
29
29
  param: FunctionParameterDef;
30
30
  arg: Expr;
31
31
  };
32
- export declare function maxScalar(dataType: FieldValueType): TypeDesc;
33
- export declare function maxAggregate(dataType: FieldValueType): TypeDesc;
34
- export declare function anyExprType(dataType: FieldValueType): FunctionParamTypeDesc;
35
- export declare function maxUngroupedAggregate(dataType: FieldValueType): FunctionParamTypeDesc;
36
- export declare function maxAnalytic(dataType: FieldValueType): FunctionParamTypeDesc;
37
- export declare function minScalar(dataType: FieldValueType): TypeDesc;
38
- export declare function minAggregate(dataType: FieldValueType): TypeDesc;
39
- export declare function minAnalytic(dataType: FieldValueType): TypeDesc;
32
+ export declare function maxScalar(type: LeafExpressionType): TypeDesc;
33
+ export declare function maxAggregate(type: LeafExpressionType): TypeDesc;
34
+ export declare function anyExprType(type: LeafExpressionType): FunctionParamTypeDesc;
35
+ export declare function maxUngroupedAggregate(type: LeafExpressionType): FunctionParamTypeDesc;
36
+ export declare function maxAnalytic(type: LeafExpressionType): FunctionParamTypeDesc;
37
+ export declare function minScalar(type: LeafExpressionType): TypeDesc;
38
+ export declare function minAggregate(type: LeafExpressionType): TypeDesc;
39
+ export declare function minAnalytic(type: LeafExpressionType): TypeDesc;
40
40
  export declare function overload(returnType: TypeDesc, params: FunctionParameterDef[], e: Expr, options?: {
41
41
  needsWindowOrderBy?: boolean;
42
42
  between?: {
@@ -48,26 +48,26 @@ export declare function overload(returnType: TypeDesc, params: FunctionParameter
48
48
  defaultOrderByArgIndex?: number;
49
49
  supportsOrderBy?: boolean | 'only_default';
50
50
  }): DialectFunctionOverloadDef;
51
- export type TypeDescBlueprint = ExpressionValueType | {
51
+ export type TypeDescBlueprint = LeafExpressionType | {
52
52
  generic: string;
53
53
  } | {
54
- literal: ExpressionValueType | {
54
+ literal: LeafExpressionType | {
55
55
  generic: string;
56
56
  };
57
57
  } | {
58
- constant: ExpressionValueType | {
58
+ constant: LeafExpressionType | {
59
59
  generic: string;
60
60
  };
61
61
  } | {
62
- dimension: ExpressionValueType | {
62
+ dimension: LeafExpressionType | {
63
63
  generic: string;
64
64
  };
65
65
  } | {
66
- measure: ExpressionValueType | {
66
+ measure: LeafExpressionType | {
67
67
  generic: string;
68
68
  };
69
69
  } | {
70
- calculation: ExpressionValueType | {
70
+ calculation: LeafExpressionType | {
71
71
  generic: string;
72
72
  };
73
73
  };
@@ -75,7 +75,7 @@ type ParamTypeBlueprint = TypeDescBlueprint | TypeDescBlueprint[] | {
75
75
  variadic: TypeDescBlueprint | TypeDescBlueprint[];
76
76
  };
77
77
  export interface SignatureBlueprint {
78
- generic?: [string, ExpressionValueType[]];
78
+ generic?: [string, LeafExpressionType[]];
79
79
  takes: {
80
80
  [name: string]: ParamTypeBlueprint;
81
81
  };
@@ -103,68 +103,36 @@ function makeParam(name, ...allowedTypes) {
103
103
  return { param: param(name, ...allowedTypes), arg: arg(name) };
104
104
  }
105
105
  exports.makeParam = makeParam;
106
- function maxScalar(dataType) {
107
- return {
108
- dataType,
109
- expressionType: 'scalar',
110
- evalSpace: 'input',
111
- };
106
+ function maxScalar(type) {
107
+ return { type, expressionType: 'scalar', evalSpace: 'input' };
112
108
  }
113
109
  exports.maxScalar = maxScalar;
114
- function maxAggregate(dataType) {
115
- return {
116
- dataType,
117
- expressionType: 'aggregate',
118
- evalSpace: 'input',
119
- };
110
+ function maxAggregate(type) {
111
+ return { type, expressionType: 'aggregate', evalSpace: 'input' };
120
112
  }
121
113
  exports.maxAggregate = maxAggregate;
122
- function anyExprType(dataType) {
123
- return {
124
- dataType,
125
- expressionType: undefined,
126
- evalSpace: 'input',
127
- };
114
+ function anyExprType(type) {
115
+ return { type, expressionType: undefined, evalSpace: 'input' };
128
116
  }
129
117
  exports.anyExprType = anyExprType;
130
- function maxUngroupedAggregate(dataType) {
131
- return {
132
- dataType,
133
- expressionType: 'ungrouped_aggregate',
134
- evalSpace: 'input',
135
- };
118
+ function maxUngroupedAggregate(type) {
119
+ return { type, expressionType: 'ungrouped_aggregate', evalSpace: 'input' };
136
120
  }
137
121
  exports.maxUngroupedAggregate = maxUngroupedAggregate;
138
- function maxAnalytic(dataType) {
139
- return {
140
- dataType,
141
- expressionType: 'aggregate_analytic',
142
- evalSpace: 'input',
143
- };
122
+ function maxAnalytic(type) {
123
+ return { type, expressionType: 'aggregate_analytic', evalSpace: 'input' };
144
124
  }
145
125
  exports.maxAnalytic = maxAnalytic;
146
- function minScalar(dataType) {
147
- return {
148
- dataType,
149
- expressionType: 'scalar',
150
- evalSpace: 'input',
151
- };
126
+ function minScalar(type) {
127
+ return { type, expressionType: 'scalar', evalSpace: 'input' };
152
128
  }
153
129
  exports.minScalar = minScalar;
154
- function minAggregate(dataType) {
155
- return {
156
- dataType,
157
- expressionType: 'aggregate',
158
- evalSpace: 'input',
159
- };
130
+ function minAggregate(type) {
131
+ return { type, expressionType: 'aggregate', evalSpace: 'input' };
160
132
  }
161
133
  exports.minAggregate = minAggregate;
162
- function minAnalytic(dataType) {
163
- return {
164
- dataType,
165
- expressionType: 'scalar_analytic',
166
- evalSpace: 'input',
167
- };
134
+ function minAnalytic(type) {
135
+ return { type, expressionType: 'scalar_analytic', evalSpace: 'input' };
168
136
  }
169
137
  exports.minAnalytic = minAnalytic;
170
138
  function overload(returnType, params, e, options) {
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export { DuckDBDialect, StandardSQLDialect, TrinoDialect, PostgresDialect, SnowflakeDialect, MySQLDialect, registerDialect, arg, qtz, overload, minScalar, anyExprType, minAggregate, maxScalar, sql, makeParam, param, variadicParam, literal, spread, Dialect, } from './dialect';
2
2
  export type { DialectFieldList, DialectFunctionOverloadDef, QueryInfo, MalloyStandardFunctionImplementations, DefinitionBlueprint, DefinitionBlueprintMap, OverloadedDefinitionBlueprint, } from './dialect';
3
- export type { QueryDataRow, StructDef, TableSourceDef, SQLSourceDef, SourceDef, JoinFieldDef, NamedSourceDefs, MalloyQueryData, DateUnit, ExtractUnit, TimestampUnit, TemporalFieldType, QueryData, QueryValue, Expr, FilterCondition, SQLSentence, FieldDef, PipeSegment, QueryFieldDef, IndexFieldDef, TurtleDef, SearchValueMapResult, SearchIndexResult, ModelDef, Query, QueryResult, QueryRunStats, NamedQuery, NamedModelObject, ExpressionType, FunctionDef, FunctionOverloadDef, FunctionParameterDef, ExpressionValueType, TypeDesc, FieldValueType, ExpressionTypeDesc, FunctionParamTypeDesc, DocumentLocation, DocumentRange, DocumentPosition, Sampling, Annotation, LeafAtomicTypeDef, LeafAtomicDef, AtomicTypeDef, AtomicFieldDef, ArrayDef, ArrayTypeDef, RecordTypeDef, RepeatedRecordTypeDef, } from './model';
3
+ export type { QueryDataRow, StructDef, TableSourceDef, SQLSourceDef, SourceDef, JoinFieldDef, NamedSourceDefs, MalloyQueryData, DateUnit, ExtractUnit, TimestampUnit, TemporalFieldType, QueryData, QueryValue, Expr, FilterCondition, SQLSentence, FieldDef, PipeSegment, QueryFieldDef, IndexFieldDef, TurtleDef, SearchValueMapResult, SearchIndexResult, ModelDef, Query, QueryResult, QueryRunStats, NamedQuery, NamedModelObject, ExpressionType, FunctionDef, FunctionOverloadDef, FunctionParameterDef, ExpressionValueType, TypeDesc, FunctionParamTypeDesc, DocumentLocation, DocumentRange, DocumentPosition, Sampling, Annotation, LeafAtomicTypeDef, LeafAtomicDef, AtomicTypeDef, AtomicFieldDef, ArrayDef, ArrayTypeDef, RecordTypeDef, RepeatedRecordTypeDef, } from './model';
4
4
  export { arrayEachFields, isRepeatedRecord, isSourceDef, Segment, isLeafAtomic, isJoined, isJoinedSource, isSamplingEnable, isSamplingPercent, isSamplingRows, expressionIsAggregate, expressionIsAnalytic, expressionIsCalculation, expressionIsScalar, expressionIsUngroupedAggregate, indent, composeSQLExpr, } from './model';
5
5
  export { MalloyTranslator, } from './lang';
6
6
  export type { LogMessage, TranslateResponse } from './lang';
@@ -33,7 +33,7 @@ exports.errorFor = void 0;
33
33
  */
34
34
  function errorFor(reason) {
35
35
  return {
36
- dataType: 'error',
36
+ type: 'error',
37
37
  expressionType: 'scalar',
38
38
  value: { node: 'error', message: reason },
39
39
  evalSpace: 'constant',
@@ -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.BinaryBoolean = void 0;
26
49
  const ast_utils_1 = require("../ast-utils");
27
- const fragtype_utils_1 = require("../fragtype-utils");
50
+ const TDU = __importStar(require("../typedesc-utils"));
28
51
  const binary_operators_1 = require("../types/binary_operators");
29
52
  const expr_value_1 = require("../types/expr-value");
30
53
  const expression_def_1 = require("../types/expression-def");
@@ -35,14 +58,14 @@ class BinaryBoolean extends expression_def_1.ExpressionDef {
35
58
  this.op = op;
36
59
  this.right = right;
37
60
  this.elementType = 'abstract boolean binary';
38
- this.legalChildTypes = [fragtype_utils_1.FT.boolT];
61
+ this.legalChildTypes = [TDU.boolT];
39
62
  }
40
63
  getExpression(fs) {
41
64
  const left = this.left.getExpression(fs);
42
65
  const right = this.right.getExpression(fs);
43
66
  if (this.typeCheck(this.left, left) && this.typeCheck(this.right, right)) {
44
67
  return (0, expr_value_1.computedExprValue)({
45
- dataType: 'boolean',
68
+ dataType: { type: 'boolean' },
46
69
  value: {
47
70
  node: (0, binary_operators_1.getExprNode)(this.op),
48
71
  kids: { left: left.value, right: right.value },
@@ -50,7 +73,7 @@ class BinaryBoolean extends expression_def_1.ExpressionDef {
50
73
  from: [left, right],
51
74
  });
52
75
  }
53
- return (0, ast_utils_1.errorFor)('logial required boolean');
76
+ return (0, ast_utils_1.errorFor)('logical-op expected boolean');
54
77
  }
55
78
  }
56
79
  exports.BinaryBoolean = BinaryBoolean;
@@ -21,9 +21,32 @@
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.BinaryNumeric = void 0;
26
- const fragtype_utils_1 = require("../fragtype-utils");
49
+ const TDU = __importStar(require("../typedesc-utils"));
27
50
  const expression_def_1 = require("../types/expression-def");
28
51
  class BinaryNumeric extends expression_def_1.ExpressionDef {
29
52
  constructor(left, op, right) {
@@ -32,7 +55,7 @@ class BinaryNumeric extends expression_def_1.ExpressionDef {
32
55
  this.op = op;
33
56
  this.right = right;
34
57
  this.elementType = 'numeric binary abstract';
35
- this.legalChildTypes = [fragtype_utils_1.FT.numberT];
58
+ this.legalChildTypes = [TDU.numberT];
36
59
  }
37
60
  getExpression(fs) {
38
61
  return this.right.apply(fs, this.op, this.left);
@@ -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.Boolean = void 0;
26
49
  const expression_def_1 = require("../types/expression-def");
27
- const fragtype_utils_1 = require("../fragtype-utils");
50
+ const TDU = __importStar(require("../typedesc-utils"));
28
51
  class Boolean extends expression_def_1.ExpressionDef {
29
52
  constructor(value) {
30
53
  super();
@@ -32,7 +55,7 @@ class Boolean extends expression_def_1.ExpressionDef {
32
55
  this.elementType = 'boolean literal';
33
56
  }
34
57
  getExpression() {
35
- return { ...fragtype_utils_1.FT.boolT, value: { node: this.value } };
58
+ return { ...TDU.boolT, value: { node: this.value } };
36
59
  }
37
60
  }
38
61
  exports.Boolean = Boolean;
@@ -5,16 +5,37 @@
5
5
  * This source code is licensed under the MIT license found in the
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
+ if (k2 === undefined) k2 = k;
10
+ var desc = Object.getOwnPropertyDescriptor(m, k);
11
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
12
+ desc = { enumerable: true, get: function() { return m[k]; } };
13
+ }
14
+ Object.defineProperty(o, k2, desc);
15
+ }) : (function(o, m, k, k2) {
16
+ if (k2 === undefined) k2 = k;
17
+ o[k2] = m[k];
18
+ }));
19
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
20
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
21
+ }) : function(o, v) {
22
+ o["default"] = v;
23
+ });
24
+ var __importStar = (this && this.__importStar) || function (mod) {
25
+ if (mod && mod.__esModule) return mod;
26
+ var result = {};
27
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
28
+ __setModuleDefault(result, mod);
29
+ return result;
30
+ };
8
31
  Object.defineProperty(exports, "__esModule", { value: true });
9
32
  exports.CaseWhen = exports.Case = void 0;
10
33
  const expr_value_1 = require("../types/expr-value");
11
34
  const expression_def_1 = require("../types/expression-def");
12
35
  const malloy_element_1 = require("../types/malloy-element");
13
- const fragtype_utils_1 = require("../fragtype-utils");
36
+ const TDU = __importStar(require("../typedesc-utils"));
14
37
  function typeCoalesce(ev1, ev2) {
15
- return ev1 === undefined ||
16
- ev1.dataType === 'null' ||
17
- ev1.dataType === 'error'
38
+ return ev1 === undefined || ev1.type === 'null' || ev1.type === 'error'
18
39
  ? ev2
19
40
  : ev1;
20
41
  }
@@ -28,7 +49,6 @@ class Case extends expression_def_1.ExpressionDef {
28
49
  this.has({ elseValue, value });
29
50
  }
30
51
  getExpression(fs) {
31
- var _a;
32
52
  const resultExpr = {
33
53
  node: 'case',
34
54
  kids: {
@@ -39,9 +59,10 @@ class Case extends expression_def_1.ExpressionDef {
39
59
  const dependents = [];
40
60
  let value = undefined;
41
61
  if (this.value) {
42
- value = this.value.getExpression(fs);
43
- dependents.push(value);
44
- resultExpr.kids.caseValue = value.value;
62
+ const v = this.value.getExpression(fs);
63
+ dependents.push(v);
64
+ resultExpr.kids.caseValue = v.value;
65
+ value = v;
45
66
  }
46
67
  const choiceValues = [];
47
68
  for (const c of this.choices) {
@@ -53,24 +74,24 @@ class Case extends expression_def_1.ExpressionDef {
53
74
  let returnType;
54
75
  for (const aChoice of choiceValues) {
55
76
  if (value !== undefined) {
56
- if (!fragtype_utils_1.FT.typeEq(aChoice.when, value)) {
77
+ if (!TDU.typeEq(aChoice.when, value)) {
57
78
  return this.loggedErrorExpr('case-when-type-does-not-match', {
58
- whenType: aChoice.when.dataType,
59
- valueType: value.dataType,
79
+ whenType: aChoice.when.type,
80
+ valueType: value.type,
60
81
  });
61
82
  }
62
83
  }
63
84
  else {
64
- if (!fragtype_utils_1.FT.typeEq(aChoice.when, fragtype_utils_1.FT.boolT)) {
85
+ if (!TDU.typeEq(aChoice.when, TDU.boolT)) {
65
86
  return this.loggedErrorExpr('case-when-must-be-boolean', {
66
- whenType: aChoice.when.dataType,
87
+ whenType: aChoice.when.type,
67
88
  });
68
89
  }
69
90
  }
70
- if (returnType && !fragtype_utils_1.FT.typeEq(returnType, aChoice.then, true)) {
91
+ if (returnType && !TDU.typeEq(returnType, aChoice.then, true)) {
71
92
  return this.loggedErrorExpr('case-then-type-does-not-match', {
72
- thenType: aChoice.then.dataType,
73
- returnType: returnType.dataType,
93
+ thenType: aChoice.then.type,
94
+ returnType: returnType.type,
74
95
  });
75
96
  }
76
97
  returnType = typeCoalesce(returnType, aChoice.then);
@@ -79,10 +100,10 @@ class Case extends expression_def_1.ExpressionDef {
79
100
  }
80
101
  if (this.elseValue) {
81
102
  const elseValue = this.elseValue.getExpression(fs);
82
- if (returnType && !fragtype_utils_1.FT.typeEq(returnType, elseValue, true)) {
103
+ if (returnType && !TDU.typeEq(returnType, elseValue, true)) {
83
104
  return this.loggedErrorExpr('case-else-type-does-not-match', {
84
- elseType: elseValue.dataType,
85
- returnType: returnType.dataType,
105
+ elseType: elseValue.type,
106
+ returnType: returnType.type,
86
107
  });
87
108
  }
88
109
  returnType = typeCoalesce(returnType, elseValue);
@@ -91,7 +112,7 @@ class Case extends expression_def_1.ExpressionDef {
91
112
  }
92
113
  return (0, expr_value_1.computedExprValue)({
93
114
  value: resultExpr,
94
- dataType: (_a = returnType === null || returnType === void 0 ? void 0 : returnType.dataType) !== null && _a !== void 0 ? _a : 'null',
115
+ dataType: returnType ? TDU.atomicDef(returnType) : { type: 'null' },
95
116
  from: dependents,
96
117
  });
97
118
  }
@@ -1,4 +1,4 @@
1
- import { AggregateFunctionType, FieldValueType } from '../../../model/malloy_types';
1
+ import { AggregateFunctionType } from '../../../model/malloy_types';
2
2
  import { FieldReference } from '../query-items/field-references';
3
3
  import { ExprValue } from '../types/expr-value';
4
4
  import { ExpressionDef } from '../types/expression-def';
@@ -12,7 +12,7 @@ export declare abstract class ExprAggregateFunction extends ExpressionDef {
12
12
  explicitSource?: boolean;
13
13
  legalChildTypes: import("../../../model/malloy_types").TypeDesc[];
14
14
  constructor(func: AggregateFunctionType, expr?: ExpressionDef, explicitSource?: boolean);
15
- returns(_forExpression: ExprValue): FieldValueType;
15
+ abstract returns(fromExpr: ExprValue): ExprValue;
16
16
  getExpression(fs: FieldSpace): ExprValue;
17
17
  isSymmetricFunction(): boolean;
18
18
  getJoinUsage(fs: FieldSpace): JoinPath[];
@@ -21,13 +21,36 @@
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.ExprAggregateFunction = void 0;
26
49
  const malloy_types_1 = require("../../../model/malloy_types");
27
50
  const utils_1 = require("../../../model/utils");
28
51
  const ast_utils_1 = require("../ast-utils");
29
52
  const static_space_1 = require("../field-space/static-space");
30
- const fragtype_utils_1 = require("../fragtype-utils");
53
+ const TDU = __importStar(require("../typedesc-utils"));
31
54
  const field_references_1 = require("../query-items/field-references");
32
55
  const expression_def_1 = require("../types/expression-def");
33
56
  const space_field_1 = require("../types/space-field");
@@ -36,7 +59,7 @@ class ExprAggregateFunction extends expression_def_1.ExpressionDef {
36
59
  constructor(func, expr, explicitSource) {
37
60
  super();
38
61
  this.func = func;
39
- this.legalChildTypes = [fragtype_utils_1.FT.numberT];
62
+ this.legalChildTypes = [TDU.numberT];
40
63
  this.elementType = func;
41
64
  this.explicitSource = explicitSource;
42
65
  if (expr) {
@@ -44,9 +67,6 @@ class ExprAggregateFunction extends expression_def_1.ExpressionDef {
44
67
  this.has({ expr: expr });
45
68
  }
46
69
  }
47
- returns(_forExpression) {
48
- return 'number';
49
- }
50
70
  getExpression(fs) {
51
71
  var _a, _b, _c;
52
72
  // It is never useful to use output fields in an aggregate expression
@@ -63,10 +83,10 @@ class ExprAggregateFunction extends expression_def_1.ExpressionDef {
63
83
  const sourceFoot = result.found;
64
84
  const footType = sourceFoot.typeDesc();
65
85
  if (!(sourceFoot instanceof static_space_1.StructSpaceField)) {
66
- if ((0, malloy_types_1.isAtomicFieldType)(footType.dataType)) {
86
+ if ((0, malloy_types_1.isAtomicFieldType)(footType.type)) {
67
87
  expr = this.source;
68
88
  exprVal = {
69
- dataType: footType.dataType,
89
+ ...TDU.atomicDef(footType),
70
90
  expressionType: footType.expressionType,
71
91
  value: footType.evalSpace === 'output'
72
92
  ? { node: 'outputField', name: this.source.refString }
@@ -87,7 +107,7 @@ class ExprAggregateFunction extends expression_def_1.ExpressionDef {
87
107
  }
88
108
  }
89
109
  else {
90
- return this.loggedErrorExpr('invalid-aggregate-source', `Aggregate source cannot be a ${footType.dataType}`);
110
+ return this.loggedErrorExpr('invalid-aggregate-source', `Aggregate source cannot be a ${footType.type}`);
91
111
  }
92
112
  }
93
113
  }
@@ -101,7 +121,7 @@ class ExprAggregateFunction extends expression_def_1.ExpressionDef {
101
121
  if ((0, malloy_types_1.expressionIsAggregate)(exprVal.expressionType)) {
102
122
  return this.loggedErrorExpr('aggregate-of-aggregate', 'Aggregate expression cannot be aggregate');
103
123
  }
104
- const isAnError = exprVal.dataType === 'error';
124
+ const isAnError = exprVal.type === 'error';
105
125
  if (!isAnError) {
106
126
  const joinUsage = this.getJoinUsage(inputFS);
107
127
  // Did the user spceify a source, either as `source.agg()` or `path.to.join.agg()` or `path.to.field.agg()`
@@ -141,7 +161,7 @@ class ExprAggregateFunction extends expression_def_1.ExpressionDef {
141
161
  f.structPath = structPath;
142
162
  }
143
163
  return {
144
- dataType: this.returns(exprVal),
164
+ ...this.returns(exprVal),
145
165
  expressionType: 'aggregate',
146
166
  value: f,
147
167
  evalSpace: 'output',
@@ -77,7 +77,7 @@ class ExprAlternationTree extends expression_def_1.ExpressionDef {
77
77
  const isIn = expr.getExpression(fs);
78
78
  const values = inList.map(v => v.getExpression(fs));
79
79
  return (0, expr_value_1.computedExprValue)({
80
- dataType: 'boolean',
80
+ dataType: { type: 'boolean' },
81
81
  value: {
82
82
  node: 'in',
83
83
  not: applyOp === '!=',
@@ -93,7 +93,7 @@ class ExprAlternationTree extends expression_def_1.ExpressionDef {
93
93
  const choice1 = this.left.apply(fs, applyOp, expr);
94
94
  const choice2 = this.right.apply(fs, applyOp, expr);
95
95
  return (0, expr_value_1.computedExprValue)({
96
- dataType: 'boolean',
96
+ dataType: { type: 'boolean' },
97
97
  value: {
98
98
  node: this.op === '&' ? 'and' : 'or',
99
99
  kids: { left: choice1.value, right: choice2.value },
@@ -1,4 +1,5 @@
1
1
  import { FieldReference } from '../query-items/field-references';
2
+ import { ExprValue } from '../types/expr-value';
2
3
  import { ExpressionDef } from '../types/expression-def';
3
4
  import { ExprAggregateFunction } from './expr-aggregate-function';
4
5
  export declare abstract class ExprAsymmetric extends ExprAggregateFunction {
@@ -7,5 +8,6 @@ export declare abstract class ExprAsymmetric extends ExprAggregateFunction {
7
8
  readonly source?: FieldReference | undefined;
8
9
  constructor(func: 'sum' | 'avg', expr: ExpressionDef | undefined, source?: FieldReference | undefined, explicitSource?: boolean);
9
10
  isSymmetricFunction(): boolean;
11
+ returns(ev: ExprValue): ExprValue;
10
12
  defaultFieldName(): undefined | string;
11
13
  }
@@ -35,6 +35,9 @@ class ExprAsymmetric extends expr_aggregate_function_1.ExprAggregateFunction {
35
35
  isSymmetricFunction() {
36
36
  return false;
37
37
  }
38
+ returns(ev) {
39
+ return ev;
40
+ }
38
41
  defaultFieldName() {
39
42
  if (this.source && this.expr === undefined) {
40
43
  const tag = this.source.nameString;
@@ -36,17 +36,15 @@ class ExprCast extends expression_def_1.ExpressionDef {
36
36
  }
37
37
  getExpression(fs) {
38
38
  const expr = this.expr.getExpression(fs);
39
- let dataType = 'error';
39
+ let dataType = { type: 'error' };
40
40
  if (typeof this.castType === 'string') {
41
- dataType = this.castType;
41
+ dataType = { type: this.castType };
42
42
  }
43
43
  else {
44
44
  const dialect = fs.dialectObj();
45
45
  if (dialect) {
46
46
  if (dialect.validateTypeName(this.castType.raw)) {
47
- // TODO theoretically `sqlTypeToMalloyType` can get number subtypes,
48
- // but `TypeDesc` does not support them.
49
- dataType = dialect.sqlTypeToMalloyType(this.castType.raw).type;
47
+ dataType = dialect.sqlTypeToMalloyType(this.castType.raw);
50
48
  }
51
49
  else {
52
50
  this.logError('invalid-sql-native-type', `Cast type \`${this.castType.raw}\` is invalid for ${dialect.name} dialect`);
@@ -58,7 +56,7 @@ class ExprCast extends expression_def_1.ExpressionDef {
58
56
  }
59
57
  return (0, expr_value_1.computedExprValue)({
60
58
  dataType,
61
- value: (0, time_utils_1.castTo)(this.castType, expr.value, expr.dataType, this.safe),
59
+ value: (0, time_utils_1.castTo)(this.castType, expr.value, expr.type, this.safe),
62
60
  from: [expr],
63
61
  });
64
62
  }