1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
let properties = [
{ name: "jacob", age: 22 },
{ name: "Ben", age: 33, city: "SF" },
];
let newProperties = [{ name: "sean", age: 31 }];
let {
Table,
Schema,
RecordBatch,
Field,
Float32,
Int32,
Struct,
Utf8,
Vector,
vectorFromArray,
makeTable,
} = Arrow;
const values = [1, 2];
const vector = vectorFromArray(values);
const nodes = [
{
id: "1",
color: 0xfff000,
label: "Movie",
position: { x: 1, y: 2, z: 3 },
properties: {
name: "jacob",
age: 22,
},
},
{
id: "2",
color: 0xfff000,
label: "Movie",
position: { x: 1, y: 2, z: 3 },
properties: {
name: "test",
age: 22,
},
},
];
const nodesVector = vectorFromArray(nodes);
const batch = new RecordBatch({id:vector ,nodes: nodesVector });
let graphTable = new Table([batch])
let ns = graphTable.getChild("nodes")
log("第一行数据的label:" + ns.get(0).label);
const newId = [3,4]
const newNodes = [
{
id: "3",
color: 0xfff000,
label: "Movie",
position: { x: 1, y: 2, z: 3 },
properties: {
name: "Rob",
age: 22,
},
},
{
id: "4",
color: 0xfff000,
label: "Movie",
position: { x: 1, y: 2, z: 3 },
properties: {
name: "Susana",
age: 22,
},
},
];
let newIdVec = vectorFromArray(newId)
let neweNodeVec = vectorFromArray(newNodes)
const newBatch = new RecordBatch({id:newIdVec ,nodes: neweNodeVec });
const newTable = new Table([newBatch])
let newNodesVec = newTable.getChild("nodes")
log("新Table的property:" + newNodesVec.get(0).properties.name);
let concatTable = graphTable.concat(newTable)
let concatVec = concatTable.getChild("nodes")
log("concat table's last row properties:"+concatTable.getChild("nodes").get(3).properties.name)
//Change property's value
let jacobProperty = concatTable.getChild("nodes").get(0).properties
jacobProperty.name = "S"
concatTable.getChild("nodes").get(0).properties = jacobProperty
log("rename:"+concatTable.getChild("nodes").get(0).properties.name)
|