@@ -360,6 +360,18 @@ def _str_to_snowflake_bindings(self, _, value: str) -> str:
360360 # NOTE: str type is always taken as a text data and never binary
361361 return str (value )
362362
363+ def _date_to_snowflake_bindings_in_bulk_insertion (self , value : date ) -> str :
364+ # notes: this is for date type bulk insertion, it's different from non-bulk date type insertion flow
365+ milliseconds = _convert_date_to_epoch_milliseconds (value )
366+ # according to https://docs.snowflake.com/en/sql-reference/functions/to_date
367+ # through test, value in seconds will lead to wrong date
368+ # millisecond and nanoarrow second are good
369+ # if the milliseconds is beyond the range of 31536000000000, we switch to use nanoseconds
370+ # otherwise we will hit overflow error in snowflake
371+ if int (milliseconds ) < 31536000000000 :
372+ return milliseconds
373+ return _convert_date_to_epoch_nanoseconds (value )
374+
363375 _int_to_snowflake_bindings = _str_to_snowflake_bindings
364376 _long_to_snowflake_bindings = _str_to_snowflake_bindings
365377 _float_to_snowflake_bindings = _str_to_snowflake_bindings
@@ -378,15 +390,9 @@ def _nonetype_to_snowflake_bindings(self, *_) -> None:
378390 return None
379391
380392 def _date_to_snowflake_bindings (self , _ , value : date ) -> str :
381- milliseconds = _convert_date_to_epoch_milliseconds (value )
382- # according to https://docs.snowflake.com/en/sql-reference/functions/to_date
383- # through test, value in seconds will lead to wrong date
384- # millisecond and nanoarrow second are good
385- # if the milliseconds is beyond the range of 31536000000000, we switch to use nanoseconds
386- # otherwise we will hit overflow error in snowflake
387- if int (milliseconds ) < 31536000000000 :
388- return milliseconds
389- return _convert_date_to_epoch_nanoseconds (value )
393+ # this is for date type non-bulk insertion, it's different from bulk date type insertion flow
394+ # milliseconds
395+ return _convert_date_to_epoch_milliseconds (value )
390396
391397 def _time_to_snowflake_bindings (self , _ , value : dt_t ) -> str :
392398 # nanoseconds
@@ -662,6 +668,11 @@ def to_csv_bindings(self, value: tuple[str, Any] | Any) -> str | None:
662668 else :
663669 if isinstance (value , (dt_t , timedelta )):
664670 val = self .to_snowflake (value )
671+ elif isinstance (value , date ) and not isinstance (value , datetime ):
672+ # FIX SNOW-770678 and SNOW-966444
673+ # bulk insertion congestion is different from non-bulk insertion
674+ # to_csv_bindings is only used in bulk insertion logic
675+ val = self ._date_to_snowflake_bindings_in_bulk_insertion (value )
665676 else :
666677 _type = self .snowflake_type (value )
667678 val = self .to_snowflake_bindings (_type , value )
0 commit comments