This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch branch-4.2
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-4.2 by this push:
new 00699492f90 branch-4.2: [fix](dcl) Support WHERE and LIKE in SHOW
CHARACTER SET (70706) (#70826)
00699492f90 is described below
commit 00699492f9074534e05b2e26ddfc10ccabe0a295
Author: 924060929 <[email protected]>
AuthorDate: Mon Nov 23 08:18:08 2026 +0800
branch-4.2: [fix](dcl) Support WHERE and LIKE in SHOW CHARACTER SET (70706)
(#70826)
cherry pick from #70706
---
.../trees/plans/commands/ShowCharsetCommand.java | 9 +++
.../java/org/apache/doris/qe/ConnectContext.java | 3 +
.../java/org/apache/doris/qe/StmtExecutor.java | 66 ++++++++++++++++++++--
.../plans/commands/ShowCharsetCommandTest.java | 56 +++++++++++-------
.../org/apache/doris/qe/ConnectContextTest.java | 6 ++
.../nereids_p0/show/test_show_charset_command.out | 3 +
.../show/test_show_charset_command.groovy | 2 +
7 files changed, 121 insertions(+), 24 deletions(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowCharsetCommand.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowCharsetCommand.java
index 5de3b644af1..8264dcb8fe8 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowCharsetCommand.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowCharsetCommand.java
@@ -20,6 +20,7 @@ package org.apache.doris.nereids.trees.plans.commands;
import org.apache.doris.catalog.Column;
import org.apache.doris.catalog.ScalarType;
import org.apache.doris.common.PatternMatcherWrapper;
+import org.apache.doris.common.Status;
import org.apache.doris.common.UserException;
import org.apache.doris.nereids.StatementContext;
import org.apache.doris.nereids.analyzer.UnboundResultSink;
@@ -116,9 +117,17 @@ public class ShowCharsetCommand extends ShowCommand {
adapter.setOrigStmt(executor.getOriginStmt());
StmtExecutor internalExecutor = new StmtExecutor(internalContext,
adapter);
internalContext.setExecutor(internalExecutor);
+ executor.setCancelDelegate(internalExecutor::cancel);
+ // Publish the delegate before checking for cancellation that
arrived before publication.
+ Status cancelReason = executor.getPendingCancelReason();
+ if (cancelReason != null) {
+ throw new UserException(cancelReason.getErrorMsg());
+ }
return internalExecutor.executeInternalQuery().stream()
.map(ResultRow::getValues)
.collect(Collectors.toList());
+ } finally {
+ executor.clearCancelDelegate();
}
}
diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/ConnectContext.java
b/fe/fe-core/src/main/java/org/apache/doris/qe/ConnectContext.java
index ec44926873d..174cf82c10e 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/qe/ConnectContext.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/qe/ConnectContext.java
@@ -577,6 +577,9 @@ public class ConnectContext {
lastQueryId = parent.lastQueryId;
computeGroup = parent.computeGroup;
cloudCluster = parent.cloudCluster;
+ defaultCatalog = parent.defaultCatalog;
+ currentDb = parent.currentDb;
+ currentDbId = parent.currentDbId;
// Borrow the caller's temporary-table namespace without registering a
new session.
sessionId = parent.sessionId;
}
diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java
b/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java
index 2f43c49db93..3d81cd40eb4 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java
@@ -147,7 +147,6 @@ import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.google.protobuf.ByteString;
-import lombok.Setter;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
@@ -165,6 +164,8 @@ import java.util.Set;
import java.util.UUID;
import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicLong;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.function.Consumer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
@@ -192,8 +193,11 @@ public class StmtExecutor {
private List<List<String>> changedSessionVarsForAudit;
private ProfileType profileType = ProfileType.QUERY;
- @Setter
private volatile Coordinator coord = null;
+ // A statement can be cancelled while it is still planning and has no
coordinator yet.
+ // Keep this state scoped to the coordinator publication handoff: other
execution targets
+ // retain their existing cancellation contracts.
+ private final AtomicReference<Status> pendingCoordinatorCancelReason = new
AtomicReference<>();
// Arrow Flight SQL: when true, this query's coordinator is kept alive
past GetFlightInfo and
// is finalized later by ConnectContext (see #62259), so the eager close
in executeAndSendResult
// is skipped.
@@ -203,6 +207,11 @@ public class StmtExecutor {
// ConnectContext.getExecTimeoutS() later would report the session value
instead.
private volatile int deferredExecTimeoutS = -1;
private MasterOpExecutor masterOpExecutor = null;
+ // Optional forward target for cancellations issued on this executor:
statements that
+ // spawn a nested internal executor with its own query id (e.g. SHOW
CHARACTER SET WHERE)
+ // register it here so Ctrl+C / KILL QUERY / statement timeout on the
outer statement also
+ // cancel the inner work, which those paths cannot address directly.
+ private volatile Consumer<Status> cancelDelegate = null;
private RedirectStatus redirectStatus = null;
private Planner planner;
private boolean isProxy;
@@ -1228,7 +1237,26 @@ public class StmtExecutor {
}
// Because this is called by other thread
+ /**
+ * Routes cancellation of this (outer) executor to a nested internal
executor, e.g. the
+ * internal filter query executor of SHOW CHARACTER SET WHERE. The
delegate receives the same
+ * cancel reason and must be cleared once the nested work is done.
+ */
+ public void setCancelDelegate(Consumer<Status> cancelDelegate) {
+ this.cancelDelegate = cancelDelegate;
+ }
+
+ public void clearCancelDelegate() {
+ this.cancelDelegate = null;
+ }
+
public void cancel(Status cancelReason, boolean needWaitCancelComplete) {
+ pendingCoordinatorCancelReason.compareAndSet(null, cancelReason);
+ Status coordinatorCancelReason = pendingCoordinatorCancelReason.get();
+ Consumer<Status> delegate = cancelDelegate;
+ if (delegate != null) {
+ delegate.accept(cancelReason);
+ }
if (masterOpExecutor != null) {
try {
masterOpExecutor.cancel();
@@ -1244,7 +1272,7 @@ public class StmtExecutor {
}
Coordinator coordRef = coord;
if (coordRef != null) {
- coordRef.cancel(cancelReason);
+ coordRef.cancel(coordinatorCancelReason);
}
if (mysqlLoadId != null) {
Env.getCurrentEnv().getLoadManager().getMysqlLoadManager().cancelMySqlLoad(mysqlLoadId);
@@ -1255,6 +1283,22 @@ public class StmtExecutor {
}
}
+ public void setCoord(Coordinator coordinator) {
+ coord = coordinator;
+ Status cancelReason = pendingCoordinatorCancelReason.get();
+ if (coordinator != null && cancelReason != null) {
+ coordinator.cancel(cancelReason);
+ }
+ }
+
+ /**
+ * The first terminal status delivered to this executor, or null when it
has not been cancelled. Sticky:
+ * a later cancellation never replaces the first one.
+ */
+ public Status getPendingCancelReason() {
+ return pendingCoordinatorCancelReason.get();
+ }
+
public void cancel(Status cancelReason) {
cancel(cancelReason, true);
}
@@ -2173,12 +2217,24 @@ public class StmtExecutor {
LOG.warn("Failed to run internal SQL: {}", originStmt, e);
throw new RuntimeException("Failed to execute internal SQL. "
+ Util.getRootCauseMessage(e), e);
}
+ if (context.supportHandleByFe()) {
+ Optional<ResultSet> resultSet =
planner.handleQueryInFe(parsedStmt);
+ if (resultSet.isPresent()) {
+ isHandleQueryInFe = true;
+ if (context.getSessionVariable().enableProfile() &&
profile != null) {
+
profile.getSummaryProfile().setExecutedByFrontend(true);
+ }
+ return resultSet.get().getResultRows().stream()
+ .map(ResultRow::new)
+ .collect(Collectors.toList());
+ }
+ }
RowBatch batch;
if (Config.enable_collect_internal_query_profile) {
context.getSessionVariable().enableProfile = true;
}
- coord = EnvFactory.getInstance().createCoordinator(context,
- planner, context.getStatsErrorEstimator());
+ setCoord(EnvFactory.getInstance().createCoordinator(context,
+ planner, context.getStatsErrorEstimator()));
profile.addExecutionProfile(coord.getExecutionProfile());
try {
QeProcessorImpl.INSTANCE.registerQuery(context.queryId(),
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/ShowCharsetCommandTest.java
b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/ShowCharsetCommandTest.java
index ffab066b499..70419bd28a0 100644
---
a/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/ShowCharsetCommandTest.java
+++
b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/ShowCharsetCommandTest.java
@@ -17,17 +17,19 @@
package org.apache.doris.nereids.trees.plans.commands;
+import org.apache.doris.common.Status;
+import org.apache.doris.common.UserException;
import org.apache.doris.nereids.StatementContext;
import org.apache.doris.nereids.parser.NereidsParser;
import org.apache.doris.qe.ConnectContext;
import org.apache.doris.qe.ShowResultSet;
import org.apache.doris.qe.StmtExecutor;
+import org.apache.doris.thrift.TStatusCode;
import org.apache.doris.thrift.TUniqueId;
import org.apache.doris.utframe.TestWithFeService;
import com.google.common.collect.ImmutableList;
import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import java.util.List;
@@ -74,10 +76,6 @@ class ShowCharsetCommandTest extends TestWithFeService {
Assertions.assertTrue(execute("SHOW CHARSET LIKE
''").getResultRows().isEmpty());
}
- // The WHERE filter runs as an internal query over a one-row relation. A
FE unit test has no
- // backend to execute that plan because branch-4.x cannot compute one-row
relations in the
- // frontend, so only the regression suite test_show_charset_command
verifies the row results.
- @Disabled("Needs a backend to execute the internal one-row-relation query;
see regression test")
@Test
void testWhere() throws Exception {
Assertions.assertEquals(EXPECTED_ROWS,
@@ -94,10 +92,6 @@ class ShowCharsetCommandTest extends TestWithFeService {
execute("SHOW CHARSET WHERE upper(Charset) = 'UTF8MB4' AND
Maxlen + 1 = 5").getResultRows());
}
- // The WHERE filter runs as an internal query over a one-row relation. A
FE unit test has no
- // backend to execute that plan because branch-4.x cannot compute one-row
relations in the
- // frontend, so only the regression suite test_show_charset_command
verifies the row results.
- @Disabled("Needs a backend to execute the internal one-row-relation query;
see regression test")
@Test
void testNullAndConstantPredicates() throws Exception {
Assertions.assertEquals(EXPECTED_ROWS, execute("SHOW CHARSET WHERE
TRUE").getResultRows());
@@ -108,6 +102,20 @@ class ShowCharsetCommandTest extends TestWithFeService {
execute("SHOW CHARSET WHERE Charset IS NOT
NULL").getResultRows());
}
+ @Test
+ void testCancelledBeforeFilterStarts() {
+ String sql = "SHOW CHARSET WHERE TRUE";
+ StmtExecutor executor = new StmtExecutor(connectContext, sql);
+ ShowCharsetCommand command = (ShowCharsetCommand) new
NereidsParser().parseSingle(sql);
+ Status reason = new Status(TStatusCode.CANCELLED, "cancelled before
SHOW filter starts");
+ executor.cancel(reason, false);
+
+ UserException exception = Assertions.assertThrows(UserException.class,
+ () -> command.doRun(connectContext, executor));
+ Assertions.assertEquals(reason.getErrorMsg(),
exception.getDetailMessage());
+ Assertions.assertSame(connectContext, ConnectContext.get());
+ }
+
@Test
void testUnknownColumn() {
RuntimeException exception =
Assertions.assertThrows(RuntimeException.class,
@@ -122,12 +130,16 @@ class ShowCharsetCommandTest extends TestWithFeService {
String originalCollation =
connectContext.getSessionVariable().collationConnection;
try {
connectContext.getSessionVariable().setEnableSqlCache(true);
+ Assertions.assertEquals(EXPECTED_ROWS, execute("SHOW CHARSET WHERE
TRUE").getResultRows());
connectContext.getSessionVariable().charsetServer = "test_charset";
connectContext.getSessionVariable().collationConnection =
"test_collation";
List<List<String>> expected = execute("SHOW
CHARSET").getResultRows();
Assertions.assertEquals(expected, execute("SHOW CHARSET LIKE
'test_%'").getResultRows());
+ Assertions.assertEquals(expected, execute("SHOW CHARSET WHERE
TRUE").getResultRows());
Assertions.assertTrue(connectContext.getSessionVariable().isEnableSqlCache());
- Assertions.assertTrue(execute("SHOW CHARSET LIKE
'utf8%'").getResultRows().isEmpty());
+ Assertions.assertEquals(expected, execute("SHOW CHARSET WHERE
Charset = 'test_charset' "
+ + "AND `Default collation` =
'test_collation'").getResultRows());
+ Assertions.assertTrue(execute("SHOW CHARSET WHERE Charset =
'utf8mb4'").getResultRows().isEmpty());
} finally {
connectContext.getSessionVariable().setEnableSqlCache(originalEnableSqlCache);
connectContext.getSessionVariable().charsetServer =
originalCharset;
@@ -135,15 +147,21 @@ class ShowCharsetCommandTest extends TestWithFeService {
}
}
- @Disabled("Needs a backend to execute the internal one-row-relation query;
see regression test")
@Test
- void testWhereSessionValues() throws Exception {
- connectContext.getSessionVariable().charsetServer = "test_charset";
- connectContext.getSessionVariable().collationConnection =
"test_collation";
- List<List<String>> expected = execute("SHOW CHARSET").getResultRows();
- Assertions.assertEquals(expected, execute("SHOW CHARSET WHERE
TRUE").getResultRows());
- Assertions.assertEquals(expected, execute("SHOW CHARSET WHERE Charset
= 'test_charset' "
- + "AND `Default collation` =
'test_collation'").getResultRows());
- Assertions.assertTrue(execute("SHOW CHARSET WHERE Charset =
'utf8mb4'").getResultRows().isEmpty());
+ void testWherePreservesDatabaseAndCatalogNamespace() throws Exception {
+ String originalCatalog = connectContext.getDefaultCatalog();
+ String originalDb = connectContext.getDatabase();
+ try {
+ connectContext.changeDefaultCatalog("internal");
+ connectContext.setDatabase("test_namespace_db");
+ Assertions.assertEquals(EXPECTED_ROWS,
+ execute("SHOW CHARSET WHERE DATABASE() =
'test_namespace_db' AND CURRENT_CATALOG() = 'internal'")
+ .getResultRows());
+ Assertions.assertTrue(
+ execute("SHOW CHARSET WHERE DATABASE() =
'other_db'").getResultRows().isEmpty());
+ } finally {
+ connectContext.changeDefaultCatalog(originalCatalog);
+ connectContext.setDatabase(originalDb);
+ }
}
}
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/qe/ConnectContextTest.java
b/fe/fe-core/src/test/java/org/apache/doris/qe/ConnectContextTest.java
index e87b47f7904..c968d096e67 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/qe/ConnectContextTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/qe/ConnectContextTest.java
@@ -93,6 +93,9 @@ public class ConnectContextTest {
SessionContext session = SessionContext.of("test-session",
new DelegatedCredential(DelegatedCredential.Type.ID_TOKEN,
"test-token"));
parent.setSessionContext(session);
+ parent.changeDefaultCatalog("external_catalog");
+ parent.currentDb = "test_db";
+ parent.currentDbId = 42L;
ConnectContext child = parent.createInternalQueryContext();
Assert.assertSame(session, child.getSessionContext());
@@ -101,6 +104,9 @@ public class ConnectContextTest {
Assert.assertNotSame(parent.getSessionVariable(),
child.getSessionVariable());
Assert.assertEquals(parent.getSessionVariable().getCharsetServer(),
child.getSessionVariable().getCharsetServer());
+ Assert.assertEquals("external_catalog", child.getDefaultCatalog());
+ Assert.assertEquals("test_db", child.getDatabase());
+ Assert.assertEquals(42L, child.getCurrentDbId());
}
@Test
diff --git a/regression-test/data/nereids_p0/show/test_show_charset_command.out
b/regression-test/data/nereids_p0/show/test_show_charset_command.out
index 28438b95d15..5b399b450cc 100644
--- a/regression-test/data/nereids_p0/show/test_show_charset_command.out
+++ b/regression-test/data/nereids_p0/show/test_show_charset_command.out
@@ -75,6 +75,9 @@ utf8mb4 UTF-8 Unicode utf8mb4_0900_bin 4
-- !select_limit_still_applies --
+-- !where_database --
+utf8mb4 UTF-8 Unicode utf8mb4_0900_bin 4
+
-- !prepared_match --
utf8mb4 UTF-8 Unicode utf8mb4_0900_bin 4
diff --git
a/regression-test/suites/nereids_p0/show/test_show_charset_command.groovy
b/regression-test/suites/nereids_p0/show/test_show_charset_command.groovy
index 4923cd05592..52552c36b54 100644
--- a/regression-test/suites/nereids_p0/show/test_show_charset_command.groovy
+++ b/regression-test/suites/nereids_p0/show/test_show_charset_command.groovy
@@ -61,6 +61,8 @@ suite("test_show_charset_command", "query,charset") {
order_qt_select_limit_still_applies "SELECT 1"
sql "SET sql_select_limit = DEFAULT"
+ order_qt_where_database "SHOW CHARSET WHERE DATABASE() =
'${context.dbName}' AND CURRENT_CATALOG() = 'internal'"
+
def url = getServerPrepareJdbcUrl(context.config.jdbcUrl, context.dbName,
false) +
"&emulateUnsupportedPstmts=false"
connect(context.config.jdbcUser, context.config.jdbcPassword, url) {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]