-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
aggfuncs: implement bit-or with new aggregation framework #6975
Changes from 4 commits
6b7ecfe
ced83db
5f59da3
742a5ff
da9bfd1
d826d6b
0b00dc8
836aafd
cd51cdb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright 2018 PingCAP, Inc. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rename the filename as func_bitfuncs.go |
||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package aggfuncs | ||
|
||
import ( | ||
"github.com/juju/errors" | ||
"github.com/pingcap/tidb/sessionctx" | ||
"github.com/pingcap/tidb/util/chunk" | ||
) | ||
|
||
type baseBitAggFunc struct { | ||
baseAggFunc | ||
} | ||
|
||
type bitOrUint64 struct { | ||
baseBitAggFunc | ||
} | ||
|
||
type partialResult4BitFunc = uint64 | ||
|
||
func (e *bitOrUint64) AllocPartialResult() PartialResult { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be a member function of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. great suggestion. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ...I take back the last sentence. 😂 |
||
return PartialResult(new(partialResult4BitFunc)) | ||
} | ||
|
||
func (e *bitOrUint64) ResetPartialResult(pr PartialResult) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
p := (*partialResult4BitFunc)(pr) | ||
*p = 0 | ||
} | ||
|
||
func (e *bitOrUint64) AppendFinalResult2Chunk(sctx sessionctx.Context, pr PartialResult, chk *chunk.Chunk) error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
p := (*partialResult4BitFunc)(pr) | ||
chk.AppendUint64(e.ordinal, *p) | ||
return nil | ||
} | ||
|
||
func (e *bitOrUint64) UpdatePartialResult(sctx sessionctx.Context, rowsInGroup []chunk.Row, pr PartialResult) error { | ||
p := (*partialResult4BitFunc)(pr) | ||
for _, row := range rowsInGroup { | ||
inputValue, isNull, err := e.args[0].EvalInt(sctx, row) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we wrap a cast as uint in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bit_or( varchar ) will return 0. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. actually, we need to add a cast, consider this case: drop table if exists t;
create table t(a decimal(10, 4));
insert into t values(12.2);
select bit_or(a) from (select * from t union all select * from t) tmp; TiDB(localhost:4000) > desc select bit_or(a) from (select * from t union all select * from t) tmp;
+--------------------------+------+----------------------------------------------+----------+
| id | task | operator info | count |
+--------------------------+------+----------------------------------------------+----------+
| StreamAgg_13 | root | funcs:bit_or(tmp.a) | 1.00 |
| └─Union_21 | root | | 20000.00 |
| ├─TableReader_24 | root | data:TableScan_23 | 10000.00 |
| │ └─TableScan_23 | cop | table:t, range:[-inf,+inf], keep order:false | 10000.00 |
| └─TableReader_27 | root | data:TableScan_26 | 10000.00 |
| └─TableScan_26 | cop | table:t, range:[-inf,+inf], keep order:false | 10000.00 |
+--------------------------+------+----------------------------------------------+----------+
6 rows in set (0.00 sec) The above There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ye, I'll fix it |
||
if err != nil { | ||
return errors.Trace(err) | ||
} | ||
if isNull { | ||
continue | ||
} | ||
*p |= uint64(inputValue) | ||
} | ||
return nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to handle the function which has the
distinct
property.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why bit-or need to care
distinct
property?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consider this query:
select bit_or(distinct a) from t;
we only calculate the distinct values of columna
in this kind of query.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't matter, because
bit_or(distinct a) = bit_or(a)
,bit_and
same too, exceptbit_xor
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add a comment here to statement that function
bitor
no need to consider thedistinct
propertyThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done