Search in sources :

Example 21 with FullQuery

use of com.palantir.atlasdb.keyvalue.dbkvs.impl.FullQuery in project atlasdb by palantir.

the class PostgresQueryFactory method getLatestCellQuery.

@Override
public FullQuery getLatestCellQuery(Cell cell, long ts, boolean includeValue) {
    String query = " /* GET_LATEST_CELL_INNER (" + tableName + ") */ " + " SELECT m.row_name, m.col_name, max(m.ts) as ts " + "   FROM " + prefixedTableName() + " m " + "  WHERE m.row_name = ? " + "    AND m.col_name = ? " + "    AND m.ts < ? " + " GROUP BY m.row_name, m.col_name " + " LIMIT 1";
    query = wrapQueryWithIncludeValue("GET_LATEST_CELL", query, includeValue);
    return new FullQuery(query).withArgs(cell.getRowName(), cell.getColumnName(), ts);
}
Also used : FullQuery(com.palantir.atlasdb.keyvalue.dbkvs.impl.FullQuery)

Example 22 with FullQuery

use of com.palantir.atlasdb.keyvalue.dbkvs.impl.FullQuery in project atlasdb by palantir.

the class PostgresQueryFactory method getAllRowQuery.

@Override
public FullQuery getAllRowQuery(byte[] row, long ts, ColumnSelection columns, boolean includeValue) {
    String query = " /* GET_ALL_ROW (" + tableName + ") */ " + " SELECT m.row_name, m.col_name, m.ts" + (includeValue ? ", m.val " : " ") + "   FROM " + prefixedTableName() + " m " + "  WHERE m.row_name = ? " + "    AND m.ts < ? " + (columns.allColumnsSelected() ? "" : "    AND m.col_name IN " + numParams(Iterables.size(columns.getSelectedColumns())));
    FullQuery fullQuery = new FullQuery(query).withArgs(row, ts);
    return columns.allColumnsSelected() ? fullQuery : fullQuery.withArgs(columns.getSelectedColumns());
}
Also used : FullQuery(com.palantir.atlasdb.keyvalue.dbkvs.impl.FullQuery)

Example 23 with FullQuery

use of com.palantir.atlasdb.keyvalue.dbkvs.impl.FullQuery in project atlasdb by palantir.

the class PostgresQueryFactory method getLatestRowsQuery.

@Override
public FullQuery getLatestRowsQuery(Iterable<byte[]> rows, long ts, 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 " + "  WHERE m.row_name IN " + numParams(Iterables.size(rows)) + "    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(rows).withArg(ts);
    return columns.allColumnsSelected() ? fullQuery : fullQuery.withArgs(columns.getSelectedColumns());
}
Also used : FullQuery(com.palantir.atlasdb.keyvalue.dbkvs.impl.FullQuery)

Example 24 with FullQuery

use of com.palantir.atlasdb.keyvalue.dbkvs.impl.FullQuery in project atlasdb by palantir.

the class PostgresQueryFactory method getRowsColumnRangeSubQuery.

@Override
protected FullQuery getRowsColumnRangeSubQuery(byte[] row, long ts, BatchColumnRangeSelection columnRangeSelection) {
    String query = " /* GET_ROWS_COLUMN_RANGE (" + tableName + ") */ " + " SELECT m.row_name, m.col_name, max(m.ts) as ts" + "   FROM " + prefixedTableName() + " m " + "  WHERE m.row_name = ? " + "    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.col_name ASC LIMIT " + columnRangeSelection.getBatchHint();
    FullQuery fullQuery = new FullQuery(wrapQueryWithIncludeValue("GET_ROWS_COLUMN_RANGE", query, true)).withArg(row).withArg(ts);
    if (columnRangeSelection.getStartCol().length > 0) {
        fullQuery = fullQuery.withArg(columnRangeSelection.getStartCol());
    }
    if (columnRangeSelection.getEndCol().length > 0) {
        fullQuery = fullQuery.withArg(columnRangeSelection.getEndCol());
    }
    return fullQuery;
}
Also used : FullQuery(com.palantir.atlasdb.keyvalue.dbkvs.impl.FullQuery)

Example 25 with FullQuery

use of com.palantir.atlasdb.keyvalue.dbkvs.impl.FullQuery in project atlasdb by palantir.

the class RangePredicateHelperTest method startCellTsInclusiveNullTimestamp.

@Test
public void startCellTsInclusiveNullTimestamp() {
    FullQuery.Builder builder = FullQuery.builder();
    RangePredicateHelper.create(false, DBType.POSTGRESQL, builder).startCellTsInclusive(ROW_NAME, COL_NAME, null);
    FullQuery query = builder.build();
    assertThat(query.getQuery(), equalTo(" AND (row_name, col_name) >= (?, ?)"));
    assertThat(query.getArgs(), arrayContaining(ROW_NAME, COL_NAME));
}
Also used : FullQuery(com.palantir.atlasdb.keyvalue.dbkvs.impl.FullQuery) Test(org.junit.Test)

Aggregations

FullQuery (com.palantir.atlasdb.keyvalue.dbkvs.impl.FullQuery)45 Test (org.junit.Test)18 AgnosticLightResultRow (com.palantir.nexus.db.sql.AgnosticLightResultRow)1