-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathmain.rs
44 lines (34 loc) · 1.01 KB
/
main.rs
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
use anyhow::Result;
use polars::frame::DataFrame;
use snowflake_api::SnowflakeApi;
#[tokio::main]
async fn main() -> Result<()> {
dotenv::dotenv().ok();
tracing_subscriber::fmt::init();
let api = SnowflakeApi::from_env()?;
// run a query that returns a tabular arrow response
run_and_print(
&api,
r"
select
count(query_id) as num_queries,
user_name
from snowflake.account_usage.query_history
where
start_time > current_date - 7
group by user_name;
",
)
.await?;
// run a query that returns a json response
run_and_print(&api, r"SHOW DATABASES;").await?;
Ok(())
}
async fn run_and_print(api: &SnowflakeApi, sql: &str) -> Result<()> {
let res = api.exec_raw(sql).await?;
let df = DataFrame::try_from(res)?;
// alternatively, you can use the `try_into` method on the response
// let df: DataFrame = res.try_into()?;
println!("{:?}", df);
Ok(())
}