diff --git a/lib/trino-filesystem-manager/src/main/java/io/trino/filesystem/manager/FileSystemConfig.java b/lib/trino-filesystem-manager/src/main/java/io/trino/filesystem/manager/FileSystemConfig.java index 7394476288d9..3b7266e38d45 100644 --- a/lib/trino-filesystem-manager/src/main/java/io/trino/filesystem/manager/FileSystemConfig.java +++ b/lib/trino-filesystem-manager/src/main/java/io/trino/filesystem/manager/FileSystemConfig.java @@ -22,6 +22,7 @@ public class FileSystemConfig private boolean nativeAzureEnabled; private boolean nativeS3Enabled; private boolean nativeGcsEnabled; + private boolean nativeLocalEnabled; private boolean cacheEnabled; public boolean isHadoopEnabled() @@ -77,6 +78,18 @@ public boolean isNativeGcsEnabled() return nativeGcsEnabled; } + @Config("fs.native-local.enabled") + public FileSystemConfig setNativeLocalEnabled(boolean nativeLocalEnabled) + { + this.nativeLocalEnabled = nativeLocalEnabled; + return this; + } + + public boolean isNativeLocalEnabled() + { + return nativeLocalEnabled; + } + @Config("fs.native-gcs.enabled") public FileSystemConfig setNativeGcsEnabled(boolean nativeGcsEnabled) { diff --git a/lib/trino-filesystem-manager/src/main/java/io/trino/filesystem/manager/FileSystemModule.java b/lib/trino-filesystem-manager/src/main/java/io/trino/filesystem/manager/FileSystemModule.java index b7984bd48925..5a397a5e085d 100644 --- a/lib/trino-filesystem-manager/src/main/java/io/trino/filesystem/manager/FileSystemModule.java +++ b/lib/trino-filesystem-manager/src/main/java/io/trino/filesystem/manager/FileSystemModule.java @@ -37,6 +37,8 @@ import io.trino.filesystem.cache.TrinoFileSystemCache; import io.trino.filesystem.gcs.GcsFileSystemFactory; import io.trino.filesystem.gcs.GcsFileSystemModule; +import io.trino.filesystem.local.LocalFileSystemConfig; +import io.trino.filesystem.local.LocalFileSystemFactory; import io.trino.filesystem.memory.MemoryFileSystemCache; import io.trino.filesystem.memory.MemoryFileSystemCacheModule; import io.trino.filesystem.s3.FileSystemS3; @@ -51,6 +53,7 @@ import static com.google.inject.multibindings.MapBinder.newMapBinder; import static com.google.inject.multibindings.OptionalBinder.newOptionalBinder; +import static io.airlift.configuration.ConfigBinder.configBinder; import static java.util.Objects.requireNonNull; public class FileSystemModule @@ -119,6 +122,12 @@ protected void setup(Binder binder) factories.addBinding("gs").to(GcsFileSystemFactory.class); } + if (config.isNativeLocalEnabled()) { + configBinder(binder).bindConfig(LocalFileSystemConfig.class); + factories.addBinding("local").to(LocalFileSystemFactory.class); + factories.addBinding("file").to(LocalFileSystemFactory.class); + } + newOptionalBinder(binder, CachingHostAddressProvider.class).setDefault().to(DefaultCachingHostAddressProvider.class).in(Scopes.SINGLETON); newOptionalBinder(binder, CacheKeyProvider.class).setDefault().to(DefaultCacheKeyProvider.class).in(Scopes.SINGLETON); diff --git a/lib/trino-filesystem-manager/src/test/java/io/trino/filesystem/manager/TestFileSystemConfig.java b/lib/trino-filesystem-manager/src/test/java/io/trino/filesystem/manager/TestFileSystemConfig.java index 088d7653d53c..f7ee83b37534 100644 --- a/lib/trino-filesystem-manager/src/test/java/io/trino/filesystem/manager/TestFileSystemConfig.java +++ b/lib/trino-filesystem-manager/src/test/java/io/trino/filesystem/manager/TestFileSystemConfig.java @@ -33,6 +33,7 @@ public void testDefaults() .setNativeAzureEnabled(false) .setNativeS3Enabled(false) .setNativeGcsEnabled(false) + .setNativeLocalEnabled(false) .setCacheEnabled(false)); } @@ -45,6 +46,7 @@ public void testExplicitPropertyMappings() .put("fs.native-azure.enabled", "true") .put("fs.native-s3.enabled", "true") .put("fs.native-gcs.enabled", "true") + .put("fs.native-local.enabled", "true") .put("fs.cache.enabled", "true") .buildOrThrow(); @@ -54,6 +56,7 @@ public void testExplicitPropertyMappings() .setNativeAzureEnabled(true) .setNativeS3Enabled(true) .setNativeGcsEnabled(true) + .setNativeLocalEnabled(true) .setCacheEnabled(true); assertFullMapping(properties, expected); diff --git a/lib/trino-filesystem/src/main/java/io/trino/filesystem/local/LocalFileSystem.java b/lib/trino-filesystem/src/main/java/io/trino/filesystem/local/LocalFileSystem.java index b20d29a33d21..eba9b27014d0 100644 --- a/lib/trino-filesystem/src/main/java/io/trino/filesystem/local/LocalFileSystem.java +++ b/lib/trino-filesystem/src/main/java/io/trino/filesystem/local/LocalFileSystem.java @@ -273,7 +273,7 @@ private Path toDirectoryPath(Location location) private static void validateLocalLocation(Location location) { - checkArgument(location.scheme().equals(Optional.of("local")), "Only 'local' scheme is supported: %s", location); + checkArgument(location.scheme().equals(Optional.of("local")) || location.scheme().equals(Optional.of("file")), "Only 'local' and 'file' scheme is supported: %s", location); checkArgument(location.userInfo().isEmpty(), "Local location cannot contain user info: %s", location); checkArgument(location.host().isEmpty(), "Local location cannot contain a host: %s", location); } diff --git a/lib/trino-filesystem/src/main/java/io/trino/filesystem/local/LocalFileSystemConfig.java b/lib/trino-filesystem/src/main/java/io/trino/filesystem/local/LocalFileSystemConfig.java new file mode 100644 index 000000000000..38e7ff66d48b --- /dev/null +++ b/lib/trino-filesystem/src/main/java/io/trino/filesystem/local/LocalFileSystemConfig.java @@ -0,0 +1,41 @@ +/* + * 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 io.trino.filesystem.local; + +import io.airlift.configuration.Config; +import io.airlift.configuration.ConfigDescription; +import io.airlift.configuration.validation.FileExists; + +import java.nio.file.Path; +import java.nio.file.Paths; + +import static com.google.common.base.StandardSystemProperty.JAVA_IO_TMPDIR; + +public class LocalFileSystemConfig +{ + private Path location = Paths.get(System.getProperty(JAVA_IO_TMPDIR.key())); + + public @FileExists Path getLocation() + { + return location; + } + + @ConfigDescription("Local file system root directory") + @Config("local.location") + public LocalFileSystemConfig setLocation(Path location) + { + this.location = location; + return this; + } +} diff --git a/lib/trino-filesystem/src/main/java/io/trino/filesystem/local/LocalFileSystemFactory.java b/lib/trino-filesystem/src/main/java/io/trino/filesystem/local/LocalFileSystemFactory.java index 799ef7f332b7..791709327546 100644 --- a/lib/trino-filesystem/src/main/java/io/trino/filesystem/local/LocalFileSystemFactory.java +++ b/lib/trino-filesystem/src/main/java/io/trino/filesystem/local/LocalFileSystemFactory.java @@ -13,6 +13,7 @@ */ package io.trino.filesystem.local; +import com.google.inject.Inject; import io.trino.filesystem.TrinoFileSystem; import io.trino.filesystem.TrinoFileSystemFactory; import io.trino.spi.security.ConnectorIdentity; @@ -32,6 +33,12 @@ public LocalFileSystemFactory(Path rootPath) fileSystem = new LocalFileSystem(rootPath); } + @Inject + public LocalFileSystemFactory(LocalFileSystemConfig config) + { + this(config.getLocation()); + } + @Override public TrinoFileSystem create(ConnectorIdentity identity) { diff --git a/lib/trino-filesystem/src/test/java/io/trino/filesystem/local/TestLocalFileSystemConfig.java b/lib/trino-filesystem/src/test/java/io/trino/filesystem/local/TestLocalFileSystemConfig.java new file mode 100644 index 000000000000..631b69aebbc2 --- /dev/null +++ b/lib/trino-filesystem/src/test/java/io/trino/filesystem/local/TestLocalFileSystemConfig.java @@ -0,0 +1,50 @@ +/* + * 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 io.trino.filesystem.local; + +import com.google.common.collect.ImmutableMap; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; + +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Map; + +import static com.google.common.base.StandardSystemProperty.JAVA_IO_TMPDIR; +import static io.airlift.configuration.testing.ConfigAssertions.assertFullMapping; +import static io.airlift.configuration.testing.ConfigAssertions.assertRecordedDefaults; +import static io.airlift.configuration.testing.ConfigAssertions.recordDefaults; + +final class TestLocalFileSystemConfig +{ + @Test + void testDefaults() + { + assertRecordedDefaults(recordDefaults(LocalFileSystemConfig.class) + .setLocation(Paths.get(System.getProperty(JAVA_IO_TMPDIR.key())))); + } + + @Test + void testExplicitPropertyMappings(@TempDir Path tempDirectory) + { + Map properties = ImmutableMap.builder() + .put("local.location", tempDirectory.toString()) + .buildOrThrow(); + + LocalFileSystemConfig expected = new LocalFileSystemConfig() + .setLocation(tempDirectory); + + assertFullMapping(properties, expected); + } +}