Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cuio calculated result as float64 val #20420

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/sql/plan/function/func_builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -2595,10 +2595,10 @@ func buildInMOCUWithCfg(parameters []*vector.Vector, result vector.FunctionResul
case "mem":
cu = motrace.CalculateCUMem(int64(stats.GetMemorySize()), durationNS, cfg)
case "ioin":
cu = motrace.CalculateCUIOIn(int64(stats.GetS3IOInputCount()), cfg) +
cu = motrace.CalculateCUIOIn(stats.GetS3IOInputCount(), cfg) +
motrace.CalculateCUIODelete(stats.GetS3IODeleteCount(), cfg)
case "ioout":
cu = motrace.CalculateCUIOOut(int64(stats.GetS3IOOutputCount()), cfg) +
cu = motrace.CalculateCUIOOut(stats.GetS3IOOutputCount(), cfg) +
motrace.CalculateCUIOList(stats.GetS3IOListCount(), cfg)
case "iolist":
cu = motrace.CalculateCUIOList(stats.GetS3IOListCount(), cfg)
Expand Down
8 changes: 4 additions & 4 deletions pkg/util/trace/impl/motrace/cu.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,18 +135,18 @@ func CalculateCUMemDecimal(memByte, durationNS int64, memPrice, cuUnit float64)
return types.Decimal256ToFloat64(val1, cuScale), nil
}

func CalculateCUIOIn(ioCnt int64, cfg *config.OBCUConfig) float64 {
func CalculateCUIOIn(ioCnt float64, cfg *config.OBCUConfig) float64 {
if cfg == nil {
cfg = GetCUConfig()
}
return float64(ioCnt) * cfg.IoInPrice / cfg.CUUnit
return ioCnt * cfg.IoInPrice / cfg.CUUnit
}

func CalculateCUIOOut(ioCnt int64, cfg *config.OBCUConfig) float64 {
func CalculateCUIOOut(ioCnt float64, cfg *config.OBCUConfig) float64 {
if cfg == nil {
cfg = GetCUConfig()
}
return float64(ioCnt) * cfg.IoOutPrice / cfg.CUUnit
return ioCnt * cfg.IoOutPrice / cfg.CUUnit
}

func CalculateCUIOList(ioCnt float64, cfg *config.OBCUConfig) float64 {
Expand Down
9 changes: 5 additions & 4 deletions pkg/util/trace/impl/motrace/cu_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
package motrace

import (
"github.com/matrixorigin/matrixone/pkg/config"
"github.com/matrixorigin/matrixone/pkg/util/trace/impl/motrace/statistic"
"testing"
"time"

"github.com/matrixorigin/matrixone/pkg/config"
"github.com/matrixorigin/matrixone/pkg/util/trace/impl/motrace/statistic"
)

// BenchmarkCalculateMem
Expand Down Expand Up @@ -229,8 +230,8 @@ func BenchmarkCalculateElem(b *testing.B) {
b.Run(bm.name+"/io", func(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
_ = CalculateCUIOIn(int64(bm.args.stats.GetS3IOInputCount()), bm.args.cfg)
_ = CalculateCUIOOut(int64(bm.args.stats.GetS3IOOutputCount()), bm.args.cfg)
_ = CalculateCUIOIn(bm.args.stats.GetS3IOInputCount(), bm.args.cfg)
_ = CalculateCUIOOut(bm.args.stats.GetS3IOOutputCount(), bm.args.cfg)
}
})
}
Expand Down
9 changes: 9 additions & 0 deletions test/distributed/cases/log/query_cu.result
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,12 @@ val
select CAST(mo_cu('[5,1,2,3,4,5,6,7,8,1,2]', 0, 'iodelete') AS DECIMAL(32,4)) val;
val
11.3097
select CAST(mo_cu('[5,1,2,0.000122,4,5,6,7,8,1,2]', 0, 'ioin') AS DECIMAL(32,4)) val;
val
11.3104
select CAST(mo_cu('[5,1,2,0.000122,4,5,6,7,8,0,0]', 0, 'ioin') AS DECIMAL(32,4)) val;
val
0.0007
select CAST(mo_cu('[5,1,2,0.000244,4,5,6,7,8,0,0]', 0, 'ioin') AS DECIMAL(32,4)) val;
val
0.0014
5 changes: 5 additions & 0 deletions test/distributed/cases/log/query_cu.sql
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,8 @@ select mo_cu('[4,1,2,3,4,5,6,7,8]', 0, 'iolist') val;
-- 10 | delete
select CAST(mo_cu('[5,1,2,3,4,5,6,7,8,1,2]', 0, 'iolist') AS DECIMAL(32,4)) val;
select CAST(mo_cu('[5,1,2,3,4,5,6,7,8,1,2]', 0, 'iodelete') AS DECIMAL(32,4)) val;
-- issue moc-4510
-- cu_ioin = 0.000122 * 5.67e-06 / 1.002678e-06 ~= 0.0007
select CAST(mo_cu('[5,1,2,0.000122,4,5,6,7,8,1,2]', 0, 'ioin') AS DECIMAL(32,4)) val;
select CAST(mo_cu('[5,1,2,0.000122,4,5,6,7,8,0,0]', 0, 'ioin') AS DECIMAL(32,4)) val;
select CAST(mo_cu('[5,1,2,0.000244,4,5,6,7,8,0,0]', 0, 'ioin') AS DECIMAL(32,4)) val;
Loading