Merge pull request #2933 from dclim/SQLMetadataSupervisorManagerTest-fix

add uuid to primary key for supervisor table
This commit is contained in:
David Lim 2016-05-09 10:41:32 -06:00
parent 90b0b0a4ad
commit 2cfd337378
2 changed files with 10 additions and 12 deletions

View File

@ -373,13 +373,13 @@ public abstract class SQLMetadataConnector implements MetadataStorageConnector
ImmutableList.of( ImmutableList.of(
String.format( String.format(
"CREATE TABLE %1$s (\n" "CREATE TABLE %1$s (\n"
+ " id VARCHAR(255) NOT NULL,\n" + " id %2$s NOT NULL,\n"
+ " spec_id VARCHAR(255) NOT NULL,\n" + " spec_id VARCHAR(255) NOT NULL,\n"
+ " version VARCHAR(255) NOT NULL,\n" + " created_date VARCHAR(255) NOT NULL,\n"
+ " payload %2$s NOT NULL,\n" + " payload %3$s NOT NULL,\n"
+ " PRIMARY KEY (id)\n" + " PRIMARY KEY (id)\n"
+ ")", + ")",
tableName, getPayloadType() tableName, getSerialType(), getPayloadType()
), ),
String.format("CREATE INDEX idx_%1$s_spec_id ON %1$s(spec_id)", tableName) String.format("CREATE INDEX idx_%1$s_spec_id ON %1$s(spec_id)", tableName)
) )

View File

@ -84,16 +84,14 @@ public class SQLMetadataSupervisorManager implements MetadataSupervisorManager
@Override @Override
public Void withHandle(Handle handle) throws Exception public Void withHandle(Handle handle) throws Exception
{ {
final String version = new DateTime().toString();
handle.createStatement( handle.createStatement(
String.format( String.format(
"INSERT INTO %s (id, spec_id, version, payload) VALUES (:id, :spec_id, :version, :payload)", "INSERT INTO %s (spec_id, created_date, payload) VALUES (:spec_id, :created_date, :payload)",
getSupervisorsTable() getSupervisorsTable()
) )
) )
.bind("id", String.format("%s_%s", id, version))
.bind("spec_id", id) .bind("spec_id", id)
.bind("version", version) .bind("created_date", new DateTime().toString())
.bind("payload", jsonMapper.writeValueAsBytes(spec)) .bind("payload", jsonMapper.writeValueAsBytes(spec))
.execute(); .execute();
@ -115,7 +113,7 @@ public class SQLMetadataSupervisorManager implements MetadataSupervisorManager
{ {
return handle.createQuery( return handle.createQuery(
String.format( String.format(
"SELECT spec_id, version, payload FROM %1$s ORDER BY version DESC", "SELECT id, spec_id, created_date, payload FROM %1$s ORDER BY id DESC",
getSupervisorsTable() getSupervisorsTable()
) )
).map( ).map(
@ -134,7 +132,7 @@ public class SQLMetadataSupervisorManager implements MetadataSupervisorManager
); );
return Pair.of( return Pair.of(
r.getString("spec_id"), r.getString("spec_id"),
new VersionedSupervisorSpec(payload, r.getString("version")) new VersionedSupervisorSpec(payload, r.getString("created_date"))
); );
} }
catch (IOException e) { catch (IOException e) {
@ -189,8 +187,8 @@ public class SQLMetadataSupervisorManager implements MetadataSupervisorManager
String.format( String.format(
"SELECT r.spec_id, r.payload " "SELECT r.spec_id, r.payload "
+ "FROM %1$s r " + "FROM %1$s r "
+ "INNER JOIN(SELECT spec_id, max(version) as version FROM %1$s GROUP BY spec_id) latest " + "INNER JOIN(SELECT spec_id, max(id) as id FROM %1$s GROUP BY spec_id) latest "
+ "ON r.spec_id = latest.spec_id and r.version = latest.version", + "ON r.id = latest.id",
getSupervisorsTable() getSupervisorsTable()
) )
).map( ).map(