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

Method fuzzCreateQuery

src/Common/QueryFuzzer.cpp:904–1321  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

902}
903
904void QueryFuzzer::fuzzCreateQuery(ASTCreateQuery & create)
905{
906 if (create.columns_list && create.columns_list->columns)
907 {
908 for (auto & ast : create.columns_list->columns->children)
909 {
910 if (auto * column = ast->as<ASTColumnDeclaration>())
911 {
912 fuzzColumnDeclaration(*column);
913 fuzz(ast);
914 }
915 }
916 }
917
918 if (create.columns_list && create.columns_list->indices)
919 {
920 for (auto & ast : create.columns_list->indices->children)
921 {
922 if (auto * index = ast->as<ASTIndexDeclaration>())
923 fuzzIndexDeclaration(*index);
924 }
925 }
926
927 if (create.storage && create.storage->engine)
928 {
929 auto & engine_name = create.storage->engine->name;
930
931 if (create.database && !create.table)
932 {
933 /// For database engine fuzzing, only swap between parameter-free engines.
934 /// Avoid touching Replicated (needs ZooKeeper), Lazy (needs arg), or external
935 /// engines (MySQL/PostgreSQL need connection params).
936 static const std::unordered_set<String> safe_database_engines = {"Atomic", "Memory", "Dictionary"};
937 if (safe_database_engines.contains(engine_name) && fuzz_rand() % 10 == 0)
938 {
939 engine_name = pickRandomly(fuzz_rand, safe_database_engines);
940 if (auto & arguments = create.storage->engine->arguments)
941 arguments->children.clear();
942 }
943 }
944 else
945 {
946 /// Replace ReplicatedMergeTree to ordinary MergeTree
947 /// to avoid inconsistency of metadata in zookeeper.
948 if (startsWith(engine_name, "Replicated"))
949 {
950 engine_name = engine_name.substr(strlen("Replicated"));
951 auto * engine = create.storage->engine;
952 if (engine->arguments)
953 {
954 if (engine->arguments->children.size() <= 2)
955 engine->reset(engine->arguments);
956 else
957 engine->arguments->children.erase(engine->arguments->children.begin(), engine->arguments->children.begin() + 2);
958 }
959 }
960
961 /// Swap between MergeTree variants that require no mandatory extra columns.

Callers

nothing calls this directly

Calls 15

getOriginalTableNameFunction · 0.85
getFuzzedTableNameFunction · 0.85
getSipHash128AsPairFunction · 0.85
supportSQLSecurityMethod · 0.80
startsWithFunction · 0.70
endsWithFunction · 0.70
swapFunction · 0.70
StringClass · 0.50
sizeFunction · 0.50
containsMethod · 0.45
clearMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected