Search in sources :

Example 6 with ConstantExpression

use of io.trino.sql.relational.ConstantExpression in project trino by trinodb.

the class InCodeGenerator method isDeterminateConstant.

private static boolean isDeterminateConstant(RowExpression expression, MethodHandle isIndeterminateFunction) {
    if (!(expression instanceof ConstantExpression)) {
        return false;
    }
    ConstantExpression constantExpression = (ConstantExpression) expression;
    Object value = constantExpression.getValue();
    if (value == null) {
        return false;
    }
    try {
        return !(boolean) isIndeterminateFunction.invoke(value);
    } catch (Throwable t) {
        throwIfUnchecked(t);
        throw new RuntimeException(t);
    }
}
Also used : ConstantExpression(io.trino.sql.relational.ConstantExpression)

Example 7 with ConstantExpression

use of io.trino.sql.relational.ConstantExpression in project trino by trinodb.

the class InCodeGenerator method checkSwitchGenerationCase.

@VisibleForTesting
static SwitchGenerationCase checkSwitchGenerationCase(Type type, List<RowExpression> values) {
    if (values.size() >= 8) {
        // Tipping point is between 5 and 10 (using round 8)
        return SwitchGenerationCase.SET_CONTAINS;
    }
    if (type.getJavaType() != long.class) {
        return SwitchGenerationCase.HASH_SWITCH;
    }
    for (RowExpression expression : values) {
        // Same argument applies for nulls.
        if (!(expression instanceof ConstantExpression)) {
            continue;
        }
        Object constant = ((ConstantExpression) expression).getValue();
        if (constant == null) {
            continue;
        }
        long longConstant = ((Number) constant).longValue();
        if (longConstant < Integer.MIN_VALUE || longConstant > Integer.MAX_VALUE) {
            return SwitchGenerationCase.HASH_SWITCH;
        }
    }
    return SwitchGenerationCase.DIRECT_SWITCH;
}
Also used : ConstantExpression(io.trino.sql.relational.ConstantExpression) RowExpression(io.trino.sql.relational.RowExpression) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

ConstantExpression (io.trino.sql.relational.ConstantExpression)7 Scope (io.airlift.bytecode.Scope)3 CallExpression (io.trino.sql.relational.CallExpression)3 InputReferenceExpression (io.trino.sql.relational.InputReferenceExpression)3 RowExpression (io.trino.sql.relational.RowExpression)3 BytecodeBlock (io.airlift.bytecode.BytecodeBlock)2 Variable (io.airlift.bytecode.Variable)2 IfStatement (io.airlift.bytecode.control.IfStatement)2 Type (io.trino.spi.type.Type)2 LambdaDefinitionExpression (io.trino.sql.relational.LambdaDefinitionExpression)2 RowExpressionVisitor (io.trino.sql.relational.RowExpressionVisitor)2 SpecialForm (io.trino.sql.relational.SpecialForm)2 VariableReferenceExpression (io.trino.sql.relational.VariableReferenceExpression)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableListMultimap (com.google.common.collect.ImmutableListMultimap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 BytecodeNode (io.airlift.bytecode.BytecodeNode)1 ClassDefinition (io.airlift.bytecode.ClassDefinition)1 Parameter (io.airlift.bytecode.Parameter)1