mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-09-04 21:20:32 +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
|
||||||
columns: Vec<String>,
|
columns: Vec<String>,
|
||||||
/// VALUES a vector of values to be copied
|
/// VALUES a vector of values to be copied
|
||||||
values: Vec<Value>,
|
values: Vec<Option<String>>,
|
||||||
},
|
},
|
||||||
/// UPDATE
|
/// UPDATE
|
||||||
SQLUpdate {
|
SQLUpdate {
|
||||||
|
@ -290,7 +290,7 @@ impl ToString for ASTNode {
|
||||||
"\n{}",
|
"\n{}",
|
||||||
values
|
values
|
||||||
.iter()
|
.iter()
|
||||||
.map(|v| v.to_string())
|
.map(|v| v.clone().unwrap_or("\\N".to_string()))
|
||||||
.collect::<Vec<String>>()
|
.collect::<Vec<String>>()
|
||||||
.join("\t")
|
.join("\t")
|
||||||
);
|
);
|
||||||
|
|
|
@ -2,15 +2,13 @@ use chrono::{offset::FixedOffset, DateTime, NaiveDate, NaiveDateTime, NaiveTime}
|
||||||
|
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
/// SQL values such as int, double, string timestamp
|
/// SQL values such as int, double, string, timestamp
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
pub enum Value {
|
pub enum Value {
|
||||||
/// Literal signed long
|
/// Literal signed long
|
||||||
Long(i64),
|
Long(i64),
|
||||||
/// Literal floating point value
|
/// Literal floating point value
|
||||||
Double(f64),
|
Double(f64),
|
||||||
/// Unquoted string
|
|
||||||
String(String),
|
|
||||||
/// Uuid value
|
/// Uuid value
|
||||||
Uuid(Uuid),
|
Uuid(Uuid),
|
||||||
/// 'string value'
|
/// 'string value'
|
||||||
|
@ -34,7 +32,6 @@ impl ToString for Value {
|
||||||
match self {
|
match self {
|
||||||
Value::Long(v) => v.to_string(),
|
Value::Long(v) => v.to_string(),
|
||||||
Value::Double(v) => v.to_string(),
|
Value::Double(v) => v.to_string(),
|
||||||
Value::String(v) => v.to_string(),
|
|
||||||
Value::Uuid(v) => v.to_string(),
|
Value::Uuid(v) => v.to_string(),
|
||||||
Value::SingleQuotedString(v) => format!("'{}'", v),
|
Value::SingleQuotedString(v) => format!("'{}'", v),
|
||||||
Value::Boolean(v) => v.to_string(),
|
Value::Boolean(v) => v.to_string(),
|
||||||
|
|
|
@ -690,7 +690,7 @@ impl Parser {
|
||||||
|
|
||||||
/// Parse a tab separated values in
|
/// Parse a tab separated values in
|
||||||
/// COPY payload
|
/// 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()?;
|
let values = self.parse_tab_value()?;
|
||||||
Ok(values)
|
Ok(values)
|
||||||
}
|
}
|
||||||
|
@ -699,17 +699,17 @@ impl Parser {
|
||||||
Ok(ASTNode::SQLValue(self.parse_value()?))
|
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 values = vec![];
|
||||||
let mut content = String::from("");
|
let mut content = String::from("");
|
||||||
while let Some(t) = self.next_token_no_skip() {
|
while let Some(t) = self.next_token_no_skip() {
|
||||||
match t {
|
match t {
|
||||||
Token::Whitespace(Whitespace::Tab) => {
|
Token::Whitespace(Whitespace::Tab) => {
|
||||||
values.push(Value::String(content.to_string()));
|
values.push(Some(content.to_string()));
|
||||||
content.clear();
|
content.clear();
|
||||||
}
|
}
|
||||||
Token::Whitespace(Whitespace::Newline) => {
|
Token::Whitespace(Whitespace::Newline) => {
|
||||||
values.push(Value::String(content.to_string()));
|
values.push(Some(content.to_string()));
|
||||||
content.clear();
|
content.clear();
|
||||||
}
|
}
|
||||||
Token::Backslash => {
|
Token::Backslash => {
|
||||||
|
@ -718,7 +718,7 @@ impl Parser {
|
||||||
}
|
}
|
||||||
if let Some(token) = self.next_token() {
|
if let Some(token) = self.next_token() {
|
||||||
if token == Token::Identifier("N".to_string()) {
|
if token == Token::Identifier("N".to_string()) {
|
||||||
values.push(Value::Null);
|
values.push(None);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
continue;
|
continue;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue