kszucs commented on a change in pull request #7519:
URL: https://github.com/apache/arrow/pull/7519#discussion_r450318972



##########
File path: cpp/src/arrow/scalar.cc
##########
@@ -185,6 +192,35 @@ 
DictionaryScalar::DictionaryScalar(std::shared_ptr<DataType> type)
                             0)
                 .ValueOrDie()} {}
 
+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::INT8:
+      index_value = checked_cast<const Int8Scalar&>(*value.index).value;
+      break;
+    case Type::INT16:
+      index_value = checked_cast<const Int16Scalar&>(*value.index).value;
+      break;
+    case Type::INT32:
+      index_value = checked_cast<const Int32Scalar&>(*value.index).value;
+      break;
+    case Type::INT64:
+      index_value = checked_cast<const Int64Scalar&>(*value.index).value;
+      break;
+    default:
+      return Status::Invalid("Not implemented dictionary index type");

Review comment:
       Updating.

##########
File path: cpp/src/arrow/scalar_test.cc
##########
@@ -80,6 +84,15 @@ TYPED_TEST(TestNumericScalar, Basics) {
 
   auto dyn_null_value = MakeNullScalar(expected_type);
   ASSERT_EQ(*null_value, *dyn_null_value);
+
+  // test Array.GetScalar
+  auto arr = ArrayFromJSON(expected_type, "[null, 1, 2]");
+  ASSERT_OK_AND_ASSIGN(auto null, arr->GetScalar(0));
+  ASSERT_OK_AND_ASSIGN(auto one, arr->GetScalar(1));
+  ASSERT_OK_AND_ASSIGN(auto two, arr->GetScalar(2));
+  ASSERT_TRUE(null->Equals(*null_value));
+  ASSERT_TRUE(one->Equals(ScalarType(1)));
+  ASSERT_TRUE(two->Equals(ScalarType(2)));

Review comment:
       Not yet, adding check for it.




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to