1#include <iostream>
2#include <iomanip>
3
4#include <common/DateLUT.h>
5
6#include <Poco/ConsoleChannel.h>
7
8#include <IO/ReadBufferFromFileDescriptor.h>
9#include <IO/WriteBufferFromFileDescriptor.h>
10
11#include <Storages/StorageLog.h>
12#include <Storages/System/attachSystemTables.h>
13
14#include <Interpreters/Context.h>
15#include <Interpreters/loadMetadata.h>
16#include <Interpreters/executeQuery.h>
17#include <Databases/IDatabase.h>
18#include <Databases/DatabaseOrdinary.h>
19
20
21using namespace DB;
22
23int main(int, char **)
24try
25{
26 Poco::AutoPtr<Poco::ConsoleChannel> channel = new Poco::ConsoleChannel(std::cerr);
27 Logger::root().setChannel(channel);
28 Logger::root().setLevel("trace");
29
30 /// Pre-initialize the `DateLUT` so that the first initialization does not affect the measured execution speed.
31 DateLUT::instance();
32
33 Context context = Context::createGlobal();
34 context.makeGlobalContext();
35
36 context.setPath("./");
37
38 loadMetadata(context);
39
40 DatabasePtr system = std::make_shared<DatabaseOrdinary>("system", "./metadata/system/", context);
41 context.addDatabase("system", system);
42 system->loadStoredObjects(context, false);
43 attachSystemTablesLocal(*context.getDatabase("system"));
44 context.setCurrentDatabase("default");
45
46 ReadBufferFromFileDescriptor in(STDIN_FILENO);
47 WriteBufferFromFileDescriptor out(STDOUT_FILENO);
48
49 executeQuery(in, out, /* allow_into_outfile = */ false, context, {}, {});
50
51 return 0;
52}
53catch (const Exception & e)
54{
55 std::cerr << e.what() << ", " << e.displayText() << std::endl
56 << std::endl
57 << "Stack trace:" << std::endl
58 << e.getStackTrace().toString();
59 return 1;
60}
61