Query table information, including its schema, configuration, Stream settings, server-side encryption (SSE), reserved throughput, and secondary indexes, using Tablestore SDK for Go.
Prerequisites
Before you begin, ensure that you have:
A client initialized. For more information, see Initialize a Tablestore client
API reference
func (tableStoreClient *TableStoreClient) DescribeTable(request *DescribeTableRequest) (*DescribeTableResponse, error)
Sample code
The following example queries information of the test_table table.
func DescribeTableSample(client *tablestore.TableStoreClient) {
describeTableReq := new(tablestore.DescribeTableRequest)
describeTableReq.TableName = "test_table"
response, err := client.DescribeTable(describeTableReq)
if err != nil {
fmt.Println("Failed to describe table with error:", err)
} else {
// Get the schema of the table.
tableMeta := response.TableMeta
fmt.Printf("* Table name: %s \n", tableMeta.TableName)
fmt.Println("* Primary key information (primary key type 1:INTEGER,2:STRING,3:BINARY)")
for _, schemaEntry := range tableMeta.SchemaEntry {
fmt.Printf("%s:%v \n", *schemaEntry.Name, *schemaEntry.Type)
}
fmt.Println("* Predefined column information (predefined column type 1:INTEGER,2:DOUBLE,3:BOOLEAN,4:STRING,5:BINARY)")
for _, definedColumn := range tableMeta.DefinedColumns {
fmt.Printf("%s:%v \n", definedColumn.Name, definedColumn.ColumnType)
}
// Get the configuration of the table.
tableOption := response.TableOption
fmt.Println("* Table configuration")
fmt.Printf("Max versions: %d \n", tableOption.MaxVersion)
fmt.Printf("Time to live (TTL): %d \n", tableOption.TimeToAlive)
fmt.Printf("Max version offset: %d \n", tableOption.DeviationCellVersionInSec)
fmt.Printf("Allow updates: %t \n", *tableOption.AllowUpdate)
// Get the Stream settings of the table.
streamDetails := response.StreamDetails
fmt.Printf("* Stream enabled: %t \n", streamDetails.EnableStream)
if streamDetails.EnableStream {
fmt.Printf("Stream expiration time: %d \n", streamDetails.ExpirationTime)
}
// Get the server-side encryption (SSE) settings of the table.
sseDetails := response.SSEDetails
fmt.Printf("* SSE enabled: %t \n", sseDetails.Enable)
if sseDetails.Enable {
fmt.Printf("Encryption key type: %s \n", sseDetails.KeyType.String())
}
// Get the reserved throughput of the table.
reservedThroughput := response.ReservedThroughput
fmt.Println("* Reserved throughput")
fmt.Printf("Reserved read throughput: %d \n", reservedThroughput.Readcap)
fmt.Printf("Reserved write throughput: %d \n", reservedThroughput.Writecap)
// Get the secondary index information.
indexMetas := response.IndexMetas
for _, indexMeta := range indexMetas {
fmt.Printf("* Secondary index name: %s \n", indexMeta.IndexName)
fmt.Printf("Primary key columns: %v \n", indexMeta.Primarykey)
fmt.Printf("Predefined columns: %v \n", indexMeta.DefinedColumns)
fmt.Printf("Secondary index type: %d (0:IT_GLOBAL_INDEX,1:IT_LOCAL_INDEX) \n", indexMeta.IndexType)
}
}
}