Function arrow_schema_from

Source
pub fn arrow_schema_from(
    result_set_metadata: &mut impl ResultSetMetadata,
    dbms_name: Option<&str>,
    map_value_errors_to_null: bool,
) -> Result<Schema, Error>
Expand description

Query the metadata to create an arrow schema. This method is invoked automatically for you by crate::OdbcReaderBuilder::build. You may want to call this method in situation there you want to create an arrow schema without creating the reader yet.

§Parameters

  • result_set_metadata: Used to query metadata about the columns in the result set, which is used to determine the arrow schema.
  • dbms_name: If provided, it is used to account for Database specific behavior than mapping types. Currently it is used to map TIME types from ‘Microsoft SQL Server’ to Time32 or Time64
  • map_value_errors_to_null: In case falliable conversions should result in NULL the arrow field must be nullable, even if the source column on the database is not nullable.

§Example

use anyhow::Error;

use arrow_odbc::{arrow_schema_from, arrow::datatypes::Schema, odbc_api::Connection};

fn fetch_schema_for_table(
    table_name: &str,
    connection: &Connection<'_>
) -> Result<Schema, Error> {
    // Query column with values to get a cursor
    let sql = format!("SELECT * FROM {}", table_name);
    let mut prepared = connection.prepare(&sql)?;
     
    // Now that we have prepared statement, we want to use it to query metadata.
    let map_errors_to_null = false;
    let dbms_name = None;
    let schema = arrow_schema_from(&mut prepared, dbms_name, map_errors_to_null)?;
    Ok(schema)
}