Skip to content
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

Add support for Azure Blob #641

Open
wants to merge 2 commits into
base: release-0.179-t
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@
<dependency>
<groupId>com.facebook.presto.hadoop</groupId>
<artifactId>hadoop-apache2</artifactId>
<version>2.7.3-1</version>
<version>2.7.3-2</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,11 @@ public class HdfsConfigurationUpdater
private final File s3StagingDirectory;
private final boolean pinS3ClientToCurrentRegion;
private final String s3UserAgentPrefix;
private final String wasbAccessKey;
private final String wasbStorageAccount;

@Inject
public HdfsConfigurationUpdater(HiveClientConfig hiveClientConfig, HiveS3Config s3Config)
public HdfsConfigurationUpdater(HiveClientConfig hiveClientConfig, HiveS3Config s3Config, HiveWasbConfig wasbConfig)
{
requireNonNull(hiveClientConfig, "hiveClientConfig is null");
checkArgument(hiveClientConfig.getDfsTimeout().toMillis() >= 1, "dfsTimeout must be at least 1 ms");
Expand Down Expand Up @@ -115,6 +117,9 @@ public HdfsConfigurationUpdater(HiveClientConfig hiveClientConfig, HiveS3Config
this.s3StagingDirectory = s3Config.getS3StagingDirectory();
this.pinS3ClientToCurrentRegion = s3Config.isPinS3ClientToCurrentRegion();
this.s3UserAgentPrefix = s3Config.getS3UserAgentPrefix();

this.wasbAccessKey = wasbConfig.getWasbAccessKey();
this.wasbStorageAccount = wasbConfig.getWasbStorageAccount();
}

private static Configuration readConfiguration(List<String> resourcePaths)
Expand Down Expand Up @@ -208,6 +213,11 @@ public void updateConfiguration(PrestoHadoopConfiguration config)
config.setLong(PrestoS3FileSystem.S3_MULTIPART_MIN_PART_SIZE, s3MultipartMinPartSize.toBytes());
config.setBoolean(PrestoS3FileSystem.S3_PIN_CLIENT_TO_CURRENT_REGION, pinS3ClientToCurrentRegion);
config.set(PrestoS3FileSystem.S3_USER_AGENT_PREFIX, s3UserAgentPrefix);

// set config for Azure Blob
if (wasbAccessKey != null && wasbStorageAccount != null) {
config.set(String.format("fs.azure.account.key.%s.blob.core.windows.net", wasbStorageAccount), wasbAccessKey);
}
}

public static void configureCompression(Configuration config, HiveCompressionCodec compressionCodec)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public void configure(Binder binder)
binder.bind(DirectoryLister.class).to(HadoopDirectoryLister.class).in(Scopes.SINGLETON);
configBinder(binder).bindConfig(HiveClientConfig.class);
configBinder(binder).bindConfig(HiveS3Config.class);
configBinder(binder).bindConfig(HiveWasbConfig.class);

binder.bind(HiveSessionProperties.class).in(Scopes.SINGLETON);
binder.bind(HiveTableProperties.class).in(Scopes.SINGLETON);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* 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 io.airlift.configuration.Config;
import io.airlift.configuration.ConfigSecuritySensitive;

public class HiveWasbConfig
{
private String wasbStorageAccount;
private String wasbAccessKey;

public String getWasbStorageAccount()
{
return wasbStorageAccount;
}

@ConfigSecuritySensitive
@Config("hive.wasb.storage-account")
public HiveWasbConfig setWasbStorageAccount(String wasbStorageAccount)
{
this.wasbStorageAccount = wasbStorageAccount;
return this;
}

public String getWasbAccessKey()
{
return wasbAccessKey;
}

@ConfigSecuritySensitive
@Config("hive.wasb.access-key")
public HiveWasbConfig setWasbAccessKey(String wasbAccessKey)
{
this.wasbAccessKey = wasbAccessKey;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ protected final void setup(String databaseName, HiveClientConfig hiveClientConfi
setupHive(connectorId.toString(), databaseName, hiveClientConfig.getTimeZone());

metastoreClient = hiveMetastore;
HdfsConfiguration hdfsConfiguration = new HiveHdfsConfiguration(new HdfsConfigurationUpdater(hiveClientConfig, new HiveS3Config()));
HdfsConfiguration hdfsConfiguration = new HiveHdfsConfiguration(new HdfsConfigurationUpdater(hiveClientConfig, new HiveS3Config(), new HiveWasbConfig()));
hdfsEnvironment = new HdfsEnvironment(hdfsConfiguration, hiveClientConfig, new NoHdfsAuthentication());
locationService = new HiveLocationService(hdfsEnvironment);
JsonCodec<PartitionUpdate> partitionUpdateCodec = JsonCodec.jsonCodec(PartitionUpdate.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ protected void setup(String host, int port, String databaseName, String awsAcces
HiveConnectorId connectorId = new HiveConnectorId("hive-test");
HiveCluster hiveCluster = new TestingHiveCluster(hiveClientConfig, host, port);
ExecutorService executor = newCachedThreadPool(daemonThreadsNamed("hive-s3-%s"));
HdfsConfiguration hdfsConfiguration = new HiveHdfsConfiguration(new HdfsConfigurationUpdater(hiveClientConfig, s3Config));
HdfsConfiguration hdfsConfiguration = new HiveHdfsConfiguration(new HdfsConfigurationUpdater(hiveClientConfig, s3Config, new HiveWasbConfig()));
HivePartitionManager hivePartitionManager = new HivePartitionManager(connectorId, TYPE_MANAGER, hiveClientConfig);

hdfsEnvironment = new HdfsEnvironment(hdfsConfiguration, hiveClientConfig, new NoHdfsAuthentication());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public static DistributedQueryRunner createQueryRunner(Iterable<TpchTable<?>> ta

HiveClientConfig hiveClientConfig = new HiveClientConfig();
HiveS3Config s3Config = new HiveS3Config();
HdfsConfiguration hdfsConfiguration = new HiveHdfsConfiguration(new HdfsConfigurationUpdater(hiveClientConfig, s3Config));
HdfsConfiguration hdfsConfiguration = new HiveHdfsConfiguration(new HdfsConfigurationUpdater(hiveClientConfig, s3Config, new HiveWasbConfig()));
HdfsEnvironment hdfsEnvironment = new HdfsEnvironment(hdfsConfiguration, hiveClientConfig, new NoHdfsAuthentication());

FileHiveMetastore metastore = new FileHiveMetastore(hdfsEnvironment, baseDir.toURI().toString(), "test");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@ public static List<Type> getTypes(List<? extends ColumnHandle> columnHandles)

public static HdfsEnvironment createTestHdfsEnvironment(HiveClientConfig config)
{
return createTestHdfsEnvironment(config, new HiveS3Config());
return createTestHdfsEnvironment(config, new HiveS3Config(), new HiveWasbConfig());
}

public static HdfsEnvironment createTestHdfsEnvironment(HiveClientConfig hiveConfig, HiveS3Config s3Config)
public static HdfsEnvironment createTestHdfsEnvironment(HiveClientConfig hiveConfig, HiveS3Config s3Config, HiveWasbConfig wasbConfig)
{
HdfsConfiguration hdfsConfig = new HiveHdfsConfiguration(new HdfsConfigurationUpdater(hiveConfig, s3Config));
HdfsConfiguration hdfsConfig = new HiveHdfsConfiguration(new HdfsConfigurationUpdater(hiveConfig, s3Config, wasbConfig));
return new HdfsEnvironment(hdfsConfig, hiveConfig, new NoHdfsAuthentication());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ protected ExtendedHiveMetastore createMetastore(File tempDir)
{
File baseDir = new File(tempDir, "metastore");
HiveClientConfig hiveConfig = new HiveClientConfig();
HdfsConfigurationUpdater updator = new HdfsConfigurationUpdater(hiveConfig, new HiveS3Config());
HdfsConfigurationUpdater updator = new HdfsConfigurationUpdater(hiveConfig, new HiveS3Config(), new HiveWasbConfig());
HdfsConfiguration hdfsConfiguration = new HiveHdfsConfiguration(updator);
HdfsEnvironment hdfsEnvironment = new HdfsEnvironment(hdfsConfiguration, hiveConfig, new NoHdfsAuthentication());
return new FileHiveMetastore(hdfsEnvironment, baseDir.toURI().toString(), "test");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* 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.google.common.collect.ImmutableMap;
import org.testng.annotations.Test;

import java.util.Map;

import static io.airlift.configuration.testing.ConfigAssertions.assertFullMapping;
import static io.airlift.configuration.testing.ConfigAssertions.assertRecordedDefaults;
import static io.airlift.configuration.testing.ConfigAssertions.recordDefaults;

public class TestHiveWasbConfig
{
@Test
public void testDefaults()
{
assertRecordedDefaults(recordDefaults(HiveWasbConfig.class)
.setWasbAccessKey(null)
.setWasbStorageAccount(null));
}

@Test
public void testExplicitPropertyMappings()
{
Map<String, String> properties = new ImmutableMap.Builder<String, String>()
.put("hive.wasb.storage-account", "testwasbstorage")
.put("hive.wasb.access-key", "secret")
.build();

HiveWasbConfig expected = new HiveWasbConfig()
.setWasbStorageAccount("testwasbstorage")
.setWasbAccessKey("secret");

assertFullMapping(properties, expected);
}
}