Skip to content

Commit

Permalink
feat: Implement 'TSRANGE' Range function
Browse files Browse the repository at this point in the history
  • Loading branch information
AmrDeveloper committed Sep 7, 2024
1 parent f3e0920 commit 46796af
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 17 deletions.
4 changes: 2 additions & 2 deletions crates/gitql-ast/src/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,8 @@ impl Expression for ContainsExpression {
ExpressionKind::Contains
}

fn expr_type(&self, scope: &Environment) -> DataType {
self.element.expr_type(scope)
fn expr_type(&self, _scope: &Environment) -> DataType {
DataType::Boolean
}

fn as_any(&self) -> &dyn Any {
Expand Down
16 changes: 16 additions & 0 deletions crates/gitql-std/src/range/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::collections::HashMap;
pub fn register_std_range_functions(map: &mut HashMap<&'static str, Function>) {
map.insert("int4range", int4range);
map.insert("daterange", daterange);
map.insert("tsrange", tsrange);
}

#[inline(always)]
Expand All @@ -27,6 +28,13 @@ pub fn register_std_range_function_signatures(map: &mut HashMap<&'static str, Si
return_type: DataType::Range(Box::new(DataType::Date)),
},
);
map.insert(
"tsrange",
Signature {
parameters: vec![DataType::DateTime, DataType::DateTime],
return_type: DataType::Range(Box::new(DataType::DateTime)),
},
);
}

pub fn int4range(inputs: &[Value]) -> Value {
Expand All @@ -44,3 +52,11 @@ pub fn daterange(inputs: &[Value]) -> Value {
Box::new(inputs[1].clone()),
)
}

pub fn tsrange(inputs: &[Value]) -> Value {
Value::Range(
DataType::DateTime,
Box::new(inputs[0].clone()),
Box::new(inputs[1].clone()),
)
}
8 changes: 5 additions & 3 deletions docs/functions/range.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

### Range functions

| Name | Parameters | Return | Description |
| --------- | ---------------- | -------------- | -------------------------------------------------- |
| int4range | Integer, Integer | Range(Integer) | Create a Range of integer type with start and end. |
| Name | Parameters | Return | Description |
| --------- | ------------------ | --------------- | ---------------------------------------------------- |
| INT4RANGE | Integer, Integer | Range(Integer) | Create a Range of integer type with start and end. |
| DATERANGE | Date, Date | Range(Date) | Create a Range of date type with start and end. |
| TSRANGE | DateTime, DateTime | Range(DateTime) | Create a Range of date time type with start and end. |
24 changes: 12 additions & 12 deletions docs/structure/tables.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ show tables

---

| Name | Type | Description |
| --------------- | ------- | ------------------------ |
| commit_id | Text | Commit id |
| title | Text | Commit title |
| message | Text | Commit full message |
| author_name | Text | Author name |
| author_email | Text | Author email |
| committer_name | Text | Committer name |
| committer_email | Text | Committer email |
| parents_count | Integer | Number of commit parents |
| datetime | Date | Commit date time |
| repo | Text | Repository full path |
| Name | Type | Description |
| --------------- | -------- | ------------------------ |
| commit_id | Text | Commit id |
| title | Text | Commit title |
| message | Text | Commit full message |
| author_name | Text | Author name |
| author_email | Text | Author email |
| committer_name | Text | Committer name |
| committer_email | Text | Committer email |
| parents_count | Integer | Number of commit parents |
| datetime | DateTime | Commit date time |
| repo | Text | Repository full path |

---

Expand Down

0 comments on commit 46796af

Please sign in to comment.