> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kinetica.com/llms.txt
> Use this file to discover all available pages before exploring further.

# AvroSchemaBuilder

> AvroSchemaBuilder — Kinetica Rust API

[gpudb\_api](https://docs.kinetica.com/content/api/rust/index.md)::<wbr />[avro\_schema\_builder](https://docs.kinetica.com/content/api/rust/avro_schema_builder/index.md)
[Source](https://github.com/kineticadb/kinetica-api-rust/blob/master/crates/gpudb-api/src/avro_schema_builder.rs#L162-L167)&#x20;

<pre>`pub struct AvroSchemaBuilder { /* private fields */ }`</pre>

Builder for constructing Avro record schemas programmatically

## Example

```rust theme={null}
use gpudb_api::avro_schema_builder::{AvroSchemaBuilder, AvroType};

let schema = AvroSchemaBuilder::new("IngestRecord")
    .field("timestampMillis", AvroType::Long)
    .field("source", AvroType::Int)
    .field("payload", AvroType::Bytes)
    .build();
```

## Implementations

[Source](https://github.com/kineticadb/kinetica-api-rust/blob/master/crates/gpudb-api/src/avro_schema_builder.rs#L169-L334)
impl [AvroSchemaBuilder](https://docs.kinetica.com/content/api/rust/avro_schema_builder/struct.AvroSchemaBuilder.md)

[Source](https://github.com/kineticadb/kinetica-api-rust/blob/master/crates/gpudb-api/src/avro_schema_builder.rs#L171-L178)
pub fn [new](#method.new)(name: impl [Into](https://doc.rust-lang.org/1.98.1/core/convert/trait.Into.html)\<[String](https://doc.rust-lang.org/1.98.1/alloc/string/struct.String.html)>) -> Self

Creates a new schema builder with the given record name

[Source](https://github.com/kineticadb/kinetica-api-rust/blob/master/crates/gpudb-api/src/avro_schema_builder.rs#L181-L184)
pub fn [namespace](#method.namespace)(self, namespace: impl [Into](https://doc.rust-lang.org/1.98.1/core/convert/trait.Into.html)\<[String](https://doc.rust-lang.org/1.98.1/alloc/string/struct.String.html)>) -> Self

Sets the namespace for the record

[Source](https://github.com/kineticadb/kinetica-api-rust/blob/master/crates/gpudb-api/src/avro_schema_builder.rs#L187-L190)
pub fn [doc](#method.doc)(self, doc: impl [Into](https://doc.rust-lang.org/1.98.1/core/convert/trait.Into.html)\<[String](https://doc.rust-lang.org/1.98.1/alloc/string/struct.String.html)>) -> Self

Sets the documentation for the record

[Source](https://github.com/kineticadb/kinetica-api-rust/blob/master/crates/gpudb-api/src/avro_schema_builder.rs#L193-L200)
pub fn [field](#method.field)(self, name: impl [Into](https://doc.rust-lang.org/1.98.1/core/convert/trait.Into.html)\<[String](https://doc.rust-lang.org/1.98.1/alloc/string/struct.String.html)>, avro\_type: [AvroType](https://docs.kinetica.com/content/api/rust/avro_schema_builder/enum.AvroType.md)) -> Self

Adds a field with the given name and type

[Source](https://github.com/kineticadb/kinetica-api-rust/blob/master/crates/gpudb-api/src/avro_schema_builder.rs#L203-L215)
pub fn [field\_with\_doc](#method.field_with_doc)( self, name: impl [Into](https://doc.rust-lang.org/1.98.1/core/convert/trait.Into.html)\<[String](https://doc.rust-lang.org/1.98.1/alloc/string/struct.String.html)>, avro\_type: [AvroType](https://docs.kinetica.com/content/api/rust/avro_schema_builder/enum.AvroType.md), doc: impl [Into](https://doc.rust-lang.org/1.98.1/core/convert/trait.Into.html)\<[String](https://doc.rust-lang.org/1.98.1/alloc/string/struct.String.html)>, ) -> Self

Adds a field with documentation

[Source](https://github.com/kineticadb/kinetica-api-rust/blob/master/crates/gpudb-api/src/avro_schema_builder.rs#L218-L220)
pub fn [nullable\_field](#method.nullable_field)( self, name: impl [Into](https://doc.rust-lang.org/1.98.1/core/convert/trait.Into.html)\<[String](https://doc.rust-lang.org/1.98.1/alloc/string/struct.String.html)>, avro\_type: [AvroType](https://docs.kinetica.com/content/api/rust/avro_schema_builder/enum.AvroType.md), ) -> Self

Adds a nullable field (shorthand for `field(name, AvroType::Nullable(...))`)

[Source](https://github.com/kineticadb/kinetica-api-rust/blob/master/crates/gpudb-api/src/avro_schema_builder.rs#L227-L229)
pub fn [int\_field](#method.int_field)(self, name: impl [Into](https://doc.rust-lang.org/1.98.1/core/convert/trait.Into.html)\<[String](https://doc.rust-lang.org/1.98.1/alloc/string/struct.String.html)>) -> Self

Adds an integer field

[Source](https://github.com/kineticadb/kinetica-api-rust/blob/master/crates/gpudb-api/src/avro_schema_builder.rs#L232-L234)
pub fn [long\_field](#method.long_field)(self, name: impl [Into](https://doc.rust-lang.org/1.98.1/core/convert/trait.Into.html)\<[String](https://doc.rust-lang.org/1.98.1/alloc/string/struct.String.html)>) -> Self

Adds a long (i64) field

[Source](https://github.com/kineticadb/kinetica-api-rust/blob/master/crates/gpudb-api/src/avro_schema_builder.rs#L237-L239)
pub fn [float\_field](#method.float_field)(self, name: impl [Into](https://doc.rust-lang.org/1.98.1/core/convert/trait.Into.html)\<[String](https://doc.rust-lang.org/1.98.1/alloc/string/struct.String.html)>) -> Self

Adds a float field

[Source](https://github.com/kineticadb/kinetica-api-rust/blob/master/crates/gpudb-api/src/avro_schema_builder.rs#L242-L244)
pub fn [double\_field](#method.double_field)(self, name: impl [Into](https://doc.rust-lang.org/1.98.1/core/convert/trait.Into.html)\<[String](https://doc.rust-lang.org/1.98.1/alloc/string/struct.String.html)>) -> Self

Adds a double field

[Source](https://github.com/kineticadb/kinetica-api-rust/blob/master/crates/gpudb-api/src/avro_schema_builder.rs#L247-L249)
pub fn [string\_field](#method.string_field)(self, name: impl [Into](https://doc.rust-lang.org/1.98.1/core/convert/trait.Into.html)\<[String](https://doc.rust-lang.org/1.98.1/alloc/string/struct.String.html)>) -> Self

Adds a string field

[Source](https://github.com/kineticadb/kinetica-api-rust/blob/master/crates/gpudb-api/src/avro_schema_builder.rs#L256-L258)
pub fn [bool\_field](#method.bool_field)(self, name: impl [Into](https://doc.rust-lang.org/1.98.1/core/convert/trait.Into.html)\<[String](https://doc.rust-lang.org/1.98.1/alloc/string/struct.String.html)>) -> Self

Adds a boolean field: an Avro `int`, as Kinetica stores a boolean (give the column the `boolean` property). The struct’s `bool` field must be written as an int, with `#[serde(with = "gpudb_api::avro_schema_builder::bool_as_int")]` (see [`bool_as_int`](https://docs.kinetica.com/content/api/rust/avro_schema_builder/bool_as_int/index)); unannotated, it fails to encode.

[Source](https://github.com/kineticadb/kinetica-api-rust/blob/master/crates/gpudb-api/src/avro_schema_builder.rs#L261-L263)
pub fn [bytes\_field](#method.bytes_field)(self, name: impl [Into](https://doc.rust-lang.org/1.98.1/core/convert/trait.Into.html)\<[String](https://doc.rust-lang.org/1.98.1/alloc/string/struct.String.html)>) -> Self

Adds a bytes field

[Source](https://github.com/kineticadb/kinetica-api-rust/blob/master/crates/gpudb-api/src/avro_schema_builder.rs#L266-L268)
pub fn [timestamp\_field](#method.timestamp_field)(self, name: impl [Into](https://doc.rust-lang.org/1.98.1/core/convert/trait.Into.html)\<[String](https://doc.rust-lang.org/1.98.1/alloc/string/struct.String.html)>) -> Self

Adds a timestamp field (long type, typically milliseconds since epoch)

[Source](https://github.com/kineticadb/kinetica-api-rust/blob/master/crates/gpudb-api/src/avro_schema_builder.rs#L271-L273)
pub fn [nullable\_string\_field](#method.nullable_string_field)(self, name: impl [Into](https://doc.rust-lang.org/1.98.1/core/convert/trait.Into.html)\<[String](https://doc.rust-lang.org/1.98.1/alloc/string/struct.String.html)>) -> Self

Adds a nullable string field

[Source](https://github.com/kineticadb/kinetica-api-rust/blob/master/crates/gpudb-api/src/avro_schema_builder.rs#L276-L278)
pub fn [nullable\_int\_field](#method.nullable_int_field)(self, name: impl [Into](https://doc.rust-lang.org/1.98.1/core/convert/trait.Into.html)\<[String](https://doc.rust-lang.org/1.98.1/alloc/string/struct.String.html)>) -> Self

Adds a nullable int field

[Source](https://github.com/kineticadb/kinetica-api-rust/blob/master/crates/gpudb-api/src/avro_schema_builder.rs#L281-L283)
pub fn [nullable\_long\_field](#method.nullable_long_field)(self, name: impl [Into](https://doc.rust-lang.org/1.98.1/core/convert/trait.Into.html)\<[String](https://doc.rust-lang.org/1.98.1/alloc/string/struct.String.html)>) -> Self

Adds a nullable long field

[Source](https://github.com/kineticadb/kinetica-api-rust/blob/master/crates/gpudb-api/src/avro_schema_builder.rs#L286-L288)
pub fn [nullable\_double\_field](#method.nullable_double_field)(self, name: impl [Into](https://doc.rust-lang.org/1.98.1/core/convert/trait.Into.html)\<[String](https://doc.rust-lang.org/1.98.1/alloc/string/struct.String.html)>) -> Self

Adds a nullable double field

[Source](https://github.com/kineticadb/kinetica-api-rust/blob/master/crates/gpudb-api/src/avro_schema_builder.rs#L291-L293)
pub fn [nullable\_bytes\_field](#method.nullable_bytes_field)(self, name: impl [Into](https://doc.rust-lang.org/1.98.1/core/convert/trait.Into.html)\<[String](https://doc.rust-lang.org/1.98.1/alloc/string/struct.String.html)>) -> Self

Adds a nullable bytes field

[Source](https://github.com/kineticadb/kinetica-api-rust/blob/master/crates/gpudb-api/src/avro_schema_builder.rs#L296-L312)
pub fn [build](#method.build)(\&self) -> [String](https://doc.rust-lang.org/1.98.1/alloc/string/struct.String.html)

Builds the Avro schema JSON string

[Source](https://github.com/kineticadb/kinetica-api-rust/blob/master/crates/gpudb-api/src/avro_schema_builder.rs#L330-L333)
pub fn [build\_static](#method.build_static)(\&self) -> &'static [str](https://doc.rust-lang.org/1.98.1/std/primitive.str.html)

Builds the schema and leaks it to get a `&'static str`This is useful for implementing `KineticaRecord::avro_schema()` which requires returning `&'static str`. The memory is intentionally leaked since schemas are typically created once and live for the program’s lifetime.

##### Example

```rust theme={null}
use gpudb_api::avro_schema_builder::{AvroSchemaBuilder, AvroType};

let schema: &'static str = AvroSchemaBuilder::new("MyRecord")
    .int_field("id")
    .string_field("name")
    .build_static();
```

## Trait Implementations

[Source](https://github.com/kineticadb/kinetica-api-rust/blob/master/crates/gpudb-api/src/avro_schema_builder.rs#L161)
impl [Clone](https://doc.rust-lang.org/1.98.1/core/clone/trait.Clone.html) for [AvroSchemaBuilder](https://docs.kinetica.com/content/api/rust/avro_schema_builder/struct.AvroSchemaBuilder.md)

[Source](https://github.com/kineticadb/kinetica-api-rust/blob/master/crates/gpudb-api/src/avro_schema_builder.rs#L161)
fn [clone](https://doc.rust-lang.org/1.98.1/core/clone/trait.Clone.html#tymethod.clone)(\&self) -> [AvroSchemaBuilder](https://docs.kinetica.com/content/api/rust/avro_schema_builder/struct.AvroSchemaBuilder.md)

Returns a duplicate of the value. [Read more](https://doc.rust-lang.org/1.98.1/core/clone/trait.Clone.html#tymethod.clone)

1.0.0 (const: [unstable](https://github.com/rust-lang/rust/issues/142757)) · [Source](https://doc.rust-lang.org/1.98.1/src/core/clone.rs.html#245-247)
fn [clone\_from](https://doc.rust-lang.org/1.98.1/core/clone/trait.Clone.html#method.clone_from)(\&mut self, source: \&Self)

Performs copy-assignment from `source`. [Read more](https://doc.rust-lang.org/1.98.1/core/clone/trait.Clone.html#method.clone_from)

[Source](https://github.com/kineticadb/kinetica-api-rust/blob/master/crates/gpudb-api/src/avro_schema_builder.rs#L161)
impl [Debug](https://doc.rust-lang.org/1.98.1/core/fmt/trait.Debug.html) for [AvroSchemaBuilder](https://docs.kinetica.com/content/api/rust/avro_schema_builder/struct.AvroSchemaBuilder.md)

[Source](https://github.com/kineticadb/kinetica-api-rust/blob/master/crates/gpudb-api/src/avro_schema_builder.rs#L161)
fn [fmt](https://doc.rust-lang.org/1.98.1/core/fmt/trait.Debug.html#tymethod.fmt)(\&self, f: \&mut [Formatter](https://doc.rust-lang.org/1.98.1/core/fmt/struct.Formatter.html)\<'\_>) -> [Result](https://doc.rust-lang.org/1.98.1/core/fmt/type.Result.html)

Formats the value using the given formatter. [Read more](https://doc.rust-lang.org/1.98.1/core/fmt/trait.Debug.html#tymethod.fmt)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.