-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjsonstat2arrow
More file actions
executable file
·56 lines (49 loc) · 1.38 KB
/
jsonstat2arrow
File metadata and controls
executable file
·56 lines (49 loc) · 1.38 KB
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
#!/usr/bin/env node
const
aq=require("arquero"),
argv=require("yargs")
.version()
.usage("Usage:\n $0 [input filename] [output filename]\n $0 < [input] > [output] -t")
.example("$0 oecd.json oecd.arrow -0", "converts JSON-stat file oecd.json into an arrow binary file.")
.example("$0 < oecd.json > oecd.arrow -0 -t", "converts JSON-stat stream oecd.json into a binary stream (oecd.arrow).")
.boolean("f")
.alias("f", "flabel")
.describe("f", "Identify dimensions, value and status by label instead of ID")
.boolean("c")
.alias("c", "cid")
.describe("c", "Identify categories by ID instead of label")
.boolean("0")
.alias("0", "binary")
.describe("0", "Save in binary format")
.boolean("t")
.alias("t", "stream")
.describe("t", "Enable the stream interface")
.help("h")
.alias("h", "help")
.argv
,
inout=require("./inout"),
callback=function(contents){
const
tbl=inout.dataset(contents).Transform({
type: "objarr",
vlabel: "value",
slabel: "status",
status: true,
content: argv.cid ? "id": "label",
field: argv.flabel ? "label": "id"
})
;
if(tbl===null){
console.error("Error: The input does not containt valid JSON-stat.");
process.exit(1);
}
var arrow=aq.table(tbl).toArrowBuffer();
if(argv.binary){
return arrow;
}else{
return Array.from(arrow);
}
}
;
inout.main(argv, callback, null, argv.binary);