morningman commented on a change in pull request #7940:
URL: https://github.com/apache/incubator-doris/pull/7940#discussion_r812512608



##########
File path: gensrc/thrift/PlanNodes.thrift
##########
@@ -741,6 +742,11 @@ struct TRuntimeFilterDesc {
   9: optional i64 bloom_filter_size_bytes
 }
 
+struct TNumbersScanNode {
+       1: optional Types.TTupleId tuple_id

Review comment:
       tab to space

##########
File path: 
fe/fe-core/src/main/java/org/apache/doris/tablefunction/TableValuedFunctionInf.java
##########
@@ -0,0 +1,50 @@
+// 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.tablefunction;
+
+import org.apache.doris.analysis.TupleDescriptor;
+import org.apache.doris.catalog.Column;
+import org.apache.doris.catalog.Table;
+import org.apache.doris.catalog.Table.TableType;
+import org.apache.doris.common.UserException;
+import org.apache.doris.planner.PlanNodeId;
+import org.apache.doris.planner.ScanNode;
+
+import java.util.List;
+
+public abstract class TableValuedFunctionInf {
+
+    public abstract String getTableName();
+
+    public abstract List<Column> getTableColumns();
+       
+    public abstract ScanNode getScanNode(PlanNodeId id, TupleDescriptor desc);
+
+    public Table getTable() {
+        Table table = new Table(-1, getTableName(), 
TableType.TABLE_VALUED_FUNCTION, getTableColumns());
+        return table;
+    }
+
+    // All table functions should be registered here
+    public static TableValuedFunctionInf getTableFunction(String funcName, 
List<String> params) throws UserException {
+        if (funcName.equalsIgnoreCase(NumbersTableValuedFunction.NAME)) {
+            return new NumbersTableValuedFunction(params);
+        }
+        throw new UserException("Could not find table function " + funcName);
+       }

Review comment:
       format

##########
File path: 
fe/fe-core/src/main/java/org/apache/doris/tablefunction/TableValuedFunctionInf.java
##########
@@ -0,0 +1,50 @@
+// 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.tablefunction;
+
+import org.apache.doris.analysis.TupleDescriptor;
+import org.apache.doris.catalog.Column;
+import org.apache.doris.catalog.Table;
+import org.apache.doris.catalog.Table.TableType;
+import org.apache.doris.common.UserException;
+import org.apache.doris.planner.PlanNodeId;
+import org.apache.doris.planner.ScanNode;
+
+import java.util.List;
+
+public abstract class TableValuedFunctionInf {

Review comment:
       ```suggestion
   public abstract class TableValuedFunctionI {
   ```

##########
File path: fe/fe-core/src/main/cup/sql_parser.cup
##########
@@ -4160,6 +4161,17 @@ table_ref ::=
     s.setLateralViewRefs(lateralViewRefList);
     RESULT = s;
   :}
+  | table_valued_function_ref:f
+  {:
+       RESULT = f;

Review comment:
       tab to space

##########
File path: 
fe/fe-core/src/main/java/org/apache/doris/tablefunction/NumbersTableValuedFunction.java
##########
@@ -0,0 +1,69 @@
+// 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.tablefunction;
+
+import org.apache.doris.analysis.TupleDescriptor;
+import org.apache.doris.catalog.Column;
+import org.apache.doris.catalog.PrimitiveType;
+import org.apache.doris.common.UserException;
+import org.apache.doris.planner.PlanNodeId;
+import org.apache.doris.planner.ScanNode;
+
+import java.util.ArrayList;
+import java.util.List;
+
+// Table function that generate int64 numbers
+// have a single column number
+public class NumbersTableValuedFunction extends TableValuedFunctionInf {
+
+    public static final String NAME = "numbers";
+
+    private static final String SCANNODE_NAME = "NUMBERS";
+

Review comment:
       Add more comment to explain what is `totalNumbers` and `tabletsNum`

##########
File path: 
fe/fe-core/src/main/java/org/apache/doris/tablefunction/NumbersTableValuedFunctionScanNode.java
##########
@@ -0,0 +1,134 @@
+// 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.tablefunction;
+
+import org.apache.doris.analysis.Analyzer;
+import org.apache.doris.analysis.TupleDescriptor;
+import org.apache.doris.catalog.Catalog;
+import org.apache.doris.common.AnalysisException;
+import org.apache.doris.common.UserException;
+import org.apache.doris.planner.PlanNodeId;
+import org.apache.doris.planner.ScanNode;
+import org.apache.doris.system.Backend;
+import org.apache.doris.thrift.TNetworkAddress;
+import org.apache.doris.thrift.TNumbersScanNode;
+import org.apache.doris.thrift.TPlanNode;
+import org.apache.doris.thrift.TPlanNodeType;
+import org.apache.doris.thrift.TScanRange;
+import org.apache.doris.thrift.TScanRangeLocation;
+import org.apache.doris.thrift.TScanRangeLocations;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import com.google.common.collect.Lists;
+
+import java.util.Collections;
+import java.util.List;
+
+// TODO yiguolei: not accept any pushdown filters
+public class NumbersTableValuedFunctionScanNode extends ScanNode {
+
+    private static final Logger LOG = 
LogManager.getLogger(NumbersTableValuedFunctionScanNode.class);
+
+    private List<Backend> backendList;
+    private List<TScanRangeLocations> shardScanRanges = Lists.newArrayList();
+    private int numTablets;
+    private long numbers;
+
+    boolean isFinalized = false;
+
+    public NumbersTableValuedFunctionScanNode(PlanNodeId id, TupleDescriptor 
desc, String planNodeName, long numbers, int tabletNum) {
+        super(id, desc, planNodeName);
+        this.numbers = numbers;
+        this.numTablets = tabletNum;
+    }
+
+    @Override
+    public void init(Analyzer analyzer) throws UserException {
+        super.init(analyzer);
+        assignBackends();
+        computeStats(analyzer);
+    }
+
+    @Override
+    public int getNumInstances() {
+        return shardScanRanges.size();
+    }
+
+    @Override
+    public List<TScanRangeLocations> getScanRangeLocations(long 
maxScanRangeLength) {
+        return shardScanRanges;
+    }
+
+    @Override
+    public void finalize(Analyzer analyzer) throws UserException {
+        if (isFinalized) {
+            return;
+        }
+
+        try {
+            shardScanRanges = getShardLocations();
+        } catch (AnalysisException e) {
+            throw new UserException(e.getMessage());
+        }
+
+        isFinalized = true;
+    }
+
+    @Override
+    protected void toThrift(TPlanNode msg) {
+        msg.node_type = TPlanNodeType.NUMBERS_SCAN_NODE;

Review comment:
       I think we need a new base class, like `TableValuedFunctionScanNode 
extends ScanNode`,
   and then all `tvfScanNodes` inherit from this class.
   This way we can avoid adding a new `TPlanNodeType` enumeration type every 
time we implement a new tvf.
   
   The BE side should also have a registry for tvf. Then the `tvfScanNode` on 
the BE side contains a tvf implementation class obtained from the tvf registry.

##########
File path: 
fe/fe-core/src/main/java/org/apache/doris/analysis/TableValuedFunctionRef.java
##########
@@ -0,0 +1,75 @@
+// 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.analysis;
+
+import org.apache.doris.catalog.Table;
+import org.apache.doris.common.UserException;
+import org.apache.doris.tablefunction.TableValuedFunctionInf;
+
+import java.util.List;
+
+public class TableValuedFunctionRef extends TableRef {
+
+    private Table table;
+    private TableValuedFunctionInf tableFunction;
+
+    public TableValuedFunctionRef(String funcName, String alias, List<String> 
params) throws UserException {
+        super(new TableName(null, "#table_function#" + funcName), alias);

Review comment:
       table name does allow "#", it may cause some unknown behavior.
   So how about `__doris_table_function`?

##########
File path: 
fe/fe-core/src/main/java/org/apache/doris/analysis/TableValuedFunctionRef.java
##########
@@ -0,0 +1,75 @@
+// 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.analysis;
+
+import org.apache.doris.catalog.Table;
+import org.apache.doris.common.UserException;
+import org.apache.doris.tablefunction.TableValuedFunctionInf;
+
+import java.util.List;
+
+public class TableValuedFunctionRef extends TableRef {
+
+    private Table table;
+    private TableValuedFunctionInf tableFunction;
+
+    public TableValuedFunctionRef(String funcName, String alias, List<String> 
params) throws UserException {
+        super(new TableName(null, "#table_function#" + funcName), alias);
+        this.tableFunction = TableValuedFunctionInf.getTableFunction(funcName, 
params);
+        if (hasExplicitAlias())
+            return;
+        aliases_ = new String[] { "#table_function#" + funcName };
+    }
+
+    public TableValuedFunctionRef(TableValuedFunctionRef other) {
+        super(other);
+        this.tableFunction = other.tableFunction;
+    }
+
+    @Override
+    public TableRef clone() {
+        return new TableValuedFunctionRef(this);

Review comment:
       This is not `clone`, because you just do a shallow copy of 
`tableFunction`




-- 
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]

Reply via email to