Skip to content

Commit

Permalink
[Enhancement] print partition info only in verbose mode for delta sca…
Browse files Browse the repository at this point in the history
…n node (#46077)

Signed-off-by: Youngwb <[email protected]>
  • Loading branch information
Youngwb authored May 23, 2024
1 parent 5b1cebb commit 6df159a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@
import java.util.concurrent.atomic.AtomicLong;
import java.util.stream.Collectors;

import static com.starrocks.thrift.TExplainLevel.VERBOSE;

public class DeltaLakeScanNode extends ScanNode {
private static final Logger LOG = LogManager.getLogger(DeltaLakeScanNode.class);
private final AtomicLong partitionIdGen = new AtomicLong(0L);
Expand Down Expand Up @@ -260,20 +258,9 @@ protected String getNodeExplainString(String prefix, TExplainLevel detailLevel)
getExplainString(scanNodePredicates.getMinMaxConjuncts())).append("\n");
}

List<String> partitionNames = GlobalStateMgr.getCurrentState().getMetadataMgr().listPartitionNames(
deltaLakeTable.getCatalogName(), deltaLakeTable.getDbName(), deltaLakeTable.getTableName());

output.append(prefix).append(
String.format("partitions=%s/%s", scanNodePredicates.getSelectedPartitionIds().size(),
partitionNames.size() == 0 ? 1 : partitionNames.size()));
output.append(prefix).append(String.format("cardinality=%s", cardinality));
output.append("\n");

// TODO: support it in verbose
if (detailLevel != VERBOSE) {
output.append(prefix).append(String.format("cardinality=%s", cardinality));
output.append("\n");
}

output.append(prefix).append(String.format("avgRowSize=%s", avgRowSize));
output.append("\n");

Expand All @@ -285,6 +272,14 @@ protected String getNodeExplainString(String prefix, TExplainLevel detailLevel)
.append(String.format("Pruned type: %d <-> [%s]\n", slotDescriptor.getId().asInt(), type));
}
}

List<String> partitionNames = GlobalStateMgr.getCurrentState().getMetadataMgr().listPartitionNames(
deltaLakeTable.getCatalogName(), deltaLakeTable.getDbName(), deltaLakeTable.getTableName());

output.append(prefix).append(
String.format("partitions=%s/%s", scanNodePredicates.getSelectedPartitionIds().size(),
partitionNames.size() == 0 ? 1 : partitionNames.size()));
output.append("\n");
}

return output.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
import com.starrocks.credential.CloudConfiguration;
import com.starrocks.credential.CloudConfigurationFactory;
import com.starrocks.server.GlobalStateMgr;
import com.starrocks.thrift.TExplainLevel;
import mockit.Expectations;
import mockit.Mocked;
import org.junit.Assert;
import org.junit.Test;

import java.util.HashMap;
Expand All @@ -48,4 +50,36 @@ public void testInit(@Mocked GlobalStateMgr globalStateMgr,
desc.setTable(table);
DeltaLakeScanNode scanNode = new DeltaLakeScanNode(new PlanNodeId(0), desc, "XXX");
}

@Test
public void testNodeExplain(@Mocked GlobalStateMgr globalStateMgr, @Mocked CatalogConnector connector,
@Mocked DeltaLakeTable table) {
String catalogName = "delta0";
CloudConfiguration cloudConfiguration = CloudConfigurationFactory.
buildCloudConfigurationForStorage(new HashMap<>());
new Expectations() {
{
GlobalStateMgr.getCurrentState().getConnectorMgr().getConnector(catalogName);
result = connector;
minTimes = 0;

connector.getMetadata().getCloudConfiguration();
result = cloudConfiguration;
minTimes = 0;

table.getCatalogName();
result = catalogName;
minTimes = 0;

table.getName();
result = "table0";
minTimes = 0;
}
};
TupleDescriptor desc = new TupleDescriptor(new TupleId(0));
desc.setTable(table);
DeltaLakeScanNode scanNode = new DeltaLakeScanNode(new PlanNodeId(0), desc, "Delta Scan Node");
Assert.assertFalse(scanNode.getNodeExplainString("", TExplainLevel.NORMAL).contains("partitions"));
Assert.assertTrue(scanNode.getNodeExplainString("", TExplainLevel.VERBOSE).contains("partitions"));
}
}

0 comments on commit 6df159a

Please sign in to comment.