use of com.palantir.atlasdb.keyvalue.dbkvs.impl.FullQuery in project atlasdb by palantir.
the class PostgresQueryFactory method getRowsColumnRangeFullyLoadedRowsSubQuery.
@Override
protected FullQuery getRowsColumnRangeFullyLoadedRowsSubQuery(List<byte[]> rows, long ts, ColumnRangeSelection columnRangeSelection) {
String query = " /* GET_ROWS_COLUMN_RANGE_FULLY_LOADED_ROW (" + tableName + ") */ " + " SELECT m.row_name, m.col_name, max(m.ts) as ts" + " FROM " + prefixedTableName() + " m " + " WHERE m.row_name IN " + numParams(Iterables.size(rows)) + " AND m.ts < ? " + (columnRangeSelection.getStartCol().length > 0 ? " AND m.col_name >= ?" : "") + (columnRangeSelection.getEndCol().length > 0 ? " AND m.col_name < ?" : "") + " GROUP BY m.row_name, m.col_name" + " ORDER BY m.row_name ASC, m.col_name ASC";
String wrappedQuery = wrapQueryWithIncludeValue("GET_ROWS_COLUMN_RANGE_FULLY_LOADED_ROW", query, true);
FullQuery fullQuery = new FullQuery(wrappedQuery).withArgs(rows).withArg(ts);
if (columnRangeSelection.getStartCol().length > 0) {
fullQuery = fullQuery.withArg(columnRangeSelection.getStartCol());
}
if (columnRangeSelection.getEndCol().length > 0) {
fullQuery = fullQuery.withArg(columnRangeSelection.getEndCol());
}
return fullQuery;
}
use of com.palantir.atlasdb.keyvalue.dbkvs.impl.FullQuery in project atlasdb by palantir.
the class PostgresQueryFactory method getLatestCellsQuery.
@Override
public FullQuery getLatestCellsQuery(Collection<Entry<Cell, Long>> cells, boolean includeValue) {
String query = " /* GET_LATEST_CELLS_INNER (" + tableName + ") */ " + " SELECT m.row_name, m.col_name, max(m.ts) as ts " + " FROM " + prefixedTableName() + " m," + " (VALUES " + groupOfNumParams(3, Iterables.size(cells)) + ") t(row_name, col_name, ts) " + " WHERE m.row_name = t.row_name " + " AND m.col_name = t.col_name " + " AND m.ts < t.ts " + " GROUP BY m.row_name, m.col_name ";
query = wrapQueryWithIncludeValue("GET_LATEST_CELLS", query, includeValue);
return addCellTsArgs(new FullQuery(query), cells);
}
use of com.palantir.atlasdb.keyvalue.dbkvs.impl.FullQuery in project atlasdb by palantir.
the class PostgresQueryFactory method getRangeQuery.
@Override
public FullQuery getRangeQuery(RangeRequest range, long ts, int maxRows) {
List<String> bounds = Lists.newArrayListWithCapacity(2);
List<Object> args = Lists.newArrayListWithCapacity(2);
byte[] start = range.getStartInclusive();
byte[] end = range.getEndExclusive();
if (start.length > 0) {
bounds.add(range.isReverse() ? "m.row_name <= ?" : "m.row_name >= ?");
args.add(start);
}
if (end.length > 0) {
bounds.add(range.isReverse() ? "m.row_name > ?" : "m.row_name < ?");
args.add(end);
}
String query = " /* GET_RANGE_ROWS (" + tableName + ") */ " + " SELECT DISTINCT m.row_name " + " FROM " + prefixedTableName() + " m " + (bounds.isEmpty() ? "" : " WHERE " + Joiner.on(" AND ").join(bounds)) + " ORDER BY m.row_name " + (range.isReverse() ? "DESC" : "ASC") + " LIMIT " + maxRows;
return new FullQuery(query).withArgs(args);
}
use of com.palantir.atlasdb.keyvalue.dbkvs.impl.FullQuery in project atlasdb by palantir.
the class PostgresQueryFactory method getLatestRowQuery.
@Override
public FullQuery getLatestRowQuery(byte[] row, long ts, ColumnSelection columns, boolean includeValue) {
String query = " /* GET_LATEST_ROW_INNER (" + tableName + ") */ " + " SELECT m.row_name, m.col_name, max(m.ts) as ts " + " FROM " + prefixedTableName() + " m " + " WHERE m.row_name = ? " + " AND m.ts < ? " + (columns.allColumnsSelected() ? "" : " AND m.col_name IN " + numParams(Iterables.size(columns.getSelectedColumns()))) + " GROUP BY m.row_name, m.col_name";
query = wrapQueryWithIncludeValue("GET_LATEST_ROW", query, includeValue);
FullQuery fullQuery = new FullQuery(query).withArgs(row, ts);
return columns.allColumnsSelected() ? fullQuery : fullQuery.withArgs(columns.getSelectedColumns());
}
use of com.palantir.atlasdb.keyvalue.dbkvs.impl.FullQuery in project atlasdb by palantir.
the class PostgresQueryFactory method getLatestRowsQuery.
@Override
public FullQuery getLatestRowsQuery(Collection<Entry<byte[], Long>> rows, ColumnSelection columns, boolean includeValue) {
String query = " /* GET_LATEST_ROWS_INNER (" + tableName + ") */ " + " SELECT m.row_name, m.col_name, max(m.ts) as ts " + " FROM " + prefixedTableName() + " m," + " (VALUES " + groupOfNumParams(2, rows.size()) + ") t(row_name, ts) " + " WHERE m.row_name = t.row_name " + " AND m.ts < t.ts " + (columns.allColumnsSelected() ? "" : " AND m.col_name IN " + numParams(Iterables.size(columns.getSelectedColumns()))) + " GROUP BY m.row_name, m.col_name ";
query = wrapQueryWithIncludeValue("GET_LATEST_ROW", query, includeValue);
FullQuery fullQuery = addRowTsArgs(new FullQuery(query), rows);
return columns.allColumnsSelected() ? fullQuery : fullQuery.withArgs(columns.getSelectedColumns());
}
Aggregations