Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix](source) fix projection and function pushdown not functioning correctly #383

Merged
merged 11 commits into from
May 11, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,6 @@ public ScanRuntimeProvider getScanRuntimeProvider(ScanContext runtimeProviderCon
String filterQuery = resolvedFilterQuery.stream().collect(Collectors.joining(" AND "));
readOptions.setFilterQuery(filterQuery);
}
if (StringUtils.isNullOrWhitespaceOnly(readOptions.getReadFields())) {
String[] selectFields =
DataType.getFieldNames(physicalRowDataType).toArray(new String[0]);
readOptions.setReadFields(
Arrays.stream(selectFields)
.map(item -> String.format("`%s`", item.trim().replace("`", "")))
.collect(Collectors.joining(", ")));
}

if (readOptions.getUseOldApi()) {
List<PartitionDefinition> dorisPartitions;
try {
Expand Down Expand Up @@ -194,7 +185,8 @@ public Result applyFilters(List<ResolvedExpression> filters) {
DorisExpressionVisitor expressionVisitor = new DorisExpressionVisitor();
for (ResolvedExpression filter : filters) {
String filterQuery = filter.accept(expressionVisitor);
if (!StringUtils.isNullOrWhitespaceOnly(filterQuery)) {
if (StringUtils.isNullOrWhitespaceOnly(filterQuery)
&& !StringUtils.isNullOrWhitespaceOnly(filterQuery)) {
vinlee19 marked this conversation as resolved.
Show resolved Hide resolved
acceptedFilters.add(filter);
this.resolvedFilterQuery.add(filterQuery);
} else {
Expand All @@ -212,5 +204,13 @@ public boolean supportsNestedProjection() {
@Override
public void applyProjection(int[][] projectedFields, DataType producedDataType) {
this.physicalRowDataType = Projection.of(projectedFields).project(physicalRowDataType);
if (StringUtils.isNullOrWhitespaceOnly(readOptions.getReadFields())) {
String[] selectFields =
DataType.getFieldNames(physicalRowDataType).toArray(new String[0]);
this.readOptions.setReadFields(
Arrays.stream(selectFields)
.map(item -> String.format("`%s`", item.trim().replace("`", "")))
.collect(Collectors.joining(", ")));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.apache.flink.table.expressions.ValueLiteralExpression;
import org.apache.flink.table.functions.BuiltInFunctionDefinitions;
import org.apache.flink.table.types.logical.LogicalTypeRoot;
import org.apache.flink.util.StringUtils;

import java.util.List;

Expand Down Expand Up @@ -66,12 +67,22 @@ public String visit(CallExpression call) {
if (BuiltInFunctionDefinitions.IS_NOT_NULL.equals(call.getFunctionDefinition())) {
return combineLeftExpression("IS NOT NULL", call.getResolvedChildren().get(0));
}

if (BuiltInFunctionDefinitions.CAST.equals(call.getFunctionDefinition())) {
return call.getChildren().get(0).accept(this);
}
return null;
}

private String combineExpression(String operator, List<ResolvedExpression> operand) {
String left = operand.get(0).accept(this);
if (StringUtils.isNullOrWhitespaceOnly(left)) {
return null;
}
String right = operand.get(1).accept(this);
if (StringUtils.isNullOrWhitespaceOnly(right)) {
return null;
}
return String.format("(%s %s %s)", left, operator, right);
}

Expand Down
Loading