xiangfu0 commented on code in PR #20337:
URL: https://github.com/apache/pinot/pull/20337#discussion_r4651652938
##########
pinot-core/src/main/java/org/apache/pinot/core/operator/blocks/ProjectionBlock.java:
##########
@@ -111,16 +115,34 @@ private BlockValSet openStructDocuments(String column,
OpenStructDataSource open
/// the shape the source had, so it wins and the paths into it are dropped.
`.` is an ordinary key character with
/// no escape, and that is exactly what makes the container's own entry the
thing that disambiguates: a dotted key
/// whose prefix is not itself a key was never a path, so it stays a key
spelled with a dot.
- private static Map<String, Object> renderDocument(Map<String, Object>
document) {
+ ///
+ /// `booleanKeys` names the materialized keys declared BOOLEAN, whose stored
INT 0/1 reads as a boolean. Only the top
+ /// level carries them: a nested object is the source's own JSON, where a
boolean is already one.
+ private static Map<String, Object> renderDocument(Map<String, Object>
document, Set<String> booleanKeys) {
Map<String, Object> rendered = new LinkedHashMap<>(document.size());
for (Map.Entry<String, Object> entry : document.entrySet()) {
- if (!isPathIntoPresentObject(entry.getKey(), document)) {
- rendered.put(entry.getKey(), renderValue(entry.getValue()));
+ String key = entry.getKey();
+ if (!isPathIntoPresentObject(key, document)) {
+ Object value = entry.getValue();
+ rendered.put(key, value instanceof Number number &&
booleanKeys.contains(key)
+ ? number.intValue() != 0 : renderValue(value));
}
}
return rendered;
}
+ /// The materialized keys declared BOOLEAN. A BOOLEAN is stored as INT 0/1
and the reconstruction hands back the
+ /// stored number, so the document needs the declared type to say `true`
instead of `1`, the way `col['key']` does.
+ private static Set<String> booleanKeys(OpenStructDataSource
openStructDataSource) {
+ Set<String> booleanKeys = new HashSet<>();
+ for (Map.Entry<String, DataSource> entry :
openStructDataSource.getDataSources().entrySet()) {
Review Comment:
Fixed in 64ac76c1f0. Projection uses the parent schema to recognize declared
sparse BOOLEAN keys, and consults a materialized child's actual type for
compatibility with older segments. The one-row sealed-segment test forces a
sparse scalar and array through the writer and verifies their JSON types.
##########
pinot-core/src/main/java/org/apache/pinot/core/operator/blocks/ProjectionBlock.java:
##########
@@ -111,16 +115,34 @@ private BlockValSet openStructDocuments(String column,
OpenStructDataSource open
/// the shape the source had, so it wins and the paths into it are dropped.
`.` is an ordinary key character with
/// no escape, and that is exactly what makes the container's own entry the
thing that disambiguates: a dotted key
/// whose prefix is not itself a key was never a path, so it stays a key
spelled with a dot.
- private static Map<String, Object> renderDocument(Map<String, Object>
document) {
+ ///
+ /// `booleanKeys` names the materialized keys declared BOOLEAN, whose stored
INT 0/1 reads as a boolean. Only the top
+ /// level carries them: a nested object is the source's own JSON, where a
boolean is already one.
+ private static Map<String, Object> renderDocument(Map<String, Object>
document, Set<String> booleanKeys) {
Map<String, Object> rendered = new LinkedHashMap<>(document.size());
for (Map.Entry<String, Object> entry : document.entrySet()) {
- if (!isPathIntoPresentObject(entry.getKey(), document)) {
- rendered.put(entry.getKey(), renderValue(entry.getValue()));
+ String key = entry.getKey();
+ if (!isPathIntoPresentObject(key, document)) {
+ Object value = entry.getValue();
+ rendered.put(key, value instanceof Number number &&
booleanKeys.contains(key)
Review Comment:
Fixed in 64ac76c1f0. The renderer carries the BOOLEAN type into boxed arrays
and sparse lists. The real-segment regression also reproduced an
ArrayIndexOutOfBoundsException in the dictionary-encoded array reader. Its
dictionary-ID buffer now uses the child's recorded maximum value count. The
dense and sparse arrays both pass through whole-document projection in the test.
##########
pinot-core/src/main/java/org/apache/pinot/core/operator/blocks/ProjectionBlock.java:
##########
@@ -111,16 +115,34 @@ private BlockValSet openStructDocuments(String column,
OpenStructDataSource open
/// the shape the source had, so it wins and the paths into it are dropped.
`.` is an ordinary key character with
/// no escape, and that is exactly what makes the container's own entry the
thing that disambiguates: a dotted key
/// whose prefix is not itself a key was never a path, so it stays a key
spelled with a dot.
- private static Map<String, Object> renderDocument(Map<String, Object>
document) {
+ ///
+ /// `booleanKeys` names the materialized keys declared BOOLEAN, whose stored
INT 0/1 reads as a boolean. Only the top
+ /// level carries them: a nested object is the source's own JSON, where a
boolean is already one.
+ private static Map<String, Object> renderDocument(Map<String, Object>
document, Set<String> booleanKeys) {
Map<String, Object> rendered = new LinkedHashMap<>(document.size());
for (Map.Entry<String, Object> entry : document.entrySet()) {
- if (!isPathIntoPresentObject(entry.getKey(), document)) {
- rendered.put(entry.getKey(), renderValue(entry.getValue()));
+ String key = entry.getKey();
+ if (!isPathIntoPresentObject(key, document)) {
+ Object value = entry.getValue();
+ rendered.put(key, value instanceof Number number &&
booleanKeys.contains(key)
+ ? number.intValue() != 0 : renderValue(value));
Review Comment:
Fixed in 64ac76c1f0. The renderer now uses BooleanUtils.toBoolean for
numeric values. The regression test writes 2 to a declared dense BOOLEAN and
verifies the JSON value is false. It also checks that an ordinary numeric
sibling remains 1.
--
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]