Skip to content

Commit

Permalink
Remove useless fields
Browse files Browse the repository at this point in the history
  • Loading branch information
JaySon-Huang committed Aug 21, 2024
1 parent 5500b35 commit 28fd8d9
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 97 deletions.
3 changes: 0 additions & 3 deletions dbms/src/Debug/MockTiDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,6 @@ TiDB::TableInfoPtr MockTiDB::parseColumns(
index_info.id = 1;
index_info.is_primary = true;
index_info.idx_name = "PRIMARY";
index_info.tbl_name = tbl_name;
index_info.is_unique = true;
index_info.index_type = 1;
index_info.idx_cols.resize(string_tokens.count());
Expand All @@ -296,8 +295,6 @@ TiDB::TableInfoPtr MockTiDB::parseColumns(
table_info.pk_is_handle = true;
}

table_info.comment = "Mocked.";

// set storage engine type
std::transform(engine_type.begin(), engine_type.end(), engine_type.begin(), [](unsigned char c) {
return std::tolower(c);
Expand Down
110 changes: 54 additions & 56 deletions dbms/src/TiDB/Schema/TiDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ namespace DB
namespace ErrorCodes
{
extern const int LOGICAL_ERROR;
}
extern const int INCORRECT_DATA;
} // namespace ErrorCodes
extern const UInt8 TYPE_CODE_LITERAL;
extern const UInt8 LITERAL_NIL;

Expand Down Expand Up @@ -378,27 +379,29 @@ try
json->set("origin_default", origin_default_value);
json->set("default", default_value);
json->set("default_bit", default_bit_value);
Poco::JSON::Object::Ptr tp_json = new Poco::JSON::Object();
tp_json->set("Tp", static_cast<Int32>(tp));
tp_json->set("Flag", flag);
tp_json->set("Flen", flen);
tp_json->set("Decimal", decimal);
tp_json->set("Charset", charset);
tp_json->set("Collate", collate);
if (!elems.empty())
{
Poco::JSON::Array::Ptr elem_arr = new Poco::JSON::Array();
for (const auto & elem : elems)
elem_arr->add(elem.first);
tp_json->set("Elems", elem_arr);
}
else
{
tp_json->set("Elems", Poco::Dynamic::Var());
// "type" field
Poco::JSON::Object::Ptr tp_json = new Poco::JSON::Object();
tp_json->set("Tp", static_cast<Int32>(tp));
tp_json->set("Flag", flag);
tp_json->set("Flen", flen);
tp_json->set("Decimal", decimal);
tp_json->set("Charset", charset);
tp_json->set("Collate", collate);
if (!elems.empty())
{
Poco::JSON::Array::Ptr elem_arr = new Poco::JSON::Array();
for (const auto & elem : elems)
elem_arr->add(elem.first);
tp_json->set("Elems", elem_arr);
}
else
{
tp_json->set("Elems", Poco::Dynamic::Var());
}
json->set("type", tp_json);
}
json->set("type", tp_json);
json->set("state", static_cast<Int32>(state));
json->set("comment", comment);

#ifndef NDEBUG
// Check stringify in Debug mode
Expand Down Expand Up @@ -427,28 +430,30 @@ try
default_value = json->get("default");
if (!json->isNull("default_bit"))
default_bit_value = json->get("default_bit");
auto type_json = json->getObject("type");
tp = static_cast<TP>(type_json->getValue<Int32>("Tp"));
flag = type_json->getValue<UInt32>("Flag");
flen = type_json->getValue<Int64>("Flen");
decimal = type_json->getValue<Int64>("Decimal");
if (!type_json->isNull("Elems"))
{
auto elems_arr = type_json->getArray("Elems");
size_t elems_size = elems_arr->size();
for (size_t i = 1; i <= elems_size; i++)
// type
auto type_json = json->getObject("type");
tp = static_cast<TP>(type_json->getValue<Int32>("Tp"));
flag = type_json->getValue<UInt32>("Flag");
flen = type_json->getValue<Int64>("Flen");
decimal = type_json->getValue<Int64>("Decimal");
if (!type_json->isNull("Elems"))
{
elems.push_back(std::make_pair(elems_arr->getElement<String>(i - 1), static_cast<Int16>(i)));
auto elems_arr = type_json->getArray("Elems");
size_t elems_size = elems_arr->size();
for (size_t i = 1; i <= elems_size; i++)
{
elems.push_back(std::make_pair(elems_arr->getElement<String>(i - 1), static_cast<Int16>(i)));
}
}
/// need to do this check for forward compatibility
if (!type_json->isNull("Charset"))
charset = type_json->get("Charset");
/// need to do this check for forward compatibility
if (!type_json->isNull("Collate"))
collate = type_json->get("Collate");
}
/// need to do this check for forward compatibility
if (!type_json->isNull("Charset"))
charset = type_json->get("Charset");
/// need to do this check for forward compatibility
if (!type_json->isNull("Collate"))
collate = type_json->get("Collate");
state = static_cast<SchemaState>(json->getValue<Int32>("state"));
comment = json->getValue<String>("comment");
}
catch (const Poco::Exception & e)
{
Expand All @@ -475,7 +480,6 @@ try
name_json->set("O", name);
name_json->set("L", name);
json->set("name", name_json);
json->set("comment", comment);

#ifndef NDEBUG
// Check stringify in Debug mode
Expand All @@ -497,8 +501,6 @@ try
{
id = json->getValue<TableID>("id");
name = json->getObject("name")->getValue<String>("L");
if (json->has("comment"))
comment = json->getValue<String>("comment");
}
catch (const Poco::Exception & e)
{
Expand Down Expand Up @@ -785,11 +787,6 @@ try
idx_name_json->set("L", idx_name);
json->set("idx_name", idx_name_json);

Poco::JSON::Object::Ptr tbl_name_json = new Poco::JSON::Object();
tbl_name_json->set("O", tbl_name);
tbl_name_json->set("L", tbl_name);
json->set("tbl_name", tbl_name_json);

Poco::JSON::Array::Ptr cols_array = new Poco::JSON::Array();
for (const auto & col : idx_cols)
{
Expand Down Expand Up @@ -823,7 +820,6 @@ try
{
id = json->getValue<Int64>("id");
idx_name = json->getObject("idx_name")->getValue<String>("L");
tbl_name = json->getObject("tbl_name")->getValue<String>("L");

auto cols_array = json->getArray("idx_cols");
idx_cols.clear();
Expand Down Expand Up @@ -904,7 +900,6 @@ try
json->set("state", static_cast<Int32>(state));
json->set("pk_is_handle", pk_is_handle);
json->set("is_common_handle", is_common_handle);
json->set("comment", comment);
json->set("update_timestamp", update_timestamp);
if (is_partition_table)
{
Expand Down Expand Up @@ -969,26 +964,28 @@ try
}
}

auto index_arr = obj->getArray("index_info");
index_infos.clear();
if (!index_arr.isNull())
bool has_primary_index = false;
if (auto index_arr = obj->getArray("index_info"); !index_arr.isNull())
{
for (size_t i = 0; i < index_arr->size(); i++)
{
auto index_info_json = index_arr->getObject(i);
IndexInfo index_info(index_info_json);
// We only keep the "primary index" in tiflash now
if (index_info.is_primary)
index_infos.emplace_back(index_info);
{
has_primary_index = true;
// always put the primary_index at the front of all index_info
index_infos.insert(index_infos.begin(), std::move(index_info));
}
}
}

state = static_cast<SchemaState>(obj->getValue<Int32>("state"));
pk_is_handle = obj->getValue<bool>("pk_is_handle");
if (obj->has("is_common_handle"))
is_common_handle = obj->getValue<bool>("is_common_handle");
if (!is_common_handle)
index_infos.clear();
comment = obj->getValue<String>("comment");
if (obj->has("update_timestamp"))
update_timestamp = obj->getValue<Timestamp>("update_timestamp");
auto partition_obj = obj->getObject("partition");
Expand Down Expand Up @@ -1019,12 +1016,13 @@ try
replica_info.deserialize(replica_obj);
}
}
if (is_common_handle && index_infos.size() != 1)
if (is_common_handle && !has_primary_index)
{
throw DB::Exception(
std::string(__PRETTY_FUNCTION__)
+ ": Parse TiDB schema JSON failed (TableInfo): clustered index without primary key info, json: "
+ JSONToString(obj));
DB::ErrorCodes::INCORRECT_DATA,
"{}: Parse TiDB schema JSON failed (TableInfo): clustered index without primary key info, json: ",
__PRETTY_FUNCTION__,
JSONToString(obj));
}
}
catch (const Poco::Exception & e)
Expand Down
4 changes: 0 additions & 4 deletions dbms/src/TiDB/Schema/TiDB.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ struct ColumnInfo
// Elems is the element list for enum and set type.
std::vector<std::pair<std::string, Int16>> elems;
SchemaState state = StateNone;
String comment;

#ifdef M
#error "Please undefine macro M first."
Expand Down Expand Up @@ -240,7 +239,6 @@ struct PartitionDefinition
TableID id = DB::InvalidTableID;
String name;
// LessThan []string `json:"less_than"`
String comment;
};

struct PartitionInfo
Expand Down Expand Up @@ -327,7 +325,6 @@ struct IndexInfo

Int64 id = -1;
String idx_name;
String tbl_name;
std::vector<IndexColumnInfo> idx_cols;
SchemaState state = StatePublic;
Int32 index_type = -1;
Expand Down Expand Up @@ -374,7 +371,6 @@ struct TableInfo
bool pk_is_handle = false;
/// when is_common_handle = true, it means this table is a clustered index table
bool is_common_handle = false;
String comment;
Timestamp update_timestamp = 0;
bool is_partition_table = false;
TableID belonging_table_id = DB::InvalidTableID;
Expand Down
Loading

0 comments on commit 28fd8d9

Please sign in to comment.