bitflicker64 commented on code in PR #561: URL: https://github.com/apache/hugegraph-doc/pull/561#discussion_r4500511033
########## content/en/docs/language/hugegraph-gremlin.md: ########## @@ -138,3 +138,46 @@ 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 + +In Gremlin-Groovy, an unsuffixed decimal literal like `1.0` is parsed as `java.math.BigDecimal`, +and an unsuffixed integer literal like `1` is parsed as `java.lang.Integer`. Depending on whether +a `has(...)` step is pushed down to HugeGraph's backend condition converter +(`TraversalUtil.convPredicateValue`) or evaluated in-memory by TinkerPop's `HasStep`, mismatched +literal types cause two distinct pitfalls: + +- **In-memory collection membership (`P.within`, `P.without`)**: When TinkerPop evaluates + `Contains.within` or `Contains.without` in memory (for example on unindexed properties or + chained `has(...)` filters such as + `g.E().has('weight', P.within(1.0)).has('weight', P.lt(1.5))`), it delegates to + `java.util.Collection.contains(value)`, which uses strict `Object.equals()` without numeric + promotion. Because `BigDecimal.valueOf(1.0).equals(Double.valueOf(1.0d))` and + `Integer.valueOf(1).equals(Long.valueOf(1L))` are both `false`, `has('weight', P.within(1.0))` + returns `0` results on a `DOUBLE` property even when `weight = 1.0`. (By contrast, `P.eq`, + `P.neq`, `P.lt`, `P.lte`, `P.gt`, `P.gte`, and `P.between` use TinkerPop's `Compare`, which + promotes numeric types in memory.) +- **Backend condition conversion (`LONG`, `INT`, `BYTE`)**: When HugeGraph converts predicate + values against the schema `data_type`, passing a decimal literal such as `1.0` (`BigDecimal`) + to an integer-typed property key (`LONG`, `INT`, or `BYTE`) fails `Long.valueOf` / + `Integer.valueOf` / `Byte.valueOf` parsing with a `NumberFormatException`. Review Comment: Minor: `DataType.valueToNumber` catches the `NumberFormatException` and `PropertyKey.validValue` rethrows it as `IllegalArgumentException` (`Invalid property value '1.0' for key ...`), so users never see a `NumberFormatException`. Name the exception users get: ```suggestion `Integer.valueOf` / `Byte.valueOf` parsing, and HugeGraph rejects the query with an `IllegalArgumentException`. ``` -- 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]
