kszucs commented on a change in pull request #11707: URL: https://github.com/apache/arrow/pull/11707#discussion_r767928625
########## File path: cpp/src/arrow/engine/substrait/extension_types.cc ########## @@ -0,0 +1,307 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you 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 "arrow/engine/substrait/extension_types.h" + +#include <unordered_map> +#include <unordered_set> + +#include "arrow/engine/simple_extension_type_internal.h" +#include "arrow/util/hash_util.h" +#include "arrow/util/hashing.h" +#include "arrow/util/string_view.h" + +namespace arrow { +namespace engine { +namespace { + +constexpr util::string_view kUuidExtensionName = "uuid"; +struct UuidExtensionParams {}; +std::shared_ptr<DataType> UuidGetStorage(const UuidExtensionParams&) { + return fixed_size_binary(16); +} +static auto kUuidExtensionParamsProperties = internal::MakeProperties(); + +using UuidType = SimpleExtensionType<kUuidExtensionName, UuidExtensionParams, + decltype(kUuidExtensionParamsProperties), + kUuidExtensionParamsProperties, UuidGetStorage>; + +constexpr util::string_view kFixedCharExtensionName = "fixed_char"; +struct FixedCharExtensionParams { + int32_t length; +}; +std::shared_ptr<DataType> FixedCharGetStorage(const FixedCharExtensionParams& params) { + return fixed_size_binary(params.length); +} +static auto kFixedCharExtensionParamsProperties = internal::MakeProperties( + internal::DataMember("length", &FixedCharExtensionParams::length)); + +using FixedCharType = + SimpleExtensionType<kFixedCharExtensionName, FixedCharExtensionParams, + decltype(kFixedCharExtensionParamsProperties), + kFixedCharExtensionParamsProperties, FixedCharGetStorage>; + +constexpr util::string_view kVarCharExtensionName = "varchar"; +struct VarCharExtensionParams { + int32_t length; +}; +std::shared_ptr<DataType> VarCharGetStorage(const VarCharExtensionParams&) { + return utf8(); +} +static auto kVarCharExtensionParamsProperties = internal::MakeProperties( + internal::DataMember("length", &VarCharExtensionParams::length)); + +using VarCharType = + SimpleExtensionType<kVarCharExtensionName, VarCharExtensionParams, + decltype(kVarCharExtensionParamsProperties), + kVarCharExtensionParamsProperties, VarCharGetStorage>; + +constexpr util::string_view kIntervalYearExtensionName = "interval_year"; +struct IntervalYearExtensionParams {}; +std::shared_ptr<DataType> IntervalYearGetStorage(const IntervalYearExtensionParams&) { + return fixed_size_list(int32(), 2); +} +static auto kIntervalYearExtensionParamsProperties = internal::MakeProperties(); + +using IntervalYearType = + SimpleExtensionType<kIntervalYearExtensionName, IntervalYearExtensionParams, + decltype(kIntervalYearExtensionParamsProperties), + kIntervalYearExtensionParamsProperties, IntervalYearGetStorage>; + +constexpr util::string_view kIntervalDayExtensionName = "interval_day"; +struct IntervalDayExtensionParams {}; +std::shared_ptr<DataType> IntervalDayGetStorage(const IntervalDayExtensionParams&) { + return fixed_size_list(int32(), 2); +} +static auto kIntervalDayExtensionParamsProperties = internal::MakeProperties(); + +using IntervalDayType = + SimpleExtensionType<kIntervalDayExtensionName, IntervalDayExtensionParams, + decltype(kIntervalDayExtensionParamsProperties), + kIntervalDayExtensionParamsProperties, IntervalDayGetStorage>; + +} // namespace + +std::shared_ptr<DataType> uuid() { return UuidType::Make({}); } + +std::shared_ptr<DataType> fixed_char(int32_t length) { + return FixedCharType::Make({length}); +} + +std::shared_ptr<DataType> varchar(int32_t length) { return VarCharType::Make({length}); } + +std::shared_ptr<DataType> interval_year() { return IntervalYearType::Make({}); } + +std::shared_ptr<DataType> interval_day() { return IntervalDayType::Make({}); } + +bool UnwrapUuid(const DataType& t) { + if (auto params = UuidType::GetIf(t)) { + return true; + } + return false; +} + +util::optional<int32_t> UnwrapFixedChar(const DataType& t) { + if (auto params = FixedCharType::GetIf(t)) { + return params->length; + } + return util::nullopt; +} + +util::optional<int32_t> UnwrapVarChar(const DataType& t) { + if (auto params = VarCharType::GetIf(t)) { + return params->length; + } + return util::nullopt; +} + +bool UnwrapIntervalYear(const DataType& t) { + if (auto params = IntervalYearType::GetIf(t)) { + return true; + } + return false; +} + +bool UnwrapIntervalDay(const DataType& t) { + if (auto params = IntervalDayType::GetIf(t)) { + return true; + } + return false; +} + +struct ExtensionSet::Impl { + struct IdHash { + size_t operator()(Id id) const { + internal::StringViewHash hash; + auto out = hash(id.uri); Review comment: I had to annotate with `size_t out` locally otherwise: ``` /Users/kszucs/Workspace/arrow/cpp/src/arrow/engine/substrait/extension_types.cc:151:7: error: no matching function for call to 'hash_combine' internal::hash_combine(out, hash(id.name)); ^~~~~~~~~~~~~~~~~~~~~~ /Users/kszucs/Workspace/arrow/cpp/src/arrow/util/hash_util.h:57:13: note: candidate function template not viable: no known conversion from 'unsigned long long' to 'std::size_t &' (aka 'unsigned long &') for 1st argument inline void hash_combine(std::size_t& seed, T const& v) { ^ ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
