Skip to content

Commit

Permalink
rename unsupported to "sql native"
Browse files Browse the repository at this point in the history
  • Loading branch information
mtoy-googly-moogly committed Jul 22, 2024
1 parent ac4f299 commit c422f34
Show file tree
Hide file tree
Showing 14 changed files with 48 additions and 38 deletions.
2 changes: 1 addition & 1 deletion packages/malloy-db-bigquery/src/bigquery_connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ export class BigQueryConnection
structDef.fields.push(innerStructDef);
} else {
const malloyType = this.dialect.sqlTypeToMalloyType(type) ?? {
type: 'unsupported',
type: 'sql native',
rawType: type.toLowerCase(),
};
structDef.fields.push({name, ...malloyType} as FieldTypeDef);
Expand Down
2 changes: 1 addition & 1 deletion packages/malloy-db-duckdb/src/duckdb_common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ export abstract class DuckDBCommon
structDef.fields.push({...malloyType, name});
} else {
structDef.fields.push({
type: 'unsupported',
type: 'sql native',
rawType: duckDBType.toLowerCase(),
name,
});
Expand Down
2 changes: 1 addition & 1 deletion packages/malloy-db-postgres/src/postgres_connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ export class PostgresConnection
s.fields.push({...malloyType, name});
} else {
s.fields.push({
type: 'unsupported',
type: 'sql native',
rawType: postgresDataType.toLowerCase(),
name,
});
Expand Down
6 changes: 3 additions & 3 deletions packages/malloy-db-snowflake/src/snowflake_connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ export class SnowflakeConnection
} else if (type === 'varchar') {
return 'string';
} else {
return 'unsupported';
return 'sql native';
}
}

Expand Down Expand Up @@ -239,7 +239,7 @@ export class SnowflakeConnection
structDef.fields.push(innerStructDef);
} else {
const malloyType = this.dialect.sqlTypeToMalloyType(type) ?? {
type: 'unsupported',
type: 'sql native',
rawType: type.toLowerCase(),
};
structDef.fields.push({name, ...malloyType} as FieldTypeDef);
Expand Down Expand Up @@ -273,7 +273,7 @@ export class SnowflakeConnection
s.fields.push({...malloyType, name});
} else {
s.fields.push({
type: 'unsupported',
type: 'sql native',
rawType: snowflakeDataType,
name,
});
Expand Down
4 changes: 2 additions & 2 deletions packages/malloy-db-trino/src/trino_connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -656,14 +656,14 @@ export abstract class TrinoPrestoConnection
} else {
malloyType.fields.push({
name: 'unknown',
type: 'unsupported',
type: 'sql native',
rawType: innerType.toLowerCase(),
});
}
}
} else {
malloyType = this.sqlToMalloyType(trinoType) ?? {
type: 'unsupported',
type: 'sql native',
rawType: trinoType.toLowerCase(),
};
}
Expand Down
4 changes: 2 additions & 2 deletions packages/malloy/src/lang/ast/expressions/expr-cast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class ExprCast extends ExpressionDef {

getExpression(fs: FieldSpace): ExprValue {
const expr = this.expr.getExpression(fs);
let dataType: AtomicFieldType = 'unsupported';
let dataType: AtomicFieldType = 'sql native';
if (typeof this.castType === 'string') {
dataType = this.castType;
} else {
Expand All @@ -51,7 +51,7 @@ export class ExprCast extends ExpressionDef {
// but `TypeDesc` does not support them.
dataType =
fs.dialectObj()?.sqlTypeToMalloyType(this.castType.raw)?.type ??
'unsupported';
'sql native';
} else {
this.log(
`Cast type \`${this.castType.raw}\` is invalid for ${dialect.name} dialect`
Expand Down
22 changes: 15 additions & 7 deletions packages/malloy/src/lang/ast/types/expression-def.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ export abstract class ExpressionDef extends MalloyElement {
*/
typeCheck(eNode: ExpressionDef, eVal: ExprValue): boolean {
if (eVal.dataType !== 'error' && !FT.in(eVal, this.legalChildTypes)) {
eNode.log(`'${this.elementType}' Can't use type ${FT.inspect(eVal)}`);
eNode.log(
eVal.dataType === 'sql native'
? `'${this.elementType}' Can't be used with unsupported SQL native type '${eVal.rawType}'[unsupported-sql-native-type-not-allowed-in-expression]`
: `'${this.elementType}' Can't use type ${FT.inspect(eVal)}`
);
return false;
}
return true;
Expand Down Expand Up @@ -319,7 +323,7 @@ function equality(

// Unsupported types can be compare with null
const checkUnsupport =
lhs.dataType === 'unsupported' || rhs.dataType === 'unsupported';
lhs.dataType === 'sql native' || rhs.dataType === 'sql native';
if (checkUnsupport) {
const oneNull = lhs.dataType === 'null' || rhs.dataType === 'null';
const rawMatch = lhs.rawType && lhs.rawType === rhs.rawType;
Expand Down Expand Up @@ -522,7 +526,7 @@ export function applyBinary(
const denom = right.getExpression(fs);
const noGo = unsupportError(left, num, right, denom);
if (noGo) {
left.log('Cannot operate with unsupported type');
left.log(`Cannot use '${op}' with sql native type`);
return noGo;
}

Expand Down Expand Up @@ -582,12 +586,16 @@ function unsupportError(
value: ["'unsupported operation'"],
evalSpace: mergeEvalSpaces(lhs.evalSpace, rhs.evalSpace),
};
if (lhs.dataType === 'unsupported') {
l.log('Unsupported type not allowed in expression');
if (lhs.dataType === 'sql native') {
l.log(
`Unsupported SQL native type '${lhs.rawType}' not allowed in expression[unsupported-sql-native-type-not-allowed-in-expression]`
);
return {...ret, dataType: rhs.dataType};
}
if (rhs.dataType === 'unsupported') {
r.log('Unsupported type not allowed in expression');
if (rhs.dataType === 'sql native') {
r.log(
`Unsupported SQL native type '${rhs.rawType}' not allowed in expression[unsupported-sql-native-type-not-allowed-in-expression]`
);
return ret;
}
return undefined;
Expand Down
4 changes: 2 additions & 2 deletions packages/malloy/src/lang/ast/types/space-field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ export abstract class SpaceField extends SpaceEntry {
ref.expressionType = def.expressionType;
}
if (
ref.dataType === 'unsupported' &&
def.type === 'unsupported' &&
ref.dataType === 'sql native' &&
def.type === 'sql native' &&
def.rawType
) {
ref.rawType = def.rawType;
Expand Down
14 changes: 8 additions & 6 deletions packages/malloy/src/lang/test/expressions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1006,12 +1006,12 @@ describe('expressions', () => {
expect(expr`${name} = NULL`).toTranslate();
});
});
describe('unspported fields in schema', () => {
test('unsupported reference in result allowed', () => {
describe('sql native fields in schema', () => {
test('sql native reference in result allowed', () => {
const uModel = new TestTranslator('run: a->{ group_by: aun }');
expect(uModel).toTranslate();
});
test('unsupported reference can be compared to NULL', () => {
test('sql native reference can be compared to NULL', () => {
const uModel = new TestTranslator(
'run: a->{ where: aun != NULL; select: * }'
);
Expand All @@ -1023,7 +1023,7 @@ describe('unspported fields in schema', () => {
'run: ab->{ where: aun = b.aun select: * }'
);
expect(uModel).translationToFailWith(
'Unsupported type not allowed in expression'
"Unsupported SQL native type 'undefined' not allowed in expression"
);
});
test('flag unsupported compare', () => {
Expand All @@ -1032,7 +1032,7 @@ describe('unspported fields in schema', () => {
'run: ab->{ where: aun > b.aun select: * }'
);
expect(uModel).translationToFailWith(
'Unsupported type not allowed in expression'
"Unsupported SQL native type 'undefined' not allowed in expression"
);
});
test('allow unsupported equality when raw types match', () => {
Expand All @@ -1045,7 +1045,9 @@ describe('unspported fields in schema', () => {
const uModel = new TestTranslator(
'source: x is a extend { dimension: notUn is not aun }'
);
expect(uModel).translationToFailWith("'not' Can't use type unsupported");
expect(uModel).translationToFailWith(
"'not' Can't be used with unsupported SQL native type 'undefined'"
);
});
test('allow unsupported to be cast', () => {
const uModel = new TestTranslator(
Expand Down
2 changes: 1 addition & 1 deletion packages/malloy/src/lang/test/field-symbols.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ describe('structdef comprehension', () => {
test('import unsupported field', () => {
const field: model.FieldDef = {
name: 't',
type: 'unsupported',
type: 'sql native',
};
const struct = mkStructDef(field);
const space = new StaticSpace(struct);
Expand Down
4 changes: 2 additions & 2 deletions packages/malloy/src/lang/test/test-translator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ const mockSchema: Record<string, StructDef> = {
{type: 'date', name: 'ad'},
{type: 'boolean', name: 'abool'},
{type: 'timestamp', name: 'ats'},
{type: 'unsupported', name: 'aun'},
{type: 'unsupported', name: 'aweird', rawType: 'weird'},
{type: 'sql native', name: 'aun'},
{type: 'sql native', name: 'aweird', rawType: 'weird'},
{
type: 'struct',
name: 'astruct',
Expand Down
8 changes: 4 additions & 4 deletions packages/malloy/src/malloy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1520,7 +1520,7 @@ export class Explore extends Entity implements Taggable {
return [name, new BooleanField(fieldDef, this, sourceField)];
} else if (fieldDef.type === 'json') {
return [name, new JSONField(fieldDef, this, sourceField)];
} else if (fieldDef.type === 'unsupported') {
} else if (fieldDef.type === 'sql native') {
return [name, new UnsupportedField(fieldDef, this, sourceField)];
}
}
Expand Down Expand Up @@ -1667,7 +1667,7 @@ export enum AtomicFieldType {
Date = 'date',
Timestamp = 'timestamp',
Json = 'json',
Unsupported = 'unsupported',
NativeSQL = 'sql native',
Error = 'error',
}

Expand Down Expand Up @@ -1699,8 +1699,8 @@ export class AtomicField extends Entity implements Taggable {
return AtomicFieldType.Number;
case 'json':
return AtomicFieldType.Json;
case 'unsupported':
return AtomicFieldType.Unsupported;
case 'sql native':
return AtomicFieldType.NativeSQL;
case 'error':
return AtomicFieldType.Error;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/malloy/src/model/malloy_query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2737,7 +2737,7 @@ class QueryQuery extends QueryField {
annotation,
});
break;
case 'unsupported':
case 'sql native':
fields.push({...fi.f.fieldDef, resultMetadata, location});
break;
default:
Expand Down Expand Up @@ -4359,7 +4359,7 @@ class QueryStruct extends QueryNode {
return new QueryFieldBoolean(field, this);
case 'json':
return new QueryFieldJSON(field, this);
case 'unsupported':
case 'sql native':
return new QueryFieldUnsupported(field, this);
// case "reduce":
// case "project":
Expand Down
8 changes: 4 additions & 4 deletions packages/malloy/src/model/malloy_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ export function isTimeFieldType(s: string): s is TimeFieldType {
return s === 'date' || s === 'timestamp';
}
export type CastType = 'string' | 'number' | TimeFieldType | 'boolean' | 'json';
export type AtomicFieldType = CastType | 'unsupported' | 'error';
export type AtomicFieldType = CastType | 'sql native' | 'error';
export function isAtomicFieldType(s: string): s is AtomicFieldType {
return [
'string',
Expand All @@ -591,7 +591,7 @@ export function isAtomicFieldType(s: string): s is AtomicFieldType {
'timestamp',
'boolean',
'json',
'unsupported',
'sql native',
'error',
].includes(s);
}
Expand Down Expand Up @@ -668,15 +668,15 @@ export interface FieldJSONDef extends FieldAtomicDef, FieldJSONTypeDef {
}

export interface FieldUnsupportedTypeDef {
type: 'unsupported';
type: 'sql native';
rawType?: string;
}

/** Scalar unsupported Field */
export interface FieldUnsupportedDef
extends FieldAtomicDef,
FieldUnsupportedTypeDef {
type: 'unsupported';
type: 'sql native';
}

export interface FieldErrorTypeDef {
Expand Down

0 comments on commit c422f34

Please sign in to comment.