[opt](Nereids) support where, group by, having, order by clause without from clause in query statement (#27006)

Support where, group by, having, order by clause without from clause in query statement.
For example as following:

SELECT 1 AS a, COUNT(), SUM(2), AVG(1), RANK() OVER() AS w_rank
WHERE 1 = 1
GROUP BY a, w_rank
HAVING COUNT() IN (1, 2) AND w_rank = 1
ORDER BY a;

this will return result:

| a  |count(*)|sum(2)|avg(1)|w_rank|
+----+--------+------+------+------+
| 1  |       1|     2|   1.0|     1|


For another example as following:

select 1 c1, 2 union (select "hell0", "") order by c1
the second column datatype will be varchar(65533), 65533 is the default varchar length.

this will return result:

|c1    | 2 |
+------+---+
|1     | 2 |
|hell0 |   |
This commit is contained in:
seawinde
2023-11-27 12:05:14 +08:00
committed by GitHub
parent 331effdb20
commit 1b4cd24b36
17 changed files with 94 additions and 30 deletions

View File

@ -1060,7 +1060,13 @@ public class ScalarType extends Type {
if (t1.type == PrimitiveType.STRING || t2.type == PrimitiveType.STRING) {
return createStringType();
}
return createVarcharType(Math.max(t1.len, t2.len));
int minLength = Math.min(t1.len, t2.len);
if (minLength < 0) {
// If < 0 which means max length, use firstly
return createVarcharType(minLength);
}
int length = Math.max(t1.len, t2.len);
return createVarcharType(length == 0 ? MAX_VARCHAR_LENGTH : length);
}
if (((t1.isDecimalV3() || t1.isDecimalV2()) && (t2.isDateV2() || t2.isDate()))