Skip to content

Commit

Permalink
Add location to polaris database entity (#500)
Browse files Browse the repository at this point in the history
  • Loading branch information
raveeram authored Jan 26, 2022
1 parent 1f2ac2d commit 2ad270c
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ drop table IF EXISTS DBS;
create table DBS (
version bigint not null,
id uuid default gen_random_uuid() not null primary key,
name varchar(255) not null unique
name varchar(255) not null unique,
location varchar(8192)
);

create table TBLS (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void create(final ConnectorRequestContext context, final DatabaseInfo dat
throw new DatabaseAlreadyExistsException(name);
}
try {
this.polarisStoreService.createDatabase(name.getDatabaseName());
this.polarisStoreService.createDatabase(name.getDatabaseName(), null /* TODO: add default */);
} catch (DataIntegrityViolationException exception) {
throw new InvalidMetaException(name, exception);
} catch (Exception exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ public class PolarisStoreConnector implements PolarisStoreService {
* @return entity
*/
@Override
public PolarisDatabaseEntity createDatabase(final String databaseName) {
final PolarisDatabaseEntity e = new PolarisDatabaseEntity(databaseName);
public PolarisDatabaseEntity createDatabase(final String databaseName,
final String location) {
final PolarisDatabaseEntity e = new PolarisDatabaseEntity(databaseName, location);
return dbRepo.save(e);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ public interface PolarisStoreService {
/**
* Creates a database entry.
* @param databaseName database name
* @param location the database location.
* @return Polaris Database entity.
*/
PolarisDatabaseEntity createDatabase(String databaseName);
PolarisDatabaseEntity createDatabase(String databaseName, String location);

/**
* Fetches database entry.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,18 @@ public class PolarisDatabaseEntity {
@Column(name = "name", nullable = false, unique = true, updatable = false)
private String dbName;

@Basic
@Column(name = "location", updatable = false)
private String location;

/**
* Constructor for Polaris Database Entity.
* @param dbName database name
* @param location database location.
*/
public PolarisDatabaseEntity(final String dbName) {
public PolarisDatabaseEntity(final String dbName,
final String location) {
this.dbName = dbName;
this.location = location;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ private static String generateTableName() {
}

private PolarisDatabaseEntity createDB(final String dbName) {
final PolarisDatabaseEntity entity = polarisConnector.createDatabase(dbName);
final String location = "file://temp";
final PolarisDatabaseEntity entity = polarisConnector.createDatabase(dbName, location);

// assert that database exists, post-creation.
Assert.assertTrue(polarisConnector.databaseExistsById(entity.getDbId()));
Expand All @@ -61,6 +62,7 @@ private PolarisDatabaseEntity createDB(final String dbName) {
Assert.assertEquals(0L, entity.getVersion().longValue());
Assert.assertTrue(entity.getDbId().length() > 0);
Assert.assertEquals(dbName, entity.getDbName());
Assert.assertEquals(location, entity.getLocation());

final Optional<PolarisDatabaseEntity> fetchedEntity = polarisConnector.getDatabase(dbName);
Assert.assertTrue(fetchedEntity.isPresent());
Expand Down
3 changes: 2 additions & 1 deletion metacat-connector-polaris/src/test/resources/h2db/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ drop table DBS if exists;
create table DBS (
version bigint not null,
id IDENTITY not null primary key,
name varchar(255) not null unique
name varchar(255) not null unique,
location varchar(1024)
);

create table TBLS (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@ drop table IF EXISTS TBLS;
drop table IF EXISTS DBS;

create table DBS (
version bigint not null,
id uuid default gen_random_uuid() not null primary key,
name varchar(255) not null unique
version bigint not null,
id uuid default gen_random_uuid() not null primary key,
name varchar(255) not null unique,
location varchar(8192)
);

create table TBLS (
version bigint not null,
id uuid default gen_random_uuid() not null primary key,
db_name varchar(255) not null,
tbl_name varchar(255) not null,
previous_metadata_location varchar(8192),
metadata_location varchar(8192),
constraint uniq_name unique(db_name, tbl_name),
foreign key (db_name) references DBS(name) ON DELETE CASCADE ON UPDATE CASCADE
version bigint not null,
id uuid default gen_random_uuid() not null primary key,
db_name varchar(255) not null,
tbl_name varchar(255) not null,
previous_metadata_location varchar(8192),
metadata_location varchar(8192),
constraint uniq_name unique(db_name, tbl_name),
foreign key (db_name) references DBS(name) ON DELETE CASCADE ON UPDATE CASCADE
);

0 comments on commit 2ad270c

Please sign in to comment.