
    <>i}              
       ^   S SK r S SKrS SKrS SKrS SKJr  S SKJ	r	  S SKJ
r
Jr   S SKJr  \R                  R                  rS)S jrS r\R                  R'                  SSS/5      S	 5       r\R                  R'                  S
\R*                  " S5      SS45      S 5       rS r\R                  R'                  SSS/5      S 5       rS rS r\R                  R'                  SSS/5      S 5       rS rS r\R                  R'                  SSS/5      S 5       rS r\R                  R'                  SSS/5      S 5       r \R                  RB                  S 5       r"\R                  RB                  S 5       r#\R                  R'                  S\RH                  " \RJ                  " S5      S5      \RH                  " \RJ                  " S5      \RJ                  " S5      5      \RJ                  " S5      S:  /5      S  5       r&S! r'S" r(S# r)S$ r*S% r+S& r,S' r-S( r.g! \ a    Sr GNf = f)*    N)tobytes)ArrowInvalidArrowNotImplementedErrorc                 F    SSK Jn  U" [        R                  " 5       U 5      $ )Nr   )_get_udf_context)pyarrow._computer   padefault_memory_pool)batch_lengthr   s     [/var/www/html/land-tabula/venv/lib/python3.13/site-packages/pyarrow/tests/test_substrait.pymock_udf_contextr   &   s    1B224lCC    c                     [         R                  R                  [        U 5      U5      n[        R
                  R                  X2R                  S9 nUR                  U5        S S S 5        U$ ! , (       d  f       U$ = f)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		%	%d<<	%	@F5! 
AK 
A	@Ks   A--
A<use_threadsTFc                    SnSn[         R                  " / SQ/S/S9n[        XU5      n[        UR	                  S[
        R                  " U5      R                  5       5      5      n[         R                  R                  U5      n[        R                  " XqS9nUR                  5       n	UR                  S/5      U	R                  S/5      :X  d   eg )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$V>DO++T 2 9 9 ;= >E --
(
(
/C  >F__F<< FMM5'$::::r   r7   s   buffers   bytesr    c                    [        U[        R                  [        45      (       dH  S[	        U5       S3n[
        R                  " [        US9   [        R                  " U5        S S S 5        g Sn[
        R                  " [        US9   [        R                  " U5        S S S 5        g ! , (       d  f       g = f! , (       d  f       g = f)Nz)Expected 'pyarrow.Buffer' or bytes, got ''matchz1ParseFromZeroCopyStream failed for substrait.Plan)
isinstancer	   Bufferbytestypepytestraises	TypeErrorr1   r2   r   )r   r7   msgs      r   test_run_query_input_typesrH   `   s     ebii/009$u+aH]]9C0& 1 >C	|3	/E" 
0	/ 10 
0	/s   B)	B:)
B7:
Cc                      Sn [         R                  R                  [        U 5      5      nSn[        R
                  " [        US9   [        R                  " U5        S S S 5        g ! , (       d  f       g = f)Nz2
    {
        "relations": [
        ]
    }
    zPlan has no relationsr>   )	r	   r/   r0   r   rD   rE   r   r1   r2   )r7   r8   exec_messages      r   test_invalid_planrK   p   sP    E --
(
(
8C*L	|<	8C  
9	8	8s   A&&
A4c                    SnSn[         R                  " / SQ/S/S9n[        XU5      n[        UR	                  S[
        R                  " U5      R                  5       5      5      n[         R                  R                  [        U5      5      n[        R                  " XqS9nUR                  5       n	UR                  S/5      U	R                  S/5      :X  d   eg )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_optionsrN   }   s    OB )IHHo&ug6E$V>DO++T 2 9 9 ;= >E
--
(
(
8C  >F__F<< FMM5'$::::r   c                 T    U SU 3nU  H  nUR                  U5      (       d  M    g   g)N#TF)endswith)fnsext_filefn_namesuffixfns        r   has_functionrW      s3    z7)$F;;v  r   c                      [         R                  R                  5       n [        U SS5      (       d   e[        U SS5      (       d   eg )Nzfunctions_arithmetic.yamladdsum)r	   r/   get_supported_functionsrW   )supported_functionss    r   test_get_supported_functionsr]      sU    --??A +3U< < < <+3U< < < <r   c                   ^^^ [         R                  R                  S/ SQ05      m[         R                  R                  S/ SQ05      m[         R                  " [         R                  " S[         R
                  " 5       5      /5      mUUU4S jnSn[         R                  R                  [        U5      5      n[         R                  R                  X1U S9nUR                  5       nUT:X  d   eg )Nxr    r!   r"   )r#   r$      c                 z   > U (       d  [        S5      eU S   S:X  a
  UT:X  d   eT$ U S   S:X  a  T$ [        S5      e)NNo names providedr   t1r    t2Unrecognized table name	Exception)r'   r   schema_1test_table_1test_table_2s     r   table_provider(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"]
            }
            }
        }}
        ]
    }
    rl   r   )r	   Tablefrom_pydictr   fieldint64r/   r0   r   r1   r2   r3   )	r   rl   r6   r8   r9   r:   ri   rj   rk   s	         @@@r   test_named_tablers      s    88''i(89L88''i(89Lyy"((3
345H	7O2 --
(
()A
BC\\## $ EF__F\!!!r   c                  >  ^ [         R                  R                  S/ SQ05      mU4S jn Sn[         R                  R	                  [        U5      5      nSn[        R                  " [        US9   [        R                  " X S9  S S S 5        g ! , (       d  f       g = f)Nr_   r`   c                 T   > U (       d  [        S5      eU S   S:X  a  T$ [        S5      eNrc   r   rd   rf   rg   r'   _rj   s     r   rl   ;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>   rl   )r	   ro   rp   r/   r0   r   rD   rE   r   r1   r2   )rl   r6   r8   rJ   rj   s       @r   #test_named_table_invalid_table_namer|      sp    88''i(89L7O2 --
(
()A
BC.L	|<	8C? 
9	8	8s   0B
Bc                  T  ^ [         R                  R                  S/ SQ05      mU4S jn Sn[        U5      n[         R                  R                  [        U5      5      nSn[        R                  " [        US9   [        R                  " X0S9  S S S 5        g ! , (       d  f       g = f)Nr_   r`   c                 T   > U (       d  [        S5      eU S   S:X  a  T$ [        S5      erv   rg   rw   s     r   rl   4test_named_table_empty_names.<locals>.table_provider  rz   r   a  
    {
        "version": { "major": 9999 },
        "relations": [
        {"rel": {
            "read": {
            "base_schema": {
                "struct": {
                "types": [
                            {"i64": {}}
                        ]
                },
                "names": [
                        "x"
                        ]
            },
            "namedTable": {
                    "names": []
            }
            }
        }}
        ]
    }
    z!names for NamedTable not providedr>   r{   )r	   ro   rp   r   r/   r0   rD   rE   r   r1   r2   )rl   r6   r7   r8   rJ   rj   s        @r   test_named_table_empty_namesr     sy    88''i(89L7O0 O$E
--
(
(
8C6L	|<	8C? 
9	8	8s   ;B
B'c           	      X  ^
 [         R                  R                  S/ SQ05      m
U
4S jnSn[         R                  R	                  U5      n[         R
                  R                  XBUS9nUR                  5       nU u  pxT
R                  SSU" [        S5      T
S   5      5      n	Xi:X  d   eg )	Nr_   r`   c                 T   > U (       d  [        S5      eU S   S:X  a  T$ [        S5      erv   rg   r'   rx   
test_tables     r   rl   .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   rl   r6   r8   r9   r:   functionnameexpected_tbr   s             @r   test_udf_via_substraitr   F  s    %%sI&67J7cOJ --
(
(
9C\\## $ EF__F'NH''3jo1/ 0K   r   c                    ^ [         R                  R                  S/ SQ05      mU4S jn Sn[         R                  R	                  U5      n[
        R                  " [         R                  5       n[         R                  R                  X S9  S S S 5        S[        WR                  5      ;   d   eg ! , (       d  f       N*= f)Nr_   r`   c                 T   > U (       d  [        S5      eU S   S:X  a  T$ [        S5      erv   rg   r   s     r   rl   =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",
        ]
      }
    }
  ]
}
    r{   zNo function registered)r	   ro   rp   r/   r0   rD   rE   ArrowKeyErrorr1   r2   r   value)rl   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   0B22
C c                 \  ^ [         R                  R                  S/ SQ05      mU4S jnSn[         R                  R	                  [        U5      5      n[         R                  R                  X1U S9nUR                  5       n[         R                  R                  S/ SQ05      nXV:X  d   eg )Nr_   r`   c                    > T$ N )r'   r   in_tables     r   rl   /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   rl   r6   r8   r9   r:   expectedr   s          @r   test_output_field_namesr   8  s    xx##S)$45HO4 --
(
()A
BC\\## $ EF__Fxx##UI$67Hr   c                 \  ^ [         R                  R                  / SQ/ SQ/ SQS.5      mU4S jnSn[         R                  R	                  U5      n[         R
                  R                  X1SS9nUR                  5       n[         R                  R                  S	S
/SS/S.5      nXV:X  d   eg )Nr    r    r!   r!   )r    r!   r"   r#   )      ?r   r   r   )kv1v2c                    > T$ r   r   r   s     r   rl   7test_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_fixturerl   r6   r8   r9   r:   r   r   s          @r   test_scalar_aggregate_udf_basicr   c  s     %%,#	%J
|Oz --
(
(
9C\\## $ ?F__F((&&Vs( K
    r   c                 h  ^ [         R                  R                  / SQ/ SQ/ SQ/ SQS.5      mU4S jnSn[         R                  R	                  U5      n[         R
                  R                  X1SS	9nUR                  5       n[         R                  R                  / S
Q/ SQ/ SQS.5      nXV:X  d   eg )N)r    r    r    r    r!   r!   r!   r!   )r    r   r   r    r   r    r   r    )r    r!   r"   r#   r$   ra         )r   r   r   r   g       @g      @g      @g      @)tr   r   r   c                    > T$ r   r   r   s     r   rl   5test_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\\## $ ?F__F((&&&( K    r   exprr_   r   r   2   c                    [         R                  " [         R                  " S[         R                  " 5       5      [         R                  " S[         R                  " 5       5      /5      n[         R                  R                  U /S/U5      n[         R                  R                  U5      nXR                  :X  d   e[        UR                  5      S:X  d   eSUR                  ;   d   eg )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##$)))(.....r   c                  r  ^ [         R                  " S5      S4[         R                  " S5      S4[         R                  " S5      S4[         R                  " 5       S4[         R                  " 5       S4[         R
                  " 5       S4S.n [         R                  " U R                  5        VVVs/ s H  u  nu  p#[         R                  " X5      PM      snnn5      mU4S jnU R                  5        H9  u  nu  p%U" [        R                  " U5      [         R                  " XRS	9:H  5        M;     g s  snnnf )
Nsr   msnstest_strings   test_string)time_secondstime_millis
time_nanosdate_millislarge_stringlarge_binaryc                    > [         R                  R                  U /S/T5      n[         R                  R                  U5      nTUR                  :X  d   eg Nr   )r	   r1   r   r   r   )r   r8   r   r   s      r   check_round_trip3test_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.hs+.QRF)
 #LLNjs$299S+CCD + Rs   0%D2c                    ^^ [         R                  " [         R                  " S[         R                  " 5       5      [         R                  " S[         R                  " 5       5      [         R                  " S[         R
                  " [         R                  " 5       [         R                  " 5       5      5      [         R                  " S[         R                  " [         R                  " 5       [         R                  " 5       5      5      /5      m[         R                  " [         R                  " S[         R                  " 5       5      [         R                  " S[         R                  " 5       5      [         R                  " S[         R                  " 5       5      [         R                  " S[         R                  " 5       5      /5      mUU4S jn T H  nU " U5        M     g )Nbinary_viewstring_view
dictionaryreec                   > [         R                  " [         R                  " U R                  5      5      n[        R
                  R                  U/S/T5      n[        R
                  R                  U5      nTUR                  :X  d   eg r   )	r   is_nullrq   r   r	   r1   r   r   r   )rq   r   r8   r   
alt_schemar   s       r   check_one_way/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                  ,   [         R                  " [         R                  " S[         R                  " 5       5      [         R                  " S[         R                  " 5       5      /5      n [        R
                  " [        R                  " S5      S5      n[        R
                  " [        R                  " S5      S5      n[        R                  " [        5       n[         R                  R                  U// U 5        S S S 5        S[        WR                  5      ;   d   e[        R                  " [        5       n[         R                  R                  U/SS/U 5        S S S 5        S[        UR                  5      ;   d   e[        R                  " [        5       n[         R                  R                  U/S/U 5        S S S 5        S	[        UR                  5      ;   d   eg ! , (       d  f       N= f! , (       d  f       N= f! , (       d  f       NL= f)
Nr_   r   r   zzneed to have the same lengthr%   rM   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#9%G4$H#
G14
H
Hc                      [         R                  " [         R                  " S[         R                  " 5       5      [         R                  " S[         R                  " 5       5      /5      n [        R
                  " [        R                  " S5      S5      [        R
                  " [        R                  " S5      [        R                  " S5      5      /n[         R                  R                  USS/U 5      n[         R                  R                  U5      nXR                  :X  d   e[        UR                  5      S:X  d   e[        R
                  " [        R                  " S5      S5      [        R
                  " [        R                  " S5      [        R                  " S5      5      /n[        UR                  S   5      [        US   5      :X  d   e[        UR                  S   5      [        US   5      :X  d   eg )	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     sW   YY
bhhj!
bhhj! F XXbhhsmQ'"((3-#)OPE
,,
,
,UWh4G
PC||33C8H__$$$x##$)))((288A;*BHHRXXa["((1+,NOJx##G,-Z]1CCCCx##H-.#jm2DDDDr   c                  b   [         R                  " [         R                  " S[         R                  " 5       5      [         R                  " S[         R                  " 5       5      /5      n [        R
                  " [        R                  " S5      S5      n[        R
                  " [        R                  " S5      S5      nUR                  U 5      n[         R                  R                  U5      nXR                  :X  d   e[        UR                  5      S:X  d   e[        UR                  S   5      [        U5      :X  d   e[         R                  R                  X/SS/U 5      n[        R                  " [        5       n[        R                   R#                  U5        S S S 5        S	[        WR$                  5      ;   d   e[         R                  R                  U/S
/U 5      n[        R                   R#                  U5      n[        U5      [        U5      :X  d   eg ! , (       d  f       N= f)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##L12c)nDDD ,,
,
,d\GX;NPV
WC	z	"g
$$S) 
#+s7==/AAAA ,,
,
,dVk]F
KCMM((-Eu:Y''' 
#	"s     H  
H.c                     [         R                  " [         R                  " S[         R                  " 5       5      /5      n [        R
                  " S5      n[        R
                  " S5      n[        R                  " X5      /n[        R                  " [        5         [         R                  R                  US/U 5        S S S 5        [         R                  R                  US/U SS9n[         R                  R                  U5      nXR                  :X  d   e[        UR                  5      S:X  d   e[        UR                  S   5      [        US   5      :X  d   eg ! , (       d  f       N= f)	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]]1 !E	/	0
**56(FC 
1 ,,
,
,x - >C||33C8H__$$$x##$)))x##F+,E!H=== 
1	0s   #E
E-c                     Sn [         R                  " [         R                  " S[         R                  " 5       5      [         R                  " S[         R                  " 5       5      /5      n[         R
                  R                  U 5      nX:X  d   e[         R
                  R                  U5      nUR                  U :X  d   e[         R
                  R                  U5      nX:X  d   e[         R
                  R                  UR                  5      nX:X  d   e[         R
                  R                  UR                  5      nUR                  U:X  d   eg )Ns   
x
y
*
br_   r   )
r	   r   rq   r   r   r1   deserialize_schemaserialize_schemar   r   )substrait_schemaexpected_schemar   arrow_substrait_schemas       r   test_serializing_schemar	  :  s   Vii
bhhj!
biik"! O ||../?@H&&&\\::8D!((,<<<<||../EFH&&&||../E/L/LMH&&&||334J4U4UVH??o---r   c                       " S S5      n Sn[         R                  R                  R                  U " U5      5      n[	        UR
                  5      S:X  d   eSUR
                  ;   d   eSUR
                  ;   d   eg )Nc                        \ rS rSrS rS rSrg)7test_bound_expression_from_Message.<locals>.FakeMessageiQ  c                     Xl         g r   r   )selfr   s     r   __init__@test_bound_expression_from_Message.<locals>.FakeMessage.__init__R  s    Ir   c                     U R                   $ r   r  )r  s    r   SerializeToStringItest_bound_expression_from_Message.<locals>.FakeMessage.SerializeToStringU  s    99r   r  N)__name__
__module____qualname____firstlineno__r  r  __static_attributes__r   r   r   FakeMessager  Q  s    		r   r  sj   

project_release

 project_version"0
project_version
project_release
:
br!   project_releaseproject_version)r	   r1   BoundExpressionsr   r   r   )r  messager   s      r   "test_bound_expression_from_Messager  P  sv     AG LL))88W9MNEu  !Q&&& 1 1111 1 1111r   )r   )/r   r,   rD   pyarrowr	   pyarrow.computecomputer   pyarrow.libr   r   r   pyarrow.substraitr1   ImportErrormark
pytestmarkr   r   parametrizer;   	py_bufferrH   rK   rN   rW   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_  $ 
      >) [[""
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 HHRXXc]AHHRXXc]BHHSM*HHSMB" 

/

/E(89(E (6>,.,2e!  Is   H   H,+H,