-
Notifications
You must be signed in to change notification settings - Fork 76
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 hive hook configuration parameters for each hms #322
Changes from 2 commits
62678a8
5c69dfe
61609db
ab44690
0d67f26
1ff4846
9508e99
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 |
---|---|---|
|
@@ -15,23 +15,28 @@ | |
*/ | ||
package com.hotels.bdp.waggledance.mapping.model; | ||
|
||
import static org.hamcrest.CoreMatchers.instanceOf; | ||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.CoreMatchers.notNullValue; | ||
import static org.hamcrest.CoreMatchers.*; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
import static com.hotels.bdp.waggledance.api.model.AbstractMetaStore.newFederatedInstance; | ||
|
||
import java.io.File; | ||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.apache.hadoop.hive.metastore.DefaultMetaStoreFilterHookImpl; | ||
import org.apache.hadoop.hive.metastore.MetaStoreFilterHook; | ||
import org.apache.hadoop.hive.metastore.api.StorageDescriptor; | ||
import org.apache.hadoop.hive.metastore.api.Table; | ||
import org.apache.thrift.TException; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.TemporaryFolder; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.Mock; | ||
import org.mockito.Mockito; | ||
|
@@ -64,6 +69,7 @@ public class MetaStoreMappingFactoryImplTest { | |
new WaggleDanceConfiguration(), new SplitTrafficMetastoreClientFactory()); | ||
|
||
private MetaStoreMappingFactoryImpl factory; | ||
public @Rule TemporaryFolder temporaryFolder = new TemporaryFolder(); | ||
|
||
@Before | ||
public void init() { | ||
|
@@ -133,13 +139,36 @@ public void unreachableMetastoreClient() { | |
} | ||
} | ||
|
||
@Test | ||
public void loadMetastoreFilterHook(){ | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this empty? |
||
} | ||
|
||
@Test | ||
public void loadMetastoreFilterHookFromConfig() { | ||
AbstractMetaStore federatedMetaStore = newFederatedInstance("fed1", thrift.getThriftConnectionUri()); | ||
federatedMetaStore.setHiveMetastoreFilterHook(PrefixingMetastoreFilter.class.getName()); | ||
Map<String,String> metaStoreConfigurationProperties = new HashMap<>(); | ||
metaStoreConfigurationProperties.put(PrefixingMetastoreFilter.PREFIX_KEY,"prefix-test-"); | ||
federatedMetaStore.setConfigurationProperties(metaStoreConfigurationProperties); | ||
|
||
MetaStoreMapping mapping = factory.newInstance(federatedMetaStore); | ||
assertThat(mapping, is(notNullValue())); | ||
assertThat(mapping.getMetastoreFilter(), instanceOf(PrefixingMetastoreFilter.class)); | ||
|
||
MetaStoreFilterHook filterHook = mapping.getMetastoreFilter(); | ||
assertThat(filterHook, instanceOf(PrefixingMetastoreFilter.class)); | ||
|
||
Table table = new Table(); | ||
try { | ||
StorageDescriptor sd = new StorageDescriptor(); | ||
File localWarehouseUri = temporaryFolder.newFolder("local-warehouse"); | ||
sd.setLocation(new File(localWarehouseUri,"local_database/local_table").toURI().toString()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please try if a simple string also works, maybe we don't need to create a dummy folder just for string manupilations.: |
||
table.setSd(sd); | ||
|
||
String oldLocation=sd.getLocation(); | ||
assertThat(filterHook.filterTable(table).getSd().getLocation(), equalTo("prefix-test-" + oldLocation ) ); | ||
}catch (Exception e){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please remove try catch. No point in swallowing exceptions in test best to just throw it and let it fail the test. |
||
} | ||
} | ||
|
||
@Test | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,9 +33,12 @@ | |
* */ | ||
public class PrefixingMetastoreFilter implements MetaStoreFilterHook { | ||
|
||
public static final String PREFIX = "prefix-"; | ||
public static final String PREFIX_KEY = "hive.metastore.hooks.prefix"; | ||
public static final String PREFIX_DEFAULT = "prefix-"; | ||
private final String prefix; | ||
|
||
public PrefixingMetastoreFilter(HiveConf conf) { | ||
prefix = conf.get(PREFIX_KEY,PREFIX_DEFAULT); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
|
||
@Override | ||
|
@@ -140,7 +143,7 @@ private void setLocationPrefix(Partition partition) { | |
|
||
private void setLocationPrefix(StorageDescriptor sd) { | ||
String location = sd.getLocation(); | ||
sd.setLocation(PREFIX + location); | ||
sd.setLocation(prefix + location); | ||
} | ||
|
||
} |
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.
organize imports please