use crate::adapters::bigquery::constants::NO_INTERNAL_STAGE_COPY as BIGQUERY_NO_INTERNAL_STAGE_COPY;
use crate::adapters::clickhouse::constants::NO_INTERNAL_STAGE_COPY as CLICKHOUSE_NO_INTERNAL_STAGE_COPY;
use crate::adapters::clickhouse::main::plan::_direct_problem::direct_problem as clickhouse_direct_problem;
use crate::adapters::databricks::constants::NO_INTERNAL_STAGE_COPY;
#[cfg(feature = "duckdb")]
use crate::adapters::duckdb::main::_direct_problem::direct_problem;
use crate::adapters::postgres::constants::NO_INTERNAL_STAGE_COPY as POSTGRES_NO_INTERNAL_STAGE_COPY;
use crate::adapters::snowflake::main::copy::_direct_check::direct_check;
use crate::adapters::snowflake::main::copy::_stage_covers::stage_covers;
use crate::adapters::snowflake::models::StageRoute;
use crate::column_types::models::Warehouse;
use crate::files_source::models::FilesRead;
use crate::loader::models::TableSpec;
pub fn direct_blocked(
spec: &TableSpec,
read: &FilesRead,
stage: Option<&StageRoute>,
) -> Option<String> {
let files = spec.files.as_ref()?;
let refused = match spec.warehouse {
Warehouse::Databricks => Some(NO_INTERNAL_STAGE_COPY),
Warehouse::BigQuery => Some(BIGQUERY_NO_INTERNAL_STAGE_COPY),
Warehouse::Postgres => Some(POSTGRES_NO_INTERNAL_STAGE_COPY),
Warehouse::ClickHouse => Some(CLICKHOUSE_NO_INTERNAL_STAGE_COPY),
_ => None,
};
if let Some(refused) = refused {
return match (files.copy_to_internal_stage, spec.warehouse) {
(true, _) => Some(refused.to_owned()),
(false, Warehouse::ClickHouse) => clickhouse_direct_problem(spec, read),
(false, _) => None,
};
}
#[cfg(feature = "duckdb")]
if spec.warehouse == Warehouse::DuckDb {
return direct_problem(spec, read);
}
let covering = match stage {
Some(StageRoute::External(stage)) if stage_covers(&stage.location, &files.location) => {
Some(stage)
}
_ => None,
};
if covering.is_none() && !files.copy_to_internal_stage {
return None;
}
direct_check(
spec,
(read, read.files.as_slice(), &[]),
covering.map(AsRef::as_ref),
)
}