
    g=                        d dl Z d dlZd dlZej                  j
                  d        Zej                  j
                  d        Zej                  j
                  d        Zej                  j
                  d        Z	ej                  j                  d      d        Zej                  j
                  d	        Zej                  j
                  d
        Zej                  j
                  d        Zej                  j
                  d        Zej                  j
                  d        Zej                  j
                  d        Zej                  j
                  d        Zy)    Nc                  <   dd l m}  | j                         }t        j                  dt        j
                               }t        j                  dt        j
                               }t        j                  ||g      }t        j                  dt        j
                               }|j                  |      }|j                  |      }|j                         |j                  k(  sJ |j                  d||gt        j                               }|j                  |||t        j
                               }	|j                  |	|      }
|
j                         j                  t        j
                         k(  sJ | j                  d      }| j!                  ||
gt        j"                         d|      }|j$                  j'                  d	      d
k7  sJ t        j(                  g dt        j
                               }t        j(                  g dt        j
                               }t        j(                  g dt        j
                               }t        j*                  j-                  ||gddg      }|j/                  |      \  }|j1                  |      sJ y )Nr   abresgreater_thanTdump_irNONE@expr_)
         type)r      r      )r   r   r   r   names)pyarrow.gandivagandivaTreeExprBuilderpafieldint32schema
make_fieldreturn_typer   make_functionbool_make_ifmake_expressionresultConfigurationmake_projectordefault_memory_poolllvm_irfindarrayRecordBatchfrom_arraysevaluateequals)r   builderfield_afield_br   field_resultnode_anode_b	conditionif_nodeexprconfig	projectorr   r   einput_batchrs                     O/var/www/openai/venv/lib/python3.12/site-packages/pyarrow/tests/test_gandiva.pytest_tree_exp_builderr>      s   %%%'GhhsBHHJ'GhhsBHHJ'GYY)*F88E288:.L(F(F7<<///%%nvv6F&(hhj2IooiDG""7L9D;;=+++""4"0F&&..0&&BI !!(+r111
!
3A
rxxz2A
!
3A..,,aVC:,FK			K	(BA88A;;    c                  2   dd l m}  t        j                  j	                  t        j
                  ddg      t        j
                  ddg      gddg      }| j                         }|j                  |j                  j                  d            }|j                  |j                  j                  d            }|j                  d||gt        j                               }t        j                  d	t        j                               }|j                  ||      }| j                  |j                  |gt        j                               }|j                  |j!                         d         \  }	t        j
                  dd
g      }
|	j#                  |
      sJ y )Nr         ?       @      @g      @r   r   addcg      @)r   r   r   Tabler,   r*   r   r   r   r   r    float64r#   r&   r'   r-   
to_batchesr.   )r   tabler/   r3   r4   sumr2   r7   r9   r<   r:   s              r=   
test_tablerK   B   s@   %HH  "((C:"6#s8L!M"%s-E %%'G 2 23 78F 2 23 78F


'7
FC88C.L""35D&&tfb4468I
 
		E,,.q1	2BA
#sA88A;;r?   c            	         dd l m}  t        j                  j	                  t        j
                  t        d      D cg c]  }d|z  	 c}      gdg      }| j                         }|j                  |j                  j                  d            }|j                  dt        j                               }|j                  d||gt        j                               }|j                  |      }|j!                         j"                  t        j                         k(  sJ | j%                  d      }| j'                  |j                  ||      }	|	j(                  j+                  d	      d
k7  sJ |	j-                  |j/                         d   t        j0                               }
|
j3                         j5                  t        j
                  t        d      t        j6                                     sJ y c c}w )Nr   i'  rA   r   g     @@	less_thanTr   r   r   i  r   )r   r   r   rF   r,   r*   ranger   r   r   r   make_literalrG   r    r!   make_conditionr$   r   r%   make_filterr(   r)   r-   rH   r'   to_arrayr.   uint32)r   irI   r/   r3   thousandcondr5   r8   filterr$   s              r=   test_filterrX   ]   s   %HH  "((U5\+J\C!G\+J"K!L"%(E %%'G 2 23 78F##FBJJL9H  vx.@"((*MD&&t,I""bhhj000""4"0F  y&AF>>x(B...__U--/2B4J4J4LMF??##BHHU4[ryy{$KLLL# ,Ks   G3c                     dd l m}  t        j                  g d      }t        j                  j                  |gdg      }| j                         }|j                  |j                  j                  d            }|j                  |ddgt        j                               }|j                  |      }| j                  |j                  |      }|j                  |j                         d   t        j                                }|j#                         j%                  t        j                  ddgt        j&                                     sJ t        j                  g d	      }t        j                  j                  |j)                  t        j*                               gdg      }|j                  |j                  j                  d            }|j                  |dd
gt        j*                               }|j                  |      }| j                  |j                  |      }|j                  |j                         d   t        j                                }|j#                         j%                  t        j                  g dt        j&                                     sJ t        j                  g d	      }t        j                  j                  |gdg      }|j                  |j                  j                  d            }|j                  |dd
gt        j,                               }|j                  |      }| j                  |j                  |      }|j                  |j                         d   t        j                                }|j#                         j%                  t        j                  g dt        j&                                     sJ y )Nr   )gaannddiivvar   r[   r\         r   )
   r`      r`   r   	   ra      r   rc   r   )r`   rb   rc      )r   r   r   r*   rF   r,   r   r   r   r   make_in_expressionstringrP   rQ   r-   rH   r'   rR   r.   rS   castr   int64)	r   arrrI   r/   r3   rV   r5   rW   r$   s	            r=   test_in_exprrl   u   s   %
((7
8CHH  #.E %%'G 2 23 78F%%ftTlBIIKHD&&t,I  y9F__U--/2B4J4J4LMF??##BHHaV"))+$FGGG ((1
2CHH  #((288:"6!7#?E 2 23 78F%%fq!fbhhjAD&&t,I  y9F__U--/2B4J4J4LMF??##BHH\		$LMMM ((1
2CHH  #.E 2 23 78F%%fq!fbhhjAD&&t,I  y9F__U--/2B4J4J4LMF??##BHH\		$LMMMr?   z>Gandiva C++ did not have *real* binary, time and date support.)reasonc                  
   dd l m}  t        j                  g d      }t        j                  j                  |gdg      }| j                         }|j                  |j                  j                  d            }|j                  |ddgt        j                               }|j                  |      }| j                  |j                  |      }|j                  |j                         d   t        j                                }|j#                         j%                  t        j                  ddgt        j&                                     sJ t(        j(                  j+                  d	      }	t(        j(                  j+                  d
      }
t(        j(                  j+                  d      }t        j                  |	|
|g      }t        j                  j                  |gdg      }| j                         }|j                  |j                  j                  d            }|j                  ||
gt        j,                  d            }|j                  |      }| j                  |j                  |      }|j                  |j                         d   t        j                                }t/        |j#                               dgk(  sJ |	j1                         }|
j1                         }|j1                         }t        j                  |||g      }t        j                  j                  |gdg      }| j                         }|j                  |j                  j                  d            }|j                  ||gt        j2                  d            }|j                  |      }| j                  |j                  |      }|j                  |j                         d   t        j                                }t/        |j#                               dgk(  sJ |	j5                         }|
j5                         }|j5                         }t        j                  |||g      }t        j                  j                  |gdg      }| j                         }|j                  |j                  j                  d            }|j                  ||gt        j6                               }|j                  |      }| j                  |j                  |      }|j                  |j                         d   t        j                                }t/        |j#                               dgk(  sJ y )Nr   )s   ga   an   nds   dis   ivs   var   ro   rp   r`   ra   r   g,Ag,Ag+Ams)r   r   r   r*   rF   r,   r   r   r   r   rg   binaryrP   rQ   r-   rH   r'   rR   r.   rS   datetimeutcfromtimestamp	timestamplisttimetime64datedate32)r   rk   rI   r/   r3   rV   r5   rW   r$   
datetime_1
datetime_2
datetime_3time_1time_2time_3date_1date_2date_3s                     r=   test_in_expr_todor      s5    & ((=
>CHH  #.E%%'G 2 23 78F%%fuenbiikJD&&t,I  y9F__U--/2B4J4J4LMF??##BHHaV"))+$FGGG ""334EFJ""334EFJ""334EFJ
((J
J7
8CHH  #.E%%'G 2 23 78F%%fzlBLL<NOD&&t,I  y9F__U--/2B4J4J4LMF!"qc))) __F__F__F
((FFF+
,CHH  #.E%%'G 2 23 78F%%fvh		$HD&&t,I  y9F__U--/2B4J4J4LMF!"qc))) __F__F__F
((FFF+
,CHH  #.E%%'G 2 23 78F%%fvh		DD&&t,I  y9F__U--/2B4J4J4LMF!"qc)))r?   c                     dd l m}  t        j                  j	                  t        j
                  g d      t        j
                  g d      gddg      }| j                         }|j                  |j                  j                  d            }|j                  |j                  j                  d            }|j                  dt        j                               }|j                  dt        j                               }|j                  d||gt        j                               }|j                  d	||gt        j                               }|j                  d||gt        j                               }	|j                  |j                  ||g      |	g      }
|j!                  |
      }| j#                  |j                  |      }|j%                  |j'                         d   t        j(                               }|j+                         j-                  t        j
                  g d
t        j.                                     sJ y )Nr   )rA   g      ?@g      G@rC   g     L@g      F@g      6@)g      @g     F@g      B@g     @R@g     T@g      7@g      S@r   r   g      I@g      &@rM   r   )r   ra   r   r   )r   r   r   rF   r,   r*   r   r   r   r   rO   rG   r    r!   make_ormake_andrP   rQ   r-   rH   r'   rR   r.   rS   )r   rI   r/   r3   r4   fiftyelevencond_1cond_2cond_3rV   r5   rW   r$   s                 r=   test_booleanr      s   %HH  
23
34"6 
c
E
 %%'G 2 23 78F 2 23 78F  rzz|4E!!$

5F"";LF"">FF3C#%88:/F"";0@"((*MF??G,,ff-=>GHD&&t,I  y9F__U--/2B4J4J4LMF??##BHHYRYY[$IJJJr?   c                     dd l m}  | j                         }|j                  dt	        j
                                |j                  dt	        j                                |j                  dt	        j                                |j                  dt	        j                                |j                  dt	        j                                |j                  dt	        j                                |j                  dt	        j                                |j                  dt	        j                                |j                  d	t	        j                                |j                  d
t	        j                                |j                  dt	        j                                |j                  dt	        j                                 |j                  dt	        j"                                |j                  dd       |j                  dd       |j                  dd       |j                  dd       |j                  dd       |j                  dd       |j                  dd       |j                  dd       |j                  d	d       |j                  d
d       |j                  dd       |j                  dd       |j                  dd       t%        j&                  t(              5  |j                  dt	        j                                d d d        t%        j&                  t(              5  |j                  dd        d d d        y # 1 sw Y   >xY w# 1 sw Y   y xY w)Nr   Tr`   ra   rb   rc   r   re      g       @g      "@hellos   worldbooluint8uint16rS   uint64int8int16r   rj   float32rG   rh   rr   )r   r   r   rO   r   r!   r   r   rS   r   r   r   r   rj   r   rG   rh   rr   pytestraises	TypeError)r   r/   s     r=   test_literalsr      s\   %%%'Grxxz*BHHJ'BIIK(BIIK(BIIK(BGGI&BHHJ'BHHJ'BHHJ'bjjl+bjjl+"))+.299;/v&G$H%H%H%F#G$G$G$i(i((+8,	y	!Wbhhj1 
"	y	!T4( 
"	! 
"	!	!	!s   .%M4MMM%c                  R   dd l m}  g d}t        j                  |t        j                               }t        j
                  j                  |gdg      }| j                         }|j                  |j                  j                  d            }|j                  dt        j                               }|j                  d||gt        j                               }t        j                  dt        j                               }|j                  ||      }	| j                  |j                  |	gt        j                                }
|
j#                  |j%                         d         \  }t        j                  g d	t        j                               }|j'                  |      sJ y )
Nr   )parksparklezbright spark and firesparkr   r   r   z%spark%liker   )FTTT)r   r   r   r*   rh   rF   r,   r   r   r   r   rO   r    r!   r#   r&   r'   r-   rH   r.   )r   elementsdatarI   r/   r3   regexr   r2   r7   r9   r<   r   s                r=   
test_regexr   '  s7   %DH88H299;/DHH  $u 5E%%'G 2 23 78F  BIIK8E  &%"((*ED88C,L""46D&&tfb4468I 
		E,,.q1	2BA
*<A88A;;r?   c                      dd l m}  | j                         }t        |d   j	                               t
        j                  u sJ t        |d   j                               t        u sJ t        |d   d      sJ y )Nr   name)
r   r   "get_registered_function_signaturesr   r   r   DataTypeparam_typesrv   hasattr)r   
signaturess     r=   'test_get_registered_function_signaturesr   ?  sk    %;;=J
1))+,;;;
1))+,444:a=&)))r?   c                     dd l m}  t        j                         }t        j                  g dt        j
                               }t        j                  g dt        j
                               }t        j                  g dt        j
                               }t        j                  j                  |||gg d      }t        j                  dt        j
                               }| j                         }|j                  |j                  j                  d            }|j                  |j                  j                  d            }	|j                  |j                  j                  d	            }
|j                  d
||	gt        j                               }|j                  |      }|j                  d|	|
gt        j                               }|j                  ||	|
t        j
                               }|j!                  ||      }| j#                  |j                  |      }| j%                  |j                  |g|d      }|j'                  |j)                         d   |      }|j'                  |j)                         d   |      \  }t        j                  g dt        j
                               }|j+                  |      sJ y )Nr   )r   r   r   r         )r   r   r   r   r   rb   )r`            N)r   r   rE   r   r   r   rE   r   rM   UINT32)r`   r   N)r   r   r   r'   r*   r   rF   r,   r   r   r   r   r    r!   rP   r"   r#   rQ   r&   r-   rH   r.   )r   mpoolarray0array1array2rI   r2   r/   r3   r4   node_cgreater_than_functionfilter_conditionproject_conditionr6   r7   rW   r9   selection_vectorr<   exps                        r=   test_filter_projectr   I  s/   %""$EXX.
;FXX,bhhj9FXX0"((*=FHH  &&&!9?KE88E288:.L%%'G 2 23 78F 2 23 78F 2 23 78F#11.3962BBHHJP--  --k/5v.>
Loo/$fbhhj:G""7L9D   /?@F &&tfeX/I u'7'7'9!'<eD 
		1/
1BA ((>288:
.C88C==r?   c            	         dd l m}  | j                         }t        |j	                  dt        j                                     j                  d      sJ t        |j	                  dt        j                                     dk(  sJ t        |j                  t        j                  dt        j                                           dk(  sJ t        |j                  t        j                  dt        j                                           d	k(  sJ |j                  t        j                  d
t        j                                     }|j                  d|gt        j                               }t        |      dk(  sJ |j                  t        j                  dt        j                                     }|j                  ||g      }t        |      dk(  sJ y )Nr   rB   z(const double) 2 raw(ra   z(const int64) 2xz
(double) xyz
(string) yznotzbool not((bool) z)zbool not((bool) z) && (bool) y)r   r   r   strrO   r   rG   
startswithrj   r   r   rh   r!   r    r   )r   r/   field_z	func_nodefield_yand_nodes         r=   test_to_stringr   x  sh   %%%'Gw##C6 345 5 5w##Arxxz237HHHHw!!"((3

"=>?<OOOw!!"((3		"<=>,NNN  #rxxz!:;G%%egY
CIy>1111  #rxxz!:;GG 45Hx=<<<<r?   c                  \   dd l m}  | j                         }t        j                  dt        j
                               }t        j                  |g      }|j                  dt        j                               }t        j                  t              5  |j                  d        d d d        t        j                  t              5  |j                  |d d d        d d d        t        j                  t              5  |j                  |d g       d d d        t        j                  t              5  |j                  d |g       d d d        t        j                  t              5  |j!                  d g dt        j
                                d d d        t        j                  t              5  |j#                  d |       d d d        t        j                  t              5  |j%                  d        d d d        t        j                  t              5  |j'                  d|d gt        j                                d d d        t        j                  t              5  | j)                  |d g       d d d        t        j                  t              5  | j+                  |d        d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   XxY w# 1 sw Y   1xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   y xY w)Nr   r   T)r`   ra   rb   rM   )r   r   r   r   r   r   r   rO   r!   r   r   r   r   r"   r   r   rg   r#   rP   r    r&   rQ   )r   r/   field_xr   literal_trues        r=   test_rejects_noner     s#   %%%'GhhsBHHJ'GYYy!F''bhhj9L	y	!4  
" 
y	!dD$7 
" 
y	!,-. 
" 
y	!|,- 
" 
y	!""4BHHJ? 
" 
y	!g. 
" 
y	!t$ 
" 
y	!kL$+?L 
" 
y	!vv. 
" 
y	!FD) 
"	!7 
"	! 
"	! 
"	! 
"	! 
"	! 
"	! 
"	! 
"	! 
"	! 
"	!sx   J/J<;K	0K%(K#.K0"K=(L
LL"/J9<K	KK #K-0K:=L
LL"L+)rs   r   pyarrowr   markr   r>   rK   rX   rl   skipr   r   r   r   r   r   r   r    r?   r=   <module>r      s  $    & &R  4 M M. !N !NH  2 3E*3E*P K K4 $) $)N  . * * + +\ = =& %* %*r?   