Skip to content

Commit cd15e8e

Browse files
committed
workload: add support to csv generation for decimal
PR #144818 modified the tpcc workload so that it generates decimals instead of floats. Usually fixture generation uses a special case in process data generator, but the import roachtests uses a datum -> csv conversation code path that was missing support for the decimal type. Fixes: #145058 Fixes: #145058 Fixes: #145185 Release note: none
1 parent fa5a923 commit cd15e8e

File tree

4 files changed

+45
-0
lines changed

4 files changed

+45
-0
lines changed

pkg/workload/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,6 @@ go_test(
7272
"//pkg/workload/bank",
7373
"//pkg/workload/tpcc",
7474
"//pkg/workload/tpch",
75+
"@com_github_stretchr_testify//require",
7576
],
7677
)

pkg/workload/bench_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ func columnByteSize(col *coldata.Vec) int64 {
3838
return col.Bytes().Size() - coldata.FlatBytesOverhead
3939
case types.TimestampTZFamily:
4040
return int64(col.Timestamp().Len()) * memsize.Time
41+
case types.DecimalFamily:
42+
return int64(col.Decimal().Len()) * memsize.Decimal
4143
default:
4244
panic(fmt.Sprintf(`unhandled type %s`, t))
4345
}

pkg/workload/csv.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ func colDatumToCSVString(col *coldata.Vec, rowIdx int) string {
8686
return *(*string)(unsafe.Pointer(&bytes))
8787
case types.TimestampTZFamily:
8888
return col.Timestamp()[rowIdx].Format(timestampOutputFormat)
89+
case types.DecimalFamily:
90+
return col.Decimal()[rowIdx].String()
8991
}
9092
panic(fmt.Sprintf(`unhandled type %s`, col.Type()))
9193
}

pkg/workload/csv_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"github.com/cockroachdb/cockroach/pkg/workload"
2222
"github.com/cockroachdb/cockroach/pkg/workload/bank"
2323
"github.com/cockroachdb/cockroach/pkg/workload/tpcc"
24+
"github.com/stretchr/testify/require"
2425
)
2526

2627
func TestHandleCSV(t *testing.T) {
@@ -69,6 +70,45 @@ func TestHandleCSV(t *testing.T) {
6970
}
7071
}
7172

73+
func TestHandleCSVTpcc(t *testing.T) {
74+
defer leaktest.AfterTest(t)()
75+
76+
tests := []struct {
77+
params, expected string
78+
}{
79+
{
80+
`?rows=1`, `
81+
0,9,10,17,16,RG,955311111,0.1622,300000.00`,
82+
},
83+
{
84+
`?rows=5&row-start=1&row-end=3`, `
85+
1,10,20,13,20,RG,327711111,0.1625,300000.00
86+
2,9,18,12,10,QN,533211111,0.1000,300000.00`,
87+
},
88+
}
89+
90+
// assertions depend on this seed
91+
tpcc.RandomSeed.Set(1)
92+
meta := tpcc.FromWarehouses(1).Meta()
93+
for _, test := range tests {
94+
t.Run(test.params, func(t *testing.T) {
95+
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
96+
require.NoError(t, workload.HandleCSV(w, r, `/tpcc/`, meta))
97+
}))
98+
defer ts.Close()
99+
100+
res, err := httputil.Get(context.Background(), ts.URL+`/tpcc/warehouse`+test.params)
101+
require.NoError(t, err)
102+
103+
data, err := io.ReadAll(res.Body)
104+
res.Body.Close()
105+
require.NoError(t, err)
106+
107+
require.Equal(t, strings.TrimSpace(test.expected), strings.TrimSpace(string(data)))
108+
})
109+
}
110+
}
111+
72112
func BenchmarkWriteCSVRows(b *testing.B) {
73113
ctx, cancel := context.WithCancel(context.Background())
74114
defer cancel()

0 commit comments

Comments
 (0)