Skip to content

Commit 22aab6d

Browse files
release3.00.4
1 parent c4e46b3 commit 22aab6d

8 files changed

Lines changed: 285 additions & 29 deletions

File tree

src/DBConnection.cs

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@
2121
namespace dolphindb
2222
{
2323

24+
public enum ParserType
25+
{
26+
Default = 0,
27+
DolphinDB = 1,
28+
Python = 2,
29+
KDB = 3
30+
}
31+
32+
2433
/// <summary>
2534
/// Sets up a connection to DolphinDB server through TCP/IP protocol
2635
/// Executes DolphinDB scripts
@@ -76,6 +85,7 @@ enum ExceptionType
7685
private bool compress_ = false;
7786
private bool loadBalance_ = true;
7887
private bool isReverseStreaming_ = false;
88+
private ParserType parser_ = ParserType.Default;
7989

8090
List<Node> nodes_ = new List<Node>();
8191
DBConnectionImpl conn_;
@@ -99,7 +109,7 @@ public class DBConnectionImpl
99109
bool compress_ = false;
100110
bool isReverseStreaming_ = false;
101111
private string startup_;
102-
private bool usePython_ = false;
112+
private ParserType parser_;
103113
private static readonly int MAX_FORM_VALUE = Enum.GetValues(typeof(DATA_FORM)).Length - 1;
104114
private static readonly int MAX_TYPE_VALUE = Enum.GetValues(typeof(DATA_TYPE)).Length - 1;
105115
BasicEntityFactory factory = (BasicEntityFactory)BasicEntityFactory.instance();
@@ -128,20 +138,22 @@ private int generateRequestFlag(bool clearSessionMemory)
128138
flag += 16;
129139
if (compress_)
130140
flag += 64;
131-
if (usePython_)
141+
if(parser_ == ParserType.Python)
132142
flag += 2048;
143+
if(parser_ == ParserType.KDB)
144+
flag += 4096;
133145
if (isReverseStreaming_)
134146
flag += 131072;
135147
return flag;
136148
}
137149

138-
public DBConnectionImpl(bool sslEnable = false, bool asynTask = false, bool compress = false, bool usePython = false,bool isReverseStreaming = false)
150+
public DBConnectionImpl(bool sslEnable = false, bool asyncTask = false, bool compress = false, bool isReverseStreaming = false, ParserType parser = ParserType.Default)
139151
{
140152
sslEnable_ = sslEnable;
141-
asynTask_ = asynTask;
153+
asynTask_ = asyncTask;
142154
compress_ = compress;
143-
usePython_ = usePython;
144155
isReverseStreaming_ = isReverseStreaming;
156+
parser_ = parser;
145157
}
146158

147159
public bool connect(string hostName, int port, string userId, string password, bool sslEnable,
@@ -570,14 +582,23 @@ public ExtendedDataInput getDataInputStream()
570582

571583
private int lastConnNodeIndex_ = 0;
572584

573-
public DBConnection(bool asynchronousTask = false, bool useSSL = false, bool compress = false, bool usePython = false,bool isReverseStreaming = false)
585+
public DBConnection(bool asynchronousTask = false, bool useSSL = false, bool compress = false, bool usePython = false, bool isReverseStreaming = false, ParserType parser = ParserType.Default)
574586
{
575587
asynTask_ = asynchronousTask;
576588
isUseSSL_ = useSSL;
589+
parser_ = parser;
577590

578591
this.compress_ = compress;
579592
this.isReverseStreaming_ = isReverseStreaming;
580-
conn_ = new DBConnectionImpl(useSSL, asynchronousTask, compress, usePython, isReverseStreaming);
593+
if(usePython && parser != ParserType.Default)
594+
{
595+
throw new Exception("usePython and parser cannot be set both.");
596+
}
597+
if (usePython)
598+
{
599+
parser = ParserType.Python;
600+
}
601+
conn_ = new DBConnectionImpl(useSSL, asynchronousTask, compress, isReverseStreaming, parser);
581602
}
582603

583604
public bool isBusy()
@@ -1099,7 +1120,14 @@ bool connectMinNode()
10991120
}
11001121
else
11011122
{
1102-
table = (BasicTable)conn_.run("rpc(getControllerAlias(),getClusterPerf)");
1123+
if(parser_ == ParserType.KDB)
1124+
{
1125+
table = (BasicTable)conn_.run("rpc[getControllerAlias[]; getClusterPerf]");
1126+
}
1127+
else
1128+
{
1129+
table = (BasicTable)conn_.run("rpc(getControllerAlias(), getClusterPerf)");
1130+
}
11031131
}
11041132
break;
11051133
}

src/ExclusiveDBConnectionPool.cs

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@
44
// Author : zhikun.luo
55
//-------------------------------------------------------------------------------------------
66

7+
using dolphindb.data;
78
using System;
89
using System.Collections.Generic;
9-
using dolphindb.data;
1010
using System.Threading;
1111
using System.Threading.Tasks;
12+
using static dolphindb.DBConnection;
1213

1314
namespace dolphindb
1415
{
15-
public class ExclusiveDBConnectionPool:IDBConnectionPool
16+
public class ExclusiveDBConnectionPool : IDBConnectionPool
1617
{
1718
private List<AsynWorker> workers_ = new List<AsynWorker>();
1819
private int tasksCount_ = 0;
@@ -106,15 +107,20 @@ private T[] newArray<T>(T[] source, int originLength, int newLength)
106107
}
107108

108109

109-
public ExclusiveDBConnectionPool(string host, int port, string uid, string pwd, int count, bool loadBalance, bool highAvailability, string[] highAvailabilitySites = null, string startup = "", bool compress = false, bool useSSL = false, bool usePython = false)
110+
public ExclusiveDBConnectionPool(string host, int port, string uid, string pwd, int count, bool loadBalance, bool highAvailability, string[] highAvailabilitySites = null, string startup = "", bool compress = false, bool useSSL = false, bool usePython = false, ParserType parser = ParserType.Default)
110111
{
111112
if (count <= 0)
112113
throw new Exception("The thread count can not be less than 1");
114+
115+
if (usePython && parser != ParserType.Python && parser != ParserType.Default)
116+
{
117+
throw new Exception("Python flag is true, parser must be ParserType.Default or ParserType.Python.");
118+
}
113119
if (!loadBalance)
114120
{
115-
for(int i = 0; i < count; i++)
121+
for (int i = 0; i < count; i++)
116122
{
117-
DBConnection conn = new DBConnection(false, useSSL, compress, usePython);
123+
DBConnection conn = new DBConnection(false, useSSL, compress, usePython, parser: parser);
118124
conn.setLoadBalance(false);
119125
if (!conn.connect(host, port, uid, pwd, startup, highAvailability, highAvailabilitySites))
120126
throw new Exception("Cant't connect to the specified host.");
@@ -143,7 +149,7 @@ public ExclusiveDBConnectionPool(string host, int port, string uid, string pwd,
143149
string[] hosts = new string[nodeCount];
144150
int[] ports = new int[nodeCount];
145151
string[] sites = new string[nodeCount];
146-
for(int i = 0; i < nodeCount; i++)
152+
for (int i = 0; i < nodeCount; i++)
147153
{
148154
string[] fields = nodes.getString(i).Split(':');
149155
if (fields.Length < 2)
@@ -173,7 +179,7 @@ public ExclusiveDBConnectionPool(string host, int port, string uid, string pwd,
173179
}
174180
for (int i = 0; i < count; i++)
175181
{
176-
DBConnection conn = new DBConnection(false, useSSL, compress, usePython);
182+
DBConnection conn = new DBConnection(false, useSSL, compress, usePython, parser: parser);
177183
conn.setLoadBalance(false);
178184
if (!(conn.connect(hosts[i % nodeCount], ports[i % nodeCount], uid, pwd, startup, highAvailability, sites)))
179185
throw new Exception("Can't connect to the specified host: ");
@@ -204,7 +210,8 @@ public void execute(List<IDBTask> tasks)
204210
}
205211
}
206212

207-
public void execute(IDBTask task) {
213+
public void execute(IDBTask task)
214+
{
208215
tasksCount_++;
209216
lock (workItem_.taskLists_)
210217
{
@@ -277,12 +284,14 @@ public void waitForThreadCompletion()
277284
}
278285
}
279286

280-
public int getConnectionCount() {
287+
public int getConnectionCount()
288+
{
281289
return workers_.Count;
282290
}
283-
public void shutdown() {
291+
public void shutdown()
292+
{
284293
waitForThreadCompletion();
285-
; foreach(AsynWorker one in workers_)
294+
foreach (AsynWorker one in workers_)
286295
{
287296
lock (one.workThread_)
288297
{
@@ -301,7 +310,7 @@ public List<IEntity> run(IList<string> sqlList, int priority = 4, int parallelis
301310
}
302311
execute(tasks);
303312
List<IEntity> results = new List<IEntity>();
304-
foreach(IDBTask dBTask in tasks)
313+
foreach (IDBTask dBTask in tasks)
305314
{
306315
if (!dBTask.isSuccessful())
307316
{

src/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@
3232
// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
3333
//通过使用 "*",如下所示:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("3.00.2.3")]
36-
[assembly: AssemblyFileVersion("3.00.2.3")]
35+
[assembly: AssemblyVersion("3.00.4")]
36+
[assembly: AssemblyFileVersion("3.00.4")]

src/data/BasicAnyVector.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,11 @@ protected internal BasicAnyVector(IEntity[] array): base(DATA_FORM.DF_VECTOR)
3232
protected internal BasicAnyVector(ExtendedDataInput @in) : base(DATA_FORM.DF_VECTOR)
3333
{
3434
int rows = @in.readInt();
35-
int cols = @in.readInt();
36-
int size = rows * cols;
35+
@in.readInt();
3736
values = new List<IEntity>();
3837

3938
BasicEntityFactory factory = new BasicEntityFactory();
40-
for (int i = 0; i < size; ++i)
39+
for (int i = 0; i < rows; ++i)
4140
{
4241
short flag = @in.readShort();
4342
int form = flag >> 8;

src/data/Utils.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class Utils
3030
private static readonly int[] cumLeapMonthDays = new int[] { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 };
3131
private static readonly int[] monthDays = new int[] { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
3232
private static readonly int[] leapMonthDays = new int[] { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
33-
private static string API_VERSION = "3.00.2.3";
33+
private static string API_VERSION = "3.00.4";
3434

3535
public static string getAPIVersion()
3636
{

test/DBConnection_test.cs

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1879,6 +1879,7 @@ public void Test_run_return_set()
18791879
BasicSet dict = (BasicSet)db.run("set(1 3 5)");
18801880
Assert.AreEqual(3, dict.rows());
18811881
Assert.AreEqual(1, dict.columns());
1882+
//Console.WriteLine(dict.getString());
18821883
db.close();
18831884
}
18841885

@@ -2085,6 +2086,80 @@ public void Test_upload_table()
20852086
db.close();
20862087
}
20872088

2089+
[TestMethod]
2090+
public void Test_upload_table_any_null()
2091+
{
2092+
DBConnection db = new DBConnection();
2093+
db.connect(SERVER, PORT, USER, PASSWORD);
2094+
BasicTable re1 = (BasicTable)db.run("re = table(100:0, `sex`name`eye, [STRING,ANY,ANY]);re");
2095+
Assert.AreEqual("sex name eye\n" +
2096+
"--- ---- ---\n" , re1.getString());
2097+
Dictionary<string, IEntity> upObj = new Dictionary<string, IEntity>();
2098+
upObj.Add("table_uploaded", (IEntity)re1);
2099+
db.upload(upObj);
2100+
BasicTable re2 = (BasicTable)db.run("select * from table_uploaded");
2101+
Assert.AreEqual(re1.getString(), re2.getString());
2102+
db.close();
2103+
}
2104+
2105+
[TestMethod]
2106+
public void Test_upload_table_any()
2107+
{
2108+
DBConnection db = new DBConnection();
2109+
db.connect(SERVER, PORT, USER, PASSWORD);
2110+
BasicTable re1 = (BasicTable)db.run("re = table(100:0, `sex`name`eye, [STRING,ANY,ANY]);\n" +
2111+
"re.tableInsert(`f`m,([`jill],['tom' 'dick' 'harry' 'jack']), ([`gray],['blue' 'green' 'blue' 'blue']));" +
2112+
"select * from re;");
2113+
Assert.AreEqual("sex name eye \n" +
2114+
"--- -------------------------- ---------------------------\n" +
2115+
"f [jill] [gray] \n" +
2116+
"m ([tom, dick, harry, jack]) ([blue, green, blue, blue])\n", re1.getString());
2117+
2118+
Dictionary<string, IEntity> upObj = new Dictionary<string, IEntity>();
2119+
upObj.Add("table_uploaded", (IEntity)re1);
2120+
db.upload(upObj);
2121+
BasicTable re2 = (BasicTable)db.run("select * from table_uploaded");
2122+
Assert.AreEqual(re1.getString(), re2.getString());
2123+
db.close();
2124+
}
2125+
2126+
2127+
[TestMethod]
2128+
public void Test_upload_table_any_all_dataform()
2129+
{
2130+
DBConnection db = new DBConnection();
2131+
db.connect(SERVER, PORT, USER, PASSWORD);
2132+
BasicTable re1 = (BasicTable)db.run("ctime=take(2025.10.18T10:27:23.275..2025.10.10T10:27:23.275,7)\n" +
2133+
"cany=array(ANY,0).append!(1000).append!(`www`qqq).append!(matrix([1 2 3, 4 5 6])).append!(100:11).append!(table(`qa`ws`ed as id)).append!((100, `11)).append!( [[`1a,`a1]].setColumnarTuple!());" +
2134+
"t1 = table(ctime, cany); t1;");
2135+
Console.WriteLine(re1.getString());
2136+
2137+
Dictionary<string, IEntity> upObj = new Dictionary<string, IEntity>();
2138+
upObj.Add("table_uploaded", (IEntity)re1);
2139+
db.upload(upObj);
2140+
BasicTable re2 = (BasicTable)db.run("select * from table_uploaded");
2141+
Assert.AreEqual(re1.getString(), re2.getString());
2142+
Assert.AreEqual(7, re1.rows());
2143+
db.close();
2144+
}
2145+
2146+
//[TestMethod]
2147+
public void Test_upload_table_any_set_dict()
2148+
{
2149+
DBConnection db = new DBConnection();
2150+
db.connect(SERVER, PORT, USER, PASSWORD);
2151+
BasicTable re1 = (BasicTable)db.run("ctime=take(2025.10.18T10:27:23.275..2025.10.10T10:27:23.275,2)\n" +
2152+
"cany=array(ANY,0).append!(set(1 2)).append!(dict(`aaa11`bbb22, [dict(`p1`p2, `1`2, true), dict(`p11`p22, `100`200, true)]));" +
2153+
"t1 = table(ctime, cany); t1;");
2154+
Console.WriteLine(re1.getString());
2155+
2156+
Dictionary<string, IEntity> upObj = new Dictionary<string, IEntity>();
2157+
upObj.Add("table_uploaded", (IEntity)re1);
2158+
db.upload(upObj);
2159+
BasicTable re2 = (BasicTable)db.run("select * from table_uploaded");
2160+
Assert.AreEqual(re1.getString(), re2.getString());
2161+
db.close();
2162+
}
20882163

20892164
[TestMethod]
20902165
public void Test_dict_toDataTable()
@@ -3553,6 +3628,78 @@ public void test_python_false()
35533628

35543629
}
35553630

3631+
[TestMethod]
3632+
public void test_ParserType_notSet()
3633+
{
3634+
DBConnection conn = new DBConnection(false, false, false, false);
3635+
conn.connect(SERVER, PORT, "admin", "123456");
3636+
IEntity re = conn.run("1+1");
3637+
Console.WriteLine(re.getString());
3638+
Assert.AreEqual("2", re.getString());
3639+
conn.close();
3640+
}
3641+
3642+
[TestMethod]//Default
3643+
public void test_ParserType_default()
3644+
{
3645+
DBConnection conn = new DBConnection(false, false, false, false, false, ParserType.Default);
3646+
conn.connect(SERVER, PORT, "admin", "123456");
3647+
IEntity re = conn.run("1+1");
3648+
Console.WriteLine(re.getString());
3649+
Assert.AreEqual("2", re.getString());
3650+
conn.close();
3651+
}
3652+
3653+
[TestMethod]//DolphinDB
3654+
public void test_ParserType_DolphinDB()
3655+
{
3656+
DBConnection conn = new DBConnection(false, false, false, false, false, ParserType.DolphinDB);
3657+
conn.connect(SERVER, PORT, "admin", "123456");
3658+
IEntity re = conn.run("1+1");
3659+
Console.WriteLine(re.getString());
3660+
Assert.AreEqual("2", re.getString());
3661+
conn.close();
3662+
}
3663+
3664+
[TestMethod]//python
3665+
public void test_ParserType_Python()
3666+
{
3667+
DBConnection db = new DBConnection();
3668+
db.connect(SERVER, PORT, "admin", "123456");
3669+
DBConnection conn = new DBConnection(false, false, false, true, false, ParserType.Python);
3670+
conn.connect(SERVER, PORT, "admin", "123456");
3671+
BasicString version = (BasicString)db.run("version()");
3672+
if (version.getString().Contains("3.00"))
3673+
{
3674+
conn.run("import pandas as pd");
3675+
}
3676+
else
3677+
{
3678+
Console.WriteLine("The current version does not support Python Parser, so this case is skipped");
3679+
}
3680+
3681+
conn.close();
3682+
db.close();
3683+
}
3684+
3685+
[TestMethod]//kdb
3686+
public void test_ParserType_KDB()
3687+
{
3688+
DBConnection conn = new DBConnection(false, false, false, false, false, ParserType.KDB);
3689+
conn.connect("192.168.0.54", 8848, "admin", "123456");
3690+
IEntity re = conn.run("D:`q`w`e!(1 2;3 4;5 6)\nkey D");
3691+
Console.WriteLine(re.getString());
3692+
Assert.AreEqual("[q, w, e]", re.getString());
3693+
3694+
IEntity re1 = conn.run("res:\"abcdef\"[1 4 3]\nres");
3695+
Assert.AreEqual("['b', 'e', 'd']", re1.getString());
3696+
3697+
IEntity re2 = conn.run("txt:((\"Now\";\" is \";\"the\";\"time\");(\"for\";\"all\";\"good\";\"folk\"))\ntxt") ;
3698+
Console.WriteLine(re2.getString());
3699+
Assert.AreEqual("((['N', 'o', 'w'],[' ', 'i', 's', ' '],['t', 'h', 'e'],['t', 'i', 'm', 'e']),(['f', 'o', 'r'],['a', 'l', 'l'],['g', 'o', 'o', 'd'],['f', 'o', 'l', 'k']))", re2.getString());
3700+
conn.close();
3701+
}
3702+
35563703

35573704
[TestMethod]
35583705
public void test_close()

0 commit comments

Comments
 (0)