File: sqllogic_command.hpp

package info (click to toggle)
duckdb 1.5.1-3
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 299,196 kB
  • sloc: cpp: 865,414; ansic: 57,292; python: 18,871; sql: 12,663; lisp: 11,751; yacc: 7,412; lex: 1,682; sh: 747; makefile: 564
file content (221 lines) | stat: -rw-r--r-- 5,017 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
//===----------------------------------------------------------------------===//
//                         DuckDB
//
// sqllogic_command.hpp
//
//
//===----------------------------------------------------------------------===//

#pragma once

#include "duckdb.hpp"
#include "duckdb/common/virtual_file_system.hpp"
#include "test_config.hpp"

namespace duckdb {
class SQLLogicTestRunner;

enum class ExpectedResult : uint8_t { RESULT_SUCCESS, RESULT_ERROR, RESULT_UNKNOWN, RESULT_DONT_CARE };

struct LoopDefinition {
	string loop_iterator_name;
	int loop_idx;
	int loop_start;
	int loop_end;
	bool is_parallel;
	vector<string> tokens;
	bool is_skipped = false;
};

struct ExecuteContext {
	ExecuteContext() : con(nullptr), is_parallel(false) {
	}
	ExecuteContext(Connection &con, vector<LoopDefinition> running_loops_p)
	    : con(con), running_loops(std::move(running_loops_p)), is_parallel(true) {
	}

	optional_ptr<Connection> con;
	vector<LoopDefinition> running_loops;
	bool is_parallel = false;
	string sql_query;
	string error_file;
	int error_line = -1;
};

struct Condition {
	string keyword;
	string value;
	ExpressionType comparison;
	bool skip_if;
};

class Command {
public:
	explicit Command(SQLLogicTestRunner &runner);
	virtual ~Command();

	SQLLogicTestRunner &runner;
	string connection_name;
	int query_line = -1;
	string base_sql_query;
	string file_name;
	vector<Condition> conditions;

public:
	Connection &CommandConnection(ExecuteContext &context) const;

	duckdb::unique_ptr<MaterializedQueryResult> ExecuteQuery(ExecuteContext &context, reference<Connection> connection,
	                                                         string file_name, idx_t query_line) const;

	virtual void ExecuteInternal(ExecuteContext &context) const = 0;
	void Execute(ExecuteContext &context) const;

	virtual bool SupportsConcurrent() const {
		return false;
	}

private:
	void RestartDatabase(ExecuteContext &context, reference<Connection> &connection, const string &sql_query) const;
};

class Statement : public Command {
public:
	Statement(SQLLogicTestRunner &runner);

	ExpectedResult expected_result;
	string expected_error;

public:
	void ExecuteInternal(ExecuteContext &context) const override;

	bool SupportsConcurrent() const override {
		return true;
	}
};

class ResetLabel : public Command {
public:
	ResetLabel(SQLLogicTestRunner &runner);

public:
	void ExecuteInternal(ExecuteContext &context) const override;

	bool SupportsConcurrent() const override {
		return true;
	}

public:
	string query_label;
};

class Query : public Command {
public:
	Query(SQLLogicTestRunner &runner);

	idx_t expected_column_count = 0;
	SortStyle sort_style = SortStyle::NO_SORT;
	vector<string> values;
	bool query_has_label = false;
	string query_label;

public:
	void ExecuteInternal(ExecuteContext &context) const override;

	bool SupportsConcurrent() const override {
		return true;
	}
};

class RestartCommand : public Command {
public:
	bool load_extensions;
	RestartCommand(SQLLogicTestRunner &runner, bool load_extensions);

public:
	void ExecuteInternal(ExecuteContext &context) const override;
};

class ReconnectCommand : public Command {
public:
	ReconnectCommand(SQLLogicTestRunner &runner);

public:
	void ExecuteInternal(ExecuteContext &context) const override;
};

class LoopCommand : public Command {
public:
	LoopCommand(SQLLogicTestRunner &runner, LoopDefinition definition_p);

public:
	LoopDefinition definition;
	vector<duckdb::unique_ptr<Command>> loop_commands;

	void ExecuteInternal(ExecuteContext &context) const override;

	bool SupportsConcurrent() const override;
};

class ContinueCommand : public Command {
public:
	explicit ContinueCommand(SQLLogicTestRunner &runner);

public:
	void ExecuteInternal(ExecuteContext &context) const override;
	bool SupportsConcurrent() const override;
};

class ModeCommand : public Command {
public:
	ModeCommand(SQLLogicTestRunner &runner, string parameter);

public:
	string parameter;

	void ExecuteInternal(ExecuteContext &context) const override;
};

enum class SleepUnit : uint8_t { NANOSECOND, MICROSECOND, MILLISECOND, SECOND };

class SleepCommand : public Command {
public:
	SleepCommand(SQLLogicTestRunner &runner, idx_t duration, SleepUnit unit);

public:
	void ExecuteInternal(ExecuteContext &context) const override;

	static SleepUnit ParseUnit(const string &unit);

private:
	idx_t duration;
	SleepUnit unit;
};

class UnzipCommand : public Command {
public:
	// 1 MB
	static constexpr const int64_t BUFFER_SIZE = 1u << 20;

public:
	UnzipCommand(SQLLogicTestRunner &runner, string &input, string &output);

	void ExecuteInternal(ExecuteContext &context) const override;

private:
	string input_path;
	string extraction_path;
};

class LoadCommand : public Command {
public:
	LoadCommand(SQLLogicTestRunner &runner, string dbpath, bool readonly, const string &version = "");

	string dbpath;
	bool readonly;
	string version;

public:
	void ExecuteInternal(ExecuteContext &context) const override;
};

} // namespace duckdb