diff --git a/presto-native-execution/presto_cpp/main/types/PrestoToVeloxExpr.cpp b/presto-native-execution/presto_cpp/main/types/PrestoToVeloxExpr.cpp index d0085c8af967e..b33c64f10cfae 100644 --- a/presto-native-execution/presto_cpp/main/types/PrestoToVeloxExpr.cpp +++ b/presto-native-execution/presto_cpp/main/types/PrestoToVeloxExpr.cpp @@ -611,6 +611,22 @@ TypedExprPtr convertDereferenceExpr( return std::make_shared(returnType, input, childName); } + +TypedExprPtr convertNullIfExpr( + const velox::TypePtr& returnType, + const std::vector& args) { + VELOX_CHECK_EQ(args.size(), 2); + + // Convert nullif(a, b) to if(a = b, null, a). + + std::vector newArgs = { + std::make_shared( + velox::BOOLEAN(), args, "presto.default.eq"), + std::make_shared( + returnType, velox::variant::null(returnType->kind())), + args[0]}; + return std::make_shared(returnType, newArgs, "if"); +} } // namespace TypedExprPtr VeloxExprConverter::toVeloxExpr( @@ -641,7 +657,7 @@ TypedExprPtr VeloxExprConverter::toVeloxExpr( } if (pexpr->form == protocol::Form::NULL_IF) { - VELOX_UNSUPPORTED("NULLIF not supported natively"); + return convertNullIfExpr(returnType, args); } auto form = std::string(json(pexpr->form));