Skip to content

Commit

Permalink
feat: Implement PI Function
Browse files Browse the repository at this point in the history
  • Loading branch information
AmrDeveloper committed Nov 6, 2023
1 parent 0e6cb4f commit baf278f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
18 changes: 18 additions & 0 deletions crates/gitql-ast/src/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ lazy_static! {
map.insert("now", date_current_timestamp);
map.insert("makedate", date_make_date);

// Numeric functions
map.insert("pi", numeric_pi);

// Other Functions
map.insert("isnull", general_is_null);
map.insert("isnumeric", general_is_numeric);
Expand Down Expand Up @@ -248,6 +251,14 @@ lazy_static! {
result: DataType::Date,
},
);
// Numeric functions
map.insert(
"pi",
Prototype {
parameters: vec![],
result: DataType::Float,
},
);
// General functions
map.insert(
"isnull",
Expand Down Expand Up @@ -513,6 +524,13 @@ fn date_make_date(inputs: Vec<Value>) -> Value {
Value::Date(time_stamp)
}

// Numeric functions

fn numeric_pi(_inputs: Vec<Value>) -> Value {
let pi = std::f64::consts::PI;
Value::Float(pi)
}

// General functions

fn general_is_null(inputs: Vec<Value>) -> Value {
Expand Down
14 changes: 14 additions & 0 deletions docs/function/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,20 @@ SELECT MAKEDATE(2023, 12)
SELECT NOW()
```

### Numeric Functions

| Name | Paramters | Return | Description |
| ---- | --------- | ------ | ----------------------- |
| PI | | Float | Return the value of PI. |

### Numeric functions samples

```sql

SELECT PI()

``````

### General functions

| Name | Paramters | Return | Description |
Expand Down

0 comments on commit baf278f

Please sign in to comment.