|
1 | | -from sqlalchemy import Column, and_ |
| 1 | +from sqlalchemy import Column, and_, func |
2 | 2 | from sqlalchemy.exc import CompileError |
3 | 3 | from sqlalchemy.sql import expression |
4 | 4 |
|
@@ -585,3 +585,49 @@ def test_distinct_on(self): |
585 | 585 | self.compile(query), |
586 | 586 | 'SELECT DISTINCT ON (t1.x) t1.x FROM t1' |
587 | 587 | ) |
| 588 | + |
| 589 | + def test_map_type(self): |
| 590 | + table = self._make_table( |
| 591 | + 't1', |
| 592 | + Column('x', types.Int32, primary_key=True), |
| 593 | + Column('y', types.Map(types.String, types.String)) |
| 594 | + ) |
| 595 | + |
| 596 | + query = select( |
| 597 | + func.mapKeys(table.c.y), func.mapValues(table.c.y) |
| 598 | + ).where( |
| 599 | + func.has(table.c.y, 'foo') |
| 600 | + ) |
| 601 | + self.assertEqual( |
| 602 | + self.compile(query, literal_binds=True), |
| 603 | + 'SELECT mapKeys(t1.y) AS "mapKeys_1", ' |
| 604 | + 'mapValues(t1.y) AS "mapValues_1" ' |
| 605 | + 'FROM t1 ' |
| 606 | + 'WHERE has(t1.y, \'foo\')' |
| 607 | + ) |
| 608 | + |
| 609 | + def test_nested_map_type(self): |
| 610 | + table = self._make_table( |
| 611 | + 't1', |
| 612 | + Column('x', types.Int32, primary_key=True), |
| 613 | + Column( |
| 614 | + 'y', |
| 615 | + types.Map( |
| 616 | + types.String, |
| 617 | + types.Map(types.String, types.String) |
| 618 | + ) |
| 619 | + ) |
| 620 | + ) |
| 621 | + |
| 622 | + query = select( |
| 623 | + func.mapKeys(table.c.y), func.mapValues(table.c.y) |
| 624 | + ).where( |
| 625 | + func.has(table.c.y, 'foo') |
| 626 | + ) |
| 627 | + self.assertEqual( |
| 628 | + self.compile(query, literal_binds=True), |
| 629 | + 'SELECT mapKeys(t1.y) AS "mapKeys_1", ' |
| 630 | + 'mapValues(t1.y) AS "mapValues_1" ' |
| 631 | + 'FROM t1 ' |
| 632 | + 'WHERE has(t1.y, \'foo\')' |
| 633 | + ) |
0 commit comments