このトピックでは、Go 用 Tablestore SDK を使用してテーブルの情報をクエリする方法について説明します。
前提条件
クライアントが初期化されていること。詳細については、「Tablestore クライアントを初期化する」をご参照ください。
メソッドの説明
func (tableStoreClient *TableStoreClient) DescribeTable(request *DescribeTableRequest) (*DescribeTableResponse, error)サンプルコード
次のサンプルコードは、test_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 {
// Obtain the schema information of the data 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)") // * プライマリキー情報 (プライマリキータイプ 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)") // * 定義済みカラム情報 (定義済みカラムタイプ 1:INTEGER,2:DOUBLE,3:BOOLEAN,4:STRING,5:BINARY)
for _, definedColumn := range tableMeta.DefinedColumns {
fmt.Printf("%s:%v \n", definedColumn.Name, definedColumn.ColumnType)
}
// Obtain the configuration information of the data table. // データテーブルの構成情報を取得します。
tableOption := response.TableOption
fmt.Println("* Table configuration information") // * テーブル構成情報
fmt.Printf("Max versions: %d \n", tableOption.MaxVersion) // 最大バージョン:
fmt.Printf("Time to live: %d \n", tableOption.TimeToAlive) // 有効期限:
fmt.Printf("Max version offset: %d \n", tableOption.DeviationCellVersionInSec) // 最大バージョンオフセット:
fmt.Printf("Allow updates: %t \n", *tableOption.AllowUpdate) // 更新を許可:
// Obtain the Stream information of the table. // テーブルの Stream 情報を取得します。
streamDetails := response.StreamDetails
fmt.Printf("* Whether to enable Stream: %t \n", streamDetails.EnableStream) // * Stream を有効にするかどうか:
if streamDetails.EnableStream {
fmt.Printf("Stream expiration time: %d \n", streamDetails.ExpirationTime) // Stream の有効期限:
}
// Obtain the encryption settings of the table. // テーブルの暗号化設定を取得します。
sseDetails := response.SSEDetails
fmt.Printf("* Whether to enable table encryption: %t \n", sseDetails.Enable) // * テーブルの暗号化を有効にするかどうか:
if sseDetails.Enable {
fmt.Printf("Encryption method: %s \n", sseDetails.KeyType.String()) // 暗号化方式:
}
// Obtain the reserved read/write throughput of the table. // テーブルの予約済み読み取り/書き込みスループットを取得します。
reservedThroughput := response.ReservedThroughput
fmt.Println("* Reserved read/write throughput") // * 予約済み読み取り/書き込みスループット
fmt.Printf("Reserved read throughput: %d \n", reservedThroughput.Readcap) // 予約済み読み取りスループット:
fmt.Printf("Reserved write throughput: %d \n", reservedThroughput.Writecap) // 予約済み書き込みスループット:
// Obtain 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) // セカンダリインデックスタイプ:
}
}
}