Skip to main content

Given

Struct Given 

Source
pub struct Given {
    pub delimiter: Option<u8>,
    pub quote: Option<u8>,
    pub escape: Option<u8>,
    pub header: Option<bool>,
    pub nulls: Option<Vec<String>>,
    pub names: Option<Vec<String>>,
    pub typed: bool,
}
Expand description

What the caller said about how the file is written, where the sniffer would otherwise decide.

Every field is optional and a None means nothing was said, which is the common case and is the one the sniffer is for. What is given is not sniffed: read_csv('f.csv', delim=';') does not try the four candidates and pick one, it uses the semicolon, and a file that is really comma separated then comes back as one column. That is DuckDB’s behaviour and it is the useful one, since somebody who wrote the delimiter down knows something the first megabyte of the file does not say.

A given value also changes the block DuckDB prints under a conversion error, where a line reads (Set By User) rather than (Auto-Detected), which is why this is carried into the reader rather than folded into a Dialect and forgotten.

The last three are not punctuation, and they are here because they travel the same road: the binder works them out from the call to sniff the file with and the executor works them out again from the plan to read it with, and a second struct beside this one would be a second thing for the two ends to keep in step.

Fields§

§delimiter: Option<u8>

The byte between two fields.

§quote: Option<u8>

The byte that opens and closes a field.

§escape: Option<u8>

The byte that makes the next quote a literal one.

§header: Option<bool>

Whether the first line names the columns.

§nulls: Option<Vec<String>>

The strings that read as a null, which is nullstr on a call and NULL on a COPY.

None is DuckDB’s default, where an empty field is a null. A field is compared once its quotes and escapes are gone, so "NA" is as much a null as NA is, and with any list here an empty field is an empty string rather than a null. Both were measured on v2.0.0-dev84237, where allow_quoted_nulls is on unless it is turned off, and it cannot be turned off here.

§names: Option<Vec<String>>

What to call the columns, first column first, in place of what the header or the generator called them. A list shorter than the file names the columns it reaches.

§typed: bool

Whether the column types are the caller’s rather than the sniffer’s, which is what COPY t FROM does with the table’s.

The reader converts to whatever types it is told either way. What this changes is the error for a value that does not convert, which tells somebody who set the type to look at the data and somebody who did not to set one.

Implementations§

Source§

impl Given

Source

pub fn shown(given: Option<u8>, sniffed: Option<u8>) -> String

How a byte is written in the block under a conversion error, and where it came from.

Source

pub fn null_strings(&self) -> Option<Vec<Vec<u8>>>

The strings that read as a null, with DuckDB’s default of the empty string written out as None so that a caller who wrote NULL '' gets the same fast test as one who wrote nothing.

Source

pub const fn source(given: bool) -> &'static str

What the block calls a value the caller gave and one it worked out.

Trait Implementations§

Source§

impl Clone for Given

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Given

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Given

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for Given

Source§

impl PartialEq for Given

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Given

Auto Trait Implementations§

§

impl Freeze for Given

§

impl RefUnwindSafe for Given

§

impl Send for Given

§

impl Sync for Given

§

impl Unpin for Given

§

impl UnsafeUnpin for Given

§

impl UnwindSafe for Given

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.