> ## 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.

# ShardKeyExtractor

> ShardKeyExtractor — Kinetica Rust API

[gpudb\_api](https://docs.kinetica.com/content/api/rust/index.md)::<wbr />[bulk\_inserter\_common](https://docs.kinetica.com/content/api/rust/bulk_inserter_common/index.md)
[Source](https://github.com/kineticadb/kinetica-api-rust/blob/master/crates/gpudb-api/src/bulk_inserter_common.rs#L125-L131)&#x20;

<pre>`pub trait ShardKeyExtractor {    // Required method    fn shard_key_values(&self) -> ShardKeyValues<'_>;}`</pre>

Trait for extracting shard key values from a record.Records must implement this trait to enable shard-aware routing. Returns a SmallVec of (column\_name, typed\_value) pairs for shard key columns.

## Performance

<ul>
  <li>Returns `ShardKeyValues` (SmallVec) which is stack-allocated for up to 4 columns</li>
  <li>Use typed variants (`Int`, `Long`, `Float`, `Double`) when possible to avoid string parsing overhead</li>
  <li>The `String` variants are for string/char columns, and specialized variants (`Date`, `Ipv4`, `Decimal`) handle formatted types</li>
  <li>Use the `smallvec!` macro for convenient construction</li>
</ul>

## Example

```rust theme={null}
use smallvec::smallvec;
use gpudb_api::{ShardKeyExtractor, ShardKeyValue, ShardKeyValues};

impl ShardKeyExtractor for MyRecord {
    fn shard_key_values(&self) -> ShardKeyValues<'_> {
        smallvec![
            ("id", ShardKeyValue::Int(self.id)),
            ("region", ShardKeyValue::String(&self.region)),
        ]
    }
}
```

## Required Methods

[Source](https://github.com/kineticadb/kinetica-api-rust/blob/master/crates/gpudb-api/src/bulk_inserter_common.rs#L130)
fn [shard\_key\_values](#tymethod.shard_key_values)(\&self) -> [ShardKeyValues](https://docs.kinetica.com/content/api/rust/bulk_inserter_common/type.ShardKeyValues.md)\<'\_>

Returns shard key column names and their typed values.Only columns that are part of the shard key need to be included. Returns a SmallVec which is stack-allocated for up to 4 shard columns.

## Dyn Compatibility

This trait is [dyn compatible](https://doc.rust-lang.org/1.98.1/reference/items/traits.html#dyn-compatibility).In older versions of Rust, dyn compatibility was called "object safety".

## Implementations on Foreign Types

[Source](https://github.com/kineticadb/kinetica-api-rust/blob/master/crates/gpudb-api/src/bulk_inserter_common.rs#L136-L140)
impl [ShardKeyExtractor](https://docs.kinetica.com/content/api/rust/bulk_inserter_common/trait.ShardKeyExtractor.md) for [String](https://doc.rust-lang.org/1.98.1/alloc/string/struct.String.html)

A JSON record, as a [`BulkInserter`](https://docs.kinetica.com/content/api/rust/bulk_inserter/struct.BulkInserter) in JSON mode takes it. Its key is not read: it has no shard key values, and each record goes to the rank of a random shard.

[Source](https://github.com/kineticadb/kinetica-api-rust/blob/master/crates/gpudb-api/src/bulk_inserter_common.rs#L137-L139)
fn [shard\_key\_values](#tymethod.shard_key_values)(\&self) -> [ShardKeyValues](https://docs.kinetica.com/content/api/rust/bulk_inserter_common/type.ShardKeyValues.md)\<'\_>

## Implementors

[Source](https://github.com/kineticadb/kinetica-api-rust/blob/master/crates/gpudb-api/src/generic_record.rs#L2339-L2378)
impl [ShardKeyExtractor](https://docs.kinetica.com/content/api/rust/bulk_inserter_common/trait.ShardKeyExtractor.md) for [GenericRecord](https://docs.kinetica.com/content/api/rust/generic_record/struct.GenericRecord.md)


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