public TSchemaElement CreateSimpleSchemaElement(string name) { var th = new TSchemaElement(name); th.Repetition_type = Thrift.FieldRepetitionType.REQUIRED; return(th); }
private static void AddSchema(List <TSchemaElement> container, SchemaElement se) { if (se.IsRepeated) { if (se.IsMap) { AddMapSchema(container, se); } else { AddListSchema(container, se); } } else if (se.IsNestedStructure) { var structure = new TSchemaElement(se.Name) { Repetition_type = Thrift.FieldRepetitionType.OPTIONAL, Num_children = se.Children.Count }; container.Add(structure); foreach (SchemaElement child in se.Children) { AddSchema(container, child); } } else { container.Add(se.Thrift); } }
public TSchemaElement CreateSimpleSchemaElement(string name, bool nullable) { var th = new TSchemaElement(name); th.Repetition_type = nullable ? Thrift.FieldRepetitionType.OPTIONAL : Thrift.FieldRepetitionType.REQUIRED; return(th); }
private static void AddSchema(List <TSchemaElement> container, SchemaElement se) { if (se.IsRepeated) { var root = new TSchemaElement(se.Name) { Converted_type = Thrift.ConvertedType.LIST, Repetition_type = Thrift.FieldRepetitionType.OPTIONAL, Num_children = 1 }; var list = new TSchemaElement("list") { Repetition_type = Thrift.FieldRepetitionType.REPEATED, Num_children = 1 }; TSchemaElement element = se.Thrift; element.Name = "element"; element.Repetition_type = Thrift.FieldRepetitionType.OPTIONAL; container.Add(root); container.Add(list); container.Add(element); } else { container.Add(se.Thrift); } }
public TSchemaElement CreateSchemaElement(string name, Type systemType, out Type elementType, out string pathName, out Type[] extras) { var th = new TSchemaElement(name); extras = null; if (TypeFactory.TryExtractDictionaryType(systemType, out Type keyType, out Type valueType)) { elementType = typeof(IDictionary); pathName = BuildDictionaryPath(name); CreateDictionary(th, keyType, valueType); th.Repetition_type = Thrift.FieldRepetitionType.REPEATED; extras = new[] { keyType, valueType }; }
private static void AddSchema(List <TSchemaElement> container, SchemaElement se) { if (se.IsRepeated) { var root = new TSchemaElement(se.Name) { Converted_type = Thrift.ConvertedType.LIST, Repetition_type = Thrift.FieldRepetitionType.OPTIONAL, Num_children = 1 }; var list = new TSchemaElement("list") { Repetition_type = Thrift.FieldRepetitionType.REPEATED, Num_children = 1 }; TSchemaElement element = se.Thrift; element.Name = "element"; element.Repetition_type = Thrift.FieldRepetitionType.OPTIONAL; container.Add(root); container.Add(list); container.Add(element); } else if (se.IsNestedStructure) { var structure = new TSchemaElement(se.Name) { Repetition_type = Thrift.FieldRepetitionType.OPTIONAL, Num_children = se.Children.Count }; container.Add(structure); foreach (SchemaElement child in se.Children) { AddSchema(container, child); } } else { container.Add(se.Thrift); } }
private static void AddMapSchema(List <TSchemaElement> container, SchemaElement se) { var root = new TSchemaElement(se.Name) { Converted_type = Thrift.ConvertedType.MAP, Num_children = 1, Repetition_type = Thrift.FieldRepetitionType.OPTIONAL, }; container.Add(root); var kv = new TSchemaElement("key_value") { Num_children = 2, Repetition_type = Thrift.FieldRepetitionType.REPEATED }; container.Add(kv); foreach (SchemaElement kvse in se.Extra) { AddSchema(container, kvse); } }
public TSchemaElement CreateSchemaElement(string name, Type systemType, out Type elementType, out string path) { var th = new TSchemaElement(name); if (TypeFactory.TryExtractEnumerableType(systemType, out Type baseType)) { elementType = baseType; path = BuildRepeatablePath(name); th.Repetition_type = Thrift.FieldRepetitionType.REPEATED; } else if (typeof(Row) == systemType) { //this is a hierarchy, therefore can be a fake type elementType = typeof(int); path = null; th.Repetition_type = Thrift.FieldRepetitionType.OPTIONAL; } else { if (TryGetNonNullableType(systemType, out Type nonNullableSystemType)) { elementType = nonNullableSystemType; th.Repetition_type = Thrift.FieldRepetitionType.OPTIONAL; } else if (systemType.GetTypeInfo().IsClass) { //reference types are always nullable elementType = systemType; th.Repetition_type = Thrift.FieldRepetitionType.OPTIONAL; } else { elementType = systemType; //this might be changed later or if column has nulls (on write) th.Repetition_type = Thrift.FieldRepetitionType.REQUIRED; } path = null; } //adjust schema TypePrimitive tp = TypePrimitive.Find(elementType); th.Type = tp.ThriftType; if (tp.ThriftAnnotation != null) { th.Converted_type = tp.ThriftAnnotation.Value; } //todo: not the best place for it, but it's a special case at the moment if (systemType == typeof(decimal)) { th.Precision = 38; th.Scale = 18; th.Type_length = 16; //set to default type length to be used when no elements are added } return(th); }