-
Notifications
You must be signed in to change notification settings - Fork 0
Support listing of Hudi files through its metadata #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -184,6 +184,8 @@ public class HiveClientConfig | |
| private boolean fileRenamingEnabled; | ||
| private boolean preferManifestToListFiles; | ||
| private boolean manifestVerificationEnabled; | ||
| private boolean preferMetadataToListHudiFiles; | ||
| private boolean hudiMetadataVerificationEnabled; | ||
|
|
||
| public int getMaxInitialSplits() | ||
| { | ||
|
|
@@ -1552,4 +1554,30 @@ public boolean isManifestVerificationEnabled() | |
| { | ||
| return this.manifestVerificationEnabled; | ||
| } | ||
|
|
||
| @Config("hive.prefer-metadata-to-list-hudi-files") | ||
| @ConfigDescription("For Hudi tables prefer to fetch the list of file names and sizes from metadata rather than storage") | ||
| public HiveClientConfig setPreferMetadataToListHudiFiles(boolean preferMetadataToListHudiFiles) | ||
| { | ||
| this.preferMetadataToListHudiFiles = preferMetadataToListHudiFiles; | ||
| return this; | ||
| } | ||
|
|
||
| public boolean isPreferMetadataToListHudiFiles() | ||
| { | ||
| return this.preferMetadataToListHudiFiles; | ||
| } | ||
|
|
||
| @Config("hive.hudi-metadata-verification-enabled") | ||
|
||
| @ConfigDescription("Enable verification of file names and sizes in Hudi metadata") | ||
| public HiveClientConfig setHudiMetadataVerificationEnabled(boolean hudiMetadataVerificationEnabled) | ||
| { | ||
| this.hudiMetadataVerificationEnabled = hudiMetadataVerificationEnabled; | ||
| return this; | ||
| } | ||
|
|
||
| public boolean isHudiMetadataVerificationEnabled() | ||
| { | ||
| return this.hudiMetadataVerificationEnabled; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| /* | ||
| * Licensed 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 com.facebook.presto.hive; | ||
|
|
||
| import com.facebook.presto.hive.filesystem.ExtendedFileSystem; | ||
| import com.facebook.presto.hive.metastore.Table; | ||
| import com.facebook.presto.hive.util.HiveFileIterator; | ||
| import com.facebook.presto.spi.ConnectorSession; | ||
| import org.apache.hadoop.conf.Configuration; | ||
| import org.apache.hadoop.fs.BlockLocation; | ||
| import org.apache.hadoop.fs.FileStatus; | ||
| import org.apache.hadoop.fs.LocatedFileStatus; | ||
| import org.apache.hadoop.fs.Path; | ||
| import org.apache.hadoop.fs.PathFilter; | ||
| import org.apache.hadoop.fs.RemoteIterator; | ||
| import org.apache.hudi.common.config.HoodieMetadataConfig; | ||
| import org.apache.hudi.common.engine.HoodieEngineContext; | ||
| import org.apache.hudi.common.engine.HoodieLocalEngineContext; | ||
| import org.apache.hudi.common.fs.FSUtils; | ||
| import org.apache.hudi.common.model.HoodieBaseFile; | ||
| import org.apache.hudi.common.table.HoodieTableMetaClient; | ||
| import org.apache.hudi.common.table.view.FileSystemViewManager; | ||
| import org.apache.hudi.common.table.view.HoodieTableFileSystemView; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Iterator; | ||
| import java.util.Optional; | ||
|
|
||
| import static com.facebook.presto.hive.HiveFileInfo.createHiveFileInfo; | ||
| import static com.facebook.presto.hive.HiveSessionProperties.isHudiMetadataVerificationEnabled; | ||
| import static com.facebook.presto.hive.HiveSessionProperties.isPreferMetadataToListHudiFiles; | ||
|
|
||
| public final class HudiDirectoryLister | ||
| implements DirectoryLister | ||
| { | ||
| private HoodieTableFileSystemView fileSystemView; | ||
|
|
||
| public HudiDirectoryLister(Configuration conf, | ||
| ConnectorSession session, | ||
| Table table) | ||
| { | ||
| System.out.println("Uditt: Initializing Hudi Directory Lister..."); | ||
| HoodieTableMetaClient metaClient = new HoodieTableMetaClient(conf, table.getStorage().getLocation()); | ||
| HoodieEngineContext engineContext = new HoodieLocalEngineContext(conf); | ||
| HoodieMetadataConfig metadataConfig = HoodieMetadataConfig.newBuilder() | ||
| .enable(isPreferMetadataToListHudiFiles(session)) | ||
| .validate(isHudiMetadataVerificationEnabled(session)) | ||
| .build(); | ||
| this.fileSystemView = FileSystemViewManager.createInMemoryFileSystemView(engineContext, metaClient, | ||
| metadataConfig); | ||
| } | ||
|
|
||
| @Override | ||
| public Iterator<HiveFileInfo> list(ExtendedFileSystem fileSystem, | ||
| Table table, | ||
| Path path, | ||
| NamenodeStats namenodeStats, | ||
| PathFilter pathFilter, | ||
| HiveDirectoryContext hiveDirectoryContext) | ||
| { | ||
| return new HiveFileIterator( | ||
| path, | ||
| p -> new HudiFileInfoIterator(fileSystemView, table.getStorage().getLocation(), p), | ||
| namenodeStats, | ||
| hiveDirectoryContext.getNestedDirectoryPolicy(), | ||
| pathFilter); | ||
| } | ||
|
|
||
| public static class HudiFileInfoIterator | ||
| implements RemoteIterator<HiveFileInfo> | ||
| { | ||
| private final Iterator<HoodieBaseFile> hoodieBaseFileIterator; | ||
|
|
||
| public HudiFileInfoIterator(HoodieTableFileSystemView fileSystemView, | ||
| String tablePath, | ||
| Path directory) | ||
| { | ||
| String partition = FSUtils.getRelativePartitionPath(new Path(tablePath), directory); | ||
| this.hoodieBaseFileIterator = fileSystemView.getLatestBaseFiles(partition).iterator(); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean hasNext() | ||
| { | ||
| return hoodieBaseFileIterator.hasNext(); | ||
| } | ||
|
|
||
| @Override | ||
| public HiveFileInfo next() throws IOException | ||
| { | ||
| FileStatus fileStatus = hoodieBaseFileIterator.next().getFileStatus(); | ||
| String[] name = new String[]{"localhost:50010"}; | ||
| String[] host = new String[]{"localhost"}; | ||
| LocatedFileStatus hoodieFileStatus = new LocatedFileStatus(fileStatus, | ||
|
||
| new BlockLocation[]{new BlockLocation(name, host, 0L, fileStatus.getLen())}); | ||
| return createHiveFileInfo(hoodieFileStatus, Optional.empty()); | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
may be just,
hive.use.hudi.metadata.to.list.filesThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think community will accept this, as the convention they follow is sepration by
-. In addition, I used the workpreferso it along the lines of https://github.com/prestodb/presto/blob/master/presto-hive/src/main/java/com/facebook/presto/hive/HiveClientConfig.java#L1530