taxa-sql 0.1.0

taxa SqlSource: ingest a Postgres query into an in-memory Polars DataFrame (a taxa_core::Source).
//! Live integration test against the local `investing` Postgres DB.
//!
//! Ignored by default (needs a live DB). Run explicitly with:
//!   cargo test -p taxa-sql -- --ignored

use polars::prelude::*;
use taxa_core::source::Source;
use taxa_sql::SqlSource;

// The sync `postgres` crate needs an explicit host. The socket lives in /tmp
// on this box; /var/run/postgresql is the other common location.
const DSN: &str = "host=/tmp dbname=investing";

#[test]
#[ignore = "requires a live Postgres at host=/tmp dbname=investing"]
fn live_universe_snapshots() {
    let query = "SELECT symbol, market_cap_usd, snapshot_date FROM universe_snapshots LIMIT 100";
    let src = SqlSource::connect(DSN, query).expect("connect + ingest");

    // It's a SqlSource that ingested 100 rows.
    assert_eq!(src.height(), 100);

    let df = src.frame().expect("frame").collect().expect("collect");
    assert_eq!(df.height(), 100, "frame should have 100 rows");

    // columns() contains the three names.
    let cols = src.columns().expect("columns");
    for name in ["symbol", "market_cap_usd", "snapshot_date"] {
        assert!(cols.contains(name), "missing column {name}");
    }

    // market_cap_usd (NUMERIC) decoded to Float64.
    let mcap_dtype = df.column("market_cap_usd").unwrap().dtype();
    assert_eq!(
        mcap_dtype,
        &DataType::Float64,
        "market_cap_usd should be Float64"
    );

    println!("live test OK: shape={:?}", df.shape());
    println!("dtypes: {:?}", src.schema().unwrap());
    println!("{}", df.head(Some(5)));
}