def test_nested_array_join(self): table = self._make_table( 't1', Column('x', types.Int32, primary_key=True), Column( 'parent', types.Nested( Column('child1', types.Int32), Column('child2', types.String), ))) query = select([ table.c.parent.child1, table.c.parent.child2, ]).array_join(table.c.parent) self.assertEqual( self.compile(query), 'SELECT t1.parent.child1, t1.parent.child2 ' 'FROM t1 ' 'ARRAY JOIN t1.parent') query = select([ table.c.parent.child1, table.c.parent.child2, ]).array_join(table.c.parent.child1, ) self.assertEqual( self.compile(query), 'SELECT t1.parent.child1, t1.parent.child2 ' 'FROM t1 ' 'ARRAY JOIN t1.parent.child1') query = select([ table.c.parent.child1, table.c.parent.child2, ]).array_join( table.c.parent.child1, table.c.parent.child2, ) self.assertEqual( self.compile(query), 'SELECT t1.parent.child1, t1.parent.child2 ' 'FROM t1 ' 'ARRAY JOIN t1.parent.child1, t1.parent.child2') parent_labeled = table.c.parent.label('p') query = select([ table.c.parent.child1, table.c.parent.child2, ]).array_join(parent_labeled) self.assertEqual( self.compile(query), 'SELECT t1.parent.child1, t1.parent.child2 ' 'FROM t1 ' 'ARRAY JOIN t1.parent AS p') query = select([ parent_labeled.child1, parent_labeled.child2, table.c.parent.child1, ]).array_join(parent_labeled) self.assertEqual( self.compile(query), 'SELECT p.child1, p.child2, t1.parent.child1 AS child1_1 ' 'FROM t1 ' 'ARRAY JOIN t1.parent AS p')
def test_create_table_nested(self): table = Table( 't1', self.metadata(), Column('x', types.Int32, primary_key=True), Column( 'parent', types.Nested( Column('child1', types.Int32), Column('child2', types.String), )), engines.Memory()) self.assertEqual( self.compile(CreateTable(table)), 'CREATE TABLE t1 (' 'x Int32, ' 'parent Nested(' 'child1 Int32, ' "child2 String" ')' ') ENGINE = Memory')
def test_nested_array_join_left(self): table = self._make_table( 't1', Column('x', types.Int32, primary_key=True), Column( 'parent', types.Nested( Column('child1', types.Int32), Column('child2', types.String), ))) query = select([ table.c.parent.child1, table.c.parent.child2, ]).array_join(table.c.parent, left=True) self.assertEqual( self.compile(query), 'SELECT t1.parent.child1, t1.parent.child2 ' 'FROM t1 ' 'LEFT ARRAY JOIN t1.parent')
def test_nested_type(self): table = self.create_table( 't1', Column('x', types.Int32, primary_key=True), Column( 'parent', types.Nested( Column('child1', types.Int32), Column('child2', types.String), ))) query = select([table.c.parent.child1]).where( and_(table.c.parent.child1 == [1, 2], table.c.parent.child2 == ['foo', 'bar'])) self.assertEqual( self.compile(query, literal_binds=True), 'SELECT parent.child1 FROM t1 ' 'WHERE parent.child1 = [1, 2] ' 'AND parent.child2 = [\'foo\', \'bar\']')