forked from facebookincubator/velox
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
227 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,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. | ||
*/ | ||
|
||
#include "velox/functions/prestosql/types/IPPrefixType.h" | ||
#include <folly/IPAddress.h> | ||
#include <folly/small_vector.h> | ||
#include "velox/expression/CastExpr.h" | ||
#include "velox/functions/prestosql/types/IPAddressType.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_UNSUPPORTED( | ||
"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_UNSUPPORTED( | ||
"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,73 @@ | ||
/* | ||
* 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 VarbinaryType { | ||
IPPrefixType() = default; | ||
|
||
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; | ||
} | ||
}; | ||
|
||
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 = Varbinary; | ||
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(), "VARBINARY"); | ||
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 |