-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Remove unnecessary directory checks in delta lake #16200
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,8 +30,6 @@ | |
| import io.trino.filesystem.FileIterator; | ||
| import io.trino.filesystem.TrinoFileSystem; | ||
| import io.trino.filesystem.TrinoFileSystemFactory; | ||
| import io.trino.hdfs.HdfsContext; | ||
| import io.trino.hdfs.HdfsEnvironment; | ||
| import io.trino.plugin.base.classloader.ClassLoaderSafeSystemTable; | ||
| import io.trino.plugin.deltalake.expression.SparkExpressionParser; | ||
| import io.trino.plugin.deltalake.metastore.DeltaLakeMetastore; | ||
|
|
@@ -218,13 +216,9 @@ | |
| import static io.trino.plugin.hive.util.HiveClassNames.SEQUENCEFILE_INPUT_FORMAT_CLASS; | ||
| import static io.trino.plugin.hive.util.HiveUtil.isDeltaLakeTable; | ||
| import static io.trino.plugin.hive.util.HiveUtil.isHiveSystemSchema; | ||
| import static io.trino.plugin.hive.util.HiveWriteUtils.createDirectory; | ||
| import static io.trino.plugin.hive.util.HiveWriteUtils.isS3FileSystem; | ||
| import static io.trino.plugin.hive.util.HiveWriteUtils.pathExists; | ||
| import static io.trino.spi.StandardErrorCode.GENERIC_INTERNAL_ERROR; | ||
| import static io.trino.spi.StandardErrorCode.INVALID_ANALYZE_PROPERTY; | ||
| import static io.trino.spi.StandardErrorCode.INVALID_SCHEMA_PROPERTY; | ||
| import static io.trino.spi.StandardErrorCode.INVALID_TABLE_PROPERTY; | ||
| import static io.trino.spi.StandardErrorCode.NOT_SUPPORTED; | ||
| import static io.trino.spi.connector.RetryMode.NO_RETRIES; | ||
| import static io.trino.spi.connector.RowChangeParadigm.DELETE_ROW_AND_INSERT_ROW; | ||
|
|
@@ -298,7 +292,6 @@ public class DeltaLakeMetadata | |
|
|
||
| private final DeltaLakeMetastore metastore; | ||
| private final TrinoFileSystemFactory fileSystemFactory; | ||
| private final HdfsEnvironment hdfsEnvironment; | ||
| private final TypeManager typeManager; | ||
| private final AccessControlMetadata accessControlMetadata; | ||
| private final TrinoViewHiveMetastore trinoViewHiveMetastore; | ||
|
|
@@ -321,7 +314,6 @@ public class DeltaLakeMetadata | |
| public DeltaLakeMetadata( | ||
| DeltaLakeMetastore metastore, | ||
| TrinoFileSystemFactory fileSystemFactory, | ||
| HdfsEnvironment hdfsEnvironment, | ||
| TypeManager typeManager, | ||
| AccessControlMetadata accessControlMetadata, | ||
| TrinoViewHiveMetastore trinoViewHiveMetastore, | ||
|
|
@@ -341,7 +333,6 @@ public DeltaLakeMetadata( | |
| { | ||
| this.metastore = requireNonNull(metastore, "metastore is null"); | ||
| this.fileSystemFactory = requireNonNull(fileSystemFactory, "fileSystemFactory is null"); | ||
| this.hdfsEnvironment = requireNonNull(hdfsEnvironment, "hdfsEnvironment is null"); | ||
| this.typeManager = requireNonNull(typeManager, "typeManager is null"); | ||
| this.accessControlMetadata = requireNonNull(accessControlMetadata, "accessControlMetadata is null"); | ||
| this.trinoViewHiveMetastore = requireNonNull(trinoViewHiveMetastore, "trinoViewHiveMetastore is null"); | ||
|
|
@@ -710,7 +701,6 @@ public void createTable(ConnectorSession session, ConnectorTableMetadata tableMe | |
| external = false; | ||
| } | ||
| Path targetPath = new Path(location); | ||
| ensurePathExists(session, targetPath); | ||
| Path deltaLogDirectory = getTransactionLogDir(targetPath); | ||
| Optional<Long> checkpointInterval = getCheckpointInterval(tableMetadata.getProperties()); | ||
| Optional<Boolean> changeDataFeedEnabled = getChangeDataFeedEnabled(tableMetadata.getProperties()); | ||
|
|
@@ -766,7 +756,7 @@ public void createTable(ConnectorSession session, ConnectorTableMetadata tableMe | |
| throw new TrinoException(DELTA_LAKE_BAD_WRITE, "Unable to access file system for: " + location, e); | ||
| } | ||
|
|
||
| Table table = buildTable(session, schemaTableName, location, targetPath, external); | ||
| Table table = buildTable(session, schemaTableName, location, external); | ||
|
|
||
| PrincipalPrivileges principalPrivileges = buildInitialPrivilegeSet(table.getOwner().orElseThrow()); | ||
| metastore.createTable( | ||
|
|
@@ -775,7 +765,7 @@ public void createTable(ConnectorSession session, ConnectorTableMetadata tableMe | |
| principalPrivileges); | ||
| } | ||
|
|
||
| public static Table buildTable(ConnectorSession session, SchemaTableName schemaTableName, String location, Path targetPath, boolean isExternal) | ||
| public static Table buildTable(ConnectorSession session, SchemaTableName schemaTableName, String location, boolean isExternal) | ||
| { | ||
| Table.Builder tableBuilder = Table.builder() | ||
| .setDatabaseName(schemaTableName.getSchemaName()) | ||
|
|
@@ -785,7 +775,7 @@ public static Table buildTable(ConnectorSession session, SchemaTableName schemaT | |
| .setDataColumns(DUMMY_DATA_COLUMNS) | ||
| .setParameters(deltaTableProperties(session, location, isExternal)); | ||
|
|
||
| setDeltaStorageFormat(tableBuilder, location, targetPath); | ||
| setDeltaStorageFormat(tableBuilder, location); | ||
| return tableBuilder.build(); | ||
| } | ||
|
|
||
|
|
@@ -808,29 +798,13 @@ private static Map<String, String> deltaTableProperties(ConnectorSession session | |
| return properties.buildOrThrow(); | ||
| } | ||
|
|
||
| private static void setDeltaStorageFormat(Table.Builder tableBuilder, String location, Path targetPath) | ||
| private static void setDeltaStorageFormat(Table.Builder tableBuilder, String location) | ||
findepi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| tableBuilder.getStorageBuilder() | ||
| // this mimics what Databricks is doing when creating a Delta table in the Hive metastore | ||
| .setStorageFormat(DELTA_STORAGE_FORMAT) | ||
| .setSerdeParameters(ImmutableMap.of(PATH_PROPERTY, location)) | ||
| .setLocation(targetPath.toString()); | ||
| } | ||
|
|
||
| private Path getExternalPath(HdfsContext context, String location) | ||
| { | ||
| try { | ||
| Path path = new Path(location); | ||
| if (!isS3FileSystem(context, hdfsEnvironment, path)) { | ||
| if (!hdfsEnvironment.getFileSystem(context, path).getFileStatus(path).isDirectory()) { | ||
| throw new TrinoException(INVALID_TABLE_PROPERTY, "External location must be a directory: " + location); | ||
| } | ||
| } | ||
| return path; | ||
| } | ||
| catch (IllegalArgumentException | IOException e) { | ||
| throw new TrinoException(INVALID_TABLE_PROPERTY, "External location is not a valid file system URI: " + location, e); | ||
| } | ||
| .setLocation(location); | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -858,7 +832,6 @@ public DeltaLakeOutputTableHandle beginCreateTable(ConnectorSession session, Con | |
| external = false; | ||
| } | ||
| Path targetPath = new Path(location); | ||
| ensurePathExists(session, targetPath); | ||
| checkPathContainsNoFiles(session, targetPath); | ||
|
|
||
| setRollback(() -> deleteRecursivelyIfExists(fileSystemFactory.create(session), targetPath)); | ||
|
|
@@ -884,14 +857,6 @@ private Optional<String> getSchemaLocation(Database database) | |
| return schemaLocation; | ||
| } | ||
|
|
||
| private void ensurePathExists(ConnectorSession session, Path directoryPath) | ||
| { | ||
| HdfsContext hdfsContext = new HdfsContext(session); | ||
| if (!pathExists(hdfsContext, hdfsEnvironment, directoryPath)) { | ||
| createDirectory(hdfsContext, hdfsEnvironment, directoryPath); | ||
| } | ||
| } | ||
|
|
||
| private void checkPathContainsNoFiles(ConnectorSession session, Path targetPath) | ||
| { | ||
| try { | ||
|
|
@@ -961,7 +926,7 @@ public Optional<ConnectorOutputMetadata> finishCreateTable( | |
| .map(dataFileInfoCodec::fromJson) | ||
| .collect(toImmutableList()); | ||
|
|
||
| Table table = buildTable(session, schemaTableName(schemaName, tableName), location, getExternalPath(new HdfsContext(session), location), handle.isExternal()); | ||
|
||
| Table table = buildTable(session, schemaTableName(schemaName, tableName), location, handle.isExternal()); | ||
| // Ensure the table has queryId set. This is relied on for exception handling | ||
| String queryId = session.getQueryId(); | ||
| verify( | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This check can be skipped because directory is created implicitly when first file is created.
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.
This should be part of the commit message