xiangfu0 commented on code in PR #19171:
URL: https://github.com/apache/pinot/pull/19171#discussion_r3789900643


##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/map/MapKeyIndexReader.java:
##########
@@ -56,29 +55,42 @@ public FieldSpec.DataType getStoredType() {
     return _keyFieldSpec.getDataType().getStoredType();
   }
 
+  // The numeric accessors below fast-path the type Jackson already produced 
for this JSON shape - Integer for a
+  // small integer, Long for a large one, Double for a decimal - instead of 
formatting it to a string and reparsing.
+  // Any other type still goes through the string round trip, so a value that 
does not match the declared type
+  // fails exactly as it did before rather than being silently coerced.
+
   @Override
   public int getInt(int docId, ForwardIndexReaderContext context) {
-    return Integer.parseInt(extractMapValue(docId, context, 
_keyName).toString());
+    Object value = extractMapValue(docId, context, _keyName);
+    return value instanceof Integer ? (Integer) value : 
Integer.parseInt(value.toString());
   }
 
   @Override
   public long getLong(int docId, ForwardIndexReaderContext context) {
-    return Long.parseLong(extractMapValue(docId, context, 
_keyName).toString());
+    Object value = extractMapValue(docId, context, _keyName);
+    if (value instanceof Long) {
+      return (Long) value;
+    }
+    return value instanceof Integer ? (Integer) value : 
Long.parseLong(value.toString());
   }
 
   @Override
   public float getFloat(int docId, ForwardIndexReaderContext context) {
-    return Float.parseFloat(extractMapValue(docId, context, 
_keyName).toString());
+    Object value = extractMapValue(docId, context, _keyName);
+    return value instanceof Float ? (Float) value : 
Float.parseFloat(value.toString());
   }

Review Comment:
   Correct - Jackson's untyped binding never yields `Float`, so that branch was 
dead. Removed it rather than narrowing the `Double`, since `(float) d` and 
`Float.parseFloat(Double.toString(d))` disagree by an ulp for doubles near a 
float midpoint (`-1.340092769725468E-17` narrows to `-1.3400928E-17`, parses to 
`-1.3400927E-17`; 1.2M of 20.9M sampled midpoint-adjacent doubles differ), and 
this method has always returned the parsed value. Rationale is now in a comment 
on the method.
   
   _🤖 Addressed by [Claude Code](https://claude.com/claude-code)_



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