Skip to content

Commit

Permalink
Support TDigestType in Velox Functions (#12326)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #12326

X-link: prestodb/presto#24546

Add support for TDIGEST(DOUBLE) in Prestissimo along with additional test cases

Reviewed By: Yuhta

Differential Revision: D69558489

fbshipit-source-id: 3d911759af5d80fde4b7653d66fa44a623a52274
  • Loading branch information
natashasehgal authored and facebook-github-bot committed Mar 5, 2025
1 parent 42c545e commit bfeb189
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 7 deletions.
4 changes: 4 additions & 0 deletions velox/core/tests/ConstantTypedExprTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "velox/core/Expressions.h"
#include "velox/functions/prestosql/types/HyperLogLogType.h"
#include "velox/functions/prestosql/types/JsonType.h"
#include "velox/functions/prestosql/types/TDigestType.h"
#include "velox/functions/prestosql/types/TimestampWithTimeZoneType.h"

namespace facebook::velox::core::test {
Expand Down Expand Up @@ -47,6 +48,9 @@ TEST(ConstantTypedExprTest, null) {
EXPECT_FALSE(*makeNull(HYPERLOGLOG()) == *makeNull(VARBINARY()));
EXPECT_FALSE(*makeNull(VARBINARY()) == *makeNull(HYPERLOGLOG()));

EXPECT_FALSE(*makeNull(TDIGEST(DOUBLE())) == *makeNull(VARBINARY()));
EXPECT_FALSE(*makeNull(VARBINARY()) == *makeNull(TDIGEST(DOUBLE())));

EXPECT_FALSE(*makeNull(TIMESTAMP_WITH_TIME_ZONE()) == *makeNull(BIGINT()));
EXPECT_FALSE(*makeNull(BIGINT()) == *makeNull(TIMESTAMP_WITH_TIME_ZONE()));

Expand Down
22 changes: 15 additions & 7 deletions velox/expression/tests/CustomTypeTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ TEST_F(CustomTypeTest, getCustomTypeNames) {
"IPADDRESS",
"IPPREFIX",
"BINGTILE",
}),
"TDIGEST"}),
names);

ASSERT_TRUE(registerCustomType(
Expand All @@ -248,7 +248,7 @@ TEST_F(CustomTypeTest, getCustomTypeNames) {
"IPPREFIX",
"BINGTILE",
"FANCY_INT",
}),
"TDIGEST"}),
names);

ASSERT_TRUE(unregisterCustomType("fancy_int"));
Expand All @@ -257,19 +257,27 @@ TEST_F(CustomTypeTest, getCustomTypeNames) {
TEST_F(CustomTypeTest, nullConstant) {
ASSERT_TRUE(registerCustomType(
"fancy_int", std::make_unique<FancyIntTypeFactories>()));

auto names = getCustomTypeNames();
for (const auto& name : names) {
auto type = getCustomType(name, {});
auto checkNullConstant = [&](const TypePtr& type,
const std::string& expectedTypeString) {
auto null = BaseVector::createNullConstant(type, 10, pool());
EXPECT_TRUE(null->isConstantEncoding());
EXPECT_TRUE(type->equivalent(*null->type()));
EXPECT_EQ(type->toString(), null->type()->toString());
EXPECT_EQ(type->toString(), expectedTypeString);
for (auto i = 0; i < 10; ++i) {
EXPECT_TRUE(null->isNullAt(i));
}
};
auto names = getCustomTypeNames();
for (const auto& name : names) {
if (name == "TDIGEST") {
auto type = getCustomType(name, {TypeParameter(DOUBLE())});
checkNullConstant(type, "TDIGEST(DOUBLE)");
} else {
auto type = getCustomType(name, {});
checkNullConstant(type, type->toString());
}
}

ASSERT_TRUE(unregisterCustomType("fancy_int"));
}

Expand Down
1 change: 1 addition & 0 deletions velox/functions/prestosql/registration/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ velox_add_library(
ProbabilityTrigonometricFunctionsRegistration.cpp
RegistrationFunctions.cpp
StringFunctionsRegistration.cpp
TDigestFunctionsRegistration.cpp
URLFunctionsRegistration.cpp)

# GCC 12 has a bug where it does not respect "pragma ignore" directives and ends
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ extern void registerComparisonFunctions(const std::string& prefix);
extern void registerDateTimeFunctions(const std::string& prefix);
extern void registerGeneralFunctions(const std::string& prefix);
extern void registerHyperLogFunctions(const std::string& prefix);
extern void registerTDigestFunctions(const std::string& prefix);
extern void registerIntegerFunctions(const std::string& prefix);
extern void registerJsonFunctions(const std::string& prefix);
extern void registerMapFunctions(const std::string& prefix);
Expand Down Expand Up @@ -72,6 +73,10 @@ void registerHyperLogFunctions(const std::string& prefix) {
functions::registerHyperLogFunctions(prefix);
}

void registerTDigestFunctions(const std::string& prefix) {
functions::registerTDigestFunctions(prefix);
}

void registerIntegerFunctions(const std::string& prefix) {
functions::registerIntegerFunctions(prefix);
}
Expand Down Expand Up @@ -112,6 +117,7 @@ void registerAllScalarFunctions(const std::string& prefix) {
registerArrayFunctions(prefix);
registerJsonFunctions(prefix);
registerHyperLogFunctions(prefix);
registerTDigestFunctions(prefix);
registerIntegerFunctions(prefix);
registerGeospatialFunctions(prefix);
registerGeneralFunctions(prefix);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ void registerJsonFunctions(const std::string& prefix = "");

void registerHyperLogFunctions(const std::string& prefix = "");

void registerTDigestFunctions(const std::string& prefix = "");

void registerGeospatialFunctions(const std::string& prefix = "");

void registerGeneralFunctions(const std::string& prefix = "");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "velox/functions/Registerer.h"
#include "velox/functions/prestosql/types/TDigestRegistration.h"

namespace facebook::velox::functions {

void registerTDigestFunctions(const std::string& prefix) {
registerTDigestType();
}
} // namespace facebook::velox::functions
4 changes: 4 additions & 0 deletions velox/vector/tests/VectorSaverTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include "velox/functions/prestosql/types/HyperLogLogType.h"
#include "velox/functions/prestosql/types/JsonRegistration.h"
#include "velox/functions/prestosql/types/JsonType.h"
#include "velox/functions/prestosql/types/TDigestRegistration.h"
#include "velox/functions/prestosql/types/TDigestType.h"
#include "velox/functions/prestosql/types/TimestampWithTimeZoneRegistration.h"
#include "velox/functions/prestosql/types/TimestampWithTimeZoneType.h"
#include "velox/vector/fuzzer/VectorFuzzer.h"
Expand All @@ -40,6 +42,7 @@ class VectorSaverTest : public testing::Test, public VectorTestBase {
registerJsonType();
registerHyperLogLogType();
registerTimestampWithTimeZoneType();
registerTDigestType();
}

void SetUp() override {
Expand Down Expand Up @@ -268,6 +271,7 @@ TEST_F(VectorSaverTest, types) {
testTypeRoundTrip(JSON());
testTypeRoundTrip(HYPERLOGLOG());
testTypeRoundTrip(TIMESTAMP_WITH_TIME_ZONE());
testTypeRoundTrip(TDIGEST(DOUBLE()));
}

TEST_F(VectorSaverTest, selectivityVector) {
Expand Down

0 comments on commit bfeb189

Please sign in to comment.