[ 
https://issues.apache.org/jira/browse/TINKERPOP-2603?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17402155#comment-17402155
 ] 

Stephen Mallette commented on TINKERPOP-2603:
---------------------------------------------

It's a bit confusing perhaps because numbers are strange in Java and perhaps a 
bit stranger in the Gremlin Console. TinkerGraph also let's you store any Java 
object so if you are not specific with your types you may end up with something 
that doesn't make sense. First note that the Gremlin Console (i.e. the Groovy 
Console) takes an unhinted number and does this to it:

{code}
gremlin> 0.65780294.class
==>class java.math.BigDecimal
{code}

so really you aren't storing float or double in TinkerGraph but a 
{{BigDecimal}}:

{code}
gremlin> g = TinkerGraph.open().traversal()
==>graphtraversalsource[tinkergraph[vertices:0 edges:0], standard]
gremlin> g.addV().property('vp2',0.65780294)
==>v[0]
gremlin> g.addV().property('vp2',0.65780294f)
==>v[2]
gremlin> g.addV().property('vp2',0.65780294d)
==>v[4]
gremlin> g.V().has('vp2',0.65780294)
==>v[0]
==>v[4]
gremlin> g.V().has('vp2',0.65780294f)
==>v[2]
gremlin> g.V().has('vp2',0.65780294d)
==>v[0]
==>v[4]
gremlin> g.V().has('vp2',0.65780294).values('vp2').map{it.get().class}
==>class java.math.BigDecimal
==>class java.lang.Double
gremlin> g.V().has('vp2',0.65780294f).values('vp2').map{it.get().class}
==>class java.lang.Float
gremlin> g.V().has('vp2',0.65780294d).values('vp2').map{it.get().class}
==>class java.math.BigDecimal
==>class java.lang.Double
gremlin> 0.65780294.class
==>class java.math.BigDecimal
{code}

Then when you consider basic equality for those with Java:

{code}
gremlin> 0.65780294d == 0.65780294f
==>false
gremlin> 0.65780294d == 0.65780294
==>true
gremlin> 0.65780294f == 0.65780294
==>false
{code}

Unlike JanusGraph/Neo4j, TinkerGraph does not do any type coercion with the 
property values you give it. That does have some advantages but it does force 
you to be specific about your types when you use it. 

> TinkerGraph sometimes could not query float values. 
> ----------------------------------------------------
>
>                 Key: TINKERPOP-2603
>                 URL: https://issues.apache.org/jira/browse/TINKERPOP-2603
>             Project: TinkerPop
>          Issue Type: Bug
>          Components: tinkergraph
>    Affects Versions: 3.4.10
>         Environment: OS: CentOS 8 
> Tinkerpop 3.4.10
>            Reporter: Zheng Qin
>            Priority: Major
>         Attachments: Result.jpg, TinkerGraph-queryfloat.md
>
>
> h1. TinkerGraph sometimes could not query float values.
> h3. Environment
> Version: 3.4.10
> OS : CentOS8
> Storage Backend: in-memory 
> h3. Bug description
> TinkerGraph sometimes could not query float values.  To be detailed, when 
> create a new TinkerGraph database in memory. We could insert a float value 
> but not query it.
> h3. Current behavior
> {quote}gremlin > g.addV().property('vp2',0.65780294)
> ==>v[1011]
> gremlin > g.V().has('vp2',0.65780294){quote}
> The second query returns with nothing. However, after several times or query 
> it with 0.65780294f, it would return v[1011]. It means that TinkerGraph 
> sometimes could not query float values which is abnormal.
> h3. Expected behavior
> When enter the same code in neo4j-gremlin or janusgraph, it would return 
> normal result like:
> {quote}gremlin > g.V().has('vp2',0.65780294)
> ==>v[3192]{quote}
> h3. Reproduce
> {quote}        GraphTraversalSource g = connection.getG();
>         g.E().drop().iterate();
>         g.V().drop().iterate();
>         try {
>             String tuery = "g.addV().property('vp2',0.65780294)";
>             connection.getClient().submit(tuery);
>             String query = "g.V().has('vp2',0.65780294) ";
>             System.out.println("query: " + query);
>             try{
>                 List<Result> results;
>                 results = connection.getClient().submit(query).all().get();
>                 for (Result r : results) {
>                     System.out.println(r);
>                 }
>                 }
> }{quote}
> Or
> {quote}gremlin > g.addV().property('vp2',0.65780294)
> gremlin > g.V().has('vp2',0.65780294) {quote}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to