

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

# 從 ServiceNow 實體中讀取
<a name="servicenow-reading-from-entities"></a>

**必要條件**

您想要從中讀取的 ServiceNow Tables 物件。您將需要物件名稱，例如 pa\$1bucket 或 incident。

**範例**：

```
servicenow_read = glueContext.create_dynamic_frame.from_options(
    connection_type="servicenow",
    connection_options={
        "connectionName": "connectionName",
        "ENTITY_NAME": "pa_buckets",
        "API_VERSION": "v2"
        "instanceUrl": "https://<instance-name>.service-now.com"
    }
)
```

**ServiceNow 實體和欄位詳細資訊**：

對於下列實體，ServiceNow 會提供端點來動態擷取中繼資料，以便在每個實體的資料類型層級擷取運算子支援。

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/glue/latest/dg/servicenow-reading-from-entities.html)

**注意**  
在連接器的回應中，Struct 資料類型會轉換為 String 資料類型。

**注意**  
`DML_STATUS` 是用於追蹤 CREATED/UPDATED 記錄的額外使用者定義的屬性。

## 分區查詢
<a name="servicenow-reading-partitioning-queries"></a>

**欄位型分區**：

如果想要在 Spark 中使用並行，可以提供其他 Spark 選項 `PARTITION_FIELD`、`LOWER_BOUND`、`UPPER_BOUND` 和 `NUM_PARTITIONS`。使用這些參數，原始查詢會分區為可由 Spark 任務並行執行的子查詢的 `NUM_PARTITIONS` 數目。

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/glue/latest/dg/servicenow-reading-from-entities.html)
+ `PARTITION_FIELD`：用來分區查詢的欄位名稱。
+ `LOWER_BOUND`：所選分區欄位的**包含**下限值。

  對於 Datetime 欄位，我們接受 Spark SQL 查詢中使用的 Spark 時間戳記格式。

  有效值的範例：

  ```
  "2024-01-30T06:47:51.000Z"
  ```
+ `UPPER_BOUND`：所選分區欄位的**唯一**上限值。
+ `NUM_PARTITIONS`：分區數目。

下表說明實體分區欄位支援詳細資訊：

範例：

```
servicenow_read = glueContext.create_dynamic_frame.from_options(
    connection_type="servicenow",
    connection_options={
        "connectionName": "connectionName",
        "ENTITY_NAME": "pa_buckets",
        "API_VERSION": "v2",
        "instanceUrl": "https://<instance-name>.service-now.com"
        "PARTITION_FIELD": "sys_created_on"
        "LOWER_BOUND": "2024-01-30T06:47:51.000Z"
        "UPPER_BOUND": "2024-06-30T06:47:51.000Z"
        "NUM_PARTITIONS": "10"
    }
```

**記錄型分區**：

如果想要在 Spark 中使用並行，可以提供其他 Spark 選項 `NUM_PARTITIONS`。使用此參數，原始查詢會分區為可由 Spark 任務並行執行的子查詢的 `NUM_PARTITIONS` 數目。

在記錄型分區中，會從 ServiceNow API 中查詢存在的記錄總數，並除以提供的 `NUM_PARTITIONS` 數目。然後，每個子查詢都會同時擷取產生的記錄數目。
+ `NUM_PARTITIONS`：分區數目。

範例：

```
servicenow_read = glueContext.create_dynamic_frame.from_options(
    connection_type="servicenow",
    connection_options={
        "connectionName": "connectionName",
        "ENTITY_NAME": "pa_buckets",
        "API_VERSION": "v2",
        "instanceUrl": "https://<instance-name>.service-now.com"
        "NUM_PARTITIONS": "2"
    }
```