|
| 1 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 2 | +# you may not use this file except in compliance with the License. |
| 3 | +# You may obtain a copy of the License at |
| 4 | +# |
| 5 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | +# |
| 7 | +# Unless required by applicable law or agreed to in writing, software |
| 8 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 9 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 10 | +# See the License for the specific language governing permissions and |
| 11 | +# limitations under the License. |
| 12 | +import pytest |
| 13 | +from sqlalchemy import Table, MetaData, Column, Integer, String, select |
| 14 | + |
| 15 | +from trino.sqlalchemy.dialect import TrinoDialect |
| 16 | + |
| 17 | +metadata = MetaData() |
| 18 | +table = Table( |
| 19 | + 'table', |
| 20 | + metadata, |
| 21 | + Column('id', Integer, primary_key=True), |
| 22 | + Column('name', String), |
| 23 | +) |
| 24 | + |
| 25 | + |
| 26 | +@pytest.fixture |
| 27 | +def dialect(): |
| 28 | + return TrinoDialect() |
| 29 | + |
| 30 | + |
| 31 | +def test_limit_offset(dialect): |
| 32 | + statement = select(table).limit(10).offset(0) |
| 33 | + query = statement.compile(dialect=dialect) |
| 34 | + assert str(query) == 'SELECT "table".id, "table".name \nFROM "table"\nOFFSET :param_1\nLIMIT :param_2' |
| 35 | + |
| 36 | + |
| 37 | +def test_limit(dialect): |
| 38 | + statement = select(table).limit(10) |
| 39 | + query = statement.compile(dialect=dialect) |
| 40 | + assert str(query) == 'SELECT "table".id, "table".name \nFROM "table"\nLIMIT :param_1' |
| 41 | + |
| 42 | + |
| 43 | +def test_offset(dialect): |
| 44 | + statement = select(table).offset(0) |
| 45 | + query = statement.compile(dialect=dialect) |
| 46 | + assert str(query) == 'SELECT "table".id, "table".name \nFROM "table"\nOFFSET :param_1' |
0 commit comments