This is an automated email from the ASF dual-hosted git repository.
granthenke 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 69d4e81 [tools] Fix create table tool for VARCHAR and DATE columns
69d4e81 is described below
commit 69d4e8116a928cef556b5447e30f4b0ed4ea0978
Author: Grant Henke <[email protected]>
AuthorDate: Tue Jan 7 14:44:44 2020 -0600
[tools] Fix create table tool for VARCHAR and DATE columns
When VARCHAR and DATE were added they weren’t added to
KuduColumnSchema::StringToDataType. This means that they
cant be used in the table tool to create a table.
This patch adds VARCHAR and DATE to StringToDataType and
test coverage to the create table tool tests.
Change-Id: I249348e16dc06616b59ac92212a0a075aac2b2fa
Reviewed-on: http://gerrit.cloudera.org:8080/14983
Tested-by: Kudu Jenkins
Reviewed-by: Adar Dembo <[email protected]>
Reviewed-by: Volodymyr Verovkin <[email protected]>
---
src/kudu/client/schema.cc | 4 ++++
src/kudu/tools/create-table-tool-test.cc | 25 ++++++++++++++++++++-----
src/kudu/tools/tool.proto | 6 ++++--
src/kudu/tools/tool_action_table.cc | 8 ++++++--
4 files changed, 34 insertions(+), 9 deletions(-)
diff --git a/src/kudu/client/schema.cc b/src/kudu/client/schema.cc
index 7ca7d74..ebb1eb3 100644
--- a/src/kudu/client/schema.cc
+++ b/src/kudu/client/schema.cc
@@ -718,6 +718,10 @@ string KuduColumnSchema::DataTypeToString(DataType type) {
*type = UNIXTIME_MICROS;
} else if (type_uc == "DECIMAL") {
*type = DECIMAL;
+ } else if (type_uc == "VARCHAR") {
+ *type = VARCHAR;
+ } else if (type_uc == "DATE") {
+ *type = DATE;
} else {
s = Status::InvalidArgument(Substitute(
"data type $0 is not supported", type_str));
diff --git a/src/kudu/tools/create-table-tool-test.cc
b/src/kudu/tools/create-table-tool-test.cc
index 0ec1614..c1c8d5c 100644
--- a/src/kudu/tools/create-table-tool-test.cc
+++ b/src/kudu/tools/create-table-tool-test.cc
@@ -417,10 +417,10 @@ TEST_F(CreateTableToolTest, TestCreateTable) {
NO_FATALS(check_good_input(hash_range_table, master_addr, "hash_range_table",
schema, partition, extra_configs, client.get()));
- // Create a table with decimal column type.
- string decimal_table = R"(
+ // Create a table with decimal, varchar, and date column types.
+ string type_table = R"(
{
- "table_name": "decimal_table",
+ "table_name": "type_table",
"schema": {
"columns": [
{
@@ -440,6 +440,20 @@ TEST_F(CreateTableToolTest, TestCreateTable) {
"comment": "range key"
},
{
+ "column_name": "text",
+ "column_type": "VARCHAR",
+ "type_attributes": {
+ "length": 10
+ },
+ "is_nullable": false,
+ "default_value": "hello world"
+ },
+ {
+ "column_name": "create_date",
+ "column_type": "DATE",
+ "is_nullable": false
+ },
+ {
"column_name": "name",
"column_type": "STRING",
"is_nullable": false,
@@ -461,10 +475,11 @@ TEST_F(CreateTableToolTest, TestCreateTable) {
}
)";
schema = "(\n id INT64 NOT NULL,\n score DECIMAL(10, 10) NOT NULL,\n"
- " name STRING NOT NULL,\n PRIMARY KEY (id)\n)";
+ " text VARCHAR(10) NOT NULL,\n create_date DATE NOT NULL,\n"
+ " name STRING NOT NULL,\n PRIMARY KEY (id)\n)";
partition = "";
extra_configs["kudu.table.history_max_age_sec"] = "3600";
- NO_FATALS(check_good_input(decimal_table, master_addr, "decimal_table",
+ NO_FATALS(check_good_input(type_table, master_addr, "type_table",
schema, partition, extra_configs, client.get()));
// Create a table using string value instead of int for enum type,
diff --git a/src/kudu/tools/tool.proto b/src/kudu/tools/tool.proto
index 1754417..c5a0bf0 100644
--- a/src/kudu/tools/tool.proto
+++ b/src/kudu/tools/tool.proto
@@ -354,9 +354,11 @@ message ColumnPB {
ZLIB = 4;
}
message ColumnAttributesPB {
- // For decimal columns
+ // For decimal columns.
optional int32 precision = 1;
optional int32 scale = 2;
+ // For varchar columns.
+ optional int32 length = 3;
}
optional string column_name = 1;
optional string column_type = 2;
@@ -366,7 +368,7 @@ message ColumnPB {
optional string comment = 5;
optional EncodingType encoding = 6;
optional CompressionType compression = 7;
- // Column's attribute, used for DECIMAL type column.
+ // Column's attribute, used for DECIMAL and VARCHAR type columns.
optional ColumnAttributesPB type_attributes = 8;
// The preferred block size for cfile blocks.
optional int32 cfile_block_size = 9;
diff --git a/src/kudu/tools/tool_action_table.cc
b/src/kudu/tools/tool_action_table.cc
index b20b7ff..adae19c 100644
--- a/src/kudu/tools/tool_action_table.cc
+++ b/src/kudu/tools/tool_action_table.cc
@@ -1006,8 +1006,12 @@ Status ParseTableSchema(const SchemaPB& schema,
column.column_type(), &type));
spec->Type(type);
if (column.has_type_attributes()) {
- spec->Precision(column.type_attributes().precision());
- spec->Scale(column.type_attributes().scale());
+ if (type == KuduColumnSchema::DataType::DECIMAL) {
+ spec->Precision(column.type_attributes().precision());
+ spec->Scale(column.type_attributes().scale());
+ } else if (type == KuduColumnSchema::DataType::VARCHAR) {
+ spec->Length(column.type_attributes().length());
+ }
}
if (!column.is_nullable()) {
spec->NotNull();