Skip to content

Commit

Permalink
generate enum cast functions on-the-fly in BuiltinFunctionNamespaceMa…
Browse files Browse the repository at this point in the history
…nager
  • Loading branch information
daniel-ohayon committed Jun 22, 2020
1 parent 0df59a1 commit 8ee5838
Showing 1 changed file with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.facebook.presto.common.block.BlockSerdeUtil;
import com.facebook.presto.common.function.OperatorType;
import com.facebook.presto.common.function.QualifiedFunctionName;
import com.facebook.presto.common.type.EnumType;
import com.facebook.presto.common.type.Type;
import com.facebook.presto.common.type.TypeManager;
import com.facebook.presto.common.type.TypeSignature;
Expand Down Expand Up @@ -191,6 +192,7 @@
import com.facebook.presto.type.DateTimeOperators;
import com.facebook.presto.type.DecimalOperators;
import com.facebook.presto.type.DoubleOperators;
import com.facebook.presto.type.EnumOperators;
import com.facebook.presto.type.HyperLogLogOperators;
import com.facebook.presto.type.IntegerOperators;
import com.facebook.presto.type.IntervalDayTimeOperators;
Expand Down Expand Up @@ -223,6 +225,7 @@
import com.google.common.cache.LoadingCache;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableListMultimap;
import com.google.common.collect.Iterables;
import com.google.common.collect.Multimap;
import com.google.common.collect.Multimaps;
import com.google.common.util.concurrent.UncheckedExecutionException;
Expand Down Expand Up @@ -901,6 +904,14 @@ private SpecializedFunctionKey doGetSpecializedFunctionKey(Signature signature)
Iterable<SqlFunction> candidates = getFunctions(null, signature.getName());
// search for exact match
Type returnType = typeManager.getType(signature.getReturnType());

if (returnType instanceof EnumType && CastType.CAST.getCastName().equals(signature.getName())) {
// Specific enum types are not known in advance at server startup time, but all enum types
// support the same CAST functions. So here, we build these cast functions on-the-fly
// for the particular enum type encountered in the signature.
candidates = Iterables.concat(candidates, EnumOperators.makeEnumCastFunctions((EnumType) returnType));
}

List<TypeSignatureProvider> argumentTypeSignatureProviders = fromTypeSignatures(signature.getArgumentTypes());
for (SqlFunction candidate : candidates) {
Optional<BoundVariables> boundVariables = new SignatureBinder(typeManager, candidate.getSignature(), false)
Expand Down

0 comments on commit 8ee5838

Please sign in to comment.