Skip to content

Commit

Permalink
Merge pull request #4902 from zhang2014/fix/ISSUE-4891
Browse files Browse the repository at this point in the history
fixes(group): fix group by with negative value
  • Loading branch information
BohuTANG authored Apr 18, 2022
2 parents 031a87d + bb66d37 commit ec64439
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 3 deletions.
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

0 comments on commit ec64439

Please sign in to comment.