You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kudu.apache.org by al...@apache.org on 2022/12/06 19:59:17 UTC

[kudu] branch master updated: Make HasColumn work without specifying col_schema

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 85357020c Make HasColumn work without specifying col_schema
85357020c is described below

commit 85357020c24fb74591da691306b49960d5c51c47
Author: Marton Greber <gr...@gmail.com>
AuthorDate: Fri Dec 2 18:06:38 2022 +0100

    Make HasColumn work without specifying col_schema
    
    KuduSchema::HasColumn() determines whether a given column name is
    present or not in a given schema. If the column is found, a new
    KuduColumnSchema object is created, and it is assigned to the argument
    col_schema pointer.
    
    There can be cases, where we are only interested in the boolean return
    value, and we don't want to obtain the actual column schema.
    This patch enables to pass a nullptr as the col_schema argument, if
    we don't want to obtain the column schema.
    
    This came up, while working on another patch [1], where there are two
    cases where I need to create column schema objects, although only the
    boolean information is needed.
    
    [1] https://gerrit.cloudera.org/#/c/19272/2/
        src/kudu/client/scan_token-test.cc
    
    Change-Id: I736f55240157a676841db8428c84ee2d78b1cdcd
    Reviewed-on: http://gerrit.cloudera.org:8080/19315
    Tested-by: Kudu Jenkins
    Reviewed-by: Alexey Serbin <al...@apache.org>
---
 src/kudu/client/client-test.cc    | 5 +----
 src/kudu/client/schema.cc         | 4 +++-
 src/kudu/client/schema.h          | 2 +-
 src/kudu/tools/kudu-admin-test.cc | 9 +++------
 4 files changed, 8 insertions(+), 12 deletions(-)

diff --git a/src/kudu/client/client-test.cc b/src/kudu/client/client-test.cc
index 492a6e90e..424f67ac7 100644
--- a/src/kudu/client/client-test.cc
+++ b/src/kudu/client/client-test.cc
@@ -3259,10 +3259,7 @@ static Status ApplyUpsertToSession(KuduSession* session,
   RETURN_NOT_OK(upsert->mutable_row()->SetInt32("key", row_key));
   RETURN_NOT_OK(upsert->mutable_row()->SetInt32("int_val", int_val));
   RETURN_NOT_OK(upsert->mutable_row()->SetStringCopy("string_val", string_val));
-  // Here we use the first column to initialize an object of KuduColumnSchema
-  // for there is no default constructor for it.
-  KuduColumnSchema col_schema = table->schema().Column(0);
-  if (table->schema().HasColumn("imm_val", &col_schema)) {
+  if (table->schema().HasColumn("imm_val", nullptr)) {
     if (imm_val) {
       RETURN_NOT_OK(upsert->mutable_row()->SetInt32("imm_val", *imm_val));
     } else {
diff --git a/src/kudu/client/schema.cc b/src/kudu/client/schema.cc
index d1b09c780..ae177d9cd 100644
--- a/src/kudu/client/schema.cc
+++ b/src/kudu/client/schema.cc
@@ -939,7 +939,9 @@ bool KuduSchema::HasColumn(const std::string& col_name, KuduColumnSchema* col_sc
   if (idx == Schema::kColumnNotFound) {
     return false;
   }
-  *col_schema = Column(idx);
+  if (col_schema != nullptr) {
+    *col_schema = Column(idx);
+  }
   return true;
 }
 
diff --git a/src/kudu/client/schema.h b/src/kudu/client/schema.h
index e4637f5d9..d273a5787 100644
--- a/src/kudu/client/schema.h
+++ b/src/kudu/client/schema.h
@@ -708,7 +708,7 @@ class KUDU_EXPORT KuduSchema {
   /// @param [in] col_name
   ///   Column name.
   /// @param [out] col_schema
-  ///   Schema for the specified column.
+  ///   If not null pointer, then the schema for the specified column.
   /// @return @c true iff the specified column exists.
   bool HasColumn(const std::string& col_name, KuduColumnSchema* col_schema) const;
 
diff --git a/src/kudu/tools/kudu-admin-test.cc b/src/kudu/tools/kudu-admin-test.cc
index 0a11686d6..f32bba194 100644
--- a/src/kudu/tools/kudu-admin-test.cc
+++ b/src/kudu/tools/kudu-admin-test.cc
@@ -3950,12 +3950,9 @@ TEST_F(AdminCliTest, TestAddColumnsAndRebuildMaster) {
     KuduSchema schema;
     ASSERT_OK(client_->GetTableSchema(kTableId, &schema));
     ASSERT_EQ(6, schema.num_columns());
-    // Here we use the first column to initialize an object of KuduColumnSchema
-    // for there is no default constructor for it.
-    KuduColumnSchema col_schema = schema.Column(0);
-    ASSERT_TRUE(schema.HasColumn("old_column_0", &col_schema));
-    ASSERT_TRUE(schema.HasColumn("old_column_1", &col_schema));
-    ASSERT_TRUE(schema.HasColumn("new_column_0", &col_schema));
+    ASSERT_TRUE(schema.HasColumn("old_column_0", nullptr));
+    ASSERT_TRUE(schema.HasColumn("old_column_1", nullptr));
+    ASSERT_TRUE(schema.HasColumn("new_column_0", nullptr));
 
     client::sp::shared_ptr<KuduTable> table;
     ASSERT_OK(client_->OpenTable(kTableId, &table));