K i=ddlmZmZmZddlmZmZ ddlmZm Z m Z m Z m Z m Z mZmZmZ ddlmZddlmZdd Zddd d edfd Zd efdZdZefdZddZy#e$rZedeedddZ[wwxYw#e$rGdd ZeZYTwxYw))Table RecordBatcharray) Expressionfield) DeclarationExecNodeOptionsTableSourceNodeOptionsFilterNodeOptionsProjectNodeOptionsAggregateNodeOptionsOrderByNodeOptionsHashJoinNodeOptionsAsofJoinNodeOptionsz@The pyarrow installation is not built with support for 'acero' ()N)ScanNodeOptionsc4eZdZGddZGddZy)DatasetModuleStubc eZdZy)DatasetModuleStub.DatasetN__name__ __module__ __qualname__S/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/pyarrow/acero.pyDatasetr3 rrc eZdZy)!DatasetModuleStub.InMemoryDatasetNrrrrInMemoryDatasetr!6rrr"N)rrrrr"rrrrr2s    rrTFc ztdt|||}|jjDcgc] }t |}}tj |tdt |g}|jjd}|*tj |tdt|g}|Scc}w)Nscan use_threadsimplicit_orderingprojectfilter) rrschemanamesr from_sequencer _scan_optionsgetr )datasetr&r'declf projections filter_exprs r_dataset_to_declr4;s v[+ - .D &-^^%9%9:58:K:  $ $ {9&8&EFG D''++H5K(( ;x):;)GH I  K;sB8c t|ttjfst dt |t|ttjfst dt |i} t|t tfs|g}t|D] \} } | | | < i}t|tt fs|g}t|D] \} } | || < |jj}|jj}|dk(s|dk(rg}nE|dk(s|dk(rg}n8|dk(s|dk(r|Dcgc] }||vs| }}n|dk(r|Dcgc] }|| vs| }}i}t|D]\} }||vs | ||<i}t|D]\} }||vs | ||<t|tjrt|| }ntd t|}t|tjrt|| }ntd t|}|rt||||||xsd |xsd | }nt||||xsd |xsd | }td |||g}|rL|dk(rFt|}t|}t!|}g}g}t||zD]\} }| t!|krq||vrm|j#|||| |}|j#t%j&dt%j(| t%j(||zg| |k\r||vr|r| |kr ||vr||z }|r| |k\r ||vr||z }|j#||j#t%j(| tdt+||}tj,||g}|j/| } | tk(r| S| tj0k(rtj0| St dcc}wcc}w)a Perform join of two tables or datasets. The result will be an output table with the result of the join operation Parameters ---------- join_type : str One of supported join types. left_operand : Table or Dataset The left operand for the join operation. left_keys : str or list[str] The left key (or keys) on which the join operation should be performed. right_operand : Table or Dataset The right operand for the join operation. right_keys : str or list[str] The right key (or keys) on which the join operation should be performed. left_suffix : str, default None Which suffix to add to left column names. This prevents confusion when the columns in left and right operands have colliding names. right_suffix : str, default None Which suffix to add to the right column names. This prevents confusion when the columns in left and right operands have colliding names. use_threads : bool, default True Whether to use multithreading or not. coalesce_keys : bool, default False If the duplicated keys should be omitted from one of the sides in the join result. output_type: Table or InMemoryDataset The output type for the exec plan result. filter_expression : pyarrow.compute.Expression Residual filter which is applied to matching row. Returns ------- result_table : Table or InMemoryDataset Expected Table or Dataset, got z left semiz left antiz right semiz right antiinnerz left outerz right outerr& table_source)output_suffix_for_leftoutput_suffix_for_rightfilter_expressionhashjoinoptionsinputsz full outercoalescer(Unsupported output type) isinstancerdsr TypeErrortypetuplelist enumerater*r+r4rr rsetlenappendr_call_fieldr r,to_tabler")! join_type left_operand left_keys right_operand right_keys left_suffix right_suffixr& coalesce_keys output_typer=left_keys_orderidxkeyright_keys_order left_columns right_columnscolleft_column_keys_indicescolnameright_column_keys_indices left_source right_source join_optsr0left_columns_setright_columns_setright_operand_indexprojected_col_namesr2right_key_index projection result_tables! r _perform_joinrnRsT lUBJJ$7 89$|:L9MNOO meRZZ%8 99$}:M9NOPPO i% /K i(#S"# j4- 0 \ j)$S #$ &&,,L!((..MK9 #; l "i<&? g l!:( C7G,GC   m #' 3o+EC  "!,/4 W i 03 $W -4!#!-05 W j 14 %g .5 , +&|M !.2H2VW -,' ;O " 2=A ' y*lM#.#4"$0$6B/  ( y*#.#4"$0$6B/  I{L.I Dl2|, .!,/  !,">?$ HCS&&32J+J#**3/ #<s34#6""$$Z"))#. 0A0A/?1A2 ++7P0P  C*=$=00;&C S,?%?//<'C#**3/""%%c*E$ J! )+7JK (($ );<==[=9Le ** *!!,//122Y  s) O13O1 O6 O6c t|ttjfst dt |t|ttjfst dt |t|t tfs|g}t|t tfs|g}|jjD cgc] } | |g|zvr| } } t|jjt| z} | rtd| dt|tjrt||d} ntdt|} t|tjrt||d} ntdt|} t|||||}td|| | g}|j!| }|tk(r|S|tj"k(rtj"|St d cc} w) a- Perform asof join of two tables or datasets. The result will be an output table with the result of the join operation Parameters ---------- left_operand : Table or Dataset The left operand for the join operation. left_on : str The left key (or keys) on which the join operation should be performed. left_by: str or list[str] The left key (or keys) on which the join operation should be performed. right_operand : Table or Dataset The right operand for the join operation. right_on : str or list[str] The right key (or keys) on which the join operation should be performed. right_by: str or list[str] The right key (or keys) on which the join operation should be performed. tolerance : int The tolerance to use for the asof join. The tolerance is interpreted in the same units as the "on" key. output_type: Table or InMemoryDataset The output type for the exec plan result. Returns ------- result_table : Table or InMemoryDataset r6zColumns zE present in both tables. AsofJoin does not support column collisions.Tr%r9asofjoinr?r8rC)rDrrErrFrGrHrIr*r+rK ValueErrorr4rr rrPr")rRleft_onleft_byrTright_onright_by tolerancer&rYr`r_columns_collisionsrdrerfr0rms r_perform_join_asofrxsB lUBJJ$7 89$|:L9MNOO meRZZ%8 99$}:M9NOPP gt} -) h .:%++11 xj8+ + M\00667#m:LL)*+; ;  , +& #"$ " 2<@ -,' {"$ # 2=A $(HiI I{L.I D==[=9Le ** *!!,//122Ys9G3c  d}t|trtj|g}d}t j t dt |t dt|g}|jd}|r|jdkDr#|jjd}|S|jDcgc]}tg|j}}tj||j }|Scc}w) aFilter rows of a table based on the provided expression. The result will be an output table with only the rows matching the provided expression. Parameters ---------- table : Table or RecordBatch Table that should be filtered. expression : Expression The expression on which rows should be filtered. Returns ------- Table or RecordBatch FTr9)r@r)r8r)rG)r*)rDrr from_batchesrr,r r rPnum_rowscombine_chunks to_batchesr*rrG from_arrays)table expressionis_batchr0resultrarrayss r _filter_tablerbs"H%%""E7+  $ $N,B5,IJH&7 &CD& D]]t] ,F ??Q **,779!Dc vt|tjrt|d}nt dt |}t dt |fi|}t j||g}|jd}|tk(r|S|tjk(rtj|Std)NTr8r9order_byrC) rDrErr4rr rr,rPrr"rF)table_or_dataset sort_keysrYkwargs data_sourcerr0rms r _sort_sourcers"BJJ/&'7TJ ! 23CD :'9)'Nv'NOH  $ $k8%< =D==T=2Le ** *!!,//122rc tjtdt|tdt||g}|j |S)Nr9 aggregate)keysr8)rr,r r rP)r aggregatesrr&r0s r _group_byrsL  $ $N$:5$ABK!5jt!LM& D ==[= 11r)TF)T) pyarrow.librrrpyarrow.computerrpyarrow._acerorr r r r r rrr ImportErrorexcstrpyarrow.datasetr/rEpyarrow._datasetrrr4rnrxrrrrrrrs221-   "  02#"%#t r3n/3#(X3v!H;@3,2i   J3s8*TUV   Bs(A A8A5A00A58B  B