All Products
Search
Document Center

Tablestore:Query information of a data table

Last Updated:May 15, 2025

This topic describes how to query information of a data table by using Tablestore SDK for Java.

Prerequisites

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

Method

public DescribeTableResponse describeTable(DescribeTableRequest request) throws TableStoreException, ClientException

DescribeTableRequest parameters

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

Sample code

The following sample code provides an example on how to query information of a data table named test_table:

public static void describeTableExample(SyncClient client) {
    DescribeTableRequest request = new DescribeTableRequest("test_table");
    DescribeTableResponse response = client.describeTable(request);

    // Query the schema information of the data table.
    TableMeta tableMeta = response.getTableMeta();
    System.out.println("* Data table name: " + tableMeta.getTableName());
    System.out.println("* Primary key information");
    for(PrimaryKeySchema primaryKeySchema : tableMeta.getPrimaryKeyList()) {
        System.out.println(primaryKeySchema);
    }
    System.out.println("* Predefined column information");
    for(DefinedColumnSchema definedColumnSchema : tableMeta.getDefinedColumnsList()) {
        System.out.println(definedColumnSchema);
    }

    // Query the configuration information of the data table.
    TableOptions tableOptions = response.getTableOptions();
    System.out.println("* Table configuration information");
    System.out.println("Max versions: " + tableOptions.getMaxVersions());
    System.out.println("Time to live: " + tableOptions.getTimeToLive());
    System.out.println("Max version offset: " + tableOptions.getMaxTimeDeviation());
    System.out.println("Whether to allow updates: " + tableOptions.getAllowUpdate());

    // Query the Stream information of the data table.
    StreamDetails streamDetails = response.getStreamDetails();
    System.out.println("* Whether to enable Stream: " + streamDetails.isEnableStream());
    if(streamDetails.isEnableStream())
        System.out.println("Stream validity period: " + streamDetails.getExpirationTime());

    // Query the encryption settings of the data table.
    SSEDetails sseDetails = response.getSseDetails();
    System.out.println("* Whether to enable encryption for the data table: " + sseDetails.isEnable());
    if(sseDetails.isEnable())
        System.out.println("Encryption method: " + sseDetails.getKeyType());
        
    // Query the reserved read/write throughput of the data table.
    ReservedThroughputDetails reservedThroughputDetails = response.getReservedThroughputDetails();
    System.out.println("* Reserved read/write throughput");
    System.out.println("Reserved read throughput: " + reservedThroughputDetails.getCapacityUnit().getReadCapacityUnit());
    System.out.println("Reserved write throughput: " + reservedThroughputDetails.getCapacityUnit().getWriteCapacityUnit());

    // Query information of the secondary index.
    for(IndexMeta indexMeta : response.getIndexMeta()) {
        System.out.println("* Secondary index name: " + indexMeta.getIndexName());
        System.out.println("Primary key columns: " + indexMeta.getPrimaryKeyList().toString());
        System.out.println("Predefined columns: " + indexMeta.getDefinedColumnsList().toString());
        System.out.println("Secondary index type: " + indexMeta.getIndexType());
        System.out.println("Secondary index update mode: " + indexMeta.getIndexUpdateMode());
    }
}

References

Query information of a time series table