-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Add IPPREFIX type #11122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add IPPREFIX type #11122
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,11 +16,13 @@ | |
| #pragma once | ||
|
|
||
| #include "velox/functions/prestosql/types/IPAddressType.h" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe add some tests in FunctionRegistryTest or CustomTypeTest to ensure that we can register functions with type IPPREFIX and retrieve them ?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added simple function registration and resolution test into FunctionRegistryTest |
||
| #include "velox/functions/prestosql/types/IPPrefixType.h" | ||
|
|
||
| namespace facebook::velox::functions { | ||
|
|
||
| void registerIPAddressFunctions(const std::string& prefix) { | ||
| registerIPAddressType(); | ||
| registerIPPrefixType(); | ||
| } | ||
|
|
||
| } // namespace facebook::velox::functions | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| /* | ||
| * 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 <folly/small_vector.h> | ||
|
|
||
| #include "velox/expression/CastExpr.h" | ||
| #include "velox/functions/prestosql/types/IPPrefixType.h" | ||
|
|
||
| namespace facebook::velox { | ||
|
|
||
| namespace { | ||
|
|
||
| class IPPrefixCastOperator : public exec::CastOperator { | ||
| public: | ||
| bool isSupportedFromType(const TypePtr& other) const override { | ||
| return false; | ||
| } | ||
|
|
||
| bool isSupportedToType(const TypePtr& other) const override { | ||
| return false; | ||
| } | ||
|
|
||
| void castTo( | ||
| const BaseVector& input, | ||
| exec::EvalCtx& context, | ||
| const SelectivityVector& rows, | ||
| const TypePtr& resultType, | ||
| VectorPtr& result) const override { | ||
| context.ensureWritable(rows, resultType, result); | ||
| VELOX_NYI( | ||
| "Cast from {} to IPPrefix not yet supported", input.type()->toString()); | ||
| } | ||
|
|
||
| void castFrom( | ||
| const BaseVector& input, | ||
| exec::EvalCtx& context, | ||
| const SelectivityVector& rows, | ||
| const TypePtr& resultType, | ||
| VectorPtr& result) const override { | ||
| context.ensureWritable(rows, resultType, result); | ||
| VELOX_NYI( | ||
| "Cast from IPPrefix to {} not yet supported", resultType->toString()); | ||
| } | ||
| }; | ||
|
|
||
| class IPPrefixTypeFactories : public CustomTypeFactories { | ||
| public: | ||
| TypePtr getType() const override { | ||
| return IPPrefixType::get(); | ||
| } | ||
|
|
||
| exec::CastOperatorPtr getCastOperator() const override { | ||
| return std::make_shared<IPPrefixCastOperator>(); | ||
| } | ||
| }; | ||
|
|
||
| } // namespace | ||
|
|
||
| void registerIPPrefixType() { | ||
| registerCustomType( | ||
| "ipprefix", std::make_unique<const IPPrefixTypeFactories>()); | ||
| } | ||
|
|
||
| } // namespace facebook::velox |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
| #pragma once | ||
|
|
||
| #include "velox/type/SimpleFunctionApi.h" | ||
| #include "velox/type/Type.h" | ||
|
|
||
| namespace facebook::velox { | ||
|
|
||
| class IPPrefixType : public RowType { | ||
| IPPrefixType() : RowType({"ip", "prefix"}, {HUGEINT(), TINYINT()}) {} | ||
|
|
||
| public: | ||
| static const std::shared_ptr<const IPPrefixType>& get() { | ||
| static const std::shared_ptr<const IPPrefixType> instance{ | ||
| new IPPrefixType()}; | ||
|
|
||
| return instance; | ||
| } | ||
|
|
||
| bool equivalent(const Type& other) const override { | ||
| // Pointer comparison works since this type is a singleton. | ||
| return this == &other; | ||
| } | ||
|
|
||
| const char* name() const override { | ||
| return "IPPREFIX"; | ||
| } | ||
|
|
||
| std::string toString() const override { | ||
| return name(); | ||
| } | ||
|
|
||
| folly::dynamic serialize() const override { | ||
| folly::dynamic obj = folly::dynamic::object; | ||
| obj["name"] = "Type"; | ||
| obj["type"] = name(); | ||
| return obj; | ||
| } | ||
|
|
||
| const std::vector<TypeParameter>& parameters() const override { | ||
| static const std::vector<TypeParameter> kEmpty = {}; | ||
| return kEmpty; | ||
| } | ||
| }; | ||
|
|
||
| FOLLY_ALWAYS_INLINE bool isIPPrefixType(const TypePtr& type) { | ||
| // Pointer comparison works since this type is a singleton. | ||
| return IPPrefixType::get() == type; | ||
| } | ||
|
|
||
| FOLLY_ALWAYS_INLINE std::shared_ptr<const IPPrefixType> IPPREFIX() { | ||
| return IPPrefixType::get(); | ||
| } | ||
|
|
||
| struct IPPrefixT { | ||
|
mohsaka marked this conversation as resolved.
|
||
| using type = Row<int128_t, int8_t>; | ||
| static constexpr const char* typeName = "ipprefix"; | ||
| }; | ||
|
|
||
| using IPPrefix = CustomType<IPPrefixT>; | ||
|
|
||
| void registerIPPrefixType(); | ||
|
|
||
| } // namespace facebook::velox | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| /* | ||
| * 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/prestosql/types/IPPrefixType.h" | ||
| #include "velox/functions/prestosql/types/tests/TypeTestBase.h" | ||
|
|
||
| namespace facebook::velox::test { | ||
|
|
||
| class IPPrefixTypeTest : public testing::Test, public TypeTestBase { | ||
| public: | ||
| IPPrefixTypeTest() { | ||
| registerIPPrefixType(); | ||
| } | ||
| }; | ||
|
|
||
| TEST_F(IPPrefixTypeTest, basic) { | ||
| ASSERT_STREQ(IPPREFIX()->name(), "IPPREFIX"); | ||
| ASSERT_STREQ(IPPREFIX()->kindName(), "ROW"); | ||
| ASSERT_EQ(IPPREFIX()->name(), "IPPREFIX"); | ||
| ASSERT_TRUE(IPPREFIX()->parameters().empty()); | ||
|
|
||
| ASSERT_TRUE(hasType("IPPREFIX")); | ||
| ASSERT_EQ(*getType("IPPREFIX", {}), *IPPREFIX()); | ||
| } | ||
|
|
||
| TEST_F(IPPrefixTypeTest, serde) { | ||
| testTypeSerde(IPPREFIX()); | ||
| } | ||
| } // namespace facebook::velox::test |
Uh oh!
There was an error while loading. Please reload this page.