4 using System.Collections.Generic;
24 System.Text.StringBuilder sb =
new System.Text.StringBuilder();
25 sb.Append(
"Contents: " );
29 foreach (
Avro.Field field in
this.Schema.Fields )
33 sb.Append( field.Name );
37 this.TryGetValue( field.Name, out value );
39 value_string = $
"{value}";
41 value_string =
"<null>";
44 sb.Append( value_string );
47 sb.Remove( (sb.Length - 2), 2 );
62 Schema dynamic_table_schema;
65 dynamic_table_schema =
Avro.Schema.Parse( dynamic_table_schema_string );
67 catch ( Exception ex )
73 IList<KineticaRecord> records =
new List<KineticaRecord>();
77 using ( var ms =
new MemoryStream( encoded_data ) )
81 var reader =
new Avro.Generic.DefaultReader(dynamic_table_schema, dynamic_table_schema);
82 BinaryDecoder decoder =
new BinaryDecoder( ms );
83 Avro.Generic.GenericRecord obj = (
Avro.Generic.GenericRecord) reader.Read( null, dynamic_table_schema, dynamic_table_schema, decoder );
86 object column_headers_0 =
new object();
87 Object[] column_headers = null;
88 if ( obj.TryGetValue(
"column_headers", out column_headers_0 ) )
90 column_headers = ( Object[] ) column_headers_0;
94 object column_types_0 =
new object();
95 Object[] column_types = null;
96 if ( obj.TryGetValue(
"column_datatypes", out column_types_0 ) )
98 column_types = ( Object[] ) column_types_0;
102 int num_columns = column_headers.Length;
106 Object[][] encoded_column_data =
new Object[ num_columns ][];
108 for (
int i = 0; i < num_columns; ++i )
111 string column_name = $
"column_{i+1}";
114 object column_data_0 =
new object();
115 Object[] column_data = null;
116 if ( obj.TryGetValue( column_name, out column_data_0 ) )
118 column_data = ( Object[] ) column_data_0;
122 encoded_column_data[i] = column_data;
127 int num_records = encoded_column_data[0].Length;
130 foreach ( Object[] l
in encoded_column_data )
132 if ( l.Length != num_records )
141 Avro.RecordSchema record_schema = (
Avro.RecordSchema) dynamic_record_type.
getSchema();
145 for (
int record_idx = 0; record_idx < num_records; ++record_idx )
151 for (
int column_idx = 0; column_idx < num_columns; ++column_idx )
154 var val = encoded_column_data[ column_idx ][ record_idx ];
157 var field = record_schema.Fields[ column_idx ];
160 record.Add( field.Name, val );
164 records.Add( record );
Convenience class for using Avro.Generic.GenericRecord objects.
KineticaRecord(RecordSchema schema)
string ContentsToString()
Convert the contents of the record to a string.
static KineticaType fromDynamicSchema(string dynamic_table_schema_string, Object[] column_headers, Object[] column_types)
Create a KineticaType object based on information provided in a dynamic schema.
static IList< KineticaRecord > DecodeDynamicTableRecords(string dynamic_table_schema_string, byte[] encoded_data)
Decodes binary encoded data of a dynamically created table returned by the server.