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

removed check for prefix so we can fallback to empty #174

Merged
merged 3 commits into from
Jun 6, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [3.3.2] - TBD
### Changed
* Changed a prefixed *primary* metastore to fallback to 'empty prefix' if nothing specified. See [#173](https://github.com/HotelsDotCom/waggle-dance/issues/173).

## [3.3.1] - 2019-05-20
### Fixed
* `Show Functions` now shows UDFs from all metastores. See [#164](https://github.com/HotelsDotCom/waggle-dance/issues/164).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,10 @@ public Database transformOutboundDatabase(Database database) {
@Override
public String transformInboundDatabaseName(String databaseName) {
databaseName = databaseName.toLowerCase(Locale.ROOT);
if (!databaseName.startsWith(getDatabasePrefix())) {
throw new IllegalArgumentException(
"Database '" + databaseName + "' does not start with prefix '" + getDatabasePrefix() + "'");
if (databaseName.startsWith(getDatabasePrefix())) {
return databaseName.substring(getDatabasePrefix().length());
}
return databaseName.substring(getDatabasePrefix().length());
return databaseName;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ public void transformInboundDatabaseName() {
assertThat(metaStoreMapping.transformInboundDatabaseName("Prefix_My_Database"), is("my_database"));
}

@Test(expected = IllegalArgumentException.class)
public void transformInboundDatabaseNameFails() {
metaStoreMapping.transformInboundDatabaseName("waggle_database");
@Test
public void transformInboundDatabaseNameWithoutPrefixReturnsDatabase() {
assertThat(metaStoreMapping.transformInboundDatabaseName("no_prefix_My_Database"), is("no_prefix_my_database"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,22 +276,17 @@ public void usePrimaryPrefix() throws Exception {
HiveMetaStoreClient proxy = getWaggleDanceClient();

// Local table
String waggledLocalDbName = primaryPrefix + LOCAL_DATABASE;
assertPrefixedLocalTable(proxy, waggledLocalDbName);
String prefixedLocalDbName = primaryPrefix + LOCAL_DATABASE;
Table localTable = proxy.getTable(prefixedLocalDbName, LOCAL_TABLE);
assertThat(localTable.getDbName(), is(prefixedLocalDbName));

// Remote table
String waggledRemoteDbName = PREFIXED_REMOTE_DATABASE;
assertTypicalRemoteTable(proxy, waggledRemoteDbName);
}
// fetch without prefix works and result is prefixed
Table localTable2 = proxy.getTable(LOCAL_DATABASE, LOCAL_TABLE);
assertThat(localTable2.getDbName(), is(prefixedLocalDbName));

private void assertPrefixedLocalTable(HiveMetaStoreClient proxy, String waggledLocalDbName) throws TException {
Table localTable = localServer.client().getTable(LOCAL_DATABASE, LOCAL_TABLE);
Table waggledLocalTable = proxy.getTable(waggledLocalDbName, LOCAL_TABLE);
assertThat(waggledLocalTable.getDbName(), is(waggledLocalDbName));
assertThat(waggledLocalTable.getTableName(), is(localTable.getTableName()));
assertThat(waggledLocalTable.getSd(), is(localTable.getSd()));
assertThat(waggledLocalTable.getParameters(), is(localTable.getParameters()));
assertThat(waggledLocalTable.getPartitionKeys(), is(localTable.getPartitionKeys()));
// Remote table
String prefixedRemoteDbName = PREFIXED_REMOTE_DATABASE;
assertTypicalRemoteTable(proxy, prefixedRemoteDbName);
}

private void assertTypicalRemoteTable(HiveMetaStoreClient proxy, String waggledRemoteDbName) throws TException {
Expand Down