jerryshao commented on code in PR #8228: URL: https://github.com/apache/gravitino/pull/8228#discussion_r2299974446
########## core/src/main/java/org/apache/gravitino/stats/storage/LancePartitionStatisticStorage.java: ########## @@ -0,0 +1,415 @@ +/* + * 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.gravitino.stats.storage; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import com.lancedb.lance.Dataset; +import com.lancedb.lance.Fragment; +import com.lancedb.lance.FragmentMetadata; +import com.lancedb.lance.FragmentOperation; +import com.lancedb.lance.WriteParams; +import com.lancedb.lance.ipc.LanceScanner; +import com.lancedb.lance.ipc.ScanOptions; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.time.Instant; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.stream.Collectors; +import org.apache.arrow.memory.BufferAllocator; +import org.apache.arrow.memory.RootAllocator; +import org.apache.arrow.vector.FieldVector; +import org.apache.arrow.vector.LargeVarCharVector; +import org.apache.arrow.vector.UInt8Vector; +import org.apache.arrow.vector.VarCharVector; +import org.apache.arrow.vector.VectorSchemaRoot; +import org.apache.arrow.vector.ipc.ArrowReader; +import org.apache.arrow.vector.types.pojo.ArrowType; +import org.apache.arrow.vector.types.pojo.Field; +import org.apache.arrow.vector.types.pojo.Schema; +import org.apache.gravitino.Entity; +import org.apache.gravitino.EntityStore; +import org.apache.gravitino.GravitinoEnv; +import org.apache.gravitino.MetadataObject; +import org.apache.gravitino.NameIdentifier; +import org.apache.gravitino.json.JsonUtils; +import org.apache.gravitino.meta.AuditInfo; +import org.apache.gravitino.meta.TableEntity; +import org.apache.gravitino.stats.PartitionRange; +import org.apache.gravitino.stats.PartitionStatisticsDrop; +import org.apache.gravitino.stats.PartitionStatisticsModification; +import org.apache.gravitino.stats.PartitionStatisticsUpdate; +import org.apache.gravitino.stats.StatisticValue; +import org.apache.gravitino.utils.MetadataObjectUtil; +import org.apache.gravitino.utils.PrincipalUtils; + +/** LancePartitionStatisticStorage is based on Lance format files. */ +public class LancePartitionStatisticStorage implements PartitionStatisticStorage { + + private final String LOCATION = "location"; + private final String DEFAULT_LOCATION = "/tmp"; + private final String MAX_ROWS_PER_FILE = "maxRowsPerFile"; + private final int DEFAULT_MAX_ROWS_PER_FILE = 1000000; // 10M + private final String MAX_BYTES_PER_FILE = "maxBytesPerFile"; + private final int DEFAULT_MAX_BYTES_PER_FILE = 100 * 1024 * 1024; // 100 MB + private final String MAX_ROWS_PER_GROUP = "maxRowsPerGroup"; + private final int DEFAULT_MAX_ROWS_PER_GROUP = 1000000; // 1M + private final String READ_BATCH_SIZE = "readBatchSize"; + private final int DEFAULT_READ_BATCH_SIZE = 10000; // 10K + private final Map<String, String> properties; + private final String location; + private final BufferAllocator allocator; + private final int maxRowsPerFile; + private final int maxBytesPerFile; + private final int maxRowsPerGroup; + private final int readBatchSize; + + // The schema is `table_id`, `partition_name`, `statistic_name`, `statistic_value`, `audit_info` + private final String TABLE_ID_COLUMN = "table_id"; + private final String PARTITION_NAME_COLUMN = "partition_name"; + private final String STATISTIC_NAME_COLUMN = "statistic_name"; + private final String STATISTIC_VALUE_COLUMN = "statistic_value"; + private final String AUDIT_INFO_COLUMN = "audit_info"; + + private final EntityStore entityStore = GravitinoEnv.getInstance().entityStore(); + + private final Schema schema = + new Schema( + Arrays.asList( + Field.notNullable(TABLE_ID_COLUMN, new ArrowType.Int(64, false)), + Field.notNullable(PARTITION_NAME_COLUMN, new ArrowType.Utf8()), + Field.notNullable(STATISTIC_NAME_COLUMN, new ArrowType.Utf8()), + Field.notNullable(STATISTIC_VALUE_COLUMN, new ArrowType.LargeUtf8()), + Field.notNullable(AUDIT_INFO_COLUMN, new ArrowType.Utf8()))); + + public LancePartitionStatisticStorage(Map<String, String> properties) { + this.properties = properties; + this.allocator = new RootAllocator(); + this.location = properties.getOrDefault(LOCATION, DEFAULT_LOCATION); + this.maxRowsPerFile = + Integer.parseInt( + properties.getOrDefault(MAX_ROWS_PER_FILE, String.valueOf(DEFAULT_MAX_ROWS_PER_FILE))); + this.maxBytesPerFile = + Integer.parseInt( + properties.getOrDefault( + MAX_BYTES_PER_FILE, String.valueOf(DEFAULT_MAX_BYTES_PER_FILE))); + this.maxRowsPerGroup = + Integer.parseInt( + properties.getOrDefault( + MAX_ROWS_PER_GROUP, String.valueOf(DEFAULT_MAX_ROWS_PER_GROUP))); + this.readBatchSize = + Integer.parseInt( + properties.getOrDefault(READ_BATCH_SIZE, String.valueOf(DEFAULT_READ_BATCH_SIZE))); Review Comment: You should check the validity of all these parameters. -- 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]
