fn validate_new_batch(
        schema: &Schema,
        columns: &[ArrayRef],
        options: &RecordBatchOptions,
    ) -> Result<()> {
        // check that there are some columns
        if columns.is_empty() {
            return Err(ArrowError::InvalidArgumentError(
                "at least one column must be defined to create a record batch".to_string(),
            ));
        }
        // check that number of fields in schema match column length
        if schema.fields().len() != columns.len() {
            return Err(ArrowError::InvalidArgumentError(format!(
                "number of columns({}) must match number of fields({}) in schema",
                columns.len(),
                schema.fields().len(),
            )));
        }
        // check that all columns have the same row count, and match the schema
        let len = columns[0].len();

        // This is a bit repetitive, but it is better to check the condition outside the loop
        if options.match_field_names {
            for (i, column) in columns.iter().enumerate() {
                if column.len() != len {
                    return Err(ArrowError::InvalidArgumentError(
                        "all columns in a record batch must have the same length".to_string(),
                    ));
                }
                if column.data_type() != schema.field(i).data_type() {
                    return Err(ArrowError::InvalidArgumentError(format!(
                        "column types must match schema types, expected {:?} but found {:?} at column index {}",
                        schema.field(i).data_type(),
                        column.data_type(),
                        i)));
                }
            }
        } else {
            for (i, column) in columns.iter().enumerate() {
                if column.len() != len {
                    return Err(ArrowError::InvalidArgumentError(
                        "all columns in a record batch must have the same length".to_string(),
                    ));
                }
                if !column
                    .data_type()
                    .equals_datatype(schema.field(i).data_type())
                {
                    return Err(ArrowError::InvalidArgumentError(format!(
                        "column types must match schema types, expected {:?} but found {:?} at column index {}",
                        schema.field(i).data_type(),
                        column.data_type(),
                        i)));
                }
            }
        }

        Ok(())
    }
/// Validate the schema and columns using [`RecordBatchOptions`]. Returns an error
/// if any validation check fails.
Validate the schema and columns using [`RecordBatchOptions`]. Returns an error
if any validation check fails.
Validate the schema and columns using [ ` RecordBatchOptions ` ] . Returns an error if any validation check fails .
fn validate_new_batch(
        schema: &Schema,
        columns: &[ArrayRef],
        options: &RecordBatchOptions,
    ) -> Result<()> {
        // check that there are some columns
        if columns.is_empty() {
            return Err(ArrowError::InvalidArgumentError(
                "at least one column must be defined to create a record batch".to_string(),
            ));
        }
        // check that number of fields in schema match column length
        if schema.fields().len() != columns.len() {
            return Err(ArrowError::InvalidArgumentError(format!(
                "number of columns({}) must match number of fields({}) in schema",
                columns.len(),
                schema.fields().len(),
            )));
        }
        // check that all columns have the same row count, and match the schema
        let len = columns[0].len();
        // This is a bit repetitive, but it is better to check the condition outside the loop
        if options.match_field_names {
            for (i, column) in columns.iter().enumerate() {
                if column.len() != len {
                    return Err(ArrowError::InvalidArgumentError(
                        "all columns in a record batch must have the same length".to_string(),
                    ));
                }
                if column.data_type() != schema.field(i).data_type() {
                    return Err(ArrowError::InvalidArgumentError(format!(
                        "column types must match schema types, expected {:?} but found {:?} at column index {}",
                        schema.field(i).data_type(),
                        column.data_type(),
                        i)));
                }
            }
        } else {
            for (i, column) in columns.iter().enumerate() {
                if column.len() != len {
                    return Err(ArrowError::InvalidArgumentError(
                        "all columns in a record batch must have the same length".to_string(),
                    ));
                }
                if !column
                    .data_type()
                    .equals_datatype(schema.field(i).data_type())
                {
                    return Err(ArrowError::InvalidArgumentError(format!(
                        "column types must match schema types, expected {:?} but found {:?} at column index {}",
                        schema.field(i).data_type(),
                        column.data_type(),
                        i)));
                }
            }
        }
        Ok(())
    }
fn validate_new_batch ( schema : & Schema , columns : & [ ArrayRef ] , options : & RecordBatchOptions , ) -> Result < ( ) > { // check that there are some columns if columns . is_empty ( ) { return Err ( ArrowError :: InvalidArgumentError ( " " . to_string ( ) , ) ) ; } // check that number of fields in schema match column length if schema . fields ( ) . len ( ) != columns . len ( ) { return Err ( ArrowError :: InvalidArgumentError ( format ! ( " " columns len ( ) schema fields ( ) len ( ) ) ) ) ; } // check that all columns have the same row count, and match the schema let len = columns [ 0 ] . len ( ) ; // This is a bit repetitive, but it is better to check the condition outside the loop if options . match_field_names { for ( i , column ) in columns . iter ( ) . enumerate ( ) { if column . len ( ) != len { return Err ( ArrowError :: InvalidArgumentError ( " " . to_string ( ) , ) ) ; } if column . data_type ( ) != schema . field ( i ) . data_type ( ) { return Err ( ArrowError :: InvalidArgumentError ( format ! ( " " schema field ( i ) data_type ( ) column data_type ( ) i ) ) ) ; } } } else { for ( i , column ) in columns . iter ( ) . enumerate ( ) { if column . len ( ) != len { return Err ( ArrowError :: InvalidArgumentError ( " " . to_string ( ) , ) ) ; } if ! column . data_type ( ) . equals_datatype ( schema . field ( i ) . data_type ( ) ) { return Err ( ArrowError :: InvalidArgumentError ( format ! ( " " schema field ( i ) data_type ( ) column data_type ( ) i ) ) ) ; } } } Ok ( ( ) ) }
Validate the schema and columns using [`RecordBatchOptions`].
Validate the schema and columns using [ ` RecordBatchOptions ` ] .
schema
&Schema
columns
&[ArrayRef]
options
&RecordBatchOptions
schema
&Schema
columns
&[ArrayRef]
options
&RecordBatchOptions