

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

# 搭配 Neptune DFE 查詢引擎使用 Gremlin
<a name="gremlin-with-dfe"></a>

如果您在[實驗室模式中](features-lab-mode.md)啟用稱為 DFE 的 Neptunes [替代查詢引擎](neptune-dfe-engine.md) `neptune_lab_mode` （透過將資料庫叢集參數設定為 `DFEQueryEngine=enabled`)，則 Neptune 會將唯讀 Gremlin 查詢/周遊轉譯為中繼邏輯表示法，並盡可能在 DFE 引擎上執行它們。

不過，DFE 尚未支援所有的 Gremlin 步驟。當步驟無法在 DFE 上以原生方式執行時，Neptune 會退回至 TinkerPop 以執行該步驟。`explain` 和 `profile` 報告包含此情況發生時的警告。

# DFE 中的 Gremlin 步驟涵蓋範圍
<a name="gremlin-step-coverage-in-DFE"></a>

 Gremlin DFE 是一種實驗室模式功能，可透過啟用叢集參數或使用`Neptune#useDFE`查詢提示來使用。如需詳細資訊，請參閱[搭配 Neptune DFE 查詢引擎使用 Gremlin](https://docs.aws.amazon.com//neptune/latest/userguide/gremlin-with-dfe.html)。

 下列步驟可用於 Gremlin DFE。

## 路徑和周遊步驟：
<a name="DFE-path-and-traversal"></a>

 [asDate()](https://tinkerpop.apache.org/docs/current/reference/#asDate-step)， [barrier()](https://tinkerpop.apache.org/docs/current/reference/#barrier-step)， [call()](https://tinkerpop.apache.org/docs/current/reference/#call-step)， [cap()](https://tinkerpop.apache.org/docs/current/reference/#cap-step)， [dateAdd()](https://tinkerpop.apache.org/docs/current/reference/#dateadd-step)， [dateDiff()](https://tinkerpop.apache.org/docs/current/reference/#datediff-step)， [disjunct()](https://tinkerpop.apache.org/docs/current/reference/#disjunct-step)， [drop()](https://tinkerpop.apache.org/docs/current/reference/#drop-step)， [fail()](https://tinkerpop.apache.org/docs/current/reference/#fail-step)， [filter()](https://tinkerpop.apache.org/docs/current/reference/#filter-step)， [flatMap()](https://tinkerpop.apache.org/docs/current/reference/#flatmap-step)， [id()](https://tinkerpop.apache.org/docs/current/reference/#id-step)， [identity()](https://tinkerpop.apache.org/docs/current/reference/#identity-step)， [index()](https://tinkerpop.apache.org/docs/current/reference/#index-step)， [intersect()](https://tinkerpop.apache.org/docs/current/reference/#intersect-step)， [inject()](https://tinkerpop.apache.org/docs/current/reference/#inject-step)， [label()](https://tinkerpop.apache.org/docs/current/reference/#label-step)， [length()](https://tinkerpop.apache.org/docs/current/reference/#length-step)， [loops()](https://tinkerpop.apache.org/docs/current/reference/#loops-step)， [map()](https://tinkerpop.apache.org/docs/current/reference/#map-step)， [order()](https://tinkerpop.apache.org/docs/current/reference/#order-step)， [order(local)](https://tinkerpop.apache.org/docs/current/reference/#order-step)， [path()](https://tinkerpop.apache.org/docs/current/reference/#path-step)， [project()](https://tinkerpop.apache.org/docs/current/reference/#project-step)， [range()](https://tinkerpop.apache.org/docs/current/reference/#range-step)， [repeat()](https://tinkerpop.apache.org/docs/current/reference/#repeat-step)， [reverse()， reverse()](https://tinkerpop.apache.org/docs/current/reference/#reverse-step)， [sack()](https://tinkerpop.apache.org/docs/current/reference/#sack-step)， [sample()](https://tinkerpop.apache.org/docs/current/reference/#sample-step)， [select(](https://tinkerpop.apache.org/docs/current/reference/#select-step)[sideEffect](https://tinkerpop.apache.org/docs/current/reference/#sideeffect-step)[)](https://tinkerpop.apache.org/docs/current/reference/#split-step)， [https://tinkerpop.apache.org/docs/current/reference/#unfold-step](https://tinkerpop.apache.org/docs/current/reference/#unfold-step) [https://tinkerpop.apache.org/docs/current/reference/#union-step](https://tinkerpop.apache.org/docs/current/reference/#union-step)

## 彙總和收集步驟：
<a name="DFE-aggregate-and-collection"></a>

 [aggregate（全域）](https://tinkerpop.apache.org/docs/current/reference/#aggregate-step)、[combin()](https://tinkerpop.apache.org/docs/current/reference/#combine-step)、[count()](https://tinkerpop.apache.org/docs/current/reference/#count-step)、[dedup()](https://tinkerpop.apache.org/docs/current/reference/#dedup-step)、[dedup（本機）](https://tinkerpop.apache.org/docs/current/reference/#dedup-step)、[fold()](https://tinkerpop.apache.org/docs/current/reference/#fold-step)、[group()](https://tinkerpop.apache.org/docs/current/reference/#group-step)、[groupCount()](https://tinkerpop.apache.org/docs/current/reference/#groupcount-step)、

## 數學步驟：
<a name="DFE-mathematical"></a>

 [max()](https://tinkerpop.apache.org/docs/current/reference/#max-step)， [mean()](https://tinkerpop.apache.org/docs/current/reference/#mean-step)， [min()](https://tinkerpop.apache.org/docs/current/reference/#min-step)， [sum()](https://tinkerpop.apache.org/docs/current/reference/#sum-step) 

## 元素步驟：
<a name="DFE-element"></a>

 [otherV()](https://tinkerpop.apache.org/docs/current/reference/#otherv-step)， [elementMap()](https://tinkerpop.apache.org/docs/current/reference/#elementmap-step)， [element()](https://tinkerpop.apache.org/docs/current/reference/#element-step)， [v()](https://tinkerpop.apache.org/docs/current/reference/#graph-step)， [ out()， in()， both()， outE()， inE()， bothE()， outV()， inV()， bothV()， otherV()](https://tinkerpop.apache.org/docs/current/reference/#vertex-step) 

## 屬性步驟：
<a name="DFE-property"></a>

 [properties()](https://tinkerpop.apache.org/docs/current/reference/#properties-step)， [key()](https://tinkerpop.apache.org/docs/current/reference/#key-step)， [valueMap()](https://tinkerpop.apache.org/docs/current/reference/#propertymap-step)， [value()](https://tinkerpop.apache.org/docs/current/reference/#value-step) 

## 篩選步驟：
<a name="DFE-filter"></a>

 [and()](https://tinkerpop.apache.org/docs/current/reference/#and-step)， [coalesce()](https://tinkerpop.apache.org/docs/current/reference/#coalesce-step)， [coin()](https://tinkerpop.apache.org/docs/current/reference/#coin-step)， [has()](https://tinkerpop.apache.org/docs/current/reference/#has-step)， [is()](https://tinkerpop.apache.org/docs/current/reference/#is-step)， [local()](https://tinkerpop.apache.org/docs/current/reference/#local-step)， [none()](https://tinkerpop.apache.org/docs/current/reference/#none-step)， [not()](https://tinkerpop.apache.org/docs/current/reference/#not-step)， [or()](https://tinkerpop.apache.org/docs/current/reference/#or-step)， [where()](https://tinkerpop.apache.org/docs/current/reference/#where-step) 

## 字串操作步驟：
<a name="DFE-string-manipulation"></a>

 [concat()](https://tinkerpop.apache.org/docs/current/reference/#concat-step)、[lTrim()](https://tinkerpop.apache.org/docs/current/reference/#lTrim-step)、[rTrim()](https://tinkerpop.apache.org/docs/current/reference/#rtrim-step)、[substring()](https://tinkerpop.apache.org/docs/current/reference/#substring-step)、[toLower()](https://tinkerpop.apache.org/docs/current/reference/#toLower-step)、[toUpper()](https://tinkerpop.apache.org/docs/current/reference/#toUpper-step)、[trim()](https://tinkerpop.apache.org/docs/current/reference/#trim-step) 

## 述詞：
<a name="DFE-predicates"></a>
+  [ 比較：eq、neq、lt、lte、gt、gte](https://tinkerpop.apache.org/docs/current/reference/#a-note-on-predicates) 
+  [包含：內部，不含](https://tinkerpop.apache.org/docs/current/reference/#a-note-on-predicates) 
+  [ TextP：endingWith、include、notStartingWith、notEndingWith、notContaining](https://tinkerpop.apache.org/docs/current/reference/#a-note-on-predicates) 
+  [ P： 和，或在外部、內部之間](https://tinkerpop.apache.org/docs/current/reference/#a-note-on-predicates) 

## 限制
<a name="gremlin-with-dfe-limitations"></a>

 以限制重複，DFE 尚不支援重複周遊和刪除內的標籤。

```
// With Limit inside the repeat traversal
  g.V().has('code','AGR').repeat(out().limit(5)).until(has('code','FRA'))
  
  // With Labels inside the repeat traversal
  g.V().has('code','AGR').repeat(out().as('a')).until(has('code','FRA'))
  
  // With Dedup inside the repeat traversal
  g.V().has('code','AGR').repeat(out().dedup()).until(has('code','FRA'))
```

 尚未支援具有巢狀重複或分支步驟的路徑。

```
// Path with branching steps
  g.V().has('code','AGR').union(identity, outE().inV()).path().by('code')
  
  
  // With nested repeat
  g.V().has('code','AGR').repeat(out().union(identity(), out())).path().by('code')
```

## 查詢規劃交錯
<a name="gremlin-with-dfe-interleaving"></a>

當轉換程序遇到沒有對應的原生 DFE 運算子的 Gremlin 步驟時，在退回使用 Tinkerpop 之前，它會嘗試尋找其他可以在 DFE 引擎上以原生方式執行的中繼查詢組件。它透過將交錯邏輯應用到頂層周遊來執行此操作。結果是盡可能使用支援的步驟。

任何此類中繼、非字首查詢轉換都會在 `explain` 和 `profile` 輸出中使用 `NeptuneInterleavingStep` 來表示。

為了進行效能比較，您可能想要關閉查詢中的交錯，同時仍使用 DFE 引擎來執行字首部分。或者，您可能只想要使用 TinkerPop 引擎，進行非字首查詢執行。您可以使用 `disableInterleaving` 查詢提示來做到這一點。

正如值為 `false` 的 [useDFE](gremlin-query-hints-useDFE.md) 查詢提示可防止完全不能在 DFE 上執行查詢一樣，值為 `true` 的 `disableInterleaving` 查詢提示會關閉 DFE 交錯以進行查詢轉換。例如：

```
g.with('Neptune#disableInterleaving', true)
 .V().has('genre','drama').in('likes')
```

## 已更新 Gremlin `explain` 和 `profile` 輸出
<a name="gremlin-with-dfe-explain-update"></a>

Gemlin [explain](gremlin-explain.md) 會提供有關 Neptune 用來執行查詢的最佳化周遊的詳細資訊。請參閱[範例 DFE `explain` 輸出](gremlin-explain-api.md#gremlin-explain-dfe)，以取得 DFE 引擎啟用時 `explain` 輸出的外觀範例。

[Gremlin `profile` API](gremlin-profile-api.md) 會執行指定的 Gemlin 周遊、收集有關執行的各種指標，以及產生設定檔報告，其中包含有關最佳化的查詢計畫和各種運算子的執行期統計資料的詳細資訊。請參閱[範例 DFE `profile` 輸出](gremlin-profile-api.md#gremlin-profile-sample-dfe-output)，以取得 DFE 引擎啟用時 `profile` 輸出的外觀範例。

**注意**  
因為 DFE 引擎是在實驗室模式下發行的一項實驗功能，所以 `explain` 和 `profile` 輸出的確切格式可能會有所變更。