diff --git a/packages/malloy/src/lang/test/query.spec.ts b/packages/malloy/src/lang/test/query.spec.ts index 5ef6c08e6f..284dde9528 100644 --- a/packages/malloy/src/lang/test/query.spec.ts +++ b/packages/malloy/src/lang/test/query.spec.ts @@ -37,6 +37,7 @@ import { isJoined, isQuerySegment, isAtomic, + hasExpression, } from '../../model'; function getFirstQuerySegment(q: Query | undefined): QuerySegment | undefined { @@ -242,6 +243,42 @@ describe('query:', () => { }`; expect(nestExclude).toTranslate(); }); + test('ungrouped from source matches ungrouped from query', () => { + // https://github.com/malloydata/malloy/issues/2137 + // this query, when run, doesn't apply the ungrouping to the field which + // was defined in the source so i wrote this test which passes to + // make sure that the definition of the field referenced does + // contain the ungrouping gesture + const errQuery = model` + run: _db_.table('malloytest.airports') extend { + dimension: first_letter is substr(state, 1, 1) + measure: + total_elev is elevation.sum() + all_total_elev is all(total_elev) + all_total_elev_first_letter is all(total_elev, first_letter) + } -> { + group_by: first_letter + aggregate: + all_total_elev_first_letter + all_total_elev_first_letter2 is all(total_elev, first_letter) + }`; + expect(errQuery).toTranslate(); + const q = errQuery.translator.getQuery(0); + expect(q).toBeDefined(); + const f = q!.structRef; + expect(typeof f).not.toBe('string'); + if (typeof f !== 'string') { + const ate = f.fields.find( + fd => fd.name === 'all_total_elev_first_letter' + ); + expect(ate).toBeDefined(); + if (hasExpression(ate!)) { + expect(ate.e.node).toEqual('all'); + } else { + expect(hasExpression(ate!)).toBe(true); + } + } + }); }); describe('query operation typechecking', () => { describe('field declarations', () => { diff --git a/test/src/databases/all/nomodel.spec.ts b/test/src/databases/all/nomodel.spec.ts index 82de860474..7a7f07f935 100644 --- a/test/src/databases/all/nomodel.spec.ts +++ b/test/src/databases/all/nomodel.spec.ts @@ -884,6 +884,43 @@ runtimes.runtimeMap.forEach((runtime, databaseName) => { } ); + test.when(runtime.supportsNesting)( + `ungrouped declared ungrouped with field - ${databaseName}`, + async () => { + await expect(` + source: s is ${databaseName}.table('malloytest.state_facts') extend { + dimension: + first_letter is substr(state,1,1) + measure: + total_births is births.sum() + all_births is all(total_births) + all_births_first_letter is all(total_births,first_letter) + } + + # test.debug + run: s -> { + group_by: + first_letter + popular_name + + aggregate: + // total_births + // all_births + all_births_first_letter + all_births_first_letter2 is all(total_births,first_letter) + + } + `).malloyResultMatches(runtime, { + // first_letter: 'C', + // popular_name: 'Isabella', + // total_births: 35596513, + // all_births: 295727065, + all_births_first_letter: 35596513, + all_births_first_letter2: 35596513, + }); + } + ); + it(`run simple sql - ${databaseName}`, async () => { const result = await runtime .loadQuery(`run: conn.sql('select 1 as ${q`one`}')`)