Skip to content

Commit

Permalink
[Enhancement] (nereids)implement showColumnStatsCommand in nereids
Browse files Browse the repository at this point in the history
  • Loading branch information
msridhar78 committed Dec 18, 2024
1 parent 011d393 commit c52a5c5
Show file tree
Hide file tree
Showing 7 changed files with 531 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ statementBase
| supportedRecoverStatement #supportedRecoverStatementAlias
| supportedAdminStatement #supportedAdminStatementAlias
| supportedUseStatement #supportedUseStatementAlias
| supportedStatsStatement #supportedStatsStatementAlias
| unsupportedStatement #unsupported
;

Expand Down Expand Up @@ -703,6 +704,11 @@ unsupportedDropStatement
| DROP STAGE (IF EXISTS)? name=identifier #dropStage
;

supportedStatsStatement
: SHOW COLUMN CACHED? STATS tableName=multipartIdentifier
columnList=identifierList? partitionSpec? #showColumnStats
;

unsupportedStatsStatement
: ANALYZE TABLE name=multipartIdentifier partitionSpec?
columns=identifierList? (WITH analyzeProperties)* propertyClause? #analyzeTable
Expand All @@ -723,8 +729,6 @@ unsupportedStatsStatement
partitionSpec? columnList=identifierList? #showTableStats
| SHOW TABLE STATS tableId=INTEGER_VALUE #showTableStats
| SHOW INDEX STATS tableName=multipartIdentifier indexId=identifier #showIndexStats
| SHOW COLUMN CACHED? STATS tableName=multipartIdentifier
columnList=identifierList? partitionSpec? #showColumnStats
| SHOW COLUMN HISTOGRAM tableName=multipartIdentifier
columnList=identifierList #showColumnHistogramStats
| SHOW AUTO? ANALYZE tableName=multipartIdentifier? wildWhere? #showAnalyze
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ public long getCount() {

@Override
public void analyze(Analyzer analyzer) throws AnalysisException {
analyze();
}

public void analyze() throws AnalysisException {
if (isStar && count > 0) {
throw new AnalysisException("All partition and partition count couldn't be set at the same time.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.apache.doris.analysis.ColumnNullableType;
import org.apache.doris.analysis.DbName;
import org.apache.doris.analysis.EncryptKeyName;
import org.apache.doris.analysis.PartitionNames;
import org.apache.doris.analysis.PassVar;
import org.apache.doris.analysis.SetType;
import org.apache.doris.analysis.StorageBackend;
Expand Down Expand Up @@ -243,6 +244,7 @@
import org.apache.doris.nereids.DorisParser.ShowBrokerContext;
import org.apache.doris.nereids.DorisParser.ShowCharsetContext;
import org.apache.doris.nereids.DorisParser.ShowCollationContext;
import org.apache.doris.nereids.DorisParser.ShowColumnStatsContext;
import org.apache.doris.nereids.DorisParser.ShowConfigContext;
import org.apache.doris.nereids.DorisParser.ShowConstraintContext;
import org.apache.doris.nereids.DorisParser.ShowCreateCatalogContext;
Expand Down Expand Up @@ -558,6 +560,7 @@
import org.apache.doris.nereids.trees.plans.commands.ShowBrokerCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowCharsetCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowCollationCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowColumnStatsCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowConfigCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowConstraintsCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowCreateCatalogCommand;
Expand Down Expand Up @@ -4541,6 +4544,42 @@ private Expression getWildWhere(DorisParser.WildWhereContext ctx) {
}
}

@Override
public LogicalPlan visitShowColumnStats(ShowColumnStatsContext ctx) {
List<String> tableNameParts = visitMultipartIdentifier(ctx.tableName);
List<String> colNames = ctx.columnList == null ? ImmutableList.of() : visitIdentifierList(ctx.columnList);
PartitionNames partitionNames = parsePartitionSpec(ctx.partitionSpec());
boolean isCached = ctx.CACHED() != null;

return new ShowColumnStatsCommand(new TableNameInfo(tableNameParts), colNames, partitionNames, isCached);
}

private PartitionNames parsePartitionSpec(PartitionSpecContext ctx) {
if (ctx == null) {
return null;
}

boolean isTemp = ctx.TEMPORARY() != null;

/* Case 1: PARTITION or PARTITIONS with identifier list */
if (ctx.partitions != null) {
List<String> partitionNames = visitIdentifierList(ctx.partitions);
return new PartitionNames(isTemp, partitionNames);
}

/* Case 2: PARTITION with a single identifier */
if (ctx.partition != null) {
return new PartitionNames(isTemp, Collections.singletonList(ctx.partition.getText()));
}

/* Case 3: PARTITION or PARTITIONS (*) - star/auto-detect partitions */
if (ctx.ASTERISK() != null) {
return new PartitionNames(true); // isStar = true
}

throw new IllegalArgumentException("Invalid partition specification.");
}

@Override
public ShowViewCommand visitShowView(ShowViewContext ctx) {
List<String> tableNameParts = visitMultipartIdentifier(ctx.tableName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ public enum PlanType {
SHOW_BROKER_COMMAND,
SHOW_CHARSET_COMMAND,
SHOW_COLLATION_COMMAND,
SHOW_COLUMN_STATS_COMMAND,
SHOW_CONFIG_COMMAND,
SHOW_CREATE_CATALOG_COMMAND,
SHOW_CREATE_DATABASE_COMMAND,
Expand Down
Loading

0 comments on commit c52a5c5

Please sign in to comment.