All Products
Search
Document Center

Tablestore:Operations on predefined columns

Last Updated:May 15, 2025

This topic describes how to add or remove predefined columns of a data table by using Tablestore SDK for Java.

Prerequisites

A client is initialized. For more information, see Initialize a Tablestore client.

Add predefined columns

Method

public AddDefinedColumnResponse addDefinedColumn(AddDefinedColumnRequest addDefinedColumnRequest) throws TableStoreException, ClientException

AddDefinedColumnRequest parameters

  • tableName (required) String: the name of the data table.

  • definedColumns (required) List<DefinedColumnSchema>: the information about the predefined columns. The following table describes the parameters that specify each predefined columm.

    Parameter

    Type

    Description

    name (required)

    String

    The name of the predefined column.

    type (required)

    DefinedColumnType

    The data type of the predefined column.

    • Data types include STRING, INTEGER, BINARY, DOUBLE, and BOOLEAN.

Sample code

The following sample code provides an example on how to add a predefined column of the String type named name to the test_table table:

public static void addDefinedColumnExample(SyncClient client) {
    AddDefinedColumnRequest addDefinedColumnRequest = new AddDefinedColumnRequest();
    addDefinedColumnRequest.setTableName("test_table");
    addDefinedColumnRequest.addDefinedColumn("name", DefinedColumnType.STRING);
    client.addDefinedColumn(addDefinedColumnRequest);
}

Remove predefined columns

Method

public DeleteDefinedColumnResponse deleteDefinedColumn(DeleteDefinedColumnRequest deleteDefinedColumnRequest) throws TableStoreException, ClientException

DeleteDefinedColumnRequest parameters

  • tableName (required) String: the name of the data table.

  • definedColumns (required) List<String>: the information about the predefined columns.

Sample code

The following sample code provides an example on how to remove a predefined column named name from the test_table table:

public static void deleteDefinedColumnExample(SyncClient client) {
    DeleteDefinedColumnRequest deleteDefinedColumnRequest = new DeleteDefinedColumnRequest();
    deleteDefinedColumnRequest.setTableName("test_table");
    deleteDefinedColumnRequest.addDefinedColumn("name");
    client.deleteDefinedColumn(deleteDefinedColumnRequest);
}