private static ExpressionAnalysis analyzeExpressionsWithInputs( Session session, Metadata metadata, SqlParser sqlParser, Map<Integer, Type> types, Iterable<Expression> expressions, List<Expression> parameters, WarningCollector warningCollector) { Field[] fields = new Field[types.size()]; for (Entry<Integer, Type> entry : types.entrySet()) { fields[entry.getKey()] = io.prestosql.sql.analyzer.Field.newUnqualified(Optional.empty(), entry.getValue()); } RelationType tupleDescriptor = new RelationType(fields); return analyzeExpressions(session, metadata, sqlParser, tupleDescriptor, TypeProvider.empty(), expressions, parameters, warningCollector); }
private static ExpressionAnalysis analyzeExpressionsWithInputs( Session session, Metadata metadata, SqlParser sqlParser, Map<Integer, Type> types, Iterable<Expression> expressions, List<Expression> parameters, WarningCollector warningCollector) { Field[] fields = new Field[types.size()]; for (Entry<Integer, Type> entry : types.entrySet()) { fields[entry.getKey()] = io.prestosql.sql.analyzer.Field.newUnqualified(Optional.empty(), entry.getValue()); } RelationType tupleDescriptor = new RelationType(fields); return analyzeExpressions(session, metadata, sqlParser, tupleDescriptor, TypeProvider.empty(), expressions, parameters, warningCollector); }
private static void assertProjection(String expression, @Nullable Object expectedValue) { assertProjection( expression, expectedValue, ImmutableMap.of(), TypeProvider.empty(), 0); }
private static void assertProjection(String expression, @Nullable Object expectedValue) { assertProjection( expression, expectedValue, ImmutableMap.of(), TypeProvider.empty(), 0); }
private SymbolStatsAssertion assertCalculate(Expression scalarExpression, PlanNodeStatsEstimate inputStatistics) { return assertCalculate(scalarExpression, inputStatistics, TypeProvider.empty()); }
private SymbolStatsAssertion assertCalculate(Expression scalarExpression, PlanNodeStatsEstimate inputStatistics) { return assertCalculate(scalarExpression, inputStatistics, TypeProvider.empty()); }
metadata, sqlParser, TypeProvider.empty(), ImmutableList.copyOf(row), emptyList(),
metadata, sqlParser, TypeProvider.empty(), ImmutableList.copyOf(row), emptyList(),
private Map<NodeRef<Expression>, Type> getExpressionTypes(Expression expression) { ExpressionAnalyzer expressionAnalyzer = ExpressionAnalyzer.createWithoutSubqueries( metadata.getFunctionRegistry(), metadata.getTypeManager(), TEST_SESSION, TypeProvider.empty(), emptyList(), node -> new IllegalStateException("Unexpected node: %s" + node), WarningCollector.NOOP, false); expressionAnalyzer.analyze(expression, Scope.create()); return expressionAnalyzer.getExpressionTypes(); } }
private Map<NodeRef<Expression>, Type> getExpressionTypes(Expression expression) { ExpressionAnalyzer expressionAnalyzer = ExpressionAnalyzer.createWithoutSubqueries( metadata.getFunctionRegistry(), metadata.getTypeManager(), TEST_SESSION, TypeProvider.empty(), emptyList(), node -> new IllegalStateException("Unexpected node: %s" + node), WarningCollector.NOOP, false); expressionAnalyzer.analyze(expression, Scope.create()); return expressionAnalyzer.getExpressionTypes(); } }
private static void assertFilter(String expression, boolean expectedValue) { InterpretedPageFilter filterFunction = new InterpretedPageFilter( createExpression(expression, METADATA, TypeProvider.empty()), TypeProvider.empty(), ImmutableMap.of(), METADATA, SQL_PARSER, TEST_SESSION); SelectedPositions selectedPositions = filterFunction.filter(TEST_SESSION.toConnectorSession(), new Page(1)); assertEquals(selectedPositions.size(), expectedValue ? 1 : 0); if (expectedValue) { if (selectedPositions.isList()) { assertEquals(selectedPositions.getPositions()[selectedPositions.getOffset()], 0); } else { assertEquals(selectedPositions.getOffset(), 0); } } else { assertTrue(selectedPositions.isEmpty()); } } }
private void validatePlan(PlanNode root, boolean forceSingleNode) { getQueryRunner().inTransaction(session -> { // metadata.getCatalogHandle() registers the catalog for the transaction session.getCatalog().ifPresent(catalog -> metadata.getCatalogHandle(session, catalog)); new ValidateAggregationsWithDefaultValues(forceSingleNode).validate(root, session, metadata, SQL_PARSER, TypeProvider.empty(), WarningCollector.NOOP); return null; }); } }
private void validatePlan(PlanNode root, boolean forceSingleNode) { getQueryRunner().inTransaction(session -> { // metadata.getCatalogHandle() registers the catalog for the transaction session.getCatalog().ifPresent(catalog -> metadata.getCatalogHandle(session, catalog)); new ValidateAggregationsWithDefaultValues(forceSingleNode).validate(root, session, metadata, SQL_PARSER, TypeProvider.empty(), WarningCollector.NOOP); return null; }); } }
private static void assertFilter(String expression, boolean expectedValue) { InterpretedPageFilter filterFunction = new InterpretedPageFilter( createExpression(expression, METADATA, TypeProvider.empty()), TypeProvider.empty(), ImmutableMap.of(), METADATA, SQL_PARSER, TEST_SESSION); SelectedPositions selectedPositions = filterFunction.filter(TEST_SESSION.toConnectorSession(), new Page(1)); assertEquals(selectedPositions.size(), expectedValue ? 1 : 0); if (expectedValue) { if (selectedPositions.isList()) { assertEquals(selectedPositions.getPositions()[selectedPositions.getOffset()], 0); } else { assertEquals(selectedPositions.getOffset(), 0); } } else { assertTrue(selectedPositions.isEmpty()); } } }
private static class Context { private final Scope scope; // functionInputTypes and nameToLambdaDeclarationMap can be null or non-null independently. All 4 combinations are possible. // The list of types when expecting a lambda (i.e. processing lambda parameters of a function); null otherwise. // Empty list represents expecting a lambda with no arguments. private final List<Type> functionInputTypes; // The mapping from names to corresponding lambda argument declarations when inside a lambda; null otherwise. // Empty map means that the all lambda expressions surrounding the current node has no arguments. private final Map<FieldId, LambdaArgumentDeclaration> fieldToLambdaArgumentDeclaration; private Context( Scope scope, List<Type> functionInputTypes, Map<FieldId, LambdaArgumentDeclaration> fieldToLambdaArgumentDeclaration) { this.scope = requireNonNull(scope, "scope is null"); this.functionInputTypes = functionInputTypes; this.fieldToLambdaArgumentDeclaration = fieldToLambdaArgumentDeclaration; } public static Context notInLambda(Scope scope) { return new Context(scope, null, null); } public static Context inLambda(Scope scope, Map<FieldId, LambdaArgumentDeclaration> fieldToLambdaArgumentDeclaration) {
private static class Context { private final Scope scope; // functionInputTypes and nameToLambdaDeclarationMap can be null or non-null independently. All 4 combinations are possible. // The list of types when expecting a lambda (i.e. processing lambda parameters of a function); null otherwise. // Empty list represents expecting a lambda with no arguments. private final List<Type> functionInputTypes; // The mapping from names to corresponding lambda argument declarations when inside a lambda; null otherwise. // Empty map means that the all lambda expressions surrounding the current node has no arguments. private final Map<FieldId, LambdaArgumentDeclaration> fieldToLambdaArgumentDeclaration; private Context( Scope scope, List<Type> functionInputTypes, Map<FieldId, LambdaArgumentDeclaration> fieldToLambdaArgumentDeclaration) { this.scope = requireNonNull(scope, "scope is null"); this.functionInputTypes = functionInputTypes; this.fieldToLambdaArgumentDeclaration = fieldToLambdaArgumentDeclaration; } public static Context notInLambda(Scope scope) { return new Context(scope, null, null); } public static Context inLambda(Scope scope, Map<FieldId, LambdaArgumentDeclaration> fieldToLambdaArgumentDeclaration) {
metadata, sqlParser, TypeProvider.empty(), relation.getSamplePercentage(), analysis.getParameters(),
metadata, sqlParser, TypeProvider.empty(), relation.getSamplePercentage(), analysis.getParameters(),
WarningCollector warningCollector) ExpressionAnalyzer analyzer = create(analysis, session, metadata, sqlParser, accessControl, TypeProvider.empty(), warningCollector); analyzer.analyze(expression, scope);
WarningCollector warningCollector) ExpressionAnalyzer analyzer = create(analysis, session, metadata, sqlParser, accessControl, TypeProvider.empty(), warningCollector); analyzer.analyze(expression, scope);