How can I find property with a certain data type?

I have a situation where the same property has different type under the same label, kind of like the following: g.addV("Cookies").property(single, "howMany", "10").next() g.addV("Cookies").property(single, "howMany", 42).next() I am hoping to query for Cookies that only has "howMany" property that is in String, for example. We accidentally corrupted our DB with mixed types and need to find which ones are corrupted. What I am hoping to see is something like. g.V().hasLabel("Cookies").proporties("howMany").ofType(String)
Solution:
Which Graph Database are you using @ManabuBeach ? Currently Gremlin does not have any easy way to test the type of a property value built in to the language. It is something we have discussed adding in a future update. Unless the graph database backend you are using allows for lambdas/closures, you may have to do this mostly in the application.
Jump to solution
3 Replies
Solution
kelvinl2816
kelvinl28162y ago
Which Graph Database are you using @ManabuBeach ? Currently Gremlin does not have any easy way to test the type of a property value built in to the language. It is something we have discussed adding in a future update. Unless the graph database backend you are using allows for lambdas/closures, you may have to do this mostly in the application.
ManabuBeach
ManabuBeachOP2y ago
@KelvinL I would be very happy if AWS Neptune supports it. For that the solution does not have to be Gremlin, can be SPARQL just to do this. We have impedance mismatches from the JavaScript developer world who tend to care less about Types vs the Scala world, where the rules are lot stricter as for types. That's how this corruption happened. Definitely a good set of functions to have in the future Gremlin. I was able to manually query against Long and String values, so my issues are fixed right now.
kelvinl2816
kelvinl28162y ago
As Neptune supports both Gremlin and openCypher (OC) over the same data, this is a case where you could use an OC query to detect these cases. You would need a query along these lines:
MATCH (a:airport {code:'LAX'})
WHERE toInt(a.runways) = a.runways
RETURN a
MATCH (a:airport {code:'LAX'})
WHERE toInt(a.runways) = a.runways
RETURN a
You could conversely use toString as well. This will only return a value if the converted value and the actual value are of the same type.
Want results from more Discord servers?
Add your server