xiangfu0 commented on code in PR #18325: URL: https://github.com/apache/pinot/pull/18325#discussion_r3141563675
########## pinot-plugins/pinot-input-format/pinot-parquet/src/main/java/org/apache/pinot/plugin/inputformat/parquet/ParquetRecordExtractorUtils.java: ########## @@ -0,0 +1,112 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.pinot.plugin.inputformat.parquet; + +import java.util.Collection; +import java.util.LinkedHashMap; +import java.util.Map; + + +/** + * Shared helpers for normalizing Parquet list wrapper records while extracting Pinot rows. + * + * <p>This class is stateless and thread-safe. + */ +final class ParquetRecordExtractorUtils { + private static final String LIST_ELEMENT_FIELD_NAME = "element"; + private static final String MAP_ENTRIES_FIELD_NAME = "key_value"; + private static final String MAP_KEY_FIELD_NAME = "key"; + private static final String MAP_VALUE_FIELD_NAME = "value"; + + private ParquetRecordExtractorUtils() { + } + + static Object[] unwrapListElementMaps(Object[] values) { + if (values.length == 0) { + return values; + } + + boolean hasElementMap = false; + for (Object value : values) { + if (value == null) { + continue; + } + if (!(value instanceof Map)) { + return values; + } + Map<?, ?> map = (Map<?, ?>) value; + if (map.size() != 1 || !map.containsKey(LIST_ELEMENT_FIELD_NAME)) { + return values; + } + hasElementMap = true; + } + if (!hasElementMap) { + return values; + } + + Object[] unwrappedValues = new Object[values.length]; + for (int i = 0; i < values.length; i++) { + Object value = values[i]; + unwrappedValues[i] = value == null ? null : ((Map<?, ?>) value).get(LIST_ELEMENT_FIELD_NAME); Review Comment: The build-then-rewrite pattern is gone. `extractKeyValueMap` constructs the result Map directly from the Parquet group entries; there's no intermediate Map to replace. -- 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]
