Skip to content

Commit 8cdc1fb

Browse files
committed
add -f support
1 parent 16f0649 commit 8cdc1fb

File tree

7 files changed

+637392
-5
lines changed

7 files changed

+637392
-5
lines changed

README.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,9 @@ A set of native implementation of common bioinformatics algorithms to be used as
44
#
55
```bash
66
RUST_LOG=info cargo run
7-
```
7+
```
8+
9+
# Run a sql file
10+
```bash
11+
RUST_LOG=info cargo run -p sequila-cli -- --file queries/q1-coitrees.sql
12+
```

queries/q1-ailist.sql

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
SET sequila.prefer_interval_join TO true;
2+
SET sequila.interval_join_algorithm TO ailist;
3+
SET datafusion.optimizer.repartition_joins TO false;
4+
5+
CREATE EXTERNAL TABLE a (contig VARCHAR NOT NULL, start BIGINT NOT NULL, end BIGINT NOT NULL)
6+
STORED AS CSV
7+
LOCATION './testing/data/exons.bed'
8+
OPTIONS ('delimiter' '\t', 'has_header' 'false');
9+
10+
CREATE EXTERNAL TABLE b (contig VARCHAR NOT NULL, start BIGINT NOT NULL, end BIGINT NOT NULL)
11+
STORED AS CSV
12+
LOCATION './testing/data/fBrain-DS14718.bed'
13+
OPTIONS ('delimiter' '\t', 'has_header' 'false');
14+
15+
select count(1) from a join b
16+
on a.contig = b.contig
17+
and a.end >= b.start
18+
and a.start <= b.end;

queries/q1-coitrees.sql

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
SET sequila.prefer_interval_join TO true;
2+
SET sequila.interval_join_algorithm TO coitrees;
3+
SET datafusion.optimizer.repartition_joins TO false;
4+
5+
CREATE EXTERNAL TABLE a (contig VARCHAR NOT NULL, start BIGINT NOT NULL, end BIGINT NOT NULL)
6+
STORED AS CSV
7+
LOCATION './testing/data/exons.bed'
8+
OPTIONS ('delimiter' '\t', 'has_header' 'false');
9+
10+
CREATE EXTERNAL TABLE b (contig VARCHAR NOT NULL, start BIGINT NOT NULL, end BIGINT NOT NULL)
11+
STORED AS CSV
12+
LOCATION './testing/data/fBrain-DS14718.bed'
13+
OPTIONS ('delimiter' '\t', 'has_header' 'false');
14+
15+
select count(1) from a join b
16+
on a.contig = b.contig
17+
and a.end >= b.start
18+
and a.start <= b.end;

sequila/sequila-cli/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ tokio.workspace = true
1717
log.workspace = true
1818
env_logger.workspace = true
1919
emojis.workspace = true
20+
clap = { version = "4.5.20", features = ["derive"] }

sequila/sequila-cli/src/main.rs

+34-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use clap::Parser;
12
use datafusion::common::DataFusionError;
23
use datafusion::config::ConfigOptions;
34
use datafusion::error::Result;
@@ -6,10 +7,33 @@ use datafusion_cli::exec;
67
use datafusion_cli::print_options::PrintOptions;
78
use log::info;
89
use sequila_core::session_context::{SeQuiLaSessionExt, SequilaConfig};
10+
use std::path::Path;
11+
12+
#[derive(Debug, Parser)]
13+
#[command(version, about, long_about = None)]
14+
struct Args {
15+
#[clap(
16+
short,
17+
long,
18+
num_args = 0..,
19+
help = "Execute commands from file(s), then exit",
20+
value_parser(parse_valid_file)
21+
)]
22+
file: Vec<String>,
23+
}
24+
25+
fn parse_valid_file(dir: &str) -> Result<String, String> {
26+
if Path::new(dir).is_file() {
27+
Ok(dir.to_string())
28+
} else {
29+
Err(format!("Invalid file '{}'", dir))
30+
}
31+
}
932

1033
#[tokio::main(flavor = "multi_thread")]
1134
async fn main() -> Result<()> {
1235
env_logger::init();
36+
let args = Args::parse();
1337
let mut options = ConfigOptions::new();
1438
options.extensions.insert(SequilaConfig::default());
1539
let config = SessionConfig::from(options)
@@ -24,10 +48,16 @@ async fn main() -> Result<()> {
2448
maxrows: datafusion_cli::print_options::MaxRows::Limited(100),
2549
color: true,
2650
};
27-
exec::exec_from_repl(&mut ctx, &mut print_options)
28-
.await
29-
.map_err(|e| DataFusionError::External(Box::new(e)))
30-
.expect("Error");
51+
52+
if !args.file.is_empty() {
53+
exec::exec_from_files(&mut ctx, args.file, &print_options).await?;
54+
} else {
55+
exec::exec_from_repl(&mut ctx, &mut print_options)
56+
.await
57+
.map_err(|e| DataFusionError::External(Box::new(e)))
58+
.expect("Error");
59+
}
60+
3161
Ok(())
3262
}
3363

0 commit comments

Comments
 (0)