

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

# Amazon Neptune 的原生 Gremlin 步驟支援
<a name="gremlin-step-support"></a>

Amazon Neptune 引擎目前對所有 Gremlin 步驟沒有完整的原生支援。如 [調校 Gremlin 查詢](gremlin-traversal-tuning.md) 中所述。目前的支援分為四個類別：
+ [一律可以轉換為原生 Neptune 引擎操作的 Gremlin 步驟](#gremlin-steps-always)
+ [在某些情況下可以轉換為原生 Neptune 引擎操作的 Gremlin 步驟](#gremlin-steps-sometimes) 
+ [永不轉換為原生 Neptune 引擎操作的 Gremlin 步驟](#gremlin-steps-never) 
+ [Neptune 完全不支援的 Gremlin 步驟](#neptune-gremlin-steps-unsupported) 

## 一律可以轉換為原生 Neptune 引擎操作的 Gremlin 步驟
<a name="gremlin-steps-always"></a>

許多 Gemlin 步驟只要符合下列條件就可以轉換為原生 Neptune 引擎操作：
+ 它們不會在查詢前面加上無法轉換的步驟。
+ 它們的父步驟 (如果有的話) 都可以進行轉換。
+ 它們所有的子周遊 (如果有的話) 都可以進行轉換。

下列 Gemlin 步驟只要符合這些條件，一律轉換為原生 Neptune 引擎操作：
+ [and( )](http://tinkerpop.apache.org/docs/current/reference/#and-step)
+ [as( )](http://tinkerpop.apache.org/docs/current/reference/#as-step)
+ [count( )](http://tinkerpop.apache.org/docs/current/reference/#count-step)
+ [E( )](http://tinkerpop.apache.org/docs/current/reference/#graph-step)
+ [emit( )](http://tinkerpop.apache.org/docs/current/reference/#emit-step)
+ [explain( )](http://tinkerpop.apache.org/docs/current/reference/#explain-step)
+ [group( )](http://tinkerpop.apache.org/docs/current/reference/#group-step)
+ [groupCount( )](http://tinkerpop.apache.org/docs/current/reference/#groupcount-step)
+ [identity( )](http://tinkerpop.apache.org/docs/current/reference/#identity-step)
+ [is( )](http://tinkerpop.apache.org/docs/current/reference/#is-step)
+ [key( )](http://tinkerpop.apache.org/docs/current/reference/#key-step)
+ [label( )](http://tinkerpop.apache.org/docs/current/reference/#label-step)
+ [limit( )](http://tinkerpop.apache.org/docs/current/reference/#limit-step)
+ [local( )](http://tinkerpop.apache.org/docs/current/reference/#local-step)
+ [loops( )](http://tinkerpop.apache.org/docs/current/reference/#loops-step)
+ [not( )](http://tinkerpop.apache.org/docs/current/reference/#not-step)
+ [or( )](http://tinkerpop.apache.org/docs/current/reference/#or-step)
+ [profile( )](http://tinkerpop.apache.org/docs/current/reference/#profile-step)
+ [properties( )](http://tinkerpop.apache.org/docs/current/reference/#properties-step)
+ [subgraph( )](http://tinkerpop.apache.org/docs/current/reference/#subgraph-step)
+ [until( )](http://tinkerpop.apache.org/docs/current/reference/#until-step)
+ [V( )](http://tinkerpop.apache.org/docs/current/reference/#graph-step)
+ [value( )](http://tinkerpop.apache.org/docs/current/reference/#value-step)
+ [valueMap( )](http://tinkerpop.apache.org/docs/current/reference/#valuemap-step)
+ [values( )](http://tinkerpop.apache.org/docs/current/reference/#values-step)

## 在某些情況下可以轉換為原生 Neptune 引擎操作的 Gremlin 步驟
<a name="gremlin-steps-sometimes"></a>

在某些情況下，有些 Gemlin 步驟可以轉換為原生 Neptune 引擎操作，但在其他情況下則不能：
+ [addE( )](http://tinkerpop.apache.org/docs/current/reference/#addedge-step) – `addE()` 步驟通常可以轉換為原生 Neptune 引擎操作，除非它緊接著包含周遊做為索引鍵的 `property()` 步驟。
+ [addV( )](http://tinkerpop.apache.org/docs/current/reference/#addvertex-step) – `addV()` 步驟通常可以轉換為原生 Neptune 引擎操作，除非它緊接著包含周遊做為索引鍵的 `property()` 步驟，或除非指派了多個標籤。
+ [aggregate( )](http://tinkerpop.apache.org/docs/current/reference/#store-step) – `aggregate()` 步驟通常可以轉換為原生 Neptune 引擎操作，除非該步驟用於子周遊或次周遊，或者除非要儲存的值是頂點、邊緣、ID、標籤或屬性值以外的值。

  在下面範例中，不會轉換 `aggregate()`，因為正在子周遊中使用它：

  ```
  g.V().has('code','ANC').as('a')
       .project('flights').by(select('a')
       .outE().aggregate('x'))
  ```

  在此範例中，不會轉換 aggregate()，因為儲存的是值的 `min()`：

  ```
  g.V().has('code','ANC').outE().aggregate('x').by(values('dist').min())
  ```
+ [barrier( )](http://tinkerpop.apache.org/docs/current/reference/#barrier-step) – `barrier()` 步驟通常可以轉換為原生 Neptune 引擎操作，除非其後的步驟未轉換。
+ [cap( )](http://tinkerpop.apache.org/docs/current/reference/#cap-step) – 轉換 `cap()` 步驟的唯一情況是在其與 `unfold()` 步驟結合，以傳回頂點、邊緣、ID 或屬性之彙總的展開版本時。在這個範例中，將轉換 `cap()`，因為它後面是 `.unfold()`：

  ```
  g.V().has('airport','country','IE').aggregate('airport').limit(2)
       .cap('airport').unfold()
  ```

  不過，如果您移除 `.unfold()`，將不會轉換 `cap()`：

  ```
  g.V().has('airport','country','IE').aggregate('airport').limit(2)
       .cap('airport')
  ```
+ [coalesce( )](http://tinkerpop.apache.org/docs/current/reference/#coalesce-step) – 轉換 `coalesce()` 步驟的唯一情況是在它遵循 [TinkerPop 配方頁面](http://tinkerpop.apache.org/docs/current/recipes/)上建議的 [Upsert 模式](http://tinkerpop.apache.org/docs/current/recipes/#element-existence)時。不允許其他合併 coalesce() 模式。轉換限於可以轉換所有子周遊的情況，它們都會產生與輸出相同的類型 (頂點、邊緣、ID、值、金鑰或標籤)、它們都會周遊到一個新元素，並且它們不包含 `repeat()` 步驟。
+ [constant( )](http://tinkerpop.apache.org/docs/current/reference/#constant-step) – 目前，僅在周遊的 `sack().by()` 部分內使用 constant() 步驟，以指派常數值時，才會轉換此步驟，如下所示：

  ```
  g.V().has('code','ANC').sack(assign).by(constant(10)).out().limit(2)
  ```
+ [cyclicPath( )](http://tinkerpop.apache.org/docs/current/reference/#cyclicpath-step) – `cyclicPath()` 步驟通常可以轉換為原生 Neptune 引擎操作，除非該步驟與 `by()`、`from()` 或 `to()` 調幅器搭配使用。例如，在以下查詢中，不會轉換 `cyclicPath()`：

  ```
  g.V().has('code','ANC').as('a').out().out().cyclicPath().by('code')
  g.V().has('code','ANC').as('a').out().out().cyclicPath().from('a')
  g.V().has('code','ANC').as('a').out().out().cyclicPath().to('a')
  ```
+ [drop( )](http://tinkerpop.apache.org/docs/current/reference/#drop-step) – `drop()` 步驟通常可以轉換為原生 Neptune 引擎操作，除非該步驟是在 `sideEffect(`) 或 `optional()` 內部使用。
+ [fold( )](http://tinkerpop.apache.org/docs/current/reference/#fold-step) – 只有兩種情況可以轉換 fold() 步驟，即當它用於 [TinkerPop 配方頁面](http://tinkerpop.apache.org/docs/current/recipes/)上建議的 [Upsert 模式](http://tinkerpop.apache.org/docs/current/recipes/#element-existence)時，以及當它用於 `group().by()` 內容時，如下所示：

  ```
  g.V().has('code','ANC').out().group().by().by(values('code', 'city').fold())
  ```
+  [has( )](http://tinkerpop.apache.org/docs/current/reference/#has-step)   –   `has()` 步驟通常可以轉換為原生 Neptune 引擎操作，前提是具有 `T` 的查詢使用述詞 `P.eq`、`P.neq` 或 `P.contains`。預期的 `has()` 變化表示這些 `P` 執行個體也要轉換為原生執行個體，例如 `hasId('id1234')`，其相當於 `has(eq， T.id， 'id1234')`。
+ [id( )](http://tinkerpop.apache.org/docs/current/reference/#id-step) – 除非在屬性上使用 `id()` 步驟，否則會轉換此步驟，如下所示：

  ```
  g.V().has('code','ANC').properties('code').id()
  ```
+  [mergeE()](https://tinkerpop.apache.org/docs/current/reference/#mergeedge-step)   – 如果參數   （合併條件、 `onCreate`和 `onMatch`) 為常數 (`null`、常數 或 )`Map`，則可以`select()`將`mergeE()`步驟轉換為原生 Neptune 引擎操作`Map`。[ 可以轉換疊加邊緣](https://docs.aws.amazon.com//neptune/latest/userguide/gremlin-efficient-upserts.html#gremlin-upserts-edges)中的所有範例。
+  [mergeV()](https://tinkerpop.apache.org/docs/current/reference/#mergevertex-step)   – 如果參數   （合併條件、 `onCreate`和 ) 為常數 (`null`、常數 或 )`Map`，則可以將 mergeV(`onMatch`) 步驟轉換為原生 Neptune `select()` 引擎操作`Map`。[ 可以轉換高載頂點](https://docs.aws.amazon.com//neptune/latest/userguide/gremlin-efficient-upserts.html#gremlin-upserts-vertices)中的所有範例。
+ [order( )](http://tinkerpop.apache.org/docs/current/reference/#order-step) – `order()` 步驟通常可以轉換為原生 Neptune 引擎操作，除非下列其中一個條件成立：
  + `order()` 步驟是在巢狀子周遊內，如下所示：

    ```
    g.V().has('code','ANC').where(V().out().order().by(id))
    ```
  + 例如，本機排序正在與 `order(local)` 搭配使用。
  + 正在排序依據的 `by()` 調幅中使用自訂比較器。使用 `sack()` 的範例如下：

    ```
    g.withSack(0).
      V().has('code','ANC').
          repeat(outE().sack(sum).by('dist').inV()).times(2).limit(10).
          order().by(sack())
    ```
  + 在同一個元素上有多個排序。
+ [project( )](http://tinkerpop.apache.org/docs/current/reference/#project-step) – `project()` 步驟通常可以轉換為原生 Neptune 引擎操作，除非 `project()` 後面的 `by()` 陳述式數目與指定的標籤數目不符，如下所示：

  ```
  g.V().has('code','ANC').project('x', 'y').by(id)
  ```
+ [range( )](http://tinkerpop.apache.org/docs/current/reference/#range-step) – 僅在有問題範圍的下限為零 (例如，`range(0,3)`) 時，才會轉換 `range()` 步驟。
+ [repeat( )](http://tinkerpop.apache.org/docs/current/reference/#repeat-step) – `repeat()` 步驟通常可以轉換為原生 Neptune 引擎操作，除非它在另一個 `repeat()` 步驟內形成巢狀，如下所示：

  ```
  g.V().has('code','ANC').repeat(out().repeat(out()).times(2)).times(2)
  ```
+ [sack( )](http://tinkerpop.apache.org/docs/current/reference/#sack-step) – `sack()` 步驟通常可以轉換為原生 Neptune 引擎操作，但在下列情況下除外：
  + 如果使用非數字 sack 運算子。
  + 如果使用 `+`、`-`、`mult`、`div`、`min` 和 `max` 以外的數字 sack 運算子。
  + 如果在 `where()` 步驟內使用 `sack()`，根據 sack 值進行篩選，如下所示：

    ```
    g.V().has('code','ANC').sack(assign).by(values('code')).where(sack().is('ANC'))
    ```
+ [sum( )](http://tinkerpop.apache.org/docs/current/reference/#sum-step) – `sum()` 步驟通常可以轉換為原生 Neptune 引擎操作，但在用來計算全域求和時不能轉換，如下所示：

  ```
  g.V().has('code','ANC').outE('routes').values('dist').sum()
  ```
+ [union( )](http://tinkerpop.apache.org/docs/current/reference/#union-step) – `union()` 步驟可以轉換為原生 Neptune 引擎操作，只要它是查詢中的最後一個步驟，但終端步驟除外。
+ [unfold( )](http://tinkerpop.apache.org/docs/current/reference/#unfold-step) – 僅在 [TinkerPop 配方頁面](http://tinkerpop.apache.org/docs/current/recipes/)上建議的 [Upsert 模式](http://tinkerpop.apache.org/docs/current/recipes/#element-existence)中使用 `unfold()` 步驟時，以及此步驟與 `cap()` 搭配使用時，才能將此步驟轉換為原生 Neptune 引擎操作，如下所示：

  ```
  g.V().has('airport','country','IE').aggregate('airport').limit(2)
       .cap('airport').unfold()
  ```
+ [where( )](http://tinkerpop.apache.org/docs/current/reference/#where-step) – `where()` 步驟通常可以轉換為原生 Neptune 引擎操作，但在下列情況下除外：
  + 使用 by() 調幅時，如下所示：

    ```
    g.V().hasLabel('airport').as('a')
         .where(gt('a')).by('runways')
    ```
  + 使用 `eq`、`neq`、`within` 和 `without` 以外的比較運算子時。
  + 利用使用者提供的彙總時。

## 永不轉換為原生 Neptune 引擎操作的 Gremlin 步驟
<a name="gremlin-steps-never"></a>

Neptune 中支援下列 Gemlin 步驟，但這些步驟永遠不會轉換為原生 Neptune 引擎操作。相反地，它們是由 Gemlin 伺服器執行。
+ [choose( )](http://tinkerpop.apache.org/docs/current/reference/#choose-step)
+ [coin( )](http://tinkerpop.apache.org/docs/current/reference/#coin-step)
+ [inject( )](http://tinkerpop.apache.org/docs/current/reference/#inject-step)
+ [match( )](http://tinkerpop.apache.org/docs/current/reference/#match-step)
+ [math( )](http://tinkerpop.apache.org/docs/current/reference/#math-step)
+ [max( )](http://tinkerpop.apache.org/docs/current/reference/#max-step)
+ [mean( )](http://tinkerpop.apache.org/docs/current/reference/#mean-step)
+ [min( )](http://tinkerpop.apache.org/docs/current/reference/#min-step)
+ [option( )](http://tinkerpop.apache.org/docs/current/reference/#option-step)
+ [optional( )](http://tinkerpop.apache.org/docs/current/reference/#optional-step)
+ [path( )](http://tinkerpop.apache.org/docs/current/reference/#path-step)
+ [propertyMap( )](http://tinkerpop.apache.org/docs/current/reference/#propertymap-step)
+ [sample( )](http://tinkerpop.apache.org/docs/current/reference/#sample-step)
+ [skip( )](http://tinkerpop.apache.org/docs/current/reference/#skip-step)
+ [tail( )](http://tinkerpop.apache.org/docs/current/reference/#tail-step)
+ [timeLimit( )](http://tinkerpop.apache.org/docs/current/reference/#timelimit-step)
+ [tree( )](http://tinkerpop.apache.org/docs/current/reference/#tree-step)

## Neptune 完全不支援的 Gremlin 步驟
<a name="neptune-gremlin-steps-unsupported"></a>

Neptune 中完全不支援下列 Gremlin 步驟。在大多數情況下，這是因為它們需要一個 `GraphComputer`，但 Neptune 目前不支援它。
+ [connectedComponent( )](http://tinkerpop.apache.org/docs/current/reference/#connectedcomponent-step)
+ [io( )](http://tinkerpop.apache.org/docs/current/reference/#io-step)
+ [shortestPath( )](http://tinkerpop.apache.org/docs/current/reference/#shortestpath-step)
+ [withComputer( )](http://tinkerpop.apache.org/docs/current/reference/#with-step)
+ [pageRank( )](http://tinkerpop.apache.org/docs/current/reference/#pagerank-step)
+ [peerPressure( )](http://tinkerpop.apache.org/docs/current/reference/#peerpressure-step)
+ [program( )](http://tinkerpop.apache.org/docs/current/reference/#program-step)

`io()` 步驟實際上是部分受到支援，因為它可以用來從 URL 進行 `read()`，但不能進行 `write()`。