Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -33,30 +33,43 @@ public class TestDeltaLakePlugin
@Test
public void testCreateConnector()
{
Plugin plugin = new DeltaLakePlugin();
ConnectorFactory factory = getOnlyElement(plugin.getConnectorFactories());
factory.create("test", ImmutableMap.of("hive.metastore.uri", "thrift://foo:1234"), new TestingConnectorContext());
ConnectorFactory factory = getConnectorFactory();
factory.create("test", ImmutableMap.of("hive.metastore.uri", "thrift://foo:1234"), new TestingConnectorContext())
.shutdown();
}

@Test
public void testCreateTestingConnector()
{
Plugin plugin = new TestingDeltaLakePlugin();
ConnectorFactory factory = getOnlyElement(plugin.getConnectorFactories());
factory.create("test", ImmutableMap.of("hive.metastore.uri", "thrift://foo:1234"), new TestingConnectorContext());
factory.create("test", ImmutableMap.of("hive.metastore.uri", "thrift://foo:1234"), new TestingConnectorContext())
.shutdown();
}

@Test
public void testTestingFileMetastore()
{
ConnectorFactory factory = getConnectorFactory();
factory.create(
"test",
ImmutableMap.of(
"hive.metastore", "file",
"hive.metastore.catalog.dir", "/tmp"),
new TestingConnectorContext())
.shutdown();
}

@Test
public void testThriftMetastore()
{
Plugin plugin = new DeltaLakePlugin();
ConnectorFactory factory = getOnlyElement(plugin.getConnectorFactories());
ConnectorFactory factory = getConnectorFactory();
factory.create(
"test",
ImmutableMap.of(
"hive.metastore", "thrift",
"hive.metastore.uri", "thrift://foo:1234"),
new TestingConnectorContext())
"test",
ImmutableMap.of(
"hive.metastore", "thrift",
"hive.metastore.uri", "thrift://foo:1234"),
new TestingConnectorContext())
.shutdown();

assertThatThrownBy(() -> factory.create(
Expand All @@ -74,14 +87,14 @@ public void testThriftMetastore()
@Test
public void testGlueMetastore()
{
Plugin plugin = new DeltaLakePlugin();
ConnectorFactory factory = getOnlyElement(plugin.getConnectorFactories());
ConnectorFactory factory = getConnectorFactory();
factory.create(
"test",
ImmutableMap.of(
"hive.metastore", "glue",
"hive.metastore.glue.region", "us-east-2"),
new TestingConnectorContext());
"test",
ImmutableMap.of(
"hive.metastore", "glue",
"hive.metastore.glue.region", "us-east-2"),
new TestingConnectorContext())
.shutdown();

assertThatThrownBy(() -> factory.create(
"test",
Expand All @@ -100,9 +113,7 @@ public void testGlueMetastore()
@Test
public void testAlluxioMetastore()
{
Plugin plugin = new DeltaLakePlugin();
ConnectorFactory factory = getOnlyElement(plugin.getConnectorFactories());

ConnectorFactory factory = getConnectorFactory();
assertThatThrownBy(() -> factory.create(
"test",
ImmutableMap.of("hive.metastore", "alluxio"),
Expand All @@ -121,31 +132,31 @@ public void testAlluxioMetastore()
@Test
public void testNoCaching()
{
Plugin plugin = new DeltaLakePlugin();
ConnectorFactory factory = getOnlyElement(plugin.getConnectorFactories());
ConnectorFactory factory = getConnectorFactory();
factory.create("test",
ImmutableMap.of(
"hive.metastore.uri", "thrift://foo:1234",
"delta.metadata.cache-ttl", "0s"),
new TestingConnectorContext());
ImmutableMap.of(
"hive.metastore.uri", "thrift://foo:1234",
"delta.metadata.cache-ttl", "0s"),
new TestingConnectorContext())
.shutdown();
}

@Test
public void testNoActiveDataFilesCaching()
{
Plugin plugin = new DeltaLakePlugin();
ConnectorFactory factory = getOnlyElement(plugin.getConnectorFactories());
ConnectorFactory factory = getConnectorFactory();
factory.create("test",
ImmutableMap.of(
"hive.metastore.uri", "thrift://foo:1234",
"delta.metadata.live-files.cache-ttl", "0s"),
new TestingConnectorContext());
ImmutableMap.of(
"hive.metastore.uri", "thrift://foo:1234",
"delta.metadata.live-files.cache-ttl", "0s"),
new TestingConnectorContext())
.shutdown();
}

@Test
public void testHiveConfigIsNotBound()
{
ConnectorFactory factory = getOnlyElement(new DeltaLakePlugin().getConnectorFactories());
ConnectorFactory factory = getConnectorFactory();
assertThatThrownBy(() -> factory.create("test",
ImmutableMap.of(
"hive.metastore.uri", "thrift://foo:1234",
Expand All @@ -158,9 +169,7 @@ public void testHiveConfigIsNotBound()
@Test
public void testReadOnlyAllAccessControl()
{
Plugin plugin = new DeltaLakePlugin();
ConnectorFactory factory = getOnlyElement(plugin.getConnectorFactories());

ConnectorFactory factory = getConnectorFactory();
factory.create(
"test",
ImmutableMap.<String, String>builder()
Expand All @@ -174,9 +183,7 @@ public void testReadOnlyAllAccessControl()
@Test
public void testSystemAccessControl()
{
Plugin plugin = new DeltaLakePlugin();
ConnectorFactory factory = getOnlyElement(plugin.getConnectorFactories());

ConnectorFactory factory = getConnectorFactory();
Connector connector = factory.create(
"test",
ImmutableMap.<String, String>builder()
Expand All @@ -192,8 +199,7 @@ public void testSystemAccessControl()
public void testFileBasedAccessControl()
throws Exception
{
Plugin plugin = new DeltaLakePlugin();
ConnectorFactory factory = getOnlyElement(plugin.getConnectorFactories());
ConnectorFactory factory = getConnectorFactory();
File tempFile = File.createTempFile("test-delta-lake-plugin-access-control", ".json");
tempFile.deleteOnExit();
Files.writeString(tempFile.toPath(), "{}");
Expand All @@ -208,4 +214,9 @@ public void testFileBasedAccessControl()
new TestingConnectorContext())
.shutdown();
}

private static ConnectorFactory getConnectorFactory()
{
return getOnlyElement(new DeltaLakePlugin().getConnectorFactories());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,19 @@ public void testCreateConnector()
factory.create("test", ImmutableMap.of("hive.metastore.uri", "thrift://foo:1234"), new TestingConnectorContext()).shutdown();
}

@Test
public void testTestingFileMetastore()
{
ConnectorFactory factory = getHiveConnectorFactory();
factory.create(
"test",
ImmutableMap.of(
"hive.metastore", "file",
"hive.metastore.catalog.dir", "/tmp"),
new TestingConnectorContext())
.shutdown();
}

@Test
public void testThriftMetastore()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import io.trino.plugin.base.classloader.ClassLoaderSafeNodePartitioningProvider;
import io.trino.plugin.base.jmx.MBeanServerModule;
import io.trino.plugin.base.session.SessionPropertiesProvider;
import io.trino.plugin.hive.NodeVersion;
import io.trino.plugin.hive.azure.HiveAzureModule;
import io.trino.plugin.hive.gcs.HiveGcsModule;
import io.trino.plugin.hive.metastore.HiveMetastore;
Expand All @@ -49,7 +50,7 @@
import java.util.Optional;
import java.util.Set;

public class InternalHudiConnectorFactory
public final class InternalHudiConnectorFactory
{
private InternalHudiConnectorFactory() {}

Expand All @@ -75,6 +76,7 @@ public static Connector createConnector(
new HdfsFileSystemModule(),
new MBeanServerModule(),
binder -> {
binder.bind(NodeVersion.class).toInstance(new NodeVersion(context.getNodeManager().getCurrentNode().getVersion()));
binder.bind(NodeManager.class).toInstance(context.getNodeManager());
binder.bind(TypeManager.class).toInstance(context.getTypeManager());
binder.bind(CatalogName.class).toInstance(new CatalogName(catalogName));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/*
* 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.plugin.hudi;

import com.google.common.collect.ImmutableMap;
import io.airlift.bootstrap.ApplicationConfigurationException;
import io.trino.plugin.hive.HiveConfig;
import io.trino.spi.Plugin;
import io.trino.spi.connector.ConnectorFactory;
import io.trino.testing.TestingConnectorContext;
import org.testng.annotations.Test;

import java.util.Map;
import java.util.Optional;

import static com.google.common.collect.Iterables.getOnlyElement;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

public class TestHudiPlugin
{
@Test
public void testCreateConnector()
{
ConnectorFactory factory = getConnectorFactory();
factory.create("test", Map.of("hive.metastore.uri", "thrift://foo:1234"), new TestingConnectorContext())
.shutdown();
}

@Test
public void testCreateTestingConnector()
{
Plugin plugin = new TestingHudiPlugin(Optional.empty());
ConnectorFactory factory = getOnlyElement(plugin.getConnectorFactories());
factory.create("test", Map.of("hive.metastore.uri", "thrift://foo:1234"), new TestingConnectorContext())
.shutdown();
}

@Test
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: you could have added that in previous commit; just marked as ignored with comment.
And here just fix and unignore.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed. or i could add it as a failing test, showing failure, and then showing the fix.
i think it doesn't matter for the long-term, and don't want to overload the CI queue, so will merge as is

public void testTestingFileMetastore()
{
ConnectorFactory factory = getConnectorFactory();
factory.create(
"test",
ImmutableMap.of(
"hive.metastore", "file",
"hive.metastore.catalog.dir", "/tmp"),
new TestingConnectorContext())
.shutdown();
}

@Test
public void testThriftMetastore()
{
ConnectorFactory factory = getConnectorFactory();
factory.create(
"test",
Map.of(
"hive.metastore", "thrift",
"hive.metastore.uri", "thrift://foo:1234"),
new TestingConnectorContext())
.shutdown();
}

@Test
public void testGlueMetastore()
{
ConnectorFactory factory = getConnectorFactory();
factory.create(
"test",
Map.of(
"hive.metastore", "glue",
"hive.metastore.glue.region", "us-east-2"),
new TestingConnectorContext())
.shutdown();

assertThatThrownBy(() -> factory.create(
"test",
Map.of(
"hive.metastore", "glue",
"hive.metastore.uri", "thrift://foo:1234"),
new TestingConnectorContext()))
.isInstanceOf(ApplicationConfigurationException.class)
.hasMessageContaining("Error: Configuration property 'hive.metastore.uri' was not used");
}

@Test
public void testAlluxioMetastore()
{
ConnectorFactory factory = getConnectorFactory();
assertThatThrownBy(() -> factory.create(
"test",
Map.of("hive.metastore", "alluxio"),
new TestingConnectorContext()))
.hasMessageMatching("(?s)Unable to create injector, see the following errors:.*" +
"Explicit bindings are required and HiveMetastoreFactory .* is not explicitly bound.*");

assertThatThrownBy(() -> factory.create(
"test",
Map.of("hive.metastore", "alluxio-deprecated"),
new TestingConnectorContext()))
// TODO: this should fail cleanly. We do not plan to support Alluxio metastore with Hudi
.hasStackTraceContaining("Cannot invoke \"String.split(String, int)\" because \"addr\" is null");
}

@Test
public void testHiveConfigIsNotBound()
{
ConnectorFactory factory = getConnectorFactory();
assertThatThrownBy(() -> factory.create("test",
Map.of(
"hive.metastore.uri", "thrift://foo:1234",
// Try setting any property provided by HiveConfig class
HiveConfig.CONFIGURATION_HIVE_PARTITION_PROJECTION_ENABLED, "true"),
new TestingConnectorContext()))
.hasMessageContaining("Error: Configuration property 'hive.partition-projection-enabled' was not used");
}

private static ConnectorFactory getConnectorFactory()
{
return getOnlyElement(new HudiPlugin().getConnectorFactories());
}
}
Loading