From e1a060e786358e4502e6ba69876f9c2ab52cb3e8 Mon Sep 17 00:00:00 2001
From: Charles Blackmon-Luca <20627856+charlesbluca@users.noreply.github.com>
Date: Thu, 6 Oct 2022 11:05:59 -0700
Subject: [PATCH] Replace instances of `elements_from_tablefactor`
---
dask_planner/src/parser.rs | 19 +++++++--------
dask_planner/src/sql/parser_utils.rs | 35 ++--------------------------
2 files changed, 10 insertions(+), 44 deletions(-)
diff --git a/dask_planner/src/parser.rs b/dask_planner/src/parser.rs
index 71e0bfef6..9b85a8512 100644
--- a/dask_planner/src/parser.rs
+++ b/dask_planner/src/parser.rs
@@ -817,7 +817,7 @@ impl<'a> DaskParser<'a> {
}
let (mdl_schema, mdl_name) =
- DaskParserUtils::elements_from_tablefactor(&self.parser.parse_table_factor()?)?;
+ DaskParserUtils::elements_from_object_name(&self.parser.parse_object_name()?)?;
self.parser.expect_token(&Token::Comma)?;
// Limit our input to ANALYZE, DESCRIBE, SELECT, SHOW statements
@@ -1048,9 +1048,9 @@ impl<'a> DaskParser<'a> {
self.parser.prev_token();
// Parse schema and table name
- let obj_name = self.parser.parse_object_name()?;
- let (tbl_schema, tbl_name) =
- DaskParserUtils::elements_from_objectname(&obj_name)?;
+ let (tbl_schema, tbl_name) = DaskParserUtils::elements_from_object_name(
+ &self.parser.parse_object_name()?,
+ )?;
// Parse WITH options
self.parser.expect_keyword(Keyword::WITH)?;
@@ -1173,8 +1173,8 @@ impl<'a> DaskParser<'a> {
/// Parse Dask-SQL SHOW COLUMNS FROM
fn parse_show_columns(&mut self) -> Result {
self.parser.expect_keyword(Keyword::FROM)?;
- let table_factor = self.parser.parse_table_factor()?;
- let (tbl_schema, tbl_name) = DaskParserUtils::elements_from_tablefactor(&table_factor)?;
+ let (tbl_schema, tbl_name) =
+ DaskParserUtils::elements_from_object_name(&self.parser.parse_object_name()?)?;
Ok(DaskStatement::ShowColumns(Box::new(ShowColumns {
table_name: tbl_name,
schema_name: match tbl_schema.as_str() {
@@ -1186,13 +1186,10 @@ impl<'a> DaskParser<'a> {
/// Parse Dask-SQL ANALYZE TABLE
fn parse_analyze_table(&mut self) -> Result {
- let table_factor = self.parser.parse_table_factor()?;
- // parse_table_factor parses the following keyword as an alias, so we need to go back a token
- // TODO: open an issue in sqlparser around this when possible
- self.parser.prev_token();
+ let obj_name = self.parser.parse_object_name()?;
self.parser
.expect_keywords(&[Keyword::COMPUTE, Keyword::STATISTICS, Keyword::FOR])?;
- let (tbl_schema, tbl_name) = DaskParserUtils::elements_from_tablefactor(&table_factor)?;
+ let (tbl_schema, tbl_name) = DaskParserUtils::elements_from_object_name(&obj_name)?;
let columns = match self
.parser
.parse_keywords(&[Keyword::ALL, Keyword::COLUMNS])
diff --git a/dask_planner/src/sql/parser_utils.rs b/dask_planner/src/sql/parser_utils.rs
index f44d7c440..c61dfc6a4 100644
--- a/dask_planner/src/sql/parser_utils.rs
+++ b/dask_planner/src/sql/parser_utils.rs
@@ -1,11 +1,11 @@
-use datafusion_sql::sqlparser::ast::{ObjectName, TableFactor};
+use datafusion_sql::sqlparser::ast::ObjectName;
use datafusion_sql::sqlparser::parser::ParserError;
pub struct DaskParserUtils;
impl DaskParserUtils {
/// Retrieves the schema and object name from a `ObjectName` instance
- pub fn elements_from_objectname(
+ pub fn elements_from_object_name(
obj_name: &ObjectName,
) -> Result<(String, String), ParserError> {
let identities: Vec = obj_name.0.iter().map(|f| f.value.clone()).collect();
@@ -18,35 +18,4 @@ impl DaskParserUtils {
)),
}
}
-
- /// Retrieves the table_schema and table_name from a `TableFactor` instance
- pub fn elements_from_tablefactor(
- tbl_factor: &TableFactor,
- ) -> Result<(String, String), ParserError> {
- match tbl_factor {
- TableFactor::Table {
- name,
- alias: _,
- args: _,
- with_hints: _,
- } => {
- let identities: Vec = name.0.iter().map(|f| f.value.clone()).collect();
-
- match identities.len() {
- 1 => Ok(("".to_string(), identities[0].clone())),
- 2 => Ok((identities[0].clone(), identities[1].clone())),
- _ => Err(ParserError::ParserError(
- "TableFactor name only supports 1 or 2 elements".to_string(),
- )),
- }
- }
- TableFactor::Derived { alias, .. }
- | TableFactor::NestedJoin { alias, .. }
- | TableFactor::TableFunction { alias, .. }
- | TableFactor::UNNEST { alias, .. } => match alias {
- Some(e) => Ok(("".to_string(), e.name.value.clone())),
- None => Ok(("".to_string(), "".to_string())),
- },
- }
- }
}