@@ -947,3 +947,54 @@ def test_to_redshift_int_na(bucket, redshift_parameters):
947947 rows = cursor .fetchall ()
948948 assert rows [0 ][0 ] == 3
949949 conn .close ()
950+
951+
952+ def test_does_table_exists ():
953+ conn = wr .glue .get_connection ("aws-data-wrangler-redshift" )
954+ with conn .cursor () as cursor :
955+ res = wr .redshift .does_table_exists (cursor = cursor , schema = "information_schema" , table = "tables" )
956+ assert res is True
957+ res = wr .redshift .does_table_exists (cursor = cursor , schema = "information_schema" , table = "adjwbdjawbjd" )
958+ assert res is False
959+ conn .close ()
960+
961+
962+ def test_append_create_table (bucket , redshift_parameters ):
963+ df = pd .DataFrame ({
964+ "id" : [1 , 2 , 3 ],
965+ "decimal_2" : [Decimal ((0 , (1 , 9 , 9 ), - 2 )), None , Decimal ((0 , (1 , 9 , 0 ), - 2 ))],
966+ "decimal_5" : [Decimal ((0 , (1 , 9 , 9 , 9 , 9 , 9 ), - 5 )), None ,
967+ Decimal ((0 , (1 , 9 , 0 , 0 , 0 , 0 ), - 5 ))],
968+ })
969+ con = wr .redshift .get_connection ("aws-data-wrangler-redshift" )
970+ cursor = con .cursor ()
971+ cursor .execute ("DROP TABLE IF EXISTS public.test_append_create_table" )
972+ cursor .close ()
973+ path = f"s3://{ bucket } /test_append_create_table/"
974+ wr .pandas .to_redshift (
975+ dataframe = df ,
976+ path = path ,
977+ schema = "public" ,
978+ table = "test_append_create_table" ,
979+ connection = con ,
980+ iam_role = redshift_parameters .get ("RedshiftRole" ),
981+ mode = "append" ,
982+ preserve_index = False ,
983+ )
984+ cursor = con .cursor ()
985+ cursor .execute ("SELECT * from public.test_append_create_table" )
986+ rows = cursor .fetchall ()
987+ cursor .close ()
988+ con .close ()
989+ assert len (df .index ) == len (rows )
990+ assert len (list (df .columns )) == len (list (rows [0 ]))
991+ for row in rows :
992+ if row [0 ] == 1 :
993+ assert row [1 ] == Decimal ((0 , (1 , 9 , 9 ), - 2 ))
994+ assert row [2 ] == Decimal ((0 , (1 , 9 , 9 , 9 , 9 , 9 ), - 5 ))
995+ elif row [1 ] == 2 :
996+ assert row [1 ] is None
997+ assert row [2 ] is None
998+ elif row [2 ] == 3 :
999+ assert row [1 ] == Decimal ((0 , (1 , 9 , 0 ), - 2 ))
1000+ assert row [2 ] == Decimal ((0 , (1 , 9 , 0 , 0 , 0 , 0 ), - 5 ))
0 commit comments