├── .gitignore ├── LICENSE ├── README.md ├── README_CN.md ├── dolphindb_csharpapi.sln ├── dolphindb_csharpapi_net_core.csproj ├── dolphindb_csharpapi_net_core.sln ├── src ├── DBConnection.cs ├── Properties │ └── AssemblyInfo.cs ├── data │ ├── AbstractScalar.cs │ ├── AbstractVector.cs │ ├── BasicAnyVector.cs │ ├── BasicArrayVector.cs │ ├── BasicBooleanVector.cs │ ├── BasicByteVector.cs │ ├── BasicComplex.cs │ ├── BasicComplexMatrix.cs │ ├── BasicComplexVector.cs │ ├── BasicDecimal128.cs │ ├── BasicDecimal128Vector.cs │ ├── BasicDecimal32.cs │ ├── BasicDecimal32Vector.cs │ ├── BasicDecimal64.cs │ ├── BasicDecimal64Vector.cs │ ├── BasicDouble2Vector.cs │ ├── BasicDoubleVector.cs │ ├── BasicEntityFactory.cs │ ├── BasicFloatVector.cs │ ├── BasicIPAddr.cs │ ├── BasicInt.cs │ ├── BasicInt128.cs │ ├── BasicInt128Vector.cs │ ├── BasicIntVector.cs │ ├── BasicIotAnyVector.cs │ ├── BasicLongVector.cs │ ├── BasicPoint.cs │ ├── BasicPointVector.cs │ ├── BasicShortVector.cs │ ├── BasicStringVector.cs │ ├── BasicSymbolVector.cs │ ├── BasicTable.cs │ ├── BasicUuid.cs │ ├── BasicVoidVector.cs │ ├── IEntity.cs │ ├── Utils.cs │ └── Void.cs ├── dolphindb_csharpapi.csproj ├── io │ ├── AbstractExtendedDataInputStream.cs │ ├── AbstractExtendedDataOutputStream.cs │ ├── BigEndianDataInputStream.cs │ ├── BigEndianDataOutputStream.cs │ ├── Double2.cs │ ├── ExtendedDataInput.cs │ ├── ExtendedDataOutput.cs │ ├── LittleEndianDataInputStream.cs │ └── LittleEndianDataOutputStream.cs ├── route │ ├── AutoFitTableUpsert.cs │ ├── DBVersion.cs │ ├── MultithreadedTableWriter.cs │ └── PartitionedTableAppender.cs └── streaming │ ├── AbstractClient.cs │ ├── BasicMessage.cs │ ├── IMessage.cs │ ├── MessageDispatcher.cs │ ├── MessageParser.cs │ ├── PollingClient.cs │ ├── StreamDeserializer.cs │ ├── ThreadPooledClient.cs │ ├── ThreadedClient.cs │ └── cep │ └── EventClient.cs └── test ├── DBConnection_runAsync_test.cs ├── DBConnection_test.cs ├── DBConnection_test2.cs ├── EntityBlockReader_test.cs ├── ExclusiveDBConnectionPool_test.cs ├── TestResults └── 24d0142c-af77-4452-82aa-fe924e1c322a │ └── coverage.cobertura.xml ├── compression_test └── testCompress.cs ├── connectionPool_runAsync_test.cs ├── data_test ├── AbstractTest.cs ├── BasicArrayVectorTest.cs ├── BasicIotAnyVectorTest.cs ├── BasicMatrixTest.cs ├── BasicScalarTest.cs ├── BasicTableTest.cs ├── BasicVectorTest.cs └── BasicVoidTest.cs ├── dolphindb_csharpapi_net_core_test.csproj ├── route_test ├── BatchTableWriter_test.cs ├── MultithreadTableWriter_test.cs ├── PartitionedTableAppender_test.cs ├── autoFitTableAppend_test.cs └── autoFitTableUpsert_test.cs └── streaming ├── cep_test ├── EventClientTest.cs └── EventSenderTest.cs └── streamReverse_test ├── AbstractClientTest.cs ├── PoolingClientReverseTest.cs ├── ThreadPoolClientReverseTest.cs └── ThreadedClientReverseTest.cs /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | *.cache 3 | .idea 4 | .idea/* 5 | *.pdb 6 | 7 | *.dll 8 | 9 | *.props 10 | 11 | *.targets 12 | packages 13 | obj/ 14 | bin/ 15 | *.dll 16 | *.pdb 17 | *.sqlite 18 | .vs/dolphindb_csharpapi/v15/.suo 19 | *.pdb 20 | *.dll 21 | .vs/dolphindb_csharpapi/v15/.suo 22 | /WindowsFormsApp1 23 | .vs/dolphindb_csharpapi/v15/Browse.VC.db 24 | .vs/dolphindb_csharpapi/v15/Server/ 25 | .vs/dolphindb_csharpapi/v15/ipch/ 26 | /.idea 27 | /.vs 28 | /dolphindb_dataAppender 29 | /WindowsFormsApp1 30 | /dolphindb_csharpapi_test/SupWin.cs 31 | /dolphindb_csharpapi/*.user 32 | /dolphindb_csharpapi/*.user 33 | test/SupWin.cs 34 | .vscode/launch.json 35 | examples/HAWritingData.cs 36 | longTimeTask/Properties/AssemblyInfo.cs 37 | longTimeTask/Program.cs 38 | longTimeTask/longTimeTask.csproj 39 | -------------------------------------------------------------------------------- /dolphindb_csharpapi.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.6.33815.320 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "dolphindb_csharpapi", "src\dolphindb_csharpapi.csproj", "{F744DA92-D9F2-49BB-9783-F89E825CB307}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "dolphindb_csharpapi_test", "test\dolphindb_csharpapi_test.csproj", "{9297EF6F-E380-423B-BA64-FE2907226FF8}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Debug|x64 = Debug|x64 14 | Debug|x86 = Debug|x86 15 | Release|Any CPU = Release|Any CPU 16 | Release|x64 = Release|x64 17 | Release|x86 = Release|x86 18 | EndGlobalSection 19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 20 | {F744DA92-D9F2-49BB-9783-F89E825CB307}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {F744DA92-D9F2-49BB-9783-F89E825CB307}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {F744DA92-D9F2-49BB-9783-F89E825CB307}.Debug|x64.ActiveCfg = Debug|Any CPU 23 | {F744DA92-D9F2-49BB-9783-F89E825CB307}.Debug|x64.Build.0 = Debug|Any CPU 24 | {F744DA92-D9F2-49BB-9783-F89E825CB307}.Debug|x86.ActiveCfg = Debug|Any CPU 25 | {F744DA92-D9F2-49BB-9783-F89E825CB307}.Debug|x86.Build.0 = Debug|Any CPU 26 | {F744DA92-D9F2-49BB-9783-F89E825CB307}.Release|Any CPU.ActiveCfg = Release|Any CPU 27 | {F744DA92-D9F2-49BB-9783-F89E825CB307}.Release|Any CPU.Build.0 = Release|Any CPU 28 | {F744DA92-D9F2-49BB-9783-F89E825CB307}.Release|x64.ActiveCfg = Release|Any CPU 29 | {F744DA92-D9F2-49BB-9783-F89E825CB307}.Release|x64.Build.0 = Release|Any CPU 30 | {F744DA92-D9F2-49BB-9783-F89E825CB307}.Release|x86.ActiveCfg = Release|Any CPU 31 | {F744DA92-D9F2-49BB-9783-F89E825CB307}.Release|x86.Build.0 = Release|Any CPU 32 | {9297EF6F-E380-423B-BA64-FE2907226FF8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 33 | {9297EF6F-E380-423B-BA64-FE2907226FF8}.Debug|Any CPU.Build.0 = Debug|Any CPU 34 | {9297EF6F-E380-423B-BA64-FE2907226FF8}.Debug|x64.ActiveCfg = Debug|Any CPU 35 | {9297EF6F-E380-423B-BA64-FE2907226FF8}.Debug|x64.Build.0 = Debug|Any CPU 36 | {9297EF6F-E380-423B-BA64-FE2907226FF8}.Debug|x86.ActiveCfg = Debug|Any CPU 37 | {9297EF6F-E380-423B-BA64-FE2907226FF8}.Debug|x86.Build.0 = Debug|Any CPU 38 | {9297EF6F-E380-423B-BA64-FE2907226FF8}.Release|Any CPU.ActiveCfg = Release|Any CPU 39 | {9297EF6F-E380-423B-BA64-FE2907226FF8}.Release|Any CPU.Build.0 = Release|Any CPU 40 | {9297EF6F-E380-423B-BA64-FE2907226FF8}.Release|x64.ActiveCfg = Release|Any CPU 41 | {9297EF6F-E380-423B-BA64-FE2907226FF8}.Release|x64.Build.0 = Release|Any CPU 42 | {9297EF6F-E380-423B-BA64-FE2907226FF8}.Release|x86.ActiveCfg = Release|Any CPU 43 | {9297EF6F-E380-423B-BA64-FE2907226FF8}.Release|x86.Build.0 = Release|Any CPU 44 | EndGlobalSection 45 | GlobalSection(SolutionProperties) = preSolution 46 | HideSolutionNode = FALSE 47 | EndGlobalSection 48 | GlobalSection(ExtensibilityGlobals) = postSolution 49 | SolutionGuid = {BD8FB1DE-3841-4F68-A643-A686A14E10BC} 50 | EndGlobalSection 51 | EndGlobal 52 | -------------------------------------------------------------------------------- /dolphindb_csharpapi_net_core.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netcoreapp3.1 5 | True 6 | false 7 | dolphindb_csharpapi 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /dolphindb_csharpapi_net_core.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.1.32210.238 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "dolphindb_csharpapi_net_core", "dolphindb_csharpapi_net_core.csproj", "{5233ED95-F919-4FA3-8BD9-193E066A8F27}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "dolphindb_csharpapi_net_core_test", "test\dolphindb_csharpapi_net_core_test.csproj", "{6D88F097-9FEC-4636-BBA6-A3E59DB0BB7E}" 9 | ProjectSection(ProjectDependencies) = postProject 10 | {5233ED95-F919-4FA3-8BD9-193E066A8F27} = {5233ED95-F919-4FA3-8BD9-193E066A8F27} 11 | EndProjectSection 12 | EndProject 13 | Global 14 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 15 | Debug|Any CPU = Debug|Any CPU 16 | Release|Any CPU = Release|Any CPU 17 | EndGlobalSection 18 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 19 | {5233ED95-F919-4FA3-8BD9-193E066A8F27}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 20 | {5233ED95-F919-4FA3-8BD9-193E066A8F27}.Debug|Any CPU.Build.0 = Debug|Any CPU 21 | {5233ED95-F919-4FA3-8BD9-193E066A8F27}.Release|Any CPU.ActiveCfg = Release|Any CPU 22 | {5233ED95-F919-4FA3-8BD9-193E066A8F27}.Release|Any CPU.Build.0 = Release|Any CPU 23 | {6D88F097-9FEC-4636-BBA6-A3E59DB0BB7E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 24 | {6D88F097-9FEC-4636-BBA6-A3E59DB0BB7E}.Debug|Any CPU.Build.0 = Debug|Any CPU 25 | {6D88F097-9FEC-4636-BBA6-A3E59DB0BB7E}.Release|Any CPU.ActiveCfg = Release|Any CPU 26 | {6D88F097-9FEC-4636-BBA6-A3E59DB0BB7E}.Release|Any CPU.Build.0 = Release|Any CPU 27 | EndGlobalSection 28 | GlobalSection(SolutionProperties) = preSolution 29 | HideSolutionNode = FALSE 30 | EndGlobalSection 31 | GlobalSection(ExtensibilityGlobals) = postSolution 32 | SolutionGuid = {FB1A5801-604F-4CB4-B4AB-ED370B77C83F} 33 | EndGlobalSection 34 | EndGlobal 35 | -------------------------------------------------------------------------------- /src/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的一般信息由以下 6 | // 控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("dolphindb_csharpapi")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("dolphindb_csharpapi")] 13 | [assembly: AssemblyCopyright("Copyright © 2022")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // 将 ComVisible 设置为 false 会使此程序集中的类型 18 | //对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 19 | //请将此类型的 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID 23 | [assembly: Guid("f744da92-d9f2-49bb-9783-f89e825cb307")] 24 | 25 | // 程序集的版本信息由下列四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 生成号 30 | // 修订号 31 | // 32 | // 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 33 | //通过使用 "*",如下所示: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("3.00.2.3")] 36 | [assembly: AssemblyFileVersion("3.00.2.3")] 37 | -------------------------------------------------------------------------------- /src/data/AbstractScalar.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using dolphindb.io; 3 | using System.Data; 4 | namespace dolphindb.data 5 | { 6 | public abstract class AbstractScalar : AbstractEntity, IScalar 7 | { 8 | public abstract void writeScalarToOutputStream(ExtendedDataOutput @out); 9 | 10 | public override DATA_FORM getDataForm() 11 | { 12 | return DATA_FORM.DF_SCALAR; 13 | } 14 | 15 | public int rows() 16 | { 17 | return 1; 18 | } 19 | 20 | public int columns() 21 | { 22 | return 1; 23 | } 24 | 25 | public void write(ExtendedDataOutput @out) 26 | { 27 | int flag = ((int)DATA_FORM.DF_SCALAR << 8) + (int)getDataType(); 28 | @out.writeShort(flag); 29 | if( getDataCategory() == DATA_CATEGORY.DENARY) 30 | { 31 | @out.writeInt(getScale()); 32 | } 33 | writeScalarToOutputStream(@out); 34 | } 35 | 36 | public string toString() 37 | { 38 | return getString(); 39 | } 40 | 41 | public virtual bool isNull() 42 | { 43 | throw new NotImplementedException(); 44 | } 45 | 46 | public virtual void setNull() 47 | { 48 | throw new NotImplementedException(); 49 | } 50 | 51 | public virtual Number getNumber() 52 | { 53 | throw new NotImplementedException(); 54 | } 55 | 56 | public virtual object getTemporal() 57 | { 58 | throw new NotImplementedException(); 59 | } 60 | 61 | public virtual DATA_CATEGORY getDataCategory() 62 | { 63 | throw new NotImplementedException(); 64 | } 65 | 66 | public virtual DATA_TYPE getDataType() 67 | { 68 | throw new NotImplementedException(); 69 | } 70 | 71 | public abstract string getString(); 72 | 73 | public virtual DataTable toDataTable() 74 | { 75 | DataTable dt = new DataTable(); 76 | dt.Columns.Add("dolphinScalar", Utils.getSystemType(getDataType())); 77 | DataRow dr = dt.NewRow(); 78 | dr[0] = Utils.getRowDataTableObject(this); 79 | dt.Rows.Add(dr); 80 | return dt; 81 | } 82 | 83 | public abstract object getObject(); 84 | 85 | public abstract void setObject(object value); 86 | 87 | public void writeCompressed(ExtendedDataOutput output) 88 | { 89 | throw new NotImplementedException(); 90 | } 91 | 92 | public abstract int hashBucket(int buckets); 93 | 94 | public virtual int getScale() 95 | { 96 | throw new NotImplementedException(); 97 | } 98 | 99 | public virtual int getExtraParamForType(){ 100 | return 0; 101 | } 102 | } 103 | } -------------------------------------------------------------------------------- /src/data/BasicAnyVector.cs: -------------------------------------------------------------------------------- 1 | using dolphindb.io; 2 | using System; 3 | using System.Text; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | 7 | namespace dolphindb.data 8 | { 9 | public class BasicAnyVector : AbstractVector 10 | { 11 | private List values; 12 | 13 | 14 | public BasicAnyVector(int size) : base(DATA_FORM.DF_VECTOR) 15 | { 16 | values = new List(size); 17 | for(int i = 0; i < size; ++i) 18 | { 19 | values.Add(null); 20 | } 21 | } 22 | 23 | protected internal BasicAnyVector(IEntity[] array): base(DATA_FORM.DF_VECTOR) 24 | { 25 | values = new List(array.Length); 26 | for(int i = 0; i < array.Length ; ++i) 27 | { 28 | values.Add((IEntity)array[i]); 29 | } 30 | } 31 | 32 | protected internal BasicAnyVector(ExtendedDataInput @in) : base(DATA_FORM.DF_VECTOR) 33 | { 34 | int rows = @in.readInt(); 35 | int cols = @in.readInt(); 36 | int size = rows * cols; 37 | values = new List(); 38 | 39 | BasicEntityFactory factory = new BasicEntityFactory(); 40 | for (int i = 0; i < size; ++i) 41 | { 42 | short flag = @in.readShort(); 43 | int form = flag >> 8; 44 | int type = flag & 0xff; 45 | bool extended = type >= 128; 46 | if (type >= 128) 47 | type -= 128; 48 | //if (form != 1) 49 | //assert (form == 1); 50 | //if (type != 4) 51 | //assert(type == 4); 52 | IEntity obj = factory.createEntity((DATA_FORM)form, (DATA_TYPE)type, @in, extended); 53 | values.Add(obj); 54 | } 55 | 56 | } 57 | 58 | public override IScalar get(int index) 59 | { 60 | if (values[index].isScalar()) 61 | { 62 | return (IScalar)values[index]; 63 | } 64 | else 65 | { 66 | throw new Exception("The element of the vector is not a scalar object."); 67 | } 68 | } 69 | 70 | public override void set(int index, IScalar value) 71 | { 72 | values[index] = value; 73 | } 74 | 75 | public virtual void setEntity(int index, IEntity value) 76 | { 77 | values[index] = value; 78 | } 79 | 80 | public override bool isNull(int index) 81 | { 82 | return values[index] == null || (values[index].isScalar() && ((IScalar)values[index]).isNull()); 83 | } 84 | 85 | public override void setNull(int index) 86 | { 87 | values[index] = new Void(); 88 | } 89 | 90 | public override DATA_CATEGORY getDataCategory() 91 | { 92 | return DATA_CATEGORY.MIXED; 93 | } 94 | 95 | public override DATA_TYPE getDataType() 96 | { 97 | return DATA_TYPE.DT_ANY; 98 | } 99 | 100 | public override int rows() 101 | { 102 | return values.Count; 103 | } 104 | 105 | public override string getString() 106 | { 107 | StringBuilder sb = new StringBuilder("("); 108 | int size = Math.Min(10, rows()); 109 | if (size > 0) 110 | { 111 | sb.Append(getEntity(0).getString()); 112 | } 113 | for (int i = 1; i < size; ++i) 114 | { 115 | sb.Append(','); 116 | sb.Append(getEntity(i).getString()); 117 | } 118 | if (size < rows()) 119 | { 120 | sb.Append(",..."); 121 | } 122 | sb.Append(")"); 123 | return sb.ToString(); 124 | } 125 | 126 | public override Type getElementClass() 127 | { 128 | return typeof(IEntity); 129 | } 130 | 131 | protected internal override void writeVectorToOutputStream(ExtendedDataOutput @out) 132 | { 133 | foreach (IEntity value in values) 134 | { 135 | value.write(@out); 136 | } 137 | } 138 | 139 | public override void set(int index, string value) 140 | { 141 | values[index] = new BasicString(value); 142 | } 143 | 144 | public override object getList() 145 | { 146 | return values.ToList(); 147 | } 148 | 149 | public override void add(object value) 150 | { 151 | throw new NotImplementedException(); 152 | } 153 | 154 | public override void addRange(object list) 155 | { 156 | throw new NotImplementedException(); 157 | } 158 | 159 | public override IVector getSubVector(int[] indices) 160 | { 161 | int length = indices.Length; 162 | IEntity[] sub = new IEntity[length]; 163 | for (int i = 0; i < length; ++i) 164 | sub[i] = values[indices[i]]; 165 | return new BasicAnyVector(sub); 166 | } 167 | 168 | public override int asof(IScalar value) 169 | { 170 | throw new Exception("BasicAnyVector.asof not supported."); 171 | } 172 | 173 | public override void deserialize(int start, int count, ExtendedDataInput @in) 174 | { 175 | throw new NotImplementedException(); 176 | } 177 | 178 | public override void serialize(int start, int count, ExtendedDataOutput @out) 179 | { 180 | throw new NotImplementedException(); 181 | } 182 | 183 | public override int getUnitLength() 184 | { 185 | throw new NotImplementedException(); 186 | } 187 | 188 | public override int serialize(int start, int count, int offect, out int numElement, out int parition, ByteBuffer @out) 189 | { 190 | throw new NotImplementedException(); 191 | } 192 | 193 | public override void append(IScalar value) 194 | { 195 | values.Add(value); 196 | } 197 | 198 | public override void append(IVector value) 199 | { 200 | values.Add(value); 201 | } 202 | 203 | public void append(IEntity value) 204 | { 205 | values.Add(value); 206 | } 207 | 208 | public override IEntity getEntity(int index) 209 | { 210 | return values[index]; 211 | } 212 | 213 | public override int getExtraParamForType() 214 | { 215 | throw new NotImplementedException(); 216 | } 217 | 218 | public override int hashBucket(int index, int buckets) 219 | { 220 | throw new NotImplementedException(); 221 | } 222 | } 223 | 224 | } -------------------------------------------------------------------------------- /src/data/BasicBooleanVector.cs: -------------------------------------------------------------------------------- 1 | using dolphindb.io; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | 6 | namespace dolphindb.data 7 | { 8 | 9 | 10 | public class BasicBooleanVector : AbstractVector 11 | { 12 | private List values; 13 | 14 | public BasicBooleanVector(int size) : this(DATA_FORM.DF_VECTOR, size) 15 | { 16 | } 17 | 18 | public BasicBooleanVector(IList list) : base(DATA_FORM.DF_VECTOR) 19 | { 20 | if (list != null) 21 | { 22 | values = list.Where(x => x != null).Cast().ToList(); 23 | //values = new byte[list.Count]; 24 | //for (int i = 0; i < list.Count; ++i) 25 | //{ 26 | // values[i] = list[i].Value; 27 | //} 28 | } 29 | } 30 | 31 | public BasicBooleanVector(byte[] array) : base(DATA_FORM.DF_VECTOR) 32 | { 33 | values = new List(array.Length); 34 | values.AddRange(array); 35 | //array.Clone() as byte[]; 36 | } 37 | 38 | protected internal BasicBooleanVector(DATA_FORM df, int size) : base(df) 39 | { 40 | 41 | values = new List(size); 42 | values.AddRange(new byte[size]); 43 | } 44 | 45 | protected internal BasicBooleanVector(DATA_FORM df, ExtendedDataInput @in) : base(df) 46 | { 47 | int rows = @in.readInt(); 48 | int cols = @in.readInt(); 49 | int size = rows * cols; 50 | values = new List(size); 51 | values.AddRange(new byte[size]); 52 | for (int i = 0; i < size; ++i) 53 | { 54 | values[i] = @in.readByte(); 55 | } 56 | } 57 | 58 | public override IScalar get(int index) 59 | { 60 | return new BasicBoolean(values[index]); 61 | } 62 | 63 | public virtual bool getBoolean(int index) 64 | { 65 | return values[index] != 0; 66 | } 67 | 68 | public override void set(int index, IScalar value) 69 | { 70 | if(value.getNumber()==null) 71 | values[index] = (byte)0; 72 | else 73 | { 74 | values[index] = value.getNumber().byteValue(); 75 | } 76 | } 77 | 78 | public virtual void setBoolean(int index, bool value) 79 | { 80 | values[index] = value ? (byte)1 : (byte)0; 81 | } 82 | 83 | public override bool isNull(int index) 84 | { 85 | return values[index] == 128; 86 | } 87 | 88 | public override void setNull(int index) 89 | { 90 | values[index] = 128; 91 | } 92 | 93 | public override DATA_CATEGORY getDataCategory() 94 | { 95 | return DATA_CATEGORY.LOGICAL; 96 | } 97 | 98 | public override DATA_TYPE getDataType() 99 | { 100 | return DATA_TYPE.DT_BOOL; 101 | } 102 | 103 | public override Type getElementClass() 104 | { 105 | return typeof(BasicBoolean); 106 | } 107 | 108 | public override int rows() 109 | { 110 | return values.Count; 111 | } 112 | 113 | protected internal override void writeVectorToOutputStream(ExtendedDataOutput @out) 114 | { 115 | @out.write(values.ToArray()); 116 | } 117 | 118 | public override void set(int index, string value) 119 | { 120 | bool v1; 121 | long v2; 122 | if (bool.TryParse(value, out v1)) 123 | { 124 | values[index] = v1 ? (byte)1 : (byte)0; 125 | }else if(long.TryParse(value, out v2)) 126 | { 127 | values[index] = v2 > 0 ? (byte)1 : (byte)0; 128 | } 129 | else 130 | { 131 | values[index] = (byte)0; 132 | } 133 | } 134 | 135 | public override void add(object value) 136 | { 137 | values.Add(Convert.ToByte(value)); 138 | } 139 | 140 | public override void addRange(object list) 141 | { 142 | List data = (List)list; 143 | values.AddRange(data); 144 | } 145 | 146 | public override IVector getSubVector(int[] indices) 147 | { 148 | int length = indices.Length; 149 | byte[] sub = new byte[length]; 150 | for (int i = 0; i < length; ++i) 151 | sub[i] = values[indices[i]]; 152 | return new BasicBooleanVector(sub); 153 | } 154 | 155 | public override int asof(IScalar value) 156 | { 157 | throw new Exception("BasicBooleanVector.asof not supported."); 158 | } 159 | 160 | public override void deserialize(int start, int count, ExtendedDataInput @in) 161 | { 162 | if(start + count > values.Count) 163 | { 164 | values.AddRange(new byte[start + count - values.Count]); 165 | } 166 | for (int i = 0; i < count; ++i) 167 | { 168 | values[start + i] = @in.readByte(); 169 | } 170 | } 171 | 172 | public override void serialize(int start, int count, ExtendedDataOutput @out) 173 | { 174 | for (int i = 0; i < count; ++i) 175 | { 176 | @out.writeByte(values[start + i]); 177 | } 178 | } 179 | 180 | public override int getUnitLength() 181 | { 182 | return 1; 183 | } 184 | 185 | public override int serialize(int indexStart, int offect, int targetNumElement, out int numElement, out int partial, ByteBuffer @out) 186 | { 187 | targetNumElement = Math.Min((@out.remain() / getUnitLength()), targetNumElement); 188 | for (int i = 0; i < targetNumElement; ++i) 189 | { 190 | @out.WriteByte(values[indexStart + i]); 191 | } 192 | numElement = targetNumElement; 193 | partial = 0; 194 | return targetNumElement; 195 | } 196 | 197 | public override void append(IScalar value) 198 | { 199 | values.Add(((BasicBoolean)value).getByte()); 200 | } 201 | 202 | public override void append(IVector value) 203 | { 204 | values.AddRange(((BasicBooleanVector)value).getdataArray()); 205 | } 206 | 207 | 208 | public List getdataArray() 209 | { 210 | return values; 211 | } 212 | 213 | public override IEntity getEntity(int index) 214 | { 215 | return new BasicBoolean(values[index]); 216 | } 217 | 218 | public override int hashBucket(int index, int buckets) 219 | { 220 | throw new NotImplementedException(); 221 | } 222 | } 223 | 224 | } -------------------------------------------------------------------------------- /src/data/BasicByteVector.cs: -------------------------------------------------------------------------------- 1 | using dolphindb.io; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | 6 | namespace dolphindb.data 7 | { 8 | public class BasicByteVector : AbstractVector 9 | { 10 | private List values; 11 | 12 | public BasicByteVector(int size) : this(DATA_FORM.DF_VECTOR, size) 13 | { 14 | } 15 | 16 | public BasicByteVector(IList list) : base(DATA_FORM.DF_VECTOR) 17 | { 18 | if (list != null) 19 | { 20 | values = list.Where(x => x != null).Cast().ToList(); 21 | //values = new byte[list.Count]; 22 | //for (int i = 0; i < list.Count; ++i) 23 | //{ 24 | // values[i] = list[i].Value; 25 | //} 26 | } 27 | } 28 | 29 | public BasicByteVector(byte[] array) : base(DATA_FORM.DF_VECTOR) 30 | { 31 | values = new List(array.Length); 32 | values.AddRange(array); 33 | //values = array.Clone() as byte[]; 34 | } 35 | protected internal BasicByteVector(DATA_FORM df, int size) : base(df) 36 | { 37 | 38 | values = new List(size); 39 | values.AddRange(new byte[size]); 40 | } 41 | 42 | protected internal BasicByteVector(DATA_FORM df, ExtendedDataInput @in) : base(df) 43 | { 44 | int rows = @in.readInt(); 45 | int cols = @in.readInt(); 46 | int size = rows * cols; 47 | values = new List(size); 48 | values.AddRange(new byte[size]); 49 | for (int i = 0; i < size; ++i) 50 | { 51 | values[i] = @in.readByte(); 52 | } 53 | } 54 | 55 | public override IScalar get(int index) 56 | { 57 | return new BasicByte(values[index]); 58 | } 59 | 60 | public virtual byte getByte(int index) 61 | { 62 | return values[index]; 63 | } 64 | 65 | public override void set(int index, IScalar value) 66 | { 67 | if (value.getString()=="") 68 | { 69 | values[index] = (byte)0; 70 | } 71 | else 72 | { 73 | values[index] = value.getNumber().byteValue(); 74 | } 75 | 76 | } 77 | 78 | public virtual void setByte(int index, byte value) 79 | { 80 | values[index] = value; 81 | } 82 | 83 | public override bool isNull(int index) 84 | { 85 | return values[index] == 128; 86 | } 87 | 88 | public override void setNull(int index) 89 | { 90 | values[index] = 128; 91 | } 92 | 93 | public override DATA_CATEGORY getDataCategory() 94 | { 95 | return DATA_CATEGORY.INTEGRAL; 96 | } 97 | 98 | public override DATA_TYPE getDataType() 99 | { 100 | return DATA_TYPE.DT_BYTE; 101 | } 102 | 103 | public override Type getElementClass() 104 | { 105 | return typeof(BasicByte); 106 | } 107 | 108 | public override int rows() 109 | { 110 | return values.Count; 111 | } 112 | 113 | protected internal override void writeVectorToOutputStream(ExtendedDataOutput @out) 114 | { 115 | @out.write(values.ToArray()); 116 | } 117 | 118 | public override object getList() 119 | { 120 | return values; 121 | } 122 | 123 | public override void set(int index, string value) 124 | { 125 | byte v; 126 | if (byte.TryParse(value, out v)) 127 | { 128 | values[index] = v; 129 | } 130 | else 131 | { 132 | setNull(index); 133 | } 134 | } 135 | 136 | public override void add(object value) 137 | { 138 | values.Add(Convert.ToByte(value)); 139 | } 140 | 141 | public override void addRange(object list) 142 | { 143 | List data = (List)list; 144 | values.AddRange(data); 145 | } 146 | 147 | public override int hashBucket(int index, int buckets) 148 | { 149 | int value = values[index]; 150 | if (value > 0) 151 | return value % buckets; 152 | else 153 | return -1; 154 | } 155 | 156 | public override IVector getSubVector(int[] indices) 157 | { 158 | int length = indices.Length; 159 | byte[] sub = new byte[length]; 160 | for (int i = 0; i < length; ++i) 161 | sub[i] = values[indices[i]]; 162 | return new BasicByteVector(sub); 163 | } 164 | 165 | 166 | public override int asof(IScalar value) 167 | { 168 | byte target; 169 | target = value.getNumber().byteValue(); 170 | 171 | int start = 0; 172 | int end = values.Count - 1; 173 | int mid; 174 | while (start <= end) 175 | { 176 | mid = (start + end) / 2; 177 | if (values[mid] <= target) 178 | start = mid + 1; 179 | else 180 | end = mid - 1; 181 | } 182 | return end; 183 | } 184 | 185 | public override void deserialize(int start, int count, ExtendedDataInput @in) 186 | { 187 | if (start + count > values.Count) 188 | { 189 | values.AddRange(new byte[start + count - values.Count]); 190 | } 191 | for (int i = 0; i < count; ++i) 192 | { 193 | values[start + i] = @in.readByte(); 194 | } 195 | } 196 | 197 | public override void serialize(int start, int count, ExtendedDataOutput @out) 198 | { 199 | for (int i = 0; i < count; ++i) 200 | { 201 | @out.writeByte(values[start + i]); 202 | } 203 | } 204 | 205 | public override int getUnitLength() 206 | { 207 | return 1; 208 | } 209 | 210 | public override int serialize(int indexStart, int offect, int targetNumElement, out int numElement, out int partial, ByteBuffer @out) 211 | { 212 | targetNumElement = Math.Min((@out.remain() / getUnitLength()), targetNumElement); 213 | for (int i = 0; i < targetNumElement; ++i) 214 | { 215 | @out.WriteByte(values[indexStart + i]); 216 | } 217 | numElement = targetNumElement; 218 | partial = 0; 219 | return targetNumElement; 220 | } 221 | 222 | public override void append(IScalar value) 223 | { 224 | values.Add(((BasicByte)value).getValue()); 225 | } 226 | 227 | public override void append(IVector value) 228 | { 229 | values.AddRange(((BasicByteVector)value).getdataArray()); 230 | } 231 | 232 | public List getdataArray() 233 | { 234 | return values; 235 | } 236 | 237 | public override IEntity getEntity(int index) 238 | { 239 | return new BasicByte(values[index]); 240 | } 241 | } 242 | 243 | } -------------------------------------------------------------------------------- /src/data/BasicComplex.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using dolphindb.io; 4 | 5 | namespace dolphindb.data 6 | { 7 | public class BasicComplex : AbstractScalar 8 | { 9 | 10 | protected Double2 value; 11 | 12 | public BasicComplex(double real, double image) 13 | { 14 | value = new Double2(real, image); 15 | } 16 | 17 | public BasicComplex(ExtendedDataInput @in) 18 | { 19 | value = @in.readDouble2(); 20 | } 21 | 22 | public Double2 getDouble2() 23 | { 24 | return value; 25 | } 26 | 27 | 28 | public override bool isNull() 29 | { 30 | return value.isNull(); 31 | } 32 | 33 | 34 | public override void setNull() 35 | { 36 | value = new Double2(-double.MaxValue, -double.MaxValue); 37 | } 38 | 39 | public double getReal() { 40 | return value.x; 41 | } 42 | 43 | public double getImage(){ 44 | return value.y; 45 | } 46 | 47 | public override Number getNumber() 48 | { 49 | throw new Exception("Imcompatible data type"); 50 | } 51 | 52 | public override object getObject() 53 | { 54 | throw new NotImplementedException(); 55 | } 56 | 57 | public override void setObject(object value) 58 | { 59 | throw new NotImplementedException(); 60 | } 61 | public override Object getTemporal() 62 | { 63 | throw new Exception("Imcompatible data type"); 64 | } 65 | 66 | public override DATA_CATEGORY getDataCategory() 67 | { 68 | return DATA_CATEGORY.BINARY; 69 | } 70 | public override DATA_TYPE getDataType() 71 | { 72 | return DATA_TYPE.DT_COMPLEX; 73 | } 74 | 75 | public override String getString() 76 | { 77 | if (isNull()) 78 | { 79 | return ""; 80 | } 81 | else 82 | { 83 | return value.x.ToString() + (value.y >= 0 ? "+" : "") + value.y.ToString() + "i"; 84 | } 85 | } 86 | 87 | public bool equals(Object o) 88 | { 89 | if (!(o is BasicComplex) || o == null) 90 | return false; 91 | else 92 | return value.equals(((BasicComplex)o).value); 93 | } 94 | 95 | public override void writeScalarToOutputStream(ExtendedDataOutput @out) 96 | { 97 | @out.writeDouble2(value); 98 | } 99 | 100 | public Double2 getValue() 101 | { 102 | return value; 103 | } 104 | 105 | public override int hashBucket(int buckets) 106 | { 107 | return value.hashBucket(buckets); 108 | } 109 | 110 | public override bool Equals(object o) 111 | { 112 | if (!(o is BasicComplex) || o == null) 113 | { 114 | return false; 115 | } 116 | else 117 | { 118 | return getValue().equals(((BasicComplex)o).getValue()); 119 | } 120 | } 121 | 122 | public override int GetHashCode() 123 | { 124 | return value.GetHashCode(); 125 | } 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /src/data/BasicComplexMatrix.cs: -------------------------------------------------------------------------------- 1 | using dolphindb.io; 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace dolphindb.data 6 | { 7 | 8 | public class BasicComplexMatrix : AbstractMatrix 9 | { 10 | private BasicComplexVector value; 11 | 12 | public BasicComplexMatrix(int rows, int columns) : base(rows, columns) 13 | { 14 | this.value = new BasicComplexVector(rows * columns); 15 | } 16 | 17 | public BasicComplexMatrix(int rows, int columns, IList list) : base(rows, columns) 18 | { 19 | List tmp = new List(); 20 | foreach (Double2[] data in list) 21 | { 22 | tmp.AddRange(data); 23 | } 24 | if (tmp.Count != rows * columns) 25 | { 26 | throw new Exception("the total size of list must be equal to rows * columns"); 27 | } 28 | value = new BasicComplexVector(tmp); 29 | } 30 | 31 | public BasicComplexMatrix(ExtendedDataInput @in) : base(@in) 32 | { 33 | } 34 | 35 | public override bool isNull(int row, int column) 36 | { 37 | return value.isNull(getIndex(row, column)); 38 | } 39 | 40 | public override void setNull(int row, int column) 41 | { 42 | value.setNull(getIndex(row, column)); 43 | } 44 | 45 | public override IScalar get(int row, int column) 46 | { 47 | return this.value.get(getIndex(row, column)); 48 | } 49 | 50 | public void set(int row, int column, IScalar value) 51 | { 52 | this.value.set(getIndex(row, column), value); 53 | } 54 | 55 | public override DATA_CATEGORY getDataCategory() 56 | { 57 | return DATA_CATEGORY.BINARY; 58 | } 59 | 60 | public override DATA_TYPE getDataType() 61 | { 62 | return DATA_TYPE.DT_COMPLEX; 63 | } 64 | 65 | public override Type getElementClass() 66 | { 67 | return typeof(BasicComplex); 68 | } 69 | 70 | protected internal override void readMatrixFromInputStream(int rows, int columns, ExtendedDataInput @in) 71 | { 72 | this.value = new BasicComplexVector(rows * columns); 73 | value.deserialize(0, rows * columns, @in); 74 | } 75 | 76 | protected internal override void writeVectorToOutputStream(ExtendedDataOutput @out) 77 | { 78 | this.value.writeVectorToOutputStream(@out); 79 | } 80 | } 81 | 82 | } -------------------------------------------------------------------------------- /src/data/BasicComplexVector.cs: -------------------------------------------------------------------------------- 1 |  2 | using dolphindb.io; 3 | using dolphindb.data; 4 | using System.Collections.Generic; 5 | using System; 6 | 7 | public class BasicComplexVector : BasicDouble2Vector 8 | { 9 | public BasicComplexVector(int size) : this(DATA_FORM.DF_VECTOR, size) { } 10 | public BasicComplexVector(List list) : base(list) { } 11 | 12 | public BasicComplexVector(Double2[] array) : base(array) { } 13 | internal BasicComplexVector(DATA_FORM df, int size) : base(df, size) { } 14 | 15 | internal BasicComplexVector(DATA_FORM df, ExtendedDataInput @in) : base(df, @in) { } 16 | 17 | public override IScalar get(int index) 18 | { 19 | return new BasicComplex(values[index].x, values[index].y); 20 | } 21 | 22 | public override void set(int index, IScalar value) 23 | { 24 | if (value.getDataType() == DATA_TYPE.DT_COMPLEX) 25 | { 26 | values[index] = new Double2(((BasicComplex)value).getReal(), ((BasicComplex)value).getImage()); 27 | } 28 | else 29 | throw new Exception("The value must be a complex scalar. "); 30 | } 31 | 32 | public void setComplex(int index, double real, double image) 33 | { 34 | values[index] = new Double2(real, image); 35 | } 36 | 37 | public override DATA_TYPE getDataType() 38 | { 39 | return DATA_TYPE.DT_COMPLEX; 40 | } 41 | 42 | 43 | public override Type getElementClass() 44 | { 45 | return typeof(BasicComplex); 46 | } 47 | 48 | public override IVector getSubVector(int[] indices) 49 | { 50 | int length = indices.Length; 51 | Double2[] sub = new Double2[length]; 52 | for (int i = 0; i < length; ++i) 53 | sub[i] = values[indices[i]]; 54 | return new BasicComplexVector(sub); 55 | } 56 | 57 | public override void append(IScalar value) 58 | { 59 | values.Add(((BasicComplex)value).getValue()); 60 | } 61 | 62 | public override void append(IVector value) 63 | { 64 | values.AddRange(((BasicComplexVector)value).getDataArray()); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/data/BasicDecimal32.cs: -------------------------------------------------------------------------------- 1 | using dolphindb.data; 2 | using dolphindb.io; 3 | using Microsoft.VisualBasic; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Diagnostics.CodeAnalysis; 7 | using System.Numerics; 8 | using System.Text; 9 | 10 | namespace dolphindb.data 11 | { 12 | public class BasicDecimal32 : AbstractScalar 13 | { 14 | private int scale_ = 0;//Decimal precision 15 | private int value_; //covert decimal to int for saving 16 | 17 | public BasicDecimal32(string data, int scale = -1) 18 | { 19 | if(scale == -1) 20 | { 21 | value_ = parseString(data, ref scale_, false); 22 | } 23 | else 24 | { 25 | scale_ = scale; 26 | value_ = parseString(data, ref scale); 27 | } 28 | } 29 | 30 | public BasicDecimal32(decimal data, int scale) 31 | { 32 | checkScale(scale); 33 | try 34 | { 35 | data = checked(pow10(scale) * data); 36 | scale_ = scale; 37 | value_ = checked((int)Math.Round(data)); 38 | }catch(OverflowException) 39 | { 40 | throw new OverflowException("Decimal math overflow!"); 41 | } 42 | } 43 | 44 | internal BasicDecimal32(ExtendedDataInput @input, int scale = -1) 45 | { 46 | scale_ = scale == -1 ? @input.readInt() : scale; 47 | value_ = @input.readInt(); 48 | } 49 | 50 | internal BasicDecimal32(int rawData, int scale) 51 | { 52 | checkScale(scale); 53 | value_ = rawData; 54 | scale_ = scale; 55 | } 56 | 57 | 58 | public override DATA_CATEGORY getDataCategory() 59 | { 60 | return DATA_CATEGORY.DENARY; 61 | } 62 | 63 | public override string ToString() 64 | { 65 | return getString(); 66 | } 67 | public override DATA_TYPE getDataType() 68 | { 69 | return DATA_TYPE.DT_DECIMAL32; 70 | } 71 | 72 | public override object getObject() 73 | { 74 | return getString(); 75 | } 76 | 77 | public decimal getDecimalValue() 78 | { 79 | decimal tmp = value_; 80 | return tmp / pow10(scale_); 81 | } 82 | 83 | public override string getString() 84 | { 85 | if (scale_ == 0 && (!isNull())) 86 | return value_.ToString(); 87 | else if (isNull()) 88 | return ""; 89 | else 90 | { 91 | StringBuilder sb = new StringBuilder(); 92 | if (value_ < 0) 93 | sb.Append("-"); 94 | int val = value_; 95 | if (val < 0) val *= -1; 96 | 97 | int pow = pow10(scale_); 98 | int begin = val / (int)pow; 99 | sb.Append(begin.ToString()); 100 | if (scale_ > 0) 101 | { 102 | sb.Append("."); 103 | int after = val % pow; 104 | int zeroBeginSize = pow.ToString().Length - after.ToString().Length - 1; 105 | for (int i = 0; i < zeroBeginSize; ++i) sb.Append('0'); 106 | sb.Append(after.ToString()); 107 | int zeroSize = scale_ - after.ToString().Length - zeroBeginSize; 108 | for (int i = 0; i < zeroSize; ++i) sb.Append('0'); 109 | } 110 | return sb.ToString(); 111 | } 112 | } 113 | 114 | public override bool isNull() 115 | { 116 | return value_ == int.MinValue; 117 | } 118 | 119 | public override void setNull() 120 | { 121 | value_ = int.MinValue; 122 | } 123 | 124 | public override Number getNumber() 125 | { 126 | return new Number(getDecimalValue()); 127 | } 128 | 129 | public override int getScale() 130 | { 131 | return scale_; 132 | } 133 | 134 | public int getRawData() 135 | { 136 | return value_; 137 | } 138 | 139 | public void setRawData(int rawData) 140 | { 141 | value_ = rawData; 142 | } 143 | 144 | public override int hashBucket(int buckets) 145 | { 146 | throw new NotImplementedException(); 147 | } 148 | 149 | public override void setObject(object value) 150 | { 151 | if (typeof(string) == value.GetType()) 152 | { 153 | value_ = parseString((string)value, ref scale_, true); 154 | } 155 | else 156 | { 157 | throw new ArgumentException("the type of value must be string."); 158 | } 159 | } 160 | 161 | public override void writeScalarToOutputStream(ExtendedDataOutput @out) 162 | { 163 | @out.writeInt(value_); 164 | } 165 | 166 | public override bool Equals(object o) 167 | { 168 | if (!(o is BasicDecimal32) || o == null) 169 | { 170 | return false; 171 | } 172 | else 173 | { 174 | BasicDecimal32 obj = (BasicDecimal32)o; 175 | return value_ == obj.value_ && scale_ == obj.scale_; 176 | } 177 | } 178 | 179 | internal static void checkScale(int scale) 180 | { 181 | if (scale < 0 || scale > 9) 182 | { 183 | throw new Exception("Scale " + scale + " is out of bounds, it must be in [0,9]."); 184 | } 185 | } 186 | 187 | internal static int pow10(int scale) // TODO: Improve performance 188 | { 189 | if (scale == 0) return 1; 190 | int data = 1; 191 | for(int i = 0; i < scale; ++i) 192 | { 193 | try 194 | { 195 | data = checked(data * 10); 196 | } catch (OverflowException) 197 | { 198 | throw new Exception("Decimal math overflow!"); 199 | } 200 | } 201 | return data; 202 | } 203 | 204 | internal static int parseString(string data, ref int scale, bool scale_work=true) 205 | { 206 | if(scale_work) checkScale(scale); 207 | if (data == "") 208 | { 209 | if (!scale_work) 210 | { 211 | throw new Exception("When the data is an empty string, the scale must be set. "); 212 | } 213 | else 214 | { 215 | return int.MinValue; 216 | } 217 | } 218 | BigInteger tmp = BasicDecimal128.parseString(data, ref scale, scale_work); 219 | if (tmp > int.MaxValue || tmp < int.MinValue) 220 | { 221 | throw new Exception("Decimal math overflow!"); 222 | } 223 | return ((int)tmp); 224 | } 225 | 226 | public override int GetHashCode() 227 | { 228 | int hashCode = -230681975; 229 | hashCode = hashCode * -1521134295 + scale_.GetHashCode(); 230 | hashCode = hashCode * -1521134295 + value_.GetHashCode(); 231 | return hashCode; 232 | } 233 | 234 | public override int getExtraParamForType(){ 235 | return scale_; 236 | } 237 | } 238 | } 239 | -------------------------------------------------------------------------------- /src/data/BasicDecimal64.cs: -------------------------------------------------------------------------------- 1 | using dolphindb.data; 2 | using dolphindb.io; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Diagnostics.CodeAnalysis; 6 | using System.Numerics; 7 | using System.Text; 8 | 9 | namespace dolphindb.data 10 | { 11 | public class BasicDecimal64 : AbstractScalar 12 | { 13 | private int scale_ = 0;//Decimal precision 14 | private long value_; //covert decimal to int for saving 15 | 16 | internal BasicDecimal64(ExtendedDataInput @input, int scale = -1) 17 | { 18 | scale_ = scale == -1 ? @input.readInt() : scale; 19 | value_ = @input.readLong(); 20 | } 21 | 22 | public BasicDecimal64(string data, int scale = -1) 23 | { 24 | if (scale == -1) 25 | { 26 | value_ = parseString(data, ref scale_, false); 27 | } 28 | else 29 | { 30 | scale_ = scale; 31 | value_ = parseString(data, ref scale); 32 | } 33 | } 34 | 35 | public BasicDecimal64(decimal data, int scale) 36 | { 37 | checkScale(scale); 38 | try 39 | { 40 | data = checked(pow10(scale) * data); 41 | scale_ = scale; 42 | value_ = checked((long)Math.Round(data)); 43 | } 44 | catch (OverflowException) 45 | { 46 | throw new OverflowException("Decimal math overflow!"); 47 | } 48 | } 49 | 50 | internal BasicDecimal64(long rawData, int scale) 51 | { 52 | checkScale(scale); 53 | value_ = rawData; 54 | scale_ = scale; 55 | } 56 | 57 | public override DATA_CATEGORY getDataCategory() 58 | { 59 | return DATA_CATEGORY.DENARY; 60 | } 61 | 62 | public override string ToString() 63 | { 64 | return getString(); 65 | } 66 | public override DATA_TYPE getDataType() 67 | { 68 | return DATA_TYPE.DT_DECIMAL64; 69 | } 70 | 71 | public override object getObject() 72 | { 73 | return getString(); 74 | } 75 | 76 | public virtual decimal getDecimalValue() 77 | { 78 | decimal tmp = value_; 79 | return tmp / pow10(scale_); 80 | } 81 | 82 | public override string getString() 83 | { 84 | if (scale_ == 0 && (!isNull())) 85 | return value_.ToString(); 86 | else if (isNull()) 87 | return ""; 88 | else 89 | { 90 | StringBuilder sb = new StringBuilder(); 91 | if (value_ < 0) 92 | sb.Append("-"); 93 | long val = value_; 94 | if (val < 0) val *= -1; 95 | 96 | long pow = pow10(scale_); 97 | long begin = val / pow; 98 | sb.Append(begin.ToString()); 99 | if (scale_ > 0) 100 | { 101 | sb.Append("."); 102 | long after = val % pow; 103 | int zeroBeginSize = pow.ToString().Length - after.ToString().Length - 1; 104 | for (int i = 0; i < zeroBeginSize; ++i) sb.Append('0'); 105 | sb.Append(after.ToString()); 106 | int zeroSize = scale_ - after.ToString().Length - zeroBeginSize; 107 | for (int i = 0; i < zeroSize; ++i) sb.Append('0'); 108 | } 109 | return sb.ToString(); 110 | } 111 | } 112 | 113 | public override bool isNull() 114 | { 115 | return value_ == long.MinValue; 116 | } 117 | 118 | public override void setNull() 119 | { 120 | value_ = long.MinValue; 121 | } 122 | 123 | public override Number getNumber() 124 | { 125 | return new Number(getDecimalValue()); 126 | } 127 | 128 | public override int getScale() 129 | { 130 | return scale_; 131 | } 132 | 133 | public long getRawData() 134 | { 135 | return value_; 136 | } 137 | 138 | public void setRawData(long rawData) 139 | { 140 | value_ = rawData; 141 | } 142 | 143 | public override int hashBucket(int buckets) 144 | { 145 | throw new NotImplementedException(); 146 | } 147 | 148 | public override void setObject(object value) 149 | { 150 | if (typeof(string) == value.GetType()) 151 | { 152 | value_ = parseString((string)value, ref scale_, true); 153 | } 154 | else 155 | { 156 | throw new ArgumentException("the type of value must be string."); 157 | } 158 | } 159 | 160 | public override void writeScalarToOutputStream(ExtendedDataOutput @out) 161 | { 162 | @out.writeLong(value_); 163 | } 164 | 165 | public override bool Equals(object o) 166 | { 167 | if (!(o is BasicDecimal64) || o == null) 168 | { 169 | return false; 170 | } 171 | else 172 | { 173 | BasicDecimal64 obj = (BasicDecimal64)o; 174 | return value_ == obj.value_ && scale_ == obj.scale_; 175 | } 176 | } 177 | 178 | internal static void checkScale(int scale) 179 | { 180 | if (scale < 0 || scale > 18) 181 | { 182 | throw new Exception("Scale " + scale + " is out of bounds, it must be in [0,18]."); 183 | } 184 | } 185 | 186 | internal static long pow10(int scale) // TODO: Improve performance 187 | { 188 | if (scale == 0) return 1; 189 | long data = 1; 190 | for (int i = 0; i < scale; ++i) 191 | { 192 | try 193 | { 194 | data = checked(data * 10); 195 | } 196 | catch (OverflowException) 197 | { 198 | throw new Exception("Decimal math overflow!"); 199 | } 200 | } 201 | return data; 202 | } 203 | 204 | internal static long parseString(string data, ref int scale, bool scale_work=true) 205 | { 206 | if (scale_work) checkScale(scale); 207 | if (data == "") 208 | { 209 | if (!scale_work) 210 | { 211 | throw new Exception("When the data is an empty string, the scale must be set. "); 212 | } 213 | else 214 | { 215 | return long.MinValue; 216 | } 217 | } 218 | BigInteger tmp = BasicDecimal128.parseString(data, ref scale, scale_work); 219 | if(tmp > long.MaxValue || tmp < long.MinValue) 220 | { 221 | throw new Exception("Decimal math overflow!"); 222 | } 223 | return ((long)tmp); 224 | } 225 | 226 | public override int GetHashCode() 227 | { 228 | int hashCode = -230681975; 229 | hashCode = hashCode * -1521134295 + scale_.GetHashCode(); 230 | hashCode = hashCode * -1521134295 + value_.GetHashCode(); 231 | return hashCode; 232 | } 233 | 234 | public override int getExtraParamForType(){ 235 | return scale_; 236 | } 237 | } 238 | } 239 | -------------------------------------------------------------------------------- /src/data/BasicDouble2Vector.cs: -------------------------------------------------------------------------------- 1 |  2 | using dolphindb.io; 3 | using dolphindb.data; 4 | using System.Collections.Generic; 5 | using System; 6 | 7 | public abstract class BasicDouble2Vector : AbstractVector 8 | { 9 | 10 | protected List values; 11 | internal BasicDouble2Vector(int size) : this(DATA_FORM.DF_VECTOR, size) 12 | { 13 | } 14 | 15 | internal BasicDouble2Vector(List list) : base(DATA_FORM.DF_VECTOR) 16 | { 17 | if (list != null) 18 | { 19 | values = new List(); 20 | values.AddRange(new Double2[list.Count]); 21 | for (int i = 0; i < list.Count; ++i) 22 | values[i] = list[i]; 23 | } 24 | } 25 | 26 | internal BasicDouble2Vector(Double2[] array) : base(DATA_FORM.DF_VECTOR) 27 | { 28 | values = new List(); 29 | values.AddRange(array); 30 | } 31 | 32 | internal BasicDouble2Vector(DATA_FORM df, int size) : base(df) 33 | { 34 | 35 | values = new List(); 36 | values.AddRange(new Double2[size]); 37 | for (int i = 0; i < size; ++i) 38 | values[i] = new Double2(-double.MaxValue, -double.MaxValue); 39 | } 40 | 41 | internal BasicDouble2Vector(DATA_FORM df, ExtendedDataInput @in) : base(df) 42 | { 43 | int rows = @in.readInt(); 44 | int cols = @in.readInt(); 45 | int size = rows * cols; 46 | values = new List(); 47 | values.AddRange(new Double2[size]); 48 | int totalBytes = size * 16, off = 0; 49 | bool littleEndian = @in.isLittleEndian(); 50 | byte[] buffer = buf.Value; 51 | while (off < totalBytes) 52 | { 53 | int len = System.Math.Min(BUF_SIZE, totalBytes - off); 54 | @in.readFully(buffer, 0, len); 55 | int start = off / 16, end = len / 16; 56 | Byte[] dst = new Byte[len]; 57 | Buffer.BlockCopy(buffer, 0, dst, 0, len); 58 | if (!littleEndian) 59 | Array.Reverse(dst); 60 | if (littleEndian) 61 | { 62 | for (int i = 0; i < end; i++) 63 | { 64 | double real = BitConverter.ToDouble(dst, i * 16); 65 | double image = BitConverter.ToDouble(dst, i * 16 + 8); 66 | values[i + start] = new Double2(real, image); 67 | } 68 | } 69 | else 70 | { 71 | for (int i = 0; i < end; i++) 72 | { 73 | double image = BitConverter.ToDouble(dst, i * 16); 74 | double real = BitConverter.ToDouble(dst, i * 16 + 8); 75 | values[i + start] = new Double2(real, image); 76 | } 77 | } 78 | off += len; 79 | } 80 | } 81 | 82 | public Double2 getDouble2(int index) 83 | { 84 | return values[index]; 85 | } 86 | 87 | public override bool isNull(int index) 88 | { 89 | return values[index].isNull(); 90 | } 91 | 92 | 93 | public override void setNull(int index) 94 | { 95 | values[index] = new Double2(-double.MaxValue, -double.MaxValue); 96 | } 97 | 98 | 99 | public override DATA_CATEGORY getDataCategory() 100 | { 101 | return DATA_CATEGORY.BINARY; 102 | } 103 | 104 | 105 | public override int rows() 106 | { 107 | return values.Count; 108 | } 109 | 110 | protected internal override void writeVectorToOutputStream(ExtendedDataOutput @out) 111 | { 112 | @out.writeDouble2Array(values.ToArray()); 113 | } 114 | 115 | public override void set(int index, string value) 116 | { 117 | throw new NotImplementedException(); 118 | } 119 | 120 | public override void add(object value) 121 | { 122 | throw new NotImplementedException(); 123 | } 124 | 125 | public override void addRange(object list) 126 | { 127 | throw new NotImplementedException(); 128 | } 129 | 130 | public override int hashBucket(int index, int buckets) 131 | { 132 | return values[index].hashBucket(buckets); 133 | } 134 | 135 | protected Double2[] getSubArray(int[] indices) 136 | { 137 | int length = indices.Length; 138 | Double2[] sub = new Double2[length]; 139 | for (int i = 0; i < length; ++i) 140 | sub[i] = values[indices[i]]; 141 | return sub; 142 | } 143 | 144 | public override int asof(IScalar value) 145 | { 146 | throw new Exception("BasicDouble2Vector.asof not supported."); 147 | } 148 | 149 | public override void deserialize(int start, int count, ExtendedDataInput @in) 150 | { 151 | if (start + count > values.Count) 152 | { 153 | values.AddRange(new Double2[start + count - values.Count]); 154 | } 155 | int totalBytes = count * 16, off = 0; 156 | bool littleEndian = @in.isLittleEndian(); 157 | byte[] buffer = buf.Value; 158 | while (off < totalBytes) 159 | { 160 | int len = System.Math.Min(BUF_SIZE, totalBytes - off); 161 | @in.readFully(buffer, 0, len); 162 | int subStart = off / 16, end = len / 16; 163 | Byte[] dst = new Byte[len]; 164 | Buffer.BlockCopy(buffer, 0, dst, 0, len); 165 | if (!littleEndian) 166 | Array.Reverse(dst); 167 | if (littleEndian) 168 | { 169 | for (int i = 0; i < end; i++) 170 | { 171 | double real = BitConverter.ToDouble(dst, i * 16); 172 | double image = BitConverter.ToDouble(dst, i * 16 + 8); 173 | values[i + subStart + start] = new Double2(real, image); 174 | } 175 | } 176 | else 177 | { 178 | for (int i = 0; i < end; i++) 179 | { 180 | double image = BitConverter.ToDouble(dst, i * 16); 181 | double real = BitConverter.ToDouble(dst, i * 16 + 8); 182 | values[i + subStart + start] = new Double2(real, image); 183 | } 184 | } 185 | off += len; 186 | } 187 | } 188 | 189 | public override void serialize(int start, int count, ExtendedDataOutput @out) 190 | { 191 | Double2[] buffer = new Double2[count]; 192 | for (int i = 0; i < count; ++i) 193 | { 194 | buffer[i] = values[i + start]; 195 | } 196 | @out.writeDouble2Array(buffer); 197 | } 198 | 199 | 200 | public override int getUnitLength() 201 | { 202 | return 16; 203 | } 204 | 205 | public override int serialize(int indexStart, int offect, int targetNumElement, out int numElement, out int partial, ByteBuffer @out) 206 | { 207 | targetNumElement = Math.Min((@out.remain() / getUnitLength()), targetNumElement); 208 | if (@out.isLittleEndian) 209 | { 210 | for (int i = 0; i < targetNumElement; ++i) 211 | { 212 | @out.WriteDouble(values[indexStart + i].x); 213 | @out.WriteDouble(values[indexStart + i].y); 214 | } 215 | } 216 | else 217 | { 218 | for (int i = 0; i < targetNumElement; ++i) 219 | { 220 | @out.WriteDouble(values[indexStart + i].y); 221 | @out.WriteDouble(values[indexStart + i].x); 222 | } 223 | } 224 | numElement = targetNumElement; 225 | partial = 0; 226 | return targetNumElement * 16; 227 | } 228 | 229 | public List getDataArray() 230 | { 231 | return values; 232 | } 233 | 234 | public override IEntity getEntity(int index) 235 | { 236 | return get(index); 237 | } 238 | } 239 | -------------------------------------------------------------------------------- /src/data/BasicDoubleVector.cs: -------------------------------------------------------------------------------- 1 | using dolphindb.io; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | namespace dolphindb.data 6 | { 7 | public class BasicDoubleVector : AbstractVector 8 | { 9 | private List values; 10 | 11 | public BasicDoubleVector(int size) : this(DATA_FORM.DF_VECTOR, size) 12 | { 13 | } 14 | 15 | public BasicDoubleVector(IList list) : base(DATA_FORM.DF_VECTOR) 16 | { 17 | if (list != null) 18 | { 19 | values = list.Where(x => x != null).Cast().ToList(); 20 | //values = new double[list.Count]; 21 | //for (int i = 0; i < list.Count; ++i) 22 | //{ 23 | // values[i] = list[i].Value; 24 | //} 25 | } 26 | } 27 | 28 | public BasicDoubleVector(double[] array) : base(DATA_FORM.DF_VECTOR) 29 | { 30 | values = new List(array.Length); 31 | values.AddRange(array); 32 | //values = array.Clone() as double[]; 33 | } 34 | 35 | protected internal BasicDoubleVector(DATA_FORM df, int size) : base(df) 36 | { 37 | values = new List(size); 38 | values.AddRange(new double[size]); 39 | } 40 | 41 | protected internal BasicDoubleVector(DATA_FORM df, ExtendedDataInput @in) : base(df) 42 | { 43 | int rows = @in.readInt(); 44 | int cols = @in.readInt(); 45 | int size = rows * cols; 46 | values = new List(size); 47 | values.AddRange(new double[size]); 48 | for (int i = 0; i < size; ++i) 49 | { 50 | values[i] = @in.readDouble(); 51 | } 52 | } 53 | 54 | public override IScalar get(int index) 55 | { 56 | return new BasicDouble(values[index]); 57 | } 58 | 59 | public virtual double getDouble(int index) 60 | { 61 | return values[index]; 62 | } 63 | 64 | public override void set(int index, IScalar value) 65 | { 66 | if (value.getDataType() == DATA_TYPE.DT_DOUBLE) 67 | { 68 | setDouble(index, ((BasicDouble)value).getValue()); 69 | } 70 | else 71 | throw new Exception("The value must be a double scalar. "); 72 | } 73 | 74 | public virtual void setDouble(int index, double value) 75 | { 76 | values[index] = value; 77 | } 78 | 79 | public override bool isNull(int index) 80 | { 81 | return values[index] == -double.MaxValue; 82 | } 83 | 84 | public override void setNull(int index) 85 | { 86 | values[index] = -double.MaxValue; 87 | } 88 | 89 | public override DATA_CATEGORY getDataCategory() 90 | { 91 | return DATA_CATEGORY.FLOATING; 92 | } 93 | 94 | public override DATA_TYPE getDataType() 95 | { 96 | return DATA_TYPE.DT_DOUBLE; 97 | } 98 | 99 | public override Type getElementClass() 100 | { 101 | return typeof(BasicDouble); 102 | } 103 | 104 | public override int rows() 105 | { 106 | return values.Count; 107 | } 108 | 109 | protected internal override void writeVectorToOutputStream(ExtendedDataOutput @out) 110 | { 111 | @out.writeDoubleArray(values.ToArray()); 112 | } 113 | 114 | public override object getList() 115 | { 116 | return values; 117 | } 118 | 119 | public override void set(int index, string value) 120 | { 121 | double v; 122 | if (double.TryParse(value, out v)) 123 | { 124 | values[index] = v; 125 | } 126 | else 127 | { 128 | setNull(index); 129 | } 130 | } 131 | 132 | public override void add(object value) 133 | { 134 | values.Add(Convert.ToDouble(value)); 135 | } 136 | 137 | public override void addRange(object list) 138 | { 139 | List data = (List)list; 140 | values.AddRange(data); 141 | } 142 | 143 | public override IVector getSubVector(int[] indices) 144 | { 145 | int length = indices.Length; 146 | double[] sub = new double[length]; 147 | for (int i = 0; i < length; ++i) 148 | sub[i] = values[indices[i]]; 149 | return new BasicDoubleVector(sub); 150 | } 151 | 152 | public override int asof(IScalar value) 153 | { 154 | double target; 155 | target = value.getNumber().doubleValue(); 156 | 157 | int start = 0; 158 | int end = values.Count - 1; 159 | int mid; 160 | while (start <= end) 161 | { 162 | mid = (start + end) / 2; 163 | if (values[mid] <= target) 164 | start = mid + 1; 165 | else 166 | end = mid - 1; 167 | } 168 | return end; 169 | } 170 | 171 | public override void deserialize(int start, int count, ExtendedDataInput @in) 172 | { 173 | if (start + count > values.Count) 174 | { 175 | values.AddRange(new double[start + count - values.Count]); 176 | } 177 | for (int i = 0; i < count; ++i) 178 | { 179 | values[start + i] = @in.readDouble(); 180 | } 181 | } 182 | 183 | public override void serialize(int start, int count, ExtendedDataOutput @out) 184 | { 185 | for (int i = 0; i < count; ++i) 186 | { 187 | @out.writeDouble(values[start + i]); 188 | } 189 | } 190 | 191 | public override int getUnitLength() 192 | { 193 | return 8; 194 | } 195 | 196 | public override int serialize(int indexStart, int offect, int targetNumElement, out int numElement, out int partial, ByteBuffer @out) 197 | { 198 | targetNumElement = Math.Min((@out.remain() / getUnitLength()), targetNumElement); 199 | for (int i = 0; i < targetNumElement; ++i) 200 | { 201 | @out.WriteDouble(values[indexStart + i]); 202 | } 203 | numElement = targetNumElement; 204 | partial = 0; 205 | return targetNumElement * 8; 206 | } 207 | 208 | public override void append(IScalar value) 209 | { 210 | values.Add(((BasicDouble)value).getValue()); 211 | } 212 | 213 | public override void append(IVector value) 214 | { 215 | values.AddRange(((BasicDoubleVector)value).getdataArray()); 216 | } 217 | 218 | public List getdataArray() 219 | { 220 | return values; 221 | } 222 | 223 | public override IEntity getEntity(int index) 224 | { 225 | return new BasicDouble(values[index]); 226 | } 227 | 228 | public override int hashBucket(int index, int buckets) 229 | { 230 | throw new NotImplementedException(); 231 | } 232 | } 233 | } -------------------------------------------------------------------------------- /src/data/BasicFloatVector.cs: -------------------------------------------------------------------------------- 1 | using dolphindb.io; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | 6 | namespace dolphindb.data 7 | { 8 | 9 | public class BasicFloatVector : AbstractVector 10 | { 11 | private List values; 12 | 13 | public BasicFloatVector(int size) : this(DATA_FORM.DF_VECTOR, size) 14 | { 15 | } 16 | 17 | public BasicFloatVector(IList list) : base(DATA_FORM.DF_VECTOR) 18 | { 19 | if (list != null) 20 | { 21 | values = list.Where(x => x != null).Cast().ToList(); 22 | //values = new float[list.Count]; 23 | //for (int i = 0; i < list.Count; ++i) 24 | //{ 25 | // values[i] = list[i].Value; 26 | //} 27 | } 28 | } 29 | 30 | public BasicFloatVector(float[] array) : base(DATA_FORM.DF_VECTOR) 31 | { 32 | values = new List(array.Length); 33 | values.AddRange(array); 34 | //values = array.Clone() as float[]; 35 | } 36 | 37 | protected internal BasicFloatVector(DATA_FORM df, int size) : base(df) 38 | { 39 | values = new List(size); 40 | values.AddRange(new float[size]); 41 | } 42 | 43 | protected internal BasicFloatVector(DATA_FORM df, ExtendedDataInput @in) : base(df) 44 | { 45 | int rows = @in.readInt(); 46 | int cols = @in.readInt(); 47 | int size = rows * cols; 48 | values = new List(size); 49 | values.AddRange(new float[size]); 50 | for (int i = 0; i < size; ++i) 51 | { 52 | values[i] = @in.readFloat(); 53 | } 54 | } 55 | 56 | public override IScalar get(int index) 57 | { 58 | return new BasicFloat(values[index]); 59 | } 60 | 61 | public virtual float getFloat(int index) 62 | { 63 | return values[index]; 64 | } 65 | 66 | 67 | public override void set(int index, IScalar value) 68 | { 69 | if (value.getDataType() == DATA_TYPE.DT_FLOAT) 70 | { 71 | setFloat(index, ((BasicFloat)value).getValue()); 72 | } 73 | else 74 | throw new Exception("The value must be a float scalar. "); 75 | } 76 | 77 | public virtual void setFloat(int index, float value) 78 | { 79 | values[index] = value; 80 | } 81 | 82 | public override bool isNull(int index) 83 | { 84 | return values[index] == -float.MaxValue; 85 | } 86 | 87 | public override void setNull(int index) 88 | { 89 | values[index] = -float.MaxValue; 90 | } 91 | 92 | public override DATA_CATEGORY getDataCategory() 93 | { 94 | return DATA_CATEGORY.FLOATING; 95 | } 96 | 97 | public override DATA_TYPE getDataType() 98 | { 99 | return DATA_TYPE.DT_FLOAT; 100 | } 101 | 102 | public override int rows() 103 | { 104 | return values.Count; 105 | } 106 | 107 | public override Type getElementClass() 108 | { 109 | return typeof(BasicFloat); 110 | } 111 | 112 | protected internal override void writeVectorToOutputStream(ExtendedDataOutput @out) 113 | { 114 | @out.writeFloatArray(values.ToArray()); 115 | } 116 | 117 | public override object getList() 118 | { 119 | return values; 120 | } 121 | 122 | public override void set(int index, string value) 123 | { 124 | float v; 125 | if (float.TryParse(value, out v)) 126 | { 127 | values[index] = v; 128 | } 129 | else 130 | { 131 | setNull(index); 132 | } 133 | } 134 | 135 | public override void add(object value) 136 | { 137 | values.Add((float)value); 138 | } 139 | 140 | public override void addRange(object list) 141 | { 142 | List data = (List)list; 143 | values.AddRange(data); 144 | } 145 | 146 | public override IVector getSubVector(int[] indices) 147 | { 148 | int length = indices.Length; 149 | float[] sub = new float[length]; 150 | for (int i = 0; i < length; ++i) 151 | sub[i] = values[indices[i]]; 152 | return new BasicFloatVector(sub); 153 | } 154 | 155 | public override int asof(IScalar value) 156 | { 157 | float target; 158 | target = value.getNumber().floatValue(); 159 | 160 | int start = 0; 161 | int end = values.Count - 1; 162 | int mid; 163 | while (start <= end) 164 | { 165 | mid = (start + end) / 2; 166 | if (values[mid] <= target) 167 | start = mid + 1; 168 | else 169 | end = mid - 1; 170 | } 171 | return end; 172 | } 173 | 174 | public override void deserialize(int start, int count, ExtendedDataInput @in) 175 | { 176 | if (start + count > values.Count) 177 | { 178 | values.AddRange(new float[start + count - values.Count]); 179 | } 180 | for (int i = 0; i < count; ++i) 181 | { 182 | values[start + i] = @in.readFloat(); 183 | } 184 | } 185 | 186 | public override void serialize(int start, int count, ExtendedDataOutput @out) 187 | { 188 | for (int i = 0; i < count; ++i) 189 | { 190 | @out.writeFloat(values[start + i]); 191 | } 192 | } 193 | 194 | public override int getUnitLength() 195 | { 196 | return 4; 197 | } 198 | 199 | public override int serialize(int indexStart, int offect, int targetNumElement, out int numElement, out int partial, ByteBuffer @out) 200 | { 201 | targetNumElement = Math.Min((@out.remain() / getUnitLength()), targetNumElement); 202 | for (int i = 0; i < targetNumElement; ++i) 203 | { 204 | @out.WriteFloat(values[indexStart + i]); 205 | } 206 | numElement = targetNumElement; 207 | partial = 0; 208 | return targetNumElement * 4; 209 | } 210 | 211 | public override void append(IScalar value) 212 | { 213 | values.Add(((BasicFloat)value).getValue()); 214 | } 215 | 216 | public override void append(IVector value) 217 | { 218 | values.AddRange(((BasicFloatVector)value).getdataArray()); 219 | } 220 | 221 | public List getdataArray() 222 | { 223 | return values; 224 | } 225 | 226 | public override IEntity getEntity(int index) 227 | { 228 | return new BasicFloat(values[index]); 229 | } 230 | 231 | public override int hashBucket(int index, int buckets) 232 | { 233 | throw new NotImplementedException(); 234 | } 235 | } 236 | 237 | } -------------------------------------------------------------------------------- /src/data/BasicIPAddr.cs: -------------------------------------------------------------------------------- 1 | using dolphindb.io; 2 | using System; 3 | using System.Text; 4 | 5 | namespace dolphindb.data 6 | { 7 | public class BasicIPAddr : BasicInt128 8 | { 9 | 10 | 11 | public BasicIPAddr(long high, long low) : base(high, low) 12 | { 13 | 14 | } 15 | 16 | 17 | public BasicIPAddr(ExtendedDataInput @in) : base(@in) 18 | { 19 | } 20 | 21 | 22 | public override DATA_TYPE getDataType() 23 | { 24 | return DATA_TYPE.DT_IPADDR; 25 | } 26 | 27 | 28 | public override String getString() 29 | { 30 | if(isNull()) 31 | { 32 | return ""; 33 | }else{ 34 | return getString(value); 35 | } 36 | } 37 | 38 | public static String getString(Long2 value) 39 | { 40 | if (value.high == 0 && (value.low >> 32) == 0) 41 | { 42 | //ip4 43 | long ip4 = value.low; 44 | return String.Format("{0}.{1}.{2}.{3}", ip4 >> 24, (ip4 >> 16) & 0xff, (ip4 >> 8) & 0xff, ip4 & 0xff); 45 | } 46 | else 47 | { 48 | //ip6 49 | StringBuilder sb = new StringBuilder(); 50 | bool consecutiveZeros = false; 51 | int[] data = new int[8]; 52 | data[0] = (int)(value.high >> 48); 53 | data[1] = (int)((value.high >> 32) & 0xffff); 54 | data[2] = (int)((value.high >> 16) & 0xffff); 55 | data[3] = (int)(value.high & 0xffff); 56 | data[4] = (int)(value.low >> 48); 57 | data[5] = (int)((value.low >> 32) & 0xffff); 58 | data[6] = (int)((value.low >> 16) & 0xffff); 59 | data[7] = (int)(value.low & 0xffff); 60 | for (int i = 0; i < 8; ++i) 61 | { 62 | if (i > 0 && i < 6 && !consecutiveZeros && data[i] == 0 && data[i + 1] == 0) 63 | { 64 | //consecutive zeros 65 | consecutiveZeros = true; 66 | ++i; 67 | while (i < 6 && data[i + 1] == 0) ++i; 68 | } 69 | else 70 | { 71 | //swap two bytes 72 | sb.Append(String.Format("{0:x}", (short)data[i])); 73 | } 74 | sb.Append(':'); 75 | } 76 | return sb.ToString().Substring(0, sb.Length - 1); 77 | } 78 | } 79 | 80 | public static new BasicIPAddr fromString(String name) 81 | { 82 | if (name.Length < 7) 83 | return null; 84 | for (int i = 0; i < 4; ++i) 85 | { 86 | if (name.Substring(i, 1) == ".") 87 | return parseIP4(name); 88 | } 89 | return parseIP6(name); 90 | } 91 | 92 | public static BasicIPAddr parseIP4(String str) 93 | { 94 | int byteIndex = 0; 95 | long curByte = 0; 96 | int len = str.Length; 97 | long low = 0; 98 | for (int i = 0; i <= len; ++i) 99 | { 100 | if (i == len || str.Substring(i, 1) == ".") 101 | { 102 | if (curByte < 0 || curByte > 255 || byteIndex > 3) 103 | return null; 104 | low += curByte << ((3 - byteIndex) * 8); 105 | byteIndex++; 106 | curByte = 0; 107 | continue; 108 | } 109 | char ch = Convert.ToChar(str.Substring(i, 1)); 110 | if (ch < '0' || ch > '9') 111 | return null; 112 | curByte = curByte * 10 + ch - 48; 113 | } 114 | if (byteIndex != 4) 115 | return null; 116 | return new BasicIPAddr(0, low); 117 | } 118 | 119 | public static BasicIPAddr parseIP6(String str) 120 | { 121 | int byteIndex = 0; 122 | int curByte = 0; 123 | int len = str.Length; 124 | int lastColonPos = -1; 125 | byte[] buf = new byte[16]; 126 | 127 | for (int i = 0; i <= len; ++i) 128 | { 129 | if (i == len || str.Substring(i, 1) == ":") 130 | { 131 | //check consecutive colon 132 | if (lastColonPos == (int)i - 1) 133 | { 134 | //check how many colons in the remaining string 135 | int colons = byteIndex / 2; 136 | for (int k = i + 1; k < len; ++k) 137 | if (str.Substring(k, 1) == ":") 138 | ++colons; 139 | int consecutiveZeros = (7 - colons) * 2; 140 | for (int k = 0; k < consecutiveZeros; ++k) 141 | buf[byteIndex++] = 0; 142 | } 143 | else 144 | { 145 | if (curByte < 0 || curByte > 65535 || byteIndex > 15) 146 | return null; 147 | buf[byteIndex++] = (byte)(curByte >> 8); 148 | buf[byteIndex++] = (byte)(curByte & 255); 149 | curByte = 0; 150 | } 151 | lastColonPos = i; 152 | continue; 153 | } 154 | char ch = Convert.ToChar(str.Substring(i, 1)); 155 | char value = (char)(ch >= 97 ? ch - 87 : (ch >= 65 ? ch - 55 : ch - 48)); 156 | if (value < 0 || value > 15) 157 | return null; 158 | curByte = (curByte << 4) + value; 159 | } 160 | if (byteIndex == 16) 161 | { 162 | long low = (buf[8] & 0xFFL) << 56 | (buf[9] & 0xFFL) << 48 | (buf[10] & 0xFFL) << 40 | (buf[11] & 0xFFL) << 32 163 | | (buf[12] & 0xFFL) << 24 | (buf[13] & 0xFFL) << 16 | (buf[14] & 0xFFL) << 8 | (buf[15] & 0xFFL); 164 | 165 | long high = (buf[0] & 0xFFL) << 56 | (buf[1] & 0xFFL) << 48 | (buf[2] & 0xFFL) << 40 | (buf[3] & 0xFFL) << 32 166 | | (buf[4] & 0xFFL) << 24 | (buf[5] & 0xFFL) << 16 | (buf[6] & 0xFFL) << 8 | (buf[7] & 0xFFL); 167 | return new BasicIPAddr(high, low); 168 | } 169 | else 170 | return null; 171 | } 172 | } 173 | 174 | } 175 | -------------------------------------------------------------------------------- /src/data/BasicInt.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using dolphindb.io; 3 | namespace dolphindb.data 4 | { 5 | /// 6 | /// Corresponds to DolphinDB int scalar 7 | /// 8 | 9 | public class BasicInt : AbstractScalar, IComparable 10 | { 11 | private int value; 12 | static string formatStr = "0"; 13 | 14 | public BasicInt(int value) 15 | { 16 | this.value = value; 17 | } 18 | 19 | public BasicInt(ExtendedDataInput @in) 20 | { 21 | value = @in.readInt(); 22 | } 23 | 24 | public virtual int getValue() 25 | { 26 | return value; 27 | } 28 | 29 | public int getInt() 30 | { 31 | return value; 32 | } 33 | 34 | public override bool isNull() 35 | { 36 | return value == int.MinValue; 37 | } 38 | 39 | public override void setNull() 40 | { 41 | value = int.MinValue; 42 | } 43 | 44 | public override DATA_CATEGORY getDataCategory() 45 | { 46 | return DATA_CATEGORY.INTEGRAL; 47 | } 48 | 49 | public override DATA_TYPE getDataType() 50 | { 51 | return DATA_TYPE.DT_INT; 52 | } 53 | 54 | public override Number getNumber() 55 | { 56 | if (isNull()) 57 | { 58 | return null; 59 | } 60 | else 61 | { 62 | return new Number(value); 63 | } 64 | } 65 | 66 | public override object getTemporal() 67 | { 68 | throw new Exception("Imcompatible data type"); 69 | } 70 | 71 | public override bool Equals(object o) 72 | { 73 | if (!(o is BasicInt) || o == null) 74 | { 75 | return false; 76 | } 77 | else 78 | { 79 | return value == ((BasicInt)o).value; 80 | } 81 | } 82 | 83 | public override int GetHashCode() 84 | { 85 | return (new int?(value)).GetHashCode(); 86 | } 87 | 88 | public override void writeScalarToOutputStream(ExtendedDataOutput @out) 89 | { 90 | @out.writeInt(value); 91 | } 92 | 93 | public int CompareTo(BasicInt o) 94 | { 95 | return value.CompareTo(o.value); 96 | } 97 | 98 | public override string getString() 99 | { 100 | if(isNull()) 101 | { 102 | return ""; 103 | }else{ 104 | return value.ToString(formatStr); 105 | } 106 | } 107 | public override object getObject() 108 | { 109 | return getValue(); 110 | } 111 | 112 | public override string ToString() 113 | { 114 | return getString(); 115 | } 116 | 117 | public override void setObject(object value) 118 | { 119 | this.value = Convert.ToInt32(value); 120 | } 121 | 122 | public override int hashBucket(int buckets) 123 | { 124 | if (value >= 0) 125 | return value % buckets; 126 | else if (value == int.MinValue) 127 | return -1; 128 | else 129 | { 130 | return (int)((4294967296L + value) % buckets); 131 | } 132 | } 133 | } 134 | 135 | } -------------------------------------------------------------------------------- /src/data/BasicInt128.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using dolphindb.io; 4 | 5 | namespace dolphindb.data 6 | { 7 | public class BasicInt128 : AbstractScalar 8 | { 9 | 10 | protected Long2 value; 11 | 12 | public BasicInt128(long high, long low) 13 | { 14 | value = new Long2(high, low); 15 | } 16 | 17 | public BasicInt128(ExtendedDataInput @in) 18 | { 19 | value = @in.readLong2(); 20 | } 21 | 22 | public static BasicInt128 fromString(String num) 23 | { 24 | if (num.Length != 32) 25 | throw new Exception("Invalid int128 string."); 26 | long high = parseLongFromScale16(num.Substring(0, 16)); 27 | long low = parseLongFromScale16(num.Substring(16)); 28 | return new BasicInt128(high, low); 29 | } 30 | 31 | public Long2 getLong2() 32 | { 33 | return value; 34 | } 35 | 36 | 37 | public override bool isNull() 38 | { 39 | return value.isNull(); 40 | } 41 | 42 | 43 | public override void setNull() 44 | { 45 | value.setNull(); 46 | } 47 | 48 | public long getMostSignicantBits() 49 | { 50 | return value.high; 51 | } 52 | 53 | public long getLeastSignicantBits() 54 | { 55 | return value.low; 56 | } 57 | 58 | public override Number getNumber() 59 | { 60 | throw new Exception("Imcompatible data type"); 61 | } 62 | 63 | public override object getObject() 64 | { 65 | throw new NotImplementedException(); 66 | } 67 | 68 | public override void setObject(object value) 69 | { 70 | throw new NotImplementedException(); 71 | } 72 | public override Object getTemporal() 73 | { 74 | throw new Exception("Imcompatible data type"); 75 | } 76 | 77 | public override DATA_CATEGORY getDataCategory() 78 | { 79 | return DATA_CATEGORY.BINARY; 80 | } 81 | public override DATA_TYPE getDataType() 82 | { 83 | return DATA_TYPE.DT_INT128; 84 | } 85 | 86 | public override String getString() 87 | { 88 | if(isNull()) 89 | { 90 | return ""; 91 | }else{ 92 | return String.Format("{0:x16}", value.high) + String.Format("{0:x16}", value.low); 93 | } 94 | } 95 | 96 | public bool equals(Object o) 97 | { 98 | if (!(o is BasicInt128) || o == null) 99 | return false; 100 | else 101 | return value.equals(((BasicInt128)o).value); 102 | } 103 | 104 | 105 | public int hashCode() 106 | { 107 | return value.hashCode(); 108 | } 109 | 110 | 111 | public override void writeScalarToOutputStream(ExtendedDataOutput @out) 112 | { 113 | @out.writeLong2(value); 114 | } 115 | 116 | public Long2 getValue() 117 | { 118 | return value; 119 | } 120 | 121 | protected static long parseLongFromScale16(string str) 122 | { 123 | long ret = 0; 124 | for(int i = 0; i < str.Length; ++i) 125 | { 126 | ret *= 16; 127 | char data = str[i]; 128 | if(data >= '0' && data <= '9') 129 | { 130 | ret += data - '0'; 131 | }else if(data >= 'a' && data <= 'f') 132 | { 133 | ret += data - 'a' + 10; 134 | } 135 | else if (data >= 'A' && data <= 'F') 136 | { 137 | ret += data - 'A' + 10; 138 | } 139 | else 140 | { 141 | throw new Exception("Invalid character in hexadecimal string. "); 142 | } 143 | } 144 | return ret; 145 | } 146 | 147 | public override int hashBucket(int buckets) 148 | { 149 | return value.hashBucket(buckets); 150 | } 151 | 152 | public override bool Equals(object o) 153 | { 154 | if (!(o is BasicInt128) || o == null) 155 | { 156 | return false; 157 | } 158 | else 159 | { 160 | return getValue().equals(((BasicInt128)o).getValue()); 161 | } 162 | } 163 | 164 | public override int GetHashCode() 165 | { 166 | return -1584136870 + EqualityComparer.Default.GetHashCode(value); 167 | } 168 | } 169 | } 170 | -------------------------------------------------------------------------------- /src/data/BasicInt128Vector.cs: -------------------------------------------------------------------------------- 1 |  2 | using dolphindb.io; 3 | using dolphindb.data; 4 | using System.Collections.Generic; 5 | using System; 6 | 7 | public class BasicInt128Vector : AbstractVector 8 | { 9 | 10 | protected List values; 11 | 12 | public BasicInt128Vector(int size) : this(DATA_FORM.DF_VECTOR, size) 13 | { 14 | } 15 | 16 | public BasicInt128Vector(List list): base(DATA_FORM.DF_VECTOR) 17 | { 18 | if (list != null) 19 | { 20 | values = new List(); 21 | values.AddRange(new Long2[list.Count]); 22 | for (int i = 0; i < list.Count; ++i) 23 | values[i] = list[i]; 24 | } 25 | } 26 | 27 | public BasicInt128Vector(Long2[] array) : base(DATA_FORM.DF_VECTOR) 28 | { 29 | values = new List(); 30 | values.AddRange(array); 31 | } 32 | 33 | internal BasicInt128Vector(DATA_FORM df, int size) : base(df) 34 | { 35 | 36 | values = new List(); 37 | values.AddRange(new Long2[size]); 38 | for (int i = 0; i < size; ++i) 39 | values[i] = new Long2(0, 0); 40 | } 41 | 42 | internal BasicInt128Vector(DATA_FORM df, ExtendedDataInput @in):base(df) 43 | { 44 | int rows = @in.readInt(); 45 | int cols = @in.readInt(); 46 | int size = rows * cols; 47 | values = new List(); 48 | values.AddRange(new Long2[size]); 49 | int totalBytes = size * 16, off = 0; 50 | bool littleEndian = @in.isLittleEndian(); 51 | byte[] buffer = buf.Value; 52 | while (off values.Count) 188 | { 189 | values.AddRange(new Long2[start + count - values.Count]); 190 | } 191 | int totalBytes = count * 16, off = 0; 192 | bool littleEndian = @in.isLittleEndian(); 193 | byte[] buffer = buf.Value; 194 | while (off < totalBytes) 195 | { 196 | int len = System.Math.Min(BUF_SIZE, totalBytes - off); 197 | @in.readFully(buffer, 0, len); 198 | int subStart = off / 16, end = len / 16; 199 | Byte[] dst = new Byte[len]; 200 | Buffer.BlockCopy(buffer, 0, dst, 0, len); 201 | if (!littleEndian) 202 | Array.Reverse(dst); 203 | if (littleEndian) 204 | { 205 | for (int i = 0; i < end; i++) 206 | { 207 | long low = BitConverter.ToInt64(dst, i * 16); 208 | long high = BitConverter.ToInt64(dst, i * 16 + 8); 209 | values[i + subStart + start] = new Long2(high, low); 210 | } 211 | } 212 | else 213 | { 214 | for (int i = 0; i < end; i++) 215 | { 216 | long high = BitConverter.ToInt64(dst, i * 16); 217 | long low = BitConverter.ToInt64(dst, i * 16 + 8); 218 | values[i + subStart + start] = new Long2(high, low); 219 | } 220 | } 221 | off += len; 222 | } 223 | } 224 | 225 | public override void serialize(int start, int count, ExtendedDataOutput @out) 226 | { 227 | Long2[] buffer = new Long2[count]; 228 | for(int i = 0; i < count; ++i) 229 | { 230 | buffer[i] = values[i + start]; 231 | } 232 | @out.writeLong2Array(buffer); 233 | } 234 | 235 | 236 | public override int getUnitLength() 237 | { 238 | return 16; 239 | } 240 | 241 | public override int serialize(int indexStart, int offect, int targetNumElement, out int numElement, out int partial, ByteBuffer @out) 242 | { 243 | targetNumElement = Math.Min((@out.remain() / getUnitLength()), targetNumElement); 244 | if (@out.isLittleEndian) 245 | { 246 | for (int i = 0; i < targetNumElement; ++i) 247 | { 248 | @out.WriteLong(values[indexStart + i].low); 249 | @out.WriteLong(values[indexStart + i].high); 250 | } 251 | } 252 | else 253 | { 254 | for (int i = 0; i < targetNumElement; ++i) 255 | { 256 | @out.WriteLong(values[indexStart + i].high); 257 | @out.WriteLong(values[indexStart + i].low); 258 | } 259 | } 260 | numElement = targetNumElement; 261 | partial = 0; 262 | return targetNumElement * 16; 263 | } 264 | 265 | public override void append(IScalar value) 266 | { 267 | values.Add(((BasicInt128)value).getValue()); 268 | } 269 | 270 | public override void append(IVector value) 271 | { 272 | values.AddRange(((BasicInt128Vector)value).getdataArray()); 273 | } 274 | 275 | public List getdataArray() 276 | { 277 | return values; 278 | } 279 | 280 | public override IEntity getEntity(int index) 281 | { 282 | return get(index); 283 | } 284 | } 285 | -------------------------------------------------------------------------------- /src/data/BasicIntVector.cs: -------------------------------------------------------------------------------- 1 | using dolphindb.io; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | 6 | namespace dolphindb.data 7 | { 8 | public class BasicIntVector : AbstractVector 9 | { 10 | protected List values; 11 | 12 | public BasicIntVector(int size) : this(DATA_FORM.DF_VECTOR, size) 13 | { 14 | } 15 | 16 | public BasicIntVector(IList list) : base(DATA_FORM.DF_VECTOR) 17 | { 18 | if (list != null) 19 | { 20 | 21 | values = list.Where(x => x != null).Cast().ToList(); 22 | //values = new int[list.Count]; 23 | //for (int i = 0; i < list.Count; ++i) 24 | //{ 25 | // values[i] = list[i].Value; 26 | //} 27 | } 28 | } 29 | 30 | public BasicIntVector(int[] array) : base(DATA_FORM.DF_VECTOR) 31 | { 32 | values = new List(array.Length); 33 | values.AddRange(array); 34 | } 35 | 36 | protected internal BasicIntVector(DATA_FORM df, int size) : base(df) 37 | { 38 | values = new List(size); 39 | values.AddRange(new int[size]); 40 | } 41 | 42 | protected internal BasicIntVector(DATA_FORM df, ExtendedDataInput @in) : base(df) 43 | { 44 | int rows = @in.readInt(); 45 | //if (rows != 1024) 46 | //assert(rows == 1024); 47 | int cols = @in.readInt(); 48 | int size = rows * cols; 49 | values = new List(size); 50 | values.AddRange(new int[size]); 51 | for (int i = 0; i < size; ++i) 52 | { 53 | values[i] = @in.readInt(); 54 | } 55 | } 56 | 57 | public override IScalar get(int index) 58 | { 59 | return new BasicInt(values[index]); 60 | } 61 | 62 | public virtual int getInt(int index) 63 | { 64 | return values[index]; 65 | } 66 | 67 | public override void set(int index, IScalar value) 68 | { 69 | if (value.getDataType() == DATA_TYPE.DT_INT) 70 | values[index] = ((BasicInt)value).getInt(); 71 | else 72 | values[index] = Convert.ToInt32(value.getString()); 73 | } 74 | 75 | public virtual void setInt(int index, int value) 76 | { 77 | values[index] = value; 78 | } 79 | 80 | public override bool isNull(int index) 81 | { 82 | return values[index] == int.MinValue; 83 | } 84 | 85 | public override void setNull(int index) 86 | { 87 | values[index] = int.MinValue; 88 | } 89 | 90 | public override DATA_CATEGORY getDataCategory() 91 | { 92 | return DATA_CATEGORY.INTEGRAL; 93 | } 94 | 95 | public override DATA_TYPE getDataType() 96 | { 97 | return DATA_TYPE.DT_INT; 98 | } 99 | 100 | public override Type getElementClass() 101 | { 102 | return typeof(BasicInt); 103 | } 104 | 105 | public override int rows() 106 | { 107 | return values.Count; 108 | } 109 | 110 | protected internal override void writeVectorToOutputStream(ExtendedDataOutput @out) 111 | { 112 | @out.writeIntArray(values.ToArray()); 113 | } 114 | 115 | public override object getList() 116 | { 117 | return values; 118 | } 119 | 120 | public override void set(int index, string value) 121 | { 122 | int v; 123 | if (int.TryParse(value, out v)) 124 | { 125 | values[index] = v; 126 | } 127 | else 128 | { 129 | setNull(index); 130 | } 131 | } 132 | 133 | public override void add(object value) 134 | { 135 | values.Add(Convert.ToInt32(value)); 136 | } 137 | 138 | public override void addRange(object list) 139 | { 140 | List data = (List)list; 141 | values.AddRange(data); 142 | } 143 | 144 | public override int hashBucket(int index, int buckets) 145 | { 146 | int value = values[index]; 147 | if (value >= 0) 148 | return value % buckets; 149 | else if (value == int.MinValue) 150 | return -1; 151 | else 152 | { 153 | return (int)((4294967296L + value) % buckets); 154 | } 155 | } 156 | 157 | public override IVector getSubVector(int[] indices) 158 | { 159 | int length = indices.Length; 160 | int[] sub = new int[length]; 161 | for (int i = 0; i < length; ++i) 162 | sub[i] = values[indices[i]]; 163 | return new BasicIntVector(sub); 164 | } 165 | 166 | protected int[] getSubArray(int[] indices) 167 | { 168 | int length = indices.Length; 169 | int[] sub = new int[length]; 170 | for (int i = 0; i < length; ++i) 171 | sub[i] = values[indices[i]]; 172 | return sub; 173 | } 174 | 175 | 176 | public override int asof(IScalar value) 177 | { 178 | int target; 179 | target = value.getNumber().intValue(); 180 | 181 | int start = 0; 182 | int end = values.Count - 1; 183 | int mid; 184 | while (start <= end) 185 | { 186 | mid = (start + end) / 2; 187 | if (values[mid] <= target) 188 | start = mid + 1; 189 | else 190 | end = mid - 1; 191 | } 192 | return end; 193 | } 194 | 195 | public override void deserialize(int start, int count, ExtendedDataInput @in) 196 | { 197 | if (start + count > values.Count) 198 | { 199 | values.AddRange(new int[start + count - values.Count]); 200 | } 201 | for (int i = 0; i < count; ++i) 202 | { 203 | values[start + i] = @in.readInt(); 204 | } 205 | } 206 | 207 | public override void serialize(int start, int count, ExtendedDataOutput @out) 208 | { 209 | for (int i = 0; i < count; ++i) 210 | { 211 | @out.writeInt(values[start + i]); 212 | } 213 | } 214 | 215 | public override int serialize(int indexStart, int offect, int targetNumElement, out int numElement, out int partial, ByteBuffer @out) 216 | { 217 | targetNumElement = Math.Min((@out.remain() / getUnitLength()), targetNumElement); 218 | for (int i = 0; i < targetNumElement; ++i) 219 | { 220 | @out.WriteInt(values[indexStart + i]); 221 | } 222 | numElement = targetNumElement; 223 | partial = 0; 224 | return targetNumElement * 4; 225 | } 226 | 227 | public override int getUnitLength() 228 | { 229 | return 4; 230 | } 231 | 232 | public override void append(IScalar value) 233 | { 234 | values.Add(((BasicInt)value).getValue()); 235 | } 236 | 237 | public override void append(IVector value) 238 | { 239 | values.AddRange(((BasicIntVector)value).getdataArray()); 240 | } 241 | 242 | public List getdataArray() 243 | { 244 | return values; 245 | } 246 | 247 | public override IEntity getEntity(int index) 248 | { 249 | return new BasicInt(values[index]); 250 | } 251 | } 252 | } -------------------------------------------------------------------------------- /src/data/BasicIotAnyVector.cs: -------------------------------------------------------------------------------- 1 | using dolphindb.io; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace dolphindb.data 8 | { 9 | public class BasicIotAnyVector : AbstractVector 10 | { 11 | Dictionary subVectors; 12 | 13 | BasicIntVector dataTypes; 14 | 15 | BasicIntVector indexs; 16 | 17 | public BasicIotAnyVector(List scalars) : base(DATA_FORM.DF_VECTOR) 18 | { 19 | if (scalars == null || scalars.Count == 0) 20 | throw new Exception("The param 'scalars' cannot be null or empty."); 21 | int size = scalars.Count; 22 | subVectors = new Dictionary(); 23 | dataTypes = new BasicIntVector(size); 24 | indexs = new BasicIntVector(size); 25 | for (int i = 0; i < size; i++) 26 | { 27 | DATA_TYPE type = scalars[i].getDataType(); 28 | int typeInt = (int)type; 29 | if (!subVectors.ContainsKey(typeInt)) 30 | { 31 | subVectors.Add(typeInt, (AbstractVector)BasicEntityFactory.instance().createVectorWithDefaultValue(type, 0)); 32 | } 33 | subVectors[typeInt].append(scalars[i]); 34 | dataTypes.setInt(i, typeInt); 35 | indexs.setInt(i, subVectors[typeInt].rows() - 1); 36 | } 37 | } 38 | 39 | protected internal BasicIotAnyVector(DATA_FORM df, ExtendedDataInput @in) : base(df) 40 | { 41 | BasicAnyVector basicAnyVector = new BasicAnyVector(@in); 42 | BasicIntVector intVector = (BasicIntVector)basicAnyVector.getEntity(0); 43 | int indexSize = intVector.getInt(0); 44 | int typeSize = intVector.getInt(1); 45 | 46 | int[] indexValue = new int[indexSize]; 47 | int[] datatypeValue = new int[indexSize]; 48 | intVector.getdataArray().CopyTo(2, indexValue, 0, indexSize); 49 | intVector.getdataArray().CopyTo(2 + indexSize, datatypeValue, 0, indexSize); 50 | indexs = new BasicIntVector(indexValue); 51 | dataTypes = new BasicIntVector(datatypeValue); 52 | subVectors = new Dictionary(); 53 | for(int i = 0; i < typeSize; ++i) 54 | { 55 | IEntity entity = basicAnyVector.getEntity(i + 1); 56 | subVectors.Add((int)entity.getDataType(), (AbstractVector)entity); 57 | } 58 | } 59 | 60 | public override void add(object value) 61 | { 62 | throw new NotImplementedException(); 63 | } 64 | 65 | public override void addRange(object list) 66 | { 67 | throw new NotImplementedException(); 68 | } 69 | 70 | public override void append(IScalar value) 71 | { 72 | throw new NotImplementedException(); 73 | } 74 | 75 | public override void append(IVector value) 76 | { 77 | throw new NotImplementedException(); 78 | } 79 | 80 | public override void deserialize(int start, int count, ExtendedDataInput @in) 81 | { 82 | throw new NotImplementedException(); 83 | } 84 | 85 | public override IScalar get(int index) 86 | { 87 | if(dataTypes.getInt(index) == 0) 88 | { 89 | return new Void(); 90 | } 91 | else 92 | { 93 | return subVectors[dataTypes.getInt(index)].get(indexs.getInt(index)); 94 | } 95 | } 96 | 97 | public override DATA_CATEGORY getDataCategory() 98 | { 99 | return DATA_CATEGORY.MIXED; 100 | } 101 | 102 | public override DATA_TYPE getDataType() 103 | { 104 | return DATA_TYPE.DT_IOTANY; 105 | } 106 | 107 | public override Type getElementClass() 108 | { 109 | return typeof(IScalar); 110 | } 111 | 112 | public override IEntity getEntity(int index) 113 | { 114 | return get(index); 115 | } 116 | 117 | public override int getUnitLength() 118 | { 119 | throw new NotImplementedException(); 120 | } 121 | 122 | public override bool isNull(int index) 123 | { 124 | return get(index).isNull(); 125 | } 126 | 127 | public override int rows() 128 | { 129 | return dataTypes.rows(); 130 | } 131 | 132 | public override void serialize(int start, int count, ExtendedDataOutput @out) 133 | { 134 | throw new NotImplementedException(); 135 | } 136 | 137 | public override int serialize(int indexStart, int offect, int targetNumElement, out int numElement, out int partial, ByteBuffer @out) 138 | { 139 | throw new NotImplementedException(); 140 | } 141 | 142 | public override void set(int index, IScalar value) 143 | { 144 | throw new NotImplementedException(); 145 | } 146 | 147 | public override void set(int index, string value) 148 | { 149 | throw new NotImplementedException(); 150 | } 151 | 152 | public override void setNull(int index) 153 | { 154 | throw new NotImplementedException(); 155 | } 156 | 157 | protected internal override void writeVectorToOutputStream(ExtendedDataOutput @out) 158 | { 159 | BasicIntVector intVector = new BasicIntVector(new int[2]{ indexs.rows(), subVectors.Count}); 160 | intVector.append(indexs); 161 | intVector.append(dataTypes); 162 | BasicAnyVector anyVector = new BasicAnyVector(new IEntity[] { intVector }); 163 | foreach (KeyValuePair kvp in subVectors) 164 | { 165 | anyVector.append(kvp.Value); 166 | } 167 | anyVector.writeVectorToOutputStream(@out); 168 | } 169 | protected internal int serializeAnyVectorRows() 170 | { 171 | return subVectors.Count + 1; 172 | } 173 | 174 | public override int hashBucket(int index, int buckets) 175 | { 176 | throw new NotImplementedException(); 177 | } 178 | 179 | public override int asof(IScalar value) 180 | { 181 | throw new NotImplementedException(); 182 | } 183 | 184 | public override IVector getSubVector(int[] indices) 185 | { 186 | throw new NotImplementedException(); 187 | } 188 | } 189 | } 190 | -------------------------------------------------------------------------------- /src/data/BasicLongVector.cs: -------------------------------------------------------------------------------- 1 | using dolphindb.io; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | 6 | namespace dolphindb.data 7 | { 8 | 9 | 10 | public class BasicLongVector : AbstractVector 11 | { 12 | protected List values; 13 | 14 | public BasicLongVector(int size) : this(DATA_FORM.DF_VECTOR, size) 15 | { 16 | } 17 | 18 | public BasicLongVector(IList list) : base(DATA_FORM.DF_VECTOR) 19 | { 20 | if (list != null) 21 | { 22 | values = list.Where(x => x != null).Cast().ToList(); 23 | //values = new long[list.Count]; 24 | //for (int i = 0; i < list.Count; ++i) 25 | //{ 26 | // values[i] = list[i].Value; 27 | //} 28 | } 29 | } 30 | 31 | public BasicLongVector(long[] array) : base(DATA_FORM.DF_VECTOR) 32 | { 33 | values = new List(array.Length); 34 | values.AddRange(array); 35 | //values = array.Clone() as long[]; 36 | } 37 | 38 | protected internal BasicLongVector(DATA_FORM df, int size) : base(df) 39 | { 40 | values = new List(size); 41 | values.AddRange(new long[size]); 42 | } 43 | 44 | protected internal BasicLongVector(DATA_FORM df, ExtendedDataInput @in) : base(df) 45 | { 46 | int rows = @in.readInt(); 47 | int cols = @in.readInt(); 48 | int size = rows * cols; 49 | values = new List(size); 50 | values.AddRange(new long[size]); 51 | for (int i = 0; i < size; ++i) 52 | { 53 | values[i] = @in.readLong(); 54 | } 55 | } 56 | 57 | public override IScalar get(int index) 58 | { 59 | return new BasicLong(values[index]); 60 | } 61 | 62 | public virtual long getLong(int index) 63 | { 64 | return values[index]; 65 | } 66 | 67 | public override void set(int index, IScalar value) 68 | { 69 | if (value.getString() == null || value.getString() == "") 70 | setNull(index); 71 | else 72 | values[index] = Convert.ToInt64(value.getString()); 73 | } 74 | 75 | public virtual void setLong(int index, long value) 76 | { 77 | values[index] = value; 78 | } 79 | 80 | public override bool isNull(int index) 81 | { 82 | return values[index] == long.MinValue; 83 | } 84 | 85 | public override void setNull(int index) 86 | { 87 | values[index] = long.MinValue; 88 | } 89 | 90 | public override DATA_CATEGORY getDataCategory() 91 | { 92 | return DATA_CATEGORY.INTEGRAL; 93 | } 94 | 95 | public override DATA_TYPE getDataType() 96 | { 97 | return DATA_TYPE.DT_LONG; 98 | } 99 | 100 | public override int rows() 101 | { 102 | return values.Count; 103 | } 104 | 105 | public override Type getElementClass() 106 | { 107 | return typeof(BasicLong); 108 | } 109 | 110 | protected internal override void writeVectorToOutputStream(ExtendedDataOutput @out) 111 | { 112 | @out.writeLongArray(values.ToArray()); 113 | } 114 | 115 | public override object getList() 116 | { 117 | return values; 118 | } 119 | 120 | public override void set(int index, string value) 121 | { 122 | long v; 123 | if (long.TryParse(value, out v)) 124 | { 125 | values[index] = v; 126 | } 127 | else 128 | { 129 | setNull(index); 130 | } 131 | } 132 | 133 | public override void add(object value) 134 | { 135 | values.Add(Convert.ToInt64(value)); 136 | } 137 | 138 | public override void addRange(object list) 139 | { 140 | List data = (List)list; 141 | values.AddRange(data); 142 | } 143 | 144 | public override int hashBucket(int index, int buckets) 145 | { 146 | long value = values[index]; 147 | if (value >= 0) 148 | return (int)(value % buckets); 149 | else if (value == long.MinValue) 150 | return -1; 151 | else 152 | { 153 | return (int)(((long.MaxValue % buckets) + 2 + ((long.MaxValue + value) % buckets)) % buckets); 154 | } 155 | } 156 | 157 | public override IVector getSubVector(int[] indices) 158 | { 159 | int length = indices.Length; 160 | long[] sub = new long[length]; 161 | for (int i = 0; i < length; ++i) 162 | sub[i] = values[indices[i]]; 163 | return new BasicLongVector(sub); 164 | } 165 | 166 | protected long[] getSubArray(int[] indices) 167 | { 168 | int length = indices.Length; 169 | long[] sub = new long[length]; 170 | for (int i = 0; i < length; ++i) 171 | sub[i] = values[indices[i]]; 172 | return sub; 173 | } 174 | 175 | public override int asof(IScalar value) 176 | { 177 | long target; 178 | target = value.getNumber().longValue(); 179 | 180 | int start = 0; 181 | int end = values.Count - 1; 182 | int mid; 183 | while (start <= end) 184 | { 185 | mid = (start + end) / 2; 186 | if (values[mid] <= target) 187 | start = mid + 1; 188 | else 189 | end = mid - 1; 190 | } 191 | return end; 192 | } 193 | 194 | public override void deserialize(int start, int count, ExtendedDataInput @in) 195 | { 196 | if (start + count > values.Count) 197 | { 198 | values.AddRange(new long[start + count - values.Count]); 199 | } 200 | for (int i = 0; i < count; ++i) 201 | { 202 | values[start + i] = @in.readLong(); 203 | } 204 | } 205 | 206 | public override void serialize(int start, int count, ExtendedDataOutput @out) 207 | { 208 | for (int i = 0; i < count; ++i) 209 | { 210 | @out.writeLong(values[start + i]); 211 | } 212 | } 213 | 214 | public override int getUnitLength() 215 | { 216 | return 8; 217 | } 218 | 219 | public override int serialize(int indexStart, int offect, int targetNumElement, out int numElement, out int partial, ByteBuffer @out) 220 | { 221 | targetNumElement = Math.Min((@out.remain() / getUnitLength()), targetNumElement); 222 | for (int i = 0; i < targetNumElement; ++i) 223 | { 224 | @out.WriteLong(values[indexStart + i]); 225 | } 226 | numElement = targetNumElement; 227 | partial = 0; 228 | return targetNumElement * 8; 229 | } 230 | 231 | public override void append(IScalar value) 232 | { 233 | values.Add(((BasicLong)value).getValue()); 234 | } 235 | 236 | public override void append(IVector value) 237 | { 238 | values.AddRange(((BasicLongVector)value).getdataArray()); 239 | } 240 | 241 | public List getdataArray() 242 | { 243 | return values; 244 | } 245 | 246 | public override IEntity getEntity(int index) 247 | { 248 | return new BasicLong(values[index]); 249 | } 250 | } 251 | 252 | } -------------------------------------------------------------------------------- /src/data/BasicPoint.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using dolphindb.io; 4 | 5 | namespace dolphindb.data 6 | { 7 | public class BasicPoint : AbstractScalar 8 | { 9 | 10 | protected Double2 value; 11 | 12 | public BasicPoint(double x, double y) 13 | { 14 | value = new Double2(x, y); 15 | } 16 | 17 | public BasicPoint(ExtendedDataInput @in) 18 | { 19 | value = @in.readDouble2(); 20 | } 21 | 22 | public Double2 getDouble2() 23 | { 24 | return value; 25 | } 26 | 27 | 28 | public override bool isNull() 29 | { 30 | return value.isNull(); 31 | } 32 | 33 | 34 | public override void setNull() 35 | { 36 | value = new Double2(-double.MaxValue, -double.MaxValue); 37 | } 38 | 39 | public double getX() 40 | { 41 | return value.x; 42 | } 43 | 44 | public double getY() 45 | { 46 | return value.y; 47 | } 48 | 49 | public override Number getNumber() 50 | { 51 | throw new Exception("Imcompatible data type"); 52 | } 53 | 54 | public override object getObject() 55 | { 56 | throw new NotImplementedException(); 57 | } 58 | 59 | public override void setObject(object value) 60 | { 61 | throw new NotImplementedException(); 62 | } 63 | public override Object getTemporal() 64 | { 65 | throw new Exception("Imcompatible data type"); 66 | } 67 | 68 | public override DATA_CATEGORY getDataCategory() 69 | { 70 | return DATA_CATEGORY.BINARY; 71 | } 72 | public override DATA_TYPE getDataType() 73 | { 74 | return DATA_TYPE.DT_POINT; 75 | } 76 | 77 | public override String getString() 78 | { 79 | if (isNull()) 80 | { 81 | return "(, )"; 82 | } 83 | else 84 | { 85 | return "(" + value.x + ", " + value.y + ")"; 86 | } 87 | } 88 | 89 | public bool equals(Object o) 90 | { 91 | if (!(o is BasicPoint) || o == null) 92 | return false; 93 | else 94 | return value.equals(((BasicPoint)o).value); 95 | } 96 | 97 | public override void writeScalarToOutputStream(ExtendedDataOutput @out) 98 | { 99 | @out.writeDouble2(value); 100 | } 101 | 102 | public Double2 getValue() 103 | { 104 | return value; 105 | } 106 | 107 | public override int hashBucket(int buckets) 108 | { 109 | return value.hashBucket(buckets); 110 | } 111 | 112 | public override bool Equals(object o) 113 | { 114 | if (!(o is BasicPoint) || o == null) 115 | { 116 | return false; 117 | } 118 | else 119 | { 120 | return getValue().equals(((BasicPoint)o).getValue()); 121 | } 122 | } 123 | 124 | public override int GetHashCode() 125 | { 126 | return value.GetHashCode(); 127 | } 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /src/data/BasicPointVector.cs: -------------------------------------------------------------------------------- 1 |  2 | using dolphindb.io; 3 | using dolphindb.data; 4 | using System.Collections.Generic; 5 | using System; 6 | 7 | public class BasicPointVector : BasicDouble2Vector 8 | { 9 | public BasicPointVector(int size) : this(DATA_FORM.DF_VECTOR, size) { } 10 | public BasicPointVector(List list) : base(list) { } 11 | 12 | public BasicPointVector(Double2[] array) : base(array) { } 13 | internal BasicPointVector(DATA_FORM df, int size) : base(df, size) { } 14 | 15 | internal BasicPointVector(DATA_FORM df, ExtendedDataInput @in) : base(df, @in) { } 16 | 17 | public override IScalar get(int index) 18 | { 19 | return new BasicPoint(values[index].x, values[index].y); 20 | } 21 | 22 | public override void set(int index, IScalar value) 23 | { 24 | if (value.getDataType() == DATA_TYPE.DT_POINT) 25 | { 26 | values[index] = new Double2(((BasicPoint)value).getX(), ((BasicPoint)value).getY()); 27 | } 28 | else 29 | throw new Exception("The value must be a point scalar. "); 30 | } 31 | 32 | public void setPoint(int index, double x, double y) 33 | { 34 | values[index] = new Double2(x, y); 35 | } 36 | 37 | public override DATA_TYPE getDataType() 38 | { 39 | return DATA_TYPE.DT_POINT; 40 | } 41 | 42 | public override Type getElementClass() 43 | { 44 | return typeof(BasicPoint); 45 | } 46 | 47 | public override IVector getSubVector(int[] indices) 48 | { 49 | int length = indices.Length; 50 | Double2[] sub = new Double2[length]; 51 | for (int i = 0; i < length; ++i) 52 | sub[i] = values[indices[i]]; 53 | return new BasicPointVector(sub); 54 | } 55 | 56 | public override void append(IScalar value) 57 | { 58 | values.Add(((BasicPoint)value).getValue()); 59 | } 60 | 61 | public override void append(IVector value) 62 | { 63 | values.AddRange(((BasicPointVector)value).getDataArray()); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/data/BasicShortVector.cs: -------------------------------------------------------------------------------- 1 | using dolphindb.io; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | 6 | namespace dolphindb.data 7 | { 8 | 9 | public class BasicShortVector : AbstractVector 10 | { 11 | private List values; 12 | 13 | public BasicShortVector(int size) : this(DATA_FORM.DF_VECTOR, size) 14 | { 15 | } 16 | 17 | public BasicShortVector(IList list) : base(DATA_FORM.DF_VECTOR) 18 | { 19 | if (list != null) 20 | { 21 | values = list.Where(x => x != null).Cast().ToList(); 22 | //values = new short[list.Count]; 23 | //for (int i = 0; i < list.Count; ++i) 24 | //{ 25 | // values[i] = list[i].Value; 26 | //} 27 | } 28 | } 29 | 30 | public BasicShortVector(short[] array) : base(DATA_FORM.DF_VECTOR) 31 | { 32 | values = new List(array.Length); 33 | values.AddRange(array); 34 | //values = array.Clone() as short[]; 35 | } 36 | 37 | protected internal BasicShortVector(DATA_FORM df, int size) : base(df) 38 | { 39 | values = new List(size); 40 | values.AddRange(new short[size]); 41 | } 42 | 43 | protected internal BasicShortVector(DATA_FORM df, ExtendedDataInput @in) : base(df) 44 | { 45 | int rows = @in.readInt(); 46 | int cols = @in.readInt(); 47 | int size = rows * cols; 48 | values = new List(size); 49 | values.AddRange(new short[size]); 50 | for (int i = 0; i < size; ++i) 51 | { 52 | values[i] = @in.readShort(); 53 | } 54 | } 55 | 56 | public virtual short getShort(int index) 57 | { 58 | return values[index]; 59 | } 60 | 61 | public override IScalar get(int index) 62 | { 63 | return new BasicShort(values[index]); 64 | } 65 | 66 | public override void set(int index, IScalar value) 67 | { 68 | if (value.getDataType() == DATA_TYPE.DT_SHORT) 69 | { 70 | setShort(index, ((BasicShort)value).getValue()); 71 | } 72 | else 73 | throw new Exception("The value must be a short scalar. "); 74 | } 75 | 76 | public virtual void setShort(int index, short value) 77 | { 78 | values[index] = value; 79 | } 80 | 81 | public override bool isNull(int index) 82 | { 83 | return values[index] == short.MinValue; 84 | } 85 | 86 | public override void setNull(int index) 87 | { 88 | values[index] = short.MinValue; 89 | } 90 | 91 | public override DATA_CATEGORY getDataCategory() 92 | { 93 | return DATA_CATEGORY.INTEGRAL; 94 | } 95 | 96 | public override DATA_TYPE getDataType() 97 | { 98 | return DATA_TYPE.DT_SHORT; 99 | } 100 | 101 | public override int rows() 102 | { 103 | return values.Count; 104 | } 105 | 106 | public override Type getElementClass() 107 | { 108 | return typeof(BasicShort); 109 | } 110 | 111 | protected internal override void writeVectorToOutputStream(ExtendedDataOutput @out) 112 | { 113 | @out.writeShortArray(values.ToArray()); 114 | } 115 | 116 | public override object getList() 117 | { 118 | return values; 119 | } 120 | 121 | public override void set(int index, string value) 122 | { 123 | short v; 124 | if (short.TryParse(value, out v)) 125 | { 126 | values[index] = v; 127 | } 128 | else 129 | { 130 | setNull(index); 131 | } 132 | } 133 | 134 | public override void add(object value) 135 | { 136 | values.Add(Convert.ToInt16(value)); 137 | } 138 | 139 | public override void addRange(object list) 140 | { 141 | List data = (List)list; 142 | values.AddRange(data); 143 | } 144 | 145 | public override int hashBucket(int index, int buckets) 146 | { 147 | short value = values[index]; 148 | if (value >= 0) 149 | return value % buckets; 150 | else if (value == short.MinValue) 151 | return -1; 152 | else 153 | { 154 | return (int)((4294967296L + value) % buckets); 155 | } 156 | } 157 | 158 | public override IVector getSubVector(int[] indices) 159 | { 160 | int length = indices.Length; 161 | short[] sub = new short[length]; 162 | for (int i = 0; i < length; ++i) 163 | sub[i] = values[indices[i]]; 164 | return new BasicShortVector(sub); 165 | } 166 | 167 | public override int asof(IScalar value) 168 | { 169 | short target; 170 | target = value.getNumber().shortValue(); 171 | 172 | int start = 0; 173 | int end = values.Count - 1; 174 | int mid; 175 | while (start <= end) 176 | { 177 | mid = (start + end) / 2; 178 | if (values[mid] <= target) 179 | start = mid + 1; 180 | else 181 | end = mid - 1; 182 | } 183 | return end; 184 | } 185 | 186 | public override void deserialize(int start, int count, ExtendedDataInput @in) 187 | { 188 | if (start + count > values.Count) 189 | { 190 | values.AddRange(new short[start + count - values.Count]); 191 | } 192 | for (int i = 0; i < count; ++i) 193 | { 194 | values[start + i] = @in.readShort(); 195 | } 196 | } 197 | 198 | public override void serialize(int start, int count, ExtendedDataOutput @out) 199 | { 200 | for(int i = 0; i < count; ++i) 201 | { 202 | @out.writeShort(values[start + i]); 203 | } 204 | } 205 | 206 | public override int getUnitLength() 207 | { 208 | return 2; 209 | } 210 | 211 | public override int serialize(int indexStart, int offect, int targetNumElement, out int numElement, out int partial, ByteBuffer @out) 212 | { 213 | targetNumElement = Math.Min((@out.remain() / getUnitLength()), targetNumElement); 214 | for (int i = 0; i < targetNumElement; ++i) 215 | { 216 | @out.WriteShort(values[indexStart + i]); 217 | } 218 | numElement = targetNumElement; 219 | partial = 0; 220 | return targetNumElement * 2; 221 | } 222 | 223 | public override void append(IScalar value) 224 | { 225 | values.Add(((BasicShort)value).getValue()); 226 | } 227 | 228 | public override void append(IVector value) 229 | { 230 | values.AddRange(((BasicShortVector)value).getdataArray()); 231 | } 232 | 233 | public List getdataArray() 234 | { 235 | return values; 236 | } 237 | 238 | public override IEntity getEntity(int index) 239 | { 240 | return new BasicShort(values[index]); 241 | } 242 | } 243 | 244 | } -------------------------------------------------------------------------------- /src/data/BasicUuid.cs: -------------------------------------------------------------------------------- 1 | using dolphindb.io; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace dolphindb.data 8 | { 9 | public class BasicUuid : BasicInt128 10 | { 11 | 12 | 13 | public BasicUuid(long high, long low) : base(high, low) 14 | { 15 | } 16 | 17 | 18 | internal BasicUuid(ExtendedDataInput @in) : base(@in) 19 | { 20 | } 21 | 22 | public override DATA_TYPE getDataType() 23 | { 24 | return DATA_TYPE.DT_UUID; 25 | } 26 | 27 | public override String getString() 28 | { 29 | if(isNull()) 30 | { 31 | return ""; 32 | }else{ 33 | ulong c = (ulong)0xffffffff << 32; 34 | //ulong a = 0xffffffff; 35 | ulong t = (ulong)value.high & c; 36 | ulong uHigh = (ulong)value.high; 37 | ulong uLow = (ulong)value.low; 38 | byte[] buffer = new byte[8]; 39 | for (int i = 0; i < 8; ++i) 40 | { 41 | buffer[i] = (byte)(uLow >> ((7 - i) * 8)); 42 | } 43 | return new Guid((int)(uHigh >> 32 & 0xffffffff), (short)(uHigh >> 16 & 0xffff), 44 | (short)(uHigh & 0xffff), buffer).ToString(); 45 | } 46 | } 47 | 48 | public static new BasicUuid fromString(String name) 49 | { 50 | String[] components = name.Split('-'); 51 | if (components.Length != 5) 52 | throw new ArgumentException("Invalid UUID string: " + name); 53 | 54 | long mostSigBits = Convert.ToInt64(components[0], 16); 55 | mostSigBits <<= 16; 56 | mostSigBits |= Convert.ToInt64(components[1], 16); 57 | mostSigBits <<= 16; 58 | mostSigBits |= Convert.ToInt64(components[2], 16); 59 | 60 | long leastSigBits = Convert.ToInt64(components[3], 16); 61 | leastSigBits <<= 48; 62 | leastSigBits |= Convert.ToInt64(components[4], 16); 63 | 64 | return new BasicUuid(mostSigBits, leastSigBits); 65 | } 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /src/data/BasicVoidVector.cs: -------------------------------------------------------------------------------- 1 | using dolphindb.io; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace dolphindb.data 8 | { 9 | internal class BasicVoidVector : AbstractVector 10 | { 11 | public BasicVoidVector(int size) : base(DATA_FORM.DF_VECTOR) 12 | { 13 | size_= size; 14 | } 15 | 16 | public BasicVoidVector(DATA_FORM df, ExtendedDataInput @in) : base(DATA_FORM.DF_VECTOR) 17 | { 18 | int rows = @in.readInt(); 19 | int cols = @in.readInt(); 20 | int size = rows * cols; 21 | size_ = size; 22 | 23 | } 24 | 25 | int size_ = 0; 26 | public override void add(object value) 27 | { 28 | size_++; 29 | } 30 | 31 | public override void addRange(object list) 32 | { 33 | size_++; 34 | } 35 | 36 | public override void append(IScalar value) 37 | { 38 | size_++; 39 | } 40 | 41 | public override void append(IVector value) 42 | { 43 | size_ += value.rows(); 44 | } 45 | 46 | public override int asof(IScalar value) 47 | { 48 | throw new NotImplementedException(); 49 | } 50 | 51 | public override void deserialize(int start, int count, ExtendedDataInput @in) 52 | { 53 | } 54 | 55 | public override IScalar get(int index) 56 | { 57 | return new Void(); 58 | } 59 | 60 | public override DATA_CATEGORY getDataCategory() 61 | { 62 | return DATA_CATEGORY.NOTHING; 63 | } 64 | 65 | public override DATA_TYPE getDataType() 66 | { 67 | return DATA_TYPE.DT_VOID; 68 | } 69 | 70 | public override Type getElementClass() 71 | { 72 | return typeof(Void); 73 | } 74 | 75 | public override IEntity getEntity(int index) 76 | { 77 | return new Void(); 78 | } 79 | 80 | public override IVector getSubVector(int[] indices) 81 | { 82 | return new BasicVoidVector(indices.Length); 83 | } 84 | 85 | public override int getUnitLength() 86 | { 87 | throw new NotImplementedException(); 88 | } 89 | 90 | public override int hashBucket(int index, int buckets) 91 | { 92 | throw new NotImplementedException(); 93 | } 94 | 95 | public override bool isNull(int index) 96 | { 97 | return true; 98 | } 99 | 100 | public override int rows() 101 | { 102 | return size_; 103 | } 104 | 105 | public override void serialize(int start, int count, ExtendedDataOutput @out) 106 | { 107 | } 108 | 109 | public override int serialize(int indexStart, int offect, int targetNumElement, out int numElement, out int partial, ByteBuffer @out) 110 | { 111 | numElement = targetNumElement; 112 | partial = 0; 113 | return targetNumElement; 114 | } 115 | 116 | public override void set(int index, IScalar value) 117 | { 118 | } 119 | 120 | public override void set(int index, string value) 121 | { 122 | } 123 | 124 | public override void setNull(int index) 125 | { 126 | } 127 | 128 | protected internal override void writeVectorToOutputStream(ExtendedDataOutput @out) 129 | { 130 | } 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /src/data/IEntity.cs: -------------------------------------------------------------------------------- 1 | using dolphindb.io; 2 | using System.Data; 3 | 4 | namespace dolphindb.data 5 | { 6 | public interface IEntity 7 | { 8 | DATA_FORM getDataForm(); 9 | DATA_CATEGORY getDataCategory(); 10 | DATA_TYPE getDataType(); 11 | object getObject(); 12 | int rows(); 13 | int columns(); 14 | string getString(); 15 | void write(ExtendedDataOutput output); 16 | void writeCompressed(ExtendedDataOutput output); 17 | DataTable toDataTable(); 18 | bool isScalar(); 19 | bool isVector(); 20 | bool isPair(); 21 | bool isTable(); 22 | bool isMatrix(); 23 | bool isDictionary(); 24 | bool isChart(); 25 | bool isChunk(); 26 | 27 | 28 | 29 | } 30 | 31 | public enum DATA_TYPE 32 | { 33 | DT_VOID, 34 | DT_BOOL, 35 | DT_BYTE, 36 | DT_SHORT, 37 | DT_INT, 38 | DT_LONG, 39 | DT_DATE, 40 | DT_MONTH, 41 | DT_TIME, 42 | DT_MINUTE, 43 | DT_SECOND, 44 | DT_DATETIME, 45 | DT_TIMESTAMP, 46 | DT_NANOTIME, 47 | DT_NANOTIMESTAMP, 48 | DT_FLOAT, 49 | DT_DOUBLE, 50 | DT_SYMBOL, 51 | DT_STRING, 52 | DT_UUID, 53 | DT_FUNCTIONDEF, 54 | DT_HANDLE, 55 | DT_CODE, 56 | DT_DATASOURCE, 57 | DT_RESOURCE, 58 | DT_ANY, 59 | DT_COMPRESS, 60 | DT_DICTIONARY, 61 | DT_DATEHOUR, 62 | DT_DATEMINUTE, 63 | DT_IPADDR, 64 | DT_INT128, 65 | //2021.01.19 cwj 顺序! 66 | DT_BLOB, 67 | // 68 | DT_OBJECT, 69 | DT_COMPLEX = 34, 70 | DT_POINT = 35, 71 | 72 | DT_DECIMAL32 = 37, 73 | DT_DECIMAL64 = 38, 74 | DT_DECIMAL128 = 39, 75 | DT_IOTANY = 41, 76 | 77 | DT_BOOL_ARRAY = 65, 78 | DT_BYTE_ARRAY, 79 | DT_SHORT_ARRAY, 80 | DT_INT_ARRAY, 81 | DT_LONG_ARRAY, 82 | DT_DATE_ARRAY, 83 | DT_MONTH_ARRAY, 84 | DT_TIME_ARRAY, 85 | DT_MINUTE_ARRAY, 86 | DT_SECOND_ARRAY, 87 | DT_DATETIME_ARRAY, 88 | DT_TIMESTAMP_ARRAY, 89 | DT_NANOTIME_ARRAY, 90 | DT_NANOTIMESTAMP_ARRAY, 91 | DT_FLOAT_ARRAY, 92 | DT_DOUBLE_ARRAY, 93 | DT_SYMBOL_ARRAY, 94 | DT_STRING_ARRAY, 95 | DT_UUID_ARRAY, 96 | DT_FUNCTIONDEF_ARRAY, 97 | DT_HANDLE_ARRAY, 98 | DT_CODE_ARRAY, 99 | DT_DATASOURCE_ARRAY, 100 | DT_RESOURCE_ARRAY, 101 | DT_ANY_ARRAY, 102 | DT_COMPRESS_ARRAY, 103 | DT_DICTIONARY_ARRAY, 104 | DT_DATEHOUR_ARRAY, 105 | DT_DATEMINUTE_ARRAY, 106 | DT_IPADDR_ARRAY, 107 | DT_INT128_ARRAY, 108 | DT_COMPLEX_ARRAY = 98, 109 | DT_POINT_ARRAY = 99, 110 | DT_DECIMAL32_ARRAY = 101, 111 | DT_DECIMAL64_ARRAY = 102, 112 | DT_DECIMAL128_ARRAY = 103 113 | } 114 | 115 | public enum DATA_CATEGORY 116 | { 117 | NOTHING, 118 | LOGICAL, 119 | INTEGRAL, 120 | FLOATING, 121 | TEMPORAL, 122 | LITERAL, 123 | SYSTEM, 124 | MIXED, 125 | BINARY, 126 | ARRAY, 127 | DENARY 128 | } 129 | 130 | public enum DATA_FORM 131 | { 132 | DF_SCALAR, 133 | DF_VECTOR, 134 | DF_PAIR, 135 | DF_MATRIX, 136 | DF_SET, 137 | DF_DICTIONARY, 138 | DF_TABLE, 139 | DF_CHART, 140 | DF_CHUNK 141 | } 142 | 143 | public enum PARTITION_TYPE 144 | { 145 | SEQ, 146 | VALUE, 147 | RANGE, 148 | LIST, 149 | COMPO, 150 | HASH 151 | } 152 | 153 | 154 | 155 | 156 | 157 | 158 | } -------------------------------------------------------------------------------- /src/data/Void.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using dolphindb.io; 3 | 4 | namespace dolphindb.data 5 | { 6 | public class Void : AbstractScalar 7 | { 8 | public Void(){} 9 | 10 | public Void(ExtendedDataInput @in) 11 | { 12 | @in.readByte(); 13 | } 14 | 15 | public override bool isNull() 16 | { 17 | return true; 18 | } 19 | 20 | public override DATA_CATEGORY getDataCategory() 21 | { 22 | return DATA_CATEGORY.NOTHING; 23 | } 24 | 25 | public override DATA_TYPE getDataType() 26 | { 27 | return DATA_TYPE.DT_VOID; 28 | } 29 | 30 | public override string getString() 31 | { 32 | return ""; 33 | } 34 | 35 | public override bool Equals(object o) 36 | { 37 | if (!(o is Void) || o == null) 38 | { 39 | return false; 40 | } 41 | else 42 | { 43 | return true; 44 | } 45 | } 46 | 47 | public override int GetHashCode() 48 | { 49 | return 0; 50 | } 51 | 52 | 53 | public override void writeScalarToOutputStream(ExtendedDataOutput @out) 54 | { 55 | @out.writeBoolean(true); //explicit null value 56 | } 57 | 58 | public override object getObject() 59 | { 60 | return null; 61 | } 62 | 63 | public override void setObject(object value) 64 | { 65 | return; 66 | } 67 | 68 | public override int hashBucket(int buckets) 69 | { 70 | throw new NotImplementedException(); 71 | } 72 | } 73 | 74 | } -------------------------------------------------------------------------------- /src/io/AbstractExtendedDataInputStream.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Text; 4 | 5 | namespace dolphindb.io 6 | { 7 | 8 | 9 | public abstract class AbstractExtendedDataInputStream : BinaryReader, ExtendedDataInput 10 | { 11 | 12 | private const int UTF8_STRING_LIMIT = 65536; 13 | private byte[] buf_; 14 | protected Stream _inStream; 15 | protected internal AbstractExtendedDataInputStream(Stream inStream) : base(inStream) 16 | { 17 | _inStream = inStream; 18 | } 19 | 20 | public bool readBoolean() 21 | { 22 | return readUnsignedByte() != 0; 23 | } 24 | 25 | public byte readByte() 26 | { 27 | return (byte)readUnsignedByte(); 28 | } 29 | 30 | public void readFully(byte[] arg0) 31 | { 32 | int offect = 0; 33 | do 34 | { 35 | offect += base.Read(arg0, offect, arg0.Length - offect); 36 | } while (offect < arg0.Length); 37 | } 38 | 39 | public void readFully(byte[] arg0, int arg1, int arg2) 40 | { 41 | int offect = 0; 42 | do 43 | { 44 | offect += base.Read(arg0, arg1 + offect, arg2 - offect); 45 | } while (offect < arg2); 46 | } 47 | 48 | public int readUnsignedByte() 49 | { 50 | byte b1 = ReadByte(); 51 | if (0 > b1) 52 | { 53 | throw new EndOfStreamException(); 54 | } 55 | return b1; 56 | } 57 | 58 | public int skipBytes(int n) 59 | { 60 | return (int)_inStream.Seek(n, SeekOrigin.Current); 61 | } 62 | 63 | protected internal virtual byte readAndCheckByte() 64 | { 65 | int b = this.Read(); 66 | 67 | if (-1 == b) 68 | { 69 | throw new EndOfStreamException(); 70 | } 71 | 72 | return (byte)b; 73 | } 74 | 75 | protected internal virtual int fromBytes(byte b1, byte b2, byte b3, byte b4) 76 | { 77 | return b1 << 24 | (b2 & 0xFF) << 16 | (b3 & 0xFF) << 8 | (b4 & 0xFF); 78 | } 79 | 80 | protected internal virtual long fromBytes(byte b1, byte b2, byte b3, byte b4, byte b5, byte b6, byte b7, byte b8) 81 | { 82 | return (b1 & 0xFFL) << 56 | (b2 & 0xFFL) << 48 | (b3 & 0xFFL) << 40 | (b4 & 0xFFL) << 32 | (b5 & 0xFFL) << 24 | (b6 & 0xFFL) << 16 | (b7 & 0xFFL) << 8 | (b8 & 0xFFL); 83 | } 84 | 85 | string ExtendedDataInput.readLine() 86 | { 87 | return readUTF8((byte)'\n'); 88 | } 89 | 90 | short ExtendedDataInput.readShort() 91 | { 92 | return (short)readUnsignedShort(); 93 | } 94 | 95 | int ExtendedDataInput.readUnsignedByte() 96 | { 97 | return base.ReadByte(); 98 | } 99 | 100 | int ExtendedDataInput.skipBytes(int n) 101 | { 102 | return base.ReadByte(); 103 | } 104 | 105 | public abstract int readInt(); 106 | 107 | public abstract int readUnsignedShort(); 108 | 109 | private string readUTF8(byte terminator) 110 | { 111 | if (buf_ == null) 112 | buf_ = new byte[2048]; 113 | byte ch = readAndCheckByte(); 114 | int count = 0; 115 | while (ch != terminator) 116 | { 117 | if (count == buf_.Length) 118 | { 119 | if (count >= UTF8_STRING_LIMIT) 120 | throw new IOException("UTF-8 string length exceeds the limit of 65536 bytes"); 121 | byte[] tmp = new byte[buf_.Length * 2]; 122 | Array.Copy(buf_, 0, tmp, 0, buf_.Length); 123 | buf_ = tmp; 124 | } 125 | buf_[count++] = ch; 126 | ch = readAndCheckByte(); 127 | } 128 | return Encoding.UTF8.GetString(buf_, 0, count); 129 | } 130 | 131 | public abstract long readLong(); 132 | 133 | public override int Read() 134 | { 135 | int re = base.ReadByte(); 136 | return re; 137 | } 138 | 139 | byte ExtendedDataInput.readByte() 140 | { 141 | return base.ReadByte(); 142 | } 143 | 144 | public char readChar() 145 | { 146 | return base.ReadChar(); 147 | } 148 | 149 | public double readDouble() 150 | { 151 | long l = readLong(); 152 | double re = BitConverter.Int64BitsToDouble(l); 153 | return re; 154 | } 155 | 156 | public float readFloat() 157 | { 158 | byte[] b = base.ReadBytes(4); 159 | return BitConverter.ToSingle(b, 0); 160 | } 161 | 162 | public string readString() 163 | { 164 | return readUTF8((byte)0); 165 | } 166 | 167 | //2021.01.19 cwj 168 | public byte[] readBlob() 169 | { 170 | int len = readInt(); 171 | int offset = 0; 172 | int actualSize = 0; 173 | byte[] buf = new byte[len]; 174 | while (offset < len) 175 | { 176 | actualSize = base.Read(buf, offset, len - offset); 177 | offset += actualSize; 178 | } 179 | return buf; 180 | } 181 | 182 | public abstract bool isLittleEndian(); 183 | public abstract Long2 readLong2(); 184 | public abstract Double2 readDouble2(); 185 | } 186 | 187 | } -------------------------------------------------------------------------------- /src/io/BigEndianDataInputStream.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | 4 | namespace dolphindb.io 5 | { 6 | 7 | 8 | public class BigEndianDataInputStream : AbstractExtendedDataInputStream 9 | { 10 | 11 | public BigEndianDataInputStream(Stream @in) : base(@in) 12 | { 13 | 14 | } 15 | 16 | public override bool isLittleEndian() 17 | { 18 | return false; 19 | } 20 | 21 | public override int readInt() 22 | { 23 | byte b1 = readAndCheckByte(); 24 | byte b2 = readAndCheckByte(); 25 | byte b3 = readAndCheckByte(); 26 | byte b4 = readAndCheckByte(); 27 | return fromBytes(b1, b2, b3, b4); 28 | 29 | } 30 | 31 | public override long readLong() 32 | { 33 | byte b1 = readAndCheckByte(); 34 | byte b2 = readAndCheckByte(); 35 | byte b3 = readAndCheckByte(); 36 | byte b4 = readAndCheckByte(); 37 | byte b5 = readAndCheckByte(); 38 | byte b6 = readAndCheckByte(); 39 | byte b7 = readAndCheckByte(); 40 | byte b8 = readAndCheckByte(); 41 | return fromBytes(b1, b2, b3, b4, b5, b6, b7, b8); 42 | } 43 | 44 | public override Long2 readLong2() 45 | { 46 | 47 | long high = readLong(); 48 | long low = readLong(); 49 | return new Long2(high, low); 50 | } 51 | public override Double2 readDouble2() 52 | { 53 | double image = readDouble(); 54 | double real = readDouble(); 55 | return new Double2(real, image); 56 | } 57 | 58 | public override int readUnsignedShort() 59 | { 60 | byte b1 = readAndCheckByte(); 61 | byte b2 = readAndCheckByte(); 62 | return fromBytes(b1, b2, (byte)0, (byte)0); 63 | } 64 | } 65 | 66 | } -------------------------------------------------------------------------------- /src/io/BigEndianDataOutputStream.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | 4 | namespace dolphindb.io 5 | { 6 | 7 | 8 | public class BigEndianDataOutputStream : AbstractExtendedDataOutputStream 9 | { 10 | 11 | public BigEndianDataOutputStream(Stream outStream) : base(outStream) 12 | { 13 | } 14 | 15 | public override void writeShort(int v) 16 | { 17 | write(0xff & (v >> 8)); 18 | write(0xff & v); 19 | } 20 | 21 | public override void writeInt(int v) 22 | { 23 | write(0xFF & (v >> 24)); 24 | write(0xFF & (v >> 16)); 25 | write(0xFF & (v >> 8)); 26 | write(0xFF & v); 27 | 28 | 29 | } 30 | 31 | public override void writeLong(long v) 32 | { 33 | write((int)(0xFF & (v >> 56))); 34 | write((int)(0xFF & (v >> 48))); 35 | write((int)(0xFF & (v >> 40))); 36 | write((int)(0xFF & (v >> 32))); 37 | write((int)(0xFF & (v >> 24))); 38 | write((int)(0xFF & (v >> 16))); 39 | write((int)(0xFF & (v >> 8))); 40 | write((int)(0xFF & v)); 41 | 42 | 43 | } 44 | public override void writeShortArray(short[] A, int startIdx, int len) 45 | { 46 | 47 | if (buf == null) 48 | { 49 | buf = new byte[BUF_SIZE]; 50 | } 51 | int end = startIdx + len; 52 | int pos = 0; 53 | for (int i = startIdx; i < end; ++i) 54 | { 55 | short v = A[i]; 56 | if (pos + 2 >= BUF_SIZE) 57 | { 58 | write((byte[])(Array)buf, 0, pos); 59 | pos = 0; 60 | } 61 | buf[pos++] = unchecked((byte)(0xFF & (v >> 8))); 62 | buf[pos++] = unchecked((byte)(0xFF & (v))); 63 | } 64 | if (pos > 0) 65 | { 66 | write((byte[])(Array)buf, 0, pos); 67 | } 68 | } 69 | 70 | public override void writeIntArray(int[] A, int startIdx, int len) 71 | { 72 | 73 | if (buf == null) 74 | { 75 | buf = new byte[BUF_SIZE]; 76 | } 77 | int end = startIdx + len; 78 | int pos = 0; 79 | for (int i = startIdx; i < end; ++i) 80 | { 81 | int v = A[i]; 82 | if (pos + 4 >= BUF_SIZE) 83 | { 84 | write((byte[])(Array)buf, 0, pos); 85 | pos = 0; 86 | } 87 | buf[pos++] = unchecked((byte)(0xFF & (v >> 24))); 88 | buf[pos++] = unchecked((byte)(0xFF & (v >> 16))); 89 | buf[pos++] = unchecked((byte)(0xFF & (v >> 8))); 90 | buf[pos++] = unchecked((byte)(0xFF & (v))); 91 | } 92 | if (pos > 0) 93 | { 94 | write((byte[])(Array)buf, 0, pos); 95 | } 96 | } 97 | 98 | public override void writeLongArray(long[] A, int startIdx, int len) 99 | { 100 | if (buf == null) 101 | { 102 | buf = new byte[BUF_SIZE]; 103 | } 104 | int end = startIdx + len; 105 | int pos = 0; 106 | for (int i = startIdx; i < end; ++i) 107 | { 108 | long v = A[i]; 109 | if (pos + 8 >= BUF_SIZE) 110 | { 111 | write((byte[])(Array)buf, 0, pos); 112 | pos = 0; 113 | } 114 | buf[pos++] = unchecked((byte)(0xFF & (v >> 56))); 115 | buf[pos++] = unchecked((byte)(0xFF & (v >> 48))); 116 | buf[pos++] = unchecked((byte)(0xFF & (v >> 40))); 117 | buf[pos++] = unchecked((byte)(0xFF & (v >> 32))); 118 | buf[pos++] = unchecked((byte)(0xFF & (v >> 24))); 119 | buf[pos++] = unchecked((byte)(0xFF & (v >> 16))); 120 | buf[pos++] = unchecked((byte)(0xFF & (v >> 8))); 121 | buf[pos++] = unchecked((byte)(0xFF & (v))); 122 | } 123 | if (pos > 0) 124 | { 125 | write((byte[])(Array)buf, 0, pos); 126 | } 127 | } 128 | 129 | public override void writeLong2Array(Long2[] A, int startIdx, int len) 130 | { 131 | if (longBuf == null) 132 | { 133 | longBuf = new long[longBufSize]; 134 | } 135 | int end = startIdx + len; 136 | int pos = 0; 137 | for (int i = startIdx; i < end; ++i) 138 | { 139 | if (pos >= longBufSize) 140 | { 141 | writeLongArray(longBuf, 0, pos); 142 | pos = 0; 143 | } 144 | longBuf[pos++] = A[i].high; 145 | longBuf[pos++] = A[i].low; 146 | } 147 | if (pos > 0) 148 | writeLongArray(longBuf, 0, pos); 149 | } 150 | 151 | public override void writeDouble2Array(Double2[] A, int startIdx, int len) 152 | { 153 | if (doubleBuf == null) 154 | { 155 | doubleBuf = new double[doubleBufSize]; 156 | } 157 | int end = startIdx + len; 158 | int pos = 0; 159 | for (int i = startIdx; i < end; ++i) 160 | { 161 | if (pos >= doubleBufSize) 162 | { 163 | writeDoubleArray(doubleBuf, 0, pos); 164 | pos = 0; 165 | } 166 | doubleBuf[pos++] = A[i].y; 167 | doubleBuf[pos++] = A[i].x; 168 | } 169 | if (pos > 0) 170 | writeDoubleArray(doubleBuf, 0, pos); 171 | } 172 | 173 | 174 | public override void writeLong2(Long2 v) 175 | { 176 | writeLong(v.high); 177 | writeLong(v.low); 178 | } 179 | 180 | public override void writeDouble2(Double2 v) 181 | { 182 | writeDouble(v.y); 183 | writeDouble(v.x); 184 | } 185 | 186 | public override bool isLittleEndian() 187 | { 188 | return false; 189 | } 190 | 191 | } 192 | 193 | } -------------------------------------------------------------------------------- /src/io/Double2.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using dolphindb.data; 3 | 4 | namespace dolphindb.io 5 | { 6 | 7 | public struct Double2 8 | { 9 | public double x; 10 | public double y; 11 | 12 | public Double2(double x = -double.MaxValue, double y = -double.MaxValue) 13 | { 14 | this.x = x; 15 | this.y = y; 16 | } 17 | 18 | public bool isNull() 19 | { 20 | return x == -double.MaxValue && y == -double.MaxValue; 21 | } 22 | 23 | public void setNull() 24 | { 25 | x = -double.MaxValue; 26 | y = -double.MaxValue; 27 | } 28 | 29 | public bool equals(object o) 30 | { 31 | if (!(o is Double2) || o == null) 32 | return false; 33 | else 34 | return x == ((Double2)o).x && y == ((Double2)o).y; 35 | } 36 | 37 | public int hashBucket(int buckets) 38 | { 39 | return -1; 40 | } 41 | 42 | public override bool Equals(object o) 43 | { 44 | if (!(o is Double2) || o == null) 45 | { 46 | return false; 47 | } 48 | else 49 | { 50 | if (this.x != ((Double2)o).x || this.y != ((Double2)o).y) 51 | { 52 | return false; 53 | } 54 | else 55 | return true; 56 | } 57 | } 58 | 59 | public override int GetHashCode() 60 | { 61 | return new BasicDouble(x).GetHashCode() ^ new BasicDouble(y).GetHashCode(); 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/io/ExtendedDataInput.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | 3 | namespace dolphindb.io 4 | { 5 | 6 | 7 | public interface ExtendedDataInput 8 | { 9 | bool isLittleEndian(); 10 | 11 | bool readBoolean(); 12 | 13 | byte readByte(); 14 | 15 | long readLong(); 16 | 17 | int readInt(); 18 | 19 | char readChar(); 20 | 21 | double readDouble(); 22 | 23 | float readFloat(); 24 | 25 | void readFully(byte[] arg0); 26 | 27 | void readFully(byte[] arg0, int arg1, int arg2); 28 | 29 | string readLine(); 30 | 31 | string readString(); 32 | 33 | short readShort(); 34 | 35 | int readUnsignedByte(); 36 | 37 | int skipBytes(int n); 38 | 39 | Long2 readLong2(); 40 | 41 | Double2 readDouble2(); 42 | 43 | //2021.01.19 cwj 44 | byte[] readBlob(); 45 | 46 | } 47 | } -------------------------------------------------------------------------------- /src/io/ExtendedDataOutput.cs: -------------------------------------------------------------------------------- 1 | namespace dolphindb.io 2 | { 3 | 4 | 5 | public interface ExtendedDataOutput 6 | { 7 | void write(byte[] b); 8 | void writeShort(int s); 9 | void writeString(string str); 10 | 11 | //2021.01.19 cwj 12 | void writeBlob(byte[] value); 13 | // 14 | 15 | void flush(); 16 | void writeShortArray(short[] A); 17 | void writeShortArray(short[] A, int startIdx, int len); 18 | void writeIntArray(int[] A); 19 | void writeIntArray(int[] A, int startIdx, int len); 20 | void writeLongArray(long[] A); 21 | void writeLongArray(long[] A, int startIdx, int len); 22 | void writeDoubleArray(double[] A); 23 | void writeDoubleArray(double[] A, int startIdx, int len); 24 | void writeFloatArray(float[] A); 25 | void writeFloatArray(float[] A, int startIdx, int len); 26 | void writeStringArray(string[] A); 27 | void writeStringArray(string[] A, int startIdx, int len); 28 | void writeLong2Array(Long2[] A); 29 | void writeLong2Array(Long2[] A, int startIdx, int len); 30 | 31 | void writeDouble2Array(Double2[] A); 32 | void writeDouble2Array(Double2[] A, int startIdx, int len); 33 | 34 | void writeBoolean(bool v); 35 | void writeByte(int v); 36 | void writeChar(char v); 37 | void writeFloat(float v); 38 | void writeDouble(double v); 39 | void writeBytes(string s); 40 | void writeChars(string s); 41 | void writeUTF(string value); 42 | void writeInt(int value); 43 | void writeLong(long value); 44 | void writeLong2(Long2 v); 45 | 46 | void writeDouble2(Double2 v); 47 | 48 | bool isLittleEndian(); 49 | void write(byte[] b, int offset, int length); 50 | } 51 | } -------------------------------------------------------------------------------- /src/io/LittleEndianDataInputStream.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | namespace dolphindb.io 4 | { 5 | 6 | 7 | public class LittleEndianDataInputStream : AbstractExtendedDataInputStream 8 | { 9 | 10 | public LittleEndianDataInputStream(Stream @in) : base(@in) 11 | { 12 | } 13 | 14 | public override int readInt() 15 | { 16 | byte b1 = readAndCheckByte(); 17 | byte b2 = readAndCheckByte(); 18 | byte b3 = readAndCheckByte(); 19 | byte b4 = readAndCheckByte(); 20 | return fromBytes(b4, b3, b2, b1); 21 | } 22 | 23 | public override long readLong() 24 | { 25 | byte b1 = readAndCheckByte(); 26 | byte b2 = readAndCheckByte(); 27 | byte b3 = readAndCheckByte(); 28 | byte b4 = readAndCheckByte(); 29 | byte b5 = readAndCheckByte(); 30 | byte b6 = readAndCheckByte(); 31 | byte b7 = readAndCheckByte(); 32 | byte b8 = readAndCheckByte(); 33 | return fromBytes(b8, b7, b6, b5, b4, b3, b2, b1); 34 | } 35 | 36 | public override Long2 readLong2() 37 | { 38 | long low = readLong(); 39 | long high = readLong(); 40 | return new Long2(high, low); 41 | } 42 | public override Double2 readDouble2() 43 | { 44 | double real = readDouble(); 45 | double image = readDouble(); 46 | return new Double2(real, image); 47 | } 48 | 49 | public override int readUnsignedShort() 50 | { 51 | byte b1 = readAndCheckByte(); 52 | byte b2 = readAndCheckByte(); 53 | return fromBytes((byte)0, (byte)0, b2, b1); 54 | } 55 | 56 | public override bool isLittleEndian() 57 | { 58 | return true; 59 | } 60 | 61 | } 62 | 63 | 64 | } -------------------------------------------------------------------------------- /src/io/LittleEndianDataOutputStream.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | 5 | namespace dolphindb.io 6 | { 7 | 8 | 9 | public class LittleEndianDataOutputStream : AbstractExtendedDataOutputStream 10 | { 11 | 12 | public LittleEndianDataOutputStream(Stream outStream) : base(outStream) 13 | { 14 | } 15 | 16 | public override void writeShort(int v) 17 | { 18 | write(0xFF & v); 19 | write(0xFF & (v >> 8)); 20 | } 21 | 22 | 23 | public override void writeInt(int v) 24 | { 25 | write(0xFF & v); 26 | write(0xFF & (v >> 8)); 27 | write(0xFF & (v >> 16)); 28 | write(0xFF & (v >> 24)); 29 | } 30 | 31 | public override void writeLong(long v) 32 | { 33 | write((int)(0xFF & v)); 34 | write((int)(0xFF & (v >> 8))); 35 | write((int)(0xFF & (v >> 16))); 36 | write((int)(0xFF & (v >> 24))); 37 | write((int)(0xFF & (v >> 32))); 38 | write((int)(0xFF & (v >> 40))); 39 | write((int)(0xFF & (v >> 48))); 40 | write((int)(0xFF & (v >> 56))); 41 | } 42 | 43 | public override void writeLong2(Long2 v) 44 | { 45 | writeLong(v.low); 46 | writeLong(v.high); 47 | } 48 | public override void writeDouble2(Double2 v) 49 | { 50 | writeDouble(v.x); 51 | writeDouble(v.y); 52 | } 53 | 54 | public override void writeIntArray(int[] A, int startIdx, int len) 55 | { 56 | List byteSource = new List(); 57 | for (int i = startIdx; i < startIdx + len; i++) 58 | { 59 | byteSource.AddRange(BitConverter.GetBytes(A[i])); 60 | } 61 | base.write(byteSource.ToArray()); 62 | 63 | /* 64 | if (buf == null) 65 | { 66 | buf = new byte[BUF_SIZE]; 67 | } 68 | int end = startIdx + len; 69 | int pos = 0; 70 | for (int i = startIdx; i < end; ++i) 71 | { 72 | int v = A[i]; 73 | if (pos + 4 >= BUF_SIZE) 74 | { 75 | write((byte[])(Array)buf, 0, pos); 76 | pos = 0; 77 | } 78 | buf[pos++] = unchecked((byte)(0xFF & (v))); 79 | buf[pos++] = unchecked((byte)(0xFF & (v >> 8))); 80 | buf[pos++] = unchecked((byte)(0xFF & (v >> 16))); 81 | buf[pos++] = unchecked((byte)(0xFF & (v >> 24))); 82 | } 83 | if (pos > 0) 84 | { 85 | write((byte[])(Array)buf, 0, pos); 86 | } 87 | */ 88 | } 89 | 90 | 91 | public override void writeShortArray(short[] A, int startIdx, int len) 92 | { 93 | if (buf == null) 94 | { 95 | buf = new byte[BUF_SIZE]; 96 | } 97 | int end = startIdx + len; 98 | int pos = 0; 99 | for (int i = startIdx; i < end; ++i) 100 | { 101 | short v = A[i]; 102 | if (pos + 2 >= BUF_SIZE) 103 | { 104 | write((byte[])(Array)buf, 0, pos); 105 | pos = 0; 106 | } 107 | buf[pos++] = unchecked((byte)(0xFF & (v))); 108 | buf[pos++] = unchecked((byte)(0xFF & (v >> 8))); 109 | } 110 | if (pos > 0) 111 | { 112 | write((byte[])(Array)buf, 0, pos); 113 | } 114 | } 115 | 116 | public override void writeLongArray(long[] A, int startIdx, int len) 117 | { 118 | if (buf == null) 119 | { 120 | buf = new byte[BUF_SIZE]; 121 | } 122 | int end = startIdx + len; 123 | int pos = 0; 124 | for (int i = startIdx; i < end; ++i) 125 | { 126 | long v = A[i]; 127 | if (pos + 8 >= BUF_SIZE) 128 | { 129 | write((byte[])(Array)buf, 0, pos); 130 | pos = 0; 131 | } 132 | buf[pos++] = unchecked((byte)(0xFF & (v))); 133 | buf[pos++] = unchecked((byte)(0xFF & (v >> 8))); 134 | buf[pos++] = unchecked((byte)(0xFF & (v >> 16))); 135 | buf[pos++] = unchecked((byte)(0xFF & (v >> 24))); 136 | buf[pos++] = unchecked((byte)(0xFF & (v >> 32))); 137 | buf[pos++] = unchecked((byte)(0xFF & (v >> 40))); 138 | buf[pos++] = unchecked((byte)(0xFF & (v >> 48))); 139 | buf[pos++] = unchecked((byte)(0xFF & (v >> 56))); 140 | } 141 | if (pos > 0) 142 | { 143 | write((byte[])(Array)buf, 0, pos); 144 | } 145 | } 146 | 147 | 148 | public override void writeLong2Array(Long2[] A, int startIdx, int len) 149 | { 150 | if (longBuf == null) 151 | { 152 | longBuf = new long[longBufSize]; 153 | } 154 | int end = startIdx + len; 155 | int pos = 0; 156 | for (int i = startIdx; i < end; ++i) 157 | { 158 | if (pos >= longBufSize) 159 | { 160 | 161 | writeLongArray(longBuf, 0, pos); 162 | pos = 0; 163 | } 164 | longBuf[pos++] = A[i].low; 165 | longBuf[pos++] = A[i].high; 166 | } 167 | if (pos > 0) 168 | 169 | writeLongArray(longBuf, 0, pos); 170 | } 171 | 172 | public override void writeDouble2Array(Double2[] A, int startIdx, int len) 173 | { 174 | if (doubleBuf == null) 175 | { 176 | doubleBuf = new double[doubleBufSize]; 177 | } 178 | int end = startIdx + len; 179 | int pos = 0; 180 | for (int i = startIdx; i < end; ++i) 181 | { 182 | if (pos >= doubleBufSize) 183 | { 184 | 185 | writeDoubleArray(doubleBuf, 0, pos); 186 | pos = 0; 187 | } 188 | doubleBuf[pos++] = A[i].x; 189 | doubleBuf[pos++] = A[i].y; 190 | } 191 | if (pos > 0) 192 | writeDoubleArray(doubleBuf, 0, pos); 193 | } 194 | 195 | public override bool isLittleEndian() 196 | { 197 | return true; 198 | } 199 | } 200 | 201 | } -------------------------------------------------------------------------------- /src/route/AutoFitTableUpsert.cs: -------------------------------------------------------------------------------- 1 | using dolphindb; 2 | using dolphindb.data; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace dolphindb_csharpapi_net_core.src.route 8 | { 9 | public class AutoFitTableUpsert 10 | { 11 | private DBConnection connection_; 12 | private string upsertScript_; 13 | private int cols_; 14 | private List columnCategories_ = new List(); 15 | private List columnTypes_ = new List(); 16 | private List colNames_ = new List(); 17 | 18 | public AutoFitTableUpsert(string dbUrl, string tableName, DBConnection connection, bool ignoreNull, string[] pkeyColNames, string[] psortColumns) 19 | { 20 | connection_ = connection; 21 | BasicTable colDefs; 22 | BasicIntVector colTypesInt; 23 | BasicDictionary tableInfo; 24 | BasicStringVector colNames; 25 | string task; 26 | if (dbUrl.Equals("")) 27 | { 28 | task = "schema(" + tableName + ")"; 29 | upsertScript_ = "upsert!{" + tableName + ""; 30 | } 31 | else 32 | { 33 | task = "schema(loadTable(\"" + dbUrl + "\", \"" + tableName + "\"))"; 34 | upsertScript_ = "upsert!{loadTable('" + dbUrl + "', '" + tableName + "')"; 35 | } 36 | upsertScript_ += ","; 37 | if (!ignoreNull) 38 | upsertScript_ += ",ignoreNull=false"; 39 | else 40 | upsertScript_ += ",ignoreNull=true"; 41 | int ignoreParamCount = 0; 42 | if (pkeyColNames != null && pkeyColNames.Length > 0) 43 | { 44 | upsertScript_ += ",keyColNames="; 45 | foreach (string one in pkeyColNames) 46 | { 47 | upsertScript_ += "`" + one; 48 | } 49 | } 50 | else 51 | { 52 | ignoreParamCount++; 53 | } 54 | if (psortColumns != null && psortColumns.Length > 0) 55 | { 56 | while (ignoreParamCount > 0) 57 | { 58 | upsertScript_ += ","; 59 | ignoreParamCount--; 60 | } 61 | upsertScript_ += ",sortColumns="; 62 | foreach (string one in psortColumns) 63 | { 64 | upsertScript_ += "`" + one; 65 | } 66 | } 67 | upsertScript_ += "}"; 68 | tableInfo = (BasicDictionary)connection_.run(task); 69 | colDefs = (BasicTable)tableInfo.get(new BasicString("colDefs")); 70 | cols_ = colDefs.rows(); 71 | colTypesInt = (BasicIntVector)colDefs.getColumn("typeInt"); 72 | colNames = (BasicStringVector)colDefs.getColumn("name"); 73 | for (int i = 0; i < cols_; i++) 74 | { 75 | columnTypes_.Add((DATA_TYPE)colTypesInt.getInt(i)); 76 | columnCategories_.Add(Utils.getCategory(columnTypes_[i])); 77 | colNames_.Add(colNames.getString(i)); 78 | } 79 | 80 | } 81 | 82 | public int upsert(BasicTable table) 83 | { 84 | if (cols_ != table.columns()) 85 | throw new Exception("The input table columns doesn't match the columns of the target table."); 86 | List colums = new List (); 87 | for (int i = 0; i < cols_; i++) 88 | { 89 | IVector curCol = table.getColumn(i); 90 | checkColumnType(i, curCol.getDataCategory(), curCol.getDataType()); 91 | if (columnCategories_[i] == DATA_CATEGORY.TEMPORAL && curCol.getDataType() != columnTypes_[i]) 92 | { 93 | colums.Add((IVector)Utils.castDateTime(curCol, columnTypes_[i])); 94 | } 95 | else 96 | { 97 | colums.Add(curCol); 98 | } 99 | } 100 | BasicTable tableToInsert = new BasicTable(colNames_, colums); 101 | List args = new List(); 102 | args.Add(tableToInsert); 103 | IEntity res = connection_.run(upsertScript_, args); 104 | if (res.getDataType() == DATA_TYPE.DT_INT && res.getDataForm() == DATA_FORM.DF_SCALAR) 105 | { 106 | return ((BasicInt)res).getInt(); 107 | } 108 | else 109 | return 0; 110 | } 111 | 112 | private void checkColumnType(int col, DATA_CATEGORY category, DATA_TYPE type) 113 | { 114 | if (columnTypes_[col] != type && columnTypes_[col] != DATA_TYPE.DT_IOTANY) 115 | { 116 | DATA_CATEGORY expectCateGory = columnCategories_[col]; 117 | if (category != expectCateGory) 118 | throw new Exception("column " + col + ", expect category " + expectCateGory + ", got category " + category); 119 | } 120 | } 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /src/route/DBVersion.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace dolphindb.route 7 | { 8 | internal class DBVersion 9 | { 10 | int[] v = null; 11 | string version = null; 12 | public DBVersion() { } 13 | 14 | public DBVersion(string version) 15 | { 16 | v = new int[4]; 17 | this.version = version; 18 | string[] parts = version.Split(' ')[0].Split('.'); 19 | v[0] = int.Parse(parts[0]); 20 | v[1] = int.Parse(parts[1]); 21 | v[2] = int.Parse(parts[2]); 22 | if (parts.Length > 3) 23 | { 24 | v[3] = int.Parse(parts[3]); 25 | } 26 | } 27 | 28 | public int getVerNum() 29 | { 30 | try 31 | { 32 | string[] s = version.Split(' '); 33 | if (s.Length >= 2) 34 | { 35 | string vernum = s[0].Replace(".", ""); 36 | return int.Parse(vernum); 37 | } 38 | } 39 | catch (Exception) 40 | { 41 | } 42 | return 0; 43 | } 44 | 45 | public string getVersion() { return version; } 46 | 47 | public int getSubV(int index) 48 | { 49 | return v[index]; 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/streaming/BasicMessage.cs: -------------------------------------------------------------------------------- 1 | using dolphindb.data; 2 | 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace dolphindb.streaming 9 | { 10 | public class BasicMessage : IMessage 11 | { 12 | private long offset = 0; 13 | private string topic = ""; 14 | private BasicAnyVector msg = null; 15 | private string sym_; 16 | private List colsName_; 17 | 18 | public BasicMessage(long offset, string topic, BasicAnyVector msg, string sym = "", List colNames = null) 19 | { 20 | this.offset = offset; 21 | this.topic = topic; 22 | this.msg = msg; 23 | this.sym_ = sym; 24 | this.colsName_ = colNames; 25 | } 26 | 27 | public T getValue(int colIndex) 28 | { 29 | return (T)msg.getEntity(colIndex); 30 | } 31 | 32 | public string getTopic() 33 | { 34 | return topic; 35 | } 36 | 37 | public long getOffset() 38 | { 39 | return offset; 40 | } 41 | 42 | public IEntity getEntity(int colIndex) 43 | { 44 | return msg.getEntity(colIndex); 45 | } 46 | 47 | public int size() 48 | { 49 | return msg.rows(); 50 | } 51 | 52 | public string getSym() 53 | { 54 | return sym_; 55 | } 56 | 57 | public BasicTable getTable() 58 | { 59 | if (colsName_ == null) { 60 | throw new Exception("The getTable method must be used when msgAsTable is true. "); 61 | } 62 | List cols = new List (); 63 | int rows = msg.rows(); 64 | for(int i = 0; i < rows; ++i) 65 | { 66 | cols.Add((IVector)msg.getEntity(i)); 67 | } 68 | return new BasicTable(colsName_, cols); 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/streaming/IMessage.cs: -------------------------------------------------------------------------------- 1 | using dolphindb.data; 2 | 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace dolphindb.streaming 9 | { 10 | public interface IMessage 11 | { 12 | string getTopic(); 13 | long getOffset(); 14 | IEntity getEntity(int colIndex); 15 | T getValue(int colIndex); 16 | 17 | BasicTable getTable(); 18 | 19 | int size(); 20 | string getSym(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/streaming/MessageDispatcher.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Collections.Concurrent; 6 | using dolphindb.data; 7 | 8 | namespace dolphindb.streaming 9 | { 10 | public enum ConnectState { NO_CONNECT, REQUEST, RECEIVED_SCHEMA }; 11 | public interface MessageDispatcher 12 | { 13 | void dispatch(IMessage message); 14 | void batchDispatch(List message); 15 | bool tryReconnect(SubscribeInfo subscribeInfo); 16 | ConcurrentDictionary getSubscribeInfos(); 17 | List getActiveSites(Site[] sites); 18 | string getTopicForHATopic(string HATopic); 19 | bool isClose(); 20 | } 21 | 22 | public class SubscribeInfo 23 | { 24 | private DateTime lastActivateTime_; 25 | private BlockingCollection> queue_; 26 | private ConnectState connectState_ = ConnectState.NO_CONNECT; 27 | private Site[] sites_; 28 | private string topic_; 29 | private long msgId_; 30 | private bool reconnect_; 31 | private IVector filter_; 32 | private bool closed_ = false; 33 | private MessageHandler messageHandler_; 34 | private string tableName_; 35 | private string actionName_; 36 | private StreamDeserializer deserializer_; 37 | private string user_; 38 | private string password_; 39 | private bool msgAsTable_; 40 | private List colsName_; 41 | 42 | public SubscribeInfo(DateTime activate, BlockingCollection> queue, Site[] sites, string topic, long msgId, bool reconnect, IVector filter, 43 | MessageHandler messageHandler, string tableName, string actionName, StreamDeserializer deserializer, string user, string password, bool msgAsTable_, List colsName) 44 | { 45 | lastActivateTime_ = activate; 46 | this.queue_ = queue; 47 | connectState_ = ConnectState.NO_CONNECT; 48 | this.sites_ = sites; 49 | this.topic_ = topic; 50 | this.msgId_ = msgId; 51 | this.reconnect_ = reconnect; 52 | this.filter_ = filter; 53 | this.messageHandler_ = messageHandler; 54 | this.tableName_ = tableName; 55 | this.actionName_ = actionName; 56 | deserializer_ = deserializer; 57 | user_ = user; 58 | password_ = password; 59 | this.msgAsTable_ = msgAsTable_; 60 | this.colsName_ = colsName; 61 | } 62 | 63 | public string getTopic() 64 | { 65 | return topic_; 66 | } 67 | 68 | public void setConnectState(ConnectState connectState) 69 | { 70 | connectState_ = connectState; 71 | } 72 | 73 | public ConnectState getConnectState() 74 | { 75 | return connectState_; 76 | } 77 | 78 | public void setActivateTime(DateTime ActivateTime) 79 | { 80 | lastActivateTime_ = ActivateTime; 81 | } 82 | 83 | public DateTime getLastActivateTime() 84 | { 85 | return lastActivateTime_; 86 | } 87 | 88 | public Site[] getSites() 89 | { 90 | return sites_; 91 | } 92 | 93 | public BlockingCollection> getQueue() 94 | { 95 | return queue_; 96 | } 97 | 98 | public string getTableName() 99 | { 100 | return tableName_; 101 | } 102 | 103 | public string getActionName() 104 | { 105 | return actionName_; 106 | } 107 | 108 | public MessageHandler getMessageHandler() 109 | { 110 | return messageHandler_; 111 | } 112 | 113 | public long getMsgId() 114 | { 115 | return msgId_; 116 | } 117 | 118 | public IVector getFilter() 119 | { 120 | return filter_; 121 | } 122 | 123 | public void setMsgId(long msgId) 124 | { 125 | msgId_ = msgId; 126 | } 127 | 128 | public void close() 129 | { 130 | closed_ = true; 131 | } 132 | 133 | public bool isClose() 134 | { 135 | return closed_; 136 | } 137 | 138 | public StreamDeserializer getDeseriaLizer() 139 | { 140 | return deserializer_; 141 | } 142 | public string getUser() 143 | { 144 | return user_; 145 | } 146 | 147 | public string getPassword() 148 | { 149 | return password_; 150 | } 151 | 152 | public bool getMsgAsTable() 153 | { 154 | return msgAsTable_; 155 | } 156 | 157 | public List getColsName() 158 | { 159 | return colsName_; 160 | } 161 | } 162 | 163 | public struct Site 164 | { 165 | public string host; 166 | public int port; 167 | 168 | public Site(string host, int port) 169 | { 170 | this.host = host; 171 | this.port = port; 172 | } 173 | } 174 | } 175 | -------------------------------------------------------------------------------- /src/streaming/PollingClient.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Collections.Concurrent; 4 | using System.Linq; 5 | using System.Text; 6 | using dolphindb.data; 7 | using System.Threading; 8 | 9 | namespace dolphindb.streaming 10 | { 11 | public class PollingClient : AbstractClient 12 | { 13 | //private TopicPoller topicPoller = null; 14 | 15 | public PollingClient(int subscribePort) : base(DEFAULT_HOST, subscribePort) { } 16 | 17 | public PollingClient(string subscribeHost, int subscribePort) : base(subscribeHost, subscribePort) { } 18 | 19 | override protected bool doReconnect(SubscribeInfo subscribeInfo, Site site) 20 | { 21 | try 22 | { 23 | BlockingCollection> queue = subscribeInternal(site.host, site.port, subscribeInfo.getTableName(), subscribeInfo.getActionName(), null, subscribeInfo.getMsgId() + 1, true, subscribeInfo.getFilter(), subscribeInfo.getDeseriaLizer(), subscribeInfo.getUser(), subscribeInfo.getPassword(), false, subscribeInfo.getMsgAsTable()); 24 | Console.WriteLine("Successfully reconnected and subscribed " + site.host + ":" + site.port + ":" + subscribeInfo.getTableName()); 25 | return true; 26 | } 27 | catch (Exception ex) 28 | { 29 | Console.WriteLine(ex.ToString()); 30 | } 31 | return false; 32 | } 33 | 34 | public TopicPoller subscribe(string host, int port, string tableName, string actionName, long offset, bool reconnect, IVector filter, StreamDeserializer deserializer = null, string user = "", string password = "", bool msgAsTable = false) 35 | { 36 | BlockingCollection> queue = subscribeInternal(host, port, tableName, actionName, null, offset, reconnect, filter, deserializer, user, password, true, msgAsTable); 37 | return new TopicPoller(queue); 38 | } 39 | 40 | 41 | public TopicPoller subscribe(string host, int port, string tableName, string actionName, long offset, bool reconnect) 42 | { 43 | return subscribe(host, port, tableName, actionName, offset, reconnect, null); 44 | } 45 | 46 | public TopicPoller subscribe(string host, int port, string tableName, string actionName, long offset, IVector filter) 47 | { 48 | return subscribe(host, port, tableName, actionName, offset, false, filter); 49 | } 50 | 51 | public TopicPoller subscribe(string host, int port, string tableName, string actionName, long offset) 52 | { 53 | return subscribe(host, port, tableName, actionName, offset, false, null); 54 | } 55 | 56 | public TopicPoller subscribe(string host, int port, string tableName, long offset, bool reconnect) 57 | { 58 | return subscribe(host, port, tableName, DEFAULT_ACTION_NAME, offset, reconnect); 59 | } 60 | 61 | public TopicPoller subscribe(string host, int port, string tableName, long offset) 62 | { 63 | return subscribe(host, port, tableName, DEFAULT_ACTION_NAME, offset); 64 | } 65 | 66 | public TopicPoller subscribe(string host, int port, string tableName) 67 | { 68 | return subscribe(host, port, tableName, -1); 69 | } 70 | 71 | public TopicPoller subscribe(string host, int port, string tableName, string actionName) 72 | { 73 | return subscribe(host, port, tableName, actionName, -1); 74 | } 75 | 76 | public void unsubscribe(string host, int port, string tableName, string actionName) 77 | { 78 | unsubscribeInternal(host, port, tableName, actionName); 79 | } 80 | 81 | public void unsubscribe(string host, int port, string tableName) 82 | { 83 | unsubscribeInternal(host, port, tableName, DEFAULT_ACTION_NAME); 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/streaming/StreamDeserializer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Collections.Concurrent; 6 | using dolphindb.data; 7 | using dolphindb.io; 8 | using System.IO; 9 | 10 | namespace dolphindb.streaming 11 | { 12 | public class StreamDeserializer 13 | { 14 | Dictionary msgDeserializers_; 15 | Dictionary> tableNames_; 16 | 17 | public BasicMessage parse(IMessage message) 18 | { 19 | if (msgDeserializers_ == null) 20 | throw new Exception("The StreamDeserializer is not inited. "); 21 | if (message.size() < 3) 22 | throw new Exception("The data must contain 3 columns. "); 23 | if (message.getEntity(1).getDataType() != DATA_TYPE.DT_SYMBOL && message.getEntity(1).getDataType() != DATA_TYPE.DT_STRING) 24 | throw new Exception("The 2rd column must be a vector type with symbol or string. "); 25 | if (message.getEntity(2).getDataType() != DATA_TYPE.DT_BLOB) 26 | throw new Exception("The 3rd column must be a vector type with blob. "); 27 | 28 | string sym = message.getEntity(1).getString(); 29 | byte[] blob = ((BasicString)message.getEntity(2)).getBytes(); 30 | MsgDeserializer deserializer = null; 31 | if (!msgDeserializers_.TryGetValue(sym, out deserializer)) 32 | { 33 | throw new Exception("The filter " + sym + " does not exist. "); 34 | } 35 | BasicMessage mixedMessage = new BasicMessage(message.getOffset(), message.getTopic(), deserializer.parse(blob), sym); 36 | return mixedMessage; 37 | } 38 | 39 | public StreamDeserializer(Dictionary> filters) 40 | { 41 | msgDeserializers_ = new Dictionary(); 42 | foreach (KeyValuePair> keyValue in filters) 43 | { 44 | List colTypes = keyValue.Value; 45 | msgDeserializers_[keyValue.Key] =new MsgDeserializer(colTypes); 46 | } 47 | } 48 | 49 | public StreamDeserializer(Dictionary filters) 50 | { 51 | init(filters); 52 | } 53 | 54 | public StreamDeserializer(Dictionary> tableNames, DBConnection conn = null) 55 | { 56 | tableNames_ = tableNames; 57 | if (conn != null) 58 | init(conn); 59 | } 60 | 61 | void init(Dictionary filters) 62 | { 63 | msgDeserializers_ = new Dictionary(); 64 | foreach (KeyValuePair keyValue in filters) 65 | { 66 | List colTypes = new List(); 67 | List colNames = new List(); 68 | 69 | BasicTable colDefs = (BasicTable)keyValue.Value.get("colDefs"); 70 | BasicIntVector colDefsTypeInt = (BasicIntVector)colDefs.getColumn("typeInt"); 71 | BasicDictionary data = keyValue.Value; 72 | for (int i = 0; i < colDefsTypeInt.rows(); ++i) 73 | { 74 | colTypes.Add((DATA_TYPE)colDefsTypeInt.getInt(i)); 75 | } 76 | msgDeserializers_[keyValue.Key] = new MsgDeserializer(colTypes); 77 | } 78 | } 79 | 80 | public void init(DBConnection conn) 81 | { 82 | if(msgDeserializers_ != null) 83 | throw new Exception("The StreamDeserializer is inited. "); 84 | if (tableNames_ == null) 85 | throw new Exception("The tableNames_ is null. "); 86 | msgDeserializers_ = new Dictionary(); 87 | Dictionary filters = new Dictionary(); 88 | foreach (KeyValuePair> value in tableNames_) 89 | { 90 | string dbName = value.Value.Item1; 91 | string tableName = value.Value.Item2; 92 | BasicDictionary schema; 93 | if (dbName == "") 94 | { 95 | schema = (BasicDictionary)conn.run("schema(" + tableName + ")"); 96 | } 97 | else 98 | { 99 | schema = (BasicDictionary)conn.run("schema(loadTable(\"" + dbName + "\",\"" + tableName + "\"))"); 100 | } 101 | filters[value.Key] = schema; 102 | } 103 | init(filters); 104 | } 105 | 106 | public bool isInited() 107 | { 108 | return msgDeserializers_ != null; 109 | } 110 | 111 | public void checkSchema(BasicDictionary schema) 112 | { 113 | BasicTable colDefs = (BasicTable)schema.get("colDefs"); 114 | BasicStringVector types = (BasicStringVector)colDefs.getColumn(1); 115 | if (colDefs.rows() < 3) 116 | throw new Exception("The data must contain 3 columns. "); 117 | if (types.getString(1) != "SYMBOL" && types.getString(1) != "STRING") 118 | throw new Exception("The 2rd column must be a vector type with symbol or string. "); 119 | if (types.getString(2) != "BLOB") 120 | throw new Exception("The 3rd column must be a vector type with blob. "); 121 | } 122 | 123 | class MsgDeserializer 124 | { 125 | List colTypes_; 126 | public MsgDeserializer(List colTypes) 127 | { 128 | colTypes_ = new List(); 129 | colTypes_.AddRange(colTypes); 130 | } 131 | 132 | public BasicAnyVector parse(byte[] data) 133 | { 134 | MemoryStream memoryStream = new MemoryStream(); 135 | ExtendedDataOutput writeStream = new BigEndianDataOutputStream(memoryStream); 136 | writeStream.writeBlob(data); 137 | LittleEndianDataInputStream dataStream = new LittleEndianDataInputStream(new MemoryStream(memoryStream.GetBuffer(), 0, (int)memoryStream.Position)); 138 | BasicEntityFactory basicEntityFactory = (BasicEntityFactory)BasicEntityFactory.instance(); 139 | 140 | int columns = colTypes_.Count; 141 | dataStream.readInt(); 142 | BasicAnyVector ret = new BasicAnyVector(columns); 143 | for (int i = 0; i < columns; ++i) 144 | { 145 | if ((int)colTypes_[i] < AbstractVector.ARRAY_VECTOR_BASE) 146 | { 147 | ret.setEntity(i, basicEntityFactory.createEntity(DATA_FORM.DF_SCALAR, colTypes_[i], dataStream, false)); 148 | } 149 | else 150 | { 151 | BasicArrayVector basicArrayVector = new BasicArrayVector(colTypes_[i], -1); 152 | basicArrayVector.deserialize(1, dataStream); 153 | ret.setEntity(i, basicArrayVector); 154 | } 155 | } 156 | return ret; 157 | } 158 | } 159 | } 160 | 161 | } 162 | -------------------------------------------------------------------------------- /test/EntityBlockReader_test.cs: -------------------------------------------------------------------------------- 1 | using dolphindb; 2 | using dolphindb.data; 3 | using dolphindb.io; 4 | using Microsoft.VisualStudio.TestTools.UnitTesting; 5 | using dolphindb_config; 6 | using System; 7 | 8 | namespace dolphindb_csharp_api_test 9 | { 10 | [TestClass] 11 | public class EntityBlockReader_test 12 | { 13 | private string SERVER = MyConfigReader.SERVER; 14 | static private int PORT = MyConfigReader.PORT; 15 | 16 | [TestMethod] 17 | public void Test_EntityBlockReader_getObject() 18 | { 19 | DBConnection db = new DBConnection(); 20 | db.connect(SERVER, PORT, "admin", "123456"); 21 | EntityBlockReader bt = (EntityBlockReader)db.run("table(1..100000 as id)", (ProgressListener)null, 4, 4, 10000); 22 | BasicTable table = (BasicTable)bt.getObject(); 23 | table = (BasicTable)bt.getObject(); 24 | } 25 | [TestMethod] 26 | public void Test_EntityBlockReader_skipALL() 27 | { 28 | DBConnection db = new DBConnection(); 29 | db.connect(SERVER, PORT, "admin", "123456"); 30 | EntityBlockReader bt = (EntityBlockReader)db.run("table(1..100000 as id)", (ProgressListener)null, 4, 4, 10000); 31 | bt.skipAll(); 32 | Assert.AreEqual(false, bt.hasNext()); 33 | } 34 | [TestMethod] 35 | public void Test_EntityBlockReader_hasNext() 36 | { 37 | DBConnection db = new DBConnection(); 38 | db.connect(SERVER, PORT, "admin", "123456"); 39 | EntityBlockReader bt = (EntityBlockReader)db.run("table(1..100000 as id)", (ProgressListener)null, 4, 4, 10000); 40 | Assert.AreEqual(true, bt.hasNext()); 41 | } 42 | [TestMethod] 43 | public void Test_EntityBlockReader_getDataForm() 44 | { 45 | DBConnection db = new DBConnection(); 46 | db.connect(SERVER, PORT, "admin", "123456"); 47 | EntityBlockReader bt = (EntityBlockReader)db.run("table(1..100000 as id)", (ProgressListener)null, 4, 4, 10000); 48 | Assert.AreEqual("DF_TABLE", bt.getDataForm().ToString()); 49 | } 50 | [TestMethod] 51 | public void Test_EntityBlockReader_getDataCategory() 52 | { 53 | DBConnection db = new DBConnection(); 54 | db.connect(SERVER, PORT, "admin", "123456"); 55 | EntityBlockReader bt = (EntityBlockReader)db.run("table(1..100000 as id)", (ProgressListener)null, 4, 4, 10000); 56 | Assert.AreEqual("MIXED", bt.getDataCategory().ToString()); 57 | } 58 | [TestMethod] 59 | public void Test_EntityBlockReader_getDataType() 60 | { 61 | DBConnection db = new DBConnection(); 62 | db.connect(SERVER, PORT, "admin", "123456"); 63 | EntityBlockReader bt = (EntityBlockReader)db.run("table(1..100000 as id)", (ProgressListener)null, 4, 4, 10000); 64 | Assert.AreEqual("DT_ANY", bt.getDataType().ToString()); 65 | } 66 | [TestMethod] 67 | public void Test_EntityBlockReader_rows() 68 | { 69 | DBConnection db = new DBConnection(); 70 | db.connect(SERVER, PORT,"admin","123456"); 71 | EntityBlockReader bt = (EntityBlockReader)db.run("table(1..100000 as id)", (ProgressListener)null, 4, 4, 10000); 72 | Assert.AreEqual(0, bt.rows()); 73 | } 74 | [TestMethod] 75 | public void Test_EntityBlockReader_columns() 76 | { 77 | DBConnection db = new DBConnection(); 78 | db.connect(SERVER, PORT, "admin", "123456"); 79 | EntityBlockReader bt = (EntityBlockReader)db.run("table(1..100000 as id)", (ProgressListener)null, 4, 4, 10000); 80 | Assert.AreEqual(0, bt.columns()); 81 | } 82 | [TestMethod] 83 | public void Test_EntityBlockReader_getString() 84 | { 85 | DBConnection db = new DBConnection(); 86 | db.connect(SERVER, PORT, "admin", "123456"); 87 | EntityBlockReader bt = (EntityBlockReader)db.run("table(1..100000 as id)", (ProgressListener)null, 4, 4, 10000); 88 | Assert.AreEqual(null, bt.getString()); 89 | } 90 | [TestMethod] 91 | public void Test_EntityBlockReader_isScalar() 92 | { 93 | DBConnection db = new DBConnection(); 94 | db.connect(SERVER, PORT, "admin", "123456"); 95 | EntityBlockReader bt = (EntityBlockReader)db.run("table(1..100000 as id)", (ProgressListener)null, 4, 4, 10000); 96 | Assert.AreEqual(false, bt.isScalar()); 97 | } 98 | [TestMethod] 99 | public void Test_EntityBlockReader_isVector() 100 | { 101 | DBConnection db = new DBConnection(); 102 | db.connect(SERVER, PORT, "admin", "123456"); 103 | EntityBlockReader bt = (EntityBlockReader)db.run("table(1..100000 as id)", (ProgressListener)null, 4, 4, 10000); 104 | Assert.AreEqual(false, bt.isVector()); 105 | } 106 | [TestMethod] 107 | public void Test_EntityBlockReader_isPair() 108 | { 109 | DBConnection db = new DBConnection(); 110 | db.connect(SERVER, PORT, "admin", "123456"); 111 | EntityBlockReader bt = (EntityBlockReader)db.run("table(1..100000 as id)", (ProgressListener)null, 4, 4, 10000); 112 | Assert.AreEqual(false, bt.isPair()); 113 | } 114 | [TestMethod] 115 | public void Test_EntityBlockReader_isTable() 116 | { 117 | DBConnection db = new DBConnection(); 118 | db.connect(SERVER, PORT, "admin", "123456"); 119 | EntityBlockReader bt = (EntityBlockReader)db.run("table(1..100000 as id)", (ProgressListener)null, 4, 4, 10000); 120 | Assert.AreEqual(true, bt.isTable()); 121 | } 122 | [TestMethod] 123 | public void Test_EntityBlockReader_isMatrix() 124 | { 125 | DBConnection db = new DBConnection(); 126 | db.connect(SERVER, PORT, "admin", "123456"); 127 | EntityBlockReader bt = (EntityBlockReader)db.run("table(1..100000 as id)", (ProgressListener)null, 4, 4, 10000); 128 | Assert.AreEqual(false, bt.isMatrix()); 129 | } 130 | [TestMethod] 131 | public void Test_EntityBlockReader_isDictionary() 132 | { 133 | DBConnection db = new DBConnection(); 134 | db.connect(SERVER, PORT, "admin", "123456"); 135 | EntityBlockReader bt = (EntityBlockReader)db.run("table(1..100000 as id)", (ProgressListener)null, 4, 4, 10000); 136 | Assert.AreEqual(false, bt.isDictionary()); 137 | } 138 | [TestMethod] 139 | public void Test_EntityBlockReader_isChart() 140 | { 141 | DBConnection db = new DBConnection(); 142 | db.connect(SERVER, PORT, "admin", "123456"); 143 | EntityBlockReader bt = (EntityBlockReader)db.run("table(1..100000 as id)", (ProgressListener)null, 4, 4, 10000); 144 | Assert.AreEqual(false, bt.isChart()); 145 | } 146 | [TestMethod] 147 | public void Test_EntityBlockReader_isChunk() 148 | { 149 | DBConnection db = new DBConnection(); 150 | db.connect(SERVER, PORT, "admin", "123456"); 151 | EntityBlockReader bt = (EntityBlockReader)db.run("table(1..100000 as id)", (ProgressListener)null, 4, 4, 10000); 152 | Assert.AreEqual(false, bt.isChunk()); 153 | } 154 | 155 | } 156 | } 157 | -------------------------------------------------------------------------------- /test/data_test/BasicIotAnyVectorTest.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dolphindb/api-csharp/3bced304c0475024a09efe6806e543fa8d4ac80e/test/data_test/BasicIotAnyVectorTest.cs -------------------------------------------------------------------------------- /test/data_test/BasicScalarTest.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dolphindb/api-csharp/3bced304c0475024a09efe6806e543fa8d4ac80e/test/data_test/BasicScalarTest.cs -------------------------------------------------------------------------------- /test/data_test/BasicVectorTest.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dolphindb/api-csharp/3bced304c0475024a09efe6806e543fa8d4ac80e/test/data_test/BasicVectorTest.cs -------------------------------------------------------------------------------- /test/data_test/BasicVoidTest.cs: -------------------------------------------------------------------------------- 1 |  2 | using Microsoft.VisualStudio.TestTools.UnitTesting; 3 | using dolphindb_config; 4 | using dolphindb; 5 | using dolphindb.data; 6 | using System.Collections.Generic; 7 | 8 | namespace dolphindb_csharp_api_test.data_test 9 | { 10 | [TestClass] 11 | public class BasicVoidTest 12 | { 13 | private string SERVER = MyConfigReader.SERVER; 14 | static private int PORT = MyConfigReader.PORT; 15 | private readonly string USER = MyConfigReader.USER; 16 | private readonly string PASSWORD = MyConfigReader.PASSWORD; 17 | 18 | [TestMethod] 19 | public void Test_Void() 20 | { 21 | dolphindb.data.Void vo = new dolphindb.data.Void(); 22 | Assert.AreEqual(true, vo.Equals(vo)); 23 | Assert.AreEqual(false, vo.Equals(null)); 24 | Assert.AreEqual(false, vo.Equals(1)); 25 | } 26 | 27 | 28 | [TestMethod] 29 | public void test_BasicVoidVector_run() 30 | { 31 | DBConnection conn = new DBConnection(); 32 | conn.connect(SERVER, PORT, "admin", "123456"); 33 | conn.run("n = 1000;void1 = table(1..n as id);"); 34 | BasicTable table = (BasicTable)conn.run("tmp = select *,NULL as value1,NULL as value2,NULL as value3,NULL as value4 from void1;tmp;"); 35 | Assert.AreEqual(1000, table.rows()); 36 | Assert.AreEqual("", table.getColumn("value1").get(0).getString()); 37 | Assert.AreEqual("[, , , , , , , , , ,...]", table.getColumn("value1").getString()); 38 | Assert.AreEqual(1000, table.getColumn("value1").rows()); 39 | Assert.AreEqual(DATA_CATEGORY.NOTHING, table.getColumn("value1").getDataCategory()); 40 | Assert.AreEqual(DATA_TYPE.DT_VOID, table.getColumn("value1").getDataType()); 41 | Assert.AreEqual(typeof(Void), table.getColumn("value1").getElementClass()); 42 | Assert.AreEqual(new Void(), table.getColumn("value1").getEntity(0)); 43 | Assert.AreEqual("[, ]", table.getColumn("value1").getSubVector(new int[]{ 1,2}).getString()); 44 | Assert.AreEqual(true, table.getColumn("value1").isNull(0)); 45 | conn.run("t2 = table(100:0, `id`value1`value2`value3`value4, [INT,INT,DOUBLE,LONG,STRING]);t2.append!(tmp)"); 46 | BasicTable table1 = (BasicTable)conn.run("select * from t2"); 47 | Assert.AreEqual(1000, table1.rows()); 48 | } 49 | 50 | [TestMethod] 51 | public void test_BasicVoidVector_add() 52 | { 53 | DBConnection conn = new DBConnection(); 54 | conn.connect(SERVER, PORT, "admin", "123456"); 55 | conn.run("n = 1000;void1 = table(1..n as id);"); 56 | BasicTable table = (BasicTable)conn.run("tmp = select *,NULL as value1,NULL as value2,NULL as value3,NULL as value4 from void1;tmp;"); 57 | Assert.AreEqual("", table.getColumn("value1").get(0).getString()); 58 | table.getColumn("value1").add( new BasicInt(1)); 59 | Assert.AreEqual(1001, table.getColumn("value1").rows()); 60 | table.getColumn("value1").addRange(new BasicInt(1)); 61 | Assert.AreEqual(1002, table.getColumn("value1").rows()); 62 | table.getColumn("value1").append(new BasicInt(1)); 63 | Assert.AreEqual(1003, table.getColumn("value1").rows()); 64 | table.getColumn("value1").append(new BasicIntVector(5)); 65 | Assert.AreEqual(1008, table.getColumn("value1").rows()); 66 | } 67 | 68 | [TestMethod] 69 | public void test_BasicVoidVector_upload() 70 | { 71 | DBConnection conn = new DBConnection(); 72 | conn.connect(SERVER, PORT, "admin", "123456"); 73 | conn.run("n = 5;void1 = table(1..n as id);"); 74 | BasicTable table = (BasicTable)conn.run("tmp = select *,NULL as value1,NULL as value2,NULL as value3,NULL as value4 from void1;tmp;"); 75 | Assert.AreEqual(5, table.rows()); 76 | Assert.AreEqual("", table.getColumn("value1").get(0).getString()); 77 | BasicIntVector idv = (BasicIntVector)table.getColumn("id"); 78 | Dictionary upObj = new Dictionary(); 79 | upObj.Add("id", idv); 80 | upObj.Add("value1", table.getColumn("value1")); 81 | upObj.Add("value2", table.getColumn("value2")); 82 | upObj.Add("value3", table.getColumn("value3")); 83 | upObj.Add("value4", table.getColumn("value4")); 84 | conn.upload(upObj); 85 | IEntity value1 = conn.run("value1"); 86 | IEntity value2 = conn.run("value2"); 87 | IEntity value3 = conn.run("value3"); 88 | IEntity value4 = conn.run("value4"); 89 | Assert.AreEqual("[, , , , ]", value1.getString()); 90 | Assert.AreEqual("[, , , , ]", value2.getString()); 91 | Assert.AreEqual("[, , , , ]", value3.getString()); 92 | Assert.AreEqual("[, , , , ]", value4.getString()); 93 | } 94 | 95 | [TestMethod] 96 | public void test_BasicVoidVector_upload_table() 97 | { 98 | DBConnection conn = new DBConnection(); 99 | conn.connect(SERVER, PORT, "admin", "123456"); 100 | conn.run("n = 1000;void1 = table(1..n as id);"); 101 | BasicTable table = (BasicTable)conn.run("tmp = select *,NULL as value1,NULL as value2,NULL as value3,NULL as value4 from void1;tmp;"); 102 | Assert.AreEqual(1000, table.rows()); 103 | Assert.AreEqual("", table.getColumn("value1").get(0).getString()); 104 | Dictionary upObj = new Dictionary(); 105 | upObj.Add("table_upload_table", (IEntity)table); 106 | conn.upload(upObj); 107 | BasicTable table1 = (BasicTable)conn.run("table_upload_table"); 108 | Assert.AreEqual(1000, table1.rows()); 109 | Assert.AreEqual(5, table1.columns()); 110 | Assert.AreEqual("", table1.getColumn("value1").get(0).getString()); 111 | } 112 | [TestMethod] 113 | public void test_void_tableInsert() 114 | { 115 | DBConnection conn = new DBConnection(); 116 | conn.connect(SERVER, PORT, "admin", "123456"); 117 | conn.run("n = 1000;void1 = table(1..n as id);"); 118 | BasicTable table = (BasicTable)conn.run("tmp = select *,NULL as value1,NULL as value2,NULL as value3,NULL as value4 from void1;tmp;"); 119 | Assert.AreEqual(1000, table.rows()); 120 | List args = new List() { table }; 121 | conn.run("tb = table(100:0, `id`value1`value2`value3`value4, [INT,INT,DOUBLE,LONG,STRING]);"); 122 | BasicInt re = (BasicInt)conn.run("tableInsert{tb}", args); 123 | Assert.AreEqual(1000, re.getInt()); 124 | BasicTable table1 = (BasicTable)conn.run("select * from tb"); 125 | Assert.AreEqual(1000, table1.rows()); 126 | Assert.AreEqual(5, table1.columns()); 127 | Assert.AreEqual("", (((BasicIntVector)table1.getColumn("value1")).get(0)).getString()); 128 | } 129 | 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /test/dolphindb_csharpapi_net_core_test.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp7.0 5 | v4 6 | false 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | all 21 | runtime; build; native; contentfiles; analyzers; buildtransitive 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /test/route_test/MultithreadTableWriter_test.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dolphindb/api-csharp/3bced304c0475024a09efe6806e543fa8d4ac80e/test/route_test/MultithreadTableWriter_test.cs -------------------------------------------------------------------------------- /test/streaming/cep_test/EventClientTest.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dolphindb/api-csharp/3bced304c0475024a09efe6806e543fa8d4ac80e/test/streaming/cep_test/EventClientTest.cs -------------------------------------------------------------------------------- /test/streaming/cep_test/EventSenderTest.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dolphindb/api-csharp/3bced304c0475024a09efe6806e543fa8d4ac80e/test/streaming/cep_test/EventSenderTest.cs -------------------------------------------------------------------------------- /test/streaming/streamReverse_test/AbstractClientTest.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using dolphindb; 7 | using dolphindb.data; 8 | using dolphindb.streaming; 9 | using System.Threading; 10 | using dolphindb_config; 11 | 12 | namespace dolphindb_csharp_api_test.streamReverse_test 13 | { 14 | [TestClass] 15 | public class AbstractClientTest 16 | { 17 | 18 | public static DBConnection streamConn; 19 | private string SERVER = MyConfigReader.SERVER; 20 | static private int PORT = MyConfigReader.PORT; 21 | private readonly string USER = MyConfigReader.USER; 22 | private readonly string PASSWORD = MyConfigReader.PASSWORD; 23 | private string LOCALHOST = MyConfigReader.LOCALHOST; 24 | private readonly int LOCALPORT = MyConfigReader.LOCALPORT; 25 | static private int SUB_FLAG = MyConfigReader.SUB_FLAG; 26 | private string NODE1_HOST = MyConfigReader.NODE1_HOST; 27 | private readonly int NODE1_PORT = MyConfigReader.NODE1_PORT; 28 | public static string[] HASTREAM_GROUP = MyConfigReader.HASTREAM_GROUP; 29 | private readonly int HASTREAM_GROUPID = MyConfigReader.HASTREAM_GROUPID; 30 | //private readonly int TIMEOUT = 10000; 31 | 32 | [TestMethod] 33 | public void Test_activeClosePublishConnection_host_port() 34 | { 35 | DBConnection conn = new DBConnection(); 36 | conn.connect(SERVER, PORT); 37 | //string localIP = "localhost"; 38 | List @params = new List 39 | { 40 | new BasicString("tablename"), 41 | new BasicString("activeName") 42 | }; 43 | conn.run("activeClosePublishConnection", @params); 44 | 45 | } 46 | [TestMethod] 47 | public void Test_activeClosePublishConnection_host_null() 48 | { 49 | DBConnection conn = new DBConnection(); 50 | conn.connect(SERVER, 18921); 51 | try { 52 | List @params = new List 53 | { 54 | //new BasicString(SERVER), 55 | new BasicInt(8878) 56 | }; 57 | conn.run("activeClosePublishConnection", @params); 58 | } 59 | catch(Exception ex){ 60 | Console.WriteLine(ex.ToString()); 61 | } 62 | } 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /test/streaming/streamReverse_test/ThreadPoolClientReverseTest.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dolphindb/api-csharp/3bced304c0475024a09efe6806e543fa8d4ac80e/test/streaming/streamReverse_test/ThreadPoolClientReverseTest.cs -------------------------------------------------------------------------------- /test/streaming/streamReverse_test/ThreadedClientReverseTest.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dolphindb/api-csharp/3bced304c0475024a09efe6806e543fa8d4ac80e/test/streaming/streamReverse_test/ThreadedClientReverseTest.cs --------------------------------------------------------------------------------