Skip to content

Commit

Permalink
feat: Implement isnumeric function
Browse files Browse the repository at this point in the history
  • Loading branch information
AmrDeveloper committed Oct 25, 2023
1 parent 150083a commit 0e7df1c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
13 changes: 13 additions & 0 deletions crates/gitql-ast/src/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ lazy_static! {

// Other Functions
map.insert("isnull", general_is_null);
map.insert("isnumeric", general_is_numeric);
map
};
}
Expand Down Expand Up @@ -255,6 +256,13 @@ lazy_static! {
result: DataType::Boolean,
},
);
map.insert(
"isnumeric",
Prototype {
parameters: vec![DataType::Any],
result: DataType::Boolean,
},
);
map
};
}
Expand Down Expand Up @@ -511,3 +519,8 @@ fn date_make_date(inputs: Vec<Value>) -> Value {
fn general_is_null(inputs: Vec<Value>) -> Value {
return Value::Boolean(inputs[0].data_type() == DataType::Null);
}

fn general_is_numeric(inputs: Vec<Value>) -> Value {
let input_type = inputs[0].data_type();
return Value::Boolean(input_type.is_number());
}
8 changes: 5 additions & 3 deletions docs/function/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,12 @@ SELECT NOW()

### General functions

| Name | Paramters | Return | Description |
| ------ | --------- | ------- | ----------------------------------------- |
| ISNULL | ANY | BOOLEAN | Return TRUE if the argument type is null. |
| Name | Paramters | Return | Description |
| --------- | --------- | ------- | ------------------------------------------- |
| ISNULL | ANY | BOOLEAN | Return TRUE if the argument type is null. |
| ISNUMERIC | ANY | BOOLEAN | Return TRUE if the argument type is number. |

```sql
SELECT ISNULL(null), ISNULL(1)
SELECT ISNUMERIC(null), ISNUMERIC(1), ISNUMERIC(1.1), ISNUMERIC(false)
```

0 comments on commit 0e7df1c

Please sign in to comment.