Skip to content

Commit a49fd96

Browse files
shanxuechengXuecheng Shan
andauthored
KE-44971 merge KE4 to KE5 (#366)
* AL-10159 fix function params type match (#361) Co-authored-by: Xuecheng Shan <xuecheng.shan@kyligence.io> * AL-10200 fix 'order by xxx limit 0' (#362) Co-authored-by: Xuecheng Shan <xuecheng.shan@kyligence.io> --------- Co-authored-by: Xuecheng Shan <xuecheng.shan@kyligence.io>
1 parent 6eae2f4 commit a49fd96

File tree

4 files changed

+34
-9
lines changed

4 files changed

+34
-9
lines changed

core/src/main/java/org/apache/calcite/sql/type/SqlTypeExplicitPrecedenceList.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,23 +138,31 @@ private static SqlTypeExplicitPrecedenceList numeric(SqlTypeName typeName) {
138138

139139
// implement RelDataTypePrecedenceList
140140
@Override public int compareTypePrecedence(RelDataType type1, RelDataType type2) {
141-
assert containsType(type1) : type1;
142-
assert containsType(type2) : type2;
141+
if (SqlTypeName.ANY != type1.getSqlTypeName()) {
142+
assert containsType(type1) : type1;
143+
}
144+
if (SqlTypeName.ANY != type2.getSqlTypeName()) {
145+
assert containsType(type2) : type2;
146+
}
143147

144148
int p1 =
145149
getListPosition(
146150
type1.getSqlTypeName(),
147151
typeNames);
152+
p1 = (p1 == -1) ? Integer.MAX_VALUE : p1;
148153
int p2 =
149154
getListPosition(
150155
type2.getSqlTypeName(),
151156
typeNames);
157+
p2 = (p2 == -1) ? Integer.MAX_VALUE : p2;
152158
return p2 - p1;
153159
}
154160

155161
private static int getListPosition(SqlTypeName type, List<SqlTypeName> list) {
156162
int i = list.indexOf(type);
157-
assert i != -1;
163+
if (SqlTypeName.ANY != type) {
164+
assert i != -1;
165+
}
158166
return i;
159167
}
160168

core/src/main/java/org/apache/calcite/sql2rel/RelFieldTrimmer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ public TrimResult trimFields(
661661
sort.fetch == null ? -1 : RexLiteral.intValue(sort.fetch);
662662
final ImmutableList<RexNode> fields =
663663
relBuilder.fields(RexUtil.apply(inputMapping, collation));
664-
relBuilder.sortLimit(offset, fetch, fields);
664+
relBuilder.sortLimit(sort.getTraitSet(), offset, fetch, fields);
665665

666666
// The result has the same mapping as the input gave us. Sometimes we
667667
// return fields that the consumer didn't ask for, because the filter

core/src/main/java/org/apache/calcite/tools/RelBuilder.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.apache.calcite.plan.RelOptSchema;
2727
import org.apache.calcite.plan.RelOptTable;
2828
import org.apache.calcite.plan.RelOptUtil;
29+
import org.apache.calcite.plan.RelTraitSet;
2930
import org.apache.calcite.plan.ViewExpanders;
3031
import org.apache.calcite.prepare.RelOptTableImpl;
3132
import org.apache.calcite.rel.RelCollation;
@@ -3050,15 +3051,25 @@ private static boolean allNull(@Nullable Object[] values, int column, int column
30503051
* create a relation expression that retains the input, just to read its
30513052
* schema.
30523053
*/
3053-
public RelBuilder empty() {
3054+
public RelBuilder empty(RelTraitSet sortTraits) {
30543055
final Frame frame = stack.pop();
3055-
final RelNode values =
3056+
RelNode values =
30563057
struct.valuesFactory.createValues(cluster, frame.rel.getRowType(),
30573058
ImmutableList.of());
3059+
if (null != sortTraits) {
3060+
if (values.getConvention() != null) {
3061+
sortTraits = sortTraits.replace(values.getConvention());
3062+
}
3063+
values = values.copy(sortTraits, values.getInputs());
3064+
}
30583065
stack.push(new Frame(values, frame.fields));
30593066
return this;
30603067
}
30613068

3069+
public RelBuilder empty() {
3070+
return empty(null);
3071+
}
3072+
30623073
/** Creates a {@link Values} with a specified row type.
30633074
*
30643075
* <p>This method can handle cases that {@link #values(String[], Object...)}
@@ -3190,11 +3201,12 @@ public RelBuilder sort(RelCollation collation) {
31903201

31913202
/** Creates a {@link Sort} by a list of expressions, with limit and offset.
31923203
*
3204+
* @param sortTraits traits of Sort
31933205
* @param offset Number of rows to skip; non-positive means don't skip any
31943206
* @param fetch Maximum number of rows to fetch; negative means no limit
31953207
* @param nodes Sort expressions
31963208
*/
3197-
public RelBuilder sortLimit(int offset, int fetch,
3209+
public RelBuilder sortLimit(RelTraitSet sortTraits, int offset, int fetch,
31983210
Iterable<? extends RexNode> nodes) {
31993211
final Registrar registrar = new Registrar(fields(), ImmutableList.of());
32003212
final List<RelFieldCollation> fieldCollations =
@@ -3203,7 +3215,7 @@ public RelBuilder sortLimit(int offset, int fetch,
32033215
final RexNode offsetNode = offset <= 0 ? null : literal(offset);
32043216
final RexNode fetchNode = fetch < 0 ? null : literal(fetch);
32053217
if (offsetNode == null && fetch == 0 && config.simplifyLimit()) {
3206-
return empty();
3218+
return empty(sortTraits);
32073219
}
32083220
if (offsetNode == null && fetchNode == null && fieldCollations.isEmpty()) {
32093221
return this; // sort is trivial
@@ -3254,6 +3266,11 @@ public RelBuilder sortLimit(int offset, int fetch,
32543266
return this;
32553267
}
32563268

3269+
public RelBuilder sortLimit(int offset, int fetch,
3270+
Iterable<? extends RexNode> nodes) {
3271+
return sortLimit(null, offset, fetch, nodes);
3272+
}
3273+
32573274
private static RelFieldCollation collation(RexNode node,
32583275
RelFieldCollation.Direction direction,
32593276
RelFieldCollation.@Nullable NullDirection nullDirection,

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ systemProp.org.gradle.internal.publish.checksums.insecure=true
2727
# This is version for Calcite itself
2828
# Note: it should not include "-SNAPSHOT" as it is automatically added by build.gradle.kts
2929
# Release version can be generated by using -Prelease or -Prc=<int> arguments
30-
calcite.version=1.30.0-kylin-5.x-r3
30+
calcite.version=1.30.0-kylin-5.x-r4
3131
# This is a version to be used from Maven repository. It can be overridden by localAvatica below
3232
calcite.avatica.version=1.22.0
3333

0 commit comments

Comments
 (0)