vinishjail97 commented on code in PR #639: URL: https://github.com/apache/incubator-xtable/pull/639#discussion_r1952108731
########## xtable-core/src/main/java/org/apache/xtable/hudi/HudiPartitionSyncTool.java: ########## @@ -0,0 +1,464 @@ +/* + * 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.xtable.hudi; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; +import java.util.stream.Collectors; + +import lombok.extern.log4j.Log4j2; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.Path; + +import org.apache.hudi.common.engine.HoodieLocalEngineContext; +import org.apache.hudi.common.fs.FSUtils; +import org.apache.hudi.common.table.HoodieTableMetaClient; +import org.apache.hudi.common.table.timeline.HoodieInstant; +import org.apache.hudi.common.table.timeline.HoodieTimeline; +import org.apache.hudi.common.table.timeline.TimelineUtils; +import org.apache.hudi.common.util.Option; +import org.apache.hudi.common.util.VisibleForTesting; +import org.apache.hudi.hadoop.CachingPath; +import org.apache.hudi.sync.common.model.PartitionValueExtractor; + +import org.apache.xtable.catalog.CatalogPartitionSyncOperations; +import org.apache.xtable.catalog.Partition; +import org.apache.xtable.catalog.PartitionEvent; +import org.apache.xtable.catalog.PartitionSyncTool; +import org.apache.xtable.exception.CatalogSyncException; +import org.apache.xtable.model.InternalTable; +import org.apache.xtable.model.catalog.CatalogTableIdentifier; + +@Log4j2 +public class HudiPartitionSyncTool implements PartitionSyncTool { + + private final CatalogPartitionSyncOperations catalogClient; + private final HudiTableManager hudiTableManager; + private final PartitionValueExtractor partitionValuesExtractor; + private final Configuration configuration; + + public static final String LAST_COMMIT_TIME_SYNC = "last_commit_time_sync"; + public static final String LAST_COMMIT_COMPLETION_TIME_SYNC = "last_commit_completion_time_sync"; + + public HudiPartitionSyncTool( + CatalogPartitionSyncOperations catalogClient, + PartitionValueExtractor partitionValueExtractor, + Configuration configuration) { + this.catalogClient = catalogClient; + this.hudiTableManager = HudiTableManager.of(configuration); + this.partitionValuesExtractor = partitionValueExtractor; + this.configuration = configuration; + } + + @VisibleForTesting + HudiPartitionSyncTool( + CatalogPartitionSyncOperations catalogClient, + HudiTableManager hudiTableManager, + PartitionValueExtractor partitionValueExtractor, + Configuration configuration) { + this.catalogClient = catalogClient; + this.hudiTableManager = hudiTableManager; + this.partitionValuesExtractor = partitionValueExtractor; + this.configuration = configuration; + } + + HoodieTableMetaClient getMetaClient(String basePath) { + Optional<HoodieTableMetaClient> metaClientOpt = + hudiTableManager.loadTableMetaClientIfExists(basePath); + + if (!metaClientOpt.isPresent()) { + throw new CatalogSyncException( + "failed to get meta client since table is not present in the base path " + basePath); + } + + return metaClientOpt.get(); + } + + /** + * Syncs all partitions on storage to the metastore, by only making incremental changes. Review Comment: `metastore/catalog` to avoid the confusion that this is used only for HMS. ########## xtable-core/src/main/java/org/apache/xtable/hudi/HudiInputFormatUtils.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.xtable.hudi; + +import org.apache.hudi.common.model.HoodieFileFormat; + +import org.apache.xtable.exception.NotSupportedException; + +public class HudiInputFormatUtils { Review Comment: Move to catalog package inside `xtable-core/hudi ` ########## xtable-core/src/main/java/org/apache/xtable/hudi/HudiPartitionSyncTool.java: ########## @@ -0,0 +1,464 @@ +/* + * 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.xtable.hudi; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; +import java.util.stream.Collectors; + +import lombok.extern.log4j.Log4j2; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.Path; + +import org.apache.hudi.common.engine.HoodieLocalEngineContext; +import org.apache.hudi.common.fs.FSUtils; +import org.apache.hudi.common.table.HoodieTableMetaClient; +import org.apache.hudi.common.table.timeline.HoodieInstant; +import org.apache.hudi.common.table.timeline.HoodieTimeline; +import org.apache.hudi.common.table.timeline.TimelineUtils; +import org.apache.hudi.common.util.Option; +import org.apache.hudi.common.util.VisibleForTesting; +import org.apache.hudi.hadoop.CachingPath; +import org.apache.hudi.sync.common.model.PartitionValueExtractor; + +import org.apache.xtable.catalog.CatalogPartitionSyncOperations; +import org.apache.xtable.catalog.Partition; +import org.apache.xtable.catalog.PartitionEvent; +import org.apache.xtable.catalog.PartitionSyncTool; +import org.apache.xtable.exception.CatalogSyncException; +import org.apache.xtable.model.InternalTable; +import org.apache.xtable.model.catalog.CatalogTableIdentifier; + +@Log4j2 +public class HudiPartitionSyncTool implements PartitionSyncTool { Review Comment: `HudiCatalogPartitionSyncTool` ? ########## xtable-core/src/main/java/org/apache/xtable/catalog/PartitionSyncTool.java: ########## @@ -0,0 +1,41 @@ +/* + * 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.xtable.catalog; + +import org.apache.xtable.model.InternalTable; +import org.apache.xtable.model.catalog.CatalogTableIdentifier; + +/** + * Defines methods to synchronize all partitions from the storage to the catalog. Implementations of + * this interface will handle the logic for syncing partitions, including detecting partition + * changes and updating the catalog accordingly. + */ +public interface PartitionSyncTool { Review Comment: `CatalogPartitionSyncTool` ? ########## xtable-core/src/main/java/org/apache/xtable/catalog/Partition.java: ########## @@ -0,0 +1,48 @@ +/* + * 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.xtable.catalog; + +import java.util.List; + +import lombok.Getter; + +/** + * This class is designed to encapsulate a set of partition values and the corresponding storage + * location where the data for this partition is stored. + */ +@Getter +public class Partition { Review Comment: CatalogPartition maybe a better name for this to avoid confusion with normal partition. ########## xtable-core/src/main/java/org/apache/xtable/catalog/PartitionEvent.java: ########## @@ -0,0 +1,49 @@ +/* + * 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.xtable.catalog; + +/** Partition Event captures any partition that needs to be added or updated. */ +public class PartitionEvent { Review Comment: `CatalogPartitionEvent` ? ########## xtable-core/src/main/java/org/apache/xtable/hudi/HudiSparkDataSourceTableUtils.java: ########## @@ -0,0 +1,114 @@ +/* + * 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.xtable.hudi; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.spark.sql.types.StructType; + +import org.apache.hudi.common.util.StringUtils; + +import org.apache.xtable.model.schema.InternalField; +import org.apache.xtable.model.schema.InternalSchema; +import org.apache.xtable.model.schema.InternalType; +import org.apache.xtable.schema.SparkSchemaExtractor; + +public class HudiSparkDataSourceTableUtils { Review Comment: java doc for this is helpful ? Having a separate class just for `getSparkTableProperties` is overkill this class should have a name which is more generic for catalogs. ########## xtable-core/src/main/java/org/apache/xtable/hudi/HudiPartitionSyncTool.java: ########## @@ -0,0 +1,464 @@ +/* + * 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.xtable.hudi; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; +import java.util.stream.Collectors; + +import lombok.extern.log4j.Log4j2; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.Path; + +import org.apache.hudi.common.engine.HoodieLocalEngineContext; +import org.apache.hudi.common.fs.FSUtils; +import org.apache.hudi.common.table.HoodieTableMetaClient; +import org.apache.hudi.common.table.timeline.HoodieInstant; +import org.apache.hudi.common.table.timeline.HoodieTimeline; +import org.apache.hudi.common.table.timeline.TimelineUtils; +import org.apache.hudi.common.util.Option; +import org.apache.hudi.common.util.VisibleForTesting; +import org.apache.hudi.hadoop.CachingPath; +import org.apache.hudi.sync.common.model.PartitionValueExtractor; + +import org.apache.xtable.catalog.CatalogPartitionSyncOperations; +import org.apache.xtable.catalog.Partition; +import org.apache.xtable.catalog.PartitionEvent; +import org.apache.xtable.catalog.PartitionSyncTool; +import org.apache.xtable.exception.CatalogSyncException; +import org.apache.xtable.model.InternalTable; +import org.apache.xtable.model.catalog.CatalogTableIdentifier; + +@Log4j2 +public class HudiPartitionSyncTool implements PartitionSyncTool { Review Comment: Create a new package known as catalog inside, something like this `xtable-core/hudi/catalog` and move these classes there. -- 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]
