Search in sources :

Example 36 with FullQuery

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

the class OracleQueryFactory 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 " + 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";
    FullQuery fullQuery = new FullQuery(query).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 37 with FullQuery

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

the class OracleQueryFactory method getAllRowsQuery.

@Override
public FullQuery getAllRowsQuery(Iterable<byte[]> rows, long ts, ColumnSelection columns, boolean includeValue) {
    String query = " /* GET_ALL_ROWS_SINGLE_BOUND (" + tableName + ") */ " + " SELECT" + "   /*+ USE_NL(t m) CARDINALITY(t 1) CARDINALITY(m 10) INDEX(m " + PrimaryKeyConstraintNames.get(tableName) + ") */ " + "   m.row_name, m.col_name, m.ts" + getValueSubselect("m", includeValue) + " FROM " + tableName + " m, TABLE(CAST(? AS " + structArrayPrefix() + "CELL_TS_TABLE)) t " + " WHERE m.row_name = t.row_name " + "   AND m.ts < ? " + (columns.allColumnsSelected() ? "" : " AND EXISTS (" + "SELECT" + "  /*+ NL_SJ */" + "  1" + " FROM TABLE(CAST(? AS " + structArrayPrefix() + "CELL_TS_TABLE))" + " WHERE row_name = m.col_name) ");
    FullQuery fullQuery = new FullQuery(query).withArgs(rowsToOracleArray(rows), ts);
    return columns.allColumnsSelected() ? fullQuery : fullQuery.withArg(rowsToOracleArray(columns.getSelectedColumns()));
}
Also used : FullQuery(com.palantir.atlasdb.keyvalue.dbkvs.impl.FullQuery)

Example 38 with FullQuery

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

the class OracleQueryFactory method getAllRowQuery.

@Override
public FullQuery getAllRowQuery(byte[] row, long ts, ColumnSelection columns, boolean includeValue) {
    String query = " /* GET_ALL_ONE_ROW (" + tableName + ") */ " + " SELECT" + "   /*+ INDEX(m " + PrimaryKeyConstraintNames.get(tableName) + ") */ " + "   m.row_name, m.col_name, m.ts" + getValueSubselect("m", includeValue) + " FROM " + tableName + " m " + " WHERE m.row_name = ? " + "   AND m.ts < ? " + (columns.allColumnsSelected() ? "" : " AND EXISTS (" + "SELECT" + "  /*+ NL_SJ */" + "  1" + " FROM TABLE(CAST(? AS " + structArrayPrefix() + "CELL_TS_TABLE))" + " WHERE row_name = m.col_name) ");
    FullQuery fullQuery = new FullQuery(query).withArgs(row, ts);
    return columns.allColumnsSelected() ? fullQuery : fullQuery.withArg(rowsToOracleArray(columns.getSelectedColumns()));
}
Also used : FullQuery(com.palantir.atlasdb.keyvalue.dbkvs.impl.FullQuery)

Example 39 with FullQuery

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

the class OracleQueryFactory method getLatestRowsQuery.

@Override
public FullQuery getLatestRowsQuery(Iterable<byte[]> rows, long ts, ColumnSelection columns, boolean includeValue) {
    String query = " /* GET_LATEST_ROWS_SINGLE_BOUND_INNER (" + tableName + ") */ " + " SELECT" + "   /*+ USE_NL(t m) CARDINALITY(t 1) CARDINALITY(m 10) INDEX(m " + PrimaryKeyConstraintNames.get(tableName) + ") */ " + "   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 < ? " + (columns.allColumnsSelected() ? "" : " AND EXISTS (" + "SELECT" + "  /*+ NL_SJ */" + "  1" + " FROM TABLE(CAST(? AS " + structArrayPrefix() + "CELL_TS_TABLE))" + " WHERE row_name = m.col_name) ") + " GROUP BY m.row_name, m.col_name";
    query = wrapQueryWithIncludeValue("GET_LATEST_ROWS_SINGLE_BOUND", query, includeValue);
    FullQuery fullQuery = new FullQuery(query).withArgs(rowsToOracleArray(rows), ts);
    return columns.allColumnsSelected() ? fullQuery : fullQuery.withArg(rowsToOracleArray(columns.getSelectedColumns()));
}
Also used : FullQuery(com.palantir.atlasdb.keyvalue.dbkvs.impl.FullQuery)

Example 40 with FullQuery

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

the class OracleQueryFactory method getLatestCellsQuery.

@Override
public FullQuery getLatestCellsQuery(Collection<Map.Entry<Cell, Long>> cells, boolean includeValue) {
    String query = " /* GET_LATEST_CELLS_MANY_BOUNDS_INNER (" + tableName + ") */ " + " SELECT" + "   /*+ USE_NL(t m) CARDINALITY(t 1) CARDINALITY(m 10) INDEX(m " + PrimaryKeyConstraintNames.get(tableName) + ") */ " + "   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.col_name = t.col_name " + "   AND m.ts < t.max_ts " + " GROUP BY m.row_name, m.col_name";
    query = wrapQueryWithIncludeValue("GET_LATEST_CELLS_MANY_BOUNDS", query, includeValue);
    return new FullQuery(query).withArg(cellsAndTimestampsToOracleArray(cells));
}
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