o
    i                      @   sd   d dl Z d dlmZ d dlmZ d dlmZ d dl	m
Z
 d dlmZ d dlmZ G dd	 d	eZdS )
    N)Schemaschema)data_streams_processor)SchemaBuilder)SchemaIterator)Spanc                   @   s   e Zd ZdZdZdZdefddZede	de
d	e
d
ededefddZeded
ededefddZededefddZd
efddZededede
fddZede
de
fddZdS )SchemaExtractorserializationdeserializationavror   c                 C   s
   || _ d S Nr   )selfr    r   a/home/ubuntu/.local/lib/python3.10/site-packages/ddtrace/contrib/internal/avro/schema_iterator.py__init__   s   
zSchemaExtractor.__init__fieldschema_name
field_namebuilderdepthreturnc              
   C   sN  d}d }d }d }d }	d }
| j }|j dkrd}|jd j }n~t|dddkrXt|dg }t|d	krWtt|D ]}|d	krGd
t|d	  }q7|dt||  7 }q7|d7 }nCt|dddkrtd}d|j }	t|||d ssdS n't|}|dkrd}n|dkrd}n|dkrd}n|dkrd}n|dkrd}|	||||||	||
S )NFarrayTitemstype unionschemasr   zunion[,]recordobjectz#/components/schemas/   bytesbyteintint32longint64floatdouble)
r   propsgetattrlenranger	   get_typenameextract_schemaadd_property)r   r   r   r   r   r   type_format_descriptionrefenum_values
field_typer   ir   r   r   extract_property   sJ   

z SchemaExtractor.extract_propertyc                 C   sb   |d7 }| j }|||sdS z| jD ]}t|||j||s# W dS qW dS  ty0   Y dS w )Nr"   FT)fullnameshould_extract_schemafieldsr	   r:   r0   	Exception)r   r   r   r   r   r   r   r   r1   ?   s   
zSchemaExtractor.extract_schemac                 C   s   t  | jt| S r   )r   
get_schemar;   r	   r   r   r   r   extract_schemasM   s   zSchemaExtractor.extract_schemasc                 C   s   |  | j|d d S Nr   )r1   r   )r   r   r   r   r   iterate_over_schemaQ   s   z#SchemaExtractor.iterate_over_schemaspan	operationc                 C   s   | d u s|d u r
d S | tjtj | tj| j | tj| t 	|s)d S |j
j}|d u s5|dkr7d S t |}|dkrCd S t| }| tj|j |tj| | tj|j d S rA   )set_tagSCHEMA_TAGSSCHEMA_TYPEr	   AVROSCHEMA_NAMEr;   SCHEMA_OPERATIONr   can_sample_schemacontextsampling_prioritytry_sample_schemar@   SCHEMA_DEFINITION
definition
set_metricSCHEMA_WEIGHT	SCHEMA_IDid)r   rC   rD   prioweightschema_datar   r   r   attach_schema_on_spanT   s"   
z%SchemaExtractor.attach_schema_on_spanr3   c                 C   s*   dddddddddddddd | jdS )	Nstringintegernumberbooleannullr!   r   )rY   r%   r'   r)   r*   r\   r]   r#   r    enumr   mapfixed)getr   )r3   r   r   r   r/   n   s    
zSchemaExtractor.get_typeN)__name__
__module____qualname__SERIALIZATIONDESERIALIZATIONrH   
AvroSchemar   staticmethodr   strr   r%   r:   boolr1   r@   rB   r   rX   r/   r   r   r   r   r	      s     $+r	   )r   avro.schemar   rg   ddtrace.extr   rF   ddtrace.internal.datastreamsr   3ddtrace.internal.datastreams.schemas.schema_builderr   4ddtrace.internal.datastreams.schemas.schema_iteratorr   ddtrace.tracer   r	   r   r   r   r   <module>   s    