Skip to content

Commit e00480a

Browse files
author
eedalong
committed
reconstruct Field
1 parent 7234bde commit e00480a

File tree

2 files changed

+39
-58
lines changed

2 files changed

+39
-58
lines changed

client/utils/Field.cs

Lines changed: 25 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -6,77 +6,59 @@ namespace iotdb_client_csharp.client.utils
66
public class Field
77
{
88
// TBD By Zengz
9-
public bool bool_val;
10-
public int int_val;
11-
public long long_val;
12-
public float float_val;
13-
public double double_val;
14-
// why we need to keep binary values here
15-
public string str_val;
16-
17-
private TSDataType type{get;set;}
18-
9+
private object val;
10+
public TSDataType type{get;set;}
1911
public Field(TSDataType data_type){
2012
this.type = data_type;
2113
}
22-
23-
public void set(string value){
24-
str_val = value;
14+
public void set<T>(T value){
15+
val = value;
2516
}
26-
public void set(int value){
27-
int_val = value;
17+
public double get_double(){
18+
return type==TSDataType.TEXT?double.Parse((string)val):(double)val;
2819
}
29-
public void set(double value){
30-
double_val = value;
20+
public Int32 get_int(){
21+
return type==TSDataType.TEXT?Int32.Parse((string)val):(Int32)val;
3122
}
32-
public void set(long value){
33-
long_val = value;
23+
public Int64 get_long(){
24+
return type==TSDataType.TEXT?Int64.Parse((string)val):(Int64)val;
3425
}
35-
public void set(float value){
36-
float_val = value;
26+
public float get_float(){
27+
return type==TSDataType.TEXT?float.Parse((string)val):(float)val;
3728
}
38-
public void set(bool value){
39-
bool_val = value;
29+
public string get_str(){
30+
return val.ToString();
4031
}
4132
public T get<T>(){
4233
switch(type){
43-
case TSDataType.BOOLEAN:
44-
return (T)(object)bool_val;
45-
case TSDataType.INT64:
46-
return (T)(object)long_val;
47-
case TSDataType.FLOAT:
48-
return (T)(object)float_val;
49-
case TSDataType.INT32:
50-
return (T)(object)int_val;
51-
case TSDataType.DOUBLE:
52-
return (T)(object)double_val;
53-
case TSDataType.TEXT:
54-
return (T)(object)str_val;
55-
default:
34+
case TSDataType.NONE :
5635
return (T)(object)null;
36+
default:
37+
return (T)val;
5738
}
5839
}
40+
5941
public byte[] get_bytes(){
6042
ByteBuffer buffer = new ByteBuffer(new byte[]{});
6143
buffer.add_int((int)type);
6244
switch(type){
6345
case TSDataType.BOOLEAN:
64-
buffer.add_bool(bool_val);
46+
buffer.add_bool((bool)val);
6547
break;
6648
case TSDataType.INT32:
67-
buffer.add_int(int_val);
49+
buffer.add_int((Int32)val);
6850
break;
6951
case TSDataType.INT64:
70-
buffer.add_long(long_val);
52+
buffer.add_long((Int64)val);
7153
break;
7254
case TSDataType.FLOAT:
73-
buffer.add_float(float_val);
55+
buffer.add_float((float)val);
7456
break;
7557
case TSDataType.DOUBLE:
76-
buffer.add_double(double_val);
58+
buffer.add_double((double)val);
7759
break;
7860
case TSDataType.TEXT:
79-
buffer.add_str(str_val);
61+
buffer.add_str((string)val);
8062
break;
8163
case TSDataType.NONE:
8264
var err_msg = string.Format("NONE type does not support get bytes");
@@ -88,22 +70,10 @@ public byte[] get_bytes(){
8870
public override string ToString()
8971
{
9072
switch(type){
91-
case TSDataType.TEXT:
92-
return str_val;
93-
case TSDataType.INT32:
94-
return int_val.ToString();
95-
case TSDataType.INT64:
96-
return long_val.ToString();
97-
case TSDataType.FLOAT:
98-
return float_val.ToString();
99-
case TSDataType.DOUBLE:
100-
return double_val.ToString();
101-
case TSDataType.BOOLEAN:
102-
return bool_val.ToString();
10373
case TSDataType.NONE:
10474
return "NULL";
10575
default:
106-
return "";
76+
return val.ToString();
10777
}
10878
}
10979

client/utils/RowRecord.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,33 @@
11
using System.Collections.Generic;
22
using Thrift;
3+
using System;
34
namespace iotdb_client_csharp.client.utils
45
{
56
public class RowRecord
67
{
7-
private long timestamp{get;set;}
8-
private List<Field> field_lst{get;set;}
8+
public long timestamp{get;set;}
9+
public List<Field> field_lst{get;set;}
910
public RowRecord(long timestamp, List<Field> field_lst){
1011
this.timestamp = timestamp;
1112
this.field_lst = field_lst;
1213
}
13-
public void add_filed(Field field){
14+
public void add_field(Field field){
15+
field_lst.Add(field);
16+
}
17+
public void append(Field field){
1418
field_lst.Add(field);
1519
}
1620

1721
public void set_filed(int index, Field filed){
1822
field_lst[index] = filed;
1923
}
24+
public Field this[int index]{
25+
get => field_lst[index];
26+
set => field_lst[index] = value;
27+
}
28+
public DateTime TimeStampAsDateTime(){
29+
return DateTime.UnixEpoch.AddMilliseconds(timestamp);
30+
}
2031
public override string ToString()
2132
{
2233
var str = timestamp.ToString();

0 commit comments

Comments
 (0)