You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kudu.apache.org by gr...@apache.org on 2019/02/12 22:34:28 UTC

[kudu] 03/03: [client] Fix GetUnscaledDecimal backward compatiblity

This is an automated email from the ASF dual-hosted git repository.

granthenke pushed a commit to branch branch-1.9.x
in repository https://gitbox.apache.org/repos/asf/kudu.git

commit 320a799762d5eb13a30e9cc1a811f90478dd8c1f
Author: Grant Henke <gr...@apache.org>
AuthorDate: Mon Feb 11 15:54:37 2019 -0600

    [client] Fix GetUnscaledDecimal backward compatiblity
    
    We added the const version of GetUnscaledDecimal to
    the KuduPartialRow. However, that change was not
    backward compatible. This patch adds back the
    non-const version of the function and tests to
    ensure calling both is successful.
    
    Change-Id: I1bce3f6df6a09327a503f2793ed1317e147349c9
    Reviewed-on: http://gerrit.cloudera.org:8080/12454
    Tested-by: Kudu Jenkins
    Reviewed-by: Adar Dembo <ad...@cloudera.com>
---
 src/kudu/common/partial_row-test.cc | 15 ++++++++++++++-
 src/kudu/common/partial_row.cc      |  8 ++++++++
 src/kudu/common/partial_row.h       |  4 ++++
 3 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/src/kudu/common/partial_row-test.cc b/src/kudu/common/partial_row-test.cc
index 5421f1d..383a090 100644
--- a/src/kudu/common/partial_row-test.cc
+++ b/src/kudu/common/partial_row-test.cc
@@ -15,6 +15,8 @@
 // specific language governing permissions and limitations
 // under the License.
 
+#include "kudu/common/partial_row.h"
+
 #include <cstdint>
 #include <functional>
 #include <string>
@@ -22,8 +24,8 @@
 #include <gtest/gtest.h>
 
 #include "kudu/common/common.pb.h"
-#include "kudu/common/partial_row.h"
 #include "kudu/common/schema.h"
+#include "kudu/util/int128.h"
 #include "kudu/util/slice.h"
 #include "kudu/util/status.h"
 #include "kudu/util/test_macros.h"
@@ -214,6 +216,17 @@ TEST_F(PartialRowTest, UnitTest) {
   EXPECT_TRUE(row.IsColumnSet(4));
   EXPECT_EQ("decimal decimal_val=123456_D32", row.ToString());
 
+  // Get a decimal value using the const version of the function.
+  int128_t decValFromConst;
+  EXPECT_OK(const_cast<const KuduPartialRow&>(row).GetUnscaledDecimal("decimal_val",
+      &decValFromConst));
+  EXPECT_EQ(123456, decValFromConst);
+
+  // Get a decimal value the backward compatible non-const version of the function.
+  int128_t decValFromNonConst;
+  EXPECT_OK(row.GetUnscaledDecimal("decimal_val", &decValFromNonConst));
+  EXPECT_EQ(123456, decValFromNonConst);
+
   // Set the max decimal value for the decimal_val column
   EXPECT_OK(row.SetUnscaledDecimal("decimal_val", 999999));
   EXPECT_EQ("decimal decimal_val=999999_D32", row.ToString());
diff --git a/src/kudu/common/partial_row.cc b/src/kudu/common/partial_row.cc
index cb422f5..07719f8 100644
--- a/src/kudu/common/partial_row.cc
+++ b/src/kudu/common/partial_row.cc
@@ -650,6 +650,10 @@ Status KuduPartialRow::GetFloat(const Slice& col_name, float* val) const {
 Status KuduPartialRow::GetDouble(const Slice& col_name, double* val) const {
   return Get<TypeTraits<DOUBLE> >(col_name, val);
 }
+Status KuduPartialRow::GetUnscaledDecimal(const Slice &col_name, int128_t *val) {
+  // Call the const version of the function.
+  return const_cast<const KuduPartialRow*>(this)->GetUnscaledDecimal(col_name, val);
+}
 Status KuduPartialRow::GetUnscaledDecimal(const Slice &col_name, int128_t *val) const {
   int col_idx;
   RETURN_NOT_OK(FindColumn(*schema_, col_name, &col_idx));
@@ -686,6 +690,10 @@ Status KuduPartialRow::GetFloat(int col_idx, float* val) const {
 Status KuduPartialRow::GetDouble(int col_idx, double* val) const {
   return Get<TypeTraits<DOUBLE> >(col_idx, val);
 }
+Status KuduPartialRow::GetUnscaledDecimal(int col_idx, int128_t *val) {
+  // Call the const version of the function.
+  return const_cast<const KuduPartialRow*>(this)->GetUnscaledDecimal(col_idx, val);
+}
 Status KuduPartialRow::GetUnscaledDecimal(int col_idx, int128_t *val) const {
   const ColumnSchema& col = schema_->column(col_idx);
   const DataType col_type = col.type_info()->type();
diff --git a/src/kudu/common/partial_row.h b/src/kudu/common/partial_row.h
index 3dca69d..11698f4 100644
--- a/src/kudu/common/partial_row.h
+++ b/src/kudu/common/partial_row.h
@@ -361,6 +361,8 @@ class KUDU_EXPORT KuduPartialRow {
   Status GetFloat(const Slice& col_name, float* val) const WARN_UNUSED_RESULT;
   Status GetDouble(const Slice& col_name, double* val) const WARN_UNUSED_RESULT;
 #if KUDU_INT128_SUPPORTED
+  // NOTE: The non-const version of this function is kept for backwards compatibility.
+  Status GetUnscaledDecimal(const Slice& col_name, int128_t* val) WARN_UNUSED_RESULT;
   Status GetUnscaledDecimal(const Slice& col_name, int128_t* val) const WARN_UNUSED_RESULT;
 #endif
   ///@}
@@ -394,6 +396,8 @@ class KUDU_EXPORT KuduPartialRow {
   Status GetFloat(int col_idx, float* val) const WARN_UNUSED_RESULT;
   Status GetDouble(int col_idx, double* val) const WARN_UNUSED_RESULT;
 #if KUDU_INT128_SUPPORTED
+  // NOTE: The non-const version of this function is kept for backwards compatibility.
+  Status GetUnscaledDecimal(int col_idx, int128_t* val) WARN_UNUSED_RESULT;
   Status GetUnscaledDecimal(int col_idx, int128_t* val) const WARN_UNUSED_RESULT;
 #endif
   ///@}