@malloydata/malloy 0.0.56-dev230710210430 → 0.0.56-dev230710210433

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.
@@ -163,6 +163,9 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
163
163
  }
164
164
  getFilterShortcut(cx) {
165
165
  const el = this.getFilterElement(cx.fieldExpr());
166
+ if (this.m4WarningsEnabled()) {
167
+ this.astError(el, 'Filter shortcut `{? condition }` is deprecated; use `{ where: condition } instead', 'warn');
168
+ }
166
169
  return new ast.Filter([el]);
167
170
  }
168
171
  getPlainString(cx) {
@@ -278,7 +281,11 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
278
281
  visitQueryByName(pcx) {
279
282
  const query = new ast.ExistingQuery();
280
283
  query.head = this.getModelEntryName(pcx);
281
- return this.astAt(query, pcx);
284
+ const res = this.astAt(query, pcx);
285
+ if (this.m4WarningsEnabled() && pcx.ARROW()) {
286
+ this.astError(res, 'Leading arrow (`->`) when referencing a query is deprecated; remove the arrow', 'warn');
287
+ }
288
+ return res;
282
289
  }
283
290
  getSourceExtensions(pcx) {
284
291
  const extensions = pcx === null || pcx === void 0 ? void 0 : pcx.exploreProperties();
@@ -351,7 +358,11 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
351
358
  }
352
359
  visitSQLSourceName(pcx) {
353
360
  const name = this.getModelEntryName(pcx.sqlExploreNameRef());
354
- return this.astAt(new ast.FromSQLSource(name), pcx);
361
+ const res = this.astAt(new ast.FromSQLSource(name), pcx);
362
+ if (this.m4WarningsEnabled()) {
363
+ this.astError(res, '`from_sql` is deprecated; use `connection_name.sql(...)` as a source directly', 'warn');
364
+ }
365
+ return res;
355
366
  }
356
367
  visitSqlSource(pcx) {
357
368
  const connId = pcx.connectionId();
@@ -530,7 +541,11 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
530
541
  }
531
542
  visitFilterByShortcut(pcx) {
532
543
  const el = this.getFilterElement(pcx.fieldExpr());
533
- return this.astAt(new ast.Filter([el]), pcx);
544
+ const res = this.astAt(new ast.Filter([el]), pcx);
545
+ if (this.m4WarningsEnabled()) {
546
+ this.astError(el, 'Filter shortcut `{? condition }` is deprecated; use `{ where: condition } instead', 'warn');
547
+ }
548
+ return res;
534
549
  }
535
550
  visitWhereStatement(pcx) {
536
551
  const where = this.visitFilterClauseList(pcx.filterClauseList());
@@ -65,6 +65,12 @@ describe('model statements', () => {
65
65
  test('shorcut fitlered table', () => {
66
66
  expect("source: xA is table('aTable') {? astr ~ 'a%' }").toTranslate();
67
67
  });
68
+ test('shorcut fitlered table m4warning', () => {
69
+ expect(`
70
+ ##! m4warnings
71
+ source: xA is conn.table('aTable') extend {? astr ~ 'a%' }
72
+ `).toTranslateWithWarnings('Filter shortcut `{? condition }` is deprecated; use `{ where: condition } instead');
73
+ });
68
74
  test('fitlered table', () => {
69
75
  expect("source: testA is table('aTable') { where: astr ~ 'a%' }").toTranslate();
70
76
  });
@@ -130,6 +136,12 @@ describe('model statements', () => {
130
136
  test('query with shortcut filtered turtle', () => {
131
137
  expect("query: allA is ab->aturtle {? astr ~ 'a%' }").toTranslate();
132
138
  });
139
+ test('query with shortcut filtered turtle m4warning', () => {
140
+ expect(`
141
+ ##! m4warnings
142
+ query: allA is ab->aturtle refine {? astr ~ 'a%' }
143
+ `).toTranslateWithWarnings('Filter shortcut `{? condition }` is deprecated; use `{ where: condition } instead');
144
+ });
133
145
  test('query with filtered turtle', () => {
134
146
  expect("query: allA is ab->aturtle { where: astr ~ 'a%' }").toTranslate();
135
147
  });
@@ -779,6 +791,14 @@ describe('source properties', () => {
779
791
  }
780
792
  `).toTranslate();
781
793
  });
794
+ test('refined explore-query m4warning', () => {
795
+ expect(`
796
+ ##! m4warnings
797
+ source: abNew is ab extend {
798
+ query: for1 is aturtle refine {? ai = 1 }
799
+ }
800
+ `).toTranslateWithWarnings('Filter shortcut `{? condition }` is deprecated; use `{ where: condition } instead');
801
+ });
782
802
  test('chained explore-query', () => {
783
803
  expect(`
784
804
  source: c is a {
@@ -1345,6 +1365,15 @@ describe('expressions', () => {
1345
1365
  }
1346
1366
  `).toTranslate();
1347
1367
  });
1368
+ test('shortcut filtered measure m4warning', () => {
1369
+ expect(`
1370
+ ##! m4warnings
1371
+ run: a -> {
1372
+ group_by: ai
1373
+ aggregate: x is avg(ai) {? astr = 'why?' }
1374
+ }
1375
+ `).toTranslateWithWarnings('Filter shortcut `{? condition }` is deprecated; use `{ where: condition } instead');
1376
+ });
1348
1377
  test('correctly flags filtered scalar', () => {
1349
1378
  const e = new test_translator_1.BetaExpression('ai { where: true }');
1350
1379
  expect(e).translationToFailWith('Filtered expression requires an aggregate computation');
@@ -2908,6 +2937,18 @@ describe('sql expressions', () => {
2908
2937
  }
2909
2938
  expect(m).toTranslateWithWarnings('`sql:` statement is deprecated, use `connection_name.sql(...)` instead');
2910
2939
  });
2940
+ test('from_sql deprecation warning', () => {
2941
+ const m = new test_translator_1.TestTranslator(`##! m4warnings
2942
+ sql: bad_sql is {select: """SELECT 1 as one"""}
2943
+ source: foo is from_sql(bad_sql)`);
2944
+ const req = m.translate().compileSQL;
2945
+ if (req) {
2946
+ m.update({
2947
+ compileSQL: { [req.name]: getSelectOneStruct(req) },
2948
+ });
2949
+ }
2950
+ expect(m).toTranslateWithWarnings('`sql:` statement is deprecated, use `connection_name.sql(...)` instead', '`from_sql` is deprecated; use `connection_name.sql(...)` as a source directly');
2951
+ });
2911
2952
  test('reference to sql expression in run', () => {
2912
2953
  const m = new test_translator_1.TestTranslator(`
2913
2954
  run: bigquery.sql("""select 1 as one""")
@@ -3166,4 +3207,28 @@ describe('extend and refine', () => {
3166
3207
  });
3167
3208
  });
3168
3209
  });
3210
+ describe('miscellaneous m4 warnings', () => {
3211
+ test('query leading arrow', () => {
3212
+ expect(`
3213
+ ##! m4warnings
3214
+ query: x is a -> { project: * }
3215
+ run: x
3216
+ `).toTranslate();
3217
+ expect(`
3218
+ ##! m4warnings
3219
+ query: x is a -> { project: * }
3220
+ run: x -> { project: * }
3221
+ `).toTranslate();
3222
+ expect(`
3223
+ ##! m4warnings
3224
+ query: x is a -> { project: * }
3225
+ run: -> x
3226
+ `).toTranslateWithWarnings('Leading arrow (`->`) when referencing a query is deprecated; remove the arrow');
3227
+ expect(`
3228
+ ##! m4warnings
3229
+ query: x is a -> { project: * }
3230
+ run: -> x -> { project: * }
3231
+ `).toTranslateWithWarnings('Leading arrow (`->`) when referencing a query is deprecated; remove the arrow');
3232
+ });
3233
+ });
3169
3234
  //# sourceMappingURL=parse.spec.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@malloydata/malloy",
3
- "version": "0.0.56-dev230710210430",
3
+ "version": "0.0.56-dev230710210433",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",