PostgresSQL integration with druid

This commit is contained in:
Pablo Nebrera 2013-06-28 12:49:24 +02:00
parent b6e198ffb6
commit e9ce6b596c
4 changed files with 15 additions and 14 deletions

View File

@ -140,15 +140,16 @@ public class DbConnector
@Override
public Void withHandle(Handle handle) throws Exception
{
List<Map<String, Object>> table = handle.select(String.format("SHOW tables LIKE '%s'", tableName));
if ( !handle.getConnection().getMetaData().getDatabaseProductName().contains("PostgreSQL") ) {
List<Map<String, Object>> table = handle.select(String.format("SHOW tables LIKE '%s'", tableName));
if (table.isEmpty()) {
log.info("Creating table[%s]", tableName);
handle.createStatement(sql).execute();
} else {
log.info("Table[%s] existed: [%s]", tableName, table);
if (table.isEmpty()) {
log.info("Creating table[%s]", tableName);
handle.createStatement(sql).execute();
} else {
log.info("Table[%s] existed: [%s]", tableName, table);
}
}
return null;
}
}

View File

@ -62,7 +62,7 @@ public class DbSegmentPublisher implements SegmentPublisher
{
handle.createStatement(
String.format(
"INSERT INTO %s (id, dataSource, created_date, start, end, partitioned, version, used, payload) "
"INSERT INTO %s (id, dataSource, created_date, start, \"end\", partitioned, version, used, payload) "
+ "VALUES (:id, :dataSource, :created_date, :start, :end, :partitioned, :version, :used, :payload)",
config.getSegmentTable()
)

View File

@ -192,7 +192,7 @@ public class DatabaseRuleManager
return handle.createQuery(
// Return latest version rule by dataSource
String.format(
"SELECT %1$s.dataSource, %1$s.payload FROM %1$s INNER JOIN(SELECT dataSource, max(version) as version, payload FROM %1$s GROUP BY dataSource) ds ON %1$s.datasource = ds.datasource and %1$s.version = ds.version",
"SELECT %1$s.dataSource, %1$s.payload FROM %1$s INNER JOIN(SELECT dataSource, max(version) as version FROM %1$s GROUP BY dataSource) ds ON %1$s.datasource = ds.datasource and %1$s.version = ds.version",
config.getRuleTable()
)
).fold(

View File

@ -203,7 +203,7 @@ public class DatabaseSegmentManager
for (DataSegment segment : segments) {
batch.add(
String.format(
"UPDATE %s SET used=1 WHERE id = '%s'",
"UPDATE %s SET used=true WHERE id = '%s'",
config.getSegmentTable(),
segment.getIdentifier()
)
@ -234,7 +234,7 @@ public class DatabaseSegmentManager
public Void withHandle(Handle handle) throws Exception
{
handle.createStatement(
String.format("UPDATE %s SET used=1 WHERE id = :id", config.getSegmentTable())
String.format("UPDATE %s SET used=true WHERE id = :id", config.getSegmentTable())
)
.bind("id", segmentId)
.execute();
@ -268,7 +268,7 @@ public class DatabaseSegmentManager
public Void withHandle(Handle handle) throws Exception
{
handle.createStatement(
String.format("UPDATE %s SET used=0 WHERE dataSource = :dataSource", config.getSegmentTable())
String.format("UPDATE %s SET used=false WHERE dataSource = :dataSource", config.getSegmentTable())
)
.bind("dataSource", ds)
.execute();
@ -298,7 +298,7 @@ public class DatabaseSegmentManager
public Void withHandle(Handle handle) throws Exception
{
handle.createStatement(
String.format("UPDATE %s SET used=0 WHERE id = :segmentID", config.getSegmentTable())
String.format("UPDATE %s SET used=false WHERE id = :segmentID", config.getSegmentTable())
).bind("segmentID", segmentID)
.execute();
@ -398,7 +398,7 @@ public class DatabaseSegmentManager
public List<Map<String, Object>> withHandle(Handle handle) throws Exception
{
return handle.createQuery(
String.format("SELECT payload FROM %s WHERE used=1", config.getSegmentTable())
String.format("SELECT payload FROM %s WHERE used=true", config.getSegmentTable())
).list();
}
}