d}i!?6ddlmZmZmZddlmZmZ ddlmZm Z m Z m Z m Z m Z mZmZmZn&#e$rZedeedddZ[wwxYw ddlmZddlmZn#e$rGdd ZeZYnwxYwdd Zddd d edfd Zd efdZdZefdZddZdS))Table RecordBatcharray) Expressionfield) DeclarationExecNodeOptionsTableSourceNodeOptionsFilterNodeOptionsProjectNodeOptionsAggregateNodeOptionsOrderByNodeOptionsHashJoinNodeOptionsAsofJoinNodeOptionsz@The pyarrow installation is not built with support for 'acero' ()N)ScanNodeOptionscBeZdZGddZGddZdS)DatasetModuleStubceZdZdS)DatasetModuleStub.DatasetN__name__ __module__ __qualname__;C:\PYTHON\_runtimes\venv\Lib\site-packages\pyarrow/acero.pyDatasetr3 DrrceZdZdS)!DatasetModuleStub.InMemoryDatasetNrrrrInMemoryDatasetr!6rrr"N)rrrrr"rrrrr2sd                  rrTFc ntdt|||}d|jjD}tj|tdt |g}|jd}|1tj|tdt|g}|S)Nscan use_threadsimplicit_orderingc,g|]}t|Sr)r).0fs r z$_dataset_to_decl..Bs:::588:::rprojectfilter) rrschemanames from_sequencer _scan_optionsgetr )datasetr&r'decl projections filter_exprs r_dataset_to_declr7;s v[+ - - - . .D ;:W^%9:::K  $ {9&8&E&EFFG  D'++H55K( ;x):;)G)GHH I   Krc  t|ttjfst dt |t|ttjfst dt |it|t tfs|g}t|D] \} } | | < i t|tt fs|g}t|D] \} } | | < |j j } |j j }|dks|dkrg}n>|dks|dkrg} n/|dks|dkr fd|D}n|d krfd | D} i}t| D]\} }||vr| ||<i}t|D]\} }||vr| ||<t|tjrt|| }ntd t|}t|tjrt|| }ntd t|}|rt|||| ||pd |pd | }nt||||pd |pd | }td|||g}|r|dkrzt| }t|}t!| }g}g}t| |zD]\} }| t!| kr||vr{|||||}|t%jdt%j| t%j||zg| |kr||vr|r| |kr ||vr||z }|r| |kr ||vr||z }|||t%j| tdt+||}tj||g}|| }| tkr|S| tjkrtj|St d)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 outercg|]}|v| Srr)r)colright_keys_orders rr+z!_perform_join..s+   C7G,G,GC,G,G,Grz right outercg|]}|v| Srr)r)r<left_keys_orders rr+z!_perform_join..s*   3o+E+EC+E+E+Err& table_source)output_suffix_for_leftoutput_suffix_for_rightfilter_expressionhashjoinoptionsinputsz full outercoalescer,Unsupported output type) isinstancerdsr TypeErrortypetuplelist enumerater.r/r7rr rsetlenappendr_call_fieldr r0to_tabler")! join_type left_operand left_keys right_operand right_keys left_suffix right_suffixr& coalesce_keys output_typerEidxkey left_columns right_columnsleft_column_keys_indicescolnameright_column_keys_indices left_source right_source join_optsr4left_columns_setright_columns_setright_operand_indexprojected_col_namesr5r<right_key_index projection result_tabler?r=s! @@r _perform_joinrsRsT lUBJ$7 8 8PN$|:L:LNNOOO meRZ%8 9 9QO$}:M:MOOPPPO i% / / K i((##S" j4- 0 0" \ j))$$S # &,L!(.MK9 #;#; l " "i<&?&? g  l!:!:    (    m # #    '   "!,//44 W i  03 $W - "!-0055 W j 14 %g ., ++X&|MMM !.2H2V2VWW -,, ' ;OOO " 2=AA    ' y*lM#.#4"$0$6B/    ( y*#.#4"$0$6B/    I{L.I   D2=l22|,, ..!,//  !,">??$ $ HCS&&&&32J+J+J#**3/// #<s34#6""$Z")#.. 0A/?1A1A2 +++7P0P0P  '$'*=$=$=000;&C (%(,?%?%?///<'C#**3///""%c**! )+7JKK  ($ );<<==[=99Le * * *!,///1222rc Rt|ttjfst dt |t|ttjfst dt |t|t tfs|g}tt tfsgfd|jj D} t|jj t| z} | rtd| dt|tjrt||d} ntdt|} t|tjrt||d} ntdt|} t|||} td| | | g }|| }|tkr|S|tjkrtj|St d ) 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 r9c$g|] }|gzv | Srr)r)r<right_byright_ons rr+z&_perform_join_asof..3s5 xj8+ + + + + +rzColumns zE present in both tables. AsofJoin does not support column collisions.Tr%rAasofjoinrGr@rK)rLrrMrrNrOrPrQr.r/rS ValueErrorr7rr rrXr")rZleft_onleft_byr\rwrv tolerancer&rarecolumns_collisionsrirjrkr4rrs `` r_perform_join_asofr~ssB lUBJ$7 8 8PN$|:L:LNNOOO meRZ%8 9 9QO$}:M:MOOPPP gt} - -) h . .:$+1M\0677#m:L:LL  ;) ; ; ;   , ++ & #"$$$ " 2<@@  -,, ' {"$$$ # 2=AA  $(HiI I{L.I   D==[=99Le * * *!,///1222rc d}t|trtj|g}d}t jt dt |t dt|g}|d}|rd|j dkr-| d}n,d|j D}tj ||j }|S) 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 FTrA)rHr-r@rc:g|]}tg|jS))rO)rrO)r)rs rr+z!_filter_table..s'LLLUeBUZ000LLLr)r.)rLrr from_batchesrr0r r rXnum_rowscombine_chunks to_batchesr. from_arrays)table expressionis_batchr4resultarrayss r _filter_tablerbs"H%%%"E7++  $N,B5,I,IJJJH&7 &C&CDDD&  D]]t] , ,FK ?Q  **,,7799!rs$22111111111--------                        +V33s88VVV          0000000 BBB2#"%#t r3r3r3r3n/3#(X3X3X3X3v!!!H;@3333,222222s&+AA  A AA65A6