Skip to content

Commit

Permalink
remove some todos
Browse files Browse the repository at this point in the history
  • Loading branch information
mtoy-googly-moogly committed Nov 27, 2024
1 parent dc88851 commit ee4bb9e
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 18 deletions.
43 changes: 31 additions & 12 deletions packages/malloy/src/lang/ast/expressions/expr-array-literal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
* LICENSE file in the root directory of this source tree.
*/

import {ArrayLiteralNode, arrayEachFields, ArrayTypeDef} from '../../../model';
import {
ArrayLiteralNode,
arrayEachFields,
ArrayTypeDef,
Expr,
} from '../../../model';
import {ExprValue, computedExprValue} from '../types/expr-value';
import {ExpressionDef} from '../types/expression-def';
import {FieldSpace} from '../types/field-space';
Expand All @@ -19,17 +24,31 @@ export class ArrayLiteral extends ExpressionDef {
}

getExpression(fs: FieldSpace): ExprValue {
const values = this.elements.map(v => v.getExpression(fs));
const type = values[0];
const checkedValues = [values[0].value];
for (const newType of values.slice(1)) {
if (TDU.typeEq(type, newType)) {
checkedValues.push(newType.value);
} else {
throw new Error('mtoy todo array elements should be same type');
const values: Expr[] = [];
const fromValues: ExprValue[] = [];
let firstValue: ExprValue | undefined = undefined;
if (this.elements.length > 0) {
for (const nextElement of this.elements) {
const v = nextElement.getExpression(fs);
fromValues.push(v);
if (v.type === 'error') {
continue;
}
if (firstValue) {
if (!TDU.typeEq(firstValue, v)) {
nextElement.logError(
'array-values-incompatible',
'All array elements must be same type'
);
continue;
}
} else {
firstValue = v;
}
values.push(v.value);
}
}
const elementTypeDef = TDU.atomicDef(values[0]);
const elementTypeDef = TDU.atomicDef(firstValue || {type: 'number'});
const typeDef: ArrayTypeDef = {
type: 'array',
join: 'many',
Expand All @@ -46,13 +65,13 @@ export class ArrayLiteral extends ExpressionDef {
};
const aLit: ArrayLiteralNode = {
node: 'arrayLiteral',
kids: {values: checkedValues},
kids: {values},
typeDef,
};
return computedExprValue({
dataType: typeDef,
value: aLit,
from: values,
from: fromValues,
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export class ReferenceField extends SpaceField {
e: {node: 'parameter', path},
};
} else {
// mtoy todo
// not sure what to do here, if we get here
throw new Error('impossible turtle/join parameter');
}
} else {
Expand Down
3 changes: 0 additions & 3 deletions packages/malloy/src/lang/ast/query-properties/filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,6 @@ export class Filter
): FilterCondition | undefined {
const fExpr = filter.filterCondition(fs);

// mtoy todo is having we never set then queryRefinementStage might be wrong
// ... calculations and aggregations must go last

// Aggregates are ALSO checked at SQL generation time, but checking
// here allows better reflection of errors back to user.
if (this.havingClause !== undefined) {
Expand Down
1 change: 0 additions & 1 deletion packages/malloy/src/lang/grammar/MalloyParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,6 @@ fieldExpr
| fieldPath DOT aggregate
OPAREN fieldExpr? CPAREN # exprAggregate
| OPAREN fieldExpr CPAREN # exprExpr
// mtoy todo should allow expr DOT expr, since expr can now be a record
| fieldPath DOT id
OPAREN ( argumentList? ) CPAREN # exprAggFunc
| ((id (EXCLAM malloyType?)?) | timeframe)
Expand Down
1 change: 1 addition & 0 deletions packages/malloy/src/lang/parse-log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ type MessageParameterTypes = {
'or-choices-only': string;
'sql-in': string;
'dialect-cast-unsafe-only': string;
'array-values-incompatible': string;
};

export const MESSAGE_FORMATTERS: PartialErrorCodeMessageMap = {
Expand Down
1 change: 0 additions & 1 deletion test/src/databases/all/compound-atomic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ describe.each(runtimes.runtimeList)(
{small: 0}
);
});
// mtoy todo remove this
test('nested data looks like a record', async () => {
await expect(`
run: ${databaseName}.sql('SELECT 1 as ${quote('o')}') -> {
Expand Down

0 comments on commit ee4bb9e

Please sign in to comment.