Skip to content

Commit

Permalink
[fix](show_proc) fix show statistic proc dir to ensure that result on…
Browse files Browse the repository at this point in the history
…ly contains dbs in internal catalog (#26254) (#26763)

backport #26254
Co-authored-by: caiconghui <55968745+caiconghui@users.noreply.github.com>
  • Loading branch information
morningman authored Nov 10, 2023
1 parent cf9a209 commit 7fd0195
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public StatisticProcNode(Env env) {

@Override
public ProcResult fetchResult() throws AnalysisException {
List<DBStatistic> statistics = env.getCatalogMgr().getDbIds().parallelStream()
List<DBStatistic> statistics = env.getInternalCatalog().getDbIds().parallelStream()
// skip information_schema database
.flatMap(id -> Stream.of(id == 0 ? null : env.getCatalogMgr().getDbNullable(id)))
.filter(Objects::nonNull).map(DBStatistic::new)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,22 +228,6 @@ public DatabaseIf getDbNullable(long dbId) {
return null;
}

public List<Long> getDbIds() {
List<Long> dbIds = Lists.newArrayList();
for (CatalogIf catalog : nameToCatalog.values()) {
dbIds.addAll(catalog.getDbIds());
}
return dbIds;
}

public List<String> getDbNames() {
List<String> dbNames = Lists.newArrayList();
for (CatalogIf catalog : nameToCatalog.values()) {
dbNames.addAll(catalog.getDbNames());
}
return dbNames;
}

private void writeLock() {
lock.writeLock().lock();
}
Expand Down
45 changes: 45 additions & 0 deletions regression-test/suites/show_p0/test_show_statistic_proc.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// 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.

suite("test_show_statistic_proc", "show") {

sql """drop user if exists test_show_statistic_proc_user1"""

sql """create user test_show_statistic_proc_user1 identified by '12345'"""

sql """grant ADMIN_PRIV on *.*.* to test_show_statistic_proc_user1"""

sql """create database test_statistic_proc_db"""

def result1 = connect(user = 'test_show_statistic_proc_user1', password = '12345', url = context.config.jdbcUrl) {
sql """ show proc '/statistic' """
}
def result2 = connect(user = 'test_show_statistic_proc_user1', password = '12345', url = context.config.jdbcUrl) {
sql """ show databases """
}
assertEquals(result1.size(), result2.size())
assertEquals(result1[result1.size() - 1][1].toInteger(), result2.size() - 1)
def containsTargetDb = false
result1.each { row ->
if (row[1] == 'default_cluster:test_statistic_proc_db') {
containsTargetDb = true
return
}
}
assertTrue(containsTargetDb)
}

0 comments on commit 7fd0195

Please sign in to comment.