This is an automated email from the ASF dual-hosted git repository.

morningman pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 8ee64878c9d [fix](arrow-flight) Let clients behind a load balancer 
read results the FE holds (#70465)
8ee64878c9d is described below

commit 8ee64878c9db33e27976e711b474f9252442639b
Author: Raghvendra Singh <[email protected]>
AuthorDate: Tue Dec 1 14:24:41 2026 +0530

    [fix](arrow-flight) Let clients behind a load balancer read results the FE 
holds (#70465)
    
    ### Background
    
    An Arrow Flight SQL client sends each request to an FE with
    GetFlightInfo and gets back endpoints: a ticket, plus the locations
    where the client redeems it with DoGet. A query's result stays on a BE,
    and its endpoint names that BE, or `public_host` and
    `arrow_flight_sql_proxy_port` from be.conf for clients outside the
    cluster network. A result that only the FE can serve, the answer to a
    statement that is not a query (SHOW, USE, SET) or to a metadata request
    (GetCatalogs, GetTables, GetSqlInfo, ...), gets an endpoint naming the
    FE's own address: its host as `FrontendOptions` reports it, and
    `arrow_flight_sql_port`.
    
    ### What problem does this PR solve?
    
    Issue Number: #62538
    Related PR: #24314 (introduced the behavior), #69996 (added
    `test_flight_cancel_cleanup`, adapted here), #70796 (tested together
    with)
    PR Type: Bugfix
    
    Problem Summary:
    
    A client that reaches the FEs through a load balancer or a proxy often
    cannot resolve or reach an FE's own address. It reads query results from
    the BEs through `public_host`, but every call the FE answers fails, so a
    BI tool cannot even list databases or tables. This PR adds a mutable FE
    config, `arrow_flight_fe_result_empty_location`: set to `true`, the FE
    sends these endpoints with no location, which the Flight protocol
    defines as redeemable only on the service that issued the ticket, so the
    client fetches over the connection it already holds to that FE. The
    default, `false`, keeps today's behavior. The production change is 40
    lines; most of the diff is tests.
    
    For example, clients in a container reach an FE only through a port
    forward, while the FE advertises `127.0.0.1:34918`. Turning the setting
    on
    
    ```sql
    ADMIN SET ALL FRONTENDS CONFIG ("arrow_flight_fe_result_empty_location" = 
"true");
    ```
    
    changes what they get:
    
    | Call | `false` (the default, as before this PR) | `true` |
    |---|---|---|
    | `SHOW DATABASES`, Flight SQL JDBC 19.0.0 | `Error while executing SQL
    "SHOW DATABASES": io exception <- ... Connection refused:
    /127.0.0.1:34918` | 3 rows |
    | `getTables`, Flight SQL JDBC 19.0.0 | `FlightRuntimeException: io
    exception <- ... Connection refused: /127.0.0.1:34918` | 63 rows |
    | GetTables, pyarrow Flight client | endpoint
    `['grpc+tcp://127.0.0.1:34918']`, DoGet: `failed to connect to all
    addresses` | endpoint with no location, DoGet on the same connection: 63
    rows |
    | a `SELECT` whose result is on two BEs | 10000 rows, through
    `public_host` | the same |
    
    ### Details
    
    - **Change map:** +486/−21 in 9 files: production code +39/−1 in 2
    files, tests +420/−6 in 6 files, and the Java sample client +27/−14.
    Each commit is one part:
    1. `7eec9332f53`, the fix: the config and
    `DorisFlightSqlProducer.localResultEndpoint` (+29/−1), with three
    `DorisFlightSqlProducerTest` cases (+102).
    2. `0e040af7bca`, end-to-end coverage (+320/−16 in tests):
    `FlightSqlFeResultLocationTest`, the `nonConcurrent` regression suite
    `test_fe_result_empty_location`, and a unit case for the SHOW branch.
    `test_flight_native_variant`, `test_flight_parallel_partitions` and the
    sample read `locations[0]` of every endpoint, `SET`s included; the two
    suites now redeem an endpoint with no location on the issuing client
    (the sample: the fourth commit). The config description and the Javadoc
    are reworded (+20/−10).
    3. `fabf41c83ac`, test follow-ups (+16/−8):
    `test_flight_cancel_cleanup`, which #69996 added to master after this PR
    was opened, redeems an endpoint with no location the same way, and
    `test_fe_result_empty_location` keeps its table and names it in each
    statement, as the regression rules in AGENTS.md ask.
    4. `32b1146d395`, the sample (+26/−20): it read an endpoint with no
    location over a new connection to its configured FE address, which
    behind a load balancer can reach an FE that does not know the bearer
    token (found by the CI review); it now reads it on the issuing FE
    client, like the suites.
    - **Frequency:** Always, on every FE-answered call from a client that
    cannot resolve or reach the FE's own host, typically any client outside
    the cluster network; see the example.
    - **Root cause:** `DorisFlightSqlProducer.getFlightInfoForSchema`, which
    builds the endpoint of every result only the FE can serve, always names
    this FE's host and `arrow_flight_sql_port`. BEs have `public_host` and
    `arrow_flight_sql_proxy_port` for clients outside the network; FEs have
    nothing.
    - **Why existing tests missed it:** No unit test asserted an endpoint's
    location, and the `arrow_flight_sql_p0` suites connect from the
    regression runner, which reaches the FE's own address; no test ran a
    client outside the cluster network.
    - **Fix:** `getFlightInfoForSchema`, the only place that builds an
    FE-held endpoint, now gets it from `localResultEndpoint(ticket)`, which
    leaves the location out when the config is `true`.
    - **Other paths and branches:** Results held on a BE are not affected,
    with the setting on or off. `branch-3.1`, `branch-4.0`, `branch-4.1` and
    `branch-4.2` build the FE endpoint the same way, as every version has
    since #24314; their producer is still in
    `org.apache.doris.service.arrowflight`, which #67866 moved on master, so
    a pick needs its paths adapted.
    - **Configs and defaults:** `arrow_flight_fe_result_empty_location`, FE,
    default `false` (today's behavior), mutable: `ADMIN SET FRONTEND CONFIG`
    applies from the next GetFlightInfo. It is per FE, not master-only: set
    it on every FE, and in fe.conf to keep it across restarts.
    
    ### Testing
    
    - **FE unit tests at this head, locally:** the 21 classes under
    `org.apache.doris.arrowflight` pass (190 tests).
    `FlightSqlFeResultLocationTest` runs a real Flight SQL server whose FE
    advertises an address the client cannot reach: by default a client that
    follows endpoint locations cannot read a metadata result; with the
    setting on, it reads it over the issuing connection.
    - **The author's runs, before the rebase:** the 19 Arrow Flight FE test
    classes (172 tests) passed, and so did `test_fe_result_empty_location`,
    `test_flight_native_variant`, `test_flight_parallel_partitions` and
    `test_table_types_over_arrow_flight` on a single-node cluster. By hand,
    with the first commit, through port forwards from a machine where the
    FE's host does not resolve, ADBC 1.13.0, JDBC 15.0.2 and 19.0.0 and
    pyarrow failed every FE-answered call (`name resolver error: produced
    zero addresses`, `UNAVAILABLE: unresolved address`) until the setting
    was turned on at runtime, and failed again once it was turned off. A
    Tableau workbook over JDBC, outside the cluster network, works against
    three FEs behind a TLS-terminating load balancer with the setting on.
    - **Independent run by morningman, on a local cluster of 2 FEs and 2
    BEs** built from master `5bc6ed62f9b` with the pre-rebase head merged
    in; its Flight FE code and suites are byte-identical to this head, and
    its BEs also carried #70796. Clients in a container that reaches the
    cluster only through port forwards and an L4 load balancer (ADBC 1.12.0,
    JDBC 19.0.0 with and without `?catalog=`, and a pyarrow client that
    follows locations) made every metadata call, `SHOW DATABASES` and `SET`,
    and read queries spread over both BEs, checked against counts and sums
    computed over MySQL:
    
      | FE reached through | Setting | FE-answered calls | Results on BEs |
      |---|---|---|---|
    | direct, same network | `false` or `true` | pass; no location with
    `true` | pass |
    | a port forward | `false` | fail: connection refused to
    `127.0.0.1:34918` | pass, through `public_host` and a BE proxy |
      | a port forward | `true` | pass | pass |
    | an L4 load balancer over both FEs | `false` | fail: each FE names its
    own address | pass |
    | an L4 load balancer over both FEs | `true` | pass on both FEs | pass |
    
      Each client kept one Flight session throughout.
    - **The `arrow_flight_sql_p0` suites at this head, on the same
    cluster:** with the setting on, the 26 suites other than
    `test_fe_result_empty_location` (which assumes the default) pass; before
    the third commit, `test_flight_cancel_cleanup` failed there with a
    `NullPointerException` from `FlightClient.builder(allocator,
    endpoint.locations[0])`. With the setting off, all 27 pass.
    - **The Java sample's `FlightSqlClient`, on the same cluster, through an
    L4 round-robin proxy over both FEs:** with the setting on, `show
    databases` failed 3 of 3 times at `fabf41c83ac` (`UNAUTHENTICATED:
    invalid bearer token, ...: no Arrow Flight SQL session is open under it
    on this frontend`; the proxy put the DoGet's new connection on the other
    FE) and read its 14 rows 3 of 3 times at this head, over one connection.
    A `SELECT` through the proxy, `show databases` straight to an FE, and
    the setting off read the same rows at both commits.
    
    ### Notes for Reviewers
    
    - **No location rather than `Location.reuseConnection()`:** #67578 (A2)
    names the reuse URI as the standard answer to #62538. For a result the
    FE holds, an empty list means the same, "redeem on the service that
    issued the ticket", and it is the older form: the drivers tested above
    redeem it on the current client, while one that does not know the reuse
    scheme would dial its empty host. Switching is a one-line change in
    `localResultEndpoint`.
    - **Why the default stays `false`:** a client that assumes
    `locations[0]` exists breaks on an empty list, as three suites and the
    sample did.
    - **Why not an FE `public_host`, as #62538 asks:** the result exists
    only in the session on the FE that answered. In the independent run,
    redeeming an FE-answered ticket over a new connection through the load
    balancer failed 6 of 6 times (`invalid bearer token, ...: no Arrow
    Flight SQL session is open under it on this frontend`) and passed 6 of 6
    on the issuing connection.
    - **Out of scope:** a Flight SQL JDBC driver below 15.0.0 ignores
    endpoint locations altogether.
---
 .../main/java/org/apache/doris/common/Config.java  |  18 +++
 .../doris/arrowflight/DorisFlightSqlProducer.java  |  22 ++-
 .../arrowflight/DorisFlightSqlProducerTest.java    | 149 +++++++++++++++++++++
 .../arrowflight/FlightSqlFeResultLocationTest.java | 122 +++++++++++++++++
 .../test_fe_result_empty_location.groovy           | 116 ++++++++++++++++
 .../test_flight_cancel_cleanup.groovy              |  13 +-
 .../test_flight_native_variant.groovy              |  13 +-
 .../test_flight_parallel_partitions.groovy         |  13 +-
 .../doris/arrowflight/demo/FlightSqlClient.java    |  41 ++++--
 9 files changed, 486 insertions(+), 21 deletions(-)

diff --git a/fe/fe-common/src/main/java/org/apache/doris/common/Config.java 
b/fe/fe-common/src/main/java/org/apache/doris/common/Config.java
index afd6a9e878a..162ffa0d85c 100644
--- a/fe/fe-common/src/main/java/org/apache/doris/common/Config.java
+++ b/fe/fe-common/src/main/java/org/apache/doris/common/Config.java
@@ -2890,6 +2890,24 @@ public class Config extends ConfigBase {
             + "(wait_timeout still governs that). 0 disables the bound.")
     public static int arrow_flight_deferred_query_idle_timeout_second = 3600;
 
+    @ConfField(mutable = true, description = "Arrow Flight SQL only. Where a 
client fetches (DoGet) a result that "
+            + "only this FE can serve: the result of a statement that is not a 
query (SHOW, EXPLAIN, USE, SET, "
+            + "DDL, DML), which is cached in the session on this FE, and the 
answer to every metadata request "
+            + "(GetCatalogs, GetDbSchemas, GetTables, GetTableTypes, 
GetSqlInfo, ...), which this FE computes at "
+            + "DoGet for the session that presents the ticket. Either way the 
DoGet has to come back to this FE, "
+            + "where the session and its bearer token exist. "
+            + "false (the default) names this FE's own address in the endpoint 
(its host as FrontendOptions "
+            + "reports it, and arrow_flight_sql_port), which a client outside 
the cluster network often cannot "
+            + "resolve or reach, for example one that connects through a load 
balancer or a proxy. true sends "
+            + "the endpoint with no location, which the Flight protocol 
defines as redeemable only on the "
+            + "service that issued the ticket: a client that redeems a 
location-less endpoint on its own "
+            + "connection (the Flight SQL JDBC driver 15.0.0 or later and the 
ADBC Flight SQL drivers do) "
+            + "fetches over the connection it already holds to this FE; code 
that connects to the endpoint's "
+            + "first location must fall back to its FE connection when the 
list is empty. The result of a "
+            + "query stays on a BE and is not affected (see public_host and 
arrow_flight_sql_proxy_port in "
+            + "be.conf). Read for each request, so a change applies from the 
next GetFlightInfo.")
+    public static boolean arrow_flight_fe_result_empty_location = false;
+
     @ConfField(mutable = true, masterOnly = true, description = "In auto 
bucketing, the number of buckets is "
             + "estimated based on the partition size. For storage "
             + "and computing integration, a partition size of 5GB " + "is 
estimated as one bucket, but for cloud, a "
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/arrowflight/DorisFlightSqlProducer.java
 
b/fe/fe-core/src/main/java/org/apache/doris/arrowflight/DorisFlightSqlProducer.java
index 52d8b97bf6d..baad2cebb06 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/arrowflight/DorisFlightSqlProducer.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/arrowflight/DorisFlightSqlProducer.java
@@ -26,6 +26,7 @@ import 
org.apache.doris.arrowflight.protocol.FlightProtocolAdapter.PreparedQuery
 import org.apache.doris.arrowflight.results.FlightSqlEndpointsLocation;
 import org.apache.doris.arrowflight.results.FlightSqlResultCacheEntry;
 import org.apache.doris.arrowflight.sessions.FlightSessionsManager;
+import org.apache.doris.common.Config;
 import org.apache.doris.common.IncrWindowNotReadyException;
 import org.apache.doris.common.Status;
 import org.apache.doris.common.Version;
@@ -953,11 +954,30 @@ public class DorisFlightSqlProducer implements 
FlightSqlProducer, AutoCloseable
     private <T extends Message> FlightInfo getFlightInfoForSchema(final T 
request, final FlightDescriptor descriptor,
             final Schema schema) {
         final Ticket ticket = new Ticket(Any.pack(request).toByteArray());
-        final List<FlightEndpoint> endpoints = Collections.singletonList(new 
FlightEndpoint(ticket, location));
+        final List<FlightEndpoint> endpoints = 
Collections.singletonList(localResultEndpoint(ticket));
 
         return new FlightInfo(schema, descriptor, endpoints, -1, -1);
     }
 
+    /**
+     * The endpoint of a result only this FE can serve: the result of a 
statement that is not a query
+     * (SHOW, EXPLAIN, USE, SET, DDL, DML), which is cached in the session on 
this FE, and the answer
+     * to a metadata request, which this FE computes at DoGet for the session 
that presents the ticket.
+     * Either way the DoGet has to come back to this FE, where the session and 
its bearer token exist:
+     * by this FE's own address, or, with {@link 
Config#arrow_flight_fe_result_empty_location}, by no
+     * location at all, which the Flight protocol defines as redeemable only 
on the service that issued
+     * the ticket. A client that redeems such an endpoint on its own 
connection fetches over the one it
+     * already holds to this FE; code that connects to an endpoint's first 
location must fall back to
+     * its FE connection when the list is empty. The setting is read per 
request, so a runtime change
+     * applies to the next one.
+     */
+    private FlightEndpoint localResultEndpoint(Ticket ticket) {
+        if (Config.arrow_flight_fe_result_empty_location) {
+            return new FlightEndpoint(ticket);
+        }
+        return new FlightEndpoint(ticket, location);
+    }
+
     private static void handleStreamException(Throwable e, String errMsg, 
ServerStreamListener listener) {
         LOG.error(errMsg, e);
         
listener.error(CallStatus.INTERNAL.withDescription(errMsg).withCause(e).toRuntimeException());
diff --git 
a/fe/fe-core/src/test/java/org/apache/doris/arrowflight/DorisFlightSqlProducerTest.java
 
b/fe/fe-core/src/test/java/org/apache/doris/arrowflight/DorisFlightSqlProducerTest.java
index 1238286917a..071c3744ec7 100644
--- 
a/fe/fe-core/src/test/java/org/apache/doris/arrowflight/DorisFlightSqlProducerTest.java
+++ 
b/fe/fe-core/src/test/java/org/apache/doris/arrowflight/DorisFlightSqlProducerTest.java
@@ -21,16 +21,23 @@ import org.apache.doris.analysis.UserIdentity;
 import org.apache.doris.arrowflight.auth2.FlightAuthResult;
 import org.apache.doris.arrowflight.protocol.FlightProtocolAdapter;
 import org.apache.doris.arrowflight.results.FlightSqlChannel;
+import org.apache.doris.arrowflight.results.FlightSqlEndpointsLocation;
 import org.apache.doris.arrowflight.sessions.FlightSessionsManager;
+import org.apache.doris.catalog.Column;
+import org.apache.doris.catalog.Type;
+import org.apache.doris.common.Config;
 import org.apache.doris.common.ErrorCode;
 import org.apache.doris.common.FeConstants;
 import org.apache.doris.common.IncrWindowNotReadyException;
 import org.apache.doris.common.Status;
+import org.apache.doris.common.util.DebugUtil;
 import org.apache.doris.mysql.MysqlCommand;
 import org.apache.doris.qe.ConnectContext;
 import org.apache.doris.qe.ConnectPoolTestSupport;
 import org.apache.doris.qe.ConnectScheduler;
 import org.apache.doris.qe.QueryState;
+import org.apache.doris.qe.ShowResultSet;
+import org.apache.doris.qe.ShowResultSetMetaData;
 import org.apache.doris.qe.StmtExecutor;
 import org.apache.doris.rpc.BackendServiceProxy;
 import org.apache.doris.thrift.TNetworkAddress;
@@ -48,6 +55,8 @@ import org.apache.arrow.flight.CloseSessionResult;
 import org.apache.arrow.flight.ErrorFlightMetadata;
 import org.apache.arrow.flight.FlightConstants;
 import org.apache.arrow.flight.FlightDescriptor;
+import org.apache.arrow.flight.FlightEndpoint;
+import org.apache.arrow.flight.FlightInfo;
 import org.apache.arrow.flight.FlightProducer.CallContext;
 import org.apache.arrow.flight.FlightProducer.StreamListener;
 import org.apache.arrow.flight.FlightRuntimeException;
@@ -63,6 +72,7 @@ import 
org.apache.arrow.flight.SetSessionOptionsResult.ErrorValue;
 import org.apache.arrow.flight.sql.FlightSqlUtils;
 import 
org.apache.arrow.flight.sql.impl.FlightSql.ActionCreatePreparedStatementRequest;
 import 
org.apache.arrow.flight.sql.impl.FlightSql.ActionCreatePreparedStatementResult;
+import org.apache.arrow.flight.sql.impl.FlightSql.CommandGetCatalogs;
 import org.apache.arrow.flight.sql.impl.FlightSql.CommandStatementQuery;
 import org.apache.arrow.vector.ipc.ReadChannel;
 import org.apache.arrow.vector.ipc.message.MessageSerializer;
@@ -78,6 +88,7 @@ import org.mockito.Mockito;
 import java.io.ByteArrayInputStream;
 import java.nio.channels.Channels;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 import java.util.Set;
 import java.util.concurrent.CountDownLatch;
@@ -89,6 +100,7 @@ import java.util.stream.Collectors;
 public class DorisFlightSqlProducerTest {
 
     private boolean prevRunningUnitTest;
+    private boolean prevFeResultEmptyLocation;
 
     @Test
     public void 
testWindowNotReadyHasRetryableFlightStatusAndStableBusinessCode() {
@@ -177,11 +189,13 @@ public class DorisFlightSqlProducerTest {
         // context can be built without a running FE.
         prevRunningUnitTest = FeConstants.runningUnitTest;
         FeConstants.runningUnitTest = true;
+        prevFeResultEmptyLocation = 
Config.arrow_flight_fe_result_empty_location;
     }
 
     @AfterEach
     public void tearDown() {
         FeConstants.runningUnitTest = prevRunningUnitTest;
+        Config.arrow_flight_fe_result_empty_location = 
prevFeResultEmptyLocation;
     }
 
     /**
@@ -677,4 +691,139 @@ public class DorisFlightSqlProducerTest {
             producer.close();
         }
     }
+
+    private static final Location THIS_FE = 
Location.forGrpcInsecure("doris-fe-0.doris-fe.svc.cluster.local", 8040);
+
+    private static FlightEndpoint onlyEndpoint(FlightInfo info) {
+        Assertions.assertEquals(1, info.getEndpoints().size(), "endpoints " + 
info.getEndpoints());
+        return info.getEndpoints().get(0);
+    }
+
+    // A metadata request is answered by this FE at DoGet, for the session 
that presents the ticket. By
+    // default its endpoint names this FE's own address; with 
arrow_flight_fe_result_empty_location it
+    // carries no location, which a client redeems on the connection that 
issued the ticket. The
+    // setting is read per request: the same producer follows a change between 
two requests, both
+    // ways, and the ticket does not change.
+    @Test
+    public void testMetadataResultEndpointFollowsTheSettingPerRequest() throws 
Exception {
+        DorisFlightSqlProducer producer = new DorisFlightSqlProducer(THIS_FE,
+                Mockito.mock(FlightSessionsManager.class));
+        try {
+            CommandGetCatalogs request = 
CommandGetCatalogs.getDefaultInstance();
+            FlightDescriptor descriptor = 
FlightDescriptor.command(Any.pack(request).toByteArray());
+
+            Config.arrow_flight_fe_result_empty_location = false;
+            FlightEndpoint byAddress = 
onlyEndpoint(producer.getFlightInfoCatalogs(request, callOf("token"),
+                    descriptor));
+            Assertions.assertEquals(ImmutableList.of(THIS_FE), 
byAddress.getLocations());
+
+            Config.arrow_flight_fe_result_empty_location = true;
+            FlightEndpoint noLocation = 
onlyEndpoint(producer.getFlightInfoCatalogs(request, callOf("token"),
+                    descriptor));
+            Assertions.assertTrue(noLocation.getLocations().isEmpty(), 
"locations " + noLocation.getLocations());
+            Assertions.assertEquals(byAddress.getTicket(), 
noLocation.getTicket());
+
+            Config.arrow_flight_fe_result_empty_location = false;
+            Assertions.assertEquals(ImmutableList.of(THIS_FE),
+                    onlyEndpoint(producer.getFlightInfoCatalogs(request, 
callOf("token"), descriptor)).getLocations());
+        } finally {
+            producer.close();
+        }
+    }
+
+    // A statement answered with a status (USE, SET): the processor caches no 
result, so the producer
+    // synthesizes the status row in the session on this FE. Its endpoint 
follows the setting the same way.
+    @Test
+    public void testFrontendAnsweredStatementEndpointFollowsTheSetting() 
throws Exception {
+        ConnectContext ctx = ConnectContext.forFlight("token");
+        DorisFlightSqlProducer producer = new DorisFlightSqlProducer(THIS_FE, 
sessionsOf(ctx));
+        try (MockedConstruction<FlightSqlConnectProcessor> mocked = 
Mockito.mockConstruction(
+                FlightSqlConnectProcessor.class)) {
+            CommandStatementQuery request = 
CommandStatementQuery.newBuilder().setQuery("use db1").build();
+            FlightDescriptor descriptor = FlightDescriptor.command(new 
byte[0]);
+
+            Config.arrow_flight_fe_result_empty_location = true;
+            FlightEndpoint noLocation = 
onlyEndpoint(producer.getFlightInfoStatement(request, callOf("token"),
+                    descriptor));
+            Assertions.assertTrue(noLocation.getLocations().isEmpty(), 
"locations " + noLocation.getLocations());
+
+            Config.arrow_flight_fe_result_empty_location = false;
+            Assertions.assertEquals(ImmutableList.of(THIS_FE),
+                    onlyEndpoint(producer.getFlightInfoStatement(request, 
callOf("token"), descriptor)).getLocations());
+        } finally {
+            producer.close();
+            ctx.getFlightSqlChannel().close();
+        }
+    }
+
+    // A statement that caches its own result (SHOW, EXPLAIN): the processor 
leaves one result on the
+    // session's channel under the statement's query id, and the producer 
serves it from there. Its
+    // endpoint follows the setting like the status row does.
+    @Test
+    public void testCachedShowResultEndpointFollowsTheSetting() throws 
Exception {
+        ConnectContext ctx = ConnectContext.forFlight("token");
+        DorisFlightSqlProducer producer = new DorisFlightSqlProducer(THIS_FE, 
sessionsOf(ctx));
+        try (MockedConstruction<FlightSqlConnectProcessor> mocked = 
Mockito.mockConstruction(
+                FlightSqlConnectProcessor.class, (mock, context) -> {
+                    Mockito.doAnswer(invocation -> {
+                        ctx.getState().reset();
+                        FlightProtocolAdapter.of(ctx).beforeStatement(ctx);
+                        ShowResultSetMetaData.Builder header = 
ShowResultSetMetaData.builder();
+                        header.addColumn(new Column("Database", Type.STRING));
+                        ctx.setQueryId(new TUniqueId(48, 1));
+                        
ctx.getFlightSqlChannel().addResult(DebugUtil.printId(ctx.queryId()),
+                                invocation.getArgument(0), new 
ShowResultSet(header.build(), Collections.emptyList()));
+                        return null;
+                    }).when(mock).handleQuery(Mockito.anyString());
+                })) {
+            CommandStatementQuery request = 
CommandStatementQuery.newBuilder().setQuery("show databases").build();
+            FlightDescriptor descriptor = FlightDescriptor.command(new 
byte[0]);
+
+            Config.arrow_flight_fe_result_empty_location = false;
+            Assertions.assertEquals(ImmutableList.of(THIS_FE),
+                    onlyEndpoint(producer.getFlightInfoStatement(request, 
callOf("token"), descriptor)).getLocations());
+
+            Config.arrow_flight_fe_result_empty_location = true;
+            FlightEndpoint noLocation = 
onlyEndpoint(producer.getFlightInfoStatement(request, callOf("token"),
+                    descriptor));
+            Assertions.assertTrue(noLocation.getLocations().isEmpty(), 
"locations " + noLocation.getLocations());
+            Assertions.assertEquals(1, ctx.getFlightSqlChannel().resultNum(), 
"the SHOW result is cached, once");
+        } finally {
+            producer.close();
+            ctx.getFlightSqlChannel().close();
+        }
+    }
+
+    // A query whose result stays on a backend keeps the backend's address in 
its endpoint whatever
+    // the setting: only results this FE holds lose their location.
+    @Test
+    public void testBackendHeldResultKeepsTheBackendAddress() throws Exception 
{
+        ConnectContext ctx = ConnectContext.forFlight("token");
+        DorisFlightSqlProducer producer = new DorisFlightSqlProducer(THIS_FE, 
sessionsOf(ctx));
+        try (MockedConstruction<FlightSqlConnectProcessor> mocked = 
Mockito.mockConstruction(
+                FlightSqlConnectProcessor.class, (mock, context) -> {
+                    Mockito.doAnswer(invocation -> {
+                        FlightProtocolAdapter.of(ctx).beforeQuery(ctx);
+                        ctx.addFlightSqlEndpointsLocation(new 
FlightSqlEndpointsLocation(new TUniqueId(1L, 2L),
+                                new 
TNetworkAddress("doris-be-0.doris-be.svc.cluster.local", 8050),
+                                new 
TNetworkAddress("doris-be-0.doris-be.svc.cluster.local", 8060),
+                                new ArrayList<>()));
+                        return null;
+                    }).when(mock).handleQuery(Mockito.anyString());
+                    Mockito.when(mock.getArrowSchema()).thenReturn(new 
Schema(new ArrayList<>()));
+                })) {
+            CommandStatementQuery request = 
CommandStatementQuery.newBuilder().setQuery("select 1").build();
+            for (boolean emptyLocation : new boolean[] {true, false}) {
+                Config.arrow_flight_fe_result_empty_location = emptyLocation;
+                FlightEndpoint endpoint = 
onlyEndpoint(producer.getFlightInfoStatement(request, callOf("token"),
+                        FlightDescriptor.command(new byte[0])));
+                Assertions.assertEquals(
+                        
ImmutableList.of(Location.forGrpcInsecure("doris-be-0.doris-be.svc.cluster.local",
 8050)),
+                        endpoint.getLocations(), 
"arrow_flight_fe_result_empty_location=" + emptyLocation);
+            }
+        } finally {
+            producer.close();
+            ctx.getFlightSqlChannel().close();
+        }
+    }
 }
diff --git 
a/fe/fe-core/src/test/java/org/apache/doris/arrowflight/FlightSqlFeResultLocationTest.java
 
b/fe/fe-core/src/test/java/org/apache/doris/arrowflight/FlightSqlFeResultLocationTest.java
new file mode 100644
index 00000000000..66c9ef9d1c7
--- /dev/null
+++ 
b/fe/fe-core/src/test/java/org/apache/doris/arrowflight/FlightSqlFeResultLocationTest.java
@@ -0,0 +1,122 @@
+// 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.arrowflight;
+
+import org.apache.doris.arrowflight.sessions.FlightSessionsManager;
+import org.apache.doris.common.Config;
+import org.apache.doris.common.FeConstants;
+import org.apache.doris.qe.ConnectContext;
+
+import org.apache.arrow.flight.CallOptions;
+import org.apache.arrow.flight.FlightClient;
+import org.apache.arrow.flight.FlightEndpoint;
+import org.apache.arrow.flight.FlightRuntimeException;
+import org.apache.arrow.flight.FlightServer;
+import org.apache.arrow.flight.FlightStatusCode;
+import org.apache.arrow.flight.FlightStream;
+import org.apache.arrow.flight.Location;
+import org.apache.arrow.flight.sql.FlightSqlClient;
+import org.apache.arrow.memory.BufferAllocator;
+import org.apache.arrow.memory.RootAllocator;
+import org.apache.arrow.vector.VectorSchemaRoot;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
+
+import java.net.ServerSocket;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
+public class FlightSqlFeResultLocationTest {
+    // The defect this setting fixes, end to end through a real Flight SQL 
server: the FE advertises an
+    // address its client cannot reach, as an FE behind a load balancer or a 
proxy does. A metadata
+    // result's endpoint names that address by default, so a client that 
follows endpoint locations
+    // cannot fetch it; with arrow_flight_fe_result_empty_location the 
endpoint carries no location and
+    // the same client reads it over the connection that issued the ticket.
+    @Test
+    public void 
locationFollowingClientReadsAnFeHeldResultOnlyWithoutALocation() throws 
Exception {
+        boolean previousRunningUnitTest = FeConstants.runningUnitTest;
+        boolean previousEmptyLocation = 
Config.arrow_flight_fe_result_empty_location;
+        FeConstants.runningUnitTest = true;
+        ConnectContext ctx = ConnectContext.forFlight("metadata-token");
+        try {
+            FlightSessionsManager sessions = 
Mockito.mock(FlightSessionsManager.class);
+            
Mockito.when(sessions.getConnectContext(Mockito.anyString())).thenReturn(ctx);
+            // A loopback port nothing listens on: unreachable on every host, 
refused at once, no DNS.
+            int closedPort;
+            try (ServerSocket probe = new ServerSocket(0)) {
+                closedPort = probe.getLocalPort();
+            }
+            Location advertised = Location.forGrpcInsecure("127.0.0.1", 
closedPort);
+            try (DorisFlightSqlProducer producer = new 
DorisFlightSqlProducer(advertised, sessions);
+                    RootAllocator allocator = new RootAllocator();
+                    FlightServer server = FlightServer.builder(allocator, 
Location.forGrpcInsecure("127.0.0.1", 0),
+                            producer).build().start();
+                    FlightClient client = FlightClient.builder(allocator,
+                            Location.forGrpcInsecure("127.0.0.1", 
server.getPort())).build()) {
+                FlightSqlClient sql = new FlightSqlClient(client);
+
+                Config.arrow_flight_fe_result_empty_location = false;
+                FlightEndpoint byAddress = 
sql.getTableTypes().getEndpoints().get(0);
+                Assertions.assertEquals(Collections.singletonList(advertised), 
byAddress.getLocations());
+                FlightRuntimeException unreachable = 
Assertions.assertThrows(FlightRuntimeException.class,
+                        () -> readTableTypes(allocator, client, byAddress));
+                Assertions.assertEquals(FlightStatusCode.UNAVAILABLE, 
unreachable.status().code(),
+                        unreachable.getMessage());
+
+                Config.arrow_flight_fe_result_empty_location = true;
+                FlightEndpoint noLocation = 
sql.getTableTypes().getEndpoints().get(0);
+                Assertions.assertTrue(noLocation.getLocations().isEmpty(), 
"locations " + noLocation.getLocations());
+                Assertions.assertEquals(Arrays.asList("BASE TABLE", "SYSTEM 
VIEW", "VIEW"),
+                        readTableTypes(allocator, client, noLocation));
+            }
+        } finally {
+            ctx.getFlightSqlChannel().close();
+            Config.arrow_flight_fe_result_empty_location = 
previousEmptyLocation;
+            FeConstants.runningUnitTest = previousRunningUnitTest;
+        }
+    }
+
+    // Reads an endpoint the way a client that follows locations does (the 
Flight SQL JDBC driver): at its
+    // first location, or, when it has none, on the client that issued the 
ticket.
+    private static List<String> readTableTypes(BufferAllocator allocator, 
FlightClient issuer,
+            FlightEndpoint endpoint) throws Exception {
+        if (endpoint.getLocations().isEmpty()) {
+            return readTableTypes(issuer, endpoint);
+        }
+        try (FlightClient atLocation = FlightClient.builder(allocator, 
endpoint.getLocations().get(0)).build()) {
+            return readTableTypes(atLocation, endpoint);
+        }
+    }
+
+    private static List<String> readTableTypes(FlightClient reader, 
FlightEndpoint endpoint) throws Exception {
+        List<String> types = new ArrayList<>();
+        try (FlightStream stream = reader.getStream(endpoint.getTicket(), 
CallOptions.timeout(10, TimeUnit.SECONDS))) {
+            while (stream.next()) {
+                VectorSchemaRoot root = stream.getRoot();
+                for (int row = 0; row < root.getRowCount(); ++row) {
+                    
types.add(root.getVector("table_type").getObject(row).toString());
+                }
+            }
+        }
+        return types;
+    }
+}
diff --git 
a/regression-test/suites/arrow_flight_sql_p0/test_fe_result_empty_location.groovy
 
b/regression-test/suites/arrow_flight_sql_p0/test_fe_result_empty_location.groovy
new file mode 100644
index 00000000000..aaaece2a7c0
--- /dev/null
+++ 
b/regression-test/suites/arrow_flight_sql_p0/test_fe_result_empty_location.groovy
@@ -0,0 +1,116 @@
+// 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.
+
+import org.apache.arrow.driver.jdbc.shaded.org.apache.arrow.flight.CallOption
+import org.apache.arrow.driver.jdbc.shaded.org.apache.arrow.flight.CallOptions
+import 
org.apache.arrow.driver.jdbc.shaded.org.apache.arrow.flight.CloseSessionRequest
+import org.apache.arrow.driver.jdbc.shaded.org.apache.arrow.flight.FlightClient
+import org.apache.arrow.driver.jdbc.shaded.org.apache.arrow.flight.Location
+import 
org.apache.arrow.driver.jdbc.shaded.org.apache.arrow.flight.sql.FlightSqlClient
+import 
org.apache.arrow.driver.jdbc.shaded.org.apache.arrow.memory.RootAllocator
+import org.apache.doris.regression.util.JdbcUtils
+
+import java.util.concurrent.TimeUnit
+
+// arrow_flight_fe_result_empty_location: with it on, a result only the FE can 
serve (a SHOW, a metadata
+// request) is handed out with no location and redeemed on the connection that 
issued the ticket, while a
+// query's result keeps its BE address. setFeConfigTemporary changes every FE, 
so the suite runs alone.
+suite("test_fe_result_empty_location", "arrow_flight_sql,nonConcurrent") {
+    sql "DROP TABLE IF EXISTS test_fe_result_empty_location_t"
+    sql """CREATE TABLE test_fe_result_empty_location_t (id INT)
+            DISTRIBUTED BY HASH(id) BUCKETS 1 PROPERTIES ("replication_num" = 
"1")"""
+    sql "INSERT INTO test_fe_result_empty_location_t VALUES (1), (2), (3)"
+
+    def config = context.config.otherConfigs
+    def feLocation = 
Location.forGrpcInsecure(config.get("extArrowFlightSqlHost"),
+            Integer.parseInt(config.get("extArrowFlightSqlPort")))
+
+    // The endpoints a plain Flight SQL client gets, and what it reads from 
them.
+    def checkPlainClient = { boolean emptyLocation ->
+        new RootAllocator().withCloseable { allocator ->
+            FlightClient.builder(allocator, feLocation).build().withCloseable 
{ flight ->
+                def token = 
flight.authenticateBasicToken(config.get("extArrowFlightSqlUser"),
+                        config.get("extArrowFlightSqlPassword")).get()
+                CallOption[] options = [token, CallOptions.timeout(30, 
TimeUnit.SECONDS)]
+                def client = new FlightSqlClient(flight)
+                def countRows = { FlightClient reader, endpoint ->
+                    int rows = 0
+                    reader.getStream(endpoint.getTicket(), 
options).withCloseable { stream ->
+                        while (stream.next()) {
+                            rows += stream.getRoot().getRowCount()
+                        }
+                    }
+                    rows
+                }
+                try {
+                    // Results only this FE can serve: a metadata request and 
a SHOW.
+                    [client.getCatalogs(options), client.execute("SHOW 
DATABASES", options)].each { info ->
+                        assertEquals(1, info.getEndpoints().size())
+                        def endpoint = info.getEndpoints()[0]
+                        if (emptyLocation) {
+                            assertTrue(endpoint.getLocations().isEmpty(), 
"locations ${endpoint.getLocations()}")
+                        } else {
+                            assertEquals(1, endpoint.getLocations().size(), 
"locations ${endpoint.getLocations()}")
+                        }
+                        // Redeemed on the client that issued the ticket.
+                        assertTrue(countRows(flight, endpoint) > 0)
+                    }
+                    // A query's result stays on a BE and keeps the BE's 
address whatever the setting.
+                    def query = client.execute("SELECT id FROM 
${context.dbName}.test_fe_result_empty_location_t", options)
+                    assertFalse(query.getEndpoints().isEmpty())
+                    int queryRows = 0
+                    query.getEndpoints().each { endpoint ->
+                        assertFalse(endpoint.getLocations().isEmpty(), "a 
BE-held result must keep its location")
+                        FlightClient.builder(allocator, 
endpoint.getLocations()[0]).build().withCloseable { be ->
+                            queryRows += countRows(be, endpoint)
+                        }
+                    }
+                    assertEquals(3, queryRows)
+                } finally {
+                    flight.closeSession(new CloseSessionRequest(), token)
+                }
+            }
+        }
+    }
+
+    // What the Flight SQL JDBC driver reads: it follows a location, and 
redeems an endpoint that has
+    // none on its own connection.
+    def checkJdbcDriver = {
+        def flightConn = context.getArrowFlightSqlConnection()
+        assertFalse(JdbcUtils.executeToList(flightConn, "SHOW 
DATABASES").isEmpty())
+        def typeRows = flightConn.getMetaData().getTableTypes()
+        try {
+            def types = []
+            while (typeRows.next()) {
+                types.add(typeRows.getString("TABLE_TYPE"))
+            }
+            assertEquals(["BASE TABLE", "SYSTEM VIEW", "VIEW"], types)
+        } finally {
+            typeRows.close()
+        }
+    }
+
+    setFeConfigTemporary([arrow_flight_fe_result_empty_location: true]) {
+        assertEquals("true", 
getFeConfig("arrow_flight_fe_result_empty_location"))
+        checkPlainClient(true)
+        checkJdbcDriver()
+    }
+    // Back to the default: the same requests name the FE's address again.
+    assertEquals("false", getFeConfig("arrow_flight_fe_result_empty_location"))
+    checkPlainClient(false)
+    checkJdbcDriver()
+}
diff --git 
a/regression-test/suites/arrow_flight_sql_p0/test_flight_cancel_cleanup.groovy 
b/regression-test/suites/arrow_flight_sql_p0/test_flight_cancel_cleanup.groovy
index 6179834793b..0d144a3fc35 100644
--- 
a/regression-test/suites/arrow_flight_sql_p0/test_flight_cancel_cleanup.groovy
+++ 
b/regression-test/suites/arrow_flight_sql_p0/test_flight_cancel_cleanup.groovy
@@ -43,13 +43,22 @@ suite("test_flight_cancel_cleanup", "arrow_flight_sql") {
         def info = client.execute(query, auth)
         def rows = 0
         info.endpoints.each { endpoint ->
-            FlightClient.builder(allocator, 
endpoint.locations[0]).build().withCloseable { beClient ->
-                beClient.getStream(endpoint.ticket, auth).withCloseable { 
stream ->
+            def readFrom = { FlightClient reader ->
+                reader.getStream(endpoint.ticket, auth).withCloseable { stream 
->
                     while (stream.next()) {
                         rows += stream.root.rowCount
                     }
                 }
             }
+            // An endpoint with no location (an FE-held result under 
arrow_flight_fe_result_empty_location) is
+            // redeemed on the client that issued the ticket, as the Flight 
SQL JDBC driver does.
+            if (endpoint.locations.isEmpty()) {
+                readFrom(feClient)
+            } else {
+                FlightClient.builder(allocator, 
endpoint.locations[0]).build().withCloseable { beClient ->
+                    readFrom(beClient)
+                }
+            }
         }
         rows
     }
diff --git 
a/regression-test/suites/arrow_flight_sql_p0/test_flight_native_variant.groovy 
b/regression-test/suites/arrow_flight_sql_p0/test_flight_native_variant.groovy
index 6fb755585cf..61b9a17498e 100644
--- 
a/regression-test/suites/arrow_flight_sql_p0/test_flight_native_variant.groovy
+++ 
b/regression-test/suites/arrow_flight_sql_p0/test_flight_native_variant.groovy
@@ -55,8 +55,8 @@ suite("test_flight_native_variant", "arrow_flight_sql") {
             }
         }
         info.endpoints.each { endpoint ->
-            FlightClient.builder(allocator, 
endpoint.locations[0]).build().withCloseable { beClient ->
-                beClient.getStream(endpoint.ticket, auth, 
CallOptions.timeout(30, TimeUnit.SECONDS)).withCloseable { stream ->
+            def readFrom = { FlightClient reader ->
+                reader.getStream(endpoint.ticket, auth, 
CallOptions.timeout(30, TimeUnit.SECONDS)).withCloseable { stream ->
                     assertEquals(info.schema, stream.schema, "Result endpoints 
must share the published schema")
                     while (stream.next()) {
                         inspect(stream.root)
@@ -64,6 +64,15 @@ suite("test_flight_native_variant", "arrow_flight_sql") {
                     }
                 }
             }
+            // An endpoint with no location (an FE-held result under 
arrow_flight_fe_result_empty_location) is
+            // redeemed on the client that issued the ticket, as the Flight 
SQL JDBC driver does.
+            if (endpoint.locations.isEmpty()) {
+                readFrom(feClient)
+            } else {
+                FlightClient.builder(allocator, 
endpoint.locations[0]).build().withCloseable { beClient ->
+                    readFrom(beClient)
+                }
+            }
         }
         count
     }
diff --git 
a/regression-test/suites/arrow_flight_sql_p0/test_flight_parallel_partitions.groovy
 
b/regression-test/suites/arrow_flight_sql_p0/test_flight_parallel_partitions.groovy
index 005341df0ee..1dc63506b51 100644
--- 
a/regression-test/suites/arrow_flight_sql_p0/test_flight_parallel_partitions.groovy
+++ 
b/regression-test/suites/arrow_flight_sql_p0/test_flight_parallel_partitions.groovy
@@ -42,8 +42,8 @@ suite("test_flight_parallel_partitions", "arrow_flight_sql") {
     def auth
     def readEndpoint = { endpoint, boolean collectRows ->
         def rows = []
-        FlightClient.builder(allocator, 
endpoint.locations[0]).build().withCloseable { beClient ->
-            beClient.getStream(endpoint.ticket, auth, CallOptions.timeout(30, 
TimeUnit.SECONDS)).withCloseable { stream ->
+        def readFrom = { FlightClient reader ->
+            reader.getStream(endpoint.ticket, auth, CallOptions.timeout(30, 
TimeUnit.SECONDS)).withCloseable { stream ->
                 while (stream.next()) {
                     if (collectRows) {
                         def vector = stream.root.getVector(0)
@@ -54,6 +54,15 @@ suite("test_flight_parallel_partitions", "arrow_flight_sql") 
{
                 }
             }
         }
+        // An endpoint with no location (an FE-held result under 
arrow_flight_fe_result_empty_location) is
+        // redeemed on the client that issued the ticket, as the Flight SQL 
JDBC driver does.
+        if (endpoint.locations.isEmpty()) {
+            readFrom(feClient)
+        } else {
+            FlightClient.builder(allocator, 
endpoint.locations[0]).build().withCloseable { beClient ->
+                readFrom(beClient)
+            }
+        }
         rows
     }
     def executeSetting = { String statement ->
diff --git 
a/samples/arrow-flight-sql/java/src/main/java/doris/arrowflight/demo/FlightSqlClient.java
 
b/samples/arrow-flight-sql/java/src/main/java/doris/arrowflight/demo/FlightSqlClient.java
index 3a01ea16370..a61ce8fa1da 100644
--- 
a/samples/arrow-flight-sql/java/src/main/java/doris/arrowflight/demo/FlightSqlClient.java
+++ 
b/samples/arrow-flight-sql/java/src/main/java/doris/arrowflight/demo/FlightSqlClient.java
@@ -33,12 +33,13 @@ import org.apache.arrow.vector.VectorSchemaRoot;
 
 import java.net.URI;
 import java.net.URISyntaxException;
+import java.util.List;
 
 /**
  * Manually execute Arrow Flight SQL Rpc process, usually used for debug.
  */
 public class FlightSqlClient {
-    public record FlightInfoResult<T, T2, T3>(T first, T2 second, T3 third) {
+    public record FlightInfoResult<T, T2, T3, T4>(T first, T2 second, T3 
third, T4 fourth) {
     }
 
     public record DummyFlightInfoResult<T, T2>(T first, T2 second) {
@@ -46,8 +47,11 @@ public class FlightSqlClient {
 
     /**
      * Connect to FE Arrow Flight Server to obtain Bearertoken and execute 
Query to get Ticket.
+     * Also returns the FE client, on which a result the FE holds itself is 
read.
      */
-    public static FlightInfoResult<FlightInfo, CredentialCallOption, 
org.apache.arrow.flight.sql.FlightSqlClient.PreparedStatement> 
getFlightInfoFromDorisFe(
+    public static FlightInfoResult<FlightInfo, CredentialCallOption,
+            org.apache.arrow.flight.sql.FlightSqlClient.PreparedStatement,
+            org.apache.arrow.flight.sql.FlightSqlClient> 
getFlightInfoFromDorisFe(
             Configuration configuration) throws URISyntaxException {
         BufferAllocator allocatorFE = new RootAllocator(Integer.MAX_VALUE);
         final Location clientLocationFE = new Location(
@@ -64,22 +68,30 @@ public class FlightSqlClient {
                 configuration.sql,
                 credentialCallOption);
         final FlightInfo info = 
preparedStatement.execute(credentialCallOption);
-        return new FlightInfoResult<>(info, credentialCallOption, 
preparedStatement);
+        return new FlightInfoResult<>(info, credentialCallOption, 
preparedStatement, sqlClinetFE);
     }
 
     /**
      * Use the correct Bearertoken and the correct Ticket, and the expected 
return result is normal.
+     * An endpoint with no location is a result the FE holds itself (a SHOW, a 
SET, ... under the FE config
+     * arrow_flight_fe_result_empty_location): it is read on the FE client 
that issued the ticket, because a new
+     * connection to the same address can reach another FE (behind a load 
balancer, say), where the session and
+     * its bearer token do not exist.
      */
-    public static void getResultFromDorisBe(FlightInfo info, Ticket ticket, 
CredentialCallOption credentialCallOption)
-            throws Exception {
-        final Location locationBE = 
info.getEndpoints().get(0).getLocations().get(0);
-        // 连接 BE Arrow Flight Server
-        BufferAllocator allocatorBE = new RootAllocator(Integer.MAX_VALUE);
-        FlightClient clientBE = FlightClient.builder(allocatorBE, 
locationBE).build();
-        org.apache.arrow.flight.sql.FlightSqlClient sqlClinetBE = new 
org.apache.arrow.flight.sql.FlightSqlClient(
-                clientBE);
+    public static void getResultFromDorisBe(FlightInfo info, Ticket ticket, 
CredentialCallOption credentialCallOption,
+            org.apache.arrow.flight.sql.FlightSqlClient sqlClientFE) throws 
Exception {
+        final List<Location> locations = 
info.getEndpoints().get(0).getLocations();
+        final org.apache.arrow.flight.sql.FlightSqlClient sqlClient;
+        if (locations.isEmpty()) {
+            sqlClient = sqlClientFE;
+        } else {
+            // 连接 BE Arrow Flight Server
+            BufferAllocator allocatorBE = new RootAllocator(Integer.MAX_VALUE);
+            FlightClient clientBE = FlightClient.builder(allocatorBE, 
locations.get(0)).build();
+            sqlClient = new 
org.apache.arrow.flight.sql.FlightSqlClient(clientBE);
+        }
 
-        FlightStream stream = sqlClinetBE.getStream(ticket, 
credentialCallOption);
+        FlightStream stream = sqlClient.getStream(ticket, 
credentialCallOption);
         int rowCount = 0;
         int batchCount = 0;
         while (stream.next()) {
@@ -122,13 +134,14 @@ public class FlightSqlClient {
             System.out.println("FlightSqlClient > getFlightInfoFromDorisFe");
             var flightInfo = getFlightInfoFromDorisFe(configuration);
             getResultFromDorisBe(flightInfo.first(), 
flightInfo.first().getEndpoints().get(0).getTicket(),
-                    flightInfo.second());
+                    flightInfo.second(), flightInfo.fourth());
             System.out.println();
 
             System.out.println(
                     "FlightSqlClient > constructDummyFlightInfo, don't be 
afraid! expected to get error `INVALID_ARGUMENT: Malformed ticket`");
             var dummyFlightInfo = constructDummyFlightInfo();
-            getResultFromDorisBe(flightInfo.first(), dummyFlightInfo.first(), 
dummyFlightInfo.second());
+            getResultFromDorisBe(flightInfo.first(), dummyFlightInfo.first(), 
dummyFlightInfo.second(),
+                    flightInfo.fourth());
             System.out.println();
 
             flightInfo.third().close(flightInfo.second());


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to