This is an automated email from the ASF dual-hosted git repository. colegreer pushed a commit to branch strategyConstruction in repository https://gitbox.apache.org/repos/asf/tinkerpop.git
commit f37da938016c48a4d84b196d4f8512d2c37d64b5 Author: Cole-Greer <[email protected]> AuthorDate: Thu Sep 19 13:08:34 2024 -0700 python --- gremlin-python/build/generate.groovy | 2 +- .../gremlin_python/process/graph_traversal.py | 2 +- .../python/gremlin_python/process/strategies.py | 37 ++++++++++- gremlin-python/src/main/python/radish/gremlin.py | 75 +++++++++++++++++++++- .../src/main/python/tests/driver/test_client.py | 2 +- .../main/python/tests/process/test_gremlin_lang.py | 2 +- .../main/python/tests/process/test_strategies.py | 2 +- 7 files changed, 115 insertions(+), 7 deletions(-) diff --git a/gremlin-python/build/generate.groovy b/gremlin-python/build/generate.groovy index 5672b55add..9ca21c2cdf 100644 --- a/gremlin-python/build/generate.groovy +++ b/gremlin-python/build/generate.groovy @@ -58,7 +58,7 @@ radishGremlinFile.withWriter('UTF-8') { Writer writer -> 'import datetime\n' + 'from gremlin_python.statics import long, GremlinType\n' + 'from gremlin_python.process.anonymous_traversal import traversal\n' + - 'from gremlin_python.process.strategies import SeedStrategy, SubgraphStrategy, PartitionStrategy, ProductiveByStrategy, ReadOnlyStrategy\n' + + 'from gremlin_python.process.strategies import *\n' + 'from gremlin_python.process.traversal import TraversalStrategy\n' + 'from gremlin_python.process.graph_traversal import __\n' + 'from gremlin_python.structure.graph import Graph\n' + diff --git a/gremlin-python/src/main/python/gremlin_python/process/graph_traversal.py b/gremlin-python/src/main/python/gremlin_python/process/graph_traversal.py index a5e66371aa..c9c59fda6d 100644 --- a/gremlin-python/src/main/python/gremlin_python/process/graph_traversal.py +++ b/gremlin-python/src/main/python/gremlin_python/process/graph_traversal.py @@ -135,7 +135,7 @@ class GraphTraversalSource(object): val = True if v is None else v if options_strategy is None: - options_strategy = OptionsStrategy({k: val}) + options_strategy = OptionsStrategy(**{k: val}) source = self.with_strategies(options_strategy) else: options_strategy[1].configuration[k] = val diff --git a/gremlin-python/src/main/python/gremlin_python/process/strategies.py b/gremlin-python/src/main/python/gremlin_python/process/strategies.py index b1e1619f96..15bca18786 100644 --- a/gremlin-python/src/main/python/gremlin_python/process/strategies.py +++ b/gremlin-python/src/main/python/gremlin_python/process/strategies.py @@ -41,6 +41,7 @@ class ConnectiveStrategy(TraversalStrategy): class ElementIdStrategy(TraversalStrategy): def __init__(self): TraversalStrategy.__init__(self, fqcn=decoration_namespace + 'ElementIdStrategy') + self.configuration = {} # EventStrategy doesn't make sense outside JVM traversal machine @@ -53,7 +54,7 @@ class HaltedTraverserStrategy(TraversalStrategy): class OptionsStrategy(TraversalStrategy): - def __init__(self, options=None): + def __init__(self, **options): TraversalStrategy.__init__(self, configuration=options, fqcn=decoration_namespace + 'OptionsStrategy') @@ -121,6 +122,21 @@ class MatchAlgorithmStrategy(TraversalStrategy): self.configuration["matchAlgorithm"] = match_algorithm +class ReferenceElementStrategy(TraversalStrategy): + def __init__(self, options=None): + TraversalStrategy.__init__(self, configuration=options, fqcn=decoration_namespace + 'ReferenceElementStrategy') + + +class ComputerFinalizationStrategy(TraversalStrategy): + def __init__(self, options=None): + TraversalStrategy.__init__(self, configuration=options, fqcn=decoration_namespace + 'ComputerFinalizationStrategy') + + +class ProfileStrategy(TraversalStrategy): + def __init__(self, options=None): + TraversalStrategy.__init__(self, configuration=options, fqcn=decoration_namespace + 'ProfileStrategy') + + ########################### # OPTIMIZATION STRATEGIES # ########################### @@ -210,10 +226,19 @@ class EarlyLimitStrategy(TraversalStrategy): def __init__(self): TraversalStrategy.__init__(self, fqcn=optimization_namespace + 'EarlyLimitStrategy') + +class MessagePassingReductionStrategy(TraversalStrategy): + def __init__(self, options=None): + TraversalStrategy.__init__(self, configuration=options, fqcn=decoration_namespace + 'MessagePassingReductionStrategy') + ########################### # VERIFICATION STRATEGIES # ########################### +class ComputerVerificationStrategy(TraversalStrategy): + def __init__(self, options=None): + TraversalStrategy.__init__(self, configuration=options, fqcn=decoration_namespace + 'ComputerVerificationStrategy') + class LambdaRestrictionStrategy(TraversalStrategy): def __init__(self): @@ -237,3 +262,13 @@ class ReservedKeysVerificationStrategy(TraversalStrategy): self.configuration["logWarning"] = log_warning self.configuration["throwException"] = throw_exception self.configuration["keys"] = keys + + +class VertexProgramRestrictionStrategy(TraversalStrategy): + def __init__(self): + TraversalStrategy.__init__(self, fqcn=verification_namespace + 'VertexProgramRestrictionStrategy') + + +class StandardVerificationStrategy(TraversalStrategy): + def __init__(self): + TraversalStrategy.__init__(self, fqcn=verification_namespace + 'StandardVerificationStrategy') diff --git a/gremlin-python/src/main/python/radish/gremlin.py b/gremlin-python/src/main/python/radish/gremlin.py index e743770e98..df77351516 100644 --- a/gremlin-python/src/main/python/radish/gremlin.py +++ b/gremlin-python/src/main/python/radish/gremlin.py @@ -28,7 +28,7 @@ from radish import world import datetime from gremlin_python.statics import long, GremlinType from gremlin_python.process.anonymous_traversal import traversal -from gremlin_python.process.strategies import SeedStrategy, SubgraphStrategy, PartitionStrategy, ProductiveByStrategy, ReadOnlyStrategy +from gremlin_python.process.strategies import * from gremlin_python.process.traversal import TraversalStrategy from gremlin_python.process.graph_traversal import __ from gremlin_python.structure.graph import Graph @@ -384,9 +384,58 @@ world.gremlins = { 'g_V_asXnX_whereXorXhasLabelXsoftwareX_hasLabelXpersonXXX_selectXnX_byXnameX': [(lambda g:g.V().as_('n').where(__.or_(__.has_label('software'), __.has_label('person'))).select('n').by('name'))], 'g_V_asXnX_whereXorXselectXnX_hasLabelXsoftwareX_selectXnX_hasLabelXpersonXXX_selectXnX_byXnameX': [(lambda g:g.V().as_('n').where(__.or_(__.select('n').has_label('software'), __.select('n').has_label('person'))).select('n').by('name'))], 'g_V_hasLabelXpersonX_asXxX_whereXinEXknowsX_count_isXgteX1XXX_selectXxX': [(lambda g:g.V().has_label('person').as_('x').where(__.in_e('knows').count().is_(P.gte(1))).select('x'))], + 'g_withStrategiesXAdjacentToIncidentStrategyX_V': [(lambda g:g.with_strategies(AdjacentToIncidentStrategy()).V())], + 'g_withoutStrategiesXAdjacentToIncidentStrategyX_V': [(lambda g:g.without_strategies(*[GremlinType('org.apache.tinkerpop.gremlin.process.traversal.strategy.optimization.AdjacentToIncidentStrategy')]).V())], + 'g_withStrategiesXAdjacentToIncidentStrategyX_V_out_count': [(lambda g:g.with_strategies(AdjacentToIncidentStrategy()).V().out().count())], + 'g_withStrategiesXAdjacentToIncidentStrategyX_V_whereXoutX': [(lambda g:g.with_strategies(AdjacentToIncidentStrategy()).V().where(__.out()))], + 'g_withStrategiesXByModulatorOptimizationStrategyX_V_order_byXvaluesXnameXX': [(lambda g:g.with_strategies(ByModulatorOptimizationStrategy()).V().order().by(__.values('name')))], + 'g_withoutStrategiesXByModulatorOptimizationStrategyX_V_order_byXvaluesXnameXX': [(lambda g:g.without_strategies(*[GremlinType('org.apache.tinkerpop.gremlin.process.traversal.strategy.optimization.ByModulatorOptimizationStrategy')]).V().order().by(__.values('name')))], + 'g_withStrategiesXComputerFinalizationStrategyX_V': [(lambda g:g.with_strategies(ComputerFinalizationStrategy()).V())], + 'g_withoutStrategiesXByModulatorOptimizationStrategyX_V': [(lambda g:g.without_strategies(*[GremlinType('org.apache.tinkerpop.gremlin.process.computer.traversal.strategy.finalization.ComputerFinalizationStrategy')]).V())], + 'g_withStrategiesXComputerVerificationStrategyX_V': [(lambda g:g.with_strategies(ComputerVerificationStrategy()).V())], + 'g_withoutStrategiesXComputerVerificationStrategyX_V': [(lambda g:g.without_strategies(*[GremlinType('org.apache.tinkerpop.gremlin.process.traversal.strategy.verification.ComputerVerificationStrategy')]).V())], + 'g_withStrategiesXConnectiveStrategyStrategyX_V_hasXname_markoX_or_whereXinXknowsX_hasXname_markoXX': [(lambda g:g.with_strategies(ConnectiveStrategy()).V().has('name', 'marko').or_().where(__.in_('knows').has('name', 'marko')))], + 'g_withStrategiesXCountStrategyX_V_whereXoutE_count_isX0XX': [(lambda g:g.with_strategies(CountStrategy()).V().where(__.out_e().count().is_(0)))], + 'g_withoutStrategiesXCountStrategyX_V_whereXoutE_count_isX0XX': [(lambda g:g.without_strategies(*[GremlinType('org.apache.tinkerpop.gremlin.process.traversal.strategy.optimization.CountStrategy')]).V().where(__.out_e().count().is_(0)))], + 'g_withStrategiesXEarlyLimitStrategyX_V_out_order_valueMap_limitX3X_selectXnameX': [(lambda g:g.with_strategies(EarlyLimitStrategy()).V().out().order().value_map().limit(3).select('name'))], + 'g_withoutStrategiesXEarlyLimitStrategyX_V_out_order_valueMap_limitX3X_selectXnameX': [(lambda g:g.without_strategies(*[GremlinType('org.apache.tinkerpop.gremlin.process.traversal.strategy.optimization.EarlyLimitStrategy')]).V().out().order().value_map().limit(3).select('name'))], + 'g_withStrategiesXEdgeLabelVerificationStrategyXthrowException_true_logWarning_falseXX_V': [(lambda g:g.with_strategies(EdgeLabelVerificationStrategy(throw_exception=True, log_warning=False)).V().out())], + 'g_withStrategiesXEdgeLabelVerificationStrategyXthrowException_false_logWarning_falseXX_V': [(lambda g:g.with_strategies(EdgeLabelVerificationStrategy(throw_exception=False, log_warning=False)).V().out())], + 'g_withoutStrategiesXEdgeLabelVerificationStrategyX_V': [(lambda g:g.without_strategies(*[GremlinType('org.apache.tinkerpop.gremlin.process.traversal.strategy.verification.EdgeLabelVerificationStrategy')]).V().out())], + 'g_withStrategiesXElementIdStrategyX_V': [(lambda g:g.with_strategies(ElementIdStrategy()).V())], + 'g_withoutStrategiesXElementIdStrategyX_V': [(lambda g:g.without_strategies(*[GremlinType('org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.ElementIdStrategy')]).V())], + 'g_withStrategiesXFilterRankingStrategyX_V_out_order_dedup': [(lambda g:g.with_strategies(FilterRankingStrategy()).V().out().order().dedup())], + 'g_withoutStrategiesXFilterRankingStrategyX_V_out_order_dedup': [(lambda g:g.without_strategies(*[GremlinType('org.apache.tinkerpop.gremlin.process.traversal.strategy.optimization.FilterRankingStrategy')]).V().out().order().dedup())], + 'g_withStrategiesXGraphFilterStrategyX_V': [(lambda g:g.with_strategies(GraphFilterStrategy()).V())], + 'g_withoutStrategiesXGraphFilterStrategyX_V': [(lambda g:g.without_strategies(*[GremlinType('org.apache.tinkerpop.gremlin.process.computer.traversal.strategy.optimization.GraphFilterStrategy')]).V())], + 'g_withStrategiesXHaltedTraverserStrategyXDetachedFactoryXX_V': [(lambda g:g.with_strategies(HaltedTraverserStrategy(halted_traverser_factory='org.apache.tinkerpop.gremlin.structure.util.detached.DetachedFactory')).V())], + 'g_withStrategiesXHaltedTraverserStrategyXReferenceFactoryXX_V': [(lambda g:g.with_strategies(HaltedTraverserStrategy(halted_traverser_factory='org.apache.tinkerpop.gremlin.structure.util.reference.ReferenceFactory')).V())], + 'g_withoutStrategiesXHaltedTraverserStrategyX_V': [(lambda g:g.without_strategies(*[GremlinType('org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.HaltedTraverserStrategy')]).V())], + 'g_withStrategiesXIdentityRemovalStrategyX_V_identity_out': [(lambda g:g.with_strategies(IdentityRemovalStrategy()).V().identity().out())], + 'g_withoutStrategiesXIdentityRemovalStrategyX_V_identity_out': [(lambda g:g.without_strategies(*[GremlinType('org.apache.tinkerpop.gremlin.process.traversal.strategy.optimization.IdentityRemovalStrategy')]).V().identity().out())], + 'g_withStrategiesXIncidentToAdjacentStrategyX_V_outE_inV': [(lambda g:g.with_strategies(IncidentToAdjacentStrategy()).V().out_e().in_v())], + 'g_withoutStrategiesXIncidentToAdjacentStrategyX_V_outE_inV': [(lambda g:g.without_strategies(*[GremlinType('org.apache.tinkerpop.gremlin.process.traversal.strategy.optimization.IncidentToAdjacentStrategy')]).V().out_e().in_v())], + 'g_withStrategiesXInlineFilterStrategyX_V_filterXhasXname_markoXX': [(lambda g:g.with_strategies(InlineFilterStrategy()).V().filter_(__.has('name', 'marko')))], + 'g_withoutStrategiesXInlineFilterStrategyX_V_filterXhasXname_markoXX': [(lambda g:g.without_strategies(*[GremlinType('org.apache.tinkerpop.gremlin.process.traversal.strategy.optimization.InlineFilterStrategy')]).V().filter_(__.has('name', 'marko')))], + 'g_withStrategiesXLambdaRestrictionStrategyX_V': [], # skipping as it contains a lambda + 'g_withoutStrategiesXLambdaRestrictionStrategyX_V': [], # skipping as it contains a lambda + 'g_withStrategiesXLazyBarrierStrategyX_V_out_bothE_count': [(lambda g:g.with_strategies(LazyBarrierStrategy()).V().out().both_e().count())], + 'g_withoutStrategiesXLazyBarrierStrategyX_V_out_bothE_count': [(lambda g:g.without_strategies(*[GremlinType('org.apache.tinkerpop.gremlin.process.traversal.strategy.optimization.LazyBarrierStrategy')]).V().out().both_e().count())], + 'g_withStrategiesXMatchAlgorithmStrategyXmatchAlgorithm_CountMatchAlgorithmXX_V_matchXa_knows_b__a_created_cX': [(lambda g:g.with_strategies(MatchAlgorithmStrategy(match_algorithm='org.apache.tinkerpop.gremlin.process.traversal.step.map.MatchStep$CountMatchAlgorithm')).V().match(__.as_('a').out('knows').as_('b'), __.as_('a').out('created').as_('c')))], + 'g_withStrategiesXMatchAlgorithmStrategyXmatchAlgorithm_GreedyMatchAlgorithmXX_V_matchXa_knows_b__a_created_cX': [(lambda g:g.with_strategies(MatchAlgorithmStrategy(match_algorithm='org.apache.tinkerpop.gremlin.process.traversal.step.map.MatchStep$GreedyMatchAlgorithm')).V().match(__.as_('a').out('knows').as_('b'), __.as_('a').out('created').as_('c')))], + 'g_withoutStrategiesXMatchAlgorithmStrategyX_V_matchXa_knows_b__a_created_cX': [(lambda g:g.without_strategies(*[GremlinType('org.apache.tinkerpop.gremlin.process.traversal.strategy.finalization.MatchAlgorithmStrategy')]).V().match(__.as_('a').out('knows').as_('b'), __.as_('a').out('created').as_('c')))], + 'g_withStrategiesXMatchPredicateStrategyX_V_matchXa_created_lop_b__b_0created_29_cX_whereXc_repeatXoutX_timesX2XX_selectXa_b_cX': [(lambda g:g.with_strategies(MatchPredicateStrategy()).V().match(__.as_('a').out('created').has('name', 'lop').as_('b'), __.as_('b').in_('created').has('age', 29).as_('c')).where(__.as_('c').repeat(__.out()).times(2)).select('a', 'b', 'c'))], + 'g_withoutStrategiesXMatchPredicateStrategyX_V_matchXa_created_lop_b__b_0created_29_cX_whereXc_repeatXoutX_timesX2XX_selectXa_b_cX': [(lambda g:g.without_strategies(*[GremlinType('org.apache.tinkerpop.gremlin.process.traversal.strategy.optimization.MatchPredicateStrategy')]).V().match(__.as_('a').out('created').has('name', 'lop').as_('b'), __.as_('b').in_('created').has('age', 29).as_('c')).where(__.as_('c').repeat(__.out()).times(2)).select('a', 'b', 'c'))], + 'g_withStrategiesXMessagePassingReductionStrategyX_V': [(lambda g:g.with_strategies(MessagePassingReductionStrategy()).V())], + 'g_withoutStrategiesXMessagePassingReductionStrategyX_V': [(lambda g:g.without_strategies(*[GremlinType('org.apache.tinkerpop.gremlin.process.computer.traversal.strategy.optimization.MessagePassingReductionStrategy')]).V())], 'g_withoutStrategiesXCountStrategyX_V_count': [(lambda g:g.without_strategies(*[GremlinType('org.apache.tinkerpop.gremlin.process.traversal.strategy.optimization.CountStrategy')]).V().count())], 'g_V_coworker': [(lambda g, xx1=None:g.V().has_label('person').filter_(__.out_e('created')).aggregate('p').as_('p1').values('name').as_('p1n').select('p').unfold().where(P.neq('p1')).as_('p2').values('name').as_('p2n').select('p2').out('created').choose(__.in_('created').where(P.eq('p1')), __.values('name'), __.constant(xx1)).group().by(__.select('p1n')).by(__.group().by(__.select('p2n')).by(__.unfold().fold().project('numCoCreated', 'coCreated').by(__.count(Scope.local)).by())).unfo [...] 'g_V_coworker_with_midV': [(lambda g:g.V().has_label('person').filter_(__.out_e('created')).as_('p1').V().has_label('person').where(P.neq('p1')).filter_(__.out_e('created')).as_('p2').map(__.out('created').where(__.in_('created').as_('p1')).values('name').fold()).group().by(__.select('p1').by('name')).by(__.group().by(__.select('p2').by('name')).by(__.project('numCoCreated', 'coCreated').by(__.count(Scope.local)).by())).unfold())], + 'g_withStrategiesXOptionsStrategyX_V': [(lambda g:g.with_strategies(OptionsStrategy()).V())], + 'g_withStrategiesXOptionsStrategyXmyVar_myValueXX_V': [(lambda g:g.with_strategies(OptionsStrategy(my_var='myValue')).V())], + 'g_withoutStrategiesXOptionsStrategyX_V': [(lambda g:g.without_strategies(*[GremlinType('org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.OptionsStrategy')]).V())], + 'g_withStrategiesXOrderLimitStrategyX_V': [(lambda g:g.with_strategies(OrderLimitStrategy()).V())], + 'g_withoutStrategiesXOrderLimitStrategyX_V': [(lambda g:g.without_strategies(*[GremlinType('org.apache.tinkerpop.gremlin.process.traversal.strategy.optimization.OrderLimitStrategy')]).V())], 'g_withStrategiesXPartitionStrategyXwrite_a_read_aXX_V_name': [(lambda g:g.add_v('person').property('_partition', 'a').property('name', 'alice').add_v('person').property('_partition', 'b').property('name', 'bob')), (lambda g:g.with_strategies(PartitionStrategy(partition_key='_partition', write_partition='a', read_partitions=['a'])).V().values('name'))], 'g_withStrategiesXPartitionStrategyXwrite_a_read_a_bXX_V_name': [(lambda g:g.add_v('person').property('_partition', 'a').property('name', 'alice').add_v('person').property('_partition', 'b').property('name', 'bob')), (lambda g:g.with_strategies(PartitionStrategy(partition_key='_partition', write_partition='a', read_partitions=['a', 'b'])).V().values('name'))], 'g_withStrategiesXPartitionStrategyXwrite_a_read_cXX_V_name': [(lambda g:g.add_v('person').property('_partition', 'a').property('name', 'alice').add_v('person').property('_partition', 'b').property('name', 'bob')), (lambda g:g.with_strategies(PartitionStrategy(partition_key='_partition', write_partition='a', read_partitions=['c'])).V().values('name'))], @@ -411,7 +460,15 @@ world.gremlins = { 'g_withStrategiesXPartitionStrategyXwrite_a_read_aXX_mergeVXlabel_person_name_aliceX_optionXonMatch_name_bobX': [(lambda g, xx1=None,xx2=None:g.add_v('person').property('_partition', 'a').property('name', 'alice').add_v('person').property('_partition', 'b').property('name', 'alice')), (lambda g, xx1=None,xx2=None:g.with_strategies(PartitionStrategy(partition_key='_partition', write_partition='a', read_partitions=['a'])).merge_v(xx1).option(Merge.on_match, xx2)), (lambda g, xx1=None,x [...] 'g_withStrategiesXPartitionStrategyXwrite_a_read_aXX_mergeV_optionXonCreateX': [(lambda g, xx1=None,xx2=None:g.add_v('person').property('_partition', 'b').property('name', 'alice')), (lambda g, xx1=None,xx2=None:g.with_strategies(PartitionStrategy(partition_key='_partition', write_partition='a', read_partitions=['a'])).merge_v(xx1).option(Merge.on_create, xx2)), (lambda g, xx1=None,xx2=None:g.V().has('name', 'alice').has('age', 35).has('_partition', 'a')), (lambda g, xx1=None,xx2=Non [...] 'g_withStrategiesXPartitionStrategyXwrite_a_read_aXX_injectX0X__mergeV_optionXonCreateX': [(lambda g, xx1=None,xx2=None:g.add_v('person').property('_partition', 'b').property('name', 'alice')), (lambda g, xx1=None,xx2=None:g.with_strategies(PartitionStrategy(partition_key='_partition', write_partition='a', read_partitions=['a'])).inject(0).merge_v(xx1).option(Merge.on_create, xx2)), (lambda g, xx1=None,xx2=None:g.V().has('name', 'alice').has('age', 35).has('_partition', 'a')), (lambd [...] + 'g_withStrategiesXPathProcessorStrategyX_V_asXaX_selectXaX_byXvaluesXnameXX': [(lambda g:g.with_strategies(PathProcessorStrategy()).V().as_('a').select('a').by(__.values('name')))], + 'g_withoutStrategiesXPathProcessorStrategyX_V_asXaX_selectXaX_byXvaluesXnameXX': [(lambda g:g.without_strategies(*[GremlinType('org.apache.tinkerpop.gremlin.process.traversal.strategy.optimization.PathProcessorStrategy')]).V().as_('a').select('a').by(__.values('name')))], + 'g_withStrategiesXPathRetractionStrategyX_V': [(lambda g:g.with_strategies(PathRetractionStrategy()).V())], + 'g_withoutStrategiesXPathRetractionStrategyX_V': [(lambda g:g.without_strategies(*[GremlinType('org.apache.tinkerpop.gremlin.process.traversal.strategy.optimization.PathRetractionStrategy')]).V())], 'g_V_shortestpath': [(lambda g:g.V().as_('v').both().as_('v').project('src', 'tgt', 'p').by(__.select(Pop.first, 'v')).by(__.select(Pop.last, 'v')).by(__.select(Pop.all_, 'v')).as_('triple').group('x').by(__.select('src', 'tgt')).by(__.select('p').fold()).select('tgt').barrier().repeat(__.both().as_('v').project('src', 'tgt', 'p').by(__.select(Pop.first, 'v')).by(__.select(Pop.last, 'v')).by(__.select(Pop.all_, 'v')).as_('t').filter_(__.select(Pop.all_, 'p').count(Scope.local).as_('l [...] + 'g_withStrategiesXProductiveByStrategyX_V_group_byXageX_byXnameX': [(lambda g:g.with_strategies(ProductiveByStrategy()).V().order().by('name').group().by('age').by('name'))], + 'g_withoutStrategiesXProductiveByStrategyX_V_group_byXageX_byXnameX': [(lambda g:g.without_strategies(*[GremlinType('org.apache.tinkerpop.gremlin.process.traversal.strategy.optimization.ProductiveByStrategy')]).V().group().by('age').by('name'))], + 'g_withStrategiesXProfileStrategyX_V': [(lambda g:g.with_strategies(ProfileStrategy()).V())], + 'g_withoutStrategiesXProfileStrategyX_V': [(lambda g:g.without_strategies(*[GremlinType('org.apache.tinkerpop.gremlin.process.traversal.strategy.finalization.ProfileStrategy')]).V())], 'g_withStrategiesXReadOnlyStrategyX_V': [(lambda g:g.with_strategies(ReadOnlyStrategy()).V())], 'g_withStrategiesXReadOnlyStrategyX_V_outXknowsX_name': [(lambda g:g.with_strategies(ReadOnlyStrategy()).V().out('knows').values('name'))], 'g_withStrategiesXReadOnlyStrategyX_addVXpersonX': [(lambda g:g.with_strategies(ReadOnlyStrategy()).add_v('person'))], @@ -420,6 +477,17 @@ world.gremlins = { 'g_withStrategiesXReadOnlyStrategyX_V_propertyXname_joshX': [(lambda g:g.with_strategies(ReadOnlyStrategy()).V().property('name', 'josh'))], 'g_withStrategiesXReadOnlyStrategyX_E_propertyXweight_0X': [(lambda g:g.with_strategies(ReadOnlyStrategy()).E().property('weight', 0))], 'g_V_classic_recommendation': [(lambda g:g.V().has('name', 'DARK STAR').as_('a').out('followedBy').aggregate('stash').in_('followedBy').where(P.neq('a').and_(P.not_(P.within('stash')))).group_count().unfold().project('x', 'y', 'z').by(__.select(Column.keys).values('name')).by(__.select(Column.keys).values('performances')).by(__.select(Column.values)).order().by(__.select('z'), Order.desc).by(__.select('y'), Order.asc).limit(5).aggregate(Scope.local, 'm').select('x'))], + 'g_withStrategiesXReferenceElementStrategyX_V': [(lambda g:g.with_strategies(ReferenceElementStrategy()).V())], + 'g_withoutStrategiesXReferenceElementStrategyX_V': [(lambda g:g.without_strategies(*[GremlinType('org.apache.tinkerpop.gremlin.process.traversal.strategy.finalization.ReferenceElementStrategy')]).V())], + 'g_withStrategiesXRepeatUnrollStrategyX_V_repeatXoutX_timesX2X': [(lambda g:g.with_strategies(RepeatUnrollStrategy()).V().repeat(__.out()).times(2))], + 'g_withoutStrategiesXRepeatUnrollStrategyX_V_repeatXoutX_timesX2X': [(lambda g:g.without_strategies(*[GremlinType('org.apache.tinkerpop.gremlin.process.traversal.strategy.optimization.RepeatUnrollStrategy')]).V().repeat(__.out()).times(2))], + 'g_withStrategiesXReservedKeysVerificationStrategyXthrowException_trueXX_addVXpersonX_propertyXid_123X_propertyXname_markoX': [(lambda g:g.with_strategies(ReservedKeysVerificationStrategy(throw_exception=True)).add_v('person').property('id', 123).property('name', 'marko'))], + 'g_withStrategiesXReservedKeysVerificationStrategyXthrowException_trueXX_addVXpersonX_propertyXage_29X_propertyXname_markoX': [(lambda g:g.with_strategies(ReservedKeysVerificationStrategy(throw_exception=True, keys=['age'])).add_v('person').property('age', 29).property('name', 'marko'))], + 'g_withoutStrategiesXReservedKeysVerificationStrategyX_addVXpersonX_propertyXid_123X_propertyXname_markoX': [(lambda g:g.without_strategies(*[GremlinType('org.apache.tinkerpop.gremlin.process.traversal.strategy.verification.ReservedKeysVerificationStrategy')]).add_v('person').property('id', 123).property('name', 'marko'))], + 'g_withStrategiesXSeedStrategyX_V': [(lambda g:g.with_strategies(SeedStrategy(seed=7)).V().coin(0.5))], + 'g_withoutStrategiesXSeedStrategyX_V': [(lambda g:g.without_strategies(*[GremlinType('org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.SeedStrategy')]).V())], + 'g_withStrategiesXStandardVerificationStrategyX_V': [(lambda g:g.with_strategies(StandardVerificationStrategy()).V())], + 'g_withoutStrategiesXStandardVerificationStrategyX_V': [(lambda g:g.without_strategies(*[GremlinType('org.apache.tinkerpop.gremlin.process.traversal.strategy.verification.StandardVerificationStrategy')]).V())], 'g_withStrategiesXSubgraphStrategyXsubgraphAXX_V': [(lambda g:g.with_strategies(SubgraphStrategy(vertices=__.has('name', P.within('josh', 'lop', 'ripple')))).V())], 'g_withStrategiesXSubgraphStrategyXsubgraphAXX_E': [(lambda g:g.with_strategies(SubgraphStrategy(vertices=__.has('name', P.within('josh', 'lop', 'ripple')))).E())], 'g_withStrategiesXSubgraphStrategyXsubgraphAXX_VX4X_outE': [(lambda g, vid4=None:g.with_strategies(SubgraphStrategy(vertices=__.has('name', P.within('josh', 'lop', 'ripple')))).V(vid4).out_e())], @@ -481,6 +549,11 @@ world.gremlins = { 'g_withStrategiesXSubgraphStrategyXsubgraphDXX_EX12X_bothV': [(lambda g, eid12=None:g.with_strategies(SubgraphStrategy(check_adjacent_vertices=False, vertices=__.has('name', P.within('josh', 'lop', 'ripple')), edges=__.or_(__.has('weight', 0.4).has_label('created'), __.has('weight', 1.0).has_label('created')))).E(eid12).both_v())], 'g_withStrategiesXSubgraphStrategyXsubgraphDXX_EX9X_bothV': [(lambda g, eid9=None:g.with_strategies(SubgraphStrategy(check_adjacent_vertices=False, vertices=__.has('name', P.within('josh', 'lop', 'ripple')), edges=__.or_(__.has('weight', 0.4).has_label('created'), __.has('weight', 1.0).has_label('created')))).E(eid9).both_v())], 'g_withStrategiesXSubgraphStrategyXcheckAdjacentVertices_subgraphDXX_EX9X_bothV': [(lambda g, eid9=None:g.with_strategies(SubgraphStrategy(check_adjacent_vertices=True, vertices=__.has('name', P.within('josh', 'lop', 'ripple')), edges=__.or_(__.has('weight', 0.4).has_label('created'), __.has('weight', 1.0).has_label('created')))).E(eid9).both_v())], + 'g_withStrategiesXVertexProgramRestrictionStrategyX_withoutStrategiesXVertexProgramStrategyX_V': [(lambda g:g.with_strategies(VertexProgramRestrictionStrategy()).without_strategies(*[GremlinType('org.apache.tinkerpop.gremlin.process.computer.traversal.strategy.decoration.VertexProgramStrategy')]).V())], + 'g_withStrategiesXVertexProgramRestrictionStrategy_VertexProgramStrategyX_V': [(lambda g:g.with_strategies(VertexProgramRestrictionStrategy(), VertexProgramStrategy()).V())], + 'g_withoutStrategiesXVertexProgramRestrictionStrategyX_V': [(lambda g:g.without_strategies(*[GremlinType('org.apache.tinkerpop.gremlin.process.computer.traversal.strategy.verification.VertexProgramRestrictionStrategy')]).with_strategies(VertexProgramStrategy()).V())], + 'g_withStrategiesXVertexProgramStrategyX_V': [(lambda g:g.with_strategies(VertexProgramStrategy()).V())], + 'g_withoutStrategiesXVertexProgramStrategyX_V': [(lambda g:g.without_strategies(*[GremlinType('org.apache.tinkerpop.gremlin.process.computer.traversal.strategy.decoration.VertexProgramStrategy')]).V())], 'g_VX1X_asXaX_outXcreatedX_addEXcreatedByX_toXaX': [(lambda g, vid1=None:g.add_v('person').property('name', 'marko').property('age', 29).as_('marko').add_v('person').property('name', 'vadas').property('age', 27).as_('vadas').add_v('software').property('name', 'lop').property('lang', 'java').as_('lop').add_v('person').property('name', 'josh').property('age', 32).as_('josh').add_v('software').property('name', 'ripple').property('lang', 'java').as_('ripple').add_v('person').property('na [...] 'g_VX1X_asXaX_outXcreatedX_addEXcreatedByX_toXaX_propertyXweight_2X': [(lambda g, vid1=None:g.add_v('person').property('name', 'marko').property('age', 29).as_('marko').add_v('person').property('name', 'vadas').property('age', 27).as_('vadas').add_v('software').property('name', 'lop').property('lang', 'java').as_('lop').add_v('person').property('name', 'josh').property('age', 32).as_('josh').add_v('software').property('name', 'ripple').property('lang', 'java').as_('ripple').add_v('pe [...] 'g_V_outE_propertyXweight_nullX': [(lambda g:g.add_v('person').property('name', 'marko').property('age', 29).as_('marko').add_v('person').property('name', 'vadas').property('age', 27).as_('vadas').add_v('software').property('name', 'lop').property('lang', 'java').as_('lop').add_v('person').property('name', 'josh').property('age', 32).as_('josh').add_v('software').property('name', 'ripple').property('lang', 'java').as_('ripple').add_v('person').property('name', 'peter').property('age' [...] diff --git a/gremlin-python/src/main/python/tests/driver/test_client.py b/gremlin-python/src/main/python/tests/driver/test_client.py index 74f07f51f6..01fdd95916 100644 --- a/gremlin-python/src/main/python/tests/driver/test_client.py +++ b/gremlin-python/src/main/python/tests/driver/test_client.py @@ -237,7 +237,7 @@ def test_client_gremlin_lang_options(client): # smoke test to validate serialization of OptionsStrategy. no way to really validate this from an integration # test perspective because there's no way to access the internals of the strategy via bytecode g = GraphTraversalSource(Graph(), TraversalStrategies()) - t = g.with_strategies(OptionsStrategy(options={"x": "test", "y": True})).V() + t = g.with_strategies(OptionsStrategy(**{"x": "test", "y": True})).V() message = create_basic_request_message(t) result_set = client.submit(message) assert len(result_set.all().result()) == 6 diff --git a/gremlin-python/src/main/python/tests/process/test_gremlin_lang.py b/gremlin-python/src/main/python/tests/process/test_gremlin_lang.py index 0457bfe00c..f6126d2008 100644 --- a/gremlin-python/src/main/python/tests/process/test_gremlin_lang.py +++ b/gremlin-python/src/main/python/tests/process/test_gremlin_lang.py @@ -367,7 +367,7 @@ class TestGremlinLang(object): "g.V().count()"]) # 96 Note OptionsStrategy are now extracted into request message and is no longer sent with the script - tests.append([g.with_strategies(OptionsStrategy({'evaluationTimeout': 500})).V().count(), + tests.append([g.with_strategies(OptionsStrategy(evaluationTimeout=500)).V().count(), "g.V().count()"]) # 97 diff --git a/gremlin-python/src/main/python/tests/process/test_strategies.py b/gremlin-python/src/main/python/tests/process/test_strategies.py index b6fd0e3015..81f428dd14 100644 --- a/gremlin-python/src/main/python/tests/process/test_strategies.py +++ b/gremlin-python/src/main/python/tests/process/test_strategies.py @@ -89,7 +89,7 @@ class TestTraversalStrategies(object): assert "SubgraphStrategy" in str(gremlin_script) assert "__.has('name','marko')" in str(gremlin_script) ### - gremlin_script = g.with_strategies(OptionsStrategy(options={"x": "test", "y": True})).gremlin_lang + gremlin_script = g.with_strategies(OptionsStrategy(x="test", y=True)).gremlin_lang options = gremlin_script.options_strategies assert "test" == options[0].configuration["x"] assert options[0].configuration["y"]
