Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions packages/malloy/src/lang/test/query.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
isJoined,
isQuerySegment,
isAtomic,
hasExpression,
} from '../../model';

function getFirstQuerySegment(q: Query | undefined): QuerySegment | undefined {
Expand Down Expand Up @@ -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', () => {
Expand Down
37 changes: 37 additions & 0 deletions test/src/databases/all/nomodel.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`}')`)
Expand Down
Loading