xiangfu0 commented on code in PR #20337:
URL: https://github.com/apache/pinot/pull/20337#discussion_r4651555146
##########
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:
A declared multi-value BOOLEAN reaches this code as a boxed array for a
materialized key or a list from the sparse blob. Neither enters the `Number`
branch. A row containing `[true,false]` therefore still renders as `[1,0]`.
Please carry the key's BOOLEAN type into the existing array and list rendering
and cover both reader shapes.
##########
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:
The splitter coerces numeric input for declared BOOLEAN keys to the stored
INT type, so an input of `2` can reach this expression. Pinot's BOOLEAN result
formatter treats only `1` as true. Using `BooleanUtils.toBoolean(number)` here
keeps `SELECT col` consistent with `SELECT col['flag']` for that input as well.
##########
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:
`getDataSources()` omits sparse children. With a declared BOOLEAN `flag` and
`maxDenseKeys=0`, `OpenStructColumnSplitter` coerces `true` to INT and writes
that `1` into the sparse JSON. The sparse reader returns the number, so `SELECT
col` still emits `{"flag":1}`. The current sparse test supplies a Java Boolean
and skips this case. Can we use the declared child field spec for sparse keys
and exercise the writer output? This would also avoid building data sources for
every observed key on a consuming segment just to inspect their types.
--
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]