Search in sources :

Example 41 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(Collection<Map.Entry<byte[], Long>> rows, ColumnSelection columns, boolean includeValue) {
    String query = " /* GET_LATEST_ROWS_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.ts < t.max_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_MANY_BOUNDS", query, includeValue);
    FullQuery fullQuery = new FullQuery(query).withArg(rowsAndTimestampsToOracleArray(rows));
    return columns.allColumnsSelected() ? fullQuery : fullQuery.withArg(rowsToOracleArray(columns.getSelectedColumns()));
}
Also used : FullQuery(com.palantir.atlasdb.keyvalue.dbkvs.impl.FullQuery)

Example 42 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(Iterable<Cell> cells, long ts, boolean includeValue) {
    String query = " /* GET_LATEST_CELLS_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.col_name = t.col_name " + "   AND m.ts < ? " + " GROUP BY m.row_name, m.col_name";
    query = wrapQueryWithIncludeValue("GET_LATEST_CELLS_SINGLE_BOUND", query, includeValue);
    return new FullQuery(query).withArgs(cellsToOracleArray(cells), ts);
}
Also used : FullQuery(com.palantir.atlasdb.keyvalue.dbkvs.impl.FullQuery)

Example 43 with FullQuery

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

the class OracleQueryFactory method getLatestRowQuery.

@Override
public FullQuery getLatestRowQuery(byte[] row, long ts, ColumnSelection columns, boolean includeValue) {
    String query = " /* GET_LATEST_ONE_ROW_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 " + " 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)") + " GROUP BY m.row_name, m.col_name";
    query = wrapQueryWithIncludeValue("GET_LATEST_ONE_ROW", query, includeValue);
    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 44 with FullQuery

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

the class OracleQueryFactory method getLatestCellQuery.

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

Example 45 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(Collection<Map.Entry<byte[], Long>> rows, ColumnSelection columns, boolean includeValue) {
    String query = " /* GET_ALL_ROWS_MANY_BOUNDS (" + 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 < t.max_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).withArg(rowsAndTimestampsToOracleArray(rows));
    return columns.allColumnsSelected() ? fullQuery : fullQuery.withArg(rowsToOracleArray(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