Skip to content

Commit a6d9f69

Browse files
committed
support multiple ranges for MetadataTableValuedFunction
1 parent ca78f18 commit a6d9f69

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

fe/fe-core/src/main/java/org/apache/doris/datasource/tvf/source/MetadataScanNode.java

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.apache.doris.system.Backend;
2828
import org.apache.doris.tablefunction.MetadataTableValuedFunction;
2929
import org.apache.doris.thrift.TMetaScanNode;
30+
import org.apache.doris.thrift.TMetaScanRange;
3031
import org.apache.doris.thrift.TNetworkAddress;
3132
import org.apache.doris.thrift.TPlanNode;
3233
import org.apache.doris.thrift.TPlanNodeType;
@@ -70,19 +71,21 @@ protected void toThrift(TPlanNode planNode) {
7071

7172
@Override
7273
protected void createScanRangeLocations() throws UserException {
73-
TScanRange scanRange = new TScanRange();
74-
scanRange.setMetaScanRange(tvf.getMetaScanRange());
75-
// set location
76-
TScanRangeLocation location = new TScanRangeLocation();
77-
Backend backend = backendPolicy.getNextBe();
78-
location.setBackendId(backend.getId());
79-
location.setServer(new TNetworkAddress(backend.getHost(), backend.getBePort()));
80-
81-
TScanRangeLocations locations = new TScanRangeLocations();
82-
locations.addToLocations(location);
83-
locations.setScanRange(scanRange);
84-
85-
scanRangeLocations.add(locations);
74+
for (TMetaScanRange metaScanRange : tvf.getMetaScanRanges()) {
75+
TScanRange scanRange = new TScanRange();
76+
scanRange.setMetaScanRange(metaScanRange);
77+
78+
TScanRangeLocation location = new TScanRangeLocation();
79+
Backend backend = backendPolicy.getNextBe();
80+
location.setBackendId(backend.getId());
81+
location.setServer(new TNetworkAddress(backend.getHost(), backend.getBePort()));
82+
83+
TScanRangeLocations locations = new TScanRangeLocations();
84+
locations.addToLocations(location);
85+
locations.setScanRange(scanRange);
86+
87+
scanRangeLocations.add(locations);
88+
}
8689
}
8790

8891
@Override

fe/fe-core/src/main/java/org/apache/doris/tablefunction/MetadataTableValuedFunction.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
import org.apache.doris.thrift.TMetadataTableRequestParams;
2828
import org.apache.doris.thrift.TMetadataType;
2929

30+
import java.util.List;
31+
3032
public abstract class MetadataTableValuedFunction extends TableValuedFunctionIf {
3133

3234
public static Integer getColumnIndexFromColumnName(TMetadataType type, String columnName,
@@ -60,6 +62,12 @@ public static Integer getColumnIndexFromColumnName(TMetadataType type, String co
6062

6163
public abstract TMetaScanRange getMetaScanRange();
6264

65+
public List<TMetaScanRange> getMetaScanRanges() {
66+
// most of the time, we only have one scan range,
67+
// but you can override this method to return multiple ranges
68+
return List.of(getMetaScanRange());
69+
}
70+
6371
@Override
6472
public ScanNode getScanNode(PlanNodeId id, TupleDescriptor desc, SessionVariable sv) {
6573
return new MetadataScanNode(id, desc, this);

0 commit comments

Comments
 (0)