Skip to content

Commit 5e2988e

Browse files
author
peco-engineer-bot[bot]
committed
fix(csharp): address issue #525
1 parent 53c85d3 commit 5e2988e

3 files changed

Lines changed: 46 additions & 4 deletions

File tree

csharp/src/StatementExecution/MetadataCommands/MetadataCommandBase.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,24 @@ protected static string ConvertPattern(string? pattern)
9292
return result.ToString();
9393
}
9494

95+
/// <summary>
96+
/// Determines whether a catalog scope argument means "all catalogs".
97+
/// A null catalog, or the bare SQL-LIKE wildcard "%", both expand to every
98+
/// catalog. This keeps SEA in step with Thrift, where a "%" catalog enumerates
99+
/// all catalogs rather than matching a single (non-existent) catalog literally
100+
/// named "%". See issue #525.
101+
/// </summary>
102+
protected static bool IsAllCatalogsScope(string? catalog)
103+
{
104+
return catalog == null || catalog == "%";
105+
}
106+
95107
protected static void AppendCatalogScope(StringBuilder sql, string? catalog)
96108
{
97-
if (catalog == null)
109+
if (IsAllCatalogsScope(catalog))
98110
sql.Append(InAllCatalogs);
99111
else
100-
sql.Append(string.Format(InCatalogFormat, QuoteIdentifier(catalog)));
112+
sql.Append(string.Format(InCatalogFormat, QuoteIdentifier(catalog!)));
101113
}
102114
}
103115
}

csharp/src/StatementExecution/MetadataCommands/ShowSchemasCommand.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ public ShowSchemasCommand(string? catalog, string? schemaPattern = null)
3232
public override string Build()
3333
{
3434
var sql = new StringBuilder("SHOW SCHEMAS");
35-
if (_catalog == null)
35+
if (IsAllCatalogsScope(_catalog))
3636
sql.Append(InAllCatalogs);
3737
else
38-
sql.Append($" IN {QuoteIdentifier(_catalog)}");
38+
sql.Append($" IN {QuoteIdentifier(_catalog!)}");
3939
if (_schemaPattern != null)
4040
sql.Append(string.Format(LikeFormat, ConvertPattern(_schemaPattern)));
4141
return sql.ToString();

csharp/test/Unit/StatementExecution/ShowCommandTests.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,24 @@ public void ShowSchemas_CatalogWithBacktick()
6969
Assert.Equal("SHOW SCHEMAS IN `my``catalog`", new ShowSchemasCommand("my`catalog").Build());
7070
}
7171

72+
// Catalog "%" wildcard semantics (issue #525): a "%" catalog scope must mean
73+
// "all catalogs" on the SEA path, matching Thrift, rather than being quoted as
74+
// a literal identifier (`%`) that matches a non-existent catalog.
75+
76+
[Fact]
77+
public void ShowSchemas_PercentCatalog_UsesAllCatalogs()
78+
{
79+
Assert.Equal("SHOW SCHEMAS IN ALL CATALOGS", new ShowSchemasCommand("%").Build());
80+
}
81+
82+
[Fact]
83+
public void ShowSchemas_PercentCatalogWithSchemaPattern_UsesAllCatalogs()
84+
{
85+
Assert.Equal(
86+
"SHOW SCHEMAS IN ALL CATALOGS LIKE 'def*'",
87+
new ShowSchemasCommand("%", "def%").Build());
88+
}
89+
7290
// ShowTablesCommand
7391

7492
[Fact]
@@ -83,6 +101,18 @@ public void ShowTables_WithCatalog()
83101
Assert.Equal("SHOW TABLES IN CATALOG `main`", new ShowTablesCommand("main").Build());
84102
}
85103

104+
[Fact]
105+
public void ShowTables_PercentCatalog_UsesAllCatalogs()
106+
{
107+
Assert.Equal("SHOW TABLES IN ALL CATALOGS", new ShowTablesCommand("%").Build());
108+
}
109+
110+
[Fact]
111+
public void ShowColumns_PercentCatalog_UsesAllCatalogs()
112+
{
113+
Assert.Equal("SHOW COLUMNS IN ALL CATALOGS", new ShowColumnsCommand("%").Build());
114+
}
115+
86116
[Fact]
87117
public void ShowTables_WithCatalogAndSchema()
88118
{

0 commit comments

Comments
 (0)