From bee9f2ea55810c0d17ec9579a0286de5692b8402 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Fri, 5 Mar 2010 17:38:01 +0000 Subject: [PATCH] dbms: development. --- dbms/include/DB/ColumnTypes/ColumnTypes.h | 20 ----------- .../DB/ColumnTypes/ColumnTypesNumberFixed.h | 35 ------------------- dbms/include/DB/Core/ColumnWithNameAndType.h | 4 +-- dbms/include/DB/Core/NameAndType.h | 4 +-- .../DataStreams/TabSeparatedRowOutputStream.h | 6 ++-- dbms/include/DB/DataTypes/DataTypes.h | 20 +++++++++++ .../DB/DataTypes/DataTypesNumberFixed.h | 35 +++++++++++++++++++ .../IColumnType.h => DataTypes/IDataType.h} | 8 ++--- .../IDataTypeNumber.h} | 10 +++--- .../IDataTypeNumberFixed.h} | 10 +++--- .../tests/column_types_number_fixed.cpp | 31 ---------------- .../TabSeparatedRowOutputStream.cpp | 6 ++-- dbms/src/Storages/StorageSystemNumbers.cpp | 4 +-- dbms/src/Storages/tests/system_numbers.cpp | 6 ++-- 14 files changed, 84 insertions(+), 115 deletions(-) delete mode 100644 dbms/include/DB/ColumnTypes/ColumnTypes.h delete mode 100644 dbms/include/DB/ColumnTypes/ColumnTypesNumberFixed.h create mode 100644 dbms/include/DB/DataTypes/DataTypes.h create mode 100644 dbms/include/DB/DataTypes/DataTypesNumberFixed.h rename dbms/include/DB/{ColumnTypes/IColumnType.h => DataTypes/IDataType.h} (95%) rename dbms/include/DB/{ColumnTypes/IColumnTypeNumber.h => DataTypes/IDataTypeNumber.h} (74%) rename dbms/include/DB/{ColumnTypes/IColumnTypeNumberFixed.h => DataTypes/IDataTypeNumberFixed.h} (81%) delete mode 100644 dbms/src/ColumnTypes/tests/column_types_number_fixed.cpp diff --git a/dbms/include/DB/ColumnTypes/ColumnTypes.h b/dbms/include/DB/ColumnTypes/ColumnTypes.h deleted file mode 100644 index 646dabd0c36..00000000000 --- a/dbms/include/DB/ColumnTypes/ColumnTypes.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef DBMS_COLUMN_TYPES_COLUMNTYPES_H -#define DBMS_COLUMN_TYPES_COLUMNTYPES_H - -#include - -#include - -#include - - -namespace DB -{ - -using Poco::SharedPtr; - -typedef std::vector > ColumnTypes; - -} - -#endif diff --git a/dbms/include/DB/ColumnTypes/ColumnTypesNumberFixed.h b/dbms/include/DB/ColumnTypes/ColumnTypesNumberFixed.h deleted file mode 100644 index da45d307a53..00000000000 --- a/dbms/include/DB/ColumnTypes/ColumnTypesNumberFixed.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef DBMS_COLUMN_TYPES_NUMBER_FIXED_H -#define DBMS_COLUMN_TYPES_NUMBER_FIXED_H - -#include -#include - - -namespace DB -{ - -/** Типы столбцов для чисел фиксированной ширины. */ - -#define DEFINE_COLUMN_TYPE_NUMBER_FIXED(TYPE) \ - class ColumnType ## TYPE : public IColumnTypeNumberFixed \ - { \ - public: \ - std::string getName() const { return #TYPE; } \ - }; - -DEFINE_COLUMN_TYPE_NUMBER_FIXED(UInt8); -DEFINE_COLUMN_TYPE_NUMBER_FIXED(UInt16); -DEFINE_COLUMN_TYPE_NUMBER_FIXED(UInt32); -DEFINE_COLUMN_TYPE_NUMBER_FIXED(UInt64); - -DEFINE_COLUMN_TYPE_NUMBER_FIXED(Int8); -DEFINE_COLUMN_TYPE_NUMBER_FIXED(Int16); -DEFINE_COLUMN_TYPE_NUMBER_FIXED(Int32); -DEFINE_COLUMN_TYPE_NUMBER_FIXED(Int64); - -DEFINE_COLUMN_TYPE_NUMBER_FIXED(Float32); -DEFINE_COLUMN_TYPE_NUMBER_FIXED(Float64); - -} - -#endif diff --git a/dbms/include/DB/Core/ColumnWithNameAndType.h b/dbms/include/DB/Core/ColumnWithNameAndType.h index cef0820259a..0c0f37e8642 100644 --- a/dbms/include/DB/Core/ColumnWithNameAndType.h +++ b/dbms/include/DB/Core/ColumnWithNameAndType.h @@ -4,7 +4,7 @@ #include #include -#include +#include namespace DB @@ -18,7 +18,7 @@ using Poco::SharedPtr; struct ColumnWithNameAndType { SharedPtr column; - SharedPtr type; + SharedPtr type; String name; }; diff --git a/dbms/include/DB/Core/NameAndType.h b/dbms/include/DB/Core/NameAndType.h index 886dc9156c7..98148dfcc05 100644 --- a/dbms/include/DB/Core/NameAndType.h +++ b/dbms/include/DB/Core/NameAndType.h @@ -4,7 +4,7 @@ #include #include -#include +#include namespace DB @@ -17,7 +17,7 @@ using Poco::SharedPtr; struct NameAndType { - SharedPtr type; + SharedPtr type; String name; }; diff --git a/dbms/include/DB/DataStreams/TabSeparatedRowOutputStream.h b/dbms/include/DB/DataStreams/TabSeparatedRowOutputStream.h index 5afe53d23b4..01c696eb14b 100644 --- a/dbms/include/DB/DataStreams/TabSeparatedRowOutputStream.h +++ b/dbms/include/DB/DataStreams/TabSeparatedRowOutputStream.h @@ -5,7 +5,7 @@ #include -#include +#include #include @@ -20,7 +20,7 @@ using Poco::SharedPtr; class TabSeparatedRowOutputStream : public IRowOutputStream { public: - TabSeparatedRowOutputStream(std::ostream & ostr_, SharedPtr column_types_); + TabSeparatedRowOutputStream(std::ostream & ostr_, SharedPtr data_types_); void writeField(const Field & field); void writeFieldDelimiter(); @@ -28,7 +28,7 @@ public: private: std::ostream & ostr; - SharedPtr column_types; + SharedPtr data_types; size_t field_number; }; diff --git a/dbms/include/DB/DataTypes/DataTypes.h b/dbms/include/DB/DataTypes/DataTypes.h new file mode 100644 index 00000000000..51e71d811b4 --- /dev/null +++ b/dbms/include/DB/DataTypes/DataTypes.h @@ -0,0 +1,20 @@ +#ifndef DBMS_DATA_TYPES_DATATYPES_H +#define DBMS_DATA_TYPES_DATATYPES_H + +#include + +#include + +#include + + +namespace DB +{ + +using Poco::SharedPtr; + +typedef std::vector > DataTypes; + +} + +#endif diff --git a/dbms/include/DB/DataTypes/DataTypesNumberFixed.h b/dbms/include/DB/DataTypes/DataTypesNumberFixed.h new file mode 100644 index 00000000000..d77fd6393a0 --- /dev/null +++ b/dbms/include/DB/DataTypes/DataTypesNumberFixed.h @@ -0,0 +1,35 @@ +#ifndef DBMS_DATA_TYPES_NUMBER_FIXED_H +#define DBMS_DATA_TYPES_NUMBER_FIXED_H + +#include +#include + + +namespace DB +{ + +/** Типы столбцов для чисел фиксированной ширины. */ + +#define DEFINE_DATA_TYPE_NUMBER_FIXED(TYPE) \ + class DataType ## TYPE : public IDataTypeNumberFixed \ + { \ + public: \ + std::string getName() const { return #TYPE; } \ + }; + +DEFINE_DATA_TYPE_NUMBER_FIXED(UInt8); +DEFINE_DATA_TYPE_NUMBER_FIXED(UInt16); +DEFINE_DATA_TYPE_NUMBER_FIXED(UInt32); +DEFINE_DATA_TYPE_NUMBER_FIXED(UInt64); + +DEFINE_DATA_TYPE_NUMBER_FIXED(Int8); +DEFINE_DATA_TYPE_NUMBER_FIXED(Int16); +DEFINE_DATA_TYPE_NUMBER_FIXED(Int32); +DEFINE_DATA_TYPE_NUMBER_FIXED(Int64); + +DEFINE_DATA_TYPE_NUMBER_FIXED(Float32); +DEFINE_DATA_TYPE_NUMBER_FIXED(Float64); + +} + +#endif diff --git a/dbms/include/DB/ColumnTypes/IColumnType.h b/dbms/include/DB/DataTypes/IDataType.h similarity index 95% rename from dbms/include/DB/ColumnTypes/IColumnType.h rename to dbms/include/DB/DataTypes/IDataType.h index 70bfe9515d4..c2d7b467999 100644 --- a/dbms/include/DB/ColumnTypes/IColumnType.h +++ b/dbms/include/DB/DataTypes/IDataType.h @@ -1,5 +1,5 @@ -#ifndef DBMS_COLUMN_TYPES_ICOLUMNTYPE_H -#define DBMS_COLUMN_TYPES_ICOLUMNTYPE_H +#ifndef DBMS_DATA_TYPES_IDATATYPE_H +#define DBMS_DATA_TYPES_IDATATYPE_H #include @@ -14,7 +14,7 @@ namespace DB /** Метаданные типа для хранения (столбца). * Содержит методы для сериализации/десериализации. */ -class IColumnType +class IDataType { public: /// Основное имя типа (например, BIGINT UNSIGNED). @@ -53,7 +53,7 @@ public: virtual void deserializeTextQuoted(Field & field, std::istream & istr, bool compatible = false) const = 0; - virtual ~IColumnType() {} + virtual ~IDataType() {} }; } diff --git a/dbms/include/DB/ColumnTypes/IColumnTypeNumber.h b/dbms/include/DB/DataTypes/IDataTypeNumber.h similarity index 74% rename from dbms/include/DB/ColumnTypes/IColumnTypeNumber.h rename to dbms/include/DB/DataTypes/IDataTypeNumber.h index 199eb70a052..d2a7886f23b 100644 --- a/dbms/include/DB/ColumnTypes/IColumnTypeNumber.h +++ b/dbms/include/DB/DataTypes/IDataTypeNumber.h @@ -1,18 +1,18 @@ -#ifndef DBMS_COLUMN_TYPES_ICOLUMNTYPE_NUMBER_H -#define DBMS_COLUMN_TYPES_ICOLUMNTYPE_NUMBER_H +#ifndef DBMS_DATA_TYPES_IDATATYPE_NUMBER_H +#define DBMS_DATA_TYPES_IDATATYPE_NUMBER_H -#include +#include namespace DB { -/** Реализует часть интерфейса IColumnType, общую для всяких чисел +/** Реализует часть интерфейса IDataType, общую для всяких чисел * - ввод и вывод в текстовом виде. */ template -class IColumnTypeNumber : public IColumnType +class IDataTypeNumber : public IDataType { public: void serializeText(const Field & field, std::ostream & ostr) const diff --git a/dbms/include/DB/ColumnTypes/IColumnTypeNumberFixed.h b/dbms/include/DB/DataTypes/IDataTypeNumberFixed.h similarity index 81% rename from dbms/include/DB/ColumnTypes/IColumnTypeNumberFixed.h rename to dbms/include/DB/DataTypes/IDataTypeNumberFixed.h index 2e876a059a8..041402084f7 100644 --- a/dbms/include/DB/ColumnTypes/IColumnTypeNumberFixed.h +++ b/dbms/include/DB/DataTypes/IDataTypeNumberFixed.h @@ -1,17 +1,17 @@ -#ifndef DBMS_COLUMN_TYPES_ICOLUMNTYPE_NUMBER_FIXED_H -#define DBMS_COLUMN_TYPES_ICOLUMNTYPE_NUMBER_FIXED_H +#ifndef DBMS_DATA_TYPES_IDATATYPE_NUMBER_FIXED_H +#define DBMS_DATA_TYPES_IDATATYPE_NUMBER_FIXED_H #include #include -#include +#include namespace DB { -/** Реализует часть интерфейса IColumnType, общую для всяких чисел фиксированной ширины +/** Реализует часть интерфейса IDataType, общую для всяких чисел фиксированной ширины * - ввод и вывод в текстовом и бинарном виде. * Остаётся лишь чисто виртуальный метод getName(). * @@ -19,7 +19,7 @@ namespace DB * (см. Field.h, Column.h) */ template -class IColumnTypeNumberFixed : public IColumnTypeNumber +class IDataTypeNumberFixed : public IDataTypeNumber { public: /** Формат платформозависимый (зависит от представления данных в памяти). diff --git a/dbms/src/ColumnTypes/tests/column_types_number_fixed.cpp b/dbms/src/ColumnTypes/tests/column_types_number_fixed.cpp deleted file mode 100644 index add717311f8..00000000000 --- a/dbms/src/ColumnTypes/tests/column_types_number_fixed.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include -#include - -#include - -#include - - -int main(int argc, char ** argv) -{ - DB::Column column = DB::UInt64Column(); - DB::UInt64Column & vec = boost::get(column); - DB::ColumnTypeUInt64 column_type; - - Poco::Stopwatch stopwatch; - size_t n = 10000000; - - vec.resize(n); - for (size_t i = 0; i < n; ++i) - vec[i] = i; - - std::ofstream ostr("/dev/null"); - - stopwatch.restart(); - column_type.serializeBinary(column, ostr); - stopwatch.stop(); - - std::cout << "Elapsed: " << static_cast(stopwatch.elapsed()) / 1000000 << std::endl; - - return 0; -} diff --git a/dbms/src/DataStreams/TabSeparatedRowOutputStream.cpp b/dbms/src/DataStreams/TabSeparatedRowOutputStream.cpp index 8b7c7adbad2..8846af96e81 100644 --- a/dbms/src/DataStreams/TabSeparatedRowOutputStream.cpp +++ b/dbms/src/DataStreams/TabSeparatedRowOutputStream.cpp @@ -7,15 +7,15 @@ namespace DB using Poco::SharedPtr; -TabSeparatedRowOutputStream::TabSeparatedRowOutputStream(std::ostream & ostr_, SharedPtr column_types_) - : ostr(ostr_), column_types(column_types_), field_number(0) +TabSeparatedRowOutputStream::TabSeparatedRowOutputStream(std::ostream & ostr_, SharedPtr data_types_) + : ostr(ostr_), data_types(data_types_), field_number(0) { } void TabSeparatedRowOutputStream::writeField(const Field & field) { - column_types->at(field_number)->serializeTextEscaped(field, ostr); + data_types->at(field_number)->serializeTextEscaped(field, ostr); ++field_number; } diff --git a/dbms/src/Storages/StorageSystemNumbers.cpp b/dbms/src/Storages/StorageSystemNumbers.cpp index ebda8160f2c..4b10571e390 100644 --- a/dbms/src/Storages/StorageSystemNumbers.cpp +++ b/dbms/src/Storages/StorageSystemNumbers.cpp @@ -2,7 +2,7 @@ #include #include -#include +#include #include @@ -23,7 +23,7 @@ Block NumbersBlockInputStream::read() res.insert(ColumnWithNameAndType()); ColumnWithNameAndType & column_with_name_and_type = res.getByPosition(0); column_with_name_and_type.name = "number"; - column_with_name_and_type.type = new ColumnTypeUInt64(); + column_with_name_and_type.type = new DataTypeUInt64(); column_with_name_and_type.column = new Column; *column_with_name_and_type.column = UInt64Column(block_size); UInt64Column & vec = boost::get(*column_with_name_and_type.column); diff --git a/dbms/src/Storages/tests/system_numbers.cpp b/dbms/src/Storages/tests/system_numbers.cpp index 5107f0bc434..eacadfdc1bc 100644 --- a/dbms/src/Storages/tests/system_numbers.cpp +++ b/dbms/src/Storages/tests/system_numbers.cpp @@ -5,7 +5,7 @@ #include #include #include -#include +#include using Poco::SharedPtr; @@ -19,8 +19,8 @@ int main(int argc, char ** argv) DB::ColumnNames column_names; column_names.push_back("number"); - Poco::SharedPtr column_types = new DB::ColumnTypes; - column_types->push_back(new DB::ColumnTypeUInt64); + Poco::SharedPtr column_types = new DB::DataTypes; + column_types->push_back(new DB::DataTypeUInt64); SharedPtr input = table.read(column_names, 0); DB::TabSeparatedRowOutputStream output(std::cout, column_types);