コード例 #1
0
 private void AnalyzeProperty(RelaxedField parent, JProperty jp)
 {
     if (jp.Value.Type >= JTokenType.Integer)
     {
         var field = new RelaxedField(jp.Name, parent);
         field.DataType = GetParquetDataType(jp.Value.Type, parent.DataType);
         parent.Children.Add(field);
     }
     else
     {
         throw new NotImplementedException();
     }
 }
コード例 #2
0
        public void Analyze(RelaxedField parent, JContainer jo)
        {
            foreach (JToken jt in jo)
            {
                switch (jt.Type)
                {
                case JTokenType.Property:
                    AnalyzeProperty(parent, jt as JProperty);
                    break;

                default:
                    throw new NotImplementedException($"no {jt.Type} yet ;)");
                }
            }
        }
コード例 #3
0
        private void Analyze(RelaxedField parent, JToken token)
        {
            switch (token.Type)
            {
            //object has key-value properties that are columns!
            case JTokenType.Object:
                JObject jObject = (JObject)token;
                foreach (JToken child in jObject.Children())
                {
                    Analyze(parent, child);
                }
                break;

            //contains a value or further nesting
            case JTokenType.Property:
                JProperty jProperty = (JProperty)token;
                var       property  = new RelaxedField(jProperty.Name, parent);
                parent.Children.Add(property);
                Analyze(property, jProperty.Value);
                break;

            //is either a simple value or a list
            case JTokenType.Array:
                JArray jArray = (JArray)token;
                parent.IsArray = true;
                JToken jae = jArray.First;
                if (jae != null)
                {
                    if (jae.IsPrimitiveValue())
                    {
                        parent.DataType = GetParquetDataType(jae.Type, null);
                    }
                    else
                    {
                        //it's not an array then, children are actual objects!
                        Analyze(parent, jae);
                    }
                }
                else
                {
                    //array is empty, remove it from parent!
                    parent.Remove();
                }
                break;

            case JTokenType.Integer:
            case JTokenType.Float:
            case JTokenType.String:
            case JTokenType.Boolean:
            case JTokenType.Date:
            case JTokenType.Raw:
            case JTokenType.Bytes:
            case JTokenType.Guid:
            case JTokenType.Uri:
            case JTokenType.TimeSpan:
                parent.DataType = GetParquetDataType(token.Type, null);
                break;

            case JTokenType.Null:
                //cannot infer type for nulls
                parent.Remove();
                break;

            default:
                throw new NotImplementedException($"what's {token.Type}?");
            }
        }
コード例 #4
0
        //    JObject -> JContainer -> JToken
        //  JProperty -> JContainer
        //     JArray -> JContainer

        public JsonSchemaInferring()
        {
            _root = new RelaxedField("root", null);
        }
コード例 #5
0
 public JsonSchemaExtractor()
 {
     _root = new RelaxedField("root", null);
 }