Beispiel #1
0
        /// <summary>
        /// Creates a new field for the record
        /// </summary>
        /// <param name="jfield">JSON object for the field</param>
        /// <param name="pos">position number of the field</param>
        /// <param name="names">list of named schemas already read</param>
        /// <param name="encspace">enclosing namespace of the records schema</param>
        /// <returns>new Field object</returns>
        private static Field createField(JToken jfield, int pos, SchemaNames names, string encspace)
        {
            var name = JsonHelper.GetRequiredString(jfield, "name");
            var doc  = JsonHelper.GetOptionalString(jfield, "doc");

            var jorder = JsonHelper.GetOptionalString(jfield, "order");

            Field.SortOrder sortorder = Field.SortOrder.ignore;
            if (null != jorder)
            {
                sortorder = (Field.SortOrder)Enum.Parse(typeof(Field.SortOrder), jorder);
            }

            var aliases      = Field.GetAliases(jfield);
            var props        = Schema.GetProperties(jfield);
            var defaultValue = jfield["default"];

            JToken jtype = jfield["type"];

            if (null == jtype)
            {
                throw new SchemaParseException("'type' was not found for field: " + name);
            }
            var schema = Schema.ParseJson(jtype, names, encspace);

            return(new Field(schema, name, aliases, pos, doc, defaultValue, sortorder, props));
        }
Beispiel #2
0
        /// <summary>
        /// Static function to return instance of the union schema
        /// </summary>
        /// <param name="jarr">JSON object for the union schema</param>
        /// <param name="names">list of named schemas already read</param>
        /// <param name="encspace">enclosing namespace of the schema</param>
        /// <returns>new UnionSchema object</returns>
        internal static UnionSchema NewInstance(JArray jarr, PropertyMap props, SchemaNames names, string encspace)
        {
            List <Schema> schemas = new List <Schema>();
            IDictionary <string, string> uniqueSchemas = new Dictionary <string, string>();

            foreach (JToken jvalue in jarr)
            {
                Schema unionType = Schema.ParseJson(jvalue, names, encspace);
                if (null == unionType)
                {
                    throw new SchemaParseException("Invalid JSON in union" + jvalue.ToString());
                }

                string name = unionType.Name;
                if (uniqueSchemas.ContainsKey(name))
                {
                    throw new SchemaParseException("Duplicate type in union: " + name);
                }

                uniqueSchemas.Add(name, name);
                schemas.Add(unionType);
            }

            return(new UnionSchema(schemas, props));
        }
Beispiel #3
0
        /// <summary>
        /// Static function to return new instance of map schema
        /// </summary>
        /// <param name="jtok">JSON object for the map schema</param>
        /// <param name="names">list of named schemas already read</param>
        /// <param name="encspace">enclosing namespace of the map schema</param>
        /// <returns></returns>
        internal static MapSchema NewInstance(JToken jtok, PropertyMap props, SchemaNames names, string encspace)
        {
            JToken jvalue = jtok["values"];

            if (null == jvalue)
            {
                throw new AvroTypeException("Map does not have 'values'");
            }

            return(new MapSchema(Schema.ParseJson(jvalue, names, encspace), props));
        }
Beispiel #4
0
        /// <summary>
        /// Static class to return a new instance of ArraySchema
        /// </summary>
        /// <param name="jtok">JSON object for the array schema</param>
        /// <param name="names">list of named schemas already parsed</param>
        /// <param name="encspace">enclosing namespace for the array schema</param>
        /// <returns></returns>
        internal static ArraySchema NewInstance(JToken jtok, PropertyMap props, SchemaNames names, string encspace)
        {
            JToken jitem = jtok["items"];

            if (null == jitem)
            {
                throw new AvroTypeException("Array does not have 'items'");
            }

            return(new ArraySchema(Schema.ParseJson(jitem, names, encspace), props));
        }