Skip to content

Commit

Permalink
Merge pull request #11 from hmeriann/delete-statement
Browse files Browse the repository at this point in the history
Add Delete statement functionality to fuzzer
  • Loading branch information
Tmonster authored Jul 15, 2024
2 parents 9a249fa + 8e676a2 commit c5305fd
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
8 changes: 3 additions & 5 deletions .github/workflows/MainDistributionPipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,15 @@ jobs:
name: Build extension binaries
uses: duckdb/extension-ci-tools/.github/workflows/[email protected]
with:
duckdb_version: v1.0.0
duckdb_version: main
extension_name: sqlsmith
exclude_archs: 'wasm_mvp;wasm_eh;wasm_threads;windows_amd64_rtools'

duckdb-stable-deploy:
name: Deploy extension binaries
needs: duckdb-stable-build
uses: duckdb/extension-ci-tools/.github/workflows/[email protected]
secrets: inherit
with:
duckdb_version: v1.0.0
duckdb_version: main
extension_name: sqlsmith
exclude_archs: 'wasm_mvp;wasm_eh;wasm_threads;windows_amd64_rtools'
deploy_latest: ${{ startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main' }}
deploy_latest: ${{ startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main' }}
10 changes: 6 additions & 4 deletions src/include/statement_generator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,18 @@ class StatementGenerator {
unique_ptr<SQLStatement> GenerateStatement(StatementType type); // came from private

private:
unique_ptr<MultiStatement> GenerateAttachUse();
unique_ptr<SetStatement> GenerateSet();
unique_ptr<AttachStatement> GenerateAttach();
unique_ptr<CreateStatement> GenerateCreate();
unique_ptr<DeleteStatement> GenerateDelete();
unique_ptr<DetachStatement> GenerateDetach();
unique_ptr<MultiStatement> GenerateAttachUse();
unique_ptr<SelectStatement> GenerateSelect();
unique_ptr<CreateStatement> GenerateCreate();
unique_ptr<SetStatement> GenerateSet();

unique_ptr<QueryNode> GenerateQueryNode();

unique_ptr<CreateInfo> GenerateCreateInfo();
unique_ptr<AttachInfo> GenerateAttachInfo();
unique_ptr<CreateInfo> GenerateCreateInfo();
unique_ptr<DetachInfo> GenerateDetachInfo();

void GenerateCTEs(QueryNode &node);
Expand Down
25 changes: 25 additions & 0 deletions src/statement_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ unique_ptr<SQLStatement> StatementGenerator::GenerateStatement() {
if (RandomPercentage(30)) {
return GenerateStatement(StatementType::SET_STATEMENT);
}
if (RandomPercentage(40)) { //20
return GenerateStatement(StatementType::DELETE_STATEMENT);
}
return GenerateStatement(StatementType::CREATE_STATEMENT);
}

Expand All @@ -125,6 +128,8 @@ unique_ptr<SQLStatement> StatementGenerator::GenerateStatement(StatementType typ
// generate USE statement
case StatementType::SET_STATEMENT:
return GenerateSet();
case StatementType::DELETE_STATEMENT:
return GenerateDelete();
default:
throw InternalException("Unsupported type");
}
Expand Down Expand Up @@ -175,6 +180,26 @@ unique_ptr<MultiStatement> StatementGenerator::GenerateAttachUse() {
return multi_statement;
}

unique_ptr<DeleteStatement> StatementGenerator::GenerateDelete() {
auto delete_statement = make_uniq<DeleteStatement>();
auto state = GetDatabaseState(context);
if (!generator_context->tables_and_views.empty()) {
auto &entry_ref = Choose(generator_context->tables_and_views);
auto &entry = entry_ref.get();
if (entry.type == CatalogType::TABLE_ENTRY) {
auto result = make_uniq<BaseTableRef>();
result->table_name = entry.name;
delete_statement->table = std::move(result);
} else {
delete_statement->table = GenerateTableRef();
}
} else {
delete_statement->table = GenerateTableRef();
}

return delete_statement;
}

//===--------------------------------------------------------------------===//
// Generate Detach Info
//===--------------------------------------------------------------------===//
Expand Down

0 comments on commit c5305fd

Please sign in to comment.