Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat/adding scalar-variable expression #1260

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,11 @@ pub enum Expr {
OuterJoin(Box<Expr>),
/// A reference to the prior level in a CONNECT BY clause.
Prior(Box<Expr>),
/// Scalar variable creation e.g. `[@]foo INT`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to add a link to some documentation that uses this expression? I think that would be helpful in this case - e.g I'm unfamiliar with the syntax and unable to tell how it's used as a result

ScalarVariable {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, it looks like we're missing implementation in the PR for how the parser actually parses/constructs the ScalarVariable expression or is that intended?

data_type: DataType,
name: String,
},
/// A lambda function.
///
/// Syntax:
Expand Down Expand Up @@ -1294,6 +1299,9 @@ impl fmt::Display for Expr {
write!(f, "{expr} (+)")
}
Expr::Prior(expr) => write!(f, "PRIOR {expr}"),
Expr::ScalarVariable { data_type, name } => {
write!(f, "{name} {data_type}")
}
Expr::Lambda(lambda) => write!(f, "{lambda}"),
}
}
Expand Down Expand Up @@ -6495,6 +6503,24 @@ mod tests {
assert_eq!("CUBE (a, (b, c), d)", format!("{cube}"));
}

#[test]
fn test_scalar_variable_display() {
let scalar_variable = Expr::ScalarVariable {
data_type: DataType::Boolean,
name: "foo".to_string(),
};
assert_eq!("foo BOOLEAN", format!("{scalar_variable}"));
}

#[test]
fn test_scalar_variable_display_int() {
let scalar_variable = Expr::ScalarVariable {
data_type: DataType::Int(None),
name: "foo".to_string(),
};
assert_eq!("foo INT", format!("{scalar_variable}"));
}

#[test]
fn test_interval_display() {
let interval = Expr::Interval(Interval {
Expand Down
Loading