Kudu C++ client API
Loading...
Searching...
No Matches
Public Member Functions | List of all members
kudu::client::KuduSchemaBuilder Class Reference

Builder API for constructing a KuduSchema object. More...

#include <schema.h>

Public Member Functions

KuduColumnSpecAddColumn (const std::string &name)
 
KuduSchemaBuilderSetPrimaryKey (const std::vector< std::string > &key_col_names)
 
KuduSchemaBuilderSetNonUniquePrimaryKey (const std::vector< std::string > &key_col_names)
 
Status Build (KuduSchema *schema)
 

Detailed Description

Builder API for constructing a KuduSchema object.

The API here is a "fluent" style of programming, such that the resulting code looks somewhat like a SQL "CREATE TABLE" statement. For example:

SQL:

CREATE TABLE t (
my_key int not null primary key,
a float default 1.5
);

is represented as:

t.AddColumn("my_key")->Type(KuduColumnSchema::INT32)->NotNull()->PrimaryKey();
t.AddColumn("a")->Type(KuduColumnSchema::FLOAT)->Default(KuduValue::FromFloat(1.5));
KuduSchema schema;
t.Build(&schema);
KuduColumnSpec * NotNull()
KuduColumnSpec * Type(KuduColumnSchema::DataType type)
KuduColumnSpec * Default(KuduValue *value)
KuduColumnSpec * PrimaryKey()
Builder API for constructing a KuduSchema object.
Definition schema.h:622
KuduColumnSpec * AddColumn(const std::string &name)
Status Build(KuduSchema *schema)
A representation of a table's schema.
Definition schema.h:688
static KuduValue * FromFloat(float val)

Member Function Documentation

◆ AddColumn()

KuduColumnSpec * kudu::client::KuduSchemaBuilder::AddColumn ( const std::string &  name)

Add a column with the specified name to the schema.

Parameters
[in]nameName of the column to add.
Returns
A KuduColumnSpec object for a new column within the Schema. The returned object is owned by the KuduSchemaBuilder.

◆ Build()

Status kudu::client::KuduSchemaBuilder::Build ( KuduSchema schema)

Build the schema based on current configuration of the builder object.

Parameters
[out]schemaThe placeholder for the result schema. Upon successful completion, the parameter is reset to the result of this builder: literally, calling KuduSchema::Reset() on the parameter.
Returns
Operation result status. If the resulting would-be-schema is invalid for any reason (e.g. missing types, duplicate column names, etc.) a bad Status is returned.

◆ SetNonUniquePrimaryKey()

KuduSchemaBuilder * kudu::client::KuduSchemaBuilder::SetNonUniquePrimaryKey ( const std::vector< std::string > &  key_col_names)

Set the non-unique primary key of the new Schema based on the given column names.

This may be used to specify a compound non-unique primary key.

Note
By specifying non-unique primary keys, an auto incrementing column is created automatically. They form together the effective primary key. The auto incrementing field is populated on the server side, it must not be specified during insertion. All subsequent operations like scans will contain the auto incrementing column by default. If one wants to omit the auto incrementing column, it can be accomplished through existing projection methods.
A call to SetPrimaryKey() or SetNonUniquePrimaryKey() overrides any previous call to these two methods.
Parameters
[in]key_col_namesNames of the columns to include into the compound non-unique primary key.
Returns
Pointer to the modified object.

◆ SetPrimaryKey()

KuduSchemaBuilder * kudu::client::KuduSchemaBuilder::SetPrimaryKey ( const std::vector< std::string > &  key_col_names)

Set the primary key of the new Schema based on the given column names.

This may be used to specify a compound primary key.

Note
A call to SetPrimaryKey() or SetNonUniquePrimaryKey() overrides any previous call to these two methods.
Parameters
[in]key_col_namesNames of the columns to include into the compound primary key.
Returns
Pointer to the modified object.

The documentation for this class was generated from the following file: