Search in sources :

Example 6 with Qualifier

use of org.apache.derby.iapi.store.access.Qualifier in project derby by apache.

the class NoPutResultSetImpl method printQualifiers.

/**
 * Return a 2-d array of Qualifiers as a String
 */
public static String printQualifiers(Qualifier[][] qualifiers) {
    String idt = "";
    String output = "";
    if (qualifiers == null) {
        return idt + MessageService.getTextMessage(SQLState.LANG_NONE);
    }
    for (int term = 0; term < qualifiers.length; term++) {
        for (int i = 0; i < qualifiers[term].length; i++) {
            Qualifier qual = qualifiers[term][i];
            output = idt + output + MessageService.getTextMessage(SQLState.LANG_COLUMN_ID_ARRAY, String.valueOf(term), String.valueOf(i)) + ": " + qual.getColumnId() + "\n";
            int operator = qual.getOperator();
            String opString = null;
            switch(operator) {
                case Orderable.ORDER_OP_EQUALS:
                    opString = "=";
                    break;
                case Orderable.ORDER_OP_LESSOREQUALS:
                    opString = "<=";
                    break;
                case Orderable.ORDER_OP_LESSTHAN:
                    opString = "<";
                    break;
                default:
                    if (SanityManager.DEBUG) {
                        SanityManager.THROWASSERT("Unknown operator " + operator);
                    }
                    // NOTE: This does not have to be internationalized, because
                    // this code should never be reached.
                    opString = "unknown value (" + operator + ")";
                    break;
            }
            output = output + idt + MessageService.getTextMessage(SQLState.LANG_OPERATOR) + ": " + opString + "\n" + idt + MessageService.getTextMessage(SQLState.LANG_ORDERED_NULLS) + ": " + qual.getOrderedNulls() + "\n" + idt + MessageService.getTextMessage(SQLState.LANG_UNKNOWN_RETURN_VALUE) + ": " + qual.getUnknownRV() + "\n" + idt + MessageService.getTextMessage(SQLState.LANG_NEGATE_COMPARISON_RESULT) + ": " + qual.negateCompareResult() + "\n";
        }
    }
    return output;
}
Also used : Qualifier(org.apache.derby.iapi.store.access.Qualifier)

Example 7 with Qualifier

use of org.apache.derby.iapi.store.access.Qualifier in project derby by apache.

the class T_QualifierTest method t_testqual.

/* public methods of T_QualifierTest */
public boolean t_testqual(TransactionController tc) throws StandardException, T_Fail {
    boolean ret_val = true;
    DataValueDescriptor[] openscan_template = null;
    DataValueDescriptor[] fetch_template = null;
    DataValueDescriptor[] base_row = null;
    T_SecondaryIndexRow index_row = null;
    long value = -1;
    long[] col1 = { 1, 3, 4, 4, 4, 5, 5, 5, 6, 7, 9 };
    long[] col2 = { 1, 1, 2, 4, 6, 2, 4, 6, 1, 1, 1 };
    long[] col3 = { 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21 };
    long conglomid;
    long base_conglomid;
    long index_conglomid;
    ConglomerateController base_cc = null;
    ConglomerateController index_cc = null;
    RowLocation base_rowloc = null;
    base_row = TemplateRow.newU8Row(3);
    if (init_conglomerate_type.compareTo("BTREE") == 0) {
        base_conglomid = tc.createConglomerate("heap", base_row, null, null, null, TransactionController.IS_DEFAULT);
        index_row = new T_SecondaryIndexRow();
        base_cc = tc.openConglomerate(base_conglomid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
        base_rowloc = base_cc.newRowLocationTemplate();
        index_row.init(base_row, base_rowloc, 4);
        index_conglomid = tc.createConglomerate(init_conglomerate_type, index_row.getRow(), null, null, init_properties, init_temporary ? TransactionController.IS_TEMPORARY : TransactionController.IS_DEFAULT);
        index_cc = tc.openConglomerate(index_conglomid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
        conglomid = index_conglomid;
        openscan_template = index_row.getRow();
        // make another template
        T_SecondaryIndexRow fetch_index_row = new T_SecondaryIndexRow();
        fetch_index_row.init(TemplateRow.newU8Row(3), base_cc.newRowLocationTemplate(), 4);
        fetch_template = fetch_index_row.getRow();
    } else {
        base_conglomid = tc.createConglomerate(init_conglomerate_type, base_row, // default order
        null, // default collation
        null, init_properties, init_temporary ? TransactionController.IS_TEMPORARY : TransactionController.IS_DEFAULT);
        base_cc = tc.openConglomerate(base_conglomid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
        base_rowloc = base_cc.newRowLocationTemplate();
        conglomid = base_conglomid;
        openscan_template = base_row;
        fetch_template = TemplateRow.newU8Row(3);
    }
    // insert them in reverse order just to make sure btree is sorting them
    for (int i = col1.length - 1; i >= 0; i--) {
        ((SQLLongint) (base_row[0])).setValue(col1[i]);
        ((SQLLongint) (base_row[1])).setValue(col2[i]);
        ((SQLLongint) (base_row[2])).setValue(col3[i]);
        base_cc.insertAndFetchLocation(base_row, base_rowloc);
        if (init_conglomerate_type.compareTo("BTREE") == 0) {
            index_cc.insert(index_row.getRow());
        }
    }
    tc.commit();
    // run through a predicates as described in the openScan() interface,
    // and implement them in qualifiers rather than start and stop.
    // 
    // Use the following SQLLongint's for qualifier values //
    SQLLongint qual_col1 = new SQLLongint(-1);
    SQLLongint qual_col2 = new SQLLongint(-1);
    SQLLongint qual_col3 = new SQLLongint(-1);
    SQLLongint qual_col4 = new SQLLongint(-1);
    SQLLongint qual_col5 = new SQLLongint(-1);
    SQLLongint qual_col6 = new SQLLongint(-1);
    SQLLongint qual_col7 = new SQLLongint(-1);
    // test predicate x = 5
    // 
    // result set should be: {5,2,16}, {5,4,17}, {5,6,18}
    // 
    progress("qual scan (x = 5)");
    qual_col1.setValue(5);
    Qualifier[][] q1 = { { new QualifierUtil(0, qual_col1, Orderable.ORDER_OP_EQUALS, false, true, true) } };
    if (!t_scan(tc, conglomid, openscan_template, fetch_template, null, ScanController.NA, q1, null, ScanController.NA, 3, 16, init_order)) {
        ret_val = false;
    }
    // +---------------------------------------------------------+
    // |pred  |start|key|stop |key|rows returned |rows locked    |
    // |      |value|op |value|op |              |(serialization)|
    // +------+-----+---+-----+---+--------------+---------------+
    // |x > 5 |{5}  |GT |null |   |{6,1} .. {9,1}|{5,6} .. {9,1} |
    // +-----------------------------------------+---------------+
    progress("qual scan (x > 5)");
    qual_col1.setValue(5);
    Qualifier[][] q2 = { { new QualifierUtil(0, qual_col1, Orderable.ORDER_OP_LESSOREQUALS, true, true, true) } };
    if (!t_scan(tc, conglomid, openscan_template, fetch_template, null, ScanController.NA, q2, null, ScanController.NA, 3, 19, init_order)) {
        ret_val = false;
    }
    // +---------------------------------------------------------+
    // |pred  |start|key|stop |key|rows returned |rows locked    |
    // |      |value|op |value|op |              |(serialization)|
    // +------+-----+---+-----+---+--------------+---------------+
    // |x >= 5|{5}  |GE |null |   |{5,2} .. {9,1}|{4,6} .. {9,1} |
    // +-----------------------------------------+---------------+
    progress("qual scan (x >= 5)");
    qual_col1.setValue(5);
    Qualifier[][] q3 = { { new QualifierUtil(0, qual_col1, Orderable.ORDER_OP_LESSTHAN, true, true, true) } };
    if (!t_scan(tc, conglomid, openscan_template, fetch_template, null, ScanController.NA, q3, null, ScanController.NA, 6, 16, init_order)) {
        ret_val = false;
    }
    // 
    // +---------------------------------------------------------+
    // |pred  |start|key|stop |key|rows returned |rows locked    |
    // |      |value|op |value|op |              |(serialization)|
    // +------+-----+---+-----+---+--------------+---------------+
    // |x <= 5|null |   |{5}  |GT |{1,1} .. {5,6}|first .. {5,6} |
    // +-----------------------------------------+---------------+
    progress("qual scan (x <= 5)");
    qual_col1.setValue(5);
    Qualifier[][] q4 = { { new QualifierUtil(0, qual_col1, Orderable.ORDER_OP_LESSOREQUALS, false, true, true) } };
    if (!t_scan(tc, conglomid, openscan_template, fetch_template, null, ScanController.NA, q4, null, ScanController.NA, 8, 11, init_order)) {
        ret_val = false;
    }
    // 
    // +---------------------------------------------------------+
    // |pred  |start|key|stop |key|rows returned |rows locked    |
    // |      |value|op |value|op |              |(serialization)|
    // +------+-----+---+-----+---+--------------+---------------+
    // |x < 5 |null |   |{5}  |GE |{1,1} .. {4,6}|first .. {4,6} |
    // +-----------------------------------------+---------------+
    progress("qual scan (x < 5)");
    qual_col1.setValue(5);
    Qualifier[][] q5 = { { new QualifierUtil(0, qual_col1, Orderable.ORDER_OP_LESSTHAN, false, true, true) } };
    if (!t_scan(tc, conglomid, openscan_template, fetch_template, null, ScanController.NA, q5, null, ScanController.NA, 5, 11, init_order)) {
        ret_val = false;
    }
    // +------------------------------------------------------------------+
    // |pred             |start|key|stop |key|rows returned|rows locked   |
    // |                 |value|op |value|op |             |(serialized)  |
    // +-----------------+------+--+-----+--+--------------+--------------+
    // |x >= 5 and x <= 7|{5},  |GE|{7}  |GT|{5,2} .. {7,1}|{4,6} .. {7,1}|
    // +------------------------------------------------------------------+
    progress("qual scan (x >= 5 and x <= 7)");
    qual_col1.setValue(5);
    qual_col2.setValue(7);
    Qualifier[][] q6 = { { new QualifierUtil(0, qual_col1, Orderable.ORDER_OP_LESSTHAN, true, true, true), new QualifierUtil(0, qual_col2, Orderable.ORDER_OP_LESSOREQUALS, false, true, true) } };
    if (!t_scan(tc, conglomid, openscan_template, fetch_template, null, ScanController.NA, q6, null, ScanController.NA, 5, 16, init_order)) {
        ret_val = false;
    }
    // passing qualifier in q6[0][0], q6[0][1] should evaluate same as
    // passing in q6[0][0], q6[1][0]
    // +------------------------------------------------------------------+
    // |pred             |start|key|stop |key|rows returned|rows locked   |
    // |                 |value|op |value|op |             |(serialized)  |
    // +-----------------+------+--+-----+--+--------------+--------------+
    // |x >= 5 and x <= 7|{5},  |GE|{7}  |GT|{5,2} .. {7,1}|{4,6} .. {7,1}|
    // +------------------------------------------------------------------+
    progress("qual scan (x >= 5 and x <= 7)");
    qual_col1.setValue(5);
    qual_col2.setValue(7);
    Qualifier[][] q6_2 = { { new QualifierUtil(0, qual_col1, Orderable.ORDER_OP_LESSTHAN, true, true, true) }, { new QualifierUtil(0, qual_col2, Orderable.ORDER_OP_LESSOREQUALS, false, true, true) } };
    if (!t_scan(tc, conglomid, openscan_template, fetch_template, null, ScanController.NA, q6_2, null, ScanController.NA, 5, 16, init_order)) {
        ret_val = false;
    }
    // +------------------------------------------------------------------+
    // |pred             |start|key|stop |key|rows returned|rows locked   |
    // |                 |value|op |value|op |             |(serialized)  |
    // +-----------------+------+--+-----+--+--------------+--------------+
    // |x = 5 and y > 2  |{5,2} |GT|{5}  |GT|{5,4} .. {5,6}|{5,2} .. {9,1}|
    // +------------------------------------------------------------------+
    progress("qual scan (x = 5 and y > 2)");
    qual_col1.setValue(5);
    qual_col2.setValue(2);
    Qualifier[][] q7 = { { new QualifierUtil(0, qual_col1, Orderable.ORDER_OP_EQUALS, false, true, true), new QualifierUtil(1, qual_col2, Orderable.ORDER_OP_LESSOREQUALS, true, true, true) } };
    if (!t_scan(tc, conglomid, openscan_template, fetch_template, null, ScanController.NA, q7, null, ScanController.NA, 2, 17, init_order)) {
        ret_val = false;
    }
    // +------------------------------------------------------------------+
    // |pred             |start|key|stop |key|rows returned|rows locked   |
    // |                 |value|op |value|op |             |(serialized)  |
    // +-----------------+------+--+-----+--+--------------+--------------+
    // |x = 5 and y >= 2 | {5,2}|GE| {5} |GT|{5,2} .. {5,6}|{4,6} .. {9,1}|
    // +------------------------------------------------------------------+
    progress("qual scan (x = 5 and y >= 2)");
    qual_col1.setValue(5);
    qual_col2.setValue(2);
    Qualifier[][] q8 = { { new QualifierUtil(0, qual_col1, Orderable.ORDER_OP_EQUALS, false, true, true), new QualifierUtil(1, qual_col2, Orderable.ORDER_OP_LESSTHAN, true, true, true) } };
    if (!t_scan(tc, conglomid, openscan_template, fetch_template, null, ScanController.NA, q8, null, ScanController.NA, 3, 16, init_order)) {
        ret_val = false;
    }
    // +------------------------------------------------------------------+
    // |pred             |start|key|stop |key|rows returned|rows locked   |
    // |                 |value|op |value|op |             |(serialized)  |
    // +-----------------+------+--+-----+--+--------------+--------------+
    // |x = 5 and y < 5  | {5}  |GE|{5,5}|GE|{5,2} .. {5,4}|{4,6} .. {5,4}|
    // +------------------------------------------------------------------+
    progress("qual scan (x = 5 and y < 5)");
    qual_col1.setValue(5);
    qual_col2.setValue(5);
    Qualifier[][] q9 = { { new QualifierUtil(0, qual_col1, Orderable.ORDER_OP_EQUALS, false, true, true), new QualifierUtil(1, qual_col1, Orderable.ORDER_OP_LESSTHAN, false, true, true) } };
    if (!t_scan(tc, conglomid, openscan_template, fetch_template, null, ScanController.NA, q9, null, ScanController.NA, 2, 16, init_order)) {
        ret_val = false;
    }
    // +------------------------------------------------------------------+
    // |pred             |start|key|stop |key|rows returned|rows locked   |
    // |                 |value|op |value|op |             |(serialized)  |
    // +-----------------+------+--+-----+--+--------------+--------------+
    // |x = 2            | {2}  |GE| {2} |GT|none          |{1,1} .. {1,1}|
    // +------------------------------------------------------------------+
    progress("qual scan (x = 2)");
    qual_col1.setValue(2);
    Qualifier[][] q10 = { { new QualifierUtil(0, qual_col1, Orderable.ORDER_OP_EQUALS, false, true, true) } };
    if (!t_scan(tc, conglomid, openscan_template, fetch_template, null, ScanController.NA, q10, null, ScanController.NA, 0, 0, init_order)) {
        ret_val = false;
    }
    // +------------------------------------------------------------------+
    // |pred            |start|key|stop |key|rows returned |rows locked   |
    // |                |value|op |value|op |              |(serialized)  |
    // +----------------+-----+---+-----+-- +--------------+--------------+
    // |x >= 5 or y = 6 | null|   | null|   |{4,6} .. {9,1}|{1,1} .. {9,1}|
    // +------------------------------------------------------------------+
    progress("qual scan (x >= 5) or (y = 6)");
    qual_col1.setValue(5);
    qual_col2.setValue(6);
    Qualifier[][] q11 = new Qualifier[2][];
    q11[0] = new Qualifier[0];
    q11[1] = new Qualifier[2];
    q11[1][0] = new QualifierUtil(0, qual_col1, Orderable.ORDER_OP_GREATEROREQUALS, false, true, true);
    q11[1][1] = new QualifierUtil(1, qual_col2, Orderable.ORDER_OP_EQUALS, false, true, true);
    if (!t_scan(tc, conglomid, openscan_template, fetch_template, null, ScanController.NA, q11, null, ScanController.NA, 7, 15, init_order)) {
        ret_val = false;
    }
    // +------------------------------------------------------------------+
    // |pred            |start|key|stop |key|rows returned |rows locked   |
    // |                |value|op |value|op |              |(serialized)  |
    // +----------------+-----+---+-----+-- +--------------+--------------+
    // |(x = 1 or y = 1 or y = 6)|
    // |     and        |
    // |(x > 5 or y = 1)|
    // |     and        |
    // |(x = 9 or x = 7)|null |   | null|   |{7,1} .. {9,1}|{1,1} .. {9,1}|
    // +------------------------------------------------------------------+
    progress("qual scan (x = 1 or y = 1 or y = 6) and (x > 5 or y = 1) and (x = 9 or x = 7)");
    qual_col1.setValue(1);
    qual_col2.setValue(1);
    qual_col3.setValue(6);
    qual_col4.setValue(5);
    qual_col5.setValue(1);
    qual_col6.setValue(9);
    qual_col7.setValue(7);
    Qualifier[][] q12 = new Qualifier[4][];
    q12[0] = new Qualifier[0];
    q12[1] = new Qualifier[3];
    q12[2] = new Qualifier[2];
    q12[3] = new Qualifier[2];
    q12[1][0] = new QualifierUtil(0, qual_col1, Orderable.ORDER_OP_EQUALS, false, true, true);
    q12[1][1] = new QualifierUtil(1, qual_col2, Orderable.ORDER_OP_EQUALS, false, true, true);
    q12[1][2] = new QualifierUtil(1, qual_col3, Orderable.ORDER_OP_EQUALS, false, true, true);
    q12[2][0] = new QualifierUtil(0, qual_col4, Orderable.ORDER_OP_GREATERTHAN, false, true, true);
    q12[2][1] = new QualifierUtil(1, qual_col5, Orderable.ORDER_OP_EQUALS, false, true, true);
    q12[3][0] = new QualifierUtil(0, qual_col6, Orderable.ORDER_OP_EQUALS, false, true, true);
    q12[3][1] = new QualifierUtil(0, qual_col7, Orderable.ORDER_OP_EQUALS, false, true, true);
    if (!t_scan(tc, conglomid, openscan_template, fetch_template, null, ScanController.NA, q12, null, ScanController.NA, 2, 20, init_order)) {
        ret_val = false;
    }
    // +------------------------------------------------------------------+
    // |pred            |start|key|stop |key|rows returned |rows locked   |
    // |                |value|op |value|op |              |(serialized)  |
    // +----------------+-----+---+-----+-- +--------------+--------------+
    // |(y = 4 or y = 1)|
    // |     and        |
    // |(x = 1 or x = 4 or x= 9)|
    // |     and        |
    // |(z = 15 or z = 14)|null |   | null|   |{4,4} .. {4,4}| ALL        |
    // +------------------------------------------------------------------+
    progress("qual scan (x = 1 or x = 4 or x= 9) and (y = 4 or y = 1) and (z = 15 or z = 14)");
    qual_col1.setValue(4);
    qual_col2.setValue(1);
    qual_col3.setValue(1);
    qual_col4.setValue(4);
    qual_col5.setValue(9);
    qual_col6.setValue(15);
    qual_col7.setValue(14);
    Qualifier[][] q13 = new Qualifier[4][];
    q13[0] = new Qualifier[0];
    q13[1] = new Qualifier[2];
    q13[2] = new Qualifier[3];
    q13[3] = new Qualifier[2];
    q13[1][0] = new QualifierUtil(1, qual_col1, Orderable.ORDER_OP_EQUALS, false, true, true);
    q13[1][1] = new QualifierUtil(1, qual_col2, Orderable.ORDER_OP_EQUALS, false, true, true);
    q13[2][0] = new QualifierUtil(0, qual_col4, Orderable.ORDER_OP_EQUALS, false, true, true);
    q13[2][1] = new QualifierUtil(0, qual_col5, Orderable.ORDER_OP_EQUALS, false, true, true);
    q13[2][2] = new QualifierUtil(0, qual_col3, Orderable.ORDER_OP_EQUALS, false, true, true);
    q13[3][0] = new QualifierUtil(2, qual_col6, Orderable.ORDER_OP_EQUALS, false, true, true);
    q13[3][1] = new QualifierUtil(2, qual_col7, Orderable.ORDER_OP_EQUALS, false, true, true);
    if (!t_scan(tc, conglomid, openscan_template, fetch_template, null, ScanController.NA, q13, null, ScanController.NA, 1, 14, init_order)) {
        ret_val = false;
    }
    tc.commit();
    progress("Ending t_testqual");
    return (ret_val);
}
Also used : ConglomerateController(org.apache.derby.iapi.store.access.ConglomerateController) SQLLongint(org.apache.derby.iapi.types.SQLLongint) SQLLongint(org.apache.derby.iapi.types.SQLLongint) Qualifier(org.apache.derby.iapi.store.access.Qualifier) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) RowLocation(org.apache.derby.iapi.types.RowLocation)

Example 8 with Qualifier

use of org.apache.derby.iapi.store.access.Qualifier in project derby by apache.

the class T_Util method t_checkFetchColFromSlot.

public static void t_checkFetchColFromSlot(Page page, int slot, int fieldId, DataValueDescriptor column, boolean forUpdate, String data) throws StandardException, T_Fail {
    DataValueDescriptor[] fetch_row = new DataValueDescriptor[fieldId + 1];
    fetch_row[fieldId] = column;
    FormatableBitSet validCols = new FormatableBitSet(fieldId + 1);
    validCols.set(fieldId);
    RecordHandle rh = page.fetchFromSlot(null, slot, fetch_row, new FetchDescriptor(fetch_row.length, validCols, (Qualifier[][]) null), true);
    if (rh == null)
        throw T_Fail.testFailMsg("Failed to fetch record: slot " + slot + " field " + fieldId);
    if (data == null) {
        if (!column.isNull())
            throw T_Fail.testFailMsg("Failed to fetch null column: slot " + slot + " field " + fieldId + " column is " + column);
    } else {
        if (column.isNull())
            throw T_Fail.testFailMsg("expect non null column, got null: slot " + slot + " field " + fieldId);
        if (!column.toString().equals(data))
            throw T_Fail.testFailMsg("expect " + data + " got " + column.toString() + ": slot " + slot + " field " + fieldId);
    }
}
Also used : FormatableBitSet(org.apache.derby.iapi.services.io.FormatableBitSet) Qualifier(org.apache.derby.iapi.store.access.Qualifier) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor)

Example 9 with Qualifier

use of org.apache.derby.iapi.store.access.Qualifier in project derby by apache.

the class StoredPage method qualifyRecordFromRow.

/**
 * Process the qualifier list on the row, return true if it qualifies.
 * <p>
 * A two dimensional array is to be used to pass around a AND's and OR's in
 * conjunctive normal form.  The top slot of the 2 dimensional array is
 * optimized for the more frequent where no OR's are present.  The first
 * array slot is always a list of AND's to be treated as described above
 * for single dimensional AND qualifier arrays.  The subsequent slots are
 * to be treated as AND'd arrays or OR's.  Thus the 2 dimensional array
 * qual[][] argument is to be treated as the following, note if
 * qual.length = 1 then only the first array is valid and it is and an
 * array of and clauses:
 *
 * (qual[0][0] and qual[0][0] ... and qual[0][qual[0].length - 1])
 * and
 * (qual[1][0] or  qual[1][1] ... or  qual[1][qual[1].length - 1])
 * and
 * (qual[2][0] or  qual[2][1] ... or  qual[2][qual[2].length - 1])
 * ...
 * and
 * (qual[qual.length - 1][0] or  qual[1][1] ... or  qual[1][2])
 *
 * @return true if the row qualifies.
 *
 * @param row               The row being qualified.
 * @param qual_list         2 dimensional array representing conjunctive
 *                          normal form of simple qualifiers.
 *
 * @exception  StandardException  Standard exception policy.
 */
private boolean qualifyRecordFromRow(Object[] row, Qualifier[][] qual_list) throws StandardException {
    boolean row_qualifies = true;
    if (SanityManager.DEBUG) {
        SanityManager.ASSERT(row != null);
    }
    if (SanityManager.DEBUG) {
        // routine should not be called if there is no qualifier
        SanityManager.ASSERT(qual_list != null);
        SanityManager.ASSERT(qual_list.length > 0);
    }
    for (int i = 0; i < qual_list[0].length; i++) {
        // process each AND clause
        row_qualifies = false;
        // process each OR clause.
        Qualifier q = qual_list[0][i];
        // Get the column from the possibly partial row, of the
        // q.getColumnId()'th column in the full row.
        DataValueDescriptor columnValue = (DataValueDescriptor) row[q.getColumnId()];
        row_qualifies = columnValue.compare(q.getOperator(), q.getOrderable(), q.getOrderedNulls(), q.getUnknownRV());
        if (q.negateCompareResult())
            row_qualifies = !row_qualifies;
        // Once an AND fails the whole Qualification fails - do a return!
        if (!row_qualifies)
            return (false);
    }
    for (int and_idx = 1; and_idx < qual_list.length; and_idx++) {
        // loop through each of the "and" clause.
        row_qualifies = false;
        if (SanityManager.DEBUG) {
            // Each OR clause must be non-empty.
            SanityManager.ASSERT(qual_list[and_idx].length > 0);
        }
        for (int or_idx = 0; or_idx < qual_list[and_idx].length; or_idx++) {
            // Apply one qualifier to the row.
            Qualifier q = qual_list[and_idx][or_idx];
            int col_id = q.getColumnId();
            if (SanityManager.DEBUG) {
                SanityManager.ASSERT((col_id < row.length), "Qualifier is referencing a column not in the row.");
            }
            // Get the column from the possibly partial row, of the
            // q.getColumnId()'th column in the full row.
            DataValueDescriptor columnValue = (DataValueDescriptor) row[q.getColumnId()];
            if (SanityManager.DEBUG) {
                if (columnValue == null)
                    SanityManager.THROWASSERT("1:row = " + RowUtil.toString(row) + "row.length = " + row.length + ";q.getColumnId() = " + q.getColumnId());
            }
            // do the compare between the column value and value in the
            // qualifier.
            row_qualifies = columnValue.compare(q.getOperator(), q.getOrderable(), q.getOrderedNulls(), q.getUnknownRV());
            if (q.negateCompareResult())
                row_qualifies = !row_qualifies;
            // to go and process next AND clause.
            if (row_qualifies)
                break;
        }
        // qualifications so as soon as one is false processing is done.
        if (!row_qualifies)
            break;
    }
    return (row_qualifies);
}
Also used : Qualifier(org.apache.derby.iapi.store.access.Qualifier) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor)

Example 10 with Qualifier

use of org.apache.derby.iapi.store.access.Qualifier in project derby by apache.

the class NoPutResultSetImpl method clearOrderableCache.

// class implementation
/**
 * Clear the Orderable cache for each qualifier.
 * (This should be done each time a scan/conglomerate with
 * qualifiers is reopened.)
 *
 * @param qualifiers	The Qualifiers to clear
 */
protected void clearOrderableCache(Qualifier[][] qualifiers) throws StandardException {
    // Clear the Qualifiers's Orderable cache
    if (qualifiers != null) {
        Qualifier qual;
        for (int term = 0; term < qualifiers.length; term++) {
            for (int index = 0; index < qualifiers[term].length; index++) {
                qual = qualifiers[term][index];
                qual.clearOrderableCache();
                /* beetle 4880 performance enhancement and avoid deadlock while pushing
					 * down method call to store: pre-evaluate.
					 */
                if (((GenericQualifier) qual).variantType != Qualifier.VARIANT)
                    // ignore return value
                    qual.getOrderable();
            }
        }
    }
}
Also used : Qualifier(org.apache.derby.iapi.store.access.Qualifier)

Aggregations

Qualifier (org.apache.derby.iapi.store.access.Qualifier)12 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)6 FetchDescriptor (org.apache.derby.iapi.store.raw.FetchDescriptor)4 List (java.util.List)1 FormatableBitSet (org.apache.derby.iapi.services.io.FormatableBitSet)1 Storable (org.apache.derby.iapi.services.io.Storable)1 StatementContext (org.apache.derby.iapi.sql.conn.StatementContext)1 ExecRow (org.apache.derby.iapi.sql.execute.ExecRow)1 ConglomerateController (org.apache.derby.iapi.store.access.ConglomerateController)1 KeyHasher (org.apache.derby.iapi.store.access.KeyHasher)1 AuxObject (org.apache.derby.iapi.store.raw.AuxObject)1 RowLocation (org.apache.derby.iapi.types.RowLocation)1 SQLLongint (org.apache.derby.iapi.types.SQLLongint)1 StorableFormatId (org.apache.derby.impl.store.access.StorableFormatId)1