14 Vector Support in Oracle Database

This chapter describes the Oracle Database vector support in OCCI.

Starting with Oracle Database Release 23ai vectors as a datatype is introduced to represent semi-structured and unstructured data for AI and machine learning semantics. Vectors are represented as a series of numbers with a specified length and number type.

The vector elements can be represented by the following data types:

  • INT8_t : This corresponds to an int8 (8-bit signed integer) data type in C++
  • FLOAT32 :This corresponds to a float in C++
  • FLOAT64 :This corresponds to a double type in C++
  • BINARY :Although C++ does not support binary data type, uin8_t is used to support binary data. Each uint8_t value has 8 bits (binary values). BINARY vectors must have a dimension that is a multiple of 8.

14.1 Oracle Database Vector Support in OCCI

This section describes the Oracle Database vector support functions in OCCI.

14.1.1 Binding Vectors in a Statement Handle

This section describes the functions introduced for binding the vector data to a statement handle.

14.1.1.1 setInt8Vector()

Sets the value of an Oracle Database Vector data type in int8(ub1) format from a C++ vector value of type int8_t.

Syntax

void setInt8Vector(unsigned int paramIndex,vector<int8_t> &vec);
Parameter Description
paramIndex Specifies the parameter index; first parameter is 1, second is 2, and so on.
vec Specifies the vector to be set.
14.1.1.2 setFloatVector()

Sets the value of an Oracle Database Vector data type in IEEE FLOAT32 format from a C++ vector value of type float.

Syntax

void setFloatVector(unsigned int paramIndex,vector<float> &vec);
Parameter Description
paramIndex Specifies the parameter index; first parameter is 1, second is 2, and so on.
vec Specifies the vector to be set.
14.1.1.3 setDoubleVector()

Sets the value of an Oracle Database Vector data type in format IEEE FLOAT64 from a C++ vector of type double.

Syntax

void setDoubleVector(unsigned int paramIndex,vector<double> &vec);
Parameter Description
paramIndex Specifies the parameter index; first parameter is 1, second is 2, and so on.
vec Specifies the vector to be set.
14.1.1.4 setBinaryVector()

Sets the value of an Oracle Database Vector data type in binary format from a C++ vector of type uint8_t.

Syntax

Note:

You can only insert binary vectors with dimensions that are a multiple of 8.
void setBinaryVector(unsigned int paramIndex,vector<uint8_t> &vec);
Parameter Description
paramIndex Specifies the parameter index; first parameter is 1, second is 2, and so on.
vec Specifies the vector to be set.

The following sample code snippet, binds the vector myData as a FLOAT32 to position 1 in stmt. On executing the statement further, it is inserted in the database table.

Statement *stmt;
stmt = conn->createStatement ("INSERT INTO test_vecflt values(:1,:2)");
vector<float> myData({1.4,1.2,3.5});
stmt->setInt(1,10);
stmt->setFloatVector(2,myData);
stmt->executeUpdate();

14.1.2 PL/SQL Out-Binds for Vectors

This section describes the functions used to get the output from PL/SQL procedures or functions through out-binds in a statement handle.

14.1.2.1 getInt8Vector()

Gets the value of an Oracle Database Vector data type in int8(ub1) format from a C++ vector value of type int8_t format.

Syntax

void getInt8Vector(unsigned int paramIndex,vector<int8_t> &vec);
Parameter Description
paramIndex
Specifies the parameter index; first parameter is 1, second is 2, and so on.
vec References to the vector (OUT parameter) into which the values must be inserted.
14.1.2.2 getFloatVector()

Gets the value of an Oracle Database Vector in IEEE FLOAT32 format from a C++ vector value of type float.

Syntax

void getFloatVector(unsigned int paramIndex,vector<float> &vec);
Parameter Description
paramIndex Specifies the parameter index; first parameter is 1, second is 2, and so on.
vec References to the vector (OUT parameter) into which the values must be inserted.
14.1.2.3 getDoubleVector()

Gets the value of an Oracle Database Vector data type in IEEE FLOAT64 format from a C++ vector value of type double.

Syntax

void getDoubleVector(unsigned int paramIndex,vector<double> &vec);
Parameter Description
paramIndex Specifies the parameter index; first parameter is 1, second is 2, and so on.
vec References to the vector (OUT parameter) into which the values must be inserted.
14.1.2.4 getBinaryVector()

Gets the value of an Oracle Database Vector data type in binary format inside a C++ vector of type uint8_t.

Syntax

void getBinaryVector(unsigned int paramIndex,vector<uint8_t>&vec);
Parameter Description
paramIndex Specifies the parameter index; first parameter is 1, second is 2, and so on.
vec References to the vector (OUT parameter) into which the values must be inserted.

Note:

Currently, the dimension of binary vectors is a multiple of 8. That is, 8*vec.size()where, vec is a stl vector<uint8_t>.

The following code snippet can be used for out binds to obtain a vector:

Statement *stmt;
stmt = conn->createStatement ("BEGIN occivec_demo(:1) END;");
//Disclaimer: Binary literals introduced in C++14 and above, used here for descriptive purposes.
vector<uint8_t> myInBind({0b00100011,0b01000011,0b10101011,0b01001001});
stmt->setBinaryVector(1,myInOutBind);
stmt->stmtExecute();
stmt->getBinaryVector(1,myInOutBind);

This obtains the data fetched from INOUT bind at position 1 in myInOutBind.

In case of flexible dimensions, there may be a case where the size of the vector is not the same as the dimension of the Database vector. In such a case, stmt->getBinaryVector() will always have a return value indicating the dimension of the OUT vector.

int dimension = stmt->getBinaryVector(1,myInOutBind);
//printing the bits
for(int i=0;i<dimension;i++)
    cout<<((v[i/8]>>(8-(i%8)))&1;
The following code snippet can be used for out binds to obtain a vector:
Statement *stmt;
stmt = conn->createStatement ("BEGIN occivec_demo(:1,:2,:3) END;");
vector<double> myInBind({1.4,1.2,3.5});
vector<double> myInOutBind;
vector<double> myOutBind;
stmt->setInt(1,myInBind);
stmt->setDoubleVector(2,myInOutBind);
stmt->registerOutParam(3,OCCI_SQLT_VEC);
stmt->stmtExecute();
stmt->getDoubleVector(2,myInOutBind);
stmt->getDoubleVector(3,myOutBind);

14.1.3 Defining Vectors from a ResultSet of a Query

This section describes the functions introduced in the ResultSet class to obtain the column values of type vector into C++ stl vector containers.

14.1.3.1 getInt8Vector()

Gets the column value of an Oracle Database Vector data type in int8(ub1) format as a C++ vector value of type int8_t.

Syntax

void getInt8Vector(unsigned int paramIndex,vector<int8_t> &vec);
Parameter Description
colIndex Specifies the column index, first column is 1, second is 2, and so on.
vec References to the vector (OUT parameter) into which the values must be inserted.
14.1.3.2 getFloatVector()

Gets the column value of an Oracle Database Vector data type in IEEE FLOAT32 format from a C++ vector value of type float.

Syntax

void getFloatVector(unsigned int paramIndex,vector<float> &vec);
Parameter Description
colIndex Specifies the column index, first column is 1, second is 2, and so on.
vec References to the vector (OUT parameter) into which the values must be inserted.
14.1.3.3 getDoubleVector()

Gets the column value of an Oracle Database Vector data type in IEEE FLOAT64 format from a C++ vector value of type double.

Syntax

void getDoubleVector(unsigned int paramIndex,vector<double> &vec);
Parameter Description
colIndex Specifies the column index, first column is 1, second is 2, and so on.
vec References to the vector (OUT parameter) into which the values must be inserted.
14.1.3.4 getBinaryVector()

Gets the column value of an Oracle Database Vector data type in binary format from a C++ vector value of type uint8_t.

Syntax

void getBinaryVector(unsigned int paramIndex,vector<uint8_t> &vec);
Parameter Description
colIndex Specifies the column index, first column is 1, second is 2, and so on.
vec References to the vector (OUT parameter) into which the values must be inserted.

The following code snippet can be used in ResultSet to obtain a vector:

Statement stmt;
stmt = conn->createStatement ("SELECT * FROM TEST_VECFLT");
ResultSet *rs = stmt->getResultSet();
vector<float> myResult;
stmt->stmtExecute();
rs->getFloatVector(2,myResult);

The type of vector data in the result depends on the function called. For example, getFloatVector corresponds to FLOAT32 format.

14.1.3.5 getString()

Gets the column value of an Oracle Database vector of any format as a C++ string.

Syntax

string getString(unsigned int paramIndex);
Parameter Description
colIndex Specifies the column index, first column is 1, second is 2, and so on.
The following sample code snippet can be used in ResultSet to obtain a vector:
Statement stmt;
stmt = conn->createStatement ("SELECT id,embedding FROM TEST_SPARSEVECFLT");
ResultSet *rs = stmt->getResultSet();
stmt->stmtExecute();
int id = rs->getInt(1);
string vec = rs->getString(2);

14.1.4 MetaData of Vectors

A new data type OCCI_SQLT_VEC is introduced for supporting MetaData in describe functionality.

The following column attributes specific to vector column have been added to MetaData:
  • ATTR_VECTOR_DIMENSION : Information of vector dimensions
  • ATTR_VECTOR_DATA_FORMAT: Type of data format stored in a vector column
  • ATTR_VECTOR_PROPERTY: Information of the data flag
The following code snippet is used to get the column metadata for a vector:
vector<MetaData> v1;
MetaData metaData = conn->getMetaData("TEST_VECDBL");
v1 = metaData.getVector(MetaData::ATTR_LIST_COLUMNS);
for(int i=0; i < v1.size(); i++)
{
    MetaData md = v1[i];
    cout << " Column Name :" << md.getString(MetaData::ATTR_NAME)           << endl;
    cout << " Data Type :"   << md.getInt(MetaData::ATTR_DATA_TYPE)         << endl;
    cout << " Dimension :"   << md.getUInt(MetaData::ATTR_VECTOR_DIMENSION) << endl;
}
14.1.4.1 Example
#include <sys/types.h>
#include <fstream>
#include <iostream>
#include <occi.h>
#include <cstdlib>
#include <string.h>
 
using namespace oracle::occi;
using namespace std;
 
static  char *username=strdup("scott");
static  char *password=strdup("tiger");
static  char *dbname=strdup("inst1");
 
class occivec
{
  private:
 
  Environment *env;
  Connection *conn;
  Statement *stmt;
  ResultSet *rs;
  public:
 
  occivec ()
  {
    env = Environment::createEnvironment (Environment::DEFAULT);
    conn = env->createConnection (username, password, dbname);
  }
 
  ~occivec ()
  {
    env->terminateConnection (conn);
    Environment::terminateEnvironment (env);
  }
 
  void displayAllRows (string tableName)
  {
    cout<<"--- Displaying rows of "<<tableName<<"---"<<endl;
    string sqlStmt = "select * from "+tableName;
    stmt = conn->createStatement (sqlStmt);
    ResultSet *rset = stmt->executeQuery ();
    try{
    while (rset->next ())
    {
      cout << "ID: " << rset->getInt (1) << endl;
      vector<double> ans;
      rset->getDoubleVector(2,ans);
      cout << "Embedding: ";
      for(auto i:ans)cout<<i<<" ";cout<<endl;
    }
    }catch(SQLException ex)
    {
     cout<<"Exception thrown for displayAllRows"<<endl;
     cout<<"Error number: "<<  ex.getErrorCode() << endl;
     cout<<ex.getMessage() << endl;
    }
 
    stmt->closeResultSet (rset);
    conn->terminateStatement (stmt);
    cout<<endl;
  }
 
  void testproc ()
  {
    cout << "--- Testing Procedure Binds ---" << endl;
    vector<double> myInBind = {10.1,20.2,30.3,40.4};
    vector<double> myInOutBind = {50.5,60.6,70.7,80.8};
    vector<double> myOutBind;
    try{
      cout << "callproc - invoking a PL/SQL procedure having IN, OUT and IN/OUT ";
      stmt = conn->createStatement("BEGIN occivec_demo(:1,:2,:3); END;");
      stmt->setDoubleVector(1,myInBind);
      stmt->setDoubleVector (2,myInOutBind);
      stmt->registerOutParam (3, OCCI_SQLT_VEC);
      stmt->executeUpdate ();
      stmt->getDoubleVector(2,myInOutBind);
      stmt->getDoubleVector(3,myOutBind);
      cout << "Printing the INOUT & OUT parameters:" << endl;
      cout<< "IN/OUT vector:"<<endl;
      for(auto i:myInOutBind)cout<<i<<" ";cout<<endl;
      cout<< "OUT vector:"<<endl;
      for(auto i:myOutBind)cout<<i<<" ";cout<<endl;
      conn->terminateStatement (stmt);
      cout << endl;
    }catch(SQLException ex)
    {
      cout<<"Exception thrown for testproc"<<endl;
      cout<<"Error number: "<<  ex.getErrorCode() << endl;
      cout<<ex.getMessage() << endl;
    }
  }
 
  void insertElement ()
  {
    cout << "--- Inserting in a vector table ---" << endl;
    int num = 1;
    vector<double> myData = {10,20.30,30,40.50};
    vector<double> myResult;
    try{
        stmt = conn->createStatement ("INSERT INTO test_vecint values(:1,:2)");
        stmt->setInt(1,num);
        stmt->setDoubleVector(2,myData);
        stmt->executeUpdate();
        conn->terminateStatement (stmt);
        cout << endl;
    }catch(SQLException ex)
    {
        cout<<"Exception thrown for insertElement"<<endl;
        cout<<"Error number: "<<  ex.getErrorCode() << endl;
        cout<<ex.getMessage() << endl;
    }
  }
 
  void describe_table ()
  {
    cout << "--- Describing the table - TEST_VECDBL ---" << endl;
    vector<MetaData> v1;
    MetaData metaData = conn->getMetaData("TEST_VECDBL");
    v1 =  metaData.getVector(MetaData::ATTR_LIST_COLUMNS);
    for(int i=0;i<v1.size();i++)
    {
        MetaData md = v1[i];
        cout << " Column Name :" << (md.getString(MetaData::ATTR_NAME)) << endl;
        cout << " Data Type :" << (printType (md.getInt(MetaData::ATTR_DATA_TYPE))) << endl;
        cout << " Dimension :"<< md.getUInt(MetaData::ATTR_VECTOR_DIMENSION) << endl;
        cout << endl;
    }
    cout << endl;
  }
 
  string printType (int type)
  {
    switch (type)
    {
      case OCCI_SQLT_NUM : return "NUMBER";
                           break;
      case OCCI_SQLT_VEC:  return "VECTOR";
                           break;
      default: return to_string(type);
    }
  } // End of printType (int)
 
};
 
int main (void)
{
  try{
    cout << "Demo Program for OCCI Vector" << endl;
    occivec *demo = new occivec ();
    demo->insertElement();
    demo->describe_table();
    demo->testproc();
    demo->displayAllRows("TEST_VECDBL");
    delete (demo);
  }
  catch (SQLException ex){
    cout << ex.getMessage() << endl;
  }
  cout << "done" << endl;
}

14.2 Sparse Vectors

This section describes the functions to work with the SparseVectors. Sparse vectors are preferred as they reduce the cost of memory.

Currently C++ has no implicit sparse-vector support, so SparseVector class is introduced as a data structure.

Note:

Sparse vectors follow a 0-based indexing conforming with the current vector implementations.

14.2.1 SparseVector Constructors

This section describes the SparseVector constructors.

14.2.1.1 SparseVector()

SparseVector function initializes a SparseVector of required type that fixes the type of values it uses.

This is the default constructor:
SparseVector<T> mySparseVector();
This function can be used in your library to construct a sparse vector as follows:
SparseVector<float> mySparseVector;
14.2.1.2 SparseVector(uint32_t size,vector<uint32_t> indices,vector<T> values)

This function initializes a SparseVector of required size and non_zeroes values with respective indices.

Syntax

Copying these vectors to the vector members of our SparseVector class.

Note:

The size must strictly be greater than or equal to the length of the indices and values vector. Also, ensure that the length of indices and the values are same.
SparseVector<T> mySparseVector(uint32_t size, vector<uint32_t> indices, vector<A>
    values);
Parameter Description
size Specifies the total size of the sparse vector.
indices Specifies the indices of non-zero values of the sparse vector.
values Specifies the values of the non-zero indices in the sparse vector.

This function can be used in your library to construct a sparse vector as follows:

SparseVector<float> mySparseVector(45,{1,5,40},{1.3,2.5,4554}};
14.2.1.3 SparseVec(uint32_t size,pair<vector<uint32_t>,vector<T>> &vecp) Ref constructor

This function is more efficient or a faster constructor.

Syntax

You do not need to copy the vectors in your own class vector members. Instead, in this constructor, we can utilize references to the vectors inside the pair given as your argument. This means that all the changes made to the user vectors are reflected in your SparseVector and vice-versa.

SparseVector<T> myCopySparseVector(uint32_t size, pair<vector<uint32_t>,vector<T>>
    &vecp);
Parameter Description
size Specifies the total size of the sparse vector.
vecp Specifies the pair of vectors containing the index and the value of the vectors respectively.
   

The following code snippet shows how this function is used to construct a sparse vector from an existing sparse vector:

pair<vector<uint32_t>,vector<float>> vecp({1,3,5},{2,4,6});
SparseVector<float> mySparseVector(100,vecp); // now we initialize this does no copies of the vectors inside our pair
 
string sqlStmt = "SELECT * FROM DEMO_TAB"; //Table has one row with two columns (id:2,SparseVector:10,{0,2,4},{3,5,7})
stmt = conn->createStatement (sqlStmt);
rset = stmt->executeQuery ();
while(rset->next())
{
    cout << "ID: " << rset->getInt (1) << endl;
    rset->getSparseVector(2, mySparseVector);
    //each time we do getSparseVector our vecp directly gets modified to the sparse-vector we recieved.
    //We can check this by printing each vectors of vecp.
    for(auto i:vecp.first)
        cout<<i<<" ";
    cout<<endl;
    // this will print 0,2,4 as our indices in SparseVector of our table
    for(auto i:vecp.second)
        cout<<i<<" ";
    cout<<endl;
    // this will print 3,5,7 as our indices in SparseVector of our table
}

Note:

The pair we used for initialization that is, vecp should not go out of scope when you are using your mySparseVector for the database operations. Otherwise, your SparseVector is also invalidated.

14.2.2 Binding Sparse Vectors in a Statement Handle

The functions described in this section are introduced for binding SparseVector data to a statement handle.

Note:

Functionality of sparse vector and dense vector bind/define functions:

We can insert using SparseVector/std::vector regardless of the table having dense/sparse vector columns. However, we can only fetch SparseVector from sparse vector columns and dense vectors (std::vector) from dense vector columns.

14.2.2.1 setInt8Vector()

Binds the value to a Sparse Vector in INT8 format from an OCCI SparseVector of type int8_t.

Syntax

void setInt8Vector(unsigned int paramIndex, SparseVector<int8_t> &vec);
Parameter Description
paramIndex Specifies the parameter index; first parameter is 1, second is 2, and so on.
vec Specifies the SparseVector to be set.
14.2.2.2 setFloatVector()

Binds the value to a Sparse Vector IEEE FLOAT32 format from an OCCI SparseVector of type float.

Syntax

void setFloatVector(unsigned int paramIndex, SparseVector<float> &vec);
Parameter Description
paramIndex Specifies the parameter index; first parameter is 1, second is 2, and so on.
vec Specifies the SparseVector to be set.
14.2.2.3 setDoubleVector()

Binds the value to a Sparse Vector in IEEE FLOAT64 format from an OCCI SparseVector of type double.

Syntax

void setDoubleVector(unsigned int paramIndex, SparseVector<double> &vec);
Parameter Description
paramIndex Specifies the parameter index; first parameter is 1, second is 2, and so on.
vec Specifies the SparseVector to be set.
14.2.2.4 setBinaryVector()

Sets the value of an Oracle Database Vector data type in binary format from a C++ vector of type uint8_t

Syntax

Note:

You can only insert vectors with dimension that are a mutliple of 8.
void setBinaryVector(unsigned int paramIndex, SparseVector<uint8_t> &vec);
Parameter Description
paramIndex Specifies the parameter index; first parameter is 1, second is 2, and so on.
vec Specifies the SparseVector to be set.

The following code snippet binds the SparseVector mySparseVector of FLOAT32 format to position 1 in stmt. Further executing the statement, inserts it in the database table:

Statement *stmt;
stmt = conn->createStatement ("INSERT INTO test_sparsevecflt values(:1,:2)");
vector<uint32_t> inds = {0, 5, 9};
vector<float> vals = {1.5, 2.3, 4.6};
SparseVector<float> mySparseVector(10, inds, vals);
stmt->setInt(1,10);
stmt->setFloatVector(2, mySparseVector);
stmt->executeUpdate();

14.2.3 PL/SQL out-binds for Sparse Vectors

The functions described in this section, can be used to get output from PLSQL procedures or functions through out-binds in the statement handle.

14.2.3.1 getInt8Vector()

Gets the value of an Oracle Database sparse vector data type in int8(ub1) format as an OCCI SparseVector of type int8_t.

Syntax

void getInt8Vector(unsigned int paramIndex, SparseVector<int8_t> &vec);
Parameter Description
paramIndex Specifies the parameter index; first parameter is 1, second is 2, and so on.
vec References to the SparseVector (OUT parameter) into which the values must be inserted.
14.2.3.2 getFloatVector()

Gets the value of an Oracle Database sparse vector data type in IEEE FLOAT32 format as an OCCI SparseVector of type float.

Syntax

void getFloatVector(unsigned int paramIndex, SparseVector<float> &vec);
Parameter Description
paramIndex Specifies the parameter index; first parameter is 1, second is 2, and so on.
vec References to the SparseVector (OUT parameter) into which the values must be inserted.
14.2.3.3 getDoubleVector()

Gets the value of an Oracle Database sparse vector data type in IEEE FLOAT64 format as an OCCI SparseVector of type doubles.

Syntax

void getDoubleVector(unsigned int paramIndex, SparseVector<double> &vec);
Parameter Description
paramIndex Specifies the parameter index; first parameter is 1, second is 2, and so on.
vec References the SparseVector (OUT parameter) into which the values must be inserted.

The following sample code snippet uses this function for out binds to obtain a vector:

Statement *stmt;
stmt = conn->createStatement ("BEGIN occivec_demo(:1,:2,:3) END;");
pair<vector<uint32_t>, vector<double>> myInPair = {{3, 7, 8}, {2.6, 7.6, 1001.1}};
pair<vector<uint32_t>, vector<double>> myInOutPair = {{0, 4, 9}, {3, 5.7, 2001}};
pair<vector<uint32_t>, vector<double>> myOutPair;
SparseVector<uint32_t> myInBind(9, myInPair);
SparseVector<uint32_t> myInOutBind(10, myInOutPair);
SparseVector<uint32_t> myOutBind(0, myOutPair);
stmt->setDoubleVector(1, myInBind);
stmt->setDoubleVector(2, myInOutBind);
stmt->registerOutParam(3, OCCI_SQLT_VEC);
stmt->stmtExecute();
stmt->getDoubleVector(2, myInOutBind);
stmt->getDoubleVector(3, myOutBind);

The preceding code snippet gets the data obtained from INOUT bind at position 2 into myInOutBind SparseVector as well as the OUT bind at position 3 in myOutBind.

14.2.4 Defining Sparse Vectors from a ResultSet of a Query

This section describes the functions introduced in ResultSet class to obtain the column values of type SparseVector into C++ stl vector containers.

14.2.4.1 getInt8Vector()

Gets the column value of an Oracle Database sparse vector datatype in int8(ub1) as an OCCI SparseVector of type int8_t.

Syntax

void getInt8Vector(unsigned int paramIndex, SparseVector<int8_t> &vec);
Parameter Description
colIndex Specifies the column index, first column is 1, second is 2, and so on.
vec References to the SparseVector (OUT parameter) into which the values must be inserted.
14.2.4.2 getFloatVector()

Gets the column value of an Oracle Database sparse vector data type in IEEE FLOAT32 format as an OCCI SparseVector of type float.

Syntax

void getFloatVector(unsigned int paramIndex, SparseVector<float> &vec);
Parameter Description
colIndex Specifies the column index, first column is 1, second is 2, and so on.
vec References to the SparseVector (OUT parameter) into which the values must be inserted.
14.2.4.3 getDoubleVector()

Gets the column value of an Oracle Database vector data type in IEEE FLOAT64 format as an OCCI SparseVector of type double.

Syntax

void getDoubleVector(unsigned int paramIndex, SparseVector<double> &vec);
Parameter Description
colIndex Specifies the column index, first column is 1, second is 2, and so on.
vec References to the SparseVector (OUT parameter) into which the values must be inserted.

The following code snippet shows how this function can be used in the ResultSet to obtain a Sparse Vector:

Statement stmt;
stmt = conn->createStatement ("SELECT * FROM TEST_SPARSEVECFLT");
ResultSet *rs = stmt->getResultSet();
pair<vector<uint32_t>,vector<float>> myResult;
SparseVector mySparseVector(0, myResult);
stmt->stmtExecute();
rs->getFloatVector(2, myResult);

The type of SparseVector data in result is decided depending on the vector type provided. That is, SparseVector<float> corresponds to FLOAT32 format.

14.2.4.4 getString()

Gets the column value of an Oracle Database sparse vector data type of any format as a C++ string.

Syntax

string getString(unsigned int paramIndex);
Parameter Description
colIndex Specifies the column index, first column is 1, second is 2, and so on.

The following code snippet shows how to use this function in ResultSet to obtain a vector:

Statement stmt;
stmt = conn->createStatement ("SELECT id,embedding FROM TEST_SPARSEVECFLT");
ResultSet *rs = stmt->getResultSet();
stmt->stmtExecute();
int id = rs->getInt(1);
string vec = rs->getString(2);

14.3 Utility Function for SparseVector

This section describes a member function of the SparseVector class and returns a dense form of the vector stored by your SparseVector.

14.3.1 toDenseVec()

Returns the dense vector form of an OCCI SparseVector of type <T>.

Syntax

vector<T> toDense();

Note:

Here T is the desired type of vector value.

The following code snippet shows how you can use this function in SparseVector to obtain a dense vector:

SparseVector<float> mySparseVector(10,{0,5,9},{0.5,5.5,9.5});
vector<float> myDenseVector = mySparseVector.toDense();
for(auto i:myDenseVector)
    cout<<i<<" ";
cout<<endl;