Skip to content

Commit 85c9415

Browse files
craig[bot]Pradyum-Git
andcommitted
Merge #148886
148886: workload_generator: parse DDLs and build schema structs for debug-zip… r=nameisbhaskar a=Pradyum-Git … workloads Before this patch, there was no support for parsing CREATE TABLE DDLs or representing their schema metadata in Go. This was inadequate because the workload generator could not programmatically consume table definitions, column order, or constraint information from CockroachDB debug zip outputs. To address this, this patch introduces a GenerateDDLs function and TableSchema structs that parse DDL statements exported in debug zips and build internal schema representations (tracking column order, primary keys, unique and foreign key constraints). This forms the foundation for generating workloads directly from debug-zip schemas. Informs: CRDB-51752 Release note: None Co-authored-by: Pradyum <[email protected]>
2 parents 255f60e + c6cab13 commit 85c9415

File tree

7 files changed

+16698
-0
lines changed

7 files changed

+16698
-0
lines changed

pkg/BUILD.bazel

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,7 @@ ALL_TESTS = [
831831
"//pkg/workload/tpcc:tpcc_test",
832832
"//pkg/workload/tpch:tpch_test",
833833
"//pkg/workload/vecann:vecann_test",
834+
"//pkg/workload/workload_generator:workload_generator_test",
834835
"//pkg/workload/workloadimpl:workloadimpl_test",
835836
"//pkg/workload/workloadsql:workloadsql_test",
836837
"//pkg/workload/ycsb:ycsb_test",
@@ -2827,6 +2828,8 @@ GO_TARGETS = [
28272828
"//pkg/workload/ttllogger:ttllogger",
28282829
"//pkg/workload/vecann:vecann",
28292830
"//pkg/workload/vecann:vecann_test",
2831+
"//pkg/workload/workload_generator:workload_generator",
2832+
"//pkg/workload/workload_generator:workload_generator_test",
28302833
"//pkg/workload/workloadimpl:workloadimpl",
28312834
"//pkg/workload/workloadimpl:workloadimpl_test",
28322835
"//pkg/workload/workloadsql:workloadsql",
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
2+
3+
go_library(
4+
name = "workload_generator",
5+
srcs = [
6+
"constants.go",
7+
"ddl_generator.go",
8+
"schema_designs.go",
9+
],
10+
importpath = "github.com/cockroachdb/cockroach/pkg/workload/workload_generator",
11+
visibility = ["//visibility:public"],
12+
deps = ["@com_github_cockroachdb_errors//:errors"],
13+
)
14+
15+
go_test(
16+
name = "workload_generator_test",
17+
srcs = ["ddl_generator_test.go"],
18+
embed = [":workload_generator"],
19+
embedsrcs = ["test_data/debug/crdb_internal.create_statements.txt"],
20+
deps = ["@com_github_stretchr_testify//assert"],
21+
)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2025 The Cockroach Authors.
2+
//
3+
// Use of this software is governed by the CockroachDB Software License
4+
// included in the /LICENSE file.
5+
6+
package workload_generator
7+
8+
const (
9+
10+
// SQL keywords for constraints
11+
sqlIndex = "INDEX" // sqlIndex is a constant string used to represent index definitions in column definitions
12+
sqlNull = "NULL" // sqlNull is a constant string used to represent NULL values in column definitions
13+
sqlNotNull = "NOT NULL" // sqlNotNull is a constant string used to represent NOT NULL constraints in column definitions
14+
sqlPrimaryKey = "PRIMARY KEY" // sqlPrimaryKey is a constant string used to represent primary key constraints in column definitions
15+
sqlUnique = "UNIQUE" // sqlUnique is a constant string used to represent unique constraints in column definitions
16+
sqlDefault = "DEFAULT" // sqlDefault is a constant string used to represent default value expressions in column definitions
17+
sqlCheck = "CHECK" // sqlCheck is a constant string used to represent CHECK constraints in column definitions
18+
sqlForeignKey = "FOREIGN KEY" // sqlForeignKey is a constant string used to represent foreign key constraints in column definitions
19+
)

0 commit comments

Comments
 (0)