Repository: tobymao/sqlglot

Issue:
Athena Iceberg Tables parsing issue
Hi,
I want to parse a SQL Statement that creates an Iceberg table on Athena:

```sql
create table if not exists tmp.mytable (
    name string
)
location 's3://bucket/tmp/mytable/'
tblproperties (
  'table_type'='iceberg',
  'format'='parquet'
);
```
running 
```python
stmts = sqlglot.parse(sql, read=sqlglot.Dialects.ATHENA)
stmts[0].sql()
```
returns:
```sql
CREATE TABLE IF NOT EXISTS tmp.mytable 
    (name TEXT) 
LOCATION 's3://bucket/tmp/mytable/' 
WITH (
    table_type='iceberg', 
    FORMAT='parquet'
)
```

Unfortunately, the syntax in Athena is different for Iceberg Tables and Hive-style tables.

The parsed statement should look like this:

```sql
CREATE TABLE IF NOT EXISTS tmp.mytable 
    (name STRING) 
LOCATION 's3://bucket/tmp/mytable/' 
TBLPROPERTIES (
    'table_type'='iceberg', 
    'FORMAT'='parquet'
)
```

Instead of WITH -> TBLPROPERTIES
The keys in the this block are wrapped in upper quotes and iceberg has slightly different data types. In this case STRING instead of TEXT

https://docs.aws.amazon.com/athena/latest/ug/querying-iceberg-supported-data-types.html
https://docs.aws.amazon.com/athena/latest/ug/querying-iceberg-creating-tables.html



Discussion:

Patch:
diff --git a/sqlglot/dialects/athena.py b/sqlglot/dialects/athena.py
index dc87d8dc..f2deec88 100644
--- a/sqlglot/dialects/athena.py
+++ b/sqlglot/dialects/athena.py
@@ -1,5 +1,6 @@
 from __future__ import annotations
 
+from sqlglot import exp
 from sqlglot.dialects.trino import Trino
 from sqlglot.tokens import TokenType
 
@@ -10,3 +11,27 @@ class Athena(Trino):
             **Trino.Parser.STATEMENT_PARSERS,
             TokenType.USING: lambda self: self._parse_as_command(self._prev),
         }
+
+    class Generator(Trino.Generator):
+        PROPERTIES_LOCATION = {
+            **Trino.Generator.PROPERTIES_LOCATION,
+            exp.LocationProperty: exp.Properties.Location.POST_SCHEMA,
+        }
+
+        TYPE_MAPPING = {
+            **Trino.Generator.TYPE_MAPPING,
+            exp.DataType.Type.TEXT: "STRING",
+        }
+
+        TRANSFORMS = {
+            **Trino.Generator.TRANSFORMS,
+            exp.FileFormatProperty: lambda self, e: f"'FORMAT'={self.sql(e, 'this')}",
+        }
+
+        def property_sql(self, expression: exp.Property) -> str:
+            return (
+                f"{self.property_name(expression, string_key=True)}={self.sql(expression, 'value')}"
+            )
+
+        def with_properties(self, properties: exp.Properties) -> str:
+            return self.properties(properties, prefix=self.seg("TBLPROPERTIES"))


Test patch:
diff --git a/tests/dialects/test_athena.py b/tests/dialects/test_athena.py
index 99e36f21..3288ada7 100644
--- a/tests/dialects/test_athena.py
+++ b/tests/dialects/test_athena.py
@@ -14,3 +14,7 @@ class TestAthena(Validator):
             some_function(1)""",
             check_command_warning=True,
         )
+
+        self.validate_identity(
+            "CREATE TABLE IF NOT EXISTS t (name STRING) LOCATION 's3://bucket/tmp/mytable/' TBLPROPERTIES ('table_type'='iceberg', 'FORMAT'='parquet')"
+        )