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

分库分表:结果集处理——聚合函数(不含 Group By 子句) #187

Merged
merged 14 commits into from
Apr 14, 2023
Merged

分库分表:结果集处理——聚合函数(不含 Group By 子句) #187

merged 14 commits into from
Apr 14, 2023

Conversation

juniaoshaonian
Copy link
Collaborator

No description provided.

@codecov
Copy link

codecov bot commented Apr 1, 2023

Codecov Report

Merging #187 (25ff222) into dev (96d0b3c) will increase coverage by 1.20%.
The diff coverage is 96.27%.

@@            Coverage Diff             @@
##              dev     #187      +/-   ##
==========================================
+ Coverage   84.86%   86.07%   +1.20%     
==========================================
  Files          36       43       +7     
  Lines        2723     3045     +322     
==========================================
+ Hits         2311     2621     +310     
- Misses        335      343       +8     
- Partials       77       81       +4     
Impacted Files Coverage Δ
internal/merger/aggregatemerger/merger.go 92.15% <92.15%> (ø)
internal/merger/aggregatemerger/aggregator/avg.go 100.00% <100.00%> (ø)
...nternal/merger/aggregatemerger/aggregator/count.go 100.00% <100.00%> (ø)
internal/merger/aggregatemerger/aggregator/max.go 100.00% <100.00%> (ø)
internal/merger/aggregatemerger/aggregator/min.go 100.00% <100.00%> (ø)
internal/merger/aggregatemerger/aggregator/sum.go 100.00% <100.00%> (ø)
internal/merger/aggregatemerger/aggregator/type.go 100.00% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

script/setup.sh Show resolved Hide resolved
internal/merger/aggregatemerger/aggregator/avg.go Outdated Show resolved Hide resolved
internal/merger/aggregatemerger/aggregator/avg.go Outdated Show resolved Hide resolved
internal/merger/aggregatemerger/aggregator/max.go Outdated Show resolved Hide resolved
internal/merger/aggregatemerger/aggregator/min.go Outdated Show resolved Hide resolved
Copy link
Contributor

@flycash flycash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

明日再看看

internal/merger/aggregatemerger/aggregator/avg.go Outdated Show resolved Hide resolved
internal/merger/aggregatemerger/aggregator/avg.go Outdated Show resolved Hide resolved
internal/merger/aggregatemerger/aggregator/avg.go Outdated Show resolved Hide resolved
internal/merger/aggregatemerger/merger.go Show resolved Hide resolved
internal/merger/aggregatemerger/merger.go Outdated Show resolved Hide resolved
@flycash
Copy link
Contributor

flycash commented Apr 3, 2023

func TestColumnType(t *testing.T) {
	db, err := sql.Open("mysql", "root:root@tcp(localhost:13306)/integration_test")
	require.NoError(t, err)
	defer func() {
		db.Exec("DELETE FROM `order`")
		db.Exec("DELETE FROM `item`")
		db.Exec("DELETE FROM `order_detail`")
	}()
	o, err := eorm.Open("mysql", single.NewDB(db))
	require.NoError(t, err)
	initSql(o, t)
	rows, err := db.Query("SELECT * FROM `order` limit 1")
	require.NoError(t, err)
	types, err := rows.ColumnTypes()
	require.NoError(t, err)
	var vals []any
	for _, typ := range types {
		goType := typ.ScanType()
		zero := reflect.New(goType)
		vals = append(vals, zero.Interface())
	}
	rows.Next()
	err = rows.Scan(vals...)
	require.NoError(t, err)
	fmt.Println(vals)
}

确实可以拿到。但是我没有进一步考察,还要考虑一些数据库上奇怪的类型,尤其是 big int, big unsign int 之类的,在转为 Go 类型的时候会不会有问题。

internal/merger/aggregatemerger/aggregator/avg.go Outdated Show resolved Hide resolved
internal/merger/aggregatemerger/aggregator/avg.go Outdated Show resolved Hide resolved
internal/merger/aggregatemerger/aggregator/avg.go Outdated Show resolved Hide resolved
internal/merger/aggregatemerger/aggregator/avg.go Outdated Show resolved Hide resolved
internal/merger/aggregatemerger/aggregator/avg_test.go Outdated Show resolved Hide resolved
internal/merger/aggregatemerger/aggregator/avg.go Outdated Show resolved Hide resolved
internal/merger/aggregatemerger/aggregator/avg.go Outdated Show resolved Hide resolved
internal/merger/aggregatemerger/aggregator/count.go Outdated Show resolved Hide resolved
internal/merger/aggregatemerger/merger.go Outdated Show resolved Hide resolved
internal/merger/aggregatemerger/aggregator/avg.go Outdated Show resolved Hide resolved
internal/merger/aggregatemerger/aggregator/avg.go Outdated Show resolved Hide resolved
internal/merger/aggregatemerger/aggregator/count.go Outdated Show resolved Hide resolved
internal/merger/aggregatemerger/aggregator/max.go Outdated Show resolved Hide resolved
Copy link
Contributor

@flycash flycash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我注意到一个问题,在除了 Avg 以外的所有的聚合函数都要求传入一个 alias,我看上去有点多余。比如说在 ColInfo 里面已经有了一个 name,那么在我的设想里面,这个 name 代表的就是我们的列名,即是数据库返回的列名,也是我们在 rows.Columns 里面使用的列名。

那么:

SELECT SUM(age) FROM

ColInfo.name 应该是 SUM(age)
而:

SELECT SUM(age) as sum_age FROM

这个 ColInfo.Name 就是 sum_age。

在结果集处理层面上,应该没有 alias 这个概念的。

internal/merger/aggregatemerger/aggregator/avg.go Outdated Show resolved Hide resolved
internal/merger/aggregatemerger/aggregator/sum.go Outdated Show resolved Hide resolved
internal/merger/aggregatemerger/aggregator/avg.go Outdated Show resolved Hide resolved
internal/merger/aggregatemerger/aggregator/avg.go Outdated Show resolved Hide resolved
internal/merger/aggregatemerger/aggregator/count.go Outdated Show resolved Hide resolved
internal/merger/aggregatemerger/aggregator/max.go Outdated Show resolved Hide resolved
internal/merger/aggregatemerger/aggregator/min.go Outdated Show resolved Hide resolved
internal/merger/aggregatemerger/aggregator/min.go Outdated Show resolved Hide resolved
internal/merger/aggregatemerger/aggregator/sum.go Outdated Show resolved Hide resolved
internal/merger/aggregatemerger/aggregator/type.go Outdated Show resolved Hide resolved
internal/merger/aggregatemerger/aggregator/sum.go Outdated Show resolved Hide resolved
internal/merger/aggregatemerger/merger.go Outdated Show resolved Hide resolved
internal/merger/aggregatemerger/merger.go Outdated Show resolved Hide resolved
internal/merger/aggregatemerger/merger.go Outdated Show resolved Hide resolved
internal/merger/aggregatemerger/merger.go Outdated Show resolved Hide resolved
internal/merger/aggregatemerger/merger.go Outdated Show resolved Hide resolved
@flycash
Copy link
Contributor

flycash commented Apr 12, 2023

@juniaoshaonian deepsource 有一个小问题,你修复一下。
@longyue0521 确认没有问题之后你就可以合并了。

@longyue0521
Copy link
Collaborator

确认没有问题之后你就可以合并了。

OK

internal/merger/aggregatemerger/aggregator/avg.go Outdated Show resolved Hide resolved
internal/merger/aggregatemerger/aggregator/max.go Outdated Show resolved Hide resolved
internal/merger/aggregatemerger/merger.go Outdated Show resolved Hide resolved
internal/merger/aggregatemerger/merger.go Outdated Show resolved Hide resolved
internal/merger/aggregatemerger/merger.go Outdated Show resolved Hide resolved
internal/merger/aggregatemerger/merger_test.go Outdated Show resolved Hide resolved
internal/merger/aggregatemerger/merger_test.go Outdated Show resolved Hide resolved
internal/merger/aggregatemerger/merger_test.go Outdated Show resolved Hide resolved
internal/merger/aggregatemerger/merger_test.go Outdated Show resolved Hide resolved
internal/merger/aggregatemerger/merger.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@Stone-afk Stone-afk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mark

@longyue0521
Copy link
Collaborator

@juniaoshaonian golangci-lint 问题修复一下

@juniaoshaonian
Copy link
Collaborator Author

@juniaoshaonian golangci-lint 问题修复一下

奇怪了我就改了个变量名呀,昨天还可以的

@longyue0521 longyue0521 merged commit 7b1fd2b into ecodeclub:dev Apr 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants