Skip to content

Commit

Permalink
more
Browse files Browse the repository at this point in the history
  • Loading branch information
scsmithr committed Dec 17, 2024
1 parent 6355704 commit 548dc1e
Show file tree
Hide file tree
Showing 9 changed files with 123 additions and 6 deletions.
1 change: 1 addition & 0 deletions crates/rayexec_execution/src/functions/documentation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub enum Category {
Date,
Time,
Interval,
List,
String,
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ impl FunctionInfo for Eq {
fn signatures(&self) -> &[Signature] {
const DOC: Documentation = Documentation {
category: Category::General,
description: "Check if two values are equal. Returns NULL if either argument is NULL",
description: "Check if two values are equal. Returns NULL if either argument is NULL.",
arguments: &["a", "b"],
example: Some(Example {
example: "a = b",
Expand Down Expand Up @@ -232,7 +232,7 @@ impl FunctionInfo for Neq {
const DOC: Documentation = Documentation {
category: Category::General,
description:
"Check if two values are not equal. Returns NULL if either argument is NULL",
"Check if two values are not equal. Returns NULL if either argument is NULL.",
arguments: &["a", "b"],
example: Some(Example {
example: "a != b",
Expand Down Expand Up @@ -273,7 +273,7 @@ impl FunctionInfo for Lt {
const DOC: Documentation = Documentation {
category: Category::General,
description:
"Check if the left argument is less than the right. Returns NULL if either argument is NULL",
"Check if the left argument is less than the right. Returns NULL if either argument is NULL.",
arguments: &["a", "b"],
example: Some(Example {
example: "a < b",
Expand Down Expand Up @@ -314,7 +314,7 @@ impl FunctionInfo for LtEq {
const DOC: Documentation = Documentation {
category: Category::General,
description:
"Check if the left argument is less than or equal to the right. Returns NULL if either argument is NULL",
"Check if the left argument is less than or equal to the right. Returns NULL if either argument is NULL.",
arguments: &["a", "b"],
example: Some(Example {
example: "a <= b",
Expand Down Expand Up @@ -355,7 +355,7 @@ impl FunctionInfo for Gt {
const DOC: Documentation = Documentation {
category: Category::General,
description:
"Check if the left argument is greater than the right. Returns NULL if either argument is NULL",
"Check if the left argument is greater than the right. Returns NULL if either argument is NULL.",
arguments: &["a", "b"],
example: Some(Example {
example: "a > b",
Expand Down Expand Up @@ -396,7 +396,7 @@ impl FunctionInfo for GtEq {
const DOC: Documentation = Documentation {
category: Category::General,
description:
"Check if the left argument is greater than or equal to the right. Returns NULL if either argument is NULL",
"Check if the left argument is greater than or equal to the right. Returns NULL if either argument is NULL.",
arguments: &["a", "b"],
example: Some(Example {
example: "a >= b",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use rayexec_error::Result;
use rayexec_parser::ast;

use crate::expr::Expression;
use crate::functions::documentation::{Category, Documentation, Example};
use crate::functions::scalar::{PlannedScalarFunction, ScalarFunction, ScalarFunctionImpl};
use crate::functions::{invalid_input_types_error, plan_check_num_args, FunctionInfo, Signature};
use crate::logical::binder::table_list::TableList;
Expand All @@ -21,21 +22,35 @@ impl FunctionInfo for DatePart {
}

fn signatures(&self) -> &[Signature] {
// TODO: Specific docs for each.
const DOC: &Documentation = &Documentation {
category: Category::Date,
description: "Get a subfield.",
arguments: &["part", "date"],
example: Some(Example {
example: "date_part('day', DATE '2024-12-17')",
output: "17.000", // TODO: Gotta fix the trailing zeros.
}),
};

&[
Signature {
positional_args: &[DataTypeId::Utf8, DataTypeId::Date32],
variadic_arg: None,
return_type: DataTypeId::Decimal64,
doc: Some(DOC),
},
Signature {
positional_args: &[DataTypeId::Utf8, DataTypeId::Date64],
variadic_arg: None,
return_type: DataTypeId::Decimal64,
doc: Some(DOC),
},
Signature {
positional_args: &[DataTypeId::Utf8, DataTypeId::Timestamp],
variadic_arg: None,
return_type: DataTypeId::Decimal64,
doc: Some(DOC),
},
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,35 @@ impl FunctionInfo for DateTrunc {
}

fn signatures(&self) -> &[Signature] {
// TODO: Need to fix
// const DOC: &Documentation = &Documentation {
// category: Category::Date,
// description: "Truncate to a specified precision.",
// arguments: &["part", "date"],
// example: Some(Example {
// example: "date_trunc('month', DATE '2024-12-17')",
// output: "17.000",
// }),
// };

&[
Signature {
positional_args: &[DataTypeId::Utf8, DataTypeId::Date32],
variadic_arg: None,
return_type: DataTypeId::Decimal64,
doc: None,
},
Signature {
positional_args: &[DataTypeId::Utf8, DataTypeId::Date64],
variadic_arg: None,
return_type: DataTypeId::Decimal64,
doc: None,
},
Signature {
positional_args: &[DataTypeId::Utf8, DataTypeId::Timestamp],
variadic_arg: None,
return_type: DataTypeId::Decimal64,
doc: None,
},
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ impl FunctionInfo for Epoch {
positional_args: &[DataTypeId::Int64],
variadic_arg: None,
return_type: DataTypeId::Timestamp,
doc: None,
},
]
}
Expand Down Expand Up @@ -70,6 +71,7 @@ impl FunctionInfo for EpochMs {
positional_args: &[DataTypeId::Int64],
variadic_arg: None,
return_type: DataTypeId::Timestamp,
doc: None,
},
]
}
Expand Down
55 changes: 55 additions & 0 deletions crates/rayexec_execution/src/functions/scalar/builtin/is.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use rayexec_bullet::executor::scalar::UnaryExecutor;
use rayexec_error::Result;

use crate::expr::Expression;
use crate::functions::documentation::{Category, Documentation, Example};
use crate::functions::scalar::{PlannedScalarFunction, ScalarFunction, ScalarFunctionImpl};
use crate::functions::{plan_check_num_args, FunctionInfo, Signature};
use crate::logical::binder::table_list::TableList;
Expand All @@ -23,6 +24,15 @@ impl FunctionInfo for IsNull {
positional_args: &[DataTypeId::Any],
variadic_arg: None,
return_type: DataTypeId::Boolean,
doc: Some(&Documentation {
category: Category::General,
description: "Check if a value is NULL.",
arguments: &["value"],
example: Some(Example {
example: "is_null(NULL)",
output: "true",
}),
}),
}]
}
}
Expand Down Expand Up @@ -57,6 +67,15 @@ impl FunctionInfo for IsNotNull {
positional_args: &[DataTypeId::Any],
variadic_arg: None,
return_type: DataTypeId::Boolean,
doc: Some(&Documentation {
category: Category::General,
description: "Check if a value is not NULL.",
arguments: &["value"],
example: Some(Example {
example: "is_not_null(NULL)",
output: "false",
}),
}),
}]
}
}
Expand Down Expand Up @@ -121,6 +140,15 @@ impl FunctionInfo for IsTrue {
positional_args: &[DataTypeId::Boolean],
variadic_arg: None,
return_type: DataTypeId::Boolean,
doc: Some(&Documentation {
category: Category::General,
description: "Check if a value is true.",
arguments: &["value"],
example: Some(Example {
example: "is_true(false)",
output: "false",
}),
}),
}]
}
}
Expand Down Expand Up @@ -155,6 +183,15 @@ impl FunctionInfo for IsNotTrue {
positional_args: &[DataTypeId::Boolean],
variadic_arg: None,
return_type: DataTypeId::Boolean,
doc: Some(&Documentation {
category: Category::General,
description: "Check if a value is not true.",
arguments: &["value"],
example: Some(Example {
example: "is_not_true(false)",
output: "true",
}),
}),
}]
}
}
Expand Down Expand Up @@ -189,6 +226,15 @@ impl FunctionInfo for IsFalse {
positional_args: &[DataTypeId::Boolean],
variadic_arg: None,
return_type: DataTypeId::Boolean,
doc: Some(&Documentation {
category: Category::General,
description: "Check if a value is false.",
arguments: &["value"],
example: Some(Example {
example: "is_false(false)",
output: "true",
}),
}),
}]
}
}
Expand Down Expand Up @@ -223,6 +269,15 @@ impl FunctionInfo for IsNotFalse {
positional_args: &[DataTypeId::Boolean],
variadic_arg: None,
return_type: DataTypeId::Boolean,
doc: Some(&Documentation {
category: Category::General,
description: "Check if a value is not false.",
arguments: &["value"],
example: Some(Example {
example: "is_not_false(false)",
output: "false",
}),
}),
}]
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ use rayexec_error::{not_implemented, RayexecError, Result};
use serde::{Deserialize, Serialize};

use crate::expr::Expression;
use crate::functions::documentation::{Category, Documentation, Example};
use crate::functions::scalar::{PlannedScalarFunction, ScalarFunction, ScalarFunctionImpl};
use crate::functions::{plan_check_num_args, FunctionInfo, Signature};
use crate::logical::binder::table_list::TableList;
Expand All @@ -56,6 +57,15 @@ impl FunctionInfo for ListExtract {
positional_args: &[DataTypeId::List, DataTypeId::Int64],
variadic_arg: None,
return_type: DataTypeId::Any,
doc: Some(&Documentation {
category: Category::List,
description: "Extract an item from the list. Used 1-based indexing.",
arguments: &["list", "index"],
example: Some(Example {
example: "list_extract([4,5,6], 2)",
output: "5",
}),
}),
}]
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use rayexec_bullet::storage::ListStorage;
use rayexec_error::{RayexecError, Result};

use crate::expr::Expression;
use crate::functions::documentation::{Category, Documentation, Example};
use crate::functions::scalar::{PlannedScalarFunction, ScalarFunction, ScalarFunctionImpl};
use crate::functions::{FunctionInfo, Signature};
use crate::logical::binder::table_list::TableList;
Expand All @@ -22,6 +23,15 @@ impl FunctionInfo for ListValues {
positional_args: &[],
variadic_arg: Some(DataTypeId::Any),
return_type: DataTypeId::List,
doc: Some(&Documentation {
category: Category::List,
description: "Create a list fromt the given values.",
arguments: &["var_arg"],
example: Some(Example {
example: "list_values('cat', 'dog', 'mouse')",
output: "[cat, dog, mouse]",
}),
}),
}]
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use rayexec_bullet::executor::scalar::{BinaryListReducer, ListExecutor};
use rayexec_error::Result;

use crate::expr::Expression;
use crate::functions::documentation::{Category, Documentation, Example};
use crate::functions::scalar::{PlannedScalarFunction, ScalarFunction, ScalarFunctionImpl};
use crate::functions::{invalid_input_types_error, plan_check_num_args, FunctionInfo, Signature};
use crate::logical::binder::table_list::TableList;
Expand All @@ -39,6 +40,15 @@ impl FunctionInfo for L2Distance {
positional_args: &[DataTypeId::List, DataTypeId::List],
variadic_arg: None,
return_type: DataTypeId::Float64,
doc: Some(&Documentation{
category: Category::List,
description: "Compute the Euclidean distance between two lists. Both lists must be the same length and cannot contain NULLs.",
arguments: &["list1", "list2"],
example: Some(Example{
example: "l2_distance([1.0, 1.0], [2.0, 4.0])",
output: "3.1622776601683795",
}),
}),
}]
}
}
Expand Down

0 comments on commit 548dc1e

Please sign in to comment.