@malloydata/malloy 0.0.414 → 0.0.416

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.
@@ -78,6 +78,7 @@ class ExprGranularTime extends expression_def_1.ExpressionDef {
78
78
  };
79
79
  }
80
80
  getExpression(fs) {
81
+ var _a;
81
82
  const timeframe = this.units;
82
83
  const exprVal = this.expr.getExpression(fs);
83
84
  let timeType;
@@ -113,7 +114,21 @@ class ExprGranularTime extends expression_def_1.ExpressionDef {
113
114
  return tsVal;
114
115
  }
115
116
  if (exprVal.type !== 'error') {
116
- this.logError('unsupported-type-for-time-truncation', `Cannot do time truncation on type '${exprVal.type}'`);
117
+ if (!(0, malloy_types_1.isBasicAtomicType)(exprVal.type)) {
118
+ // The truncation target has fields (a join/struct/record/array), so it
119
+ // can't be a time value. The likely intent is a field whose name is a
120
+ // time unit (e.g. `flight.year`); since `.year` parses as a truncation
121
+ // and time units are reserved words, that field has to be quoted.
122
+ const ref = this.expr.drillExpression();
123
+ const lhs = (ref === null || ref === void 0 ? void 0 : ref.kind) === 'field_reference'
124
+ ? [...((_a = ref.path) !== null && _a !== void 0 ? _a : []), ref.name].join('.')
125
+ : undefined;
126
+ const quoted = lhs ? `${lhs}.\`${timeframe}\`` : `\`${timeframe}\``;
127
+ this.logError('unsupported-type-for-time-truncation', `'.${timeframe}' is a time truncation, but ${lhs ? `'${lhs}'` : 'the left side'} is type '${exprVal.type}', not a time value. If '${timeframe}' is a field name it must be quoted, because it is a reserved word: ${quoted}`);
128
+ }
129
+ else {
130
+ this.logError('unsupported-type-for-time-truncation', `Cannot do time truncation on type '${exprVal.type}'`);
131
+ }
117
132
  }
118
133
  const returnType = { ...exprVal };
119
134
  if (exprVal.type === 'error') {
@@ -312,65 +312,67 @@ export declare class MalloyParser extends Parser {
312
312
  static readonly RULE_orderByStatement = 123;
313
313
  static readonly RULE_ordering = 124;
314
314
  static readonly RULE_orderBySpec = 125;
315
- static readonly RULE_limitStatement = 126;
316
- static readonly RULE_bySpec = 127;
317
- static readonly RULE_topStatement = 128;
318
- static readonly RULE_indexElement = 129;
319
- static readonly RULE_indexFields = 130;
320
- static readonly RULE_indexStatement = 131;
321
- static readonly RULE_sampleStatement = 132;
322
- static readonly RULE_timezoneStatement = 133;
323
- static readonly RULE_queryAnnotation = 134;
324
- static readonly RULE_sampleSpec = 135;
325
- static readonly RULE_aggregate = 136;
326
- static readonly RULE_malloyType = 137;
327
- static readonly RULE_malloyBasicType = 138;
328
- static readonly RULE_malloyRecordType = 139;
329
- static readonly RULE_malloyRecordField = 140;
330
- static readonly RULE_compareOp = 141;
331
- static readonly RULE_string = 142;
332
- static readonly RULE_shortString = 143;
333
- static readonly RULE_rawString = 144;
334
- static readonly RULE_numericLiteral = 145;
335
- static readonly RULE_literal = 146;
336
- static readonly RULE_dateLiteral = 147;
337
- static readonly RULE_tablePath = 148;
338
- static readonly RULE_tableURI = 149;
339
- static readonly RULE_id = 150;
340
- static readonly RULE_timeframe = 151;
341
- static readonly RULE_ungroup = 152;
342
- static readonly RULE_malloyOrSQLType = 153;
343
- static readonly RULE_fieldExpr = 154;
344
- static readonly RULE_partialCompare = 155;
345
- static readonly RULE_partialTest = 156;
346
- static readonly RULE_partialAllowedFieldExpr = 157;
347
- static readonly RULE_fieldExprList = 158;
348
- static readonly RULE_pickStatement = 159;
349
- static readonly RULE_pick = 160;
350
- static readonly RULE_caseStatement = 161;
351
- static readonly RULE_caseWhen = 162;
352
- static readonly RULE_recordKey = 163;
353
- static readonly RULE_recordElement = 164;
354
- static readonly RULE_argumentList = 165;
355
- static readonly RULE_fieldNameList = 166;
356
- static readonly RULE_fieldCollection = 167;
357
- static readonly RULE_collectionWildCard = 168;
358
- static readonly RULE_starQualified = 169;
359
- static readonly RULE_taggedRef = 170;
360
- static readonly RULE_refExpr = 171;
361
- static readonly RULE_collectionMember = 172;
362
- static readonly RULE_fieldPath = 173;
363
- static readonly RULE_joinName = 174;
364
- static readonly RULE_fieldName = 175;
365
- static readonly RULE_sqlExploreNameRef = 176;
366
- static readonly RULE_nameSQLBlock = 177;
367
- static readonly RULE_connectionName = 178;
368
- static readonly RULE_tripFilterString = 179;
369
- static readonly RULE_tickFilterString = 180;
370
- static readonly RULE_filterString = 181;
371
- static readonly RULE_debugExpr = 182;
372
- static readonly RULE_debugPartial = 183;
373
- static readonly RULE_experimentalStatementForTesting = 184;
315
+ static readonly RULE_possibleBadPath = 126;
316
+ static readonly RULE_badWord = 127;
317
+ static readonly RULE_limitStatement = 128;
318
+ static readonly RULE_bySpec = 129;
319
+ static readonly RULE_topStatement = 130;
320
+ static readonly RULE_indexElement = 131;
321
+ static readonly RULE_indexFields = 132;
322
+ static readonly RULE_indexStatement = 133;
323
+ static readonly RULE_sampleStatement = 134;
324
+ static readonly RULE_timezoneStatement = 135;
325
+ static readonly RULE_queryAnnotation = 136;
326
+ static readonly RULE_sampleSpec = 137;
327
+ static readonly RULE_aggregate = 138;
328
+ static readonly RULE_malloyType = 139;
329
+ static readonly RULE_malloyBasicType = 140;
330
+ static readonly RULE_malloyRecordType = 141;
331
+ static readonly RULE_malloyRecordField = 142;
332
+ static readonly RULE_compareOp = 143;
333
+ static readonly RULE_string = 144;
334
+ static readonly RULE_shortString = 145;
335
+ static readonly RULE_rawString = 146;
336
+ static readonly RULE_numericLiteral = 147;
337
+ static readonly RULE_literal = 148;
338
+ static readonly RULE_dateLiteral = 149;
339
+ static readonly RULE_tablePath = 150;
340
+ static readonly RULE_tableURI = 151;
341
+ static readonly RULE_id = 152;
342
+ static readonly RULE_timeframe = 153;
343
+ static readonly RULE_ungroup = 154;
344
+ static readonly RULE_malloyOrSQLType = 155;
345
+ static readonly RULE_fieldExpr = 156;
346
+ static readonly RULE_partialCompare = 157;
347
+ static readonly RULE_partialTest = 158;
348
+ static readonly RULE_partialAllowedFieldExpr = 159;
349
+ static readonly RULE_fieldExprList = 160;
350
+ static readonly RULE_pickStatement = 161;
351
+ static readonly RULE_pick = 162;
352
+ static readonly RULE_caseStatement = 163;
353
+ static readonly RULE_caseWhen = 164;
354
+ static readonly RULE_recordKey = 165;
355
+ static readonly RULE_recordElement = 166;
356
+ static readonly RULE_argumentList = 167;
357
+ static readonly RULE_fieldNameList = 168;
358
+ static readonly RULE_fieldCollection = 169;
359
+ static readonly RULE_collectionWildCard = 170;
360
+ static readonly RULE_starQualified = 171;
361
+ static readonly RULE_taggedRef = 172;
362
+ static readonly RULE_refExpr = 173;
363
+ static readonly RULE_collectionMember = 174;
364
+ static readonly RULE_fieldPath = 175;
365
+ static readonly RULE_joinName = 176;
366
+ static readonly RULE_fieldName = 177;
367
+ static readonly RULE_sqlExploreNameRef = 178;
368
+ static readonly RULE_nameSQLBlock = 179;
369
+ static readonly RULE_connectionName = 180;
370
+ static readonly RULE_tripFilterString = 181;
371
+ static readonly RULE_tickFilterString = 182;
372
+ static readonly RULE_filterString = 183;
373
+ static readonly RULE_debugExpr = 184;
374
+ static readonly RULE_debugPartial = 185;
375
+ static readonly RULE_experimentalStatementForTesting = 186;
374
376
  static readonly ruleNames: string[];
375
377
  private static readonly _LITERAL_NAMES;
376
378
  private static readonly _SYMBOLIC_NAMES;
@@ -510,6 +512,8 @@ export declare class MalloyParser extends Parser {
510
512
  orderByStatement(): OrderByStatementContext;
511
513
  ordering(): OrderingContext;
512
514
  orderBySpec(): OrderBySpecContext;
515
+ possibleBadPath(): PossibleBadPathContext;
516
+ badWord(): BadWordContext;
513
517
  limitStatement(): LimitStatementContext;
514
518
  bySpec(): BySpecContext;
515
519
  topStatement(): TopStatementContext;
@@ -2200,7 +2204,7 @@ export declare class OrderingContext extends ParserRuleContext {
2200
2204
  }
2201
2205
  export declare class OrderBySpecContext extends ParserRuleContext {
2202
2206
  INTEGER_LITERAL(): TerminalNode | undefined;
2203
- fieldName(): FieldNameContext | undefined;
2207
+ possibleBadPath(): PossibleBadPathContext | undefined;
2204
2208
  ASC(): TerminalNode | undefined;
2205
2209
  DESC(): TerminalNode | undefined;
2206
2210
  constructor(parent: ParserRuleContext | undefined, invokingState: number);
@@ -2209,6 +2213,84 @@ export declare class OrderBySpecContext extends ParserRuleContext {
2209
2213
  exitRule(listener: MalloyParserListener): void;
2210
2214
  accept<Result>(visitor: MalloyParserVisitor<Result>): Result;
2211
2215
  }
2216
+ export declare class PossibleBadPathContext extends ParserRuleContext {
2217
+ badWord(): BadWordContext[];
2218
+ badWord(i: number): BadWordContext;
2219
+ DOT(): TerminalNode[];
2220
+ DOT(i: number): TerminalNode;
2221
+ constructor(parent: ParserRuleContext | undefined, invokingState: number);
2222
+ get ruleIndex(): number;
2223
+ enterRule(listener: MalloyParserListener): void;
2224
+ exitRule(listener: MalloyParserListener): void;
2225
+ accept<Result>(visitor: MalloyParserVisitor<Result>): Result;
2226
+ }
2227
+ export declare class BadWordContext extends ParserRuleContext {
2228
+ fieldName(): FieldNameContext | undefined;
2229
+ timeframe(): TimeframeContext | undefined;
2230
+ ALL(): TerminalNode | undefined;
2231
+ AND(): TerminalNode | undefined;
2232
+ AS(): TerminalNode | undefined;
2233
+ AVG(): TerminalNode | undefined;
2234
+ BOOLEAN(): TerminalNode | undefined;
2235
+ BY(): TerminalNode | undefined;
2236
+ CASE(): TerminalNode | undefined;
2237
+ CAST(): TerminalNode | undefined;
2238
+ COUNT(): TerminalNode | undefined;
2239
+ COMPOSE(): TerminalNode | undefined;
2240
+ DATE(): TerminalNode | undefined;
2241
+ DISTINCT(): TerminalNode | undefined;
2242
+ ELSE(): TerminalNode | undefined;
2243
+ END(): TerminalNode | undefined;
2244
+ EXCLUDE(): TerminalNode | undefined;
2245
+ EXPORT(): TerminalNode | undefined;
2246
+ EXTEND(): TerminalNode | undefined;
2247
+ FALSE(): TerminalNode | undefined;
2248
+ FILTER(): TerminalNode | undefined;
2249
+ FULL(): TerminalNode | undefined;
2250
+ FOR(): TerminalNode | undefined;
2251
+ FROM(): TerminalNode | undefined;
2252
+ HAS(): TerminalNode | undefined;
2253
+ IMPORT(): TerminalNode | undefined;
2254
+ INCLUDE(): TerminalNode | undefined;
2255
+ INNER(): TerminalNode | undefined;
2256
+ IS(): TerminalNode | undefined;
2257
+ IN(): TerminalNode | undefined;
2258
+ INTERNAL_KW(): TerminalNode | undefined;
2259
+ JSON(): TerminalNode | undefined;
2260
+ LEFT(): TerminalNode | undefined;
2261
+ LIKE(): TerminalNode | undefined;
2262
+ MAX(): TerminalNode | undefined;
2263
+ MIN(): TerminalNode | undefined;
2264
+ NOT(): TerminalNode | undefined;
2265
+ NOW(): TerminalNode | undefined;
2266
+ NULL(): TerminalNode | undefined;
2267
+ NUMBER(): TerminalNode | undefined;
2268
+ ON(): TerminalNode | undefined;
2269
+ OR(): TerminalNode | undefined;
2270
+ PICK(): TerminalNode | undefined;
2271
+ PRIVATE_KW(): TerminalNode | undefined;
2272
+ PUBLIC_KW(): TerminalNode | undefined;
2273
+ RIGHT(): TerminalNode | undefined;
2274
+ STRING(): TerminalNode | undefined;
2275
+ SOURCE_KW(): TerminalNode | undefined;
2276
+ SUM(): TerminalNode | undefined;
2277
+ SQL(): TerminalNode | undefined;
2278
+ TABLE(): TerminalNode | undefined;
2279
+ THEN(): TerminalNode | undefined;
2280
+ THIS(): TerminalNode | undefined;
2281
+ TIMESTAMPTZ(): TerminalNode | undefined;
2282
+ TIMESTAMP(): TerminalNode | undefined;
2283
+ TO(): TerminalNode | undefined;
2284
+ TRUE(): TerminalNode | undefined;
2285
+ WHEN(): TerminalNode | undefined;
2286
+ WITH(): TerminalNode | undefined;
2287
+ VIRTUAL(): TerminalNode | undefined;
2288
+ constructor(parent: ParserRuleContext | undefined, invokingState: number);
2289
+ get ruleIndex(): number;
2290
+ enterRule(listener: MalloyParserListener): void;
2291
+ exitRule(listener: MalloyParserListener): void;
2292
+ accept<Result>(visitor: MalloyParserVisitor<Result>): Result;
2293
+ }
2212
2294
  export declare class LimitStatementContext extends ParserRuleContext {
2213
2295
  LIMIT(): TerminalNode;
2214
2296
  INTEGER_LITERAL(): TerminalNode;