forked from apache/datafusion-sqlparser-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
Add value spans to clickbench tests, add docs and From impl #1
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
Closed
Closed
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,8 +30,41 @@ use crate::{ast::Ident, tokenizer::Span}; | |
| #[cfg(feature = "visitor")] | ||
| use sqlparser_derive::{Visit, VisitMut}; | ||
|
|
||
| /// Primitive SQL values such as number and string | ||
| #[derive(Debug, Clone, Eq, Ord)] | ||
| /// Wraps a primitive SQL [`Value`] with its [`Span`] location | ||
| /// | ||
| /// # Example: create a `ValueWithSpan` from a `Value` | ||
| /// ``` | ||
| /// # use sqlparser::ast::{Value, ValueWithSpan}; | ||
| /// # use sqlparser::tokenizer::{Location, Span}; | ||
| /// let value = Value::SingleQuotedString(String::from("endpoint")); | ||
| /// // from line 1, column 1 to line 1, column 7 | ||
| /// let span = Span::new(Location::new(1, 1), Location::new(1, 7)); | ||
| /// let value_with_span = value.with_span(span); | ||
| /// ``` | ||
| /// | ||
| /// # Example: create a `ValueWithSpan` from a `Value` with an empty span | ||
| /// | ||
| /// You can call [`Value::with_empty_span`] to create a `ValueWithSpan` with an empty span | ||
| /// ``` | ||
| /// # use sqlparser::ast::{Value, ValueWithSpan}; | ||
| /// # use sqlparser::tokenizer::{Location, Span}; | ||
| /// let value = Value::SingleQuotedString(String::from("endpoint")); | ||
| /// let value_with_span = value.with_empty_span(); | ||
| /// assert_eq!(value_with_span.span, Span::empty()); | ||
| /// ``` | ||
| /// | ||
| /// You can also use the [`From`] trait to convert `ValueWithSpan` to/from `Value`s | ||
| /// ``` | ||
| /// # use sqlparser::ast::{Value, ValueWithSpan}; | ||
| /// # use sqlparser::tokenizer::{Location, Span}; | ||
| /// let value = Value::SingleQuotedString(String::from("endpoint")); | ||
| /// // converting `Value` to `ValueWithSpan` results in an empty span | ||
| /// let value_with_span: ValueWithSpan = value.into(); | ||
| /// assert_eq!(value_with_span.span, Span::empty()); | ||
| /// // convert back to `Value` | ||
| /// let value: Value = value_with_span.into(); | ||
| /// ``` | ||
| #[derive(Debug, Clone, Eq)] | ||
| #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] | ||
| #[cfg_attr(feature = "visitor", derive(Visit, VisitMut))] | ||
| pub struct ValueWithSpan { | ||
|
|
@@ -47,7 +80,13 @@ impl PartialEq for ValueWithSpan { | |
|
|
||
| impl PartialOrd for ValueWithSpan { | ||
| fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> { | ||
| self.value.partial_cmp(&other.value) | ||
| Some(self.cmp(other)) | ||
| } | ||
| } | ||
|
|
||
| impl Ord for ValueWithSpan { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did this to fix clippy |
||
| fn cmp(&self, other: &Self) -> core::cmp::Ordering { | ||
| self.value.cmp(&other.value) | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -63,6 +102,12 @@ impl From<ValueWithSpan> for Value { | |
| } | ||
| } | ||
|
|
||
| impl From<Value> for ValueWithSpan { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This makes it easy to create new ValueWithSpan |
||
| fn from(value: Value) -> Self { | ||
| value.with_empty_span() | ||
| } | ||
| } | ||
|
|
||
| /// Primitive SQL values such as number and string | ||
| #[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)] | ||
| #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added some examples to make the transition easier