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

fixes(group): fix group by with negative value #4902

Merged
merged 6 commits into from
Apr 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ pub trait PolymorphicKeysHelper<Method: HashMethod> {
impl PolymorphicKeysHelper<HashMethodKeysU8> for HashMethodKeysU8 {
type State = ShortFixedKeysAggregatorState<u8>;
fn aggregate_state(&self) -> Self::State {
Self::State::create(u8::MAX as usize)
Self::State::create((u8::MAX as usize) + 1)
}

type ColumnBuilder = FixedKeysColumnBuilder<u8>;
Expand Down Expand Up @@ -125,7 +125,7 @@ impl PolymorphicKeysHelper<HashMethodKeysU8> for HashMethodKeysU8 {
impl PolymorphicKeysHelper<HashMethodKeysU16> for HashMethodKeysU16 {
type State = ShortFixedKeysAggregatorState<u16>;
fn aggregate_state(&self) -> Self::State {
Self::State::create(u16::MAX as usize)
Self::State::create((u16::MAX as usize) + 1)
}

type ColumnBuilder = FixedKeysColumnBuilder<u16>;
Expand Down
23 changes: 23 additions & 0 deletions tests/suites/0_stateless/03_dml/03_0020_group_by_negative.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
0
-1
-127
-128
256
127
0
-1
-32768
65535
32766
0
-1
-32768
-32769
65535
0
0
-1
-32768
-32769
65535
0
27 changes: 27 additions & 0 deletions tests/suites/0_stateless/03_dml/03_0020_group_by_negative.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
SELECT (0 - number) :: Int8 AS c FROM numbers(256) GROUP BY c HAVING c = 0;
SELECT (0 - number) :: Int8 AS c FROM numbers(256) GROUP BY c HAVING c = -1;
SELECT (0 - number) :: Int8 AS c FROM numbers(256) GROUP BY c HAVING c = -127;
SELECT (0 - number) :: Int8 AS c FROM numbers(256) GROUP BY c HAVING c = -128;
SELECT COUNT() FROM (SELECT (0 - number) :: Int8 AS c FROM numbers(256) GROUP BY c);
SELECT COUNT() FROM (SELECT (0 - number) :: Int8 AS c FROM numbers(256) GROUP BY c HAVING c > 0);

SELECT (0 - number) :: Int16 AS c FROM numbers(65535) GROUP BY c HAVING c = 0;
SELECT (0 - number) :: Int16 AS c FROM numbers(65535) GROUP BY c HAVING c = -1;
SELECT (0 - number) :: Int16 AS c FROM numbers(65535) GROUP BY c HAVING c = -32768;
SELECT (0 - number) :: Int16 AS c FROM numbers(65535) GROUP BY c HAVING c = -32769;
SELECT COUNT() FROM (SELECT (0 - number) :: Int16 AS c FROM numbers(65535) GROUP BY c);
SELECT COUNT() FROM (SELECT (0 - number) :: Int16 AS c FROM numbers(65535) GROUP BY c HAVING c > 0);

SELECT (0 - number) :: Int32 AS c FROM numbers(65535) GROUP BY c HAVING c = 0;
SELECT (0 - number) :: Int32 AS c FROM numbers(65535) GROUP BY c HAVING c = -1;
SELECT (0 - number) :: Int32 AS c FROM numbers(65535) GROUP BY c HAVING c = -32768;
SELECT (0 - number) :: Int32 AS c FROM numbers(65535) GROUP BY c HAVING c = -32769;
SELECT COUNT() FROM (SELECT (0 - number) :: Int32 AS c FROM numbers(65535) GROUP BY c);
SELECT COUNT() FROM (SELECT (0 - number) :: Int32 AS c FROM numbers(65535) GROUP BY c HAVING c > 0);

SELECT (0 - number) :: Int64 AS c FROM numbers(65535) GROUP BY c HAVING c = 0;
SELECT (0 - number) :: Int64 AS c FROM numbers(65535) GROUP BY c HAVING c = -1;
SELECT (0 - number) :: Int64 AS c FROM numbers(65535) GROUP BY c HAVING c = -32768;
SELECT (0 - number) :: Int64 AS c FROM numbers(65535) GROUP BY c HAVING c = -32769;
SELECT COUNT() FROM (SELECT (0 - number) :: Int64 AS c FROM numbers(65535) GROUP BY c);
SELECT COUNT() FROM (SELECT (0 - number) :: Int64 AS c FROM numbers(65535) GROUP BY c HAVING c > 0);
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
-1 255
-1
127 255
-128 0
1 change: 0 additions & 1 deletion tools/fuzz/fuzz_targets/fuzz_parse_sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use databend_query::sessions::Session;
use databend_query::sessions::SessionType;
use databend_query::sql::DfParser;
use honggfuzz::fuzz;
Expand Down