siddharthteotia commented on a change in pull request #6710: URL: https://github.com/apache/incubator-pinot/pull/6710#discussion_r603688817
########## File path: pinot-core/src/main/java/org/apache/pinot/core/common/datatable/DataTableImplV3.java ########## @@ -0,0 +1,594 @@ +/** + * 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.core.common.datatable; + +import com.google.common.primitives.Ints; +import com.google.common.primitives.Longs; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; +import org.apache.pinot.common.response.ProcessingException; +import org.apache.pinot.common.utils.DataSchema; +import org.apache.pinot.common.utils.DataTable; +import org.apache.pinot.common.utils.StringUtil; +import org.apache.pinot.core.common.ObjectSerDeUtils; +import org.apache.pinot.core.query.request.context.ThreadTimer; +import org.apache.pinot.spi.utils.ByteArray; +import org.apache.pinot.spi.utils.BytesUtils; + +import static org.apache.pinot.common.utils.DataTable.MetadataKeys.EXECUTION_THREAD_CPU_TIME_NS; +import static org.apache.pinot.core.common.datatable.DataTableUtils.*; + + +/** + * Datatable V3 implementation. + * The layout of serialized V3 datatable looks like: + * +-----------------------------------------------+ + * | 13 bytes of header: | + * | VERSION | + * | NUM_ROWS | + * | NUM_COLUMNS | + * | EXCEPTIONS SECTION START OFFSET | + * | EXCEPTIONS SECTION LENGTH | + * | DICTIONARY_MAP SECTION START OFFSET | + * | DICTIONARY_MAP SECTION LENGTH | + * | DATA_SCHEMA SECTION START OFFSET | + * | DATA_SCHEMA SECTION LENGTH | + * | FIXED_SIZE_DATA SECTION START OFFSET | + * | FIXED_SIZE_DATA SECTION LENGTH | + * | VARIABLE_SIZE_DATA SECTION START OFFSET | + * | VARIABLE_SIZE_DATA SECTION LENGTH | + * +-----------------------------------------------+ + * | EXCEPTIONS SECTION | + * +-----------------------------------------------+ + * | DICTIONARY_MAP SECTION | + * +-----------------------------------------------+ + * | DATA_SCHEMA SECTION | + * +-----------------------------------------------+ + * | FIXED_SIZE_DATA SECTION | + * +-----------------------------------------------+ + * | VARIABLE_SIZE_DATA SECTION | + * +-----------------------------------------------+ + * | METADATA LENGTH | + * | METADATA SECTION | + * +-----------------------------------------------+ + */ +public class DataTableImplV3 implements DataTable { + private static final int VERSION = 3; + private static final int HEADER_SIZE = Integer.BYTES * 13; + + private final int _numRows; + private final int _numColumns; + private final DataSchema _dataSchema; + private final int[] _columnOffsets; + private final int _rowSizeInBytes; + private final Map<String, Map<Integer, String>> _dictionaryMap; + private final byte[] _fixedSizeDataBytes; + private final ByteBuffer _fixedSizeData; + private final byte[] _variableSizeDataBytes; + private final ByteBuffer _variableSizeData; + // _exceptions stores exceptions as a map of errorCode->errorMessage + private final Map<Integer, String> _exceptions; + private final Map<MetadataKeys, String> _metadata; + // _metadataV2 is just a V2 presentation of _metadata, we copy KV pairs between _metadata and _metadataV2 during + // serialization/deserialization. This is because V2 API of getMetadata returns a Map<String, String> and there are + // a lot of existing code using string as key to access metadata. + // TODO: remove this and change all metadata accessing code use MetadataKeys. + private final Map<String, String> _metadataV2; Review comment: So this is needed to comply with existing interface **`Map<String, String> getMetadata();`** right and keep its callers happy for now ? I don't think there is any way of resolving this TODO in a clean manner. All the callers of getMetadata API will have to be changed and the code will become conditional/ugly since we will have to support both V2 and V3 and the structure returned by API will be different. So, I suggest to not worry about it at all and for internal in-memory processing of metadata get/put always use `Map<String, String> _metadata` Here is what we can do - Remove `private final Map<MetadataKeys, String> _metadata;` - Replace `private final Map<String, String> _metadataV2` with `private final Map<String, String> _metadata`; - getMetadata() will continue to return _metadata - Before serialization you are anyway converting String key to MetadataKeys enum by copying all KV pairs. You don't do any copy. Just convert from String to MetadataKeys enum in the `serializeMetadata` function itself before you generate the wire payload. We won't need to copy pairs from one map to another. - During deserialization on the broker, you deserialize MetadataKeys based format and convert it into String, String for processing. -- 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. For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
