

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 创建具有更高热吞吐量的新 Amazon Keyspaces 表
<a name="create-table-warm-throughput"></a>

在创建 Amazon Keyspaces 表时，您可以使用控制台、CQL 或调整热吞吐量值。 Amazon CLI

------
#### [ Console ]

**如何使用热吞吐量设置创建新表**

1. [登录并在家中打开 Amazon Keyspaces 控制台。 Amazon Web Services 管理控制台 https://console.aws.amazon.com/keyspaces/](https://console.amazonaws.cn/keyspaces/home)

1. 在导航窗格中，选择**表**，然后选择**创建表**。

1. 在**创建表**页面的**表详细信息**部分中，选择一个键空间并为新表提供一个名称。

1. 在**列**部分，为您的表创建架构。

1. 在**主键**部分中，定义表的主键并选择可选的集群列。

1. 在**表设置**部分，选择**自定义设置**。

1. 继续**读取/写入容量设置**。

1. 对于**容量模式**，您可以选择**按需**或**预配置。**

1. 在**表格的预热**部分中，您可以根据需要增加每秒**读取单位数和每秒****写入单位数**的值，以准备表处理计划的峰值事件。

   默认情况下，Amazon Keyspaces 根据您的按需使用量或预配置容量调整的温吞吐量值适用于所有表，无需支付额外费用。请注意，如果您手动增加默认的热吞吐量值以预热流量高峰事件，则需要支付额外费用。

1. 根据需要配置其他可选表格功能。然后选择 “**创建表**”。

------
#### [ Cassandra Query Language (CQL) ]
+ 使用以下方法之一创建具有温吞吐量的表：
  + 对于预配置模式，使用以下 CQL 语法创建表并指定读取和写入的预期峰值容量：

    ```
    CREATE TABLE catalog.book_awards (
       year int,
       award text,
       rank int,
       category text,
       book_title text,
       author text,
       publisher text,
       PRIMARY KEY ((year, award), category, rank))
    WITH CUSTOM_PROPERTIES = {  
        'capacity_mode': {
           'throughput_mode': 'PROVISIONED',
           'read_capacity_units': 20000,
           'write_capacity_units': 10000
         },
        'warm_throughput': {  
            'read_units_per_second': 40000,  
            'write_units_per_second': 20000  
         }
    };
    ```
  + 对于按需模式，使用以下 CQL 语法创建表并指定读取和写入的预期峰值容量：

    ```
    CREATE TABLE catalog.book_awards (
       year int,
       award text,
       rank int,
       category text,
       book_title text,
       author text,
       publisher text,
       PRIMARY KEY ((year, award), category, rank))
    WITH CUSTOM_PROPERTIES = {  
        'capacity_mode': {
           'throughput_mode': 'PAY_PER_REQUEST'
         },
        'warm_throughput': {  
            'read_units_per_second': 40000,  
            'write_units_per_second': 20000  
         }
    };
    ```

  要确认表的容量设置，请参阅[查看 Amazon Keyspaces 表的热吞吐量](view-warm-throughput.md)。

------
#### [ CLI ]

1. 使用以下方法之一创建具有温吞吐量的表 Amazon CLI
   + 在预置模式下创建新表，并指定新表的预期读取和写入容量峰值。下面是一个示例语句。

     ```
     aws keyspaces create-table \
     --keyspace-name 'catalog' \
     --table-name 'book_awards' \
     --schema-definition 'allColumns=[{name=year,type=int},{name=award,type=text},{name=rank,type=int},{name=category,type=text},{name=book_title,type=text},{name=author,type=text},{name=publisher,type=text}],partitionKeys=[{name=year},{name=award}],clusteringKeys=[{name=category,orderBy=ASC},{name=rank,orderBy=ASC}]' \
     --capacity-specification throughputMode=PROVISIONED,readCapacityUnits=20000,writeCapacityUnits=10000 \
     --warm-throughput-specification readUnitsPerSecond=40000,writeUnitsPerSecond=20000
     ```
   + 在按需模式下创建新表，并为新表指定读取和写入的预期峰值容量值。下面是一个示例语句。

     ```
     aws keyspaces create-table \
     --keyspace-name 'catalog' \
     --table-name 'book_awards' \
     --schema-definition 'allColumns=[{name=year,type=int},{name=award,type=text},{name=rank,type=int},{name=category,type=text},{name=book_title,type=text},{name=author,type=text},{name=publisher,type=text}],partitionKeys=[{name=year},{name=award}],clusteringKeys=[{name=category,orderBy=ASC},{name=rank,orderBy=ASC}]' \
     --warmThroughputSpecification readUnitsPerSecond=40000,writeUnitsPerSecond=20000
     ```

1. 命令的输出返回表的 ARN，如下例所示。

   ```
   {
       "resourceArn": "arn:aws::cassandra:us-east-1:111122223333:/keyspace/catalog/table/book_awards>"
   }
   ```

   要确认表的容量设置，请参阅[查看 Amazon Keyspaces 表的热吞吐量](view-warm-throughput.md)。

------
#### [ Java ]

**使用适用于 Java 的 SDK 创建新表。**
+ 在预置模式下创建新表，并指定新表的预期读取和写入容量峰值。以下代码示例就是这方面的一个示例。

  ```
  import software.amazon.awssdk.services.keyspaces.KeyspacesClient;
  import software.amazon.awssdk.services.keyspaces.model.*;
  
  public class PreWarmingExample {
      public static void main(String[] args) {
          KeyspacesClient keyspacesClient = KeyspacesClient.builder().build();
  
          // Define schema
          List<ColumnDefinition> columns = Arrays.asList(
              ColumnDefinition.builder().name("year").type("int").build(),
              ColumnDefinition.builder().name("award").type("text").build(),
              ColumnDefinition.builder().name("rank").type("int").build(),
              ColumnDefinition.builder().name("category").type("text").build(),
              ColumnDefinition.builder().name("book_title").type("text").build(),
              ColumnDefinition.builder().name("author").type("text").build(),
              ColumnDefinition.builder().name("publisher").type("text").build()
          );
          
          List<PartitionKey> partitionKeys = Arrays.asList(
              PartitionKey.builder().name("year").build(),
              PartitionKey.builder().name("award").build()
          );
          
          List<ClusteringKey> clusteringKeys = Arrays.asList(
              ClusteringKey.builder().name("category").orderBy("ASC").build(),
              ClusteringKey.builder().name("rank").orderBy("ASC").build()
          );
          
          SchemaDefinition schema = SchemaDefinition.builder()
              .allColumns(columns)
              .partitionKeys(partitionKeys)
              .clusteringKeys(clusteringKeys)
              .build();
  
          // Define capacity specification
          CapacitySpecification capacitySpec = CapacitySpecification.builder()
              .throughputMode(ThroughputMode.PROVISIONED)
              .readCapacityUnits(20000)
              .writeCapacityUnits(10000)
              .build();
              
          // Define warm throughput specification
          WarmThroughputSpecification warmThroughput = WarmThroughputSpecification.builder()
              .readUnitsPerSecond(40000L)
              .writeUnitsPerSecond(20000L)
              .build();
  
          // Create table with PreWarming
          CreateTableRequest request = CreateTableRequest.builder()
              .keyspaceName("catalog")
              .tableName("book_awards")
              .schemaDefinition(schema)
              .capacitySpecification(capacitySpec)
              .warmThroughputSpecification(warmThroughput)
              .build();
              
          CreateTableResponse response = keyspacesClient.createTable(request);
          System.out.println("Table created with ARN: " + response.resourceArn());
      }
  }
  ```

------