SebastianGruza opened a new pull request, #771:
URL: https://github.com/apache/hugegraph-toolchain/pull/771

   ## Purpose of the PR
   
   Toolchain side of apache/hugegraph#3209 (issue apache/hugegraph#3206): the 
server gains `DataType.DECIMAL`, an exact arbitrary-precision property type 
meant for amounts that go through batch `update_strategies: SUM`. Without this 
change the Java client cannot declare such a key (`asDecimal()`), a 
`BigDecimal` sent through Jackson lands as a JSON number that the server reads 
as a double, the loader cannot convert a `decimal` column, and Hubble cannot 
export such a schema to Groovy.
   
   The PR is self-contained: it compiles and tests against today's server, and 
the API test only switches on when the server knows DECIMAL.
   
   ## Main Changes
   
   ### hugegraph-client
   
   - `DataType.DECIMAL(12, "decimal", BigDecimal.class)` with `isDecimal()` and 
`valueToDecimal()` (the same conversion rules as the server: BigDecimal and 
integral numbers exactly, float/double through their shortest representation, 
decimal strings) in the public enum and in the direct-serializer copy; 
`PropertyKey.Builder.asDecimal()`. Code 12, as in #3209.
   - A `BigDecimal` is serialized as a plain string (`"1.10"`, never 
`"1.1E+2"`) in request bodies (`JsonUtilCommon`, registered in `RestClient`) 
and in query parameters (the client's `JsonUtil`). A JSON number would be a 
double on the server side and lose precision and trailing zeros. Values read 
back are the string the server returns; `new BigDecimal(String)` restores them 
exactly. This matches how the client treats DATE (long) and UUID (string) 
today: no schema-driven conversion on read.
   - `BytesBuffer.writeProperty` writes the server's DECIMAL layout (unscaled 
two's-complement bytes + scale) for the direct loaders (HBase).
   - Drive-by fix: `serializer/direct/struct/DataType` could never be 
initialised, because its static block filled the code table before the table 
was created (NPE on first use). Nothing referenced it until the new unit test 
did; the initialisers are now ordered.
   - Tests: `DecimalDataTypeTest` (unit, 5) and `DecimalPropertyApiTest` (API, 
6, guarded by `Assume` so a server without DECIMAL skips the class instead of 
failing). Two assertions in `BatchUpdateElementApiTest` now accept the message 
the server produces after #3209 (batch values are normalised to the key's data 
type before the strategy runs, so `Date, Date` instead of `Date, String`); the 
assertion checks the prefix and passes on both servers.
   
   ### hugegraph-loader, hugegraph-spark-connector
   
   - `decimal` columns are converted to `BigDecimal` through the client's 
`DataType.valueToDecimal`, with error messages in the style of the rest of 
`DataTypeUtil`; `DataTypeUtilTest` (unit, 2: single value, list).
   
   ### hugegraph-hubble
   
   - The Groovy schema export emits `.asDecimal()` (one line in 
`GroovySchemaCompatibility`).
   
   ## Verifying these changes
   
   - [x] Need tests and can be verified as follows:
   
   | what | result |
   |---|---|
   | client `UnitTestSuite` (JDK 11) | 77/77 |
   | client `DecimalPropertyApiTest` against a server built from #3209 
(rocksdb, auth off, default `BaseClientTest` settings) | 6/6 |
   | loader `UnitTestSuite` | 13/13 |
   | `apache-rat:check`, `checkstyle:check` (client, loader, spark) | clean |
   | compile of loader, spark-connector, hubble-be against the modified client 
| clean |
   
   What the API test covers on the wire: a `data_type: DECIMAL` key through the 
API and `SchemaManager`; a vertex with `new 
BigDecimal("12345678901234567890.10")` read back as the same plain string 
through the vertex API, the driver and Gremlin; `1E-18`, `42`, uint256 max and 
an integer literal stay exact; `"1,10"` is rejected with 400; batch `SUM` gives 
`0.3` for `0.1 + 0.2` and keeps the 18th fraction digit on a 21-digit value; a 
range index on a decimal key is rejected with 400.
   
   ## Does this PR potentially affect the following parts?
   
   - [ ]  Nope
   - [ ]  Dependencies (add/update license info)
   - [ ]  Modify configurations
   - [x]  The public API (a new `DataType` value and a new builder method; the 
serialization change only affects `BigDecimal`, which could not be sent 
correctly before)
   - [ ]  Other affects (typed here)
   
   ## Documentation Status
   
   - [x]  `Doc - TODO` (the data types page in hugegraph-doc, together with the 
docs for #3209; separate PR)
   - [ ]  `Doc - Done`
   - [ ]  `Doc - No Need`
   


-- 
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]

Reply via email to