Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -403,9 +403,9 @@ private void buildDbStatsOutput(long quota, long replicaQuota) {
DebugUtil.printByteWithUnit(totalRemoteInvertedSize),
DebugUtil.printByteWithUnit(totalBinlogSize)));
totalRows.add(Arrays.asList("Quota", String.valueOf(replicaQuota),
DebugUtil.printByteWithUnit(quota), "", "", "", "", ""));
DebugUtil.printByteWithUnit(quota), "", "", "", "", "", ""));
totalRows.add(Arrays.asList("Left", String.valueOf(replicaCountLeft),
DebugUtil.printByteWithUnit(left), "", "", "", "", ""));
DebugUtil.printByteWithUnit(left), "", "", "", "", "", ""));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.apache.doris.catalog.info.TableNameInfo;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.Pair;
import org.apache.doris.common.util.DebugUtil;
import org.apache.doris.datasource.InternalCatalog;
import org.apache.doris.mysql.privilege.AccessControllerManager;
import org.apache.doris.mysql.privilege.PrivPredicate;
Expand Down Expand Up @@ -144,6 +145,58 @@ public void testValidateShowAllDataNormal() throws Exception {
"SHOW DATA should contain BinlogSize column");
}

@Test
public void testValidateShowDetailedDataRowsMatchMetaData() throws Exception {
Mockito.when(connectContext.getDatabase()).thenReturn(CatalogMocker.TEST_DB_NAME);
Mockito.when(connectContext.isSkipAuth()).thenReturn(true);
mockedEnv.when(Env::getCurrentInvertedIndex).thenReturn(Mockito.mock(TabletInvertedIndex.class));
Database mockDb = CatalogMocker.mockDb();
Mockito.when(catalog.getDbOrAnalysisException(Mockito.anyString())).thenReturn(mockDb);
Mockito.when(accessControllerManager.checkTblPriv(
Mockito.nullable(ConnectContext.class), Mockito.anyString(), Mockito.anyString(),
Mockito.anyString(), Mockito.any(PrivPredicate.class))).thenReturn(true);

ShowDataCommand command = new ShowDataCommand(null, null, new HashMap<>(), true);

ShowResultSet rs = command.doRun(connectContext, null);
int columnCount = rs.getMetaData().getColumnCount();
Assertions.assertEquals(9, columnCount);
for (List<String> row : rs.getResultRows()) {
Assertions.assertEquals(columnCount, row.size());
}
}

@Test
public void testValidateShowDetailedDataRowsMatchMetaDataForEmptyDb() throws Exception {
Mockito.when(connectContext.getDatabase()).thenReturn(CatalogMocker.TEST_DB_NAME);
Mockito.when(catalog.getDbOrAnalysisException(Mockito.anyString())).thenReturn(database);
Mockito.when(accessControllerManager.checkGlobalPriv(connectContext, PrivPredicate.ADMIN)).thenReturn(true);
Mockito.when(database.getTables()).thenReturn(ImmutableList.of());
Mockito.when(database.getDataQuota()).thenReturn(1024L);
Mockito.when(database.getReplicaQuota()).thenReturn(10L);
Mockito.doNothing().when(database).readLock();
Mockito.doNothing().when(database).readUnlock();

ShowDataCommand command = new ShowDataCommand(null, null, new HashMap<>(), true);

ShowResultSet rs = command.doRun(connectContext, null);
List<List<String>> rows = rs.getResultRows();

Assertions.assertEquals(9, rs.getMetaData().getColumnCount());
Assertions.assertEquals(3, rows.size());
Assertions.assertEquals(ImmutableList.of("Total", "0", DebugUtil.printByteWithUnit(0L),
DebugUtil.printByteWithUnit(0L), DebugUtil.printByteWithUnit(0L), DebugUtil.printByteWithUnit(0L),
DebugUtil.printByteWithUnit(0L), DebugUtil.printByteWithUnit(0L),
DebugUtil.printByteWithUnit(0L)), rows.get(0));
Assertions.assertEquals(ImmutableList.of("Quota", "10", DebugUtil.printByteWithUnit(1024L),
"", "", "", "", "", ""), rows.get(1));
Assertions.assertEquals(ImmutableList.of("Left", "10", DebugUtil.printByteWithUnit(1024L),
"", "", "", "", "", ""), rows.get(2));
for (List<String> row : rows) {
Assertions.assertEquals(rs.getMetaData().getColumnCount(), row.size());
}
}

@Test
public void testValidateShowAllDataGetAllDbStats() throws Exception {
CatalogRecycleBin recycleBin = new CatalogRecycleBin();
Expand Down
41 changes: 41 additions & 0 deletions regression-test/suites/show_p0/test_show_data_all_db.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// 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_data_all_db") {
def dbName = "test_show_data_all_db";
def tableName = "test_show_data_all_tb";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new regression is an ordinary single-table case, but it defines def tableName and interpolates it through the DROP/CREATE/INSERT statements. The repo testing standard in AGENTS.md asks these simple table names to be hardcoded in the SQL instead, so please replace the variable with the literal test_show_data_all_tb.

sql """DROP DATABASE IF EXISTS ${dbName}"""
sql """CREATE DATABASE IF NOT EXISTS ${dbName}"""
sql """USE ${dbName}"""
sql """DROP TABLE IF EXISTS ${tableName}"""
sql """CREATE TABLE IF NOT EXISTS ${tableName} (
`id` int(11) NOT NULL,
`name` varchar(50) NOT NULL
) ENGINE=OLAP
UNIQUE KEY(`id`)
DISTRIBUTED BY HASH(`id`) BUCKETS 5
PROPERTIES (
"replication_num" = "1"
)"""
sql """insert into ${tableName} values(1, "test1"), (2, "test2"), (3, "test3");"""
def result = sql"""show data all;"""
logger.info("show data result:${result}");
assertTrue(result.size() > 0);
for (int i = 0; i < result.size(); i++) {
assertTrue(result[i].size() == 9);
}
}
Loading