Skip to content

Commit

Permalink
tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
alamb committed Aug 7, 2023
1 parent 3eec61b commit e56fb20
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions datafusion/expr/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -942,9 +942,10 @@ impl Expr {
/// You can access column "my_field" with
///
/// ```
/// # use datafusion_expr::{lit, col, Expr};
/// # use datafusion_expr::{col};
/// let expr = col("c1")
/// .field("my_field");
/// assert_eq!(expr.display_name().unwrap(), "c1[my_field]");
/// ```
pub fn field(self, name: impl Into<String>) -> Self {
Expr::GetIndexedField(GetIndexedField {
Expand All @@ -971,6 +972,7 @@ impl Expr {
/// # use datafusion_expr::{lit, col, Expr};
/// let expr = col("c1")
/// .index(lit(3));
/// assert_eq!(expr.display_name().unwrap(), "c1[Int32(3)]");
/// ```
pub fn index(self, key: Expr) -> Self {
Expr::GetIndexedField(GetIndexedField {
Expand All @@ -979,25 +981,26 @@ impl Expr {
})
}

/// Return element at `1` based index field. Example
/// `expr["name"]`
/// Return elements between `1` based `start` and `stop`, for
/// example `expr[1:3]`
///
/// ## Example: Access element 2 from column "c1"
/// ## Example: Access element 2, 3, 4 from column "c1"
///
/// For example if column "c1" holds documents like this
///
/// ```json
/// [10, 20, 30, 40]
/// ```
///
/// You can access the value "[20, 30, 40]" with
/// You can access the value `[20, 30, 40]` with
///
/// ```
/// # use datafusion_expr::{lit, col, Expr};
/// # use datafusion_expr::{lit, col};
/// let expr = col("c1")
/// .slice(lit(30));
/// .range(lit(2), lit(4));
/// assert_eq!(expr.display_name().unwrap(), "c1[Int32(2):Int32(4)]");
/// ```
pub fn slice(self, start: Expr, stop: Expr) -> Self {
pub fn range(self, start: Expr, stop: Expr) -> Self {
Expr::GetIndexedField(GetIndexedField {
expr: Box::new(self),
field: GetFieldAccess::ListRange {
Expand Down

0 comments on commit e56fb20

Please sign in to comment.