Esempio n. 1
0
        public EventPropertyWriter GetWriter(string propertyName)
        {
            PropertySetDescriptorItem desc = _propertyItems.Get(propertyName);
            if (desc != null)
            {
                var field = _avroSchema.GetField(propertyName);
                return new AvroEventBeanPropertyWriter(field);
            }

            Property property = PropertyParser.ParseAndWalkLaxToSimple(propertyName);
            if (property is MappedProperty)
            {
                var mapProp = (MappedProperty) property;
                var field = _avroSchema.GetField(property.PropertyNameAtomic);
                return new AvroEventBeanPropertyWriterMapProp(field, mapProp.Key);
            }

            if (property is IndexedProperty)
            {
                var indexedProp = (IndexedProperty) property;
                var field = _avroSchema.GetField(property.PropertyNameAtomic);
                return new AvroEventBeanPropertyWriterIndexedProp(field, indexedProp.Index);
            }

            return null;
        }
Esempio n. 2
0
        internal static FragmentEventType GetFragmentType(
            Schema schema,
            string propertyName,
            IDictionary <string, PropertySetDescriptorItem> propertyItems,
            EventAdapterService eventAdapterService)
        {
            string unescapePropName        = ASTUtil.UnescapeDot(propertyName);
            PropertySetDescriptorItem item = propertyItems.Get(unescapePropName);

            if (item != null)
            {
                return(item.FragmentEventType);
            }

            Property            property = PropertyParser.ParseAndWalkLaxToSimple(propertyName);
            AvroFieldDescriptor desc     = AvroFieldUtil.FieldForProperty(schema, property);

            if (desc == null)
            {
                return(null);
            }
            if (desc.IsDynamic)
            {
                return(null);
            }
            Schema fieldSchemaByAccess = desc.Field.Schema;

            if (desc.IsAccessedByIndex)
            {
                fieldSchemaByAccess = fieldSchemaByAccess.GetElementType();
            }
            return(GetFragmentEventTypeForField(fieldSchemaByAccess, eventAdapterService));
        }
Esempio n. 3
0
 public EventPropertyDescriptor GetPropertyDescriptor(string propertyName)
 {
     PropertySetDescriptorItem item = _propertyItems.Get(propertyName);
     if (item == null)
     {
         return null;
     }
     return item.PropertyDescriptor;
 }
Esempio n. 4
0
 public EventPropertyGetterIndexed GetGetterIndexed(string indexedPropertyName)
 {
     PropertySetDescriptorItem desc = _propertyItems.Get(indexedPropertyName);
     if (desc == null || !desc.PropertyDescriptor.IsIndexed)
     {
         return null;
     }
     Field field = _avroSchema.GetField(indexedPropertyName);
     return new AvroEventBeanGetterIndexedRuntimeKeyed(field);
 }
Esempio n. 5
0
        public Type GetPropertyType(string propertyName)
        {
            PropertySetDescriptorItem item = _propertyItems.Get(ASTUtil.UnescapeDot(propertyName));
            if (item != null)
            {
                return item.SimplePropertyType;
            }

            Property property = PropertyParser.ParseAndWalkLaxToSimple(propertyName);
            return AvroPropertyUtil.PropertyType(_avroSchema, property);
        }
Esempio n. 6
0
        private void Init()
        {
            _propertyNames = new string[_avroSchema.GetFields().Count];
            _propertyDescriptors = new EventPropertyDescriptor[_propertyNames.Length];
            int fieldNum = 0;

            foreach (Field field in _avroSchema.GetFields())
            {
                _propertyNames[fieldNum] = field.Name;

                Type propertyType = AvroTypeUtil.PropertyType(field.Schema);
                Type componentType = null;
                bool indexed = false;
                bool mapped = false;
                FragmentEventType fragmentEventType = null;

                if (field.Schema.Tag == global::Avro.Schema.Type.Array)
                {
                    componentType = AvroTypeUtil.PropertyType(field.Schema.GetElementType());
                    indexed = true;
                    if (field.Schema.GetElementType().Tag == global::Avro.Schema.Type.Record)
                    {
                        fragmentEventType = AvroFragmentTypeUtil.GetFragmentEventTypeForField(field.Schema, _eventAdapterService);
                    }
                }
                else if (field.Schema.Tag == global::Avro.Schema.Type.Map)
                {
                    mapped = true;
                    componentType = AvroTypeUtil.PropertyType(field.Schema.GetValueType());
                }
                else if (field.Schema.Tag == global::Avro.Schema.Type.String)
                {
                    indexed = true;
                    componentType = typeof(char);
                    fragmentEventType = null;
                }
                else
                {
                    fragmentEventType = AvroFragmentTypeUtil.GetFragmentEventTypeForField(field.Schema, _eventAdapterService);
                }

                var getter = new AvroEventBeanGetterSimple(
                    field, fragmentEventType == null ? null : fragmentEventType.FragmentType, _eventAdapterService);

                var descriptor = new EventPropertyDescriptor(
                    field.Name, propertyType, componentType, false, false, indexed, mapped, fragmentEventType != null);
                var item = new PropertySetDescriptorItem(descriptor, propertyType, getter, fragmentEventType);
                _propertyItems.Put(field.Name, item);
                _propertyDescriptors[fieldNum] = descriptor;

                fieldNum++;
            }
        }
Esempio n. 7
0
        private void Init()
        {
            var avroFields = _avroSchema.GetFields();

            _propertyNames = new string[avroFields.Count];
            _propertyDescriptors = new EventPropertyDescriptor[_propertyNames.Length];
            var fieldNum = 0;

            foreach (var field in avroFields) {
                _propertyNames[fieldNum] = field.Name;

                var propertyType = AvroTypeUtil.PropertyType(field.Schema).GetBoxedType();
                Type componentType = null;
                var indexed = false;
                var mapped = false;
                FragmentEventType fragmentEventType = null;

                if (field.Schema.Tag == global::Avro.Schema.Type.Array) {
                    componentType = AvroTypeUtil.PropertyType(field.Schema.AsArraySchema().ItemSchema);
                    indexed = true;
                    if (field.Schema.AsArraySchema().ItemSchema.Tag == global::Avro.Schema.Type.Record) {
                        fragmentEventType = AvroFragmentTypeUtil.GetFragmentEventTypeForField(
                            field.Schema,
                            Metadata.ModuleName,
                            _eventBeanTypedEventFactory,
                            _eventTypeAvroHandler,
                            _fragmentTypeCache);
                    }
                }
                else if (field.Schema.Tag == global::Avro.Schema.Type.Map) {
                    mapped = true;
                    componentType = AvroTypeUtil.PropertyType(field.Schema.AsMapSchema().ValueSchema);
                }
                else if (field.Schema.Tag == global::Avro.Schema.Type.String) {
                    componentType = typeof(char);
                    indexed = true;
                }
                else {
                    fragmentEventType = AvroFragmentTypeUtil.GetFragmentEventTypeForField(
                        field.Schema,
                        Metadata.ModuleName,
                        _eventBeanTypedEventFactory,
                        _eventTypeAvroHandler,
                        _fragmentTypeCache);
                }

                var getter = new AvroEventBeanGetterSimple(
                    field,
                    fragmentEventType?.FragmentType,
                    _eventBeanTypedEventFactory,
                    propertyType);

                var descriptor = new EventPropertyDescriptor(
                    field.Name,
                    propertyType,
                    componentType,
                    false,
                    false,
                    indexed,
                    mapped,
                    fragmentEventType != null);
                var item = new PropertySetDescriptorItem(descriptor, propertyType, getter, fragmentEventType);
                _propertyItems.Put(field.Name, item);
                _propertyDescriptors[fieldNum] = descriptor;

                fieldNum++;
            }
        }