Skip to content

Commit 4094c7d

Browse files
mahjonpYui-Song
andauthored
feat(ch): ensure revenue1 view creation for CSV data ingestion (#195)
Signed-off-by: mahjonp <junpeng.man@gmail.com> Co-authored-by: Yui-Song <84501897+Yui-Song@users.noreply.github.com>
1 parent ae4c57e commit 4094c7d

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
@@ -365,5 +365,12 @@ func (w *Workloader) FinishPlanReplayerDump() error {
365365
}
366366

367367
func (w *Workloader) Exec(sql string) error {
368-
return nil
368+
ctx := context.Background()
369+
s := &chState{
370+
TpcState: workload.NewTpcState(ctx, w.db),
371+
}
372+
defer s.Conn.Close()
373+
374+
_, err := s.Conn.ExecContext(ctx, sql)
375+
return err
369376
}

cmd/go-tpc/misc.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,23 @@ func executeWorkload(ctx context.Context, w workload.Workloader, threads int, ac
137137
panic(fmt.Sprintf("a fatal occurred when preparing view data: %v", err))
138138
}
139139
}
140+
// CH benchmark requires the revenue1 view for analytical queries.
141+
// During normal prepare flow, this view is created in prepareView() method.
142+
// However, when using CSV data ingestion, the prepare stage is skipped and
143+
// the view won't exist. So we create it here when action is "run" to ensure
144+
// the view is available regardless of how data was loaded.
145+
if w.Name() == "ch" && action == "run" {
146+
err := w.Exec(`create or replace view revenue1 (supplier_no, total_revenue) as (
147+
select mod((s_w_id * s_i_id),10000) as supplier_no,
148+
sum(ol_amount) as total_revenue
149+
from order_line, stock
150+
where ol_i_id = s_i_id and ol_supply_w_id = s_w_id
151+
and ol_delivery_d >= '2007-01-02 00:00:00.000000'
152+
group by mod((s_w_id * s_i_id),10000));`)
153+
if err != nil {
154+
panic(fmt.Sprintf("a fatal occurred when preparing view data: %v", err))
155+
}
156+
}
140157
enabledDumpPlanReplayer := w.IsPlanReplayerDumpEnabled()
141158
if enabledDumpPlanReplayer {
142159
err := w.PreparePlanReplayerDump()

0 commit comments

Comments
 (0)