Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug Fix]show partitions add absence column for filter columns check #8894

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -31,9 +31,12 @@
import com.starrocks.qe.ShowResultSetMetaData;
import com.starrocks.sql.ast.AstVisitor;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class ShowPartitionsStmt extends ShowStmt {

Expand All @@ -44,6 +47,18 @@ public class ShowPartitionsStmt extends ShowStmt {
public static final String FILTER_REPLICATION_NUM = "ReplicationNum";
public static final String FILTER_LAST_CONSISTENCY_CHECK_TIME = "LastConsistencyCheckTime";

public static final Set<String> FILTER_COLUMNS;
zhuxt2015 marked this conversation as resolved.
Show resolved Hide resolved

static {
FILTER_COLUMNS = new HashSet<>();
FILTER_COLUMNS.add(FILTER_PARTITION_ID);
FILTER_COLUMNS.add(FILTER_PARTITION_NAME);
FILTER_COLUMNS.add(FILTER_STATE);
FILTER_COLUMNS.add(FILTER_BUCKETS);
FILTER_COLUMNS.add(FILTER_REPLICATION_NUM);
FILTER_COLUMNS.add(FILTER_LAST_CONSISTENCY_CHECK_TIME);
}

private String dbName;
private String tableName;
private Expr whereClause;
Expand Down
Expand Up @@ -496,9 +496,8 @@ private void binaryPredicateHandler(Expr subExpr, String leftKey, boolean filter
throw new SemanticException("expression %s cast to datetime error: %s",
subExpr.getChild(1).toString(), e.getMessage());
}
} else if (!leftKey.equalsIgnoreCase(ShowPartitionsStmt.FILTER_PARTITION_ID) &&
!leftKey.equalsIgnoreCase(ShowPartitionsStmt.FILTER_BUCKETS) &&
!leftKey.equalsIgnoreCase(ShowPartitionsStmt.FILTER_REPLICATION_NUM)) {
} else if (ShowPartitionsStmt.FILTER_COLUMNS.stream()
.noneMatch(column -> column.equalsIgnoreCase(leftKey))) {
throw new SemanticException("Only the columns of PartitionId/PartitionName/" +
"State/Buckets/ReplicationNum/LastConsistencyCheckTime are supported.");
}
Expand Down
Expand Up @@ -80,6 +80,19 @@ public void testShowPartitionsStmtWithLikePredicate() {
stmt.toString());
}

@Test
public void testShowPartitionsStmtWithEqualPredicate() {
SlotRef slotRef = new SlotRef(null, "PartitionName");
StringLiteral stringLiteral = new StringLiteral("p1");
BinaryPredicate equalPredicate = new BinaryPredicate(BinaryPredicate.Operator.EQ, slotRef, stringLiteral);
ShowPartitionsStmt stmt =
new ShowPartitionsStmt(new TableName("testDb", "testTable"), equalPredicate, null, null, false);
com.starrocks.sql.analyzer.Analyzer.analyze(stmt, ctx);
Assert.assertEquals(
"SHOW PARTITIONS FROM `default_cluster:testDb`.`testTable` WHERE `PartitionName` = 'p1'",
stmt.toString());
}

@Test
public void testShowParitionsStmtOrderByAndLimit() {
SlotRef slotRef = new SlotRef(null, "PartitionId");
Expand Down