Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,22 @@ public TVFTableSink(PlanNodeId exchNodeId, String tvfName, Map<String, String> p
this.cols = cols;
}

public String getTvfName() {
return tvfName;
}

/**
* Returns the backend_id specified in properties, or -1 if not set.
* For local TVF, this indicates the specific BE node where data should be written.
*/
public long getBackendId() {
String backendIdStr = properties.get("backend_id");
if (backendIdStr != null) {
return Long.parseLong(backendIdStr);
}
return -1;
}

public void bindDataSink() throws AnalysisException {
TTVFTableSink tSink = new TTVFTableSink();
tSink.setTvfName(tvfName);
Expand Down
19 changes: 19 additions & 0 deletions fe/fe-core/src/main/java/org/apache/doris/qe/Coordinator.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
import org.apache.doris.planner.SchemaScanNode;
import org.apache.doris.planner.SetOperationNode;
import org.apache.doris.planner.SortNode;
import org.apache.doris.planner.TVFTableSink;
import org.apache.doris.planner.UnionNode;
import org.apache.doris.proto.InternalService;
import org.apache.doris.proto.InternalService.PExecPlanFragmentResult;
Expand Down Expand Up @@ -1767,6 +1768,24 @@ protected void computeFragmentHosts() throws Exception {
// TODO: rethink the whole function logic. could All BE sink naturally merged into other judgements?
return;
}
// For local TVF sink with a specific backend_id, we must execute the sink fragment
// on the designated backend. Otherwise, data would be written to the wrong node's local disk.
if (fragment.getSink() instanceof TVFTableSink) {
TVFTableSink tvfSink = (TVFTableSink) fragment.getSink();
if ("local".equals(tvfSink.getTvfName()) && tvfSink.getBackendId() != -1) {
Backend targetBackend = Env.getCurrentSystemInfo().getBackend(tvfSink.getBackendId());
if (targetBackend == null || !targetBackend.isAlive()) {
throw new UserException("Backend " + tvfSink.getBackendId()
+ " is not available for local TVF sink");
}
TNetworkAddress execHostport = new TNetworkAddress(
targetBackend.getHost(), targetBackend.getBePort());
this.addressToBackendID.put(execHostport, targetBackend.getId());
FInstanceExecParam instanceParam = new FInstanceExecParam(null, execHostport, params);
params.instanceExecParams.add(instanceParam);
continue;
}
}

if (fragment.getDataPartition() == DataPartition.UNPARTITIONED) {
Reference<Long> backendIdRef = new Reference<Long>();
Expand Down
Loading