Resolve aliased columns

This commit is contained in:
Simon Binder 2019-07-25 17:33:01 +02:00
parent 4bf58cb83b
commit 82f84732d0
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
3 changed files with 32 additions and 4 deletions

View File

@ -17,5 +17,7 @@ communicates with an app to verify behavior of widgets. As we want to run the wh
on a device, we instead put the test files into `flutter_db/lib` and run them with
`flutter run`. That works, but we don't get an output format that is machine readable.
Please create an issue if you know a better way, thanks!
TODO: https://github.com/tomaszpolanski/flutter-presentations/blob/master/lib/test_driver/test_runner.dart
looks promising
That is also why these tests are not running automatically.

View File

@ -80,14 +80,16 @@ class ColumnResolver extends RecursiveVisitor<void> {
}
} else if (resultColumn is ExpressionResultColumn) {
final name = _nameOfResultColumn(resultColumn);
usedColumns.add(
ExpressionColumn(name: name, expression: resultColumn.expression),
);
final column =
ExpressionColumn(name: name, expression: resultColumn.expression);
availableColumns.add(column);
usedColumns.add(column);
}
}
s.resolvedColumns = usedColumns;
s.scope.availableColumns = availableColumns;
scope.availableColumns = availableColumns;
}
String _nameOfResultColumn(ExpressionResultColumn c) {

View File

@ -1,6 +1,8 @@
import 'package:sqlparser/src/utils/ast_equality.dart';
import 'package:test/test.dart';
import 'package:sqlparser/sqlparser.dart';
import '../parser/utils.dart';
import 'data.dart';
void main() {
@ -34,4 +36,26 @@ void main() {
expect((secondColumn.expression as Reference).resolved, content);
expect(from.resolved, demoTable);
});
test('resolves the column for order by clauses', () {
final engine = SqlEngine()..registerTable(demoTable);
final context = engine
.analyze('SELECT d.content, 3 * d.id AS t FROM demo AS d ORDER BY t');
expect(context.errors, isEmpty);
final select = context.root as SelectStatement;
final orderingTerm = select.orderBy.terms.single.expression as Reference;
final resolved = orderingTerm.resolved as ExpressionColumn;
enforceEqual(
resolved.expression,
BinaryExpression(
NumericLiteral(3, token(TokenType.numberLiteral)),
token(TokenType.star),
Reference(tableName: 'd', columnName: 'id'),
),
);
});
}