5 using System.Collections.Generic;
16 private RecordSchema m_schema;
17 private PropertyInfo[] m_properties;
37 m_properties = this.GetType().GetProperties();
46 var t = type ?? this.GetType();
48 m_properties = this.GetType().GetProperties();
56 public object Get(
int fieldPos)
58 return m_properties[fieldPos].GetValue(
this);
66 public void Put(
int fieldPos,
object fieldValue)
68 m_properties[fieldPos].SetValue(
this, fieldValue);
81 string jsonType = AvroType( t, ktype );
82 return Avro.Schema.Parse( jsonType ) as RecordSchema;
100 case "Boolean":
return "\"boolean\"";
101 case "Int32":
return "\"int\"";
102 case "Int64":
return "\"long\"";
103 case "Double":
return "\"double\"";
104 case "Single":
return "\"float\"";
105 case "Byte[]":
return "\"bytes\"";
106 case "String":
return "\"string\"";
107 case "String[]":
return $
"{{ \"type\":\"array\", \"items\":\"string\"}}";
108 case "String[][]":
return $
"{{ \"type\":\"array\", \"items\":{{ \"type\":\"array\", \"items\":\"string\"}}}}";
111 case "Nullable`1":
return AvroType( Nullable.GetUnderlyingType( t ), ktype );
115 if ( t.IsGenericType )
117 var genericParams = t.GenericTypeArguments;
118 if (1 == genericParams.Length)
120 return $
"{{ \"type\":\"array\", \"items\":{AvroType( genericParams[0], ktype )}}}";
126 case "IDictionary`2":
129 var genericParams = t.GenericTypeArguments;
130 if (2 == genericParams.Length)
132 return $
"{{ \"type\":\"map\", \"values\":{AvroType( genericParams[1], ktype )}}}";
138 case "Schema":
break;
146 if (t.IsSubclassOf(typeof(Object)))
150 PropertyInfo[] type_properties = t.GetProperties( BindingFlags.DeclaredOnly |
151 BindingFlags.Instance |
152 BindingFlags.Public );
153 Array.Sort( type_properties, delegate ( PropertyInfo p1, PropertyInfo p2 )
154 {
return p1.MetadataToken.CompareTo( p2.MetadataToken ); } );
156 foreach ( var prop
in type_properties )
158 bool is_nullable =
false;
159 var prop_type = prop.PropertyType;
160 if ( prop_type.IsGenericType && prop_type.GetGenericTypeDefinition() == typeof( Nullable<> ) )
170 string avroType = AvroType( prop_type, ktype );
171 if ( !String.IsNullOrWhiteSpace( avroType ) )
175 fields += $
"{{\"name\":\"{prop.Name}\",\"type\":[{avroType},\"null\"]}},";
179 fields += $
"{{\"name\":\"{prop.Name}\",\"type\":{avroType}}},";
185 char[] comma = {
',' };
186 fields = fields.TrimEnd( comma );
189 return $
"{{\"type\":\"record\",\"name\":\"{t.Name}\",\"fields\":[{fields}]}}";
191 System.Diagnostics.Debug.WriteLine($
"Unkonwn type: {t.Name}");
break;
static RecordSchema SchemaFromType(System.Type t, KineticaType ktype=null)
Create an Avro Schema from a System.Type and a KineticaType.
KineticaData(System.Type type=null)
Default constructor, with optional System.Type
KineticaData(KineticaType type)
Constructor from Kinetica Type
Column getColumn(int index)
bool isNullable()
Returns if the column is nullable.
void Put(int fieldPos, object fieldValue)
Write a specific property to this object
Schema Schema
Avro Schema for this class
KineticaData - class to help with Avro Encoding for Kinetica
object Get(int fieldPos)
Retrieve a specific property from this object