use of com.facebook.presto.util.maps.IdentityLinkedHashMap in project presto by prestodb.
the class ExpressionInterpreter method evaluateConstantExpression.
public static Object evaluateConstantExpression(Expression expression, Type expectedType, Metadata metadata, Session session, List<Expression> parameters) {
ExpressionAnalyzer analyzer = createConstantAnalyzer(metadata, session, parameters);
analyzer.analyze(expression, Scope.builder().build());
Type actualType = analyzer.getExpressionTypes().get(expression);
if (!metadata.getTypeManager().canCoerce(actualType, expectedType)) {
throw new SemanticException(SemanticErrorCode.TYPE_MISMATCH, expression, String.format("Cannot cast type %s to %s", expectedType.getTypeSignature(), actualType.getTypeSignature()));
}
IdentityLinkedHashMap<Expression, Type> coercions = new IdentityLinkedHashMap<>();
coercions.putAll(analyzer.getExpressionCoercions());
coercions.put(expression, expectedType);
return evaluateConstantExpression(expression, coercions, metadata, session, ImmutableSet.of(), parameters);
}
use of com.facebook.presto.util.maps.IdentityLinkedHashMap in project presto by prestodb.
the class LogicalPlanner method buildLambdaDeclarationToSymbolMap.
private static IdentityLinkedHashMap<LambdaArgumentDeclaration, Symbol> buildLambdaDeclarationToSymbolMap(Analysis analysis, SymbolAllocator symbolAllocator) {
IdentityLinkedHashMap<LambdaArgumentDeclaration, Symbol> resultMap = new IdentityLinkedHashMap<>();
for (Map.Entry<Expression, Type> entry : analysis.getTypes().entrySet()) {
if (!(entry.getKey() instanceof LambdaArgumentDeclaration)) {
continue;
}
LambdaArgumentDeclaration lambdaArgumentDeclaration = (LambdaArgumentDeclaration) entry.getKey();
if (resultMap.containsKey(lambdaArgumentDeclaration)) {
continue;
}
resultMap.put(lambdaArgumentDeclaration, symbolAllocator.newSymbol(lambdaArgumentDeclaration, entry.getValue()));
}
return resultMap;
}
use of com.facebook.presto.util.maps.IdentityLinkedHashMap in project presto by prestodb.
the class TestSqlToRowExpressionTranslator method testPossibleExponentialOptimizationTime.
@Test(timeOut = 10_000)
public void testPossibleExponentialOptimizationTime() {
Expression expression = new LongLiteral("1");
IdentityLinkedHashMap<Expression, Type> types = new IdentityLinkedHashMap<>();
types.put(expression, BIGINT);
for (int i = 0; i < 100; i++) {
expression = new CoalesceExpression(expression);
types.put(expression, BIGINT);
}
SqlToRowExpressionTranslator.translate(expression, SCALAR, types, FUNCTION_REGISTRY, TYPE_MANAGER, TEST_SESSION, true);
}
Aggregations