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
use {
clap::Parser,
triplify::{
Triplify,
checksum::ChecksumMode,
emit::Header,
location::Location,
writer::Output,
},
};
/// Turn every CSV/TSV/XLSX/XLS/ODS/Parquet file under the given paths or S3
/// prefixes into raw RDF.
#[derive(Debug, Parser)]
#[command(version, about)]
struct Cli {
/// Files, directories (walked, honouring .gitignore), S3 objects
/// (s3://bucket/key) or S3 prefixes (s3://bucket/prefix/).
#[arg(default_value = ".")]
paths: Vec<Location>,
/// Output file or S3 object: .nq, .nt (graphs merged) or .trig,
/// optionally .gz. Defaults to N-Quads on stdout.
#[arg(short, long)]
output: Option<Location>,
/// Emit RDFC-1.0 canonical N-Quads/N-Triples (buffers the dataset in
/// memory).
#[arg(long)]
canonical: bool,
/// Profile every column: exact value/null/distinct counts, most
/// frequent value, an inferred datatype with its conforming count, and
/// min/max/mean/std/percentiles. Costs memory per column and time.
#[arg(long)]
profile: bool,
/// CSV/TSV files and worksheets have no header row: the first row is
/// data and columns get no labels. Parquet always uses its schema.
#[arg(long)]
no_header: bool,
/// End the output with the SHA-256 of all its preceding bytes, in the
/// run's provenance graph: a final gzip member for .gz output, final
/// lines otherwise. Verify with `head -c <checksumByteCount> FILE |
/// sha256sum`.
#[arg(long, value_enum, default_value_t = ChecksumMode::Trailer)]
checksum: ChecksumMode,
#[command(flatten)]
verbose: clap_verbosity_flag::Verbosity<clap_verbosity_flag::WarnLevel>,
}
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let cli = Cli::parse();
tracing_subscriber::fmt()
.with_writer(std::io::stderr)
.with_env_filter(
tracing_subscriber::EnvFilter::try_from_default_env()
.unwrap_or_else(|_| {
tracing_subscriber::EnvFilter::new(
cli.verbose
.tracing_level()
.map_or("off", |l| l.as_str()),
)
}),
)
.without_time()
.with_target(false)
.init();
let output = match cli.output {
Some(location) => Output::to(location, cli.canonical)?,
None => Output::stdout(cli.canonical),
}
.with_checksum(cli.checksum);
let summary = Triplify::new(cli.paths, output)
.with_profile(cli.profile)
.with_header(
if cli.no_header {
Header::Absent
} else {
Header::FirstRow
},
)
.run()
.await?;
tracing::info!(?summary, "done");
anyhow::ensure!(
summary.failed == 0,
"{} source(s) failed",
summary.failed
);
Ok(())
}