Skip to content

Commit

Permalink
添加changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
juniaoshaonian committed Jun 16, 2024
1 parent 6309646 commit e04906b
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 17 deletions.
2 changes: 2 additions & 0 deletions .CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
- [refactor(merger): 重构AVG函数实现,重构所有rows.Rows实现的ConlumnType方法并添加测试](https://github.com/ecodeclub/eorm/pull/223)
- [feat(merger): 新增Distinct Merger](https://github.com/ecodeclub/eorm/pull/224)
- [refactor(merger): 去掉无用代码及过期注释,整理代码](https://github.com/ecodeclub/eorm/pull/225)
- [eorm: 结果集处理--聚合函数支持nullable类型的数据](https://github.com/ecodeclub/eorm/pull/226)

## v0.0.1:
- [Init Project](https://github.com/ecodeclub/eorm/pull/1)
- [Selector Definition](https://github.com/ecodeclub/eorm/pull/2)
Expand Down
1 change: 0 additions & 1 deletion internal/merger/internal/aggregatemerger/aggregator/avg.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ func avgAggregator[S AggregateElement, C AggregateElement](cols [][]any, sumInde

}


func (a *AVG) avgNullAbleAggregator(cols [][]any, sumIndex int, countIndex int) (any, error) {
notNullCols := make([][]any, 0, len(cols))
var sumValKind, countValKind reflect.Kind
Expand Down
6 changes: 3 additions & 3 deletions internal/merger/internal/aggregatemerger/aggregator/count.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (s *Count) findCountFunc(col []any) (func([][]any, int) (any, error), error
if countIndex < 0 || countIndex >= len(col) {
return nil, errs.ErrMergerInvalidAggregateColumnIndex
}
return s.countNullAbleAggregator,nil
return s.countNullAbleAggregator, nil
}

func (s *Count) ColumnInfo() merger.ColumnInfo {
Expand All @@ -64,8 +64,8 @@ func countAggregate[T AggregateElement](cols [][]any, countIndex int) (any, erro
}
return count, nil
}
func (s *Count)countNullAbleAggregator(colsData [][]any, countIndex int) (any, error) {
notNullCols,kind := nullAbleAggregator(colsData, countIndex)
func (s *Count) countNullAbleAggregator(colsData [][]any, countIndex int) (any, error) {
notNullCols, kind := nullAbleAggregator(colsData, countIndex)
// 说明几个数据库里查出来的数据都为null,返回第一个null值即可
if len(notNullCols) == 0 {
return colsData[0][countIndex], nil
Expand Down
4 changes: 2 additions & 2 deletions internal/merger/internal/aggregatemerger/aggregator/max.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ func NewMax(info merger.ColumnInfo) *Max {
func maxAggregator[T AggregateElement](colsData [][]any, maxIndex int) (any, error) {
return findExtremeValue[T](colsData, isMaxValue[T], maxIndex)
}
func (m *Max)maxNullAbleAggregator(colsData [][]any, maxIndex int) (any, error) {
notNullCols,kind := nullAbleAggregator(colsData,maxIndex)
func (m *Max) maxNullAbleAggregator(colsData [][]any, maxIndex int) (any, error) {
notNullCols, kind := nullAbleAggregator(colsData, maxIndex)
// 说明几个数据库里查出来的数据都为null,返回第一个null值即可
if len(notNullCols) == 0 {
return colsData[0][maxIndex], nil
Expand Down
5 changes: 2 additions & 3 deletions internal/merger/internal/aggregatemerger/aggregator/min.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ func minAggregator[T AggregateElement](colsData [][]any, minIndex int) (any, err
return findExtremeValue[T](colsData, isMinValue[T], minIndex)
}

func (m *Min)minNullAbleAggregator(colsData [][]any, minIndex int) (any, error) {
notNullCols,kind := nullAbleAggregator(colsData,minIndex)
func (m *Min) minNullAbleAggregator(colsData [][]any, minIndex int) (any, error) {
notNullCols, kind := nullAbleAggregator(colsData, minIndex)
// 说明几个数据库里查出来的数据都为null,返回第一个null值即可
if len(notNullCols) == 0 {
return colsData[0][minIndex], nil
Expand All @@ -75,7 +75,6 @@ func (m *Min)minNullAbleAggregator(colsData [][]any, minIndex int) (any, error)
return minFunc(notNullCols, minIndex)
}


var minFuncMapping = map[reflect.Kind]func([][]any, int) (any, error){
reflect.Int: minAggregator[int],
reflect.Int8: minAggregator[int8],
Expand Down
4 changes: 2 additions & 2 deletions internal/merger/internal/aggregatemerger/aggregator/sum.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ func sumAggregate[T AggregateElement](cols [][]any, sumIndex int) (any, error) {
return sum, nil
}

func (s *Sum)sumNullAbleAggregator(colsData [][]any, sumIndex int) (any, error) {
notNullCols,kind := nullAbleAggregator(colsData, sumIndex)
func (s *Sum) sumNullAbleAggregator(colsData [][]any, sumIndex int) (any, error) {
notNullCols, kind := nullAbleAggregator(colsData, sumIndex)
// 说明几个数据库里查出来的数据都为null,返回第一个null值即可
if len(notNullCols) == 0 {
return colsData[0][sumIndex], nil
Expand Down
12 changes: 6 additions & 6 deletions internal/merger/internal/aggregatemerger/aggregator/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ package aggregator

import (
"database/sql/driver"
"github.com/ecodeclub/eorm/internal/merger"
"reflect"

"github.com/ecodeclub/eorm/internal/merger"
)

type AggregateElement interface {
Expand All @@ -33,9 +34,8 @@ type Aggregator interface {
Name() string
}


// 处理查询到的nullable类型的数据,第一个返回值为 非null的数据 如果是sql.nullfloat64{value: 1.1,valid: true},返回的就是1.1 。 第二个返回值为value的kind
func nullAbleAggregator(colsData [][]any, index int) ([][]any,reflect.Kind) {
func nullAbleAggregator(colsData [][]any, index int) ([][]any, reflect.Kind) {
notNullCols := make([][]any, 0, len(colsData))
var kind reflect.Kind
for _, colData := range colsData {
Expand All @@ -47,10 +47,10 @@ func nullAbleAggregator(colsData [][]any, index int) ([][]any,reflect.Kind) {
colData[index] = maxVal
notNullCols = append(notNullCols, colData)
}
}else {
} else {
kind = reflect.TypeOf(col).Kind()
notNullCols = append(notNullCols, colData)
}
}
return notNullCols,kind
}
return notNullCols, kind
}

0 comments on commit e04906b

Please sign in to comment.