goel-skd commented on code in PR #50347:
URL: https://github.com/apache/arrow/pull/50347#discussion_r3544309470
##########
cpp/src/arrow/scalar.cc:
##########
@@ -770,54 +770,56 @@
DictionaryScalar::DictionaryScalar(std::shared_ptr<DataType> type)
0)
.ValueOrDie()} {}
+namespace {
+
+struct DictionaryIndexValueImpl {
+ int64_t value = 0;
+
+ Status Visit(const Scalar&) {
+ return Status::TypeError("Not implemented dictionary index type");
+ }
+
+ template <typename ScalarType, typename Type = typename
ScalarType::TypeClass>
+ enable_if_integer<Type, Status> Visit(const ScalarType& scalar) {
+ value = static_cast<int64_t>(scalar.value);
+ return Status::OK();
+ }
+};
+
+Result<int64_t> DictionaryIndexValue(const Scalar& index) {
+ DictionaryIndexValueImpl impl;
+ RETURN_NOT_OK(VisitScalarInline(index, &impl));
+ return impl.value;
+}
+
+} // namespace
+
Result<std::shared_ptr<Scalar>> DictionaryScalar::GetEncodedValue() const {
const auto& dict_type = checked_cast<DictionaryType&>(*type);
if (!is_valid) {
return MakeNullScalar(dict_type.value_type());
}
- int64_t index_value = 0;
- switch (dict_type.index_type()->id()) {
- case Type::UINT8:
- index_value =
- static_cast<int64_t>(checked_cast<const
UInt8Scalar&>(*value.index).value);
- break;
- case Type::INT8:
- index_value =
- static_cast<int64_t>(checked_cast<const
Int8Scalar&>(*value.index).value);
- break;
- case Type::UINT16:
- index_value =
- static_cast<int64_t>(checked_cast<const
UInt16Scalar&>(*value.index).value);
- break;
- case Type::INT16:
- index_value =
- static_cast<int64_t>(checked_cast<const
Int16Scalar&>(*value.index).value);
- break;
- case Type::UINT32:
- index_value =
- static_cast<int64_t>(checked_cast<const
UInt32Scalar&>(*value.index).value);
- break;
- case Type::INT32:
- index_value =
- static_cast<int64_t>(checked_cast<const
Int32Scalar&>(*value.index).value);
- break;
- case Type::UINT64:
- index_value =
- static_cast<int64_t>(checked_cast<const
UInt64Scalar&>(*value.index).value);
- break;
- case Type::INT64:
- index_value =
- static_cast<int64_t>(checked_cast<const
Int64Scalar&>(*value.index).value);
- break;
- default:
- return Status::TypeError("Not implemented dictionary index type");
- break;
- }
Review Comment:
Did a small refactor while I was here!
--
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]