Skip to content

Commit

Permalink
[Enhancement] Convert the constant value to target type while making …
Browse files Browse the repository at this point in the history
…kudu predicate.

Signed-off-by: Song Jiacheng <[email protected]>
  • Loading branch information
Jcnessss committed Dec 13, 2024
1 parent 65e0b15 commit f067e1d
Showing 1 changed file with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

import com.google.common.collect.Lists;
import com.starrocks.analysis.BinaryType;
import com.starrocks.catalog.Type;
import com.starrocks.connector.ColumnTypeConverter;
import com.starrocks.sql.optimizer.operator.scalar.BinaryPredicateOperator;
import com.starrocks.sql.optimizer.operator.scalar.CastOperator;
import com.starrocks.sql.optimizer.operator.scalar.ColumnRefOperator;
Expand Down Expand Up @@ -103,7 +105,10 @@ public List<KuduPredicate> visitBinaryPredicate(BinaryPredicateOperator operator
if (columnName == null) {
return Lists.newArrayList();
}
Object literal = getLiteral(operator.getChild(1));
ColumnSchema column = schema.getColumn(columnName);
Type targetType = ColumnTypeConverter.fromKuduType(column);
Optional<ConstantOperator> casted = ((ConstantOperator) (operator.getChild(1))).castTo(targetType);
Object literal = getLiteral(casted.isPresent() ? casted.get() : operator.getChild(1));
if (literal == null) {
return Lists.newArrayList();
}
Expand Down Expand Up @@ -137,10 +142,15 @@ public List<KuduPredicate> visitInPredicate(InPredicateOperator operator, Void c
if (columnName == null) {
return Lists.newArrayList();
}
ColumnSchema column = schema.getColumn(columnName);
Type targetType = ColumnTypeConverter.fromKuduType(column);

List<ScalarOperator> valuesOperatorList = operator.getListChildren();
List<Optional<ConstantOperator>> casted =
valuesOperatorList.stream().map(x -> ((ConstantOperator) x).castTo(targetType)).collect(Collectors.toList());
List<Object> literalValues = new ArrayList<>(valuesOperatorList.size());
for (ScalarOperator valueOperator : valuesOperatorList) {
Object literal = getLiteral(valueOperator);
for (int i = 0; i < valuesOperatorList.size(); i++) {
Object literal = getLiteral(casted.get(i).isPresent() ? casted.get(i).get() : valuesOperatorList.get(i));
if (literal == null) {
return Lists.newArrayList();
}
Expand Down

0 comments on commit f067e1d

Please sign in to comment.