

# 查询还原的 Amazon Glacier 对象
<a name="querying-glacier"></a>

您可以使用 Amazon Athena 查询从 Amazon Glacier Flexible Retrieval（以前称为 Glacier）和 Amazon Glacier Deep Archive [Amazon S3 存储类别](https://docs.amazonaws.cn/AmazonS3/latest/userguide/storage-class-intro.html#sc-glacier)还原的对象。必须针对每个表启用此功能。如果您在运行查询之前未在表上启用该功能，Athena 将在查询执行期间跳过该表的所有 Amazon Glacier Flexible Retrieval 和 Amazon Glacier Deep Archive 对象。

## 注意事项和限制
<a name="querying-glacier-considerations-and-limitations"></a>
+  只有 Athena 引擎版本 3 支持查询还原的 Amazon Glacier 对象。
+  只有 Apache Hive 表支持该功能。
+  在查询数据之前，您必须还原对象；Athena 不会为您还原对象。

## 将表配置为使用还原的对象
<a name="querying-glacier-configuring-a-table-to-use-restored-objects"></a>

 要将 Athena 表配置为在查询中包含还原的对象，必须将其 `read_restored_glacier_objects` 表属性设置为 `true`。为此，您可以使用 Athena 查询编辑器或 Amazon Glue 控制台。您还可以使用 [Amazon Glue CLI](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/glue/update-table.html)、[Amazon Glue API](https://docs.amazonaws.cn/glue/latest/dg/aws-glue-api-catalog-tables.html#aws-glue-api-catalog-tables-UpdateTable) 或 [Amazon Glue SDK](https://docs.amazonaws.cn/glue/latest/dg/sdk-general-information-section.html)。

### 使用 Athena 查询编辑器
<a name="querying-glacier-using-the-athena-query-editor"></a>

 在 Athena 中，您可以使用 [ALTER TABLE SET TBLPROPERTIES](alter-table-set-tblproperties.md) 命令来设置表属性，如下例所示。

```
ALTER TABLE table_name SET TBLPROPERTIES ('read_restored_glacier_objects' = 'true')
```

### 使用 Amazon Glue 控制台
<a name="querying-glacier-using-the-aws-glue-console"></a>

 在 Amazon Glue 控制台中，执行以下步骤添加 `read_restored_glacier_objects` 表属性。

**在 Amazon Glue 控制台中配置表属性**

1. 登录 Amazon Web Services 管理控制台，然后打开 Amazon Glue 控制台，网址为：[https://console.aws.amazon.com/glue/](https://console.amazonaws.cn/glue/)。

1. 请执行以下操作之一：
   + 选择**转到数据目录**。
   + 在导航窗格中，选择**数据目录表**。

1. 在**表**页面的表列表中\+，选择要编辑的表的链接。

1. 依次选择 **Actions**（操作）、**Edit table**（编辑表）。

1. 在**编辑表**页面的**表属性**部分中，添加以下键值对：
   + 对于 **Key (键)**，添加 `read_restored_glacier_objects`。
   + 对于 **Value**（值），输入 `true`。

1. 选择**保存**。

### 使用 Amazon CLI
<a name="querying-glacier-using-the-aws-cli"></a>

 在 Amazon CLI 中，您可以使用 Amazon Glue [update-table](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/glue/update-table.html) 命令及其 `--table-input` 参数来重新定义表，并在此过程中添加 `read_restored_glacier_objects` 属性。在 `--table-input` 参数中，使用 `Parameters` 结构来指定 `read_restored_glacier_objects` 属性和 `true` 值。请注意：`--table-input` 的参数不能有空格，并且必须使用反斜杠来转义双引号。在以下示例中，将 {{my\_database}} 和 {{my\_table}} 替换为数据库和表的名称。

```
aws glue update-table \
   --database-name {{my_database}} \
   --table-input={\"Name\":\"{{my_table}}\",\"Parameters\":{\"read_restored_glacier_objects\":\"true\"}}
```

**重要**  
Amazon Glue `update-table` 命令在覆盖模式下运行，这意味着其将用 `table-input` 参数指定的新定义替换现有的表定义。因此，在添加 `read_restored_glacier_objects` 属性时，请务必在 `table-input` 参数中指定希望表中包含的所有字段。