Skip to content

Commit

Permalink
branch-2.1: [fix](show)show tables should be case insensitive when lo…
Browse files Browse the repository at this point in the history
…werCaseTableNames is 1 or 2. #46030 (#46058)

Cherry-picked from #46030

Co-authored-by: James <[email protected]>
  • Loading branch information
github-actions[bot] and Jibing-Li authored Dec 26, 2024
1 parent 25edcd2 commit 8d3e8fe
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
13 changes: 9 additions & 4 deletions fe/fe-core/src/main/java/org/apache/doris/qe/ShowExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -861,8 +861,7 @@ private void handleShowTable() throws AnalysisException {
.getDbOrAnalysisException(showTableStmt.getDb());
PatternMatcher matcher = null;
if (showTableStmt.getPattern() != null) {
matcher = PatternMatcherWrapper.createMysqlPattern(showTableStmt.getPattern(),
CaseSensibility.TABLE.getCaseSensibility());
matcher = PatternMatcherWrapper.createMysqlPattern(showTableStmt.getPattern(), isShowTablesCaseSensitive());
}
for (TableIf tbl : db.getTables()) {
if (tbl.getName().startsWith(FeConstants.TEMP_MATERIZLIZE_DVIEW_PREFIX)) {
Expand Down Expand Up @@ -901,6 +900,13 @@ private void handleShowTable() throws AnalysisException {
resultSet = new ShowResultSet(showTableStmt.getMetaData(), rows);
}

public boolean isShowTablesCaseSensitive() {
if (GlobalVariable.lowerCaseTableNames == 0) {
return CaseSensibility.TABLE.getCaseSensibility();
}
return false;
}

// Show table status statement.
private void handleShowTableStatus() throws AnalysisException {
ShowTableStatusStmt showStmt = (ShowTableStatusStmt) stmt;
Expand All @@ -911,8 +917,7 @@ private void handleShowTableStatus() throws AnalysisException {
if (db != null) {
PatternMatcher matcher = null;
if (showStmt.getPattern() != null) {
matcher = PatternMatcherWrapper.createMysqlPattern(showStmt.getPattern(),
CaseSensibility.TABLE.getCaseSensibility());
matcher = PatternMatcherWrapper.createMysqlPattern(showStmt.getPattern(), isShowTablesCaseSensitive());
}
for (TableIf table : db.getTables()) {
if (matcher != null && !matcher.match(table.getName())) {
Expand Down
13 changes: 13 additions & 0 deletions fe/fe-core/src/test/java/org/apache/doris/qe/ShowExecutorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.apache.doris.catalog.Table;
import org.apache.doris.catalog.TableIf.TableType;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.CaseSensibility;
import org.apache.doris.common.PatternMatcher;
import org.apache.doris.common.UserException;
import org.apache.doris.common.jmockit.Deencapsulation;
Expand Down Expand Up @@ -683,4 +684,16 @@ public void testShowSqlBlockRule() throws AnalysisException {
Assert.assertEquals("Global", resultSet.getMetaData().getColumn(6).getName());
Assert.assertEquals("Enable", resultSet.getMetaData().getColumn(7).getName());
}

@Test
public void testIsShowTablesCaseSensitive() {
ShowSqlBlockRuleStmt stmt = new ShowSqlBlockRuleStmt("test_case_sensitive");
ShowExecutor executor = new ShowExecutor(ctx, stmt);
GlobalVariable.lowerCaseTableNames = 0;
Assert.assertEquals(CaseSensibility.TABLE.getCaseSensibility(), executor.isShowTablesCaseSensitive());
GlobalVariable.lowerCaseTableNames = 1;
Assert.assertEquals(false, executor.isShowTablesCaseSensitive());
GlobalVariable.lowerCaseTableNames = 2;
Assert.assertEquals(false, executor.isShowTablesCaseSensitive());
}
}

0 comments on commit 8d3e8fe

Please sign in to comment.