

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

# 在 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 queries/traversals 转换为中间逻辑表示形式，并尽可能在 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) [https://tinkerpop.apache.org/docs/current/reference/#order-step](https://tinkerpop.apache.org/docs/current/reference/#order-step)[project ()](https://tinkerpop.apache.org/docs/current/reference/#project-step) [、[r [ange ()](https://tinkerpop.apache.org/docs/current/reference/#range-step)、repeat [()](https://tinkerpop.apache.org/docs/current/reference/#repeat-step)[、reverse ()](https://tinkerpop.apache.org/docs/current/reference/#reverse-step)、sample ()](https://tinkerpop.apache.org/docs/current/reference/#sack-step)[、s [el](https://tinkerpop.apache.org/docs/current/reference/#select-step) ect ()](https://tinkerpop.apache.org/docs/current/reference/#sample-step)、s [ideEffect ()](https://tinkerpop.apache.org/docs/current/reference/#sideeffect-step)、sp [lit ()](https://tinkerpop.apache.org/docs/current/reference/#split-step)、[unfold ()、union ()](https://tinkerpop.apache.org/docs/current/reference/#unfold-step)](https://tinkerpop.apache.org/docs/current/reference/#union-step) 

## 聚合和收集步骤：
<a name="DFE-aggregate-and-collection"></a>

 [聚合（全局）](https://tinkerpop.apache.org/docs/current/reference/#aggregate-step)、组[合（）、计数（）](https://tinkerpop.apache.org/docs/current/reference/#combine-step)[、重复数据删除（）](https://tinkerpop.apache.org/docs/current/reference/#count-step)、[重复数据删除（本地）](https://tinkerpop.apache.org/docs/current/reference/#dedup-step)[、折叠（）、组（）、groupCoun](https://tinkerpop.apache.org/docs/current/reference/#dedup-step) [t（）](https://tinkerpop.apache.org/docs/current/reference/#fold-step)[、[groupCount](https://tinkerpop.apache.org/docs/current/reference/#groupcount-step)（）](https://tinkerpop.apache.org/docs/current/reference/#group-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>
+  [Compare：eq、neq、lt、lte、gt、gte](https://tinkerpop.apache.org/docs/current/reference/#a-note-on-predicates) 
+  [Contains：within、without](https://tinkerpop.apache.org/docs/current/reference/#a-note-on-predicates) 
+  [TextP：结尾为、包含、、、不包含 notStartingWith notEndingWith](https://tinkerpop.apache.org/docs/current/reference/#a-note-on-predicates) 
+  [P：and、or、between、outside、inside](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>

Gremlin [explain](gremlin-explain.md) 提供有关 Neptune 用来运行查询的优化遍历的详细信息。有关启用 DFE 引擎时 `explain` 输出内容的示例，请参阅 [DFE `explain` 输出示例](gremlin-explain-api.md#gremlin-explain-dfe)。

[Gremlin `profile` API](gremlin-profile-api.md) 运行指定的 Gremlin 遍历，收集有关运行的各种指标，并生成 Profile 报告，其中包含有关优化查询计划的详细信息以及各种运算符的运行时系统统计数据。有关启用 DFE 引擎时 `profile` 输出内容的示例，请参阅 [DFE `profile` 输出示例](gremlin-profile-api.md#gremlin-profile-sample-dfe-output)。

**注意**  
由于 DFE 引擎是在实验室模式下发布的实验特征，因此 `explain` 和 `profile` 输出的确切格式可能会发生变化。