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);
}
}
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;
}
Aggregations