sqlload 0.87.0

SQL data loading tooling.
//! What stops or endangers a write into a table.

use crate::adapters::contract::models::{TableName, WriteMode};
use crate::adapters::dispatch::models::Destination;
#[cfg(feature = "duckdb")]
use crate::adapters::duckdb::main::_stage_problems::stage_problems;
#[cfg(feature = "duckdb")]
use crate::adapters::duckdb::main::_variant_problems::variant_problems;
use crate::adapters::postgres::main::session::_session_write_problems::session_write_problems as session_postgres_write_problems;
use crate::adapters::postgres::main::session::_write_problems::write_problems as postgres_write_problems;
use crate::column_types::models::Warehouse;
use crate::loader::errors::LoaderError;

/// Why `mode` cannot run against `table` (`exists` when it does) (problems), and what it may fail on (warnings); `variants` when the table has `VARIANT` columns, which MotherDuck needs a recent enough DuckDB for; and a MotherDuck `external_stage` SQLLoad cannot write or MotherDuck cannot read. None where the warehouse's writes need nothing of the table or its server.
pub async fn write_problems(
    destination: &Destination,
    table: &TableName,
    (mode, exists, variants): (&WriteMode, bool, bool),
) -> Result<(Vec<String>, Vec<String>), LoaderError> {
    #[cfg(not(feature = "duckdb"))]
    let _ = variants;
    match destination {
        Destination::Postgres(postgres) => {
            postgres_write_problems(postgres, table, (mode, exists)).await
        }
        Destination::Session(session) if session.connection.warehouse == Warehouse::Postgres => {
            session_postgres_write_problems(session, table, (mode, exists)).await
        }
        #[cfg(feature = "duckdb")]
        Destination::DuckDb(duckdb) => {
            let (mut problems, warnings) = match variants {
                true => variant_problems(duckdb).await,
                false => (Vec::new(), Vec::new()),
            };
            problems.extend(stage_problems(duckdb).await);
            Ok((problems, warnings))
        }
        _ => Ok((Vec::new(), Vec::new())),
    }
}