Search in sources :

Example 11 with FullQuery

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

the class OracleQueryFactory 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);
    }
    if (maxRows == 1) {
        String query = " /* GET_RANGE_ONE_ROW (" + tableName + ") */ " + " SELECT /*+ INDEX(m " + PrimaryKeyConstraintNames.get(tableName) + ") */ " + (range.isReverse() ? "max" : "min") + "(m.row_name) as row_name " + " FROM " + tableName + " m " + (bounds.isEmpty() ? "" : " WHERE  " + Joiner.on(" AND ").join(bounds));
        return new FullQuery(query).withArgs(args);
    }
    String query = " /* GET_RANGE_ROWS (" + tableName + ") */ " + " SELECT inner.row_name FROM " + "   ( SELECT /*+ INDEX(m " + PrimaryKeyConstraintNames.get(tableName) + ") */ " + "       DISTINCT m.row_name " + "     FROM " + tableName + " m " + (bounds.isEmpty() ? "" : " WHERE  " + Joiner.on(" AND ").join(bounds)) + "     ORDER BY m.row_name " + (range.isReverse() ? "DESC" : "ASC") + "   ) inner WHERE rownum <= " + maxRows;
    return new FullQuery(query).withArgs(args);
}
Also used : FullQuery(com.palantir.atlasdb.keyvalue.dbkvs.impl.FullQuery)

Example 12 with FullQuery

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

the class OracleQueryFactory method getRowsColumnRangeFullyLoadedRowsSubQuery.

@Override
protected FullQuery getRowsColumnRangeFullyLoadedRowsSubQuery(List<byte[]> rows, long ts, ColumnRangeSelection columnRangeSelection) {
    String query = " /* GET_ROWS_COLUMN_RANGE_FULLY_LOADED_ROWS (" + tableName + ") */ " + "SELECT * FROM ( SELECT m.row_name, m.col_name, max(m.ts) as ts" + "   FROM " + tableName + " m, TABLE(CAST(? AS " + structArrayPrefix() + "CELL_TS_TABLE)) t " + "  WHERE m.row_name = t.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.row_name ASC, m.col_name ASC )";
    String wrappedQuery = wrapQueryWithIncludeValue("GET_ROWS_COLUMN_RANGE_FULLY_LOADED_ROWS", query, true);
    FullQuery fullQuery = new FullQuery(wrappedQuery).withArgs(rowsToOracleArray(rows), 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 13 with FullQuery

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

the class PostgresQueryFactory method getRowsColumnRangeCountsQuery.

@Override
public FullQuery getRowsColumnRangeCountsQuery(Iterable<byte[]> rows, long ts, ColumnRangeSelection columnRangeSelection) {
    String query = " /* GET_ROWS_COLUMN_RANGE_COUNT(" + tableName + ") */" + " SELECT m.row_name, COUNT(m.col_name) AS column_count " + "   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";
    FullQuery fullQuery = new FullQuery(query).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;
}
Also used : FullQuery(com.palantir.atlasdb.keyvalue.dbkvs.impl.FullQuery)

Example 14 with FullQuery

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

the class PostgresQueryFactory method getAllRowsQuery.

@Override
public FullQuery getAllRowsQuery(Iterable<byte[]> rows, long ts, ColumnSelection columns, boolean includeValue) {
    String query = " /* GET_ALL_ROWS (" + tableName + ") */ " + " SELECT m.row_name, m.col_name, m.ts" + (includeValue ? ", m.val " : " ") + "   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())));
    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 15 with FullQuery

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

the class PostgresQueryFactory method getAllRowsQuery.

@Override
public FullQuery getAllRowsQuery(Collection<Entry<byte[], Long>> rows, ColumnSelection columns, boolean includeValue) {
    String query = " /* GET_ALL_ROWS (" + tableName + ") */ " + " SELECT m.row_name, m.col_name, m.ts" + (includeValue ? ", m.val " : " ") + "   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())));
    FullQuery fullQuery = addRowTsArgs(new FullQuery(query), rows);
    return columns.allColumnsSelected() ? fullQuery : fullQuery.withArgs(columns.getSelectedColumns());
}
Also used : FullQuery(com.palantir.atlasdb.keyvalue.dbkvs.impl.FullQuery)

Aggregations

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