How do you use the sideEffect() method in the Gremlin npm package - gremlin

I've tried various ways of calling sideEffect(), but none have worked, I can't find any documentation or examples online, and the source code is a bit too abstract for me to understand without spending considerably longer looking at it.
As an example:
const y = await g.V().hasId('a4b64522-9cda-1b34-8f76-634242933a0d').sideEffect('drop()').next();
Results in
Error: Server error: {"requestId":"8915089a-cde3-4861-b73a-2534cefbc0b2","code":"InternalFailureException","detailedMessage":"Could not locate method: NeptuneGraphTraversal.sideEffect([drop()])"} (599)
I'm running these traversals against AWS Neptune in case that matters (although running similar queries through Python and the Gremlin Console against Neptune work).

The sideEffect() step takes an anonymous traversal so the syntax I provided in your previous question should work equally well in every Gremlin Language Variant including javascript:
g.V().hasId('a4b64522-9cda-1b34-8f76-634242933a0d').sideEffect(drop())
drop() is of course spawned from __ and should be part of your standard imports and can be called more explicitly as:
const __ = gremlin.process.statics;
g.V().hasId('a4b64522-9cda-1b34-8f76-634242933a0d').sideEffect(__.drop())
The error you describe in your question is simply related to your usage where you pass drop() as a string value. That said, I suppose it's possible that neptune doesn't support sideEffect() as a step at all?? You could test it with a more simple traversal with legitimate syntax and see if you get the same error:
g.V().hasId('a4b64522-9cda-1b34-8f76-634242933a0d').sideEffect(__.constant(1))
If that traversal returns a Vertex with the specified id you were querying for and you don't see an error then I would think sideEffect() as being a supported step. Perhaps someone with more Neptune experience will be able to offer a more official answer for you.

Related

gremlin shortestPath() with step

where is the document about gremlin with step?
https://tinkerpop.apache.org/docs/current/reference/#with-step
https://tinkerpop.apache.org/javadocs/current/full/org/apache/tinkerpop/gremlin/process/computer/traversal/step/map/ShortestPath.html
there is no example I can use.
I want to know all with-step option(like ShortestPath.edges-Direction.OUT) for shortestPath().
I found below
g.withComputer().V(xxx).shortestPath().with(ShortestPath.edges, Direction.OUT).with(ShortestPath.distance, 'cost').with(ShortestPath.target, hasId(bbb))
I want to know all option I can use
The with()-step is not really a "step". It is a step modulator. Its context is bound to the step that it is modifying and therefore you won't find "all the with() configurations" in one place. You can only find them in the documentation related to the steps that they modulate. Using shortestPath() as an example, note that if you look at the shortestPath() step documentation all of the options are present.
You may also need to consult the documentation of your graph provider as they may provide their own configuration keys for certain steps which can help optimize or otherwise modify traversal operations.

Gremlin.NET Query Compilation Error: Unable to find any method 'hasNext'

The line: g.V('1').out('knows').hasId('2').hasNext()
This exact line works in the Gremlin console.
I have not read in the documentation that hasNext does not exist in Gremlin.NET. Am I missing something, or is there simply another way to do this in Gremlin.NET?
This method is really missing in Gremlin.Net right now. While this is not explicitly stated in the documentation, the documentation does list all terminal steps implemented by Gremlin.Net:
ITraversal.Next()
ITraversal.NextTraverser()
ITraversal.ToList()
ITraversal.ToSet()
ITraversal.Iterate()
hasNext is also such a terminal step but as you can see it is missing in this list.
The only workaround I can think of for situations like this is to use the count step and then check in your application whether the returned count is greater than zero:
var count = g.V("1").Out("knows").HasId("2").Count().Next();
var exists = count > 0;
In some cases it could also make sense to limit the number of vertices going into the Count step as you aren't interested in the exact count but only want to know whether at least one vertex exists:
g.V("1").Out("knows").HasId("2").Limit<Vertex>(1).Count().Next();
This is also the proposed workaround in the ticket for this feature: TINKERPOP-1921.
It does not exist yet:
https://issues.apache.org/jira/browse/TINKERPOP-1921
The main reason is related to the fact that hasNext() is a Java Iterator semantic that was not applied to .NET. Gremlin Language Variants (GLVs) like .NET are given some latitude in terms of how they interpret the language so as to provide the most at-home feel for developers using it. In other words, if you are using the .NET GLV you shouldn't feel as though you are coding in Java, but should instead feel write at home with the standard .NET semantics.
That said, it could be argued, as it is in the issue I've referenced above, that something like hasNext() is a common form of Gremlin as a query language and should thus be available in all GLVs. So, we will consider those options as we come across them.
For .NET I guess you would try to check Current as discussed here.

Error using Pyfhel

I am trying to use Pyfhel library to perform some operations on encrypted integer list. I am doing one multiplication operation and later performing an addition operation. But while performing addition operation, I randomly get following error:
IndexError('Unable to find key in unordered_map.’,)
If I try to decrypt that encrypted value on which I try to perform addition operation, I am getting the same error.
Can anyone please let me know what could be the problem?
Thanks!
(Couldn't add the related tags but it's around Homomorphic Encryption using Pyfhel library, Python implementation of HElib)
All I can tell you so far is that this error is originated by a search in the unordered map that contains all the cyphertexts. This unordered map is inside the Pyfhel object, accessed via a C++ call. As usual, it shouldn't be happenning. Right now, efforts are being put into upgrading Pyfhel so that you can hold each cyphertext in a single Python object, thus rendering your current error obsolete.

What is the use of double underscore in repeat() or other steps in Tinkerpop Gremlin?

I have noticed double underscore being used in some step functions in Tinkerpop Gremlin 3.3. Could someone please tell why we use this double underscore with an example ? I could not find enough information about this in the documentation.
__. allows you to define an anonymous Traversal, ie. a Traversal which is not bound to a specific TraversalSource.
In the Gremlin console, all Gremlin steps are statically imported so you never need to prefix anonymous traversals with __. unless that anonymous traversal starts with a reserved keyword in the target language. In Groovy, which is the default Gremlin flavor, this is the case with in() and as() steps: because these are reserved keywords, these two steps must be prefixed with __.
In Java, you can avoid __. prefix by statically importing all steps in your program:
import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__
See the small Note section in the documentation: http://tinkerpop.apache.org/docs/3.3.0/reference/#graph-traversal-steps
__ is used to refer to the incoming traversal (vertex or edge) in Java API. For example: in gremlin shell, one can write something like this
graph.traversal().V().repeat(out("edgeType")).until(hasLabel("label")).toList()
But in java one needs an anonymous traversal to call the functions "out" and "hasLabel" within repeat and until (or any other function like by, choose etc.). The above traversal in Java will look like:
graph.traversal().V().repeat(__.out("edgeType")).until(__.hasLabel("label")).toList()

Is there a way to validate the syntax of a Salesforce.com's SOQL query without executing it?

I'm writing an API that converts actions performed by a non-technical user into Salesforce.com SOQL 'SELECT', 'UPSERT', and 'DELETE' statements. Is there any resource, library, etc. out there that could validate the syntax of the generated SOQL? I'm the only one at my company with any experience with SOQL, so I'd love to place it into a set of automated tests so that other developers enhancing (or fixing) the SOQL generation algorithm know if it's still functioning properly.
I know one solution here is to just make these integration tests. However, I'd rather avoid that for three reasons:
I'd need to maintain another Salesforce.com account just for tests so we don't go over our API request cap.
We'll end up chasing false positives whenever there are connectivity issues with Salesforce.com.
Those other developers without experience will potentially need to figure out how to clean up the test Salesforce.com instance after DML operation test failures (which really means I'll need to clean up the instance whenever this occurs).
You might solve your problem by using the SoqlBuilder library. It generates SOQL for you and is capable of producing SOQL statements that would be quite error prone to create manually. The syntax is straight forward and I've used it extensively with very few issues.
I found another way to do this.
Salesforce.com posted their SOQL notation in Backus-Noir Form (BNF) here:
http://www.salesforce.com/us/developer/docs/api90/Content/sforce_api_calls_soql_bnf_notation.htm
This means you can use a BNF-aware language recognition tool to parse the SOQL. One of the most common tools, ANTLR, does this and is free. Following the ANTLR example, pass the SOQL grammar into its grammar compiler to get a Lexer and a Parser in your desired language (C#, Java, Python, etc.). Then you can pass the actual SOQL statements you want to validate into the Lexer, and then your Lexer tokens into your Parser, to break apart the SOQL statements. If your Lexer or Parser fails, you have invalid SOQL.
I can't think of a way to do this from outside of Salesforce (and even in Apex I've only got one idea right now that may not work), but I can think of two suggestions that may be of help:
Validate queries by running them, but do them in batches using a custom web service. i.e. write a web service in Apex that can accept up to 100 query strings at once, have it run them and return the results. This would drastically reduce the number of API calls but of course it won't work if you're expecting a trial-and-error type setup in the UI.
Use the metadata API to pull down information on all objects and their fields, and use those to validate that at least the fields in the query are correct. Validating other query syntax should be relatively straight forward, though conditionals may get a little tricky.
You can make use of the salesforce develop nuget packages that leverages SOAP API

Resources