MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / processWithASTFuzzer

Method processWithASTFuzzer

programs/client/FuzzLoop.cpp:135–492  ·  view source on GitHub ↗

Returns false when server is not available.

Source from the content-addressed store, hash-verified

133
134/// Returns false when server is not available.
135bool Client::processWithASTFuzzer(std::string_view full_query)
136{
137 ASTPtr orig_ast;
138
139 try
140 {
141 const char * begin = full_query.data();
142 orig_ast = parseQuery(
143 begin,
144 begin + full_query.size(),
145 client_context->getSettingsRef(),
146 /*allow_multi_statements=*/true);
147 }
148 catch (const Exception & e)
149 {
150 if (e.code() != ErrorCodes::SYNTAX_ERROR && e.code() != ErrorCodes::TOO_DEEP_RECURSION)
151 throw;
152 }
153
154 if (!orig_ast)
155 {
156 // Can't continue after a parsing error
157 return true;
158 }
159
160 // `USE db` should not be executed
161 // since this will break every query after `DROP db`
162 if (orig_ast->as<ASTUseQuery>())
163 {
164 return true;
165 }
166
167 // Kusto is not a subject for fuzzing (yet)
168 if (client_context->getSettingsRef()[Setting::dialect] == DB::Dialect::kusto)
169 {
170 return true;
171 }
172 if (auto * q = orig_ast->as<ASTSetQuery>())
173 {
174 if (auto * set_dialect = q->changes.tryGet("dialect"); set_dialect && set_dialect->safeGet<String>() == "kusto")
175 return true;
176 }
177
178 // Don't repeat:
179 // - INSERT -- Because the tables may grow too big.
180 // - CREATE -- Because first we run the unmodified query, it will succeed,
181 // and the subsequent queries will fail.
182 // When we run out of fuzzer errors, it may be interesting to
183 // add fuzzing of create queries that wraps columns into
184 // LowCardinality or Nullable.
185 // Also there are other kinds of create queries such as CREATE
186 // DICTIONARY, we could fuzz them as well.
187 // - DROP -- No point in this (by the same reasons).
188 // - SET -- The time to fuzz the settings has not yet come
189 // (see comments in Client/QueryFuzzer.cpp)
190 size_t this_query_runs = query_fuzzer_runs;
191 ASTs queries_for_fuzzed_tables;
192

Callers

nothing calls this directly

Calls 15

parseQueryFunction · 0.85
copyDataFunction · 0.85
getCurrentExceptionCodeFunction · 0.85
fuzzMainMethod · 0.80
settingsMethod · 0.80
getRandomSettingsMethod · 0.80
hasInlinedDataMethod · 0.80

Tested by

no test coverage detected