Skip to content

Commit

Permalink
feat(fuzz): validate semantic type of column
Browse files Browse the repository at this point in the history
  • Loading branch information
WenyXu committed Mar 13, 2024
1 parent b55905c commit 51dd36d
Showing 1 changed file with 52 additions and 1 deletion.
53 changes: 52 additions & 1 deletion tests-fuzz/src/validator/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,21 @@ fn is_nullable(str: &str) -> bool {
str.to_uppercase() == "YES"
}

enum SemanticType {
Timestamp,
Field,
Tag,
}

fn semantic_type(str: &str) -> Option<SemanticType> {
match str {
"TIMESTAMP" => Some(SemanticType::Timestamp),
"FIELD" => Some(SemanticType::Field),
"TAG" => Some(SemanticType::Tag),
_ => None,
}
}

impl PartialEq<Column> for ColumnEntry {
fn eq(&self, other: &Column) -> bool {
// Checks `table_name`
Expand Down Expand Up @@ -108,11 +123,47 @@ impl PartialEq<Column> for ColumnEntry {
.iter()
.any(|opt| matches!(opt, ColumnOption::NotNull | ColumnOption::TimeIndex))
{
debug!("unexpected ColumnOption::NotNull or ColumnOption::TimeIndex");
debug!("ColumnOption::NotNull or ColumnOption::TimeIndex is not found");
return false;
}
}
//TODO: Checks `semantic_type`
match semantic_type(&self.semantic_type) {
Some(SemanticType::Tag) => {
if !other
.options
.iter()
.any(|opt| matches!(opt, ColumnOption::PrimaryKey))
{
debug!("ColumnOption::PrimaryKey is not found");
return false;
}
}
Some(SemanticType::Field) => {
if other
.options
.iter()
.any(|opt| matches!(opt, ColumnOption::PrimaryKey | ColumnOption::TimeIndex))
{
debug!("unexpected ColumnOption::PrimaryKey or ColumnOption::TimeIndex");
return false;
}
}
Some(SemanticType::Timestamp) => {
if !other
.options
.iter()
.any(|opt| matches!(opt, ColumnOption::TimeIndex))
{
debug!("ColumnOption::TimeIndex is not found");
return false;
}
}
None => {
debug!("unknown semantic type: {}", self.semantic_type);
return false;
}
};

true
}
Expand Down

0 comments on commit 51dd36d

Please sign in to comment.