morrySnow commented on code in PR #24338:
URL: https://github.com/apache/doris/pull/24338#discussion_r1325810555
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalFileScan.java:
##########
@@ -157,3 +164,4 @@ public boolean equals(Object o) {
}
}
+
Review Comment:
remove this line
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/visitor/TableValuedFunctionVisitor.java:
##########
@@ -37,4 +38,8 @@ default R visitHdfs(Hdfs hdfs, C context) {
default R visitS3(S3 s3, C context) {
return visitTableValuedFunction(s3, context);
}
+
+ default R visitLocal(Local local, C context) {
Review Comment:
add in lexicographical order
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/table/Local.java:
##########
@@ -0,0 +1,67 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.nereids.trees.expressions.functions.table;
+
+import org.apache.doris.catalog.FunctionSignature;
+import org.apache.doris.nereids.exceptions.AnalysisException;
+import org.apache.doris.nereids.trees.expressions.Properties;
+import org.apache.doris.nereids.trees.expressions.Slot;
+import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
+import org.apache.doris.nereids.types.coercion.AnyDataType;
+import org.apache.doris.statistics.Statistics;
+import org.apache.doris.tablefunction.LocalTableValuedFunction;
+import org.apache.doris.tablefunction.TableValuedFunctionIf;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * local
+ */
+public class Local extends TableValuedFunction {
+ public Local(Properties properties) {
+ super("local", properties);
+ }
+
+ @Override
+ public FunctionSignature customSignature() {
+ return FunctionSignature.of(AnyDataType.INSTANCE_WITHOUT_INDEX, (List)
getArgumentsTypes());
Review Comment:
```suggestion
return FunctionSignature.of(AnyDataType.INSTANCE_WITHOUT_INDEX,
getArgumentsTypes());
```
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalFileScan.java:
##########
@@ -149,6 +149,13 @@ public SelectedPartitions(long totalPartitionNum,
Map<Long, PartitionItem> selec
}
}
+ /**
+ * Return true means this relation is partition prunned
+ */
+ public boolean isPartitionPruned() {
+ return this.totalPartitionNum > 0 || isPartitionPruned;
+ }
+
@Override
public boolean equals(Object o) {
Review Comment:
if override equals, hashCode also should be override
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalFileScan.java:
##########
@@ -149,6 +149,13 @@ public SelectedPartitions(long totalPartitionNum,
Map<Long, PartitionItem> selec
}
}
+ /**
+ * Return true means this relation is partition prunned
+ */
+ public boolean isPartitionPruned() {
+ return this.totalPartitionNum > 0 || isPartitionPruned;
Review Comment:
need to explain in comment why `this.totalPartitionNum > 0` means
isPartitionPruned
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/PruneFileScanPartition.java:
##########
@@ -55,22 +55,26 @@ public class PruneFileScanPartition extends
OneRewriteRuleFactory {
@Override
public Rule build() {
- return logicalFilter(logicalFileScan()).when(p ->
p.child().getSelectedPartitions() == null).thenApply(ctx -> {
- LogicalFilter<LogicalFileScan> filter = ctx.root;
- LogicalFileScan scan = filter.child();
- ExternalTable tbl = scan.getTable();
- SelectedPartitions selectedPartitions = new SelectedPartitions(0,
Maps.newHashMap(), false);
+ return logicalFilter(logicalFileScan()).when(p ->
!p.child().getSelectedPartitions().isPartitionPruned())
Review Comment:
```suggestion
return logicalFilter(logicalFileScan()).whenNot(p ->
p.child().getSelectedPartitions().isPartitionPruned())
```
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/PruneFileScanPartition.java:
##########
@@ -55,22 +55,26 @@ public class PruneFileScanPartition extends
OneRewriteRuleFactory {
@Override
public Rule build() {
- return logicalFilter(logicalFileScan()).when(p ->
p.child().getSelectedPartitions() == null).thenApply(ctx -> {
- LogicalFilter<LogicalFileScan> filter = ctx.root;
- LogicalFileScan scan = filter.child();
- ExternalTable tbl = scan.getTable();
- SelectedPartitions selectedPartitions = new SelectedPartitions(0,
Maps.newHashMap(), false);
+ return logicalFilter(logicalFileScan()).when(p ->
!p.child().getSelectedPartitions().isPartitionPruned())
+ .thenApply(ctx -> {
+ LogicalFilter<LogicalFileScan> filter = ctx.root;
+ LogicalFileScan scan = filter.child();
+ ExternalTable tbl = scan.getTable();
+ SelectedPartitions selectedPartitions = new
SelectedPartitions(0, Maps.newHashMap(), false);
Review Comment:
all class used in Nereids plan stage, should be immutable. so u should use
`ImmutableMap.of()` instead of `Maps.newHashMap()`. And use
`ImmutableMap.copy()` in `SelectedPartitions`'s constructor. BTW u should check
all parameters non-null by `Objects.requireNonNull(param, msg)` in
`SelectedPartitions`'s constructor too.
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/stats/ExpressionEstimation.java:
##########
@@ -162,9 +162,12 @@ public ColumnStatistic visitCast(Cast cast, Statistics
context) {
if (stats != null) {
return stats;
}
- ColumnStatistic childColStats = cast.child().accept(this, context);
-
- return castMinMax(childColStats, cast.getDataType());
+ stats = cast.child().accept(this, context);
+ if (stats != null) {
+ return castMinMax(stats, cast.getDataType());
+ }
+ // Some column may not have column stats, eg, column in tvf
+ return ColumnStatistic.UNKNOWN;
Review Comment:
u should let all column return stats, at least return unknown
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalFileScan.java:
##########
@@ -149,6 +149,13 @@ public SelectedPartitions(long totalPartitionNum,
Map<Long, PartitionItem> selec
}
}
+ /**
+ * Return true means this relation is partition prunned
+ */
+ public boolean isPartitionPruned() {
+ return this.totalPartitionNum > 0 || isPartitionPruned;
+ }
+
@Override
public boolean equals(Object o) {
return isPartitionPruned == ((SelectedPartitions)
o).isPartitionPruned && Objects.equals(
Review Comment:
this equals is very dangerous. It should check the class of its parameter
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/table/Local.java:
##########
@@ -0,0 +1,67 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.nereids.trees.expressions.functions.table;
+
+import org.apache.doris.catalog.FunctionSignature;
+import org.apache.doris.nereids.exceptions.AnalysisException;
+import org.apache.doris.nereids.trees.expressions.Properties;
+import org.apache.doris.nereids.trees.expressions.Slot;
+import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
+import org.apache.doris.nereids.types.coercion.AnyDataType;
+import org.apache.doris.statistics.Statistics;
+import org.apache.doris.tablefunction.LocalTableValuedFunction;
+import org.apache.doris.tablefunction.TableValuedFunctionIf;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * local
+ */
+public class Local extends TableValuedFunction {
+ public Local(Properties properties) {
+ super("local", properties);
+ }
+
+ @Override
+ public FunctionSignature customSignature() {
+ return FunctionSignature.of(AnyDataType.INSTANCE_WITHOUT_INDEX, (List)
getArgumentsTypes());
+ }
+
+ @Override
+ protected TableValuedFunctionIf toCatalogFunction() {
+ try {
+ Map<String, String> arguments = getTVFProperties().getMap();
+ return new LocalTableValuedFunction(arguments);
+ } catch (Throwable t) {
+ throw new AnalysisException("Can not build
LocalTableValuedFunction by "
+ + this + ": " + t.getMessage(), t);
+ }
+ }
+
+ @Override
+ public Statistics computeStats(List<Slot> slots) {
+ return new Statistics(0, new HashMap<>());
Review Comment:
u could call `getTableColumns` to get column list, and then generate
columnStatistic for all column
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]