数据对
数据对是只有两个值的特殊的向量。具体介绍见: Pair.
创建数据对
Currently, the Java API does not provide a specific Java data type to create or represent a pair.
Users can create a pair by running a script with the DBConnection run() method. The returned pair will be represented as a vector of the corresponding type, with its type being the corresponding data type and its form being DF_PAIR.
目前 Java API 中不提供具体的 Java 数据类型来创建、表示数据对。
用户可以用 DBConnection run() 脚本的方式来创建数据对。通过该方式创建返回的数据对,会用一个对应类型的 vector 来表示,type 为对应的数据类型,form 为 DF_PAIR。
使用示例:
// 创建一个 1:3 数据对
// 返回的 pair 是一个 BasicIntVector,type 为 DT_INT,data form 为 DF_PAIR
DBConnection conn = new DBConnection();
conn.connect("192.168.0.69", 8802, "admin", "123456");
Entity pair = conn.run("1:3"); // pair(BasicIntVector)
System.out.println(pair.getDataType()); // DT_INT
System.out.println(pair.getDataForm()); // DF_PAIR
System.out.println(pair.getString()); // [1,3]
特别的,对于一些函数返回值为 Pair 的,表示形式与上述一致。比如 tableUpsert 函数返回值为 LONG 类型数据对,第一个元素表示新插入的记录数,第二个元素表示更新的记录数。Java api 中通过 run 脚本调用 tableUpsert 函数会返回一个 BasicLongVector,type 为 DT_LONG、data form 为 DF_PAIR。
使用示例:
DBConnection conn = new DBConnection();
conn.connect("192.168.0.69", 8802, "admin", "123456");
Entity res = conn.run("sym=`A`B`C\n" +
"date=take(2021.01.06, 3)\n" +
"x=1 2 3\n" +
"y=5 6 7\n" +
"t=keyedTable(`sym`date, sym, date, x, y)\n" +
"newData = table(`A`B`C`D as sym1, take(2021.01.06, 4) as date1, NULL NULL 300 400 as x1, NULL 600 700 800 as y1);\n" +
"tableUpsert(t, newData, ignoreNull=true)");
System.out.println(res.getDataType());
System.out.println(res.getDataForm());
System.out.println(res.getString());