Pair

A pair is a special vector with only two values. For details, see: Pair.

Creating a 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.

Example:

// Create a 1:3 pair
// The returned pair is a 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]

In particular, for some functions that return a Pair, the representation is consistent with the above. For example, the tableUpsert function returns a Pair of type LONG, where the first element represents the number of newly inserted records, and the second element represents the number of updated records. When calling tableUpsert via the Java API run, the return value is a BasicLongVector, with with type DT_LONG and data form DF_PAIR.

Example:

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());