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.
Related
I have a requirement to perform different operations if string contains any special character.
Is there any way to implement regular expression in gremlin.
Input_Name= Test#input
if Input_Name.contains( "#/$%...")
{
println " error "
}
else
{
println "sucess"
}
Currently the Gremlin language does not have a TextP.regex predicate. Some implementations, such as JanusGraph, do add custom regex extensions to Gremlin. You could also, if the database you are using allows it, use Groovy closure syntax to include a regex in a query. Within the TinkerPop community we are planning to add a TextP.regex to the Gremlin language. The code is written and on a branch that we hope will be part of the TinkerPop 3.6.0 release if all goes well.
However, in your case, perhaps the existing TextP.containing could be used if there are a finite set of special characters you are looking for but it is likely not the most optimal way to solve the problem as you will have to or several has steps together.
Another option might be to use an external index if your database implementation supports that.
Just as an example of the closure syntax, if your implementation allows it, a REGEX match would look like the example below. In general though, use of closures is not recommended, and many implementations either fully block or extremely limit their use.
gremlin> g.V().limit(20).filter {it.get().values('desc').next() ==~ "[A-Za-z]* [A-Z]'(.*)"}.values('desc')
==>Chicago O'Hare International Airport
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.
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.
I'm using Protobuf 3 along with gRPC in distributed environment ("microservices").
Due to lack of supporting not-set/missing values in Protobuf 3 I got the following issue related to contract additivity.
Imagine I have Service A and couple of consumer services B and C owned by Team B and Team C.
If I add a field, say, boolean value to contract of Service A, at the first it will have default value which will be written, say, to database as is.
Then, Team B updates their service to talk using updated contract and passes 'true' as the field value.
Then, Team C still uses old contract and calls the same service - value gets replaced to false. But Team C didn't mean it, moreover they weren't aware about that field at all.
Thus, Service A cannot extend contract at all because consumers that didn't get updated for various reasons yet are able to harm data and the Service A can do nothing about it.
In Thrift such things are done just by single check (.isSet()).
There are dirty workarounds like wrapping primitives into objects but it forces to use library-implementation-specific checks-by-reference (at least in java) which seems to be rather poor hack than robust solution. Also, eventually, I have to wrap everything in wrappers, which as you imagine is not great solution as well.
What are best practices you use to manage such situations in Protobuf 3 in 2017? How do you manage/coordinate contract updates between teams/services? Thanks
Note: this question is not exactly about how to implement absence of detection for not-set/missing values, but rather about how to live with that and follow Protobuf 3 philosophy.
I think the problem here is that trying to check for field presence this way is not really an idiomatic use of protocol buffers (not even in proto2). It sounds like you are trying to evolve your schema by adding new fields but not reading those new fields unless you're sure they came from an updated client. The idiomatic way is to do this instead: just make sure the defaults for the new fields are reasonable and maintain compatible behavior if they're not explicitly set. Then don't try to check for presence--just read the fields and older clients will get good default behavior.
To give you an example, let's say you're adding a new feature that can be enabled or disabled. The right way to do this would be to add a bool field in your request message called enable_new_feature. Since older clients don't know about this field, their requests will have this default to false and so they get the old behavior they're expecting. Adding a disable_new_feature field instead would probably be the wrong way to do it because then you would indeed break older clients by enabling something they didn't want.
Using oneof looks like a better/cleaner alternative to wrappers. See this answer to a similar question: https://stackoverflow.com/a/40552570/618259
It appears that SQLite, apparently as a "compatibility feature", parses double quoted identifiers as string literals if no matching column is found.
I understand that it does so for people who write improper sql, and for backwards compatibility with legacy projects created by such people, but it makes debugging very difficult for those of us writing proper sql on brand new projects.
For example,
SELECT * FROM "users" WHERE "usernme" = 'joe';
returns a query with 0 rows, since the string 'usernme' does not equal the string 'joe'.
This leaves me scratching my head wondering why i'm not getting joe's row even when i know there's a user by that name until I painstakingly backtrack my code and realize that I left out an a.
Is there any "strict mode" PRAGMA or API option to enforce quoting rules and treat all double-quoted strings as identifiers so that it will inform me immediately if one is misspelled?
(And please, no answers telling me not to quote identifiers if I don't need to, because any such answer is basically telling me that in order to get proper debugging, you have to write bad code in the first place.)
This is hardcoded in the SQLite parser and cannot be changed from the outside.
I also asked in the SQLite channel and someone there was kind enough to look through the source code and create a patch, and even started a thread on the mailing list describing the patch:
http://www.mail-archive.com/sqlite-users#sqlite.org/msg73832.html
It's not an answer that works for the official builds, but it may be someday. For the moment, I'm just going to recompile it myself with this patch.
Ten years later, and this doesn't completely meet your criteria about "strict mode" kinds of things, but here's a trick I used to make some queries safer, if you can remember to use it. It's to give your table an alias and reference it:
SELECT t."nosuch_column" FROM some_table t;
I suppose in this form, it's clear to SQLite that a literal isn't desired.