-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: This PR only adds the IPPrefix type classes. CAST logic is not implemented. The next PR for IPPrefix type will enhance the fuzzers for IPPrefix type. After that we will add the CAST logic so that it can be tested with fuzzers from the start itself. The full logic for IPPrefix is available in PRs : Original PR: #10538 Original Split PR: #10816 Pull Request resolved: #11122 Reviewed By: Yuhta Differential Revision: D64917429 Pulled By: pedroerp fbshipit-source-id: 2aef68d20de20673d9cc9239c98178ffc803860d
- Loading branch information
1 parent
624a21c
commit c8ac4e3
Showing
12 changed files
with
260 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
using type = Row<int128_t, int8_t>; | ||
static constexpr const char* typeName = "ipprefix"; | ||
}; | ||
|
||
using IPPrefix = CustomType<IPPrefixT>; | ||
|
||
void registerIPPrefixType(); | ||
|
||
} // namespace facebook::velox |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
velox/functions/prestosql/types/tests/IPPrefixTypeTest.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters