@malloydata/malloy-tests 0.0.119-dev240123183113 → 0.0.119-dev240124170348

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/src/tags.spec.ts CHANGED
@@ -377,7 +377,25 @@ describe('tags in results', () => {
377
377
  const result = await loaded.run();
378
378
  expect(result.tagParse().tag).tagsAre(wantTag);
379
379
  });
380
- test('atomic field has tag', async () => {
380
+ test('field ref has tag', async () => {
381
+ const loaded = runtime.loadQuery(
382
+ `run: duckdb.sql("select 1 as num") extend {
383
+ dimension: # sourceNote
384
+ one is num
385
+ } -> {
386
+ select: # queryNote
387
+ one
388
+ }`
389
+ );
390
+ const result = await loaded.run();
391
+ const shape = result.resultExplore;
392
+ const one = shape.getFieldByName('one');
393
+ expect(one).toBeDefined();
394
+ const tp = one.tagParse();
395
+ expect(tp.log).toEqual([]);
396
+ expect(tp.tag).tagsAre({sourceNote: {}, queryNote: {}});
397
+ });
398
+ test('atomic field model scope tag', async () => {
381
399
  const loaded = runtime.loadQuery(
382
400
  `
383
401
  ## modelDef=ok
package/src/util/index.ts CHANGED
@@ -24,14 +24,30 @@
24
24
  import {
25
25
  FilterExpression,
26
26
  Fragment,
27
+ QueryFieldDef,
28
+ IndexFieldDef,
27
29
  QueryMaterializer,
28
30
  Result,
29
31
  Runtime,
30
32
  } from '@malloydata/malloy';
31
33
 
34
+ // these two helper functions are here just to make older hand built models
35
+ // easier to use in the new world were refs are not strings
36
+ export function fToQF(fs: (QueryFieldDef | string)[]): QueryFieldDef[] {
37
+ return fs.map(f =>
38
+ typeof f === 'string' ? {type: 'fieldref', path: f.split('.')} : f
39
+ );
40
+ }
41
+
42
+ export function fToIF(fs: string[]): IndexFieldDef[] {
43
+ return fs.map(f =>
44
+ typeof f === 'string' ? {type: 'fieldref', path: f.split('.')} : f
45
+ );
46
+ }
47
+
32
48
  export function fStringEq(field: string, value: string): FilterExpression {
33
49
  return {
34
- expression: [{type: 'field', path: field}, `='${value}'`],
50
+ expression: [{type: 'field', path: field.split('.')}, `='${value}'`],
35
51
  code: `${field}='${value}'`,
36
52
  expressionType: 'scalar',
37
53
  };
@@ -39,7 +55,7 @@ export function fStringEq(field: string, value: string): FilterExpression {
39
55
 
40
56
  export function fStringLike(field: string, value: string): FilterExpression {
41
57
  return {
42
- expression: [{type: 'field', path: field}, ` LIKE '${value}'`],
58
+ expression: [{type: 'field', path: field.split('.')}, ` LIKE '${value}'`],
43
59
  code: `${field}~'${value}'`,
44
60
  expressionType: 'scalar',
45
61
  };
@@ -48,7 +64,7 @@ export function fStringLike(field: string, value: string): FilterExpression {
48
64
  export function fYearEq(field: string, year: number): FilterExpression {
49
65
  const yBegin = `'${year}-01-01 00:00:00'`;
50
66
  const yEnd = `'${year + 1}-01-01 00:00:00'`;
51
- const fx: Fragment = {type: 'field', path: field};
67
+ const fx: Fragment = {type: 'field', path: field.split('.')};
52
68
  return {
53
69
  expression: [fx, `>=${yBegin} and `, fx, `<${yEnd}`],
54
70
  code: `${field}:@${year}`,