def test_array_of_array(self): coltype = self._type_round_trip(types.Array(types.Array( types.Int32)))[0] self.assertIsInstance(coltype, types.Array) self.assertIsInstance(coltype.item_type, types.Array) self.assertEqual(coltype.item_type.item_type, types.Int32)
def test_create_table_nested_types(self): table = Table('t1', self.metadata(), Column('x', types.Int32, primary_key=True), Column('y', types.Array(types.String)), engines.Memory()) self.assertEqual( self.compile(CreateTable(table)), 'CREATE TABLE t1 ' '(x Int32, y Array(String)) ' 'ENGINE = Memory') table = Table('t1', self.metadata(), Column('x', types.Int32, primary_key=True), Column('y', types.Array(types.Array(types.String))), engines.Memory()) self.assertEqual( self.compile(CreateTable(table)), 'CREATE TABLE t1 ' '(x Int32, y Array(Array(String))) ' 'ENGINE = Memory') table = Table('t1', self.metadata(), Column('x', types.Int32, primary_key=True), Column('y', types.Array(types.Array(types.String))), engines.Memory()) self.assertEqual( self.compile(CreateTable(table)), 'CREATE TABLE t1 ' '(x Int32, y Array(Array(String))) ' 'ENGINE = Memory')
def test_array(self): self.assertEqual( self.compile(types.Array(types.Int32())), 'Array(Int32)' ) self.assertEqual( self.compile(types.Array(types.Array(types.Int32()))), 'Array(Array(Int32))' )
def test_array_join(self): table = self._make_table( Column('nested.array_column', types.Array(types.Int8)), Column('nested.another_array_column', types.Array(types.Int8))) first_label = table.c['nested.array_column'].label('from_array') second_not_label = table.c['nested.another_array_column'] query = self.session.query(first_label, second_not_label)\ .array_join(first_label, second_not_label) self.assertEqual( self.compile(query), 'SELECT ' 't1."nested.array_column" AS from_array, ' 't1."nested.another_array_column" ' 'AS "t1_nested.another_array_column" ' 'FROM t1 ' 'ARRAY JOIN t1."nested.array_column" AS from_array, ' 't1."nested.another_array_column"')
def test_lambda_functions(self): query = session.query( func.arrayFilter( Lambda(lambda x: x.like('%World%')), literal(['Hello', 'abc World'], types.Array(types.String))).label('test')) self.assertEqual( self.compile(query, literal_binds=True), "SELECT arrayFilter(" "x -> x LIKE '%%World%%', ['Hello', 'abc World']" ") AS test")