@@ -529,19 +529,77 @@ def test_write_to_sf_with_correct_precision(session, precision):
529529
530530
531531@pytest .mark .parametrize (
532- "mock_dict " ,
532+ "mock_default_precision " ,
533533 [
534534 {"IntegerType" : 5 , "LongType" : 4 },
535535 {"LongType" : 19 , "IntegerType" : 10 },
536536 ],
537537)
538- def test_integral_type_default_precision (mock_dict ):
539- with mock .patch .object (context , "_integral_type_default_precision" , mock_dict ):
538+ def test_integral_type_default_precision (mock_default_precision ):
539+ with mock .patch .object (
540+ context , "_integral_type_default_precision" , mock_default_precision
541+ ):
540542 integer_type = IntegerType ()
541- assert integer_type ._precision == mock_dict ["IntegerType" ]
543+ assert integer_type ._precision == mock_default_precision ["IntegerType" ]
542544
543545 long_type = LongType ()
544- assert long_type ._precision == mock_dict ["LongType" ]
546+ assert long_type ._precision == mock_default_precision ["LongType" ]
545547
546548 short_type = ShortType ()
547549 assert short_type ._precision is None
550+
551+
552+ @pytest .mark .skipif (
553+ "config.getoption('local_testing_mode', default=False)" ,
554+ reason = "session.sql not supported by local testing mode" ,
555+ )
556+ @pytest .mark .parametrize ("precision" , [38 , 19 , 5 , 3 ])
557+ @pytest .mark .parametrize (
558+ "mock_default_precision" ,
559+ [
560+ {"IntegerType" : 5 , "LongType" : 4 },
561+ {"LongType" : 19 , "IntegerType" : 10 },
562+ ],
563+ )
564+ def test_end_to_end_default_precision (session , precision , mock_default_precision ):
565+ table_name = Utils .random_table_name ()
566+
567+ with mock .patch .object (
568+ context , "_is_snowpark_connect_compatible_mode" , True
569+ ), mock .patch .object (
570+ context , "_integral_type_default_precision" , mock_default_precision
571+ ):
572+
573+ schema = StructType (
574+ [
575+ StructField ("decimal_value" , DecimalType (precision , 0 ), True ),
576+ StructField ("integer_value" , IntegerType (), True ),
577+ StructField ("long_value" , LongType (), True ),
578+ ]
579+ )
580+
581+ df = session .create_dataframe (
582+ [],
583+ schema ,
584+ )
585+ assert df .schema .fields [0 ].datatype ._precision == precision
586+ assert (
587+ df .schema .fields [1 ].datatype ._precision
588+ == mock_default_precision ["IntegerType" ]
589+ )
590+ assert (
591+ df .schema .fields [2 ].datatype ._precision
592+ == mock_default_precision ["LongType" ]
593+ )
594+
595+ df .write .save_as_table (table_name , mode = "overwrite" , table_type = "temp" )
596+ result = session .sql (f"select * from { table_name } " )
597+ assert result .schema .fields [0 ].datatype ._precision == precision
598+ assert (
599+ result .schema .fields [1 ].datatype ._precision
600+ == mock_default_precision ["IntegerType" ]
601+ )
602+ assert (
603+ result .schema .fields [2 ].datatype ._precision
604+ == mock_default_precision ["LongType" ]
605+ )
0 commit comments