mirror of https://github.com/AMT-Cheif/drift.git
Don't assume nullable if no join syntax is known
This commit is contained in:
parent
c38e9cc6c0
commit
4e05067bd5
|
@ -711,16 +711,17 @@ class TypeResolver extends RecursiveVisitor<TypeExpectation, void> {
|
|||
} else if (column is DelegatedColumn && column.innerColumn != null) {
|
||||
_handleColumn(column.innerColumn);
|
||||
|
||||
var makeNullable = false;
|
||||
|
||||
if (column is AvailableColumn) {
|
||||
// The nullability depends on whether the column was introduced in an
|
||||
// outer join.
|
||||
final model = context != null ? JoinModel.of(context) : null;
|
||||
final isNullable =
|
||||
model == null || model.availableColumnIsNullable(column);
|
||||
_lazyCopy(column, column.innerColumn, makeNullable: isNullable);
|
||||
} else {
|
||||
_lazyCopy(column, column.innerColumn);
|
||||
|
||||
makeNullable = model != null && model.availableColumnIsNullable(column);
|
||||
}
|
||||
|
||||
_lazyCopy(column, column.innerColumn, makeNullable: makeNullable);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -308,4 +308,29 @@ WITH RECURSIVE
|
|||
expect(session.typeOf(columns[2]),
|
||||
const ResolvedType(type: BasicType.int, nullable: true));
|
||||
});
|
||||
|
||||
test('analyzes nested columns', () {
|
||||
engine.registerTableFromSql('''
|
||||
CREATE TABLE x (
|
||||
id INTEGER NOT NULL,
|
||||
other INTEGER
|
||||
);
|
||||
''');
|
||||
|
||||
final resolver = obtainResolver('''
|
||||
SELECT xxx.id FROM (
|
||||
SELECT * FROM (
|
||||
SELECT id FROM x
|
||||
) xx
|
||||
) xxx;
|
||||
''');
|
||||
|
||||
final session = resolver.session;
|
||||
final stmt = resolver.session.context.root as SelectStatement;
|
||||
final columns = stmt.resolvedColumns!;
|
||||
|
||||
expect(columns, hasLength(1));
|
||||
expect(session.typeOf(columns[0]),
|
||||
const ResolvedType(type: BasicType.int, nullable: false));
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue