
    gw              
       N   d dl Z d dlZd dlZd dlZd dlmZ d dlm	Z	 d dlm
Z
mZ 	 d dlmZ ej                  j                  Zd'dZd Zej                  j'                  dddg      d	        Zej                  j'                  d
 ej*                  d      ddf      d        Zd Zej                  j'                  dddg      d        Zd Zd Zej                  j'                  dddg      d        Zd Zd Zej                  j'                  dddg      d        Zd Zej                  j'                  dddg      d        Z ej                  jB                  d        Z"ej                  jB                  d        Z#ej                  j'                  d ejH                   ejJ                  d      d       ejH                   ejJ                  d       ejJ                  d             ejJ                  d      dkD  g      d         Z&d! Z'd" Z(d# Z)d$ Z*d% Z+d& Z,y# e$ r dZY w xY w)(    N)tobytes)ArrowInvalidArrowNotImplementedErrorc                 D    ddl m}  |t        j                         |       S )Nr   )_get_udf_context)pyarrow._computer   padefault_memory_pool)batch_lengthr   s     Q/var/www/openai/venv/lib/python3.12/site-packages/pyarrow/tests/test_substrait.pymock_udf_contextr   &   s    1B224lCC    c                     t         j                  j                  t        |       |      }t        j
                  j                  ||j                        5 }|j                  |       d d d        |S # 1 sw Y   |S xY w)N)schema)	ospathjoinstrr	   ipcRecordBatchFileWriterr   write_table)tmpdir	file_nametabler   writers        r   _write_dummy_data_to_diskr   +   s\    77<<FY/D		%	%d5<<	%	@F5! 
AK 
AKs   A11A;use_threadsTFc                    d}d}t        j                  g dgdg      }t        | ||      }t        |j	                  dt        j                  |      j                                     }t         j                  j                  |      }t        j                  ||      }|j                         }	|j                  dg      |	j                  dg      k(  sJ y )Nax  
    {
        "version": { "major": 9999 },
        "relations": [
        {"rel": {
            "read": {
            "base_schema": {
                "struct": {
                "types": [
                            {"i64": {}}
                        ]
                },
                "names": [
                        "foo"
                        ]
            },
            "local_files": {
                "items": [
                {
                    "uri_file": "FILENAME_PLACEHOLDER",
                    "arrow": {}
                }
                ]
            }
            }
        }}
        ]
    }
    zread_data.arrow               foonamesFILENAME_PLACEHOLDERr   r	   r   r   r   replacepathlibPathas_uri
_substrait_parse_json_plan	substrait	run_queryread_allselect
r   r   substrait_queryr   r   r   querybufreaderres_tbs
             r   test_run_serialized_queryr;   2   s    O< "IHHo&ug6E$VY>DO++T 2 9 9 ;= >E --
(
(
/C  +>F__F<< FMM5'$::::r   r7   s   buffers   bytesr    c                 |   t        |t        j                  t        f      sIdt	        |       d}t        j                  t        |      5  t        j                  |       d d d        y d}t        j                  t        |      5  t        j                  |       d d d        y # 1 sw Y   y xY w# 1 sw Y   y xY w)Nz)Expected 'pyarrow.Buffer' or bytes, got ''matchz1ParseFromZeroCopyStream failed for substrait.Plan)
isinstancer	   Bufferbytestypepytestraises	TypeErrorr1   r2   OSError)r   r7   msgs      r   test_run_query_input_typesrI   `   s     ebii/09$u+aH]]9C0& 1 >C	wc	*E" 
+	* 1 
+	*s   B&B2&B/2B;c                      d} t         j                  j                  t        |             }d}t	        j
                  t        |      5  t        j                  |       d d d        y # 1 sw Y   y xY w)Nz2
    {
        "relations": [
        ]
    }
    zPlan has no relationsr>   )	r	   r/   r0   r   rD   rE   r   r1   r2   )r7   r8   exec_messages      r   test_invalid_planrL   p   sP    E --
(
(
8C*L	|<	8C  
9	8	8s   A''A0c                    d}d}t        j                  g dgdg      }t        | ||      }t        |j	                  dt        j                  |      j                                     }t         j                  j                  t        |            }t        j                  ||      }|j                         }	|j                  dg      |	j                  dg      k(  sJ y )Na  
    {
        "version": { "major": 9999 },
        "relations": [
        {"rel": {
            "read": {
            "base_schema": {
                "struct": {
                "types": [
                            {"i64": {}}
                        ]
                },
                "names": [
                        "bar"
                        ]
            },
            "local_files": {
                "items": [
                {
                    "uri_file": "FILENAME_PLACEHOLDER",
                    "arrow": {},
                    "metadata" : {
                      "created_by" : {},
                    }
                }
                ]
            }
            }
        }}
        ]
    }
    zbinary_json_data.arrowr   barr&   r(   r)   r*   r5   s
             r   (test_binary_conversion_with_json_optionsrO   }   s    OB )IHHo&ug6E$VY>DO++T 2 9 9 ;= >E
--
(
(
8C  +>F__F<< FMM5'$::::r   c                 F    | d| }| D ]  }|j                  |      s y y)N#TF)endswith)fnsext_filefn_namesuffixfns        r   has_functionrX      s0    z7)$F;;v  r   c                  |    t         j                  j                         } t        | dd      sJ t        | dd      sJ y )Nzfunctions_arithmetic.yamladdsum)r	   r/   get_supported_functionsrX   )supported_functionss    r   test_get_supported_functionsr^      sK    --??A +3U< < <+3U< < <r   c                    t         j                  j                  dg di      t         j                  j                  dg di      t        j                  t        j                  dt        j
                               g      fd}d}t         j                  j                  t        |            }t         j                  j                  |||       }|j                         }|k(  sJ y )Nxr    r!   r"   )r#   r$      c                 j    | st        d      | d   dk(  r	|k(  sJ S | d   dk(  rS t        d      )NNo names providedr   t1r    t2Unrecognized table name	Exception)r'   r   schema_1test_table_1test_table_2s     r   table_providerz(test_named_table.<locals>.table_provider   sP    /001XX%%%1X566r   a  
    {
        "version": { "major": 9999 },
        "relations": [
        {"rel": {
            "read": {
            "base_schema": {
                "struct": {
                "types": [
                            {"i64": {}}
                        ]
                },
                "names": [
                        "x"
                        ]
            },
            "namedTable": {
                    "names": ["t1"]
            }
            }
        }}
        ]
    }
    rm   r   )r	   Tablefrom_pydictr   fieldint64r/   r0   r   r1   r2   r3   )	r   rm   r6   r8   r9   r:   rj   rk   rl   s	         @@@r   test_named_tablers      s    88''i(89L88''i(89Lyy"((3
345H	7O2 --
(
()A
BC\\##N $ EF__F\!!!r   c                  <   t         j                  j                  dg di      fd} d}t         j                  j	                  t        |            }d}t        j                  t        |      5  t        j                  ||        d d d        y # 1 sw Y   y xY w)Nr`   ra   c                 H    | st        d      | d   dk(  rS t        d      Nrd   r   re   rg   rh   r'   _rk   s     r   rm   z;test_named_table_invalid_table_name.<locals>.table_provider   0    /001X566r   a  
    {
        "version": { "major": 9999 },
        "relations": [
        {"rel": {
            "read": {
            "base_schema": {
                "struct": {
                "types": [
                            {"i64": {}}
                        ]
                },
                "names": [
                        "x"
                        ]
            },
            "namedTable": {
                    "names": ["t3"]
            }
            }
        }}
        ]
    }
    zInvalid NamedTable Sourcer>   rm   )r	   ro   rp   r/   r0   r   rD   rE   r   r1   r2   )rm   r6   r8   rK   rk   s       @r   #test_named_table_invalid_table_namer{      sr    88''i(89L7O2 --
(
()A
BC.L	|<	8C? 
9	8	8s   1BBc                  R   t         j                  j                  dg di      fd} d}t        |      }t         j                  j                  t        |            }d}t        j                  t        |      5  t        j                  ||        d d d        y # 1 sw Y   y xY w)Nr`   ra   c                 H    | st        d      | d   dk(  rS t        d      rv   rh   rw   s     r   rm   z4test_named_table_empty_names.<locals>.table_provider  ry   r   a  
    {
        "version": { "major": 9999 },
        "relations": [
        {"rel": {
            "read": {
            "base_schema": {
                "struct": {
                "types": [
                            {"i64": {}}
                        ]
                },
                "names": [
                        "x"
                        ]
            },
            "namedTable": {
                    "names": []
            }
            }
        }}
        ]
    }
    z!names for NamedTable not providedr>   rz   )r	   ro   rp   r   r/   r0   rD   rE   r   r1   r2   )rm   r6   r7   r8   rK   rk   s        @r   test_named_table_empty_namesr~     s{    88''i(89L7O0 O$E
--
(
(
8C6L	|<	8C? 
9	8	8s   <BB&c           	      `  
 t         j                  j                  dg di      

fd}d}t         j                  j	                  |      }t         j
                  j                  |||      }|j                         }| \  }}
j                  dd |t        d      
d               }	||	k(  sJ y )	Nr`   ra   c                 H    | st        d      | d   dk(  rS t        d      rv   rh   r'   rx   
test_tables     r   rm   z.test_udf_via_substrait.<locals>.table_providerJ  0    /001X566r   s	  
    {
  "extensionUris": [
    {
      "extensionUriAnchor": 1
    },
    {
      "extensionUriAnchor": 2,
      "uri": "urn:arrow:substrait_simple_extension_function"
    }
  ],
  "extensions": [
    {
      "extensionFunction": {
        "extensionUriReference": 2,
        "functionAnchor": 1,
        "name": "y=x+1"
      }
    }
  ],
  "relations": [
    {
      "root": {
        "input": {
          "project": {
            "common": {
              "emit": {
                "outputMapping": [
                  1,
                  2,
                ]
              }
            },
            "input": {
              "read": {
                "baseSchema": {
                  "names": [
                    "t",
                  ],
                  "struct": {
                    "types": [
                      {
                        "i64": {
                          "nullability": "NULLABILITY_REQUIRED"
                        }
                      },
                    ],
                    "nullability": "NULLABILITY_REQUIRED"
                  }
                },
                "namedTable": {
                  "names": [
                    "t1"
                  ]
                }
              }
            },
            "expressions": [
              {
                "selection": {
                  "directReference": {
                    "structField": {}
                  },
                  "rootReference": {}
                }
              },
              {
                "scalarFunction": {
                  "functionReference": 1,
                  "outputType": {
                    "i64": {
                      "nullability": "NULLABILITY_NULLABLE"
                    }
                  },
                  "arguments": [
                    {
                      "value": {
                        "selection": {
                          "directReference": {
                            "structField": {}
                          },
                          "rootReference": {}
                        }
                      }
                    }
                  ]
                }
              }
            ]
          }
        },
        "names": [
          "x",
          "y",
        ]
      }
    }
  ]
}
    rn   r    y
   )
r	   ro   rp   r/   r0   r1   r2   r3   
add_columnr   )unary_func_fixturer   rm   r6   r8   r9   r:   functionnameexpected_tbr   s             @r   test_udf_via_substraitr   F  s    %%sI&67J7cOJ --
(
(
9C\\##N $ EF__F'NHd''3jo1/ 0K[   r   c                  |   t         j                  j                  dg di      fd} d}t         j                  j	                  |      }t        j                  t         j                        5 }t         j                  j                  ||        d d d        dt        j                        v sJ y # 1 sw Y   #xY w)Nr`   ra   c                 H    | st        d      | d   dk(  rS t        d      rv   rh   r   s     r   rm   z=test_udf_via_substrait_wrong_udf_name.<locals>.table_provider  r   r   s	  
    {
  "extensionUris": [
    {
      "extensionUriAnchor": 1
    },
    {
      "extensionUriAnchor": 2,
      "uri": "urn:arrow:substrait_simple_extension_function"
    }
  ],
  "extensions": [
    {
      "extensionFunction": {
        "extensionUriReference": 2,
        "functionAnchor": 1,
        "name": "wrong_udf_name"
      }
    }
  ],
  "relations": [
    {
      "root": {
        "input": {
          "project": {
            "common": {
              "emit": {
                "outputMapping": [
                  1,
                  2,
                ]
              }
            },
            "input": {
              "read": {
                "baseSchema": {
                  "names": [
                    "t",
                  ],
                  "struct": {
                    "types": [
                      {
                        "i64": {
                          "nullability": "NULLABILITY_REQUIRED"
                        }
                      },
                    ],
                    "nullability": "NULLABILITY_REQUIRED"
                  }
                },
                "namedTable": {
                  "names": [
                    "t1"
                  ]
                }
              }
            },
            "expressions": [
              {
                "selection": {
                  "directReference": {
                    "structField": {}
                  },
                  "rootReference": {}
                }
              },
              {
                "scalarFunction": {
                  "functionReference": 1,
                  "outputType": {
                    "i64": {
                      "nullability": "NULLABILITY_NULLABLE"
                    }
                  },
                  "arguments": [
                    {
                      "value": {
                        "selection": {
                          "directReference": {
                            "structField": {}
                          },
                          "rootReference": {}
                        }
                      }
                    }
                  ]
                }
              }
            ]
          }
        },
        "names": [
          "x",
          "y",
        ]
      }
    }
  ]
}
    rz   zNo function registered)r	   ro   rp   r/   r0   rD   rE   ArrowKeyErrorr1   r2   r   value)rm   r6   r8   excinfor   s       @r   %test_udf_via_substrait_wrong_udf_namer     s    %%sI&67J7cOJ --
(
(
9C	r''	(G
s>B 
)#s7=='9999 
)	(s   ."B22B;c                 b   t         j                  j                  dg di      fd}d}t         j                  j	                  t        |            }t         j                  j                  |||       }|j                         }t         j                  j                  dg di      }||k(  sJ y )Nr`   ra   c                     S N )r'   r   in_tables     r   rm   z/test_output_field_names.<locals>.table_provider<  s    r   a  
    {
      "version": { "major": 9999 },
      "relations": [
        {
          "root": {
            "input": {
              "read": {
                "base_schema": {
                  "struct": {
                    "types": [{"i64": {}}]
                  },
                  "names": ["x"]
                },
                "namedTable": {
                  "names": ["t1"]
                }
              }
            },
            "names": ["out"]
          }
        }
      ]
    }
    rn   out)	r	   ro   rp   r/   r0   r   r1   r2   r3   )r   rm   r6   r8   r9   r:   expectedr   s          @r   test_output_field_namesr   8  s    xx##S)$45HO4 --
(
()A
BC\\##N $ EF__Fxx##UI$67HXr   c                 b   t         j                  j                  g dg dg dd      fd}d}t         j                  j	                  |      }t         j
                  j                  ||d      }|j                         }t         j                  j                  d	d
gddgd      }||k(  sJ y )Nr    r    r!   r!   )r    r!   r"   r#   )      ?r   r   r   )kv1v2c                     S r   r   r   s     r   rm   z7test_scalar_aggregate_udf_basic.<locals>.table_providerk  	    r   s  
{
  "extensionUris": [
    {
      "extensionUriAnchor": 1,
      "uri": "urn:arrow:substrait_simple_extension_function"
    },
  ],
  "extensions": [
    {
      "extensionFunction": {
        "extensionUriReference": 1,
        "functionAnchor": 1,
        "name": "sum_mean"
      }
    }
  ],
  "relations": [
    {
      "root": {
        "input": {
          "extensionSingle": {
            "common": {
              "emit": {
                "outputMapping": [
                  0,
                  1
                ]
              }
            },
            "input": {
              "read": {
                "baseSchema": {
                  "names": [
                    "k",
                    "v1",
                    "v2",
                  ],
                  "struct": {
                    "types": [
                      {
                        "i64": {
                          "nullability": "NULLABILITY_REQUIRED"
                        }
                      },
                      {
                        "i64": {
                          "nullability": "NULLABILITY_NULLABLE"
                        }
                      },
                      {
                        "fp64": {
                          "nullability": "NULLABILITY_NULLABLE"
                        }
                      }
                    ],
                    "nullability": "NULLABILITY_REQUIRED"
                  }
                },
                "namedTable": {
                  "names": ["t1"]
                }
              }
            },
            "detail": {
              "@type": "/arrow.substrait_ext.SegmentedAggregateRel",
              "segmentKeys": [
                {
                  "directReference": {
                    "structField": {}
                  },
                  "rootReference": {}
                }
              ],
              "measures": [
                {
                  "measure": {
                    "functionReference": 1,
                    "phase": "AGGREGATION_PHASE_INITIAL_TO_RESULT",
                    "outputType": {
                      "fp64": {
                        "nullability": "NULLABILITY_NULLABLE"
                      }
                    },
                    "arguments": [
                      {
                        "value": {
                          "selection": {
                            "directReference": {
                              "structField": {
                                "field": 1
                              }
                            },
                            "rootReference": {}
                          }
                        }
                      },
                      {
                        "value": {
                          "selection": {
                            "directReference": {
                              "structField": {
                                "field": 2
                              }
                            },
                            "rootReference": {}
                          }
                        }
                      }
                    ]
                  }
                }
              ]
            }
          }
        },
        "names": [
          "k",
          "v_avg"
        ]
      }
    }
  ],
}
Frn   r    r!   g      @g      @)r   v_avgr	   ro   rp   r/   r0   r1   r2   r3   varargs_agg_func_fixturerm   r6   r8   r9   r:   r   r   s          @r   test_scalar_aggregate_udf_basicr   c  s     %%,#	%J
|Oz --
(
(
9C\\##N $ ?F__F((&&Vs( K
 [   r   c                 n   t         j                  j                  g dg dg dg dd      fd}d}t         j                  j	                  |      }t         j
                  j                  ||d	      }|j                         }t         j                  j                  g d
g dg dd      }||k(  sJ y )N)r    r    r    r    r!   r!   r!   r!   )r    r   r   r    r   r    r   r    )r    r!   r"   r#   r$   rb         )r   r   r   r   g       @g      @g      @g      @)tr   r   r   c                     S r   r   r   s     r   rm   z5test_hash_aggregate_udf_basic.<locals>.table_provider  r   r   s  
{
  "extensionUris": [
    {
      "extensionUriAnchor": 1,
      "uri": "urn:arrow:substrait_simple_extension_function"
    },
  ],
  "extensions": [
    {
      "extensionFunction": {
        "extensionUriReference": 1,
        "functionAnchor": 1,
        "name": "sum_mean"
      }
    }
  ],
  "relations": [
    {
      "root": {
        "input": {
          "extensionSingle": {
            "common": {
              "emit": {
                "outputMapping": [
                  0,
                  1,
                  2
                ]
              }
            },
            "input": {
              "read": {
                "baseSchema": {
                  "names": [
                    "t",
                    "k",
                    "v1",
                    "v2",
                  ],
                  "struct": {
                    "types": [
                      {
                        "i64": {
                          "nullability": "NULLABILITY_REQUIRED"
                        }
                      },
                      {
                        "i64": {
                          "nullability": "NULLABILITY_REQUIRED"
                        }
                      },
                      {
                        "i64": {
                          "nullability": "NULLABILITY_NULLABLE"
                        }
                      },
                      {
                        "fp64": {
                          "nullability": "NULLABILITY_NULLABLE"
                        }
                      }
                    ],
                    "nullability": "NULLABILITY_REQUIRED"
                  }
                },
                "namedTable": {
                  "names": ["t1"]
                }
              }
            },
            "detail": {
              "@type": "/arrow.substrait_ext.SegmentedAggregateRel",
              "groupingKeys": [
                {
                  "directReference": {
                    "structField": {
                      "field": 1
                    }
                  },
                  "rootReference": {}
                }
              ],
              "segmentKeys": [
                {
                  "directReference": {
                    "structField": {}
                  },
                  "rootReference": {}
                }
              ],
              "measures": [
                {
                  "measure": {
                    "functionReference": 1,
                    "phase": "AGGREGATION_PHASE_INITIAL_TO_RESULT",
                    "outputType": {
                      "fp64": {
                        "nullability": "NULLABILITY_NULLABLE"
                      }
                    },
                    "arguments": [
                      {
                        "value": {
                          "selection": {
                            "directReference": {
                              "structField": {
                                "field": 2
                              }
                            },
                            "rootReference": {}
                          }
                        }
                      },
                      {
                        "value": {
                          "selection": {
                            "directReference": {
                              "structField": {
                                "field": 3
                              }
                            },
                            "rootReference": {}
                          }
                        }
                      }
                    ]
                  }
                }
              ]
            }
          }
        },
        "names": [
          "t",
          "k",
          "v_avg"
        ]
      }
    }
  ],
}
Frn   r   )r    r   r   r    )      @r   g      "@g      &@)r   r   r   r   r   s          @r   test_hash_aggregate_udf_basicr     s     %%&&'7	9JNO^ --
(
(
9C\\##N $ ?F__F((&&&( K [   r   exprr`   r   r   2   c                    t        j                  t        j                  dt        j                               t        j                  dt        j                               g      }t         j                  j                  | gdg|      }t         j                  j                  |      }||j                  k(  sJ t        |j                        dk(  sJ d|j                  v sJ y )Nr`   r   	test_exprr    )	r	   r   rq   int32r1   serialize_expressionsdeserialize_expressionslenexpressions)r   r   r8   returneds       r   test_serializing_expressionsr     s     YY
bhhj!
bhhj! F
 ,,
,
,dVk]F
KC||33C8HX__$$$x##$)))(.....r   c                  `   t        j                  d      dft        j                  d      dft        j                  d      dft        j                         dft        j                         dft        j
                         dfd} t        j                  | j                         D cg c]  \  }\  }}t        j                  ||        c}}}      fd}| j                         D ];  \  }\  }} |t        j                  |      t        j                  ||	      k(         = y c c}}}w )
Nsr   msnstest_strings   test_string)time_secondstime_millis
time_nanosdate_millislarge_stringlarge_binaryc                     t         j                  j                  | gdg      }t         j                  j                  |      }|j                  k(  sJ y Nr   )r	   r1   r   r   r   )r   r8   r   r   s      r   check_round_tripz3test_arrow_specific_types.<locals>.check_round_trip  sE    ll00$+O<<77<(((r   )rC   )r	   time32time64date64r   r   r   itemsrq   pcscalar)fieldsr   typrx   r   valr   s         @r   test_arrow_specific_typesr     s    3+		$+yy*		Q'*M:*N;F YY&,,.Q.hsAs+.QRF)
 #LLNjsC$299Ss+CCD + Rs   )#D)c                     t        j                  t        j                  dt        j                               t        j                  dt        j                               t        j                  dt        j
                  t        j                         t        j                                     t        j                  dt        j                  t        j                         t        j                                     g      t        j                  t        j                  dt        j                               t        j                  dt        j                               t        j                  dt        j                               t        j                  dt        j                               g      fd} D ]
  } | |        y )Nbinary_viewstring_view
dictionaryreec                    t        j                  t        j                  | j                              }t        j
                  j                  |gdg      }t        j
                  j                  |      }|j                  k(  sJ y r   )	r   is_nullrq   r   r	   r1   r   r   r   )rq   r   r8   r   
alt_schemar   s       r   check_one_wayz/test_arrow_one_way_types.<locals>.check_one_way  s`    zz"((5::./ll00$+O<<77<X__,,,r   )
r	   r   rq   r   r   r   r   stringrun_end_encodedbinary)r   rq   r   r   s     @@r   test_arrow_one_way_typesr     s
   YYHH]BNN$45HH]BNN$45HH\2==RYY[#IJHHUB..rxxz299;GH		
F HH]BIIK0HH]BIIK0HH\299;/HHUBIIK(		
J- e r   c                     t        j                  t        j                  dt        j                               t        j                  dt        j                               g      } t	        j
                  t	        j                  d      d      }t	        j
                  t	        j                  d      d      }t        j                  t              5 }t         j                  j                  |gg |        d d d        dt        j                        v sJ t        j                  t              5 }t         j                  j                  |gddg|        d d d        dt        |j                        v sJ t        j                  t              5 }t         j                  j                  |gdg|        d d d        d	t        |j                        v sJ y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   ;xY w)
Nr`   r   r   zzneed to have the same lengthr%   rN   r   zNo match for FieldRef)r	   r   rq   r   r   equalrD   rE   
ValueErrorr1   r   r   r   )r   r   bad_exprr   s       r   test_invalid_expression_ser_desr     sV   YY
bhhj!
bhhj! F 88BHHSM1%Dxxq)H	z	"g
**D62v> 
#)S-????	z	"g
**D6E5>6J 
#)S-????	z	"g
**H:xH 
#"c'--&8888 
#	" 
#	" 
#	"s$   #G,%G$G)GG&)G2c                     t        j                  t        j                  dt        j                               t        j                  dt        j                               g      } t	        j
                  t	        j                  d      d      t	        j
                  t	        j                  d      t	        j                  d            g}t         j                  j                  |ddg|       }t         j                  j                  |      }| |j                  k(  sJ t        |j                        dk(  sJ t	        j
                  t	        j                  d      d      t	        j
                  t	        j                  d      t	        j                  d            g}t        |j                  d         t        |d         k(  sJ t        |j                  d         t        |d         k(  sJ y )	Nr`   r   r   firstsecondr!   r   r    )r	   r   rq   r   r   r   r1   r   r   r   r   r   )r   exprsr8   r   
norm_exprss        r   %test_serializing_multiple_expressionsr     sY   YY
bhhj!
bhhj! F XXbhhsmQ'"((3-#)OPE
,,
,
,UWh4G
PC||33C8HX__$$$x##$)))((288A;*BHHRXXa["((1+,NOJx##G,-Z]1CCCCx##H-.#jm2DDDDr   c                  <   t        j                  t        j                  dt        j                               t        j                  dt        j                               g      } t	        j
                  t	        j                  d      d      }t	        j
                  t	        j                  d      d      }|j                  |       }t         j                  j                  |      }| |j                  k(  sJ t        |j                        dk(  sJ t        |j                  d         t        |      k(  sJ t         j                  j                  ||gddg|       }t        j                  t              5 }t        j                   j#                  |       d d d        d	t        j$                        v sJ t         j                  j                  |gd
g|       }t        j                   j#                  |      }t        |      t        |      k(  sJ y # 1 sw Y   ~xY w)Nr`   r   r   r   r    
expressionr   r   zcontained multiple expressions	weirdname)r	   r   rq   r   r   r   to_substraitr1   r   r   r   r   r   rD   rE   r   
Expressionfrom_substraitr   )r   r   	expr_normr8   r   r   expr2s          r   test_serializing_with_computer   	  s   YY
bhhj!
bhhj! F 88BHHSM1%D!a(I


F
#C||33C8HX__$$$x##$)))x##L12c)nDDD ,,
,
,dD\GX;NPV
WC	z	"g
$$S) 
#+s7==/AAAA ,,
,
,dVk]F
KCMM((-Eu:Y''' 
#	"s   5 HHc                     t        j                  t        j                  dt        j                               g      } t	        j
                  d      }t	        j
                  d      }t	        j                  ||      g}t        j                  t              5  t         j                  j                  |dg|        d d d        t         j                  j                  |dg| d      }t         j                  j                  |      }| |j                  k(  sJ t        |j                        dk(  sJ t        |j                  d         t        |d         k(  sJ y # 1 sw Y   xY w)	Nr`   r   r#   r   T)allow_arrow_extensionsr    r   )r	   r   rq   uint32r   r   
shift_leftrD   rE   r   r1   r   r   r   r   r   )r   abr   r8   r   s         r   test_serializing_udfsr   $  s    YY
biik" F 			"A
		!A]]1a !E	/	0
**56(FC 
1 ,,
,
,x - >C||33C8HX__$$$x##$)))x##F+,E!H=== 
1	0s   #EE#)r   )-r   r,   rD   pyarrowr	   pyarrow.computecomputer   pyarrow.libr   r   r   pyarrow.substraitr1   ImportErrormark
pytestmarkr   r   parametrizer;   	py_bufferrI   rL   rO   rX   r^   rs   r{   r~   r   r   r   numpyr   r   r   rq   r   r   r   r   r   r   r   r   r   r   <module>r     sc  $ 
      >) [[""
D
 u6*; 7*;Z <2<<	#:Ha"HI# J#
! u6,; 7,;b< u6-" 7-"`'@T'@T u6x! 7x!vs:l u6' 7'T Q! Q!h g! g!T BHHXRXXc]ABHHXRXXc]HBHHSM*BHHSMB" 

/

/E(89(E (6>M   Is   H H$#H$