Skip to content

Commit

Permalink
Merge branch 'dev' into r_merger_agg
Browse files Browse the repository at this point in the history
  • Loading branch information
longyue0521 committed Jun 11, 2024
2 parents b9dba8d + 9e6a3fc commit e1940c0
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 49 deletions.
1 change: 1 addition & 0 deletions .deepsource.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ enabled = true
[analyzers.meta]
import_root = "github.com/ecodeclub/eorm"
dependencies_vendored = false
cyclomatic_complexity_threshold = "high"
12 changes: 3 additions & 9 deletions internal/merger/factory/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,13 @@ func (q QuerySpec) validateSelect() error {
return fmt.Errorf("%w: select", ErrEmptyColumnList)
}
for i, c := range q.Select {
if i != c.Index || !q.isValidColumnInfo(c) {
if i != c.Index || !c.Validate() {
return fmt.Errorf("%w: select %v", ErrInvalidColumnInfo, c.Name)
}
}
return nil
}

func (q QuerySpec) isValidColumnInfo(c merger.ColumnInfo) bool {
// ColumnInfo.Name中不能包含括号,也就是聚合函数, name = `id`, 而不是name = count(`id`)
// 聚合函数需要写在aggregateFunc字段中
return !strings.Contains(c.Name, "(")
}

func (q QuerySpec) validateGroupBy() error {
if !slice.Contains(q.Features, query.GroupBy) {
return nil
Expand All @@ -107,7 +101,7 @@ func (q QuerySpec) validateGroupBy() error {
return fmt.Errorf("%w: groupby", ErrEmptyColumnList)
}
for _, c := range q.GroupBy {
if !q.isValidColumnInfo(c) {
if !c.Validate() {
return fmt.Errorf("%w: groupby %v", ErrInvalidColumnInfo, c.Name)
}
// 清除ASC
Expand Down Expand Up @@ -136,7 +130,7 @@ func (q QuerySpec) validateOrderBy() error {
}
for _, c := range q.OrderBy {

if !q.isValidColumnInfo(c) {
if !c.Validate() {
return fmt.Errorf("%w: orderby %v", ErrInvalidColumnInfo, c.Name)
}
// 清除ASC
Expand Down
Loading

0 comments on commit e1940c0

Please sign in to comment.