deniskuzZ commented on code in PR #5613: URL: https://github.com/apache/hive/pull/5613#discussion_r1931084089
########## ql/src/java/org/apache/hadoop/hive/ql/queryhistory/schema/QueryHistorySchema.java: ########## @@ -0,0 +1,270 @@ +/* + * 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 + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * 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.hadoop.hive.ql.queryhistory.schema; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +import com.google.common.annotations.VisibleForTesting; +import org.apache.hadoop.hive.metastore.api.FieldSchema; +import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector; +import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory; +import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory; + +public class QueryHistorySchema { + public static final int CURRENT_VERSION = 1; + + // how many bytes are consumed by the "short" fields in a record + // rough estimate (once per JVM), which is much efficient than counting all the fields + public static final long BASE_RECORD_SIZE_IN_MEMORY_BYTES = calculateSimpleFieldsSize(); + + private static int calculateSimpleFieldsSize() { + int baseSize = 0; + for (QueryHistorySchema.Field field : QueryHistorySchema.Field.values()) { + switch (field.getType()) { + case "string": + // consider an average 20 chars length + // longer fields are going to be considered again + baseSize += 20 * Character.BYTES; + break; + case "int": + baseSize += 4; + break; + case "bigint": + // stored as long + baseSize += 8; + break; + case "timestamp": + baseSize += 16; + break; + } + } + return baseSize; + } + + public interface QueryHistorySchemaField { Review Comment: should it be public? -- 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: gitbox-unsubscr...@hive.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: gitbox-unsubscr...@hive.apache.org For additional commands, e-mail: gitbox-h...@hive.apache.org