
    z-Ph=                     4   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        
                    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dS )    Nc                  l   dd l m}  |                                 }t          j        dt          j                              }t          j        dt          j                              }t          j        ||g          }t          j        dt          j                              }|                    |          }|                    |          }|                                |j	        k    sJ |
                    d||gt          j                              }|                    |||t          j                              }	|                    |	|          }
|
                                j	        t          j                    k    sJ |                     d          }|                     ||
gt          j                    d|          }|j                            d	          d
k    sJ t          j        g dt          j                              }t          j        g dt          j                              }t          j        g dt          j                              }t          j                            ||gddg          }|                    |          \  }|                    |          sJ d S )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                     Z/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/pyarrow/tests/test_gandiva.pytest_tree_exp_builderr>      sX   %%%%%%%%''GhsBHJJ''GhsBHJJ''GY)**F8E28::..L((F((F7<////%%nvv6F&(hjj2 2IooiDDG""7L99D;;==++++""4"00F&&.00&&B BI !!(++r1111
!!!

333A
rxzz222A
!!!

333A.,,aVC:,FFK			K	(	(BA88A;;    c                  f   dd l m}  t          j                            t          j        ddg          t          j        ddg          gddg          }|                                 }|                    |j        	                    d                    }|                    |j        	                    d                    }|
                    d||gt          j                              }t          j	        d	t          j                              }|                    ||          }|                     |j        |gt          j                              }|                    |                                d                   \  }	t          j        dd
g          }
|	                    |
          sJ d S )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|   %%%%%%H  "(C:"6"6#s8L8L!M"%s- -E %%''G 2 23 7 788F 2 23 7 788F


'7
F
FC8C..L""355D&&tfb4668 8I
 
		E,,..q1	2	2BA
#sA88A;;r?   c                  .   dd l m}  t          j                            t          j        d t          d          D                       gdg          }|                                 }|                    |j	        
                    d                    }|                    dt          j                              }|                    d||gt          j                              }|                    |          }|                                j        t          j                    k    sJ |                     d          }|                     |j	        ||          }|j                            d	          d
k    sJ |                    |                                d         t          j                              }	|	                                                    t          j        t          d          t          j                                        sJ d S )Nr   c                     g | ]}d |z  S )rA    ).0is     r=   
<listcomp>ztest_filter.<locals>.<listcomp>a   s    +J+J+JC!G+J+J+Jr?   i'  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   rI   r/   r3   thousandcondr5   r8   filterr$   s
             r=   test_filterr\   ]   s   %%%%%%H  "(+J+JU5\\+J+J+J"K"K!L"%( (E %%''G 2 23 7 788F##FBJLL99H  vx.@"(**MMD&&t,,I"bhjj0000""4"00F  y&AAF>x((B....__U--//2B4J4L4LMMF??##BHU4[[ry{{$K$K$KLLLLLLLr?   c                  V   dd l m}  t          j        g d          }t          j                            |gdg          }|                                 }|                    |j        	                    d                    }|
                    |ddgt          j                              }|                    |          }|                     |j        |          }|                    |                                d         t          j                              }|                                                    t          j        ddgt          j                                        sJ t          j        g d	          }t          j                            |                    t          j                              gdg          }|                    |j        	                    d                    }|
                    |dd
gt          j                              }|                    |          }|                     |j        |          }|                    |                                d         t          j                              }|                                                    t          j        g dt          j                                        sJ t          j        g d	          }t          j                            |gdg          }|                    |j        	                    d                    }|
                    |dd
gt          j                              }|                    |          }|                     |j        |          }|                    |                                d         t          j                              }|                                                    t          j        g dt          j                                        sJ d S )Nr   )gaannddiivvar   r_   r`         r   )
   rd      rd   r   	   re      r   rg   r   )rd   rf   rg      )r   r   r   r*   rF   r,   r   r   r   r   make_in_expressionstringrU   rV   r-   rH   r'   rW   r.   rX   castr   int64)	r   arrrI   r/   r3   rZ   r5   r[   r$   s	            r=   test_in_exprrp   u   s_   %%%%%%
(777
8
8CH  #..E %%''G 2 23 7 788F%%ftTlBIKKHHD&&t,,I  y99F__U--//2B4J4L4LMMF??##BHaV")++$F$F$FGGGGG (111
2
2CH  #((28::"6"6!7#??E 2 23 7 788F%%fq!fbhjjAAD&&t,,I  y99F__U--//2B4J4L4LMMF??##BH\\\	$L$L$LMMMMM (111
2
2CH  #..E 2 23 7 788F%%fq!fbhjjAAD&&t,,I  y99F__U--//2B4J4L4LMMF??##BH\\\	$L$L$LMMMM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                            |gdg          }|                                 }|                    |j        	                    d                    }|
                    |ddgt          j                              }|                    |          }|                     |j        |          }|                    |                                d         t          j                              }|                                                    t          j        ddgt          j                                        sJ t(          j                            d	          }	t(          j                            d
          }
t(          j                            d          }t          j        |	|
|g          }t          j                            |gdg          }|                                 }|                    |j        	                    d                    }|
                    ||
gt          j        d                    }|                    |          }|                     |j        |          }|                    |                                d         t          j                              }t/          |                                          dgk    sJ |	                                }|
                                }|                                }t          j        |||g          }t          j                            |gdg          }|                                 }|                    |j        	                    d                    }|
                    ||gt          j        d                    }|                    |          }|                     |j        |          }|                    |                                d         t          j                              }t/          |                                          dgk    sJ |	                                }|
                                }|                                }t          j        |||g          }t          j                            |gdg          }|                                 }|                    |j        	                    d                    }|
                    ||gt          j                              }|                    |          }|                     |j        |          }|                    |                                d         t          j                              }t/          |                                          dgk    sJ d S )Nr   )s   ga   an   nds   dis   ivs   var   rs   rt   rd   re   r   g,Ag,Ag+Ams)r   r   r   r*   rF   r,   r   r   r   r   rk   binaryrU   rV   r-   rH   r'   rW   r.   rX   datetimeutcfromtimestamp	timestamplisttimetime64datedate32)r   ro   rI   r/   r3   rZ   r5   r[   r$   
datetime_1
datetime_2
datetime_3time_1time_2time_3date_1date_2date_3s                     r=   test_in_expr_todor      s    &%%%%% (===
>
>CH  #..E%%''G 2 23 7 788F%%fuenbikkJJD&&t,,I  y99F__U--//2B4J4L4LMMF??##BHaV")++$F$F$FGGGGG "334EFFJ"334EFFJ"334EFFJ
(J
J7
8
8CH  #..E%%''G 2 23 7 788F%%fzlBL<N<NOOD&&t,,I  y99F__U--//2B4J4L4LMMF!!""qc)))) __F__F__F
(FFF+
,
,CH  #..E%%''G 2 23 7 788F%%fvh	$HHD&&t,,I  y99F__U--//2B4J4L4LMMF!!""qc)))) __F__F__F
(FFF+
,
,CH  #..E%%''G 2 23 7 788F%%fvh	DDD&&t,,I  y99F__U--//2B4J4L4LMMF!!""qc))))))r?   c                     dd l m}  t          j                            t          j        g d          t          j        g d          gddg          }|                                 }|                    |j        	                    d                    }|                    |j        	                    d                    }|
                    dt          j                              }|
                    dt          j                              }|                    d||gt          j                              }|                    d	||gt          j                              }|                    d||gt          j                              }	|                    |                    ||g          |	g          }
|                    |
          }|                     |j        |          }|                    |                                d         t          j                              }|                                                    t          j        g d
t          j                                        sJ d S )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      &@rR   r   )r   re   r   r   )r   r   r   rF   r,   r*   r   r   r   r   rT   rG   r    r!   make_ormake_andrU   rV   r-   rH   r'   rW   r.   rX   )r   rI   r/   r3   r4   fiftyelevencond_1cond_2cond_3rZ   r5   r[   r$   s                 r=   test_booleanr      s   %%%%%%H  
22233
33344"6 
c
 E
 %%''G 2 23 7 788F 2 23 7 788F  rz||44E!!$
55F"";LLF"">FF3C#%8::/ /F"";0@"(**MMF??G,,ff-=>>GHHD&&t,,I  y99F__U--//2B4J4L4LMMF??##BHYYYRY[[$I$I$IJJJJJJJr?   c                     dd l m}  |                                 }|                    dt	          j                               |                    dt	          j                               |                    dt	          j                               |                    dt	          j                               |                    dt	          j	                               |                    dt	          j
                               |                    dt	          j                               |                    dt	          j                               |                    d	t	          j                               |                    d
t	          j                               |                    dt	          j                               |                    dt	          j                               |                    dt	          j                               |                    dd           |                    dd           |                    dd           |                    dd           |                    dd           |                    dd           |                    dd           |                    dd           |                    d	d           |                    d
d           |                    dd           |                    dd           |                    dd           t%          j        t(                    5  |                    dt	          j                               d d d            n# 1 swxY w Y   t%          j        t(                    5  |                    dd            d d d            d S # 1 swxY w Y   d S )Nr   Trd   re   rf   rg   r   ri      g       @g      "@hellos   worldbooluint8uint16rX   uint64int8int16r   rn   float32rG   rl   rv   )r   r   r   rT   r   r!   r   r   rX   r   r   r   r   rn   r   rG   rl   rv   pytestraises	TypeError)r   r/   s     r=   test_literalsr      s   %%%%%%%%''Grxzz***BHJJ'''BIKK(((BIKK(((BIKK(((BGII&&&BHJJ'''BHJJ'''BHJJ'''bjll+++bjll+++")++...29;;///v&&&G$$$H%%%H%%%H%%%F###G$$$G$$$G$$$i(((i((((+++8,,,	y	!	! 2 2Wbhjj1112 2 2 2 2 2 2 2 2 2 2 2 2 2 2	y	!	! ) )T4((() ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) )s$   (NNN%O		OOc                     dd l m}  g d}t          j        |t          j                              }t          j                            |gdg          }|                                 }|                    |j	        
                    d                    }|                    dt          j                              }|                    d||gt          j                              }t          j
        dt          j                              }|                    ||          }	|                     |j	        |	gt          j                              }
|
                    |                                d                   \  }t          j        g d	t          j                              }|                    |          sJ d S )
Nr   )parksparklezbright spark and firesparkr   r   r   z%spark%liker   )FTTT)r   r   r   r*   rl   rF   r,   r   r   r   r   rT   r    r!   r#   r&   r'   r-   rH   r.   )r   elementsdatarI   r/   r3   regexr   r2   r7   r9   r<   r   s                r=   
test_regexr   '  s   %%%%%%DDDH8H29;;///DH  $u 55E%%''G 2 23 7 788F  BIKK88E  &%"(**EED8C,,L""466D&&tfb4668 8I 
		E,,..q1	2	2BA
***<<<A88A;;r?   c                  4   dd l m}  |                                 }t          |d                                                   t
          j        u sJ t          |d                                                   t          u sJ t          |d         d          sJ d S )Nr   name)
r   r   "get_registered_function_signaturesr   r   r   DataTypeparam_typesrz   hasattr)r   
signaturess     r=   'test_get_registered_function_signaturesr   ?  s    %%%%%%;;==J
1))++,,;;;;
1))++,,4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                            |||gg d          }t          j        dt          j                              }| 	                                }|
                    |j                            d                    }|
                    |j                            d                    }	|
                    |j                            d	                    }
|                    d
||	gt          j                              }|                    |          }|                    d|	|
gt          j                              }|                    ||	|
t          j                              }|                    ||          }|                     |j        |          }|                     |j        |g|d          }|                    |                                d         |          }|                    |                                d         |          \  }t          j        g dt          j                              }|                    |          sJ d S )Nr   )r   r   r   r         )r   r   r   r   r   rf   )rd            N)r   r   rE   r   r   r   rE   r   rR   UINT32)rd   r   N)r   r   r   r'   r*   r   rF   r,   r   r   r   r   r    r!   rU   r"   r#   rV   r&   r-   rH   r.   )r   mpoolarray0array1array2rI   r2   r/   r3   r4   node_cgreater_than_functionfilter_conditionproject_conditionr6   r7   r[   r9   selection_vectorr<   exps                        r=   test_filter_projectr   I  s   %%%%%%"$$EX...

;;FX,,,bhjj99FX000"(**==FH  &&&!9???KKE8E28::..L%%''G 2 23 7 788F 2 23 7 788F 2 23 7 788F#11.3962BBHJJP P--   --k/5v.>

L Loo/$fbhjj: :G""7L99D   /?@@F &&tfeX/ /I u'7'7'9'9!'<eDD 
		1/
1 
1BA (>>>28::
.
.C88C==r?   c            	      (   dd l m}  |                                 }t          |                    dt          j                                                            d          sJ t          |                    dt          j                                        dk    sJ t          |	                    t          j
        dt          j                                                  dk    sJ t          |	                    t          j
        dt          j                                                  d	k    sJ |	                    t          j
        d
t          j                                        }|                    d|gt          j                              }t          |          dk    sJ |	                    t          j
        dt          j                                        }|                    ||g          }t          |          dk    sJ d S )Nr   rB   z(const double) 2 raw(re   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   strrT   r   rG   
startswithrn   r   r   rl   r!   r    r   )r   r/   field_z	func_nodefield_yand_nodes         r=   test_to_stringr   x  s   %%%%%%%%''Gw##C66  3445 5 5w##Arxzz22337HHHHHw!!"(3
"="=>>??<OOOOw!!"(3	"<"<==>>,NNNN  #rxzz!:!:;;G%%egY

CCIy>>11111  #rxzz!:!:;;GG 455Hx==<<<<<<<r?   c                     dd l m}  |                                 }t          j        dt          j                              }t          j        |g          }|                    dt          j                              }t          j
        t                    5  |                    d            d d d            n# 1 swxY w Y   t          j
        t                    5  |                    |d d d            d d d            n# 1 swxY w Y   t          j
        t                    5  |                    |d g           d d d            n# 1 swxY w Y   t          j
        t                    5  |                    d |g           d d d            n# 1 swxY w Y   t          j
        t                    5  |                    d g dt          j                               d d d            n# 1 swxY w Y   t          j
        t                    5  |                    d |           d d d            n# 1 swxY w Y   t          j
        t                    5  |                    d            d d d            n# 1 swxY w Y   t          j
        t                    5  |                    d|d gt          j                               d d d            n# 1 swxY w Y   t          j
        t                    5  |                     |d g           d d d            n# 1 swxY w Y   t          j
        t                    5  |                     |d            d d d            d S # 1 swxY w Y   d S )Nr   r   T)rd   re   rf   rR   )r   r   r   r   r   r   r   rT   r!   r   r   r   r   r"   r   r   rk   r#   rU   r    r&   rV   )r   r/   field_xr   literal_trues        r=   test_rejects_noner     s   %%%%%%%%''GhsBHJJ''GYy!!F''bhjj99L	y	!	! ! !4   ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! 
y	!	! 8 8dD$7778 8 8 8 8 8 8 8 8 8 8 8 8 8 8 
y	!	! / /,-.../ / / / / / / / / / / / / / / 
y	!	! . .|,---. . . . . . . . . . . . . . . 
y	!	! @ @""4BHJJ???@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ 
y	!	! / /g.../ / / / / / / / / / / / / / / 
y	!	! % %t$$$% % % % % % % % % % % % % % % 
y	!	! M MkL$+?LLLM M M M M M M M M M M M M M M 
y	!	! / /vv.../ / / / / / / / / / / / / / / 
y	!	! * *FD)))* * * * * * * * * * * * * * * * * *s   B88B<?B<DDD%E		EE-FFF5+G,,G03G0H33H7:H7I99I= I=+KKK8LL #L  M$$M(+M()rw   r   pyarrowr   markr   r>   rK   r\   rp   skipr   r   r   r   r   r   r   r   rN   r?   r=   <module>r      s  $       & & &R   4 M M M. !N !N !NH  2 3 3E* E*3 3E*P K K K4 $) $) $)N   . * * * + + +\ = = =& %* %* %* %* %*r?   