Skip to content

Commit e66e11b

Browse files
committed
feat(ch): ensure revenue1 view creation for CSV data ingestion
Signed-off-by: mahjonp <[email protected]>
1 parent c71da30 commit e66e11b

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

ch/workload.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,5 +352,12 @@ func (w *Workloader) FinishPlanReplayerDump() error {
352352
}
353353

354354
func (w *Workloader) Exec(sql string) error {
355-
return nil
355+
ctx := context.Background()
356+
s := &chState{
357+
TpcState: workload.NewTpcState(ctx, w.db),
358+
}
359+
defer s.Conn.Close()
360+
361+
_, err := s.Conn.ExecContext(ctx, sql)
362+
return err
356363
}

cmd/go-tpc/misc.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,23 @@ func executeWorkload(ctx context.Context, w workload.Workloader, threads int, ac
114114
panic(fmt.Sprintf("a fatal occurred when preparing view data: %v", err))
115115
}
116116
}
117+
// CH benchmark requires the revenue1 view for analytical queries.
118+
// During normal prepare flow, this view is created in prepareView() method.
119+
// However, when using CSV data ingestion, the prepare stage is skipped and
120+
// the view won't exist. So we create it here when action is "run" to ensure
121+
// the view is available regardless of how data was loaded.
122+
if w.Name() == "ch" && action == "run" {
123+
err := w.Exec(`create or replace view revenue1 (supplier_no, total_revenue) as (
124+
select mod((s_w_id * s_i_id),10000) as supplier_no,
125+
sum(ol_amount) as total_revenue
126+
from order_line, stock
127+
where ol_i_id = s_i_id and ol_supply_w_id = s_w_id
128+
and ol_delivery_d >= '2007-01-02 00:00:00.000000'
129+
group by mod((s_w_id * s_i_id),10000));`)
130+
if err != nil {
131+
panic(fmt.Sprintf("a fatal occurred when preparing view data: %v", err))
132+
}
133+
}
117134
enabledDumpPlanReplayer := w.IsPlanReplayerDumpEnabled()
118135
if enabledDumpPlanReplayer {
119136
err := w.PreparePlanReplayerDump()

0 commit comments

Comments
 (0)