[
https://issues.apache.org/jira/browse/TINKERPOP-1455?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15546200#comment-15546200
]
ASF GitHub Bot commented on TINKERPOP-1455:
-------------------------------------------
GitHub user okram opened a pull request:
https://github.com/apache/tinkerpop/pull/447
TINKERPOP-1455: Provide String-based withStrategy()/withoutStrategy() for
language variant usage
https://issues.apache.org/jira/browse/TINKERPOP-1455
Added TraversalSource.withStrategy(String, Object...) and
TraversalSource.withoutStrategy(String). This allows Gremlin language variants
(e.g. Gremlin-Python) to add and remove strategies from a traversal source.
Prior to this moment, strategy addition/removal was via strategy instances
(Java objects) and classes (Class objects). That is not language variants
friendly.
This branch is backwards compatible. If a `TraversalStrategy` does not have
a builder and exposes a static `instance()`-method, then
`g.withStrategy('com.blah.MyStrategy')` will work as expected. If a
`TraversalStrategy` does have a builder (that is, can be configured), then it
should expose a static `create(Configuration)`-method. Note Gremlin language
variants could not use `withStrategies()` prior to this and thus, this addition
is backwards compatible. Finally, `TraversalSource.withComputer(Object...)` was
added as well for the same reasons.
```
>>> g =
g.withStrategy('org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.SubgraphStrategy','vertices',hasLabel('person'),'edges',has('weight',gt(0.5)))
>>> g.V().name.toList()
[u'marko', u'vadas', u'josh', u'peter']
```
The CHANGELOG, gremlin-variants.asciidoc, and upgrade doc have all been
updated accordingly.
VOTE +1
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/apache/tinkerpop TINKERPOP-1455
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/tinkerpop/pull/447.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #447
----
commit e6e59e417f119c1b71a43141fce04cb212bc0a58
Author: Marko A. Rodriguez <[email protected]>
Date: 2016-10-04T14:37:07Z
first push. We now have TraversalSource.withStrategy(String, Object...) and
TraversalSource.withoutStrategy(String). Added a test case to Gremlin-Python
that uses SubgraphStrategy and it works :).
commit 95557bf3aac279282e3f3779d68ce195bd4ca058
Author: Marko A. Rodriguez <[email protected]>
Date: 2016-10-04T16:26:12Z
added static create(Configuration) methods to all Builder-based strategies
except EventStrategy as that requires Java objects :(. Deprecated
PartitionStrategy.Builder.addReadParition() in favor of
readParitions(String...). Computer now has a Configuration-based constructor
and corresponding withComputer(Object...) arguments.
commit 20dec2076b79441c7dcf06827014ace72fcaea6c
Author: Marko A. Rodriguez <[email protected]>
Date: 2016-10-04T18:15:31Z
updated gremlin-variants.asciidoc with new withStrategy()/withoutStrategy()
method discussion. Built docs. Success.
----
> Provide String-based withStrategy()/withoutStrategy() for language variant
> usage
> --------------------------------------------------------------------------------
>
> Key: TINKERPOP-1455
> URL: https://issues.apache.org/jira/browse/TINKERPOP-1455
> Project: TinkerPop
> Issue Type: Improvement
> Components: language-variant, process
> Affects Versions: 3.2.2
> Reporter: Marko A. Rodriguez
> Assignee: Marko A. Rodriguez
>
> Right now {{withStrategies()}} is not supported by Gremlin-Python. Why?
> Because strategies are created via Java and thus you can't do stuff like:
> {code}
> g.withStrategies(SubgraphStrategy.build()...create())
> {code}
> Now, we have strategies that we have made "native" to
> {{GraphTraversalSource}} by way of {{withXXX}}. For example:
> {{withSideEffect()}}, {{withSack()}}, {{withRemote()}}, {{withPath()}}, etc.
> In order to generally support any strategy created by a user for use from a
> language variant, we should support lambda based strategies. E.g.:
> {code}
> g.withStrategies(lambda : "SubgraphStrategy.build()...create()")
> {code}
> Like any other lambda, it is executed server side using the respective
> {{ScriptEngine}}.
> Next, {{withoutStrategies()}} should support {{String...}} so you can do:
> {code}
> g.withoutStrategies("com.stuff.MyStrategy", "com.stuff.MyOtherStrategy")
> {code}
> ..instead of having to pass in the {{Class}} object.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)