Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
15 changes: 14 additions & 1 deletion src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12170,7 +12170,20 @@ impl<'a> Parser<'a> {
self.expect_token(&Token::RParen)?;
Ok(DataType::FixedString(character_length))
}
Keyword::TEXT => Ok(DataType::Text),
Keyword::TEXT => {
if dialect_is!(dialect is SnowflakeDialect) {
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Remove this condition, this code can run on all dialects

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

I addressed this feedback in 90a4ac6.

Summary: Committed the follow-up as 90a4ac6efd021f279cf4fcad8f102977f4cd8165 on the current branch. Checklist: - [x] Feedback 1: removed the Snowflake-only condition so TEXT(<modifiers>) is handled for all dialects in src/parser/mod.rs. - [x] Feedback 2: renamed the remaining Snowflake cast regression test to test_parse_cast_to_text_with_length in tests/sqlparser_snowflake.rs. - [x] Feedback 3: removed the extra unit test the review calle...

if let Some(modifiers) = self.parse_optional_type_modifiers()? {
Ok(DataType::Custom(
ObjectName::from(vec![Ident::new("TEXT")]),
modifiers,
))
} else {
Ok(DataType::Text)
}
} else {
Ok(DataType::Text)
}
}
Keyword::TINYTEXT => Ok(DataType::TinyText),
Keyword::MEDIUMTEXT => Ok(DataType::MediumText),
Keyword::LONGTEXT => Ok(DataType::LongText),
Expand Down
49 changes: 49 additions & 0 deletions tests/sqlparser_snowflake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5010,3 +5010,52 @@ fn test_select_dollar_column_from_stage() {
// With table function args, without alias
snowflake().verified_stmt("SELECT $1, $2 FROM @mystage1(file_format => 'myformat')");
}

#[test]
fn test_parse_pg_style_cast_to_text_with_length() {
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Rename to test_parse_cast_to_text_with_length

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

I addressed this feedback in 90a4ac6.

Summary: Committed the follow-up as 90a4ac6efd021f279cf4fcad8f102977f4cd8165 on the current branch. Checklist: - [x] Feedback 1: removed the Snowflake-only condition so TEXT(<modifiers>) is handled for all dialects in src/parser/mod.rs. - [x] Feedback 2: renamed the remaining Snowflake cast regression test to test_parse_cast_to_text_with_length in tests/sqlparser_snowflake.rs. - [x] Feedback 3: removed the extra unit test the review calle...

let select = snowflake().verified_only_select(
"SELECT _ID::TEXT(16777216) AS _ID FROM INCARE_ANALYTICS.USER_DETAILS",
);
match only(&select.projection) {
SelectItem::ExprWithAlias {
expr:
Expr::Cast {
kind: CastKind::DoubleColon,
data_type,
..
},
alias,
} => {
assert_eq!(alias.value, "_ID");
assert_eq!(
*data_type,
DataType::Custom(
ObjectName::from(vec![Ident::new("TEXT")]),
vec!["16777216".to_string()],
)
);
}
_ => unreachable!(),
}
}

#[test]
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Remove this unit test

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

I addressed this feedback in 90a4ac6.

Summary: Committed the follow-up as 90a4ac6efd021f279cf4fcad8f102977f4cd8165 on the current branch. Checklist: - [x] Feedback 1: removed the Snowflake-only condition so TEXT(<modifiers>) is handled for all dialects in src/parser/mod.rs. - [x] Feedback 2: renamed the remaining Snowflake cast regression test to test_parse_cast_to_text_with_length in tests/sqlparser_snowflake.rs. - [x] Feedback 3: removed the extra unit test the review calle...

fn test_parse_cast_function_to_text_with_length() {
let select = snowflake().verified_only_select("SELECT CAST(_ID AS TEXT(42)) FROM USER_DETAILS");
match expr_from_projection(only(&select.projection)) {
Expr::Cast {
kind: CastKind::Cast,
data_type,
..
} => {
assert_eq!(
*data_type,
DataType::Custom(
ObjectName::from(vec![Ident::new("TEXT")]),
vec!["42".to_string()],
)
);
}
_ => unreachable!(),
}
}
Loading