
    z-Ph}              
       .   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 n# e$ r dZY nw xY wej        j        Zd*dZd Zej                            ddd	g          d
             Zej                            d ej        d          ddf          d             Zd Zej                            ddd	g          d             Zd Zd Zej                            ddd	g          d             Zd Zd Zej                            ddd	g          d             Zd Zej                            ddd	g          d             Z ej        j!        d             Z"ej        j!        d             Z#ej                            d ej$         ej%        d          d           ej$         ej%        d           ej%        d                     ej%        d          d k    g          d!             Z&d" Z'd# Z(d$ Z)d% Z*d& Z+d' Z,d( Z-d) Z.dS )+    N)tobytes)ArrowInvalidArrowNotImplementedError
   c                 H    ddl m}  |t          j                    |           S )Nr   )_get_udf_context)pyarrow._computer   padefault_memory_pool)batch_lengthr   s     \/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/pyarrow/tests/test_substrait.pymock_udf_contextr   &   s0    111111B244lCCC    c                    t           j                            t          |           |          }t          j                            ||j                  5 }|                    |           d d d            n# 1 swxY w Y   |S )N)schema)	ospathjoinstrr
   ipcRecordBatchFileWriterr   write_table)tmpdir	file_nametabler   writers        r   _write_dummy_data_to_diskr   +   s    7<<FY//D		%	%d5<	%	@	@ "F5!!!" " " " " " " " " " " " " " "Ks   A66A:=A:use_threadsTFc                    d}d}t          j        g dgdg          }t          | ||          }t          |                    dt          j        |                                                              }t           j        	                    |          }t          j        ||          }|                                }	|                    dg          |	                    dg          k    sJ d S )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Hooo&ug666E$VY>>DO++T 2 2 9 9 ; ;= = > >E -
(
(
/
/C +>>>F__F<<  FMM5'$:$:::::::r   r8   s   buffers   bytesr!   c                    t          |t          j        t          f          s\dt	          |           d}t          j        t          |          5  t          j	        |           d d d            n# 1 swxY w Y   d S d}t          j        t          |          5  t          j	        |           d d d            d S # 1 swxY w Y   d S )Nz)Expected 'pyarrow.Buffer' or bytes, got ''matchz1ParseFromZeroCopyStream failed for substrait.Plan)
isinstancer
   Bufferbytestypepytestraises	TypeErrorr2   r3   r   )r   r8   msgs      r   test_run_query_input_typesrI   `   sD    ebi/00 H$u++HHH]9C000 	' 	'&&&	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' >C	|3	/	/	/ # #E"""# # # # # # # # # # # # # # # # # #s$   A11A58A5B==CCc                      d} t           j                            t          |                     }d}t	          j        t          |          5  t          j        |           d d d            d S # 1 swxY w Y   d S )Nz2
    {
        "relations": [
        ]
    }
    zPlan has no relationsr?   )	r
   r0   r1   r   rE   rF   r   r2   r3   )r8   r9   exec_messages      r   test_invalid_planrL   p   s    E -
(
(
8
8C*L	|<	8	8	8 ! !C   ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !s   A..A25A2c                    d}d}t          j        g dgdg          }t          | ||          }t          |                    dt          j        |                                                              }t           j        	                    t          |                    }t          j        ||          }|                                }	|                    dg          |	                    dg          k    sJ d S )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+   r6   s
             r   (test_binary_conversion_with_json_optionsrO   }   s    OB )IHooo&ug666E$VY>>DO++T 2 2 9 9 ; ;= = > >E
-
(
(
8
8C +>>>F__F<<  FMM5'$:$:::::::r   c                 N    | d| }| D ]}|                     |          r dS dS )N#TF)endswith)fnsext_filefn_namesuffixfns        r   has_functionrX      sI    $$7$$F  ;;v 	44	5r   c                      t           j                                        } t          | dd          sJ t          | dd          sJ d S )Nzfunctions_arithmetic.yamladdsum)r
   r0   get_supported_functionsrX   )supported_functionss    r   test_get_supported_functionsr^      sj    -??AA +3U< < < < <+3U< < < < < < <r   c                    t           j                            dg di          t           j                            dg di          t          j        t          j        dt          j                              g          fd}d}t           j                            t          |                    }t           j	        
                    |||           }|                                }|k    sJ d S )Nxr!   r"   r#   )r$   r%      c                     | 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   sd     	7/0001XX%%%%1X56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int64r0   r1   r   r2   r3   r4   )	r   rm   r7   r9   r:   r;   rj   rk   rl   s	         @@@r   test_named_tablers      s    8''iii(899L8''iii(899Ly"(3

33455H	7 	7 	7 	7 	7 	7 	7O2 -
(
()A)A
B
BC\##N $ E EF__F\!!!!!!r   c                  L   t           j                            dg di          fd} d}t           j                            t          |                    }d}t          j        t          |          5  t          j
        ||            d d d            d S # 1 swxY w Y   d S )Nr`   ra   c                 `    | 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   >     	7/0001X56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   r0   r1   r   rE   rF   r   r2   r3   )rm   r7   r9   rK   rk   s       @r   #test_named_table_invalid_table_namer{      s   8''iii(899L7 7 7 7 7O2 -
(
()A)A
B
BC.L	|<	8	8	8 @ @C????@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @s   5BB Bc                  j   t           j                            dg di          fd} d}t          |          }t           j                            t          |                    }d}t          j        t          |          5  t          j
        ||            d d d            d S # 1 swxY w Y   d S )Nr`   ra   c                 `    | 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   r0   r1   rE   rF   r   r2   r3   )rm   r7   r8   r9   rK   rk   s        @r   test_named_table_empty_namesr~     s   8''iii(899L7 7 7 7 7O0 O$$E
-
(
(
8
8C6L	|<	8	8	8 @ @C????@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @s   B((B,/B,c           	        
 t           j                            dg di          

fd}d}t           j                            |          }t           j                            |||          }|                                }| \  }}
                    dd |t          d          
d                             }	||	k    sJ d S )	Nr`   ra   c                 `    | 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  >     	7/0001X56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!   yr   )
r
   ro   rp   r0   r1   r2   r3   r4   
add_columnr   )unary_func_fixturer   rm   r7   r9   r:   r;   functionnameexpected_tbr   s             @r   test_udf_via_substraitr   F  s    %%sIII&677J7 7 7 7 7cOJ -
(
(
9
9C\##N $ E EF__F'NHd''3jo1/ 1/ 0 0K[      r   c                  x   t           j                            dg di          fd} d}t           j                            |          }t          j        t           j                  5 }t           j        	                    ||            d d d            n# 1 swxY w Y   dt          |j                  v sJ d S )Nr`   ra   c                 `    | 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   r0   r1   rE   rF   ArrowKeyErrorr2   r3   r   value)rm   r7   r9   excinfor   s       @r   %test_udf_via_substrait_wrong_udf_namer     s   %%sIII&677J7 7 7 7 7cOJ -
(
(
9
9C	r'	(	( CG
s>BBBC C C C C C C C C C C C C C C#s7='9'9999999s   )"BBBc                 v   t           j                            dg di          fd}d}t           j                            t          |                    }t           j                            |||           }|                                }t           j                            dg di          }||k    sJ d S )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   r0   r1   r   r2   r3   r4   )r   rm   r7   r9   r:   r;   expectedr   s          @r   test_output_field_namesr   8  s    x##S)))$455H    O4 -
(
()A)A
B
BC\##N $ E EF__Fx##UIII$677HXr   c                 n   t           j                            g dg dg dd          fd}d}t           j                            |          }t           j                            ||d          }|                                }t           j                            d	d
gddgd          }||k    sJ d S )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   r0   r1   r2   r3   r4   varargs_agg_func_fixturerm   r7   r9   r:   r;   r   r   s          @r   test_scalar_aggregate_udf_basicr   c  s     %%ll,,,###	% 	% J
    |Oz -
(
(
9
9C\##N $ ? ?F__F(&&Vs( (  K
 [      r   c                 z   t           j                            g dg dg dg dd          fd}d}t           j                            |          }t           j                            ||d	          }|                                }t           j                            g d
g dg dd          }||k    sJ d S )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77	9 	9 J    NO^ -
(
(
9
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                            | gdg|          }t           j                            |          }||j        k    sJ t          |j                  dk    sJ d|j        v sJ d S )Nr`   r   	test_exprr!   )	r
   r   rq   int32r2   serialize_expressionsdeserialize_expressionslenexpressions)r   r   r9   returneds       r   test_serializing_expressionsr     s     Y
bhjj!!
bhjj!!  F
 ,
,
,dVk]F
K
KC|33C8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        d |                                 D                       fd	}|                                 D ]=\  }\  }} |t          j	        |          t          j
        ||
          k               >d S )Nsr   msnstest_strings   test_string)time_secondstime_millis
time_nanosdate_millislarge_stringlarge_binaryc                 D    g | ]\  }\  }}t          j        ||          S r   )r
   rq   ).0r   typrx   s       r   
<listcomp>z-test_arrow_specific_types.<locals>.<listcomp>  s,    QQQhsAs++QQQr   c                     t           j                            | gdg          }t           j                            |          }|j        k    sJ d S Nr   )r
   r2   r   r   r   )r   r9   r   r   s      r   check_round_tripz3test_arrow_specific_types.<locals>.check_round_trip  sN    l00$+OO<77<<((((((r   )rD   )r
   time32time64date64r   r   r   itemspcrq   scalar)fieldsr   r   r   valr   s        @r   test_arrow_specific_typesr     s   3+	$+y*	Q'**M:**N; F YQQ&,,..QQQRRF) ) ) ) )
 #LLNN E EjsC$29Ss+C+C+CCDDDDE Er   c                  f   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 ]} | |           d S )Nbinary_viewstring_view
dictionaryreec                     t          j        t          j        | j                            }t          j                            |gdg          }t          j                            |          }|j        k    sJ d S r   )	r   is_nullrq   r   r
   r2   r   r   r   )rq   r   r9   r   
alt_schemar   s       r   check_one_wayz/test_arrow_one_way_types.<locals>.check_one_way  si    z"(5:..//l00$+O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     sO   YH]BN$4$455H]BN$4$455H\2=RY[[#I#IJJHUB.rxzz29;;GGHH		
 F H]BIKK00H]BIKK00H\29;;//HUBIKK((		
 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	        
                    |gg |            d d d            n# 1 swxY w Y   dt          |j                  v sJ t          j        t                    5 }t           j	        
                    |gddg|            d d d            n# 1 swxY w Y   dt          |j                  v sJ t          j        t                    5 }t           j	        
                    |gdg|            d d d            n# 1 swxY w Y   d	t          |j                  v sJ d S )
Nr`   r   r   zzneed to have the same lengthr&   rN   r   zNo match for FieldRef)r
   r   rq   r   r   equalrE   rF   
ValueErrorr2   r   r   r   )r   r   bad_exprr   s       r   test_invalid_expression_ser_desr     sm   Y
bhjj!!
bhjj!!  F 8BHSMM1%%Dxq))H	z	"	" ?g
**D62v>>>? ? ? ? ? ? ? ? ? ? ? ? ? ? ?)S-?-?????	z	"	" Kg
**D6E5>6JJJK K K K K K K K K K K K K K K)S-?-?????	z	"	" Ig
**H:xHHHI I I I I I I I I I I I I I I"c'-&8&8888888s6   #C55C9<C91%E""E&)E&$GGG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                            |ddg|           }t           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 d S )	Nr`   r   r   firstsecondr"   r   r!   )r
   r   rq   r   r   r   r2   r   r   r   r   r   )r   exprsr9   r   
norm_exprss        r   %test_serializing_multiple_expressionsr     sz   Y
bhjj!!
bhjj!!  F XbhsmmQ''"(3--#)O)OPE
,
,
,UWh4G
P
PC|33C88HX_$$$$x#$$))))(28A;;**BHRXa[["(1++,N,NOJx#G,--Z]1C1CCCCCx#H-..#jm2D2DDDDDDDr   c                  P   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                            |          }| |j        k    sJ t          |j
                  dk    sJ t          |j
        d                   t          |          k    sJ t           j                            ||gddg|           }t          j        t                    5 }t          j                            |           d d d            n# 1 swxY w Y   d	t          |j                  v sJ t           j                            |gd
g|           }t          j                            |          }t          |          t          |          k    sJ d S )Nr`   r   r   r   r!   
expressionr   r   zcontained multiple expressions	weirdname)r
   r   rq   r   r   r   to_substraitr2   r   r   r   r   r   rE   rF   r   
Expressionfrom_substraitr   )r   r   	expr_normr9   r   r   expr2s          r   test_serializing_with_computer   	  s   Y
bhjj!!
bhjj!!  F 8BHSMM1%%D!a((I


F
#
#C|33C88HX_$$$$x#$$))))x#L122c)nnDDDD ,
,
,dD\GX;NPV
W
WC	z	"	" *g
$$S)))* * * * * * * * * * * * * * *+s7=/A/AAAAA ,
,
,dVk]F
K
KCM((--Eu::Y''''''s   3 FF#&F#c                     t          j        t          j        dt          j                              g          } t	          j        d          }t	          j        d          }t	          j        ||          g}t          j        t                    5  t           j
                            |dg|            d d d            n# 1 swxY w Y   t           j
                            |dg| d          }t           j
                            |          }| |j        k    sJ t          |j                  dk    sJ t          |j        d                   t          |d                   k    sJ d S )	Nr`   r   r$   r   T)allow_arrow_extensionsr!   r   )r
   r   rq   uint32r   r   
shift_leftrE   rF   r   r2   r   r   r   r   r   )r   abr   r9   r   s         r   test_serializing_udfsr   $  s    Y
bikk""  F 		"A
	!A]1a  !E	/	0	0 D D
**56(FCCCD D D D D D D D D D D D D D D ,
,
,x - > >C|33C88HX_$$$$x#$$))))x#F+,,E!H======s   #C  CCc                  t   d} t          j        t          j        dt          j                              t          j        dt          j                              g          }t           j                            |           }||k    sJ t           j                            |          }|j        | k    sJ t           j                            |          }||k    sJ t           j                            |j                  }||k    sJ t           j                            |j	                  }|j        |k    sJ d S )Ns   
x
y
*
br`   r   )
r
   r   rq   r   r   r2   deserialize_schemaserialize_schemar   r   )substrait_schemaexpected_schemar   arrow_substrait_schemas       r   test_serializing_schemar  :  s   Vi
bhjj!!
bikk""!  O |../?@@Hh&&&&\::8DD!(,<<<<<|../EFFHh&&&&|../E/LMMHh&&&&|334J4UVVH?o------r   c                       G d d          } d}t           j        j                             | |                    }t	          |j                  dk    sJ d|j        v sJ d|j        v sJ d S )Nc                       e Zd Zd Zd ZdS )7test_bound_expression_from_Message.<locals>.FakeMessagec                     || _         d S r   r   )selfr   s     r   __init__z@test_bound_expression_from_Message.<locals>.FakeMessage.__init__R  s    DIIIr   c                     | j         S r   r  )r  s    r   SerializeToStringzItest_bound_expression_from_Message.<locals>.FakeMessage.SerializeToStringU  s
    9r   N)__name__
__module____qualname__r	  r  r   r   r   FakeMessager  Q  s2        	 	 		 	 	 	 	r   r  sj   

project_release

 project_version"0
project_version
project_release
:
br"   project_releaseproject_version)r
   r2   BoundExpressionsr   r   r   )r  messager   s      r   "test_bound_expression_from_Messager  P  s           AG L)88W9M9MNNEu !!Q&&&& 11111 1111111r   )r   )/r   r-   rE   pyarrowr
   pyarrow.computecomputer   pyarrow.libr   r   r   pyarrow.substraitr2   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   r   r   <module>r      s  $ 
			                   > > > > > > > >)))))))   III
 ["
D D D D
   u66*; *; 76*;Z <2<	#:#:Ha"HII# # JI#
! 
! 
! u66,; ,; 76,;b  < < < u66-" -" 76-"`'@ '@ '@T'@ '@ '@T u66x! x! 76x!vs: s: s:l u66' ' 76'T Q! Q! Q!h g! g! g!T BHXRXc]]ABHXRXc]]HBHSMM**BHSMMB"  

/ 
/ 

/E E E(  89 9 9(E E E ( ( (6> > >,. . .,2 2 2 2 2s   - 77