Repository: tobymao/sqlglot

Issue:
`UHUGEINT` is not recognized as a DuckDB Type
When testing SQLGlot, it appears that `UHUGEINT` is not recognized as a valid type. This causes a `ParseError` to be raised during parsing.

#### Example:

```python
sqlglot.errors.ParseError: Expected type. Line 1, Col: 25.
  SELECT to_hex(?::UHUGEINT) LIMIT 1
```

Discussion:

Solution patch:
diff --git a/sqlglot/dialects/duckdb.py b/sqlglot/dialects/duckdb.py
index 3932c11bc4..467152fb1e 100644
--- a/sqlglot/dialects/duckdb.py
+++ b/sqlglot/dialects/duckdb.py
@@ -549,6 +549,7 @@ class Generator(generator.Generator):
             exp.ReturnsProperty: lambda self, e: "TABLE" if isinstance(e.this, exp.Schema) else "",
             exp.Rand: rename_func("RANDOM"),
             exp.SafeDivide: no_safe_divide_sql,
+            exp.SHA: rename_func("SHA1"),
             exp.SHA2: sha256_sql,
             exp.Split: rename_func("STR_SPLIT"),
             exp.SortArray: _sort_array_sql,
diff --git a/sqlglot/tokens.py b/sqlglot/tokens.py
index b2143bcb07..29aa5c42d5 100644
--- a/sqlglot/tokens.py
+++ b/sqlglot/tokens.py
@@ -818,6 +818,7 @@ class Tokenizer(metaclass=_Tokenizer):
         "SMALLINT": TokenType.SMALLINT,
         "INT128": TokenType.INT128,
         "HUGEINT": TokenType.INT128,
+        "UHUGEINT": TokenType.UINT128,
         "INT2": TokenType.SMALLINT,
         "INTEGER": TokenType.INT,
         "INT": TokenType.INT,


Test patch:
diff --git a/tests/dialects/test_duckdb.py b/tests/dialects/test_duckdb.py
index f6a00547c0..fe919b0a90 100644
--- a/tests/dialects/test_duckdb.py
+++ b/tests/dialects/test_duckdb.py
@@ -973,6 +973,15 @@ def test_time(self):
                 "spark": "DATE_FORMAT(x, 'yy-M-ss')",
             },
         )
+
+        self.validate_all(
+            "SHA1(x)",
+            write={
+                "duckdb": "SHA1(x)",
+                "": "SHA(x)",
+            },
+        )
+
         self.validate_all(
             "STRFTIME(x, '%Y-%m-%d %H:%M:%S')",
             write={
@@ -1092,6 +1101,7 @@ def test_cast(self):
         self.validate_identity("CAST(x AS INT16)", "CAST(x AS SMALLINT)")
         self.validate_identity("CAST(x AS NUMERIC(1, 2))", "CAST(x AS DECIMAL(1, 2))")
         self.validate_identity("CAST(x AS HUGEINT)", "CAST(x AS INT128)")
+        self.validate_identity("CAST(x AS UHUGEINT)", "CAST(x AS UINT128)")
         self.validate_identity("CAST(x AS CHAR)", "CAST(x AS TEXT)")
         self.validate_identity("CAST(x AS BPCHAR)", "CAST(x AS TEXT)")
         self.validate_identity("CAST(x AS STRING)", "CAST(x AS TEXT)")