mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-09-02 12:17:21 +00:00
Remove Value::String
Its existence alongside SingleQuotedString simply doesn't make sense: `'a string'` is a string literal, while `a string` is not a "value". It's only used in postgresql-specific tab-separated-values parser to store the string representation of a field's value. For that use-case Option<String> looks like a more appropriate choice than Value.
This commit is contained in:
parent
56884dc700
commit
078eb677a1
3 changed files with 8 additions and 11 deletions
|
@ -103,7 +103,7 @@ pub enum ASTNode {
|
|||
/// COLUMNS
|
||||
columns: Vec<String>,
|
||||
/// VALUES a vector of values to be copied
|
||||
values: Vec<Value>,
|
||||
values: Vec<Option<String>>,
|
||||
},
|
||||
/// UPDATE
|
||||
SQLUpdate {
|
||||
|
@ -290,7 +290,7 @@ impl ToString for ASTNode {
|
|||
"\n{}",
|
||||
values
|
||||
.iter()
|
||||
.map(|v| v.to_string())
|
||||
.map(|v| v.clone().unwrap_or("\\N".to_string()))
|
||||
.collect::<Vec<String>>()
|
||||
.join("\t")
|
||||
);
|
||||
|
|
|
@ -2,15 +2,13 @@ use chrono::{offset::FixedOffset, DateTime, NaiveDate, NaiveDateTime, NaiveTime}
|
|||
|
||||
use uuid::Uuid;
|
||||
|
||||
/// SQL values such as int, double, string timestamp
|
||||
/// SQL values such as int, double, string, timestamp
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum Value {
|
||||
/// Literal signed long
|
||||
Long(i64),
|
||||
/// Literal floating point value
|
||||
Double(f64),
|
||||
/// Unquoted string
|
||||
String(String),
|
||||
/// Uuid value
|
||||
Uuid(Uuid),
|
||||
/// 'string value'
|
||||
|
@ -34,7 +32,6 @@ impl ToString for Value {
|
|||
match self {
|
||||
Value::Long(v) => v.to_string(),
|
||||
Value::Double(v) => v.to_string(),
|
||||
Value::String(v) => v.to_string(),
|
||||
Value::Uuid(v) => v.to_string(),
|
||||
Value::SingleQuotedString(v) => format!("'{}'", v),
|
||||
Value::Boolean(v) => v.to_string(),
|
||||
|
|
|
@ -690,7 +690,7 @@ impl Parser {
|
|||
|
||||
/// Parse a tab separated values in
|
||||
/// COPY payload
|
||||
fn parse_tsv(&mut self) -> Result<Vec<Value>, ParserError> {
|
||||
fn parse_tsv(&mut self) -> Result<Vec<Option<String>>, ParserError> {
|
||||
let values = self.parse_tab_value()?;
|
||||
Ok(values)
|
||||
}
|
||||
|
@ -699,17 +699,17 @@ impl Parser {
|
|||
Ok(ASTNode::SQLValue(self.parse_value()?))
|
||||
}
|
||||
|
||||
fn parse_tab_value(&mut self) -> Result<Vec<Value>, ParserError> {
|
||||
fn parse_tab_value(&mut self) -> Result<Vec<Option<String>>, ParserError> {
|
||||
let mut values = vec![];
|
||||
let mut content = String::from("");
|
||||
while let Some(t) = self.next_token_no_skip() {
|
||||
match t {
|
||||
Token::Whitespace(Whitespace::Tab) => {
|
||||
values.push(Value::String(content.to_string()));
|
||||
values.push(Some(content.to_string()));
|
||||
content.clear();
|
||||
}
|
||||
Token::Whitespace(Whitespace::Newline) => {
|
||||
values.push(Value::String(content.to_string()));
|
||||
values.push(Some(content.to_string()));
|
||||
content.clear();
|
||||
}
|
||||
Token::Backslash => {
|
||||
|
@ -718,7 +718,7 @@ impl Parser {
|
|||
}
|
||||
if let Some(token) = self.next_token() {
|
||||
if token == Token::Identifier("N".to_string()) {
|
||||
values.push(Value::Null);
|
||||
values.push(None);
|
||||
}
|
||||
} else {
|
||||
continue;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue