mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-27 10:02:01 +00:00
Support query in a file
This commit is contained in:
parent
086ef6ed82
commit
5fa4b5f15e
@ -13,7 +13,7 @@
|
|||||||
#include <Common/ThreadPool.h>
|
#include <Common/ThreadPool.h>
|
||||||
#include <Core/Types.h>
|
#include <Core/Types.h>
|
||||||
#include <DataStreams/RemoteBlockInputStream.h>
|
#include <DataStreams/RemoteBlockInputStream.h>
|
||||||
#include <IO/ReadBufferFromFileDescriptor.h>
|
#include <IO/ReadBufferFromFile.h>
|
||||||
#include <IO/ReadHelpers.h>
|
#include <IO/ReadHelpers.h>
|
||||||
#include <Interpreters/Settings.h>
|
#include <Interpreters/Settings.h>
|
||||||
|
|
||||||
@ -30,6 +30,8 @@
|
|||||||
* The tool walks through given or default folder in order to find files with
|
* The tool walks through given or default folder in order to find files with
|
||||||
* tests' descriptions and launches it.
|
* tests' descriptions and launches it.
|
||||||
*/
|
*/
|
||||||
|
namespace FS = boost::filesystem;
|
||||||
|
|
||||||
namespace DB
|
namespace DB
|
||||||
{
|
{
|
||||||
namespace ErrorCodes
|
namespace ErrorCodes
|
||||||
@ -727,16 +729,47 @@ private:
|
|||||||
|
|
||||||
Query query;
|
Query query;
|
||||||
|
|
||||||
if (!test_config->has("query"))
|
if (!test_config->has("query") && !test_config->has("query_file"))
|
||||||
{
|
{
|
||||||
throw Poco::Exception("Missing query field in test's config: " + test_name, 1);
|
throw Poco::Exception("Missing query fields in test's config: " + test_name, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
query = test_config->getString("query");
|
if (test_config->has("query") && test_config->has("query_file"))
|
||||||
|
|
||||||
if (query.empty())
|
|
||||||
{
|
{
|
||||||
throw Poco::Exception("The query is empty in test's config: " + test_name, 1);
|
throw Poco::Exception("Found both query and query_file fields. Choose only one", 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (test_config->has("query"))
|
||||||
|
queries.push_back(test_config->getString("query"));
|
||||||
|
|
||||||
|
if (test_config->has("query_file"))
|
||||||
|
{
|
||||||
|
const std::string filename = test_config->getString("query_file");
|
||||||
|
if (filename.empty())
|
||||||
|
throw Poco::Exception("Empty file name", 1);
|
||||||
|
|
||||||
|
bool tsv = FS::path(filename).extension().string() == ".tsv";
|
||||||
|
|
||||||
|
ReadBufferFromFile query_file(filename);
|
||||||
|
while (!query_file.eof())
|
||||||
|
{
|
||||||
|
size_t bytes = 0;
|
||||||
|
while (query_file.position() + bytes != query_file.buffer().end()
|
||||||
|
&& (query_file.position()[bytes] == '\t' || query_file.position()[bytes] == '\n')) {
|
||||||
|
std::cout << "shift" << std::endl;
|
||||||
|
++bytes;
|
||||||
|
}
|
||||||
|
query_file.position() += bytes;
|
||||||
|
|
||||||
|
tsv ? readEscapedString(query, query_file)
|
||||||
|
: readString(query, query_file);
|
||||||
|
queries.push_back(query);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (queries.empty())
|
||||||
|
{
|
||||||
|
throw Poco::Exception("Did not find any query to execute: " + test_name, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (test_config->has("substitutions"))
|
if (test_config->has("substitutions"))
|
||||||
@ -1227,17 +1260,16 @@ public:
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace fs = boost::filesystem;
|
void getFilesFromDir(FS::path && dir, std::vector<std::string> & input_files)
|
||||||
void getFilesFromDir(fs::path && dir, std::vector<std::string> & input_files)
|
|
||||||
{
|
{
|
||||||
if (dir.extension().string() == ".xml")
|
if (dir.extension().string() == ".xml")
|
||||||
std::cerr << "Warning: \"" + dir.string() + "\" is a directory, but has .xml extension" << std::endl;
|
std::cerr << "Warning: \"" + dir.string() + "\" is a directory, but has .xml extension" << std::endl;
|
||||||
|
|
||||||
fs::directory_iterator end;
|
FS::directory_iterator end;
|
||||||
for (fs::directory_iterator it(dir); it != end; ++it)
|
for (FS::directory_iterator it(dir); it != end; ++it)
|
||||||
{
|
{
|
||||||
const fs::path file = (*it);
|
const FS::path file = (*it);
|
||||||
if (!fs::is_directory(file) && file.extension().string() == ".xml")
|
if (!FS::is_directory(file) && file.extension().string() == ".xml")
|
||||||
input_files.push_back(file.string());
|
input_files.push_back(file.string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1296,27 +1328,27 @@ int mainEntryClickhousePerformanceTest(int argc, char ** argv)
|
|||||||
{
|
{
|
||||||
std::cout << "Trying to find tests in current folder" << std::endl;
|
std::cout << "Trying to find tests in current folder" << std::endl;
|
||||||
|
|
||||||
getFilesFromDir(fs::path("."), input_files);
|
getFilesFromDir(FS::path("."), input_files);
|
||||||
|
|
||||||
if (input_files.empty())
|
if (input_files.empty())
|
||||||
throw Poco::Exception("Did not find any xml files", 1);
|
throw Poco::Exception("Did not find any xml files", 1);
|
||||||
} else {
|
} else {
|
||||||
input_files = options["input-files"].as<Strings>();
|
input_files = options["input-files"].as<Strings>();
|
||||||
|
|
||||||
for (const std::string file_name : input_files)
|
for (const std::string filename : input_files)
|
||||||
{
|
{
|
||||||
fs::path file(file_name);
|
FS::path file(filename);
|
||||||
|
|
||||||
if (!fs::exists(file))
|
if (!FS::exists(file))
|
||||||
throw Poco::Exception("File \"" + file_name + "\" does not exist", 1);
|
throw Poco::Exception("File \"" + filename + "\" does not exist", 1);
|
||||||
|
|
||||||
if (fs::is_directory(file))
|
if (FS::is_directory(file))
|
||||||
{
|
{
|
||||||
input_files.erase( std::remove(input_files.begin(), input_files.end(), file_name) , input_files.end());
|
input_files.erase( std::remove(input_files.begin(), input_files.end(), filename) , input_files.end());
|
||||||
getFilesFromDir(std::move(file), input_files);
|
getFilesFromDir(std::move(file), input_files);
|
||||||
} else {
|
} else {
|
||||||
if (file.extension().string() != ".xml")
|
if (file.extension().string() != ".xml")
|
||||||
throw Poco::Exception("File \"" + file_name + "\" does not have .xml extension", 1);
|
throw Poco::Exception("File \"" + filename + "\" does not have .xml extension", 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user