在 Amazon Keyspaces 中使用客户端时间戳创建表 - Amazon Keyspaces(Apache Cassandra 兼容)
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

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

在 Amazon Keyspaces 中使用客户端时间戳创建表

按照以下示例,使用 Amazon Keyspaces Amazon Web Services Management Console、Cassandra 查询语言(CQL)或 Amazon Command Line Interface 创建启用客户端时间戳的新 Amazon Keyspaces 表

Console
使用客户端时间戳创建新表(控制台)
  1. 登录 Amazon Web Services Management Console,然后打开 Amazon Keyspaces 控制台:https://console.aws.amazon.com/keyspaces/home

  2. 在导航窗格中,选择,然后选择创建表

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

  4. 架构部分,为您的表创建架构。

  5. 表设置部分,选择自定义设置

  6. 继续查看客户端时间戳

    选择打开客户端时间戳,为表打开客户端时间戳。

  7. 选择创建表。您的表是在打开客户端时间戳的情况下创建的。

Cassandra Query Language (CQL)
使用 CQL 创建新表
  1. 要使用 CQL 创建启用客户端时间戳的新表,可以使用以下示例。

    CREATE TABLE my_keyspace.my_table ( userid uuid, time timeuuid, subject text, body text, user inet, PRIMARY KEY (userid, time) ) WITH CUSTOM_PROPERTIES = {'client_side_timestamps': {'status': 'enabled'}};
  2. 要确认新表的客户端时间戳设置,请使用 SELECT 语句查看 custom_properties,如以下示例所示。

    SELECT custom_properties from system_schema_mcs.tables where keyspace_name = 'my_keyspace' and table_name = 'my_table';

    此语句的输出显示了客户端时间戳的状态。

    'client_side_timestamps': {'status': 'enabled'}
Amazon CLI
使用 Amazon CLI 创建新表
  1. 要创建启用客户端时间戳的新表,可以使用以下示例。

    ./aws keyspaces create-table \ --keyspace-name my_keyspace \ --table-name my_table \ --client-side-timestamps 'status=ENABLED' \ --schema-definition 'allColumns=[{name=id,type=int},{name=date,type=timestamp},{name=name,type=text}],partitionKeys=[{name=id}]'
  2. 要确认新表的客户端时间戳已打开,请运行以下代码。

    ./aws keyspaces get-table \ --keyspace-name my_keyspace \ --table-name my_table

    输出应类似于以下示例:

    { "keyspaceName": "my_keyspace", "tableName": "my_table", "resourceArn": "arn:aws:cassandra:us-east-2:555555555555:/keyspace/my_keyspace/table/my_table", "creationTimestamp": 1662681206.032, "status": "ACTIVE", "schemaDefinition": { "allColumns": [ { "name": "id", "type": "int" }, { "name": "date", "type": "timestamp" }, { "name": "name", "type": "text" } ], "partitionKeys": [ { "name": "id" } ], "clusteringKeys": [], "staticColumns": [] }, "capacitySpecification": { "throughputMode": "PAY_PER_REQUEST", "lastUpdateToPayPerRequestTimestamp": 1662681206.032 }, "encryptionSpecification": { "type": "AWS_OWNED_KMS_KEY" }, "pointInTimeRecovery": { "status": "DISABLED" }, "clientSideTimestamps": { "status": "ENABLED" }, "ttl": { "status": "ENABLED" }, "defaultTimeToLive": 0, "comment": { "message": "" } }