@@ -527,8 +527,6 @@ def _cast_to_bit(arg: exp.Expression) -> exp.Expression:
527527
528528 if isinstance (arg , exp .HexString ):
529529 arg = exp .Unhex (this = exp .Literal .string (arg .this ))
530- elif isinstance (arg , exp .Cast ) and isinstance (arg .this , exp .HexString ):
531- arg = exp .Unhex (this = exp .Literal .string (arg .this .this ))
532530
533531 return exp .cast (arg , exp .DataType .Type .BIT )
534532
@@ -708,38 +706,13 @@ def _bitshift_sql(
708706 original_type = None
709707 this = expression .this
710708
711- # Check if input is binary:
712- # 1. Direct binary type annotation on expression.this
713- # 2. Chained bitshift where inner operation's input is binary
714- # 3. CAST to binary type (e.g., X'FF'::BINARY)
715- is_binary_input = (
716- _is_binary (this )
717- or (isinstance (this .this , exp .Expression ) and _is_binary (this .this ))
718- or (isinstance (this , exp .Cast ) and _is_binary (this ))
719- )
720-
721709 # Deal with binary separately, remember the original type, cast back later
722- if is_binary_input :
710+ if _is_binary ( this ) :
723711 original_type = this .to if isinstance (this , exp .Cast ) else exp .DataType .build ("BLOB" )
724-
725- # for chained binary operators
726- if isinstance (this , exp .Binary ):
727- expression .set ("this" , exp .cast (this , exp .DataType .Type .BIT ))
728- else :
729- expression .set ("this" , _cast_to_bit (this ))
730-
731- # Remove the flag for binary otherwise the final cast will get wrapped in an extra INT128 cast
732- expression .args .pop ("requires_int128" )
733-
734- # cast to INT128 if required (e.g. coming from Snowflake)
712+ expression .set ("this" , _cast_to_bit (this ))
735713 elif expression .args .get ("requires_int128" ):
736714 this .replace (exp .cast (this , exp .DataType .Type .INT128 ))
737715
738- # Cast shift amount to int in case it's something else
739- shift_amount = expression .expression
740- if isinstance (shift_amount , exp .Literal ) and not shift_amount .is_int :
741- expression .set ("expression" , exp .cast (shift_amount , exp .DataType .Type .INT ))
742-
743716 result_sql = self .binary (expression , operator )
744717
745718 # Wrap in parentheses if parent is a bitwise operator to "fix" DuckDB precedence issue
0 commit comments