Skip to content

Commit

Permalink
refine ColumnId define && some include headers
Browse files Browse the repository at this point in the history
MutableSupport::storage_name -> MutableSupport::mmt_storage_name
  • Loading branch information
JaySon-Huang committed Sep 2, 2019
1 parent 366c5bd commit d53ea7d
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 22 deletions.
1 change: 1 addition & 0 deletions dbms/src/DataStreams/DeletingDeletedBlockInputStream.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <common/logger_useful.h>
#include <DataStreams/IProfilingBlockInputStream.h>

namespace DB
{
Expand Down
1 change: 1 addition & 0 deletions dbms/src/DataStreams/StringStreamBlockInputStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <DataStreams/IProfilingBlockInputStream.h>
#include <DataStreams/dedupUtils.h>
#include <DataTypes/DataTypeString.h>

namespace DB
{
Expand Down
1 change: 1 addition & 0 deletions dbms/src/DataStreams/dedupUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <Storages/MutableSupport.h>
#include <Columns/ColumnsNumber.h>
#include <Columns/ColumnFixedString.h>
#include <DataStreams/IBlockInputStream.h>

#include <Core/SortDescription.h>
#include <Core/SortCursor.h>
Expand Down
2 changes: 1 addition & 1 deletion dbms/src/Storages/MergeTree/registerStorageMergeTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,7 @@ void registerStorageMergeTree(StorageFactory & factory)
factory.registerStorage("MergeTree", create);
factory.registerStorage("CollapsingMergeTree", create);
factory.registerStorage("ReplacingMergeTree", create);
factory.registerStorage(MutableSupport::storage_name, create);
factory.registerStorage(MutableSupport::mmt_storage_name, create);
factory.registerStorage(MutableSupport::txn_storage_name, create);
factory.registerStorage("AggregatingMergeTree", create);
factory.registerStorage("SummingMergeTree", create);
Expand Down
16 changes: 11 additions & 5 deletions dbms/src/Storages/MutableSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@
namespace DB
{

const std::string MutableSupport::storage_name = "MutableMergeTree";
const std::string MutableSupport::txn_storage_name = "TxnMergeTree";
const std::string MutableSupport::tidb_pk_column_name = "_tidb_rowid";
const std::string MutableSupport::version_column_name = "_INTERNAL_VERSION";
const std::string MutableSupport::delmark_column_name = "_INTERNAL_DELMARK";
const String MutableSupport::mmt_storage_name = "MutableMergeTree";
const String MutableSupport::txn_storage_name = "TxnMergeTree";

const String MutableSupport::tidb_pk_column_name = "_tidb_rowid";
const String MutableSupport::version_column_name = "_INTERNAL_VERSION";
const String MutableSupport::delmark_column_name = "_INTERNAL_DELMARK";

const DataTypePtr MutableSupport::tidb_pk_column_type = DataTypeFactory::instance().get("Int64");
const DataTypePtr MutableSupport::version_column_type = DataTypeFactory::instance().get("UInt64");
const DataTypePtr MutableSupport::delmark_column_type = DataTypeFactory::instance().get("UInt8");

}
33 changes: 23 additions & 10 deletions dbms/src/Storages/MutableSupport.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
#pragma once

#include <ext/singleton.h>

#include <Core/Block.h>
#include <Core/Names.h>
#include <Common/typeid_cast.h>
#include <DataTypes/DataTypeNullable.h>
#include <ext/singleton.h>
#include <Storages/MergeTree/MergeTreeData.h>
#include <DataTypes/DataTypesNumber.h>
#include <IO/WriteHelpers.h>

namespace DB
{
Expand All @@ -20,14 +24,14 @@ class MutableSupport : public ext::singleton<MutableSupport>
all_hidden.insert(all_hidden.end(), mutable_hidden.begin(), mutable_hidden.end());
}

const OrderedNameSet & hiddenColumns(std::string table_type_name)
const OrderedNameSet & hiddenColumns(const String& table_type_name)
{
if (storage_name == table_type_name || txn_storage_name == table_type_name)
if (mmt_storage_name == table_type_name || txn_storage_name == table_type_name)
return mutable_hidden;
return empty;
}

void eraseHiddenColumns(Block & block, std::string table_type_name)
void eraseHiddenColumns(Block & block, const String& table_type_name)
{
const OrderedNameSet & names = hiddenColumns(table_type_name);
for (auto & it : names)
Expand All @@ -45,11 +49,20 @@ class MutableSupport : public ext::singleton<MutableSupport>
!(typeid_cast<const DataTypeInt64 *>(t.get()) || typeid_cast<const DataTypeUInt64 *>(t.get()));
}

static const std::string storage_name;
static const std::string version_column_name;
static const std::string delmark_column_name;
static const std::string tidb_pk_column_name;
static const std::string txn_storage_name;
static const String mmt_storage_name;
static const String txn_storage_name;

static const String tidb_pk_column_name;
static const String version_column_name;
static const String delmark_column_name;

static const DataTypePtr tidb_pk_column_type;
static const DataTypePtr version_column_type;
static const DataTypePtr delmark_column_type;

/// mark that ColumnId of those columns are defined in dbms/src/Storages/Transaction/Types.h



enum DeduperType
{
Expand Down
4 changes: 2 additions & 2 deletions dbms/src/Storages/StorageMergeTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ BlockInputStreams StorageMergeTree::read(
}
else if (select_query && select_query->raw_for_mutable)
{
throw Exception("Only " + MutableSupport::storage_name + " support SELRAW.", ErrorCodes::BAD_ARGUMENTS);
throw Exception("Only " + MutableSupport::mmt_storage_name + " support SELRAW.", ErrorCodes::BAD_ARGUMENTS);
}
return res;
}
Expand Down Expand Up @@ -261,7 +261,7 @@ BlockOutputStreamPtr StorageMergeTree::write(const ASTPtr & query, const Setting
}
else if ((insert_query && insert_query->is_import) || delete_query)
{
throw Exception("Only " + MutableSupport::storage_name + " support IMPORT or DELETE.", ErrorCodes::BAD_ARGUMENTS);
throw Exception("Only " + MutableSupport::mmt_storage_name + " support IMPORT or DELETE.", ErrorCodes::BAD_ARGUMENTS);
}

return res;
Expand Down
4 changes: 2 additions & 2 deletions dbms/src/Storages/Transaction/RegionBlockReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,10 @@ std::tuple<Block, bool> readRegionBlock(const TableInfo & table_info,
auto delmark_col = ColumnUInt8::create();
auto version_col = ColumnUInt64::create();

ColumnID handle_col_id = InvalidColumnID;
ColumnID handle_col_id = TiDBPkColumnID;

constexpr size_t MustHaveColCnt = 3; // pk, del, version
constexpr ColumnID EmptyColumnID = InvalidColumnID - 1;
constexpr ColumnID EmptyColumnID = TiDBPkColumnID - 1;

// column_map contains columns in column_names_to_read exclude del and version.
ColumnDataInfoMap column_map(column_names_to_read.size() - MustHaveColCnt + 1, EmptyColumnID);
Expand Down
6 changes: 5 additions & 1 deletion dbms/src/Storages/Transaction/TiDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,11 @@ ColumnID TableInfo::getColumnID(const String & name) const
}

if (name == DB::MutableSupport::tidb_pk_column_name)
return DB::InvalidColumnID;
return DB::TiDBPkColumnID;
else if (name == DB::MutableSupport::version_column_name)
return DB::VersionColumnID;
else if (name == DB::MutableSupport::delmark_column_name)
return DB::DelMarkColumnID;

throw DB::Exception(std::string(__PRETTY_FUNCTION__) + ": Unknown column name " + name, DB::ErrorCodes::LOGICAL_ERROR);
}
Expand Down
5 changes: 4 additions & 1 deletion dbms/src/Storages/Transaction/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ using ColumnID = Int64;

enum : ColumnID
{
InvalidColumnID = -1
// Prevent conflict with TiDB.
TiDBPkColumnID = -1,
VersionColumnID = -1024,
DelMarkColumnID = -1025,
};

using HandleID = Int64;
Expand Down

0 comments on commit d53ea7d

Please sign in to comment.