Skip to content

Commit

Permalink
Add support for BigQuery ANY TYPE data type (#1602)
Browse files Browse the repository at this point in the history
Co-authored-by: Martin Abelson Sahlen <[email protected]>
Co-authored-by: Martin Abelson Sahlen <[email protected]>
  • Loading branch information
3 people authored Dec 15, 2024
1 parent 885aa93 commit 7bc6ddb
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/ast/data_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,10 @@ pub enum DataType {
///
/// [postgresql]: https://www.postgresql.org/docs/current/plpgsql-trigger.html
Trigger,
/// Any data type, used in BigQuery UDF definitions for templated parameters
///
/// [bigquery]: https://cloud.google.com/bigquery/docs/user-defined-functions#templated-sql-udf-parameters
AnyType,
}

impl fmt::Display for DataType {
Expand All @@ -383,7 +387,6 @@ impl fmt::Display for DataType {
DataType::CharacterVarying(size) => {
format_character_string_type(f, "CHARACTER VARYING", size)
}

DataType::CharVarying(size) => format_character_string_type(f, "CHAR VARYING", size),
DataType::Varchar(size) => format_character_string_type(f, "VARCHAR", size),
DataType::Nvarchar(size) => format_character_string_type(f, "NVARCHAR", size),
Expand Down Expand Up @@ -626,6 +629,7 @@ impl fmt::Display for DataType {
}
DataType::Unspecified => Ok(()),
DataType::Trigger => write!(f, "TRIGGER"),
DataType::AnyType => write!(f, "ANY TYPE"),
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8382,6 +8382,10 @@ impl<'a> Parser<'a> {
Ok(DataType::Tuple(field_defs))
}
Keyword::TRIGGER => Ok(DataType::Trigger),
Keyword::ANY if self.peek_keyword(Keyword::TYPE) => {
let _ = self.parse_keyword(Keyword::TYPE);
Ok(DataType::AnyType)
}
_ => {
self.prev_token();
let type_name = self.parse_object_name(false)?;
Expand Down
16 changes: 16 additions & 0 deletions tests/sqlparser_bigquery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2212,3 +2212,19 @@ fn test_any_value() {
bigquery_and_generic().verified_expr("ANY_VALUE(fruit HAVING MAX sold)");
bigquery_and_generic().verified_expr("ANY_VALUE(fruit HAVING MIN sold)");
}

#[test]
fn test_any_type() {
bigquery().verified_stmt(concat!(
"CREATE OR REPLACE TEMPORARY FUNCTION ",
"my_function(param1 ANY TYPE) ",
"AS (",
"(SELECT 1)",
")",
));
}

#[test]
fn test_any_type_dont_break_custom_type() {
bigquery_and_generic().verified_stmt("CREATE TABLE foo (x ANY)");
}

0 comments on commit 7bc6ddb

Please sign in to comment.