11#
22# Copyright (c) 2012-2025 Snowflake Computing Inc. All rights reserved.
33#
4+ import csv
5+ import os
6+ import tempfile
47from decimal import Decimal
58
69import pytest
@@ -414,7 +417,7 @@ def test_join_basic(session):
414417
415418@pytest .mark .skipif (
416419 "config.getoption('local_testing_mode', default=False)" ,
417- reason = "session.sql not supported in local testing" ,
420+ reason = "session.sql not supported by local testing mode " ,
418421)
419422def test_numeric_type_store_precision_and_scale (session ):
420423 table_name = Utils .random_table_name ()
@@ -427,3 +430,56 @@ def test_numeric_type_store_precision_and_scale(session):
427430 datatype = result .schema .fields [0 ].datatype
428431 assert isinstance (datatype , LongType )
429432 assert datatype ._precision == 38 and datatype ._scale == 0
433+
434+
435+ @pytest .mark .skipif (
436+ "config.getoption('local_testing_mode', default=False)" ,
437+ reason = "relaxed_types not supported by local testing mode" ,
438+ )
439+ def test_numeric_type_store_precision_and_scale_read_file (session ):
440+ stage_name = Utils .random_stage_name ()
441+ header = ("BIG_NUM" ,)
442+ test_data = [("9" * 38 ,)]
443+
444+ def write_csv (data ):
445+ with tempfile .NamedTemporaryFile (
446+ mode = "w+" ,
447+ delete = False ,
448+ suffix = ".csv" ,
449+ newline = "" ,
450+ ) as file :
451+ writer = csv .writer (file )
452+ writer .writerow (header )
453+ for row in data :
454+ writer .writerow (row )
455+ return file .name
456+
457+ file_path = write_csv (test_data )
458+
459+ try :
460+ Utils .create_stage (session , stage_name , is_temporary = True )
461+ result = session .file .put (
462+ file_path , f"@{ stage_name } " , auto_compress = False , overwrite = True
463+ )
464+
465+ # Infer schema from only the short file
466+ constrained_reader = session .read .options (
467+ {
468+ "INFER_SCHEMA" : True ,
469+ "INFER_SCHEMA_OPTIONS" : {"FILES" : [result [0 ].target ]},
470+ "PARSE_HEADER" : True ,
471+ # Only load the short file
472+ "PATTERN" : f".*{ result [0 ].target } " ,
473+ }
474+ )
475+
476+ # df1 uses constrained types
477+ df1 = constrained_reader .csv (f"@{ stage_name } /" )
478+ datatype = df1 .schema .fields [0 ].datatype
479+ assert isinstance (datatype , LongType )
480+ assert datatype ._precision == 38 and datatype ._scale == 0
481+
482+ finally :
483+ Utils .drop_stage (session , stage_name )
484+ if os .path .exists (file_path ):
485+ os .remove (file_path )
0 commit comments