Skip to content

Commit

Permalink
Probihit the cast from HLL to VARCHAR (StarRocks#3088)
Browse files Browse the repository at this point in the history
HLL to VARCHAR is not supported and the cast will crash
```
CREATE TABLE `doris_test` (
  `id` int(11) NULL COMMENT "id",
  `name` varchar(40) NULL COMMENT "名称"
) ENGINE=OLAP
DUPLICATE KEY(`id`)
COMMENT "OLAP"
DISTRIBUTED BY HASH(`id`) BUCKETS 1
PROPERTIES (
"replication_num" = "1",
"in_memory" = "false",
"storage_format" = "V2"
);

curl --location-trusted -u "root:" -H "columns:id, name=hll_hash(id)"
```
  • Loading branch information
chaoyli authored Jan 26, 2022
1 parent 82bca93 commit 0d56a15
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 61 deletions.
166 changes: 107 additions & 59 deletions be/test/exprs/vectorized/math_functions_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,31 +368,40 @@ TEST_F(VecMathFunctionsTest, Conv_intTest) {
auto tc2 = Int8Column::create();
auto tc3 = Int8Column::create();

int64_t bigints[] = {1, 2, 35,
10, 10, 10, 10, 3, 3,
99999999, 99999999, 99999999, 99999999,
-99999999, -99999999, -99999999, -99999999,
4294967296,4294967296,4294967296,4294967296,
-4294967296,-4294967296,-4294967296,-4294967296};
int8_t baseints[] = {10, 10, 10,
2, 2, -2, -2, -2, -2,
-16, -16, 16, 16,
-16, -16, 16, 16,
-16, -16, 16, 16,
-16, -16, -16, -16};
int8_t destints[] = {10, 16, 36,
10, -10, 10, -10, 10, 10,
10, -10, 10, -10,
10, -10, 10, -10,
10, -10, 10, -10,
10, -10, 10, -10};

std::string results[] = {"1", "2", "Z",
"2", "2", "2", "2", "0", "0",
"2576980377", "2576980377", "2576980377", "2576980377",
"18446744071132571239", "-2576980377", "18446744071132571239", "-2576980377",
"285960729238", "285960729238", "285960729238", "285960729238",
"18446743787748822378", "-285960729238", "18446743787748822378", "-285960729238"};
int64_t bigints[] = {1, 2, 35, 10, 10, 10, 10,
3, 3, 99999999, 99999999, 99999999, 99999999, -99999999,
-99999999, -99999999, -99999999, 4294967296, 4294967296, 4294967296, 4294967296,
-4294967296, -4294967296, -4294967296, -4294967296};
int8_t baseints[] = {10, 10, 10, 2, 2, -2, -2, -2, -2, -16, -16, 16, 16,
-16, -16, 16, 16, -16, -16, 16, 16, -16, -16, -16, -16};
int8_t destints[] = {10, 16, 36, 10, -10, 10, -10, 10, 10, 10, -10, 10, -10,
10, -10, 10, -10, 10, -10, 10, -10, 10, -10, 10, -10};

std::string results[] = {"1",
"2",
"Z",
"2",
"2",
"2",
"2",
"0",
"0",
"2576980377",
"2576980377",
"2576980377",
"2576980377",
"18446744071132571239",
"-2576980377",
"18446744071132571239",
"-2576980377",
"285960729238",
"285960729238",
"285960729238",
"285960729238",
"18446743787748822378",
"-285960729238",
"18446743787748822378",
"-285960729238"};

for (int i = 0; i < sizeof(bigints) / sizeof(bigints[0]); ++i) {
tc1->append(bigints[i]);
Expand Down Expand Up @@ -423,40 +432,79 @@ TEST_F(VecMathFunctionsTest, Conv_stringTest) {
auto tc2 = Int8Column::create();
auto tc3 = Int8Column::create();

std::string bigints[] = {"1", "2", "35", "1000", "103", "114", "18446744073709551617",
"10", "10", "10", "10",
"-9223372036854775808", "-9223372036854775808", "-9223372036854775808", "-9223372036854775808",
"9223372036854775808", "9223372036854775808", "9223372036854775808", "9223372036854775808",
"-9223372036854775809", "-9223372036854775809", "-9223372036854775809", "-9223372036854775809",
"18446744073709551616", "18446744073709551616", "18446744073709551616", "18446744073709551616",
"-18446744073709551616", "-18446744073709551616", "-18446744073709551616", "-18446744073709551616",
"de0b6b3a7640000", "8ac7230489e80000", "a"
};
int8_t baseints[] = {10, 10, 10, 8, 35, 35, 10,
-2, -2, 2, 2,
-10, -10, 10, 10,
-10, -10, 10, 10,
-10, -10, 10, 10,
-10, -10, 10, 10,
-10, -10, 10, 10,
16, 16, 10};
int8_t destints[] = {10, 16, 36, 10, 10, 10, 10,
10, -10, 10, -10,
10, -10, 10, -10,
10, -10, 10, -10,
10, -10, 10, -10,
10, -10, 10, -10,
10, -10, 10, -10,
10, 10, 10};

std::string results[] = {"1", "2", "Z", "512", "1228", "1264", "18446744073709551615",
"2", "2", "2", "2",
"9223372036854775808", "-9223372036854775808", "9223372036854775808", "-9223372036854775808",
"9223372036854775807", "9223372036854775807", "9223372036854775808", "-9223372036854775808",
"9223372036854775808", "-9223372036854775808", "9223372036854775807", "9223372036854775807",
"9223372036854775807", "9223372036854775807", "18446744073709551615", "-1",
"9223372036854775808", "-9223372036854775808", "0", "0",
"1000000000000000000", "10000000000000000000", "0"};
std::string bigints[] = {"1",
"2",
"35",
"1000",
"103",
"114",
"18446744073709551617",
"10",
"10",
"10",
"10",
"-9223372036854775808",
"-9223372036854775808",
"-9223372036854775808",
"-9223372036854775808",
"9223372036854775808",
"9223372036854775808",
"9223372036854775808",
"9223372036854775808",
"-9223372036854775809",
"-9223372036854775809",
"-9223372036854775809",
"-9223372036854775809",
"18446744073709551616",
"18446744073709551616",
"18446744073709551616",
"18446744073709551616",
"-18446744073709551616",
"-18446744073709551616",
"-18446744073709551616",
"-18446744073709551616",
"de0b6b3a7640000",
"8ac7230489e80000",
"a"};
int8_t baseints[] = {10, 10, 10, 8, 35, 35, 10, -2, -2, 2, 2, -10, -10, 10, 10, -10, -10,
10, 10, -10, -10, 10, 10, -10, -10, 10, 10, -10, -10, 10, 10, 16, 16, 10};
int8_t destints[] = {10, 16, 36, 10, 10, 10, 10, 10, -10, 10, -10, 10, -10, 10, -10, 10, -10,
10, -10, 10, -10, 10, -10, 10, -10, 10, -10, 10, -10, 10, -10, 10, 10, 10};

std::string results[] = {"1",
"2",
"Z",
"512",
"1228",
"1264",
"18446744073709551615",
"2",
"2",
"2",
"2",
"9223372036854775808",
"-9223372036854775808",
"9223372036854775808",
"-9223372036854775808",
"9223372036854775807",
"9223372036854775807",
"9223372036854775808",
"-9223372036854775808",
"9223372036854775808",
"-9223372036854775808",
"9223372036854775807",
"9223372036854775807",
"9223372036854775807",
"9223372036854775807",
"18446744073709551615",
"-1",
"9223372036854775808",
"-9223372036854775808",
"0",
"0",
"1000000000000000000",
"10000000000000000000",
"0"};

for (int i = 0; i < sizeof(bigints) / sizeof(bigints[0]); ++i) {
tc1->append(bigints[i]);
Expand Down
3 changes: 1 addition & 2 deletions fe/fe-core/src/main/java/com/starrocks/analysis/Expr.java
Original file line number Diff line number Diff line change
Expand Up @@ -1233,8 +1233,7 @@ public final Expr castTo(Type targetType) throws AnalysisException {
return this;
}

if ((targetType.isStringType() || targetType.isHllType())
&& (this.type.isStringType() || this.type.isHllType())) {
if (targetType.isHllType() && this.type.isStringType()) {
return this;
}
if (!Type.canCastTo(this.type, targetType)) {
Expand Down

0 comments on commit 0d56a15

Please sign in to comment.