|
11 | 11 | # limitations under the License.
|
12 | 12 | import pytest
|
13 | 13 | from sqlalchemy import Column
|
| 14 | +from sqlalchemy import ForeignKey |
14 | 15 | from sqlalchemy import func
|
15 | 16 | from sqlalchemy import insert
|
16 | 17 | from sqlalchemy import Integer
|
17 | 18 | from sqlalchemy import MetaData
|
18 | 19 | from sqlalchemy import select
|
19 | 20 | from sqlalchemy import String
|
20 | 21 | from sqlalchemy import Table
|
| 22 | +from sqlalchemy.exc import SAWarning |
21 | 23 | from sqlalchemy.schema import CreateTable
|
22 | 24 | from sqlalchemy.sql import column
|
23 | 25 | from sqlalchemy.sql import table
|
|
40 | 42 | trino_catalog='other'
|
41 | 43 | )
|
42 | 44 |
|
| 45 | +table_with_pk = Table( |
| 46 | + 'table_with_pk', |
| 47 | + metadata, |
| 48 | + Column('id', String, primary_key=True) |
| 49 | +) |
| 50 | + |
| 51 | +table_with_fk = Table( |
| 52 | + 'table_with_fk', |
| 53 | + metadata, |
| 54 | + Column('id', String, primary_key=True), |
| 55 | + Column('fk', String, ForeignKey('table_with_pk.id')) |
| 56 | +) |
| 57 | + |
| 58 | +table_with_unique = Table( |
| 59 | + 'table_with_constraint', |
| 60 | + metadata, |
| 61 | + Column('id', String, primary_key=True), |
| 62 | + Column('uniq', String, unique=True) |
| 63 | +) |
| 64 | + |
43 | 65 |
|
44 | 66 | @pytest.fixture
|
45 | 67 | def dialect():
|
@@ -170,3 +192,24 @@ def test_try_cast(dialect):
|
170 | 192 | statement = select(try_cast(table_without_catalog.c.id, String))
|
171 | 193 | query = statement.compile(dialect=dialect)
|
172 | 194 | assert str(query) == 'SELECT try_cast("table".id as VARCHAR) AS id \nFROM "table"'
|
| 195 | + |
| 196 | + |
| 197 | +def test_catalogs_create_table_with_pk(dialect): |
| 198 | + with pytest.warns(SAWarning, match="Trino does not support PRIMARY KEY constraints. Constraint will be ignored."): |
| 199 | + statement = CreateTable(table_with_pk) |
| 200 | + query = statement.compile(dialect=dialect) |
| 201 | + assert 'primary key' not in str(query).lower() |
| 202 | + |
| 203 | + |
| 204 | +def test_catalogs_create_table_with_fk(dialect): |
| 205 | + with pytest.warns(SAWarning, match="Trino does not support FOREIGN KEY constraints. Constraint will be ignored."): |
| 206 | + statement = CreateTable(table_with_fk) |
| 207 | + query = statement.compile(dialect=dialect) |
| 208 | + assert 'foreign key' not in str(query).lower() |
| 209 | + |
| 210 | + |
| 211 | +def test_catalogs_create_table_with_unique(dialect): |
| 212 | + with pytest.warns(SAWarning, match="Trino does not support UNIQUE constraints. Constraint will be ignored."): |
| 213 | + statement = CreateTable(table_with_unique) |
| 214 | + query = statement.compile(dialect=dialect) |
| 215 | + assert 'unique' not in str(query).lower() |
0 commit comments