data_goes 0.1.0-alpha.3.60

Biblioteca experimental para demonstração.
pub mod generator;
pub mod client_sql;
pub mod config;
pub mod map_schema;
pub use client_sql::{ClientSql, TabGoes}; 
pub use config::ConfigClient;
pub type Result<T> = anyhow::Result<T>;
pub use chrono;
pub use rust_decimal;
pub use uuid;
use polars::prelude::*;

#[derive(Debug, Clone, Copy, Default)]
pub enum IfExists {
    #[default]
    Append,
    Replace, 
    Fail,    
}


impl TabGoes {
     pub fn join_inner(mut self, other: TabGoes, left_cols: &[&str], right_cols: &[&str]) -> Self {
        let left_exprs: Vec<Expr> = left_cols.iter().map(|&c| col(c)).collect();
        let right_exprs: Vec<Expr> = right_cols.iter().map(|&c| col(c)).collect();

        self.lazy = self.lazy.join(
            other.lazy, 
            left_exprs, 
            right_exprs, 
            JoinArgs::new(JoinType::Inner)
        );
        self._files.extend(other._files);
        self
    }

    pub fn join_outer(mut self, other: TabGoes, left_cols: &[&str], right_cols: &[&str]) -> Self {
        let left_exprs: Vec<Expr> = left_cols.iter().map(|&c| col(c)).collect();
        let right_exprs: Vec<Expr> = right_cols.iter().map(|&c| col(c)).collect();

        self.lazy = self.lazy.join(
            other.lazy, 
            left_exprs, 
            right_exprs, 
            JoinArgs::new(JoinType::Left)
        );
        self._files.extend(other._files);
        self
    }

    pub fn union(mut self, other: TabGoes)->Result<Self>{
        self.lazy = concat(&[self.lazy, other.lazy], UnionArgs::default())?;
        self._files.extend(other._files);
        Ok(self)
    }

    pub fn order(mut self, cols: &[&str])-> Self{
        let exprs: Vec<Expr> = cols.iter().map(|&c| col(c)).collect();
        self.lazy = self.lazy.select(&exprs);
        self
    }

    pub async fn print(&self) -> Result<()> {
        let lazy = self.lazy.clone();
        let df = tokio::task::spawn_blocking(move || {
            lazy.collect()
        }).await??;
        println!("{}", df);
        Ok(())
    }

    pub fn filter<F>(mut self, predicate: F) -> Self 
        where F: FnOnce() -> Expr {
            self.lazy = self.lazy.filter(predicate());
            self
    }
    pub fn cast_to_string(mut self, column_name: &str) -> Self {
        self.lazy = self.lazy.with_columns([
            col(column_name).cast(DataType::String)
        ]);
        self
    }

}