bitflicker64 commented on code in PR #561: URL: https://github.com/apache/hugegraph-doc/pull/561#discussion_r4491551176
########## content/en/docs/language/hugegraph-gremlin.md: ########## @@ -138,3 +138,29 @@ please refer to the [Apache TinkerPop 3.8.1 official documentation](https://tink | `V` | Traversal steps between vertices and edges: `V`, `E`, `out`, `in`, `both`, `outE`, `inE`, `bothE`, `outV`, `inV`, `bothV`, and `otherV` | [vertex steps](https://tinkerpop.apache.org/docs/3.8.1/reference/#vertex-steps) | | `where` | Filters traversal results. Supports `eq`, `neq`, `lt`, `lte`, `gt`, `gte`, and `between` operators. | [where step](https://tinkerpop.apache.org/docs/3.8.1/reference/#where-step) | {.wide .expand} + + +### Numeric Literal Type Matching in Gremlin-Groovy Predicates + +When evaluating property predicates via Gremlin-Groovy (HTTP `/gremlin` endpoint, HugeGraph-Console, or HugeGraph-Hubble), Groovy parses **unsuffixed decimal literals** (such as `1.0` or `1.5`) as `java.math.BigDecimal` rather than `java.lang.Double` or `java.lang.Float`. + +- **Comparison predicates (`P.eq`, `P.neq`, `P.lt`, `P.lte`, `P.gt`, `P.gte`, `P.between`):** TinkerPop's `Compare` predicate performs value-based numeric promotion across `Number` subclasses (`BigDecimal`, `Double`, `Float`, `Long`, `Integer`). +- **Collection membership predicates (`P.within`, `P.without`):** `Contains.within` and `Contains.without` evaluate collection membership using Java object equality (`Collection.contains(value)`), where `BigDecimal.valueOf(1.0).equals(Double.valueOf(1.0d))` is `false` because the runtime classes differ. Review Comment: Important: TinkerPop's `Contains.within` compares numbers with `Compare.eq` in both 3.5.1 and 3.8.1, so it matches `1.0` against a stored `1.0d`; the class-sensitive match comes from HugeGraph, where `TraversalUtil.convIn2Relation` skips `validPropertyValue` and `Condition.RelationType.IN` uses `Collection.contains`. Attribute the behaviour to HugeGraph's query condition: ```suggestion - **Collection membership predicates (`P.within`, `P.without`):** HugeGraph passes the listed values to its `IN` / `NOT_IN` query condition without converting them to the `PropertyKey` data type and matches them with Java object equality (`Collection.contains(value)`). `BigDecimal.valueOf(1.0).equals(Double.valueOf(1.0d))` is `false` because the runtime classes differ. ``` ########## content/cn/docs/language/hugegraph-gremlin.md: ########## @@ -134,3 +134,29 @@ HugeGraph 支持 Gremlin 遍历规范定义的各项步骤。完整说明与高 | `V` | 顶点检索与端点跳转基础步骤:`V`、`E`、`out`、`in`、`both`、`outE`、`inE` 等 | [vertex steps](https://tinkerpop.apache.org/docs/3.8.1/reference/#vertex-steps) | | `where` | 使用表达式或谓词(`eq`、`neq`、`gt` 等)进行条件筛选过滤 | [where step](https://tinkerpop.apache.org/docs/3.8.1/reference/#where-step) | {.wide .expand} + + +### Gremlin-Groovy 数值字面量类型与属性谓词匹配规则 + +在通过 Gremlin-Groovy(如 HTTP `/gremlin` 接口、HugeGraph-Console 或 HugeGraph-Hubble)执行属性过滤时,Groovy 默认将**不带类型后缀的小数字面量**(例如 `1.0` 或 `1.5`)解析为 `java.math.BigDecimal`,而非 `java.lang.Double` 或 `java.lang.Float`。 + +- **比较谓词(`P.eq`、`P.neq`、`P.lt`、`P.lte`、`P.gt`、`P.gte`、`P.between`):** TinkerPop 的 `Compare` 谓词会对不同 `Number` 子类(`BigDecimal`、`Double`、`Float`、`Long`、`Integer`)执行基于数值的自动类型提升比较。 +- **集合包含谓词(`P.within`、`P.without`):** `Contains.within` 与 `Contains.without` 基于 Java 对象的 `Collection.contains(value)` 判等逻辑执行匹配;由于运行时类型不同,`BigDecimal.valueOf(1.0).equals(Double.valueOf(1.0d))` 返回 `false`。 Review Comment: Important: same misattribution as the English page: TinkerPop's `Contains.within` matches numbers by value, and the class-sensitive match comes from HugeGraph's `convIn2Relation` and `Condition.RelationType.IN`. Attribute it to HugeGraph: ```suggestion - **集合包含谓词(`P.within`、`P.without`):** HugeGraph 将列表中的值直接传给 `IN` / `NOT_IN` 查询条件,不按 `PropertyKey` 数据类型转换,并基于 Java 对象的 `Collection.contains(value)` 判等逻辑执行匹配;由于运行时类型不同,`BigDecimal.valueOf(1.0).equals(Double.valueOf(1.0d))` 返回 `false`。 ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
