Repository: apache/datafusion-sqlparser-rs (rust)

Issue:
Fails to parse BigQuery UDF with "ANY TYPE" parameters
EDIT: The "proper" name for this pattern is "Templated, SQL UDF Parameters", which can be further elaborated in the BQ Docs: https://cloud.google.com/bigquery/docs/user-defined-functions#templated-sql-udf-parameters

trying to parse this simple function like this: 
```
fn main() {
    let sql = "
CREATE TEMP FUNCTION my_function(are_map ANY TYPE)
AS (
  (SELECT 1)
);
    ";

    let ast = Parser::parse_sql(&BigQueryDialect, sql).unwrap();
    for stmt in &ast {
        println!("{:?}", stmt);
    }
}
```

Yields this error:
```
thread 'main' panicked at src/main.rs:18:56:
called `Result::unwrap()` on an `Err` value: ParserError("Expected: ), found: TYPE at Line: 2, Column: 46")
```
I can try to have a look at this , seems relatively straightforward to fix!

Pull request:
Add support for BigQuery `ANY TYPE` data type
As referenced in #1601 , here is a PR, with a test, that verifies correct parsing of BigQuery User-defined functions using templated SQL parameters (what a mouthful :D). 

More docs on the actual feature/functionality in BQ can be found here: https://cloud.google.com/bigquery/docs/user-defined-functions

Thanks in advance for the consideration!

EDIT: This closes #1601 

Patch:
diff --git a/src/ast/data_type.rs b/src/ast/data_type.rs
index 5b0239e..b53b8f0 100644
--- a/src/ast/data_type.rs
+++ b/src/ast/data_type.rs
@@ -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 {
@@ -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),
@@ -626,6 +629,7 @@ impl fmt::Display for DataType {
             }
             DataType::Unspecified => Ok(()),
             DataType::Trigger => write!(f, "TRIGGER"),
+            DataType::AnyType => write!(f, "ANY TYPE"),
         }
     }
 }
diff --git a/src/parser/mod.rs b/src/parser/mod.rs
index 39ab2db..3732308 100644
--- a/src/parser/mod.rs
+++ b/src/parser/mod.rs
@@ -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)?;


Test patch:
diff --git a/tests/sqlparser_bigquery.rs b/tests/sqlparser_bigquery.rs
index 2be128a..34c14cc 100644
--- a/tests/sqlparser_bigquery.rs
+++ b/tests/sqlparser_bigquery.rs
@@ -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)");
+}