
    ug22                         d dl Z d dlmZ d dlmZ d dlmZmZmZm	Z	m
Z
mZ d dlmc mZ d dlmc mZ ddZddZddZddZdd	Zdd
ZddZddZddZddZddZddZddZddZ ddZ!ddZ"ddZ#y)    N)convert)SegmentType)
CollectionCollectionConfigurationInternalSegmentSegmentScopeWhereWhereDocumentc                  x   t        t        j                         dt               ddiddddd		      } t	        j
                  |       t        j                   | j                  j                  dt               j                         t        j                  dt        j                  d
      i      ddddd	      k(  sJ y )Ntest_collectionhnsw_m      test_tenanttest_database   *   	idnameconfigurationmetadata	dimensiontenantdatabaseversionlog_position	int_valuer   	r   r   configuration_json_strr   r   r   r   r   r   )r   uuiduuid4r   r   to_proto_collectionpbr   hexto_json_strUpdateMetadataUpdateMetadataValue)
collections    p/var/www/openai/venv/lib/python3.12/site-packages/chromadb/test/segment/distributed/test_protobuf_translation.pytest_collection_to_protor-      s    ::<57C 
J &&z2bmm==>@LLN""Xr7M7MX[7\,]^ 
7 
 
 
    c                     t        j                  t        j                         j                  dt               j                         t        j                  dt        j                  d      i      dddd	d
	      } t        j                  |       t        t        j                  | j                        dt               ddidddd	d
	      k(  sJ y )Nr   r   r   r   r    r   r   r   r   r   r!   r   )r&   r   r#   r$   r'   r   r(   r)   r*   r   from_proto_collectionUUIDr   protos    r,   test_collection_from_protor4   (   s    MM::<>@LLN""Xr7M7MX[7\,]^ 
E ((/:99UXX57C 
4 
 
 
r.   c                  D   t        t        j                         t        j                  j
                  t        j                  t        j                         ddidddgi      } t        j                  |       t        j                   | d   j                  t        j                  j
                  t        j                  j                  | d   j                  t        j                  dt        j                  d	      i
      dt        j                  ddg      i      k(  sJ y )Nr   r   r   path_0path_1r   typescoper+   r   
file_pathsr   r+   r   r    paths)r   r#   r$   r   HNSW_DISTRIBUTEDvaluer   VECTORr   to_proto_segmentr&   r'   r)   r*   	FilePaths)segments    r,   test_segment_to_protorD   @   s    ::<))//!!::<CXx01G ##G,

4=))//oo$$<(,,""Xr7M7MX[7\,]^BLL(/CDE1   r.   c                     t        j                  t        j                         j                  t
        j                  j                  t         j                  j                  t        j                         j                  t        j                  dt        j                  d      i      dt        j                  ddg      i	      } t        j                  |       t        t        j                  | j                         t
        j                  j                  t        j                  t        j                  | j"                        ddidddgi	      k(  sJ y )
Nr   r   r   r    r   r6   r7   r<   r8   )r&   r   r#   r$   r'   r   r>   r?   r   r@   r)   r*   rB   r   from_proto_segmentr1   r   r+   r2   s    r,   test_segment_from_protorG   R   s    JJ::<))//oo$$::<##""Xr7M7MX[7\,]^BLL(/CDEE %%e,99UXX))//!!99U--.CXx011   r.   c                      ddi} t        j                  |       }|j                  d      sJ |j                  j                  dk(  sJ |j                  j
                  t        j                  j                  k(  sJ y )N$not_containstestdirect)	r   to_proto_where_documentHasFieldrK   documentoperatorr&   WhereDocumentOperatorNOT_CONTAINSwhere_documentr3   s     r,   )test_where_document_to_proto_not_containsrT   d   sj    %4f$=N++N;E>>(###<<  F***<<  B$<$<$I$IIIIr.   c                      ddi} t        j                  |       }|j                  d      sJ |j                  j                  dk(  sJ |j                  j
                  t        j                  j                  k(  sJ y )N	$containsrJ   rK   )	r   rL   rM   rK   rN   rO   r&   rP   CONTAINSrR   s     r,   .test_where_document_to_proto_contains_to_protorX   l   sj    %0&$9N++N;E>>(###<<  F***<<  B$<$<$E$EEEEr.   c                  `   dddiddigi} t        j                  |       }|j                  d      sJ |j                  }|j                  t
        j                  j                  k(  sJ t        |j                        dk(  sJ |j                  }|D ]0  }|j                  d      sJ |j                  j                  dk(  r0J  |d   j                  j                  t
        j                  j                  k(  sJ |d	   j                  j                  t
        j                  j                  k(  sJ y )
N$andrV   rJ   rI   children   rK   r   r   r   rL   rM   r[   rO   r&   BooleanOperatorANDlenrK   rN   rP   rW   rQ   rS   r3   children_pbr[   childs        r,    test_where_document_to_proto_andrd   t   s   &!f%
%N ++N;E>>*%%%..K2#5#5#9#9999{##$)))##H~~h'''||$$...  A;&&"*B*B*K*KKKKA;&&"*B*B*O*OOOOr.   c                  `   dddiddigi} t        j                  |       }|j                  d      sJ |j                  }|j                  t
        j                  j                  k(  sJ t        |j                        dk(  sJ |j                  }|D ]0  }|j                  d      sJ |j                  j                  dk(  r0J  |d   j                  j                  t
        j                  j                  k(  sJ |d	   j                  j                  t
        j                  j                  k(  sJ y )
N$orrV   rJ   rI   r[   r\   rK   r   r   )r   rL   rM   r[   rO   r&   r^   ORr`   rK   rN   rP   rW   rQ   ra   s        r,   test_where_document_to_proto_orrh      s   &!f%
%N ++N;E>>*%%%..K2#5#5#8#8888{##$)))##H~~h'''||$$...  A;&&"*B*B*K*KKKKA;&&"*B*B*O*OOOOr.   c                      ddddiddigidddiddigigi} t        j                  |       }|j                  d      sJ |j                  }|j                  t
        j                  j                  k(  sJ t        |j                        dk(  sJ |j                  }|D ]  }|j                  d      sJ t        |j                  j                        dk(  sJ |j                  j                  }|D ]0  }|j                  d      sJ |j                  j                  dk(  r0J  |d	   j                  j                  t
        j                  j                  k(  sJ |d
   j                  j                  t
        j                  j                  k(  rJ  y )NrZ   rf   rV   rJ   rI   r[   r\   rK   r   r   r]   )rS   r3   rb   r[   rc   nested_childrennested_childs          r,   5test_where_document_to_proto_nested_boolean_operatorsrl      s    &)$f-  &)$f-
%N  ++N;E>>*%%%..K2#5#5#9#9999{##$)))##H~~j)))5>>**+q000..11+L((222&&//6999 , q!((11R5M5M5V5VVVVA%%.."2J2J2W2WW	
W r.   c                      ddi} t        j                  |       }|j                  d      sJ |j                  }|j                  dk(  sJ |j                  d      sJ |j
                  j                  dk(  sJ y )NrJ   r?   direct_comparisonsingle_string_operand)r   to_proto_whererM   rn   keyro   r?   wherer3   ds      r,    test_where_to_proto_string_valueru      s{    E ""5)E>>-...A55F??::-...""((G333r.   c                      ddi} t        j                  |       }|j                  d      sJ |j                  }|j                  dk(  sJ |j                  d      sJ |j
                  j                  dk(  sJ y )NrJ   r   rn   single_int_operand)r   rp   rM   rn   rq   rw   r?   rr   s      r,   test_where_to_proto_int_valuerx      s{    E ""5)E>>-...A55F??::*+++%%***r.   c                      ddi} t        j                  |       }|j                  d      sJ |j                  }|j                  dk(  sJ |j                  d      sJ |j
                  j                  dk(  sJ y )NrJ         ?rn   single_double_operand)r   rp   rM   rn   rq   r{   r?   rr   s      r,    test_where_to_proto_double_valuer|      s{    E ""5)E>>-...A55F??::-...""((C///r.   c                     dddiddigi} t        j                  |       }|j                  d      sJ |j                  }|j                  t
        j                  j                  k(  sJ |j                  }t        |      dk(  sJ |D ]0  }|j                  d      sJ |j                  j                  dk(  r0J  |d   j                  j                  d	      sJ |d   j                  j                  j                  dk(  sJ |d   j                  j                  d
      sJ |d   j                  j                  j                  dk(  sJ y )NrZ   rJ   r   r?   r[   r\   rn   r   rw   ro   r   rp   rM   r[   rO   r&   r^   r_   r`   rn   rq   rw   r?   ro   rs   r3   rb   r[   rc   s        r,   test_where_to_proto_andr      sI   QKW
E ""5)E>>*%%%..K2#5#5#9#9999##Hx=A~~1222&&**f444  A;((112FGGGA;((;;AAQFFFA;((112IJJJA;((>>DDOOOr.   c                     dddiddigi} t        j                  |       }|j                  d      sJ |j                  }|j                  t
        j                  j                  k(  sJ |j                  }t        |      dk(  sJ |D ]0  }|j                  d      sJ |j                  j                  dk(  r0J  |d   j                  j                  d	      sJ |d   j                  j                  j                  dk(  sJ |d   j                  j                  d
      sJ |d   j                  j                  j                  dk(  sJ y )Nrf   rJ   r   r?   r[   r\   rn   r   rw   ro   )r   rp   rM   r[   rO   r&   r^   rg   r`   rn   rq   rw   r?   ro   r   s        r,   test_where_to_proto_orr     sI   QKW
E ""5)E>>*%%%..K2#5#5#8#8888##Hx=A~~1222&&**f444  A;((112FGGGA;((;;AAQFFFA;((112IJJJA;((>>DDOOOr.   c                  l   ddddiddigidddiddigigi} t        j                  |       }|j                  d      sJ |j                  }|j                  t
        j                  j                  k(  sJ t        |j                        dk(  sJ |j                  }|D ]  }|j                  d      sJ t        |j                  j                        dk(  sJ |j                  j                  }|D ]0  }|j                  d      sJ |j                  j                  dk(  r0J  |d	   j                  j                  d
      sJ |d	   j                  j                  j                  dk(  sJ |d   j                  j                  d      sJ |d   j                  j                  j                  dk(  rJ  y )NrZ   rf   rJ   r   r?   r[   r\   rn   r   rw   ro   r~   )rs   r3   rb   r[   rc   rj   rk   s          r,   ,test_where_to_proto_nested_boolean_operatorsr     s   QKW% QKW%
E  ""5)E>>*%%%..K2#5#5#9#9999{##$)))##H~~j)))5>>**+q000..11+L(()<===1155??? , q!33<<=QRRRq!33FFLLPQQQQq!33<<=TUUUA00FFLLPWW	
W r.   c                     dddiddigi} t        j                  |       }|j                  d      sJ |j                  }|j                  t
        j                  j                  k(  sJ t        |j                        dk(  sJ |j                  }|d   }|j                  d	      sJ |j                  j                  dk(  sJ |j                  j                  d
      sJ |j                  j                  j                  dk(  sJ |d   }|j                  d	      sJ |j                  j                  dk(  sJ |j                  j                  d
      sJ |j                  j                  j                  dk(  sJ y )NrZ   test1rz   test2g       @r[   r\   r   rn   r{   r   )r   rp   rM   r[   rO   r&   r^   r_   r`   rn   rq   r{   r?   )rs   r3   rb   r[   child_0child_1s         r,   "test_where_to_proto_float_operatorr   D  sv   cNcN
E ""5)E>>*%%%..K2#5#5#9#9999{##$)))##HqkG/000$$((G333$$--.EFFF$$::@@CGGGqkG/000$$((G333$$--.EFFF$$::@@CGGGr.   c                     t        j                  d      } t        j                  d      }t        j                  d      }t        j                  | ||d      }t        j                  d	d
|      }t        j                  |      }|d   d	k(  sJ |d   sJ |d   d   dk(  sJ |d   d   dk(  sJ |d   d   dk(  sJ y )Nrz   )float_valuer\   r   three)string_value)	float_keyint_keystr_keyr    test_idrN   )r   rN   r   r   r   r   r   r   )r&   r*   r)   query_pbProjectionRecordr   from_proto_projection_record)	float_valint_valstr_valupdaterecordprojection_records         r,   !test_projection_record_from_protor   _  s    (*(>(>)I ')&<&<'G ')&<&<'G !# 1 1(WQ!F )1(A(A)F  <<VDT"i///Z(((Z(5<<<Z(3q888Z(3w>>>r.   )returnN)$r#   chromadb.protor   chromadb.segmentr   chromadb.typesr   r   r   r   r	   r
   chromadb.proto.chroma_pb2r3   
chroma_pb2r&   !chromadb.proto.query_executor_pb2query_executor_pb2r   r-   r4   rD   rG   rT   rX   rd   rh   rl   ru   rx   r|   r   r   r   r   r    r.   r,   <module>r      s     " (  ' & 4 420$$JFP,P,$
N	4	+	0P0P0&
RH6?r.   