

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 建立資料篩選條件
<a name="creating-data-filters"></a>

您可以為每個 Data Catalog 資料表建立一或多個資料篩選條件。

**建立 Data Catalog 資料表的資料篩選條件 （主控台）**

1. 開啟 Lake Formation 主控台，網址為 [https://console.aws.amazon.com/lakeformation/](https://console.aws.amazon.com/lakeformation/)。

   以資料湖管理員、目標資料表擁有者或擁有目標資料表 Lake Formation 許可的主體身分簽署。

1. 在導覽窗格中的資料**目錄**下，選擇**資料篩選條件**。

1. 在**資料篩選條件**頁面上，選擇**建立新篩選條件**。

1. 在**建立資料篩選條件**對話方塊中，輸入下列資訊：
   + 資料篩選條件名稱 
   + 目標資料庫 – 指定包含資料表的資料庫。
   + 目標資料表 
   + 資料欄層級存取 – 將此設定為**存取所有資料欄**，以僅指定資料列篩選。選擇**包含資料**欄或**排除資料欄**以指定資料欄或儲存格篩選，然後指定要包含或排除的資料欄。

     巢狀資料欄 – 如果您要在包含巢狀資料欄的資料表上套用篩選條件，您可以明確指定資料篩選條件中巢狀結構資料欄的子結構。

     當您將 SELECT 許可授予此檔案伺服器上的委託人時，執行下列查詢的委託人只會看到 的資料，`customer.customerName`而不會看到 的資料`customer.customerId`。

     ```
     SELECT "customer" FROM "example_db"."example_table";
     ```  
![\[Column-level access settings with options to include specific columns and filter rows.\]](http://docs.aws.amazon.com/zh_tw/lake-formation/latest/dg/images/nested-column-filter.png)

      當您授予資料`customer`欄的許可時，委託人會收到資料欄的存取權，以及資料欄 (`customerName` 和 ) 下的巢狀欄位`customerID`。
   + 資料列篩選條件表達式 – 輸入篩選條件表達式以指定資料列或儲存格篩選。如需支援的資料類型和運算子，請參閱 [資料列篩選條件表達式中的 PartiQL 支援](partiql-support.md)。選擇**存取所有資料列**，以授予存取所有 的權限。

     您可以在資料列篩選條件表達式中包含巢狀資料欄的部分資料欄結構，以篩選包含特定值的資料列。

     當委託人被授予具有資料列篩選條件表達式 的資料表許可`Select * from example_nestedtable where customer.customerName <>'John'`，且**資料欄層級**存取設定為**存取所有資料欄**時，查詢結果只會顯示 `customerName <>'John'`評估為 true 的資料列。

   下列螢幕擷取畫面顯示實作儲存格篩選的資料篩選條件。在對`orders`資料表的查詢中，它會拒絕存取資料`customer_name`欄，並只顯示資料`product_type`欄中具有「製藥」的資料列。  
![\[資料篩選條件視窗包含這些垂直排列的欄位：資料篩選條件名稱；目標資料庫；目標資料表；具有選項的選項按鈕群組 存取所有欄、包含欄和排除欄；選取欄 （下拉式清單）；資料列篩選條件表達式 （多行文字方塊）。選取排除資料欄選項，選取 customer_name 資料欄進行排除，且資料列篩選條件表達式欄位包含 'product_type='pharma'。\]](http://docs.aws.amazon.com/zh_tw/lake-formation/latest/dg/images/data-filter-sample-pharma.png)

1. 選擇 **Create filter (建立篩選條件)**。

**在巢狀欄位上使用儲存格篩選條件政策建立資料篩選條件**

 本節使用以下範例結構描述，示範如何建立資料儲存格篩選條件：

```
[
    { name: "customer", type: "struct<customerId:string,customerName:string>" },
    { name: "customerApplication", type: "struct<appId:string>" },
    { name: "product", type: "struct<offer:struct<prodId:string,listingId:string>,type:string>" },
    { name: "purchaseId", type: "string" },
]
```

1. 在**建立資料篩選條件**上，頁面輸入資料篩選條件的名稱。

1.  接著，使用下拉式清單選擇資料庫名稱和資料表名稱。

1. 在**資料欄層級存取**區段中，選擇包含的資料欄，然後選取巢狀資料欄 (`customer.customerName`)。

1. 在**資料列層級存取**區段中，選擇**存取所有資料列**選項。

1. 選擇 **Create filter (建立篩選條件)**。

   當您授予此篩選條件的`SELECT`許可時，委託人可以存取 `customerName`資料欄中的所有資料列。

1. 接著，為相同的資料庫/資料表定義另一個資料篩選條件。

1. 在**資料欄層級存取**區段中，選擇包含的資料欄，然後選取另一個巢狀資料欄 (`customer.customerid`)。

1. 在**資料列層級存取**區段中，選擇**篩選資料列**，然後輸入**資料列篩選表達**式 (`customer.customerid <> 5`)。

1. 選擇 **Create filter (建立篩選條件)**。

   當您授予此篩選條件的`SELECT`許可時，委託人會收到 中所有資料列的存取權`customerName`，以及資料`customerId`欄中值為 5 的儲存格以外的`customerId`欄位。