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 hive hook configuration parameters for each hms #322

Merged
merged 7 commits into from
Jul 30, 2024
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 @@ -108,6 +108,12 @@ private MetaStoreFilterHook loadMetastoreFilterHook(AbstractMetaStore metaStore)
conf.set(property.getKey(), property.getValue());
}
}
Map<String, String> metaConfigurationProperties = metaStore.getConfigurationProperties();
if (metaConfigurationProperties != null) {
for (Map.Entry<String, String> property : metaConfigurationProperties.entrySet()) {
conf.set(property.getKey(), property.getValue());
}
}
conf.set(HiveConf.ConfVars.METASTORE_FILTER_HOOK.varname, metaStoreFilterHook);
try {
Class<? extends MetaStoreFilterHook> filterHookClass = conf
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.verify;
Expand All @@ -26,8 +27,13 @@
import static com.hotels.bdp.waggledance.api.model.AbstractMetaStore.newFederatedInstance;

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;
Expand Down Expand Up @@ -149,4 +155,26 @@ public void loadDefaultMetastoreFilterHook() {
assertThat(mapping, is(notNullValue()));
assertThat(mapping.getMetastoreFilter(), instanceOf(DefaultMetaStoreFilterHookImpl.class));
}

@Test
public void loadMetastoreFilterHookWithCustomConfig() throws Exception{
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()));
MetaStoreFilterHook filterHook = mapping.getMetastoreFilter();
assertThat(filterHook, instanceOf(PrefixingMetastoreFilter.class));

Table table = new Table();
StorageDescriptor sd = new StorageDescriptor();
sd.setLocation("file:///tmp/local_database/local_table");
table.setSd(sd);

String oldLocation=sd.getLocation();
assertThat(filterHook.filterTable(table).getSd().getLocation(), equalTo("prefix-test-" + oldLocation ) );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@
* */
public class PrefixingMetastoreFilter implements MetaStoreFilterHook {

public static final String PREFIX = "prefix-";
public static final String PREFIX_KEY = "waggledance.hook.prefix";
public static final String PREFIX_DEFAULT = "prefix-";
private final String prefix;

public PrefixingMetastoreFilter(HiveConf conf) {
prefix = conf.get(PREFIX_KEY,PREFIX_DEFAULT);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is PREFIX_KEY meaningless? Is it ok just use hardcode to determine if it is the same as "prefix -".

Copy link
Contributor

Choose a reason for hiding this comment

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

Because of ab44690 and 0d67f26, I think it's okay

}

@Override
Expand Down Expand Up @@ -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);
}

}
Loading