Skip to content

Commit f1bad2d

Browse files
Condition this behavior on ##! unsafe_complex_select_query compiler flag
1 parent 0a6f8d4 commit f1bad2d

File tree

2 files changed

+20
-43
lines changed

2 files changed

+20
-43
lines changed

packages/malloy/src/model/malloy_query.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ import {
131131
shouldMaterialize,
132132
} from './materialization/utils';
133133
import {EventStream} from '../runtime_types';
134+
import {Tag} from '../tags';
134135

135136
interface TurtleDefPlus extends TurtleDef, Filtered {}
136137

@@ -3411,6 +3412,13 @@ class QueryQuery extends QueryField {
34113412
};
34123413
this.generateStage0Fields(this.rootResult, f, stageWriter);
34133414

3415+
if (
3416+
this.firstSegment.type === 'project' &&
3417+
!this.parent.modelCompilerFlags().has('unsafe_complex_select_query')
3418+
) {
3419+
throw new Error('PROJECT cannot be used on queries with turtles');
3420+
}
3421+
34143422
const groupBy = 'GROUP BY ' + f.dimensionIndexes.join(',') + '\n';
34153423

34163424
from += this.parent.dialect.sqlGroupSetTable(this.maxGroupSet) + '\n';
@@ -4309,6 +4317,16 @@ class QueryStruct {
43094317
this.addFieldsFromFieldList(structDef.fields);
43104318
}
43114319

4320+
private _modelTag: Tag | undefined = undefined;
4321+
modelCompilerFlags(): Tag {
4322+
if (this._modelTag === undefined) {
4323+
const annotation = this.structDef.modelAnnotation;
4324+
const {tag} = Tag.annotationToTag(annotation, {prefix: /^##!\s*/});
4325+
this._modelTag = tag;
4326+
}
4327+
return this._modelTag;
4328+
}
4329+
43124330
protected findFirstDialect(): string {
43134331
if (isSourceDef(this.structDef)) {
43144332
return this.structDef.dialect;

test/src/databases/all/functions.spec.ts

Lines changed: 2 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1745,14 +1745,15 @@ describe.each(runtimes.runtimeList)('%s', (databaseName, runtime) => {
17451745
it('can be used in a select', async () => {
17461746
await expect(`
17471747
##! experimental { function_order_by partition_by }
1748+
##! unsafe_complex_select_query
17481749
run: state_facts -> {
17491750
select: state, births, popular_name
17501751
calculate: prev_births_by_name is lag(births) {
17511752
partition_by: popular_name
17521753
order_by: births desc
17531754
}
17541755
order_by: births desc
1755-
limit: 10
1756+
limit: 3
17561757
}
17571758
`).malloyResultMatches(expressionModel, [
17581759
{
@@ -1773,48 +1774,6 @@ describe.each(runtimes.runtimeList)('%s', (databaseName, runtime) => {
17731774
popular_name: 'Isabella',
17741775
prev_births_by_name: 23694136,
17751776
},
1776-
{
1777-
state: 'PA',
1778-
births: 16661910,
1779-
popular_name: 'Isabella',
1780-
prev_births_by_name: 21467359,
1781-
},
1782-
{
1783-
state: 'IL',
1784-
births: 15178876,
1785-
popular_name: 'Isabella',
1786-
prev_births_by_name: 16661910,
1787-
},
1788-
{
1789-
state: 'OH',
1790-
births: 14201526,
1791-
popular_name: 'Isabella',
1792-
prev_births_by_name: 15178876,
1793-
},
1794-
{
1795-
state: 'MI',
1796-
births: 11643455,
1797-
popular_name: 'Sophia',
1798-
prev_births_by_name: null,
1799-
},
1800-
{
1801-
state: 'FL',
1802-
births: 9277223,
1803-
popular_name: 'Isabella',
1804-
prev_births_by_name: 14201526,
1805-
},
1806-
{
1807-
state: 'NC',
1808-
births: 8440235,
1809-
popular_name: 'Emma',
1810-
prev_births_by_name: null,
1811-
},
1812-
{
1813-
state: 'NJ',
1814-
births: 8318769,
1815-
popular_name: 'Isabella',
1816-
prev_births_by_name: 9277223,
1817-
},
18181777
]);
18191778
});
18201779
});

0 commit comments

Comments
 (0)