SapHanaRealVectorToFloatArrayPropertyHandler

A property handler that maps the SAP HANA REAL_VECTOR type into a float array property.

A property handler that maps the SAP HANA REAL_VECTOR type into a float array property.

The parameter must be typed as HanaDbType.RealVector for the value to be written into a REAL_VECTOR column, for example via the SapHanaDbType attribute.

The HALF_VECTOR type is not supported by the driver, and therefore not by this handler.

Overview

Name Description
Class SapHanaRealVectorToFloatArrayPropertyHandler
Namespace RepoDb.PropertyHandlers.SapHana
Package RepoDb.SapHana
Implements IPropertyHandler<object, float[]>
Column type The SAP HANA REAL_VECTOR type
Property type float[]

Conversions

Method Direction Description
Get Database to property Converts the value returned by the driver into a float[]. The driver reads a REAL_VECTOR as a float[] and, depending on how the value is fetched, it can also surface it in the binary vector format of SAP HANA (little-endian single-precision values, optionally prefixed by a 4-byte dimension count). This handler accepts both. null and DBNull are returned as null.
Set Property to database Passes the float[] to the driver, which binds it as a REAL_VECTOR value.

Exceptions

Exception Thrown When
ArgumentException The type or the layout of the value returned by the driver is not supported, for example a byte[] whose length is not a multiple of 4 bytes.

Usability

Bind the handler to the property that maps to a REAL_VECTOR column, and type the parameter as HanaDbType.RealVector.

Attribute

public class Embedding
{
    public int Id { get; set; }

    [Map("vector"), SapHanaDbType(HanaDbType.RealVector), PropertyHandler(typeof(SapHanaRealVectorToFloatArrayPropertyHandler))]
    public float[] Vector { get; set; }
}

Once bound, the library invokes the handler automatically when the property is read or written.

using (var connection = new HanaConnection(connectionString))
{
    connection.Insert(new Embedding { Id = 1, Vector = new float[] { 1.5f, 2.5f, 3.5f } });
    var embedding = connection.Query<Embedding>(e => e.Id == 1).First();
}

Fluent Mapping

To configure via FluentMapper:

FluentMapper
    .Entity<Embedding>()
    .PropertyHandler<SapHanaRealVectorToFloatArrayPropertyHandler>(e => e.Vector);

Property Level Mapping

To configure via PropertyHandlerMapper:

PropertyHandlerMapper.Add<Embedding, SapHanaRealVectorToFloatArrayPropertyHandler>(e => e.Vector, new SapHanaRealVectorToFloatArrayPropertyHandler(), true);

Type Level Mapping

To apply the handler to every property of the type float[]:

PropertyHandlerMapper.Add<float[], SapHanaRealVectorToFloatArrayPropertyHandler>(new SapHanaRealVectorToFloatArrayPropertyHandler(), true);

A type level mapping is process-wide: it is applied to every float[] property of every entity and connection, not only to the intended column. Prefer the attribute, fluent or property level mapping unless every float[] property maps to a REAL_VECTOR column.

See Also