mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-08-28 02:44:59 +00:00
parent
c79cc3b7db
commit
cd32cd7696
2 changed files with 35 additions and 1 deletions
|
|
@ -269,7 +269,9 @@ func (i *pqlAggregateRowIter) Next(ctx context.Context) (types.Row, error) {
|
|||
case *parser.DataTypeDecimal:
|
||||
_, isAvg := i.aggregate.(*avgPlanExpression)
|
||||
if isAvg {
|
||||
if actualResult.DecimalVal == nil {
|
||||
if actualResult.Count == 0 {
|
||||
i.resultValue = nil
|
||||
} else if actualResult.DecimalVal == nil {
|
||||
average := float64(actualResult.Val) / float64(actualResult.Count)
|
||||
daverage, err := pql.FromFloat64WithScale(average, int(t.Scale))
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -394,6 +394,38 @@ var avgTests = TableTest{
|
|||
),
|
||||
Compare: CompareExactUnordered,
|
||||
},
|
||||
{
|
||||
SQLs: sqls(
|
||||
"SELECT avg(i1) AS avg_rows FROM avg_test WHERE i1 > 100",
|
||||
),
|
||||
ExpHdrs: hdrs(
|
||||
hdr("avg_rows", featurebase.WireQueryField{
|
||||
Type: dax.BaseTypeDecimal + "(4)",
|
||||
BaseType: dax.BaseTypeDecimal,
|
||||
TypeInfo: map[string]interface{}{"scale": int64(4)},
|
||||
}),
|
||||
),
|
||||
ExpRows: rows(
|
||||
row(nil),
|
||||
),
|
||||
Compare: CompareExactUnordered,
|
||||
},
|
||||
{
|
||||
SQLs: sqls(
|
||||
"SELECT avg(d1) AS avg_rows FROM avg_test WHERE d1 > 100.0",
|
||||
),
|
||||
ExpHdrs: hdrs(
|
||||
hdr("avg_rows", featurebase.WireQueryField{
|
||||
Type: dax.BaseTypeDecimal + "(4)",
|
||||
BaseType: dax.BaseTypeDecimal,
|
||||
TypeInfo: map[string]interface{}{"scale": int64(4)},
|
||||
}),
|
||||
),
|
||||
ExpRows: rows(
|
||||
row(nil),
|
||||
),
|
||||
Compare: CompareExactUnordered,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue