From 1a73e77463ff19554a2c913b1e9e54bc69e52ce7 Mon Sep 17 00:00:00 2001 From: Pavel Kartavyy Date: Fri, 29 Aug 2014 22:44:44 +0400 Subject: [PATCH] dbms: fixed exception in TinyLog when it is empty [#METR-12532] --- dbms/include/DB/Storages/StorageTinyLog.h | 2 ++ dbms/src/Storages/StorageTinyLog.cpp | 8 +++++++- .../queries/0_stateless/00068_empty_tiny_log.reference | 0 dbms/tests/queries/0_stateless/00068_empty_tiny_log.sql | 5 +++++ 4 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 dbms/tests/queries/0_stateless/00068_empty_tiny_log.reference create mode 100644 dbms/tests/queries/0_stateless/00068_empty_tiny_log.sql diff --git a/dbms/include/DB/Storages/StorageTinyLog.h b/dbms/include/DB/Storages/StorageTinyLog.h index d91cc88d9a3..770259f69d4 100644 --- a/dbms/include/DB/Storages/StorageTinyLog.h +++ b/dbms/include/DB/Storages/StorageTinyLog.h @@ -144,6 +144,8 @@ public: Files_t & getFiles(); + std::string full_path() { return path + escapeForFileName(name) + '/';} + private: String path; String name; diff --git a/dbms/src/Storages/StorageTinyLog.cpp b/dbms/src/Storages/StorageTinyLog.cpp index d48cbea70e3..92b5a0cc65a 100644 --- a/dbms/src/Storages/StorageTinyLog.cpp +++ b/dbms/src/Storages/StorageTinyLog.cpp @@ -16,7 +16,7 @@ #include #include - +#include #define DBMS_STORAGE_LOG_DATA_FILE_EXTENSION ".bin" @@ -61,6 +61,12 @@ Block TinyLogBlockInputStream::readImpl() return res; } + { + /// если в папке нет файлов, то это значит, что таблица пока пуста + if (Poco::DirectoryIterator(storage.full_path()) == Poco::DirectoryIterator()) + return res; + } + /// Если файлы не открыты, то открываем их. if (streams.empty()) for (Names::const_iterator it = column_names.begin(); it != column_names.end(); ++it) diff --git a/dbms/tests/queries/0_stateless/00068_empty_tiny_log.reference b/dbms/tests/queries/0_stateless/00068_empty_tiny_log.reference new file mode 100644 index 00000000000..e69de29bb2d diff --git a/dbms/tests/queries/0_stateless/00068_empty_tiny_log.sql b/dbms/tests/queries/0_stateless/00068_empty_tiny_log.sql new file mode 100644 index 00000000000..620f872a3d8 --- /dev/null +++ b/dbms/tests/queries/0_stateless/00068_empty_tiny_log.sql @@ -0,0 +1,5 @@ +CREATE TABLE IF NOT EXISTS test_empty_tiny_log(A UInt8) Engine = TinyLog; + +SELECT A FROM test_empty_tiny_log; + +DROP TABLE test_empty_tiny_log;