This is an automated email from the ASF dual-hosted git repository.
alexey pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git
The following commit(s) were added to refs/heads/master by this push:
new aec4c62de KUDU-1945 [client] Add UINT64 support to cpp client
aec4c62de is described below
commit aec4c62de56b8768b1ecc24fc6c08079f972df1f
Author: Abhishek Chennaka <[email protected]>
AuthorDate: Tue Nov 22 17:08:50 2022 -0500
KUDU-1945 [client] Add UINT64 support to cpp client
This patch adds cpp client support to UINT64 data type. Although it is
exposed to the end user by the name SERIAL. This is because this data
type is primarily expected to store auto-incrementing column data type.
Change-Id: I36da282f8f103d642256ea6aaadd1d052ab2f234
Reviewed-on: http://gerrit.cloudera.org:8080/19267
Tested-by: Alexey Serbin <[email protected]>
Reviewed-by: Alexey Serbin <[email protected]>
---
src/kudu/client/schema.cc | 6 ++++
src/kudu/client/schema.h | 3 +-
src/kudu/common/partial_row-test.cc | 72 +++++++++++++++++++++++--------------
src/kudu/common/partial_row.cc | 12 +++++++
src/kudu/common/partial_row.h | 4 +++
src/kudu/tools/tool_action_table.cc | 9 +++++
6 files changed, 79 insertions(+), 27 deletions(-)
diff --git a/src/kudu/client/schema.cc b/src/kudu/client/schema.cc
index 1acb290c9..d1b09c780 100644
--- a/src/kudu/client/schema.cc
+++ b/src/kudu/client/schema.cc
@@ -128,6 +128,7 @@ kudu::DataType
ToInternalDataType(KuduColumnSchema::DataType type,
case KuduColumnSchema::INT16: return kudu::INT16;
case KuduColumnSchema::INT32: return kudu::INT32;
case KuduColumnSchema::INT64: return kudu::INT64;
+ case KuduColumnSchema::SERIAL: return kudu::UINT64;
case KuduColumnSchema::UNIXTIME_MICROS: return kudu::UNIXTIME_MICROS;
case KuduColumnSchema::DATE: return kudu::DATE;
case KuduColumnSchema::FLOAT: return kudu::FLOAT;
@@ -156,6 +157,7 @@ KuduColumnSchema::DataType
FromInternalDataType(kudu::DataType type) {
case kudu::INT16: return KuduColumnSchema::INT16;
case kudu::INT32: return KuduColumnSchema::INT32;
case kudu::INT64: return KuduColumnSchema::INT64;
+ case kudu::UINT64: return KuduColumnSchema::SERIAL;
case kudu::UNIXTIME_MICROS: return KuduColumnSchema::UNIXTIME_MICROS;
case kudu::DATE: return KuduColumnSchema::DATE;
case kudu::FLOAT: return KuduColumnSchema::FLOAT;
@@ -703,6 +705,8 @@ string KuduColumnSchema::DataTypeToString(DataType type) {
return "DECIMAL";
case VARCHAR:
return "VARCHAR";
+ case SERIAL:
+ return "SERIAL";
}
LOG(FATAL) << "Unhandled type " << type;
}
@@ -737,6 +741,8 @@ string KuduColumnSchema::DataTypeToString(DataType type) {
*type = VARCHAR;
} else if (type_uc == "DATE") {
*type = DATE;
+ } else if (type_uc == "SERIAL") {
+ *type = SERIAL;
} else {
return Status::InvalidArgument(Substitute(
"data type $0 is not supported", type_str));
diff --git a/src/kudu/client/schema.h b/src/kudu/client/schema.h
index a7a8af6e5..e4637f5d9 100644
--- a/src/kudu/client/schema.h
+++ b/src/kudu/client/schema.h
@@ -229,7 +229,8 @@ class KUDU_EXPORT KuduColumnSchema {
DECIMAL = 10,
VARCHAR = 11,
TIMESTAMP = UNIXTIME_MICROS, //!< deprecated, use UNIXTIME_MICROS
- DATE = 12
+ DATE = 12,
+ SERIAL = 13
};
/// @param [in] type
diff --git a/src/kudu/common/partial_row-test.cc
b/src/kudu/common/partial_row-test.cc
index 5aaa817ce..03222bda3 100644
--- a/src/kudu/common/partial_row-test.cc
+++ b/src/kudu/common/partial_row-test.cc
@@ -40,6 +40,7 @@ class PartialRowTest : public KuduTest {
PartialRowTest()
: schema_({ ColumnSchema("key", INT32),
ColumnSchema("int_val", INT32),
+ ColumnSchema("uint64_val", UINT64),
ColumnSchema("string_val", STRING, true),
ColumnSchema("binary_val", BINARY, true),
ColumnSchema("decimal_val", DECIMAL32, true, false, nullptr,
nullptr,
@@ -134,6 +135,7 @@ TEST_F(PartialRowTest, UnitTest) {
EXPECT_FALSE(row.IsColumnSet(3));
EXPECT_FALSE(row.IsColumnSet(4));
EXPECT_FALSE(row.IsColumnSet(5));
+ EXPECT_FALSE(row.IsColumnSet(6));
EXPECT_FALSE(row.IsKeySet());
EXPECT_EQ("", row.ToString());
@@ -158,19 +160,29 @@ TEST_F(PartialRowTest, UnitTest) {
// Fill in the other columns.
EXPECT_OK(row.SetInt32("int_val", 54321));
+ EXPECT_OK(row.GetInt32("int_val", &x));
+ EXPECT_EQ(54321, x);
+ EXPECT_OK(row.SetSerial("uint64_val", 7654321));
+ uint64_t y;
+ EXPECT_OK(row.GetSerial("uint64_val", &y));
+ EXPECT_EQ(7654321, y);
EXPECT_OK(row.SetStringCopy("string_val", "hello world"));
+ Slice slice;
+ EXPECT_OK(row.GetString("string_val", &slice));
+ EXPECT_EQ("hello world", slice.ToString());
EXPECT_TRUE(row.IsColumnSet(1));
EXPECT_TRUE(row.IsColumnSet(2));
- EXPECT_EQ(R"(int32 key=12345, int32 int_val=54321, string string_val="hello
world")",
- row.ToString());
- Slice slice;
+ EXPECT_TRUE(row.IsColumnSet(3));
+ EXPECT_EQ(R"(int32 key=12345, int32 int_val=54321, uint64
uint64_val=7654321, )"
+ R"(string string_val="hello world")",row.ToString());
EXPECT_OK(row.GetString("string_val", &slice));
EXPECT_EQ("hello world", slice.ToString());
EXPECT_FALSE(row.IsNull("key"));
// Set a nullable entry to NULL
EXPECT_OK(row.SetNull("string_val"));
- EXPECT_EQ("int32 key=12345, int32 int_val=54321, string string_val=NULL",
+ EXPECT_EQ("int32 key=12345, int32 int_val=54321, uint64 uint64_val=7654321, "
+ "string string_val=NULL",
row.ToString());
EXPECT_TRUE(row.IsNull("string_val"));
@@ -190,14 +202,17 @@ TEST_F(PartialRowTest, UnitTest) {
// Set the NULL string back to non-NULL
EXPECT_OK(row.SetStringCopy("string_val", "goodbye world"));
- EXPECT_EQ(R"(int32 key=12345, int32 int_val=54321, string
string_val="goodbye world")",
- row.ToString());
+ EXPECT_EQ(R"(int32 key=12345, int32 int_val=54321, uint64
uint64_val=7654321, )"
+ R"(string string_val="goodbye world")",row.ToString());
// Unset some columns.
EXPECT_OK(row.Unset("string_val"));
- EXPECT_EQ("int32 key=12345, int32 int_val=54321", row.ToString());
+ EXPECT_EQ("int32 key=12345, int32 int_val=54321, uint64 uint64_val=7654321",
row.ToString());
EXPECT_OK(row.Unset("key"));
+ EXPECT_EQ("int32 int_val=54321, uint64 uint64_val=7654321", row.ToString());
+
+ EXPECT_OK(row.Unset("uint64_val"));
EXPECT_EQ("int32 int_val=54321", row.ToString());
// Set the column by index
@@ -218,7 +233,7 @@ TEST_F(PartialRowTest, UnitTest) {
// Set a decimal column
EXPECT_OK(row.SetUnscaledDecimal("decimal_val", 123456));
- EXPECT_TRUE(row.IsColumnSet(4));
+ EXPECT_TRUE(row.IsColumnSet(5));
EXPECT_EQ("decimal decimal_val=123456_D32", row.ToString());
// Get a decimal value using the const version of the function.
@@ -261,10 +276,10 @@ TEST_F(PartialRowTest, UnitTest) {
EXPECT_FALSE(row.SetBinaryCopy("string_val", "oops").ok());
EXPECT_FALSE(row.SetStringCopy("binary_val", "oops").ok());
- EXPECT_OK(row.Unset(4));
+ EXPECT_OK(row.Unset(5));
s = row.SetVarchar("varchar_val", "shortval");
- EXPECT_TRUE(row.IsColumnSet(5));
+ EXPECT_TRUE(row.IsColumnSet(6));
EXPECT_EQ("varchar varchar_val=\"shortval\"", row.ToString());
s = row.SetVarchar("varchar_val", "shortval value ");
@@ -311,12 +326,15 @@ TEST_F(PartialRowTest, TestCopy) {
EXPECT_FALSE(copy.IsColumnSet(0));
EXPECT_FALSE(copy.IsColumnSet(1));
EXPECT_FALSE(copy.IsColumnSet(2));
+ EXPECT_FALSE(copy.IsColumnSet(3));
ASSERT_OK(row.SetInt32(0, 42));
ASSERT_OK(row.SetInt32(1, 99));
- ASSERT_OK(row.SetStringCopy(2, "copied-string"));
+ ASSERT_OK(row.SetSerial(2, 9999));
+ ASSERT_OK(row.SetStringCopy(3, "copied-string"));
int32_t int_val;
+ uint64_t uint64_val;
Slice string_val;
Slice binary_val;
@@ -326,31 +344,33 @@ TEST_F(PartialRowTest, TestCopy) {
EXPECT_EQ(42, int_val);
ASSERT_OK(copy.GetInt32(1, &int_val));
EXPECT_EQ(99, int_val);
- ASSERT_OK(copy.GetString(2, &string_val));
+ ASSERT_OK(copy.GetSerial(2, &uint64_val));
+ EXPECT_EQ(9999, uint64_val);
+ ASSERT_OK(copy.GetString(3, &string_val));
EXPECT_EQ("copied-string", string_val.ToString());
// Check a copy with a null value.
- ASSERT_OK(row.SetNull(2));
+ ASSERT_OK(row.SetNull(3));
copy = row;
- EXPECT_TRUE(copy.IsNull(2));
+ EXPECT_TRUE(copy.IsNull(3));
// Check a copy with a borrowed value.
string borrowed_string = "borrowed-string";
string borrowed_binary = "borrowed-binary";
- ASSERT_OK(row.SetStringNoCopy(2, borrowed_string));
- ASSERT_OK(row.SetBinaryNoCopy(3, borrowed_binary));
+ ASSERT_OK(row.SetStringNoCopy(3, borrowed_string));
+ ASSERT_OK(row.SetBinaryNoCopy(4, borrowed_binary));
copy = row;
- ASSERT_OK(copy.GetString(2, &string_val));
+ ASSERT_OK(copy.GetString(3, &string_val));
EXPECT_EQ("borrowed-string", string_val.ToString());
- ASSERT_OK(copy.GetBinary(3, &binary_val));
+ ASSERT_OK(copy.GetBinary(4, &binary_val));
EXPECT_EQ("borrowed-binary", binary_val.ToString());
borrowed_string.replace(0, 8, "mutated-");
borrowed_binary.replace(0, 8, "mutated-");
- ASSERT_OK(copy.GetString(2, &string_val));
+ ASSERT_OK(copy.GetString(3, &string_val));
EXPECT_EQ("mutated--string", string_val.ToString());
- ASSERT_OK(copy.GetBinary(3, &string_val));
+ ASSERT_OK(copy.GetBinary(4, &string_val));
EXPECT_EQ("mutated--binary", string_val.ToString());
}
@@ -359,7 +379,7 @@ TEST_F(PartialRowTest, TestSetBinaryCopy) {
BinaryDataSetterTest(
static_cast<BinaryGetter>(&KuduPartialRow::GetBinary),
static_cast<BinarySetter>(&KuduPartialRow::SetBinaryCopy),
- 3, COPY);
+ 4, COPY);
}
// Check that PartialRow::SetStringCopy() copies the input data.
@@ -367,7 +387,7 @@ TEST_F(PartialRowTest, TestSetStringCopy) {
BinaryDataSetterTest(
static_cast<BinaryGetter>(&KuduPartialRow::GetString),
static_cast<BinarySetter>(&KuduPartialRow::SetStringCopy),
- 2, COPY);
+ 3, COPY);
}
// Check that PartialRow::SetBinaryNoCopy() does not copy the input data.
@@ -375,7 +395,7 @@ TEST_F(PartialRowTest, TestSetBinaryNoCopy) {
BinaryDataSetterTest(
static_cast<BinaryGetter>(&KuduPartialRow::GetBinary),
static_cast<BinarySetter>(&KuduPartialRow::SetBinaryNoCopy),
- 3, NO_COPY);
+ 4, NO_COPY);
}
// Check that PartialRow::SetStringNoCopy() does not copy the input data.
@@ -383,7 +403,7 @@ TEST_F(PartialRowTest, TestSetStringNoCopy) {
BinaryDataSetterTest(
static_cast<BinaryGetter>(&KuduPartialRow::GetString),
static_cast<BinarySetter>(&KuduPartialRow::SetStringNoCopy),
- 2, NO_COPY);
+ 3, NO_COPY);
}
// Check that PartialRow::SetBinary() copies the input data.
@@ -391,7 +411,7 @@ TEST_F(PartialRowTest, TestSetBinary) {
BinaryDataSetterTest(
static_cast<BinaryGetter>(&KuduPartialRow::GetBinary),
static_cast<BinarySetter>(&KuduPartialRow::SetBinary),
- 3, COPY);
+ 4, COPY);
}
// Check that PartialRow::SetString() copies the input data.
@@ -399,7 +419,7 @@ TEST_F(PartialRowTest, TestSetString) {
BinaryDataSetterTest(
static_cast<BinaryGetter>(&KuduPartialRow::GetString),
static_cast<BinarySetter>(&KuduPartialRow::SetString),
- 2, COPY);
+ 3, COPY);
}
} // namespace kudu
diff --git a/src/kudu/common/partial_row.cc b/src/kudu/common/partial_row.cc
index 6951e6a6d..19e43793b 100644
--- a/src/kudu/common/partial_row.cc
+++ b/src/kudu/common/partial_row.cc
@@ -283,6 +283,9 @@ Status KuduPartialRow::SetInt32(const Slice& col_name,
int32_t val) {
Status KuduPartialRow::SetInt64(const Slice& col_name, int64_t val) {
return Set<TypeTraits<INT64> >(col_name, val);
}
+Status KuduPartialRow::SetSerial(const Slice& col_name, uint64_t val) {
+ return Set<TypeTraits<UINT64> >(col_name, val);
+}
Status KuduPartialRow::SetUnixTimeMicros(const Slice& col_name, int64_t
micros_since_utc_epoch) {
return Set<TypeTraits<UNIXTIME_MICROS> >(col_name, micros_since_utc_epoch);
}
@@ -315,6 +318,9 @@ Status KuduPartialRow::SetInt32(int col_idx, int32_t val) {
Status KuduPartialRow::SetInt64(int col_idx, int64_t val) {
return Set<TypeTraits<INT64> >(col_idx, val);
}
+Status KuduPartialRow::SetSerial(int col_idx, uint64_t val) {
+ return Set<TypeTraits<UINT64> >(col_idx, val);
+}
Status KuduPartialRow::SetUnixTimeMicros(int col_idx, int64_t
micros_since_utc_epoch) {
return Set<TypeTraits<UNIXTIME_MICROS> >(col_idx, micros_since_utc_epoch);
}
@@ -707,6 +713,9 @@ Status KuduPartialRow::GetInt32(const Slice& col_name,
int32_t* val) const {
Status KuduPartialRow::GetInt64(const Slice& col_name, int64_t* val) const {
return Get<TypeTraits<INT64> >(col_name, val);
}
+Status KuduPartialRow::GetSerial(const Slice& col_name, uint64_t* val) const {
+ return Get<TypeTraits<UINT64> >(col_name, val);
+}
Status KuduPartialRow::GetUnixTimeMicros(const Slice& col_name,
int64_t* micros_since_utc_epoch)
const {
return Get<TypeTraits<UNIXTIME_MICROS> >(col_name, micros_since_utc_epoch);
@@ -757,6 +766,9 @@ Status KuduPartialRow::GetInt32(int col_idx, int32_t* val)
const {
Status KuduPartialRow::GetInt64(int col_idx, int64_t* val) const {
return Get<TypeTraits<INT64> >(col_idx, val);
}
+Status KuduPartialRow::GetSerial(int col_idx, uint64_t* val) const {
+ return Get<TypeTraits<UINT64> >(col_idx, val);
+}
Status KuduPartialRow::GetUnixTimeMicros(int col_idx, int64_t*
micros_since_utc_epoch) const {
return Get<TypeTraits<UNIXTIME_MICROS> >(col_idx, micros_since_utc_epoch);
}
diff --git a/src/kudu/common/partial_row.h b/src/kudu/common/partial_row.h
index 47033b13b..0016b1965 100644
--- a/src/kudu/common/partial_row.h
+++ b/src/kudu/common/partial_row.h
@@ -106,6 +106,7 @@ class KUDU_EXPORT KuduPartialRow {
Status SetInt16(const Slice& col_name, int16_t val) WARN_UNUSED_RESULT;
Status SetInt32(const Slice& col_name, int32_t val) WARN_UNUSED_RESULT;
Status SetInt64(const Slice& col_name, int64_t val) WARN_UNUSED_RESULT;
+ Status SetSerial(const Slice& col_name, uint64_t val) WARN_UNUSED_RESULT;
/// Set value for a column by name.
///
/// @param [in] col_name
@@ -149,6 +150,7 @@ class KUDU_EXPORT KuduPartialRow {
Status SetInt16(int col_idx, int16_t val) WARN_UNUSED_RESULT;
Status SetInt32(int col_idx, int32_t val) WARN_UNUSED_RESULT;
Status SetInt64(int col_idx, int64_t val) WARN_UNUSED_RESULT;
+ Status SetSerial(int col_idx, uint64_t val) WARN_UNUSED_RESULT;
/// @param [in] col_idx
/// The index of the target column.
@@ -460,6 +462,7 @@ class KUDU_EXPORT KuduPartialRow {
Status GetInt16(const Slice& col_name, int16_t* val) const
WARN_UNUSED_RESULT;
Status GetInt32(const Slice& col_name, int32_t* val) const
WARN_UNUSED_RESULT;
Status GetInt64(const Slice& col_name, int64_t* val) const
WARN_UNUSED_RESULT;
+ Status GetSerial(const Slice& col_name, uint64_t* val) const
WARN_UNUSED_RESULT;
/// @param [in] col_name
/// The name of the column.
@@ -516,6 +519,7 @@ class KUDU_EXPORT KuduPartialRow {
Status GetInt16(int col_idx, int16_t* val) const WARN_UNUSED_RESULT;
Status GetInt32(int col_idx, int32_t* val) const WARN_UNUSED_RESULT;
Status GetInt64(int col_idx, int64_t* val) const WARN_UNUSED_RESULT;
+ Status GetSerial(int col_idx, uint64_t* val) const WARN_UNUSED_RESULT;
/// @param [in] col_idx
/// The index of the target column.
diff --git a/src/kudu/tools/tool_action_table.cc
b/src/kudu/tools/tool_action_table.cc
index fa554d4c8..a8987029f 100644
--- a/src/kudu/tools/tool_action_table.cc
+++ b/src/kudu/tools/tool_action_table.cc
@@ -657,6 +657,7 @@ Status LocateRow(const RunnerContext& context) {
case KuduColumnSchema::INT32:
case KuduColumnSchema::INT64:
case KuduColumnSchema::DATE:
+ case KuduColumnSchema::SERIAL:
case KuduColumnSchema::UNIXTIME_MICROS: {
int64_t value;
RETURN_NOT_OK_PREPEND(
@@ -996,6 +997,14 @@ Status ConvertToKuduPartialRow(
RETURN_NOT_OK(range_bound_partial_row->SetInt64(col_name, value));
break;
}
+ case KuduColumnSchema::SERIAL: {
+ uint64_t value;
+ RETURN_NOT_OK_PREPEND(
+ reader.ExtractUint64(values[i], /*field=*/nullptr, &value),
+ error_msg);
+ RETURN_NOT_OK(range_bound_partial_row->SetSerial(col_name, value));
+ break;
+ }
case KuduColumnSchema::DATE: {
int32_t value;
RETURN_NOT_OK_PREPEND(