Search in sources :

Example 26 with SQLLongint

use of org.apache.derby.iapi.types.SQLLongint 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 27 with SQLLongint

use of org.apache.derby.iapi.types.SQLLongint in project derby by apache.

the class T_QualifierTest method t_scanFetchHashtable.

/**
 * Test scan which does FetchSet.
 * <p>
 * FetchSet() returns the entire result set in the hash table.
 * <p>
 *
 * @return Whether the test succeeded or not.
 *
 * @exception  StandardException  Standard exception policy.
 */
public static boolean t_scanFetchHashtable(TransactionController tc, long conglomid, DataValueDescriptor[] fetch_template, DataValueDescriptor[] start_key, int start_op, Qualifier[][] qualifier, DataValueDescriptor[] stop_key, int stop_op, int expect_numrows, int input_expect_key, int order) throws StandardException, T_Fail {
    HashSet set = null;
    long key;
    long numrows = 0;
    boolean ordered = (order == ORDER_FORWARD || order == ORDER_DESC);
    set = create_hash_set(input_expect_key, expect_numrows, order);
    // select entire data set into a hash table, with first column key
    int[] keyColumns = new int[1];
    keyColumns[0] = 0;
    BackingStoreHashtable result_set = tc.createBackingStoreHashtableFromScan(conglomid, 0, TransactionController.MODE_TABLE, TransactionController.ISOLATION_SERIALIZABLE, (FormatableBitSet) null, start_key, start_op, qualifier, stop_key, stop_op, // no limit on total rows.
    -1, // first column is hash key column
    keyColumns, // don't remove duplicates
    false, // no estimate of rows
    -1, // put it all into memory
    -1, // use default initial capacity
    -1, // use default load factor
    -1, // don't maintain runtime statistics
    false, // don't skip null key columns
    false, // don't keep after commit
    false, // don't include row locations
    false);
    // make sure the expected result set is the same as the actual result
    // set.
    Enumeration e = result_set.elements();
    while (e.hasMoreElements()) {
        Object obj;
        DataValueDescriptor[] row = null;
        if ((obj = e.nextElement()) instanceof DataValueDescriptor[]) {
            row = (DataValueDescriptor[]) obj;
            key = ((SQLLongint) (row[2])).getLong();
            if (!set.remove(key)) {
                return (fail("(t_scanFetchHashtable-obj) wrong key, expected (" + input_expect_key + ")" + "but got (" + key + ")."));
            }
            numrows++;
        } else if (obj instanceof List) {
            List row_vect = (List) obj;
            for (int i = 0; i < row_vect.size(); i++) {
                row = (DataValueDescriptor[]) row_vect.get(i);
                key = ((SQLLongint) (row[2])).getLong();
                if (!set.remove(key)) {
                    return (fail("(t_scanFetchHashtable-vector) wrong key, expected (" + input_expect_key + ")" + "but got (" + key + ")."));
                }
                numrows++;
            }
        } else {
            return (fail("(t_scanFetchHashtable) got bad type for data: " + obj));
        }
    }
    if (numrows != expect_numrows) {
        return (fail("(t_scanFetchHashtable) wrong number of rows. Expected " + expect_numrows + " rows, but got " + numrows + "rows."));
    }
    result_set.close();
    // select entire data set into a hash table, with key being
    // the third column, which is the unique id used to verify the
    // right result set is being returned.:
    // open a new scan
    keyColumns[0] = 2;
    result_set = tc.createBackingStoreHashtableFromScan(conglomid, 0, TransactionController.MODE_TABLE, TransactionController.ISOLATION_SERIALIZABLE, (FormatableBitSet) null, start_key, start_op, qualifier, stop_key, stop_op, // no limit on total rows.
    -1, // third column is hash key column
    keyColumns, // don't remove duplicates
    false, // no estimate of rows
    -1, // put it all into memory
    -1, // use default initial capacity
    -1, // use default load factor
    -1, // don't maintain runtime statistics
    false, // don't skip null key columns
    false, // don't keep after commit
    false, // don't include row locations
    false);
    Object removed_obj;
    for (numrows = 0; numrows < expect_numrows; numrows++) {
        long exp_key;
        if (order == ORDER_DESC)
            exp_key = input_expect_key - numrows;
        else
            exp_key = input_expect_key + numrows;
        if ((removed_obj = result_set.remove(new SQLLongint(exp_key))) == null) {
            fail("(t_scanFetchHashtable-2-vector) wrong key, expected (" + (exp_key) + ")" + "but did not find it.");
        }
    }
    if (numrows != expect_numrows) {
        return (fail("(t_scanFetchHashtable-2) wrong number of rows. Expected " + expect_numrows + " rows, but got " + numrows + "rows."));
    }
    return (true);
}
Also used : Enumeration(java.util.Enumeration) SQLLongint(org.apache.derby.iapi.types.SQLLongint) List(java.util.List) FormatableBitSet(org.apache.derby.iapi.services.io.FormatableBitSet) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) HashSet(java.util.HashSet) BackingStoreHashtable(org.apache.derby.iapi.store.access.BackingStoreHashtable)

Example 28 with SQLLongint

use of org.apache.derby.iapi.types.SQLLongint in project derby by apache.

the class T_QualifierTest method t_scanFetchNextPartial.

/**
 * Test scan which does FetchNext with subset of fields.
 * <p>
 * FetchNext() may be optimized by the underlying scan code to try and
 * not do multiple fetches of the same row for the user, but if the user
 * asks for one column, but the stop position depends on the whole row
 * this optimization is not possible.
 * <p>
 *
 * @return Whether the test succeeded or not.
 *
 * @exception  StandardException  Standard exception policy.
 */
public static boolean t_scanFetchNextPartial(TransactionController tc, long conglomid, DataValueDescriptor[] fetch_template, DataValueDescriptor[] start_key, int start_op, Qualifier[][] qualifier, DataValueDescriptor[] stop_key, int stop_op, int expect_numrows, int input_expect_key, int order) throws StandardException, T_Fail {
    HashSet set = null;
    boolean ordered = (order == ORDER_FORWARD || order == ORDER_DESC);
    /**
     ********************************************************************
     * setup shared by both.
     **********************************************************************
     */
    // In the fetchNext call only ask the minimum set of columns
    // necessary, which is the union of the "key" (col[2]) and other
    // columns referenced in the qualifier list.
    FormatableBitSet fetch_row_validColumns = RowUtil.getQualifierBitSet(qualifier);
    // now add in column 2, as we always need the key field.
    // grow to length of 3
    fetch_row_validColumns.grow(3);
    fetch_row_validColumns.set(2);
    // add in any fields in start and stop positions
    if (start_key != null) {
        for (int i = 0; i < start_key.length; i++) {
            fetch_row_validColumns.set(i);
        }
    }
    if (stop_key != null) {
        for (int i = 0; i < stop_key.length; i++) {
            fetch_row_validColumns.set(i);
        }
    }
    // point key at the right column in the fetch_template
    SQLLongint key_column = (SQLLongint) fetch_template[2];
    if (!ordered) {
        set = create_hash_set(input_expect_key, expect_numrows, order);
    }
    ScanController scan = tc.openScan(conglomid, false, 0, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE, (FormatableBitSet) fetch_row_validColumns, start_key, start_op, qualifier, stop_key, stop_op);
    int expect_key = input_expect_key;
    long key = -42;
    long key2 = -42;
    long numrows = 0;
    while (scan.fetchNext(fetch_template)) {
        // see if we are getting the right keys.
        key = key_column.getLong();
        // make sure a subsequent fetch also works.
        key_column.setValue(-42);
        scan.fetch(fetch_template);
        key2 = key_column.getLong();
        if (ordered) {
            if ((key != expect_key) || (key2 != expect_key)) {
                return (fail("(t_scanFetchNext) wrong key, expected (" + expect_key + ")" + "but got (" + key + ")."));
            } else {
                if (order == ORDER_DESC)
                    expect_key--;
                else
                    expect_key++;
            }
        } else {
            if (!set.remove(key)) {
                return (fail("(t_scanFetchNext) wrong key, expected (" + expect_key + ")" + "but got (" + key + ")."));
            }
        }
        numrows++;
    }
    scan.close();
    if (numrows != expect_numrows) {
        return (fail("(t_scanFetchNext) wrong number of rows. Expected " + expect_numrows + " rows, but got " + numrows + "rows."));
    }
    return (true);
}
Also used : ScanController(org.apache.derby.iapi.store.access.ScanController) GroupFetchScanController(org.apache.derby.iapi.store.access.GroupFetchScanController) SQLLongint(org.apache.derby.iapi.types.SQLLongint) FormatableBitSet(org.apache.derby.iapi.services.io.FormatableBitSet) SQLLongint(org.apache.derby.iapi.types.SQLLongint) HashSet(java.util.HashSet)

Example 29 with SQLLongint

use of org.apache.derby.iapi.types.SQLLongint in project derby by apache.

the class T_CreateConglomRet method t_012.

/**
 * Test Special cases of split.
 * <p>
 * Testing: restartSplitFor() call in BranchControlRow().
 *
 * The second case is the same as the first except the calling code is
 * trying to split a branch page and the parent branch page doesn't have
 * room for the row.
 *
 * @exception  StandardException  Standard exception policy.
 * @exception  T_Fail  Throws T_Fail on any test failure.
 */
protected boolean t_012(TransactionController tc) throws StandardException, T_Fail {
    boolean ret_val = true;
    REPORT("Starting t_011");
    T_CreateConglomRet create_ret = new T_CreateConglomRet();
    createCongloms(tc, 2, false, true, 0, create_ret);
    // Open the base conglomerate.
    ConglomerateController base_cc = tc.openConglomerate(create_ret.base_conglomid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
    // Open the index conglomerate.
    ConglomerateController index_cc = tc.openConglomerate(create_ret.index_conglomid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
    // Create a row.
    T_SecondaryIndexRow index_row = new T_SecondaryIndexRow();
    RowLocation rowloc = base_cc.newRowLocationTemplate();
    DataValueDescriptor[] base_row = TemplateRow.newU8Row(2);
    base_row[0] = new SQLChar("aaaaaaaaaa");
    index_row.init(base_row, rowloc, 3);
    ((SQLChar) base_row[0]).setValue(T_b2i.repeatString("a", 1000));
    ((SQLLongint) base_row[1]).setValue(1);
    base_cc.insertAndFetchLocation(base_row, rowloc);
    // CAUSE BRANCH splitFor to loop:
    // pick numbers so that split will happen in middle of page.  Do this
    // by first inserting last row in table and then insert smaller rows,
    // then insert rows before it until the table is just ready to split
    // the root, and finally insert some shorter rows in such a way as
    // they cause a split but the split point is chosen with one of the
    // larger rows as the descriminator causing 1st splitfor pass to fail
    // and loop back and do a splitFor the larger row.
    // insert enough rows so the tree is 3 levels, just ready to go to
    // 4 levels.
    ((SQLChar) base_row[0]).setValue(T_b2i.repeatString("ma", 500));
    for (int i = 0; i < 3; i++) {
        ((SQLLongint) base_row[1]).setValue(i);
        base_cc.insertAndFetchLocation(base_row, rowloc);
        if (index_cc.insert(index_row.getRow()) != 0)
            throw T_Fail.testFailMsg("insert failed");
    }
    ((SQLChar) base_row[0]).setValue(T_b2i.repeatString("m", 1000));
    for (int i = 3; i < 23; i++) {
        ((SQLLongint) base_row[1]).setValue(i);
        base_cc.insertAndFetchLocation(base_row, rowloc);
        if (index_cc.insert(index_row.getRow()) != 0)
            throw T_Fail.testFailMsg("insert failed");
    }
    ((SQLChar) base_row[0]).setValue(T_b2i.repeatString("a", 600));
    for (int i = 123; i > 111; i--) {
        ((SQLLongint) base_row[1]).setValue(i * 2);
        base_cc.insertAndFetchLocation(base_row, rowloc);
        if (index_cc.insert(index_row.getRow()) != 0)
            throw T_Fail.testFailMsg("insert failed");
    }
    {
        ((SQLLongint) base_row[1]).setValue(227);
        base_cc.insertAndFetchLocation(base_row, rowloc);
        if (index_cc.insert(index_row.getRow()) != 0)
            throw T_Fail.testFailMsg("insert failed");
    }
    // ((B2IController)index_cc).printTree();
    tc.commit();
    // Close the conglomerate.
    index_cc.close();
    REPORT("Ending t_012");
    return (ret_val);
}
Also used : ConglomerateController(org.apache.derby.iapi.store.access.ConglomerateController) SQLLongint(org.apache.derby.iapi.types.SQLLongint) SQLChar(org.apache.derby.iapi.types.SQLChar) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) RowLocation(org.apache.derby.iapi.types.RowLocation) SQLLongint(org.apache.derby.iapi.types.SQLLongint)

Example 30 with SQLLongint

use of org.apache.derby.iapi.types.SQLLongint in project derby by apache.

the class T_CreateConglomRet method t_005.

/**
 * Test Branch splits - number of rows necessary to cause splits is raw
 * store implementation dependant (currently 5 rows per page in in-memory
 * implementation).
 *
 * @exception  StandardException  Standard exception policy.
 * @exception  T_Fail  Throws T_Fail on any test failure.
 */
protected boolean t_005(TransactionController tc) throws StandardException, T_Fail {
    boolean ret_val = true;
    REPORT("Starting t_005");
    T_CreateConglomRet create_ret = new T_CreateConglomRet();
    createCongloms(tc, 2, false, false, 0, create_ret);
    // Open the base conglomerate.
    ConglomerateController base_cc = tc.openConglomerate(create_ret.base_conglomid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
    // Open the index conglomerate.
    ConglomerateController index_cc = tc.openConglomerate(create_ret.index_conglomid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
    // Create a row.
    T_SecondaryIndexRow index_row = new T_SecondaryIndexRow();
    RowLocation rowloc = base_cc.newRowLocationTemplate();
    DataValueDescriptor[] base_row = TemplateRow.newU8Row(2);
    index_row.init(base_row, rowloc, 3);
    // insert them in reverse order just to make sure btree is sorting them
    for (int i = 200; i >= 0; i -= 4) {
        ((SQLLongint) base_row[0]).setValue(1);
        ((SQLLongint) base_row[1]).setValue(i);
        base_cc.insertAndFetchLocation(base_row, rowloc);
        if (index_cc.insert(index_row.getRow()) != 0)
            throw T_Fail.testFailMsg("insert failed");
    }
    for (int i = 199; i >= 0; i -= 4) {
        ((SQLLongint) base_row[0]).setValue(1);
        ((SQLLongint) base_row[1]).setValue(i);
        base_cc.insertAndFetchLocation(base_row, rowloc);
        if (index_cc.insert(index_row.getRow()) != 0)
            throw T_Fail.testFailMsg("insert failed");
    }
    index_cc.checkConsistency();
    // Close the conglomerate.
    index_cc.close();
    tc.commit();
    // Search for each of the keys and delete them one at a time.
    DataValueDescriptor[] delete_key = TemplateRow.newU8Row(2);
    for (int i = 200; i >= 0; i -= 4) {
        ((SQLLongint) delete_key[0]).setValue(1);
        ((SQLLongint) delete_key[1]).setValue(i);
        if (!t_delete(tc, create_ret.index_conglomid, delete_key, false)) {
            ret_val = false;
        }
    }
    for (int i = 199; i >= 0; i -= 4) {
        ((SQLLongint) delete_key[0]).setValue(1);
        ((SQLLongint) delete_key[1]).setValue(i);
        if (!t_delete(tc, create_ret.index_conglomid, delete_key, false)) {
            ret_val = false;
        }
    }
    tc.commit();
    // Open the base conglomerate.
    base_cc = tc.openConglomerate(create_ret.base_conglomid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
    // Open the conglomerate.
    index_cc = tc.openConglomerate(create_ret.index_conglomid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
    // flush and empty cache to make sure rereading stuff works.
    RawStoreFactory rawstore = (RawStoreFactory) findServiceModule(this.store_module, RawStoreFactory.MODULE);
    rawstore.idle();
    for (int i = 200; i >= 0; i -= 3) {
        ((SQLLongint) base_row[0]).setValue(1);
        ((SQLLongint) base_row[1]).setValue(i);
        base_cc.insertAndFetchLocation(base_row, rowloc);
        if (index_cc.insert(index_row.getRow()) != 0)
            throw T_Fail.testFailMsg("insert failed");
    }
    for (int i = 200; i >= 0; i -= 3) {
        ((SQLLongint) delete_key[0]).setValue(1);
        ((SQLLongint) delete_key[1]).setValue(i);
        if (!t_delete(tc, create_ret.index_conglomid, delete_key, false)) {
            ret_val = false;
        }
    }
    // index check - there should be no records left.
    ScanController empty_scan = tc.openScan(create_ret.index_conglomid, false, 0, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE, (FormatableBitSet) null, null, ScanController.NA, null, null, ScanController.NA);
    if (empty_scan.next())
        throw T_Fail.testFailMsg("t_005: there are still rows in table.");
    index_cc.checkConsistency();
    for (int i = 600; i >= 400; i -= 3) {
        ((SQLLongint) base_row[0]).setValue(1);
        ((SQLLongint) base_row[1]).setValue(i);
        base_cc.insertAndFetchLocation(base_row, rowloc);
        if (index_cc.insert(index_row.getRow()) != 0)
            throw T_Fail.testFailMsg("insert failed");
    }
    index_cc.checkConsistency();
    tc.abort();
    // index check - there should be no records left.
    empty_scan = tc.openScan(create_ret.index_conglomid, false, 0, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE, (FormatableBitSet) null, null, ScanController.NA, null, null, ScanController.NA);
    if (empty_scan.next())
        throw T_Fail.testFailMsg("t_005: there are still rows in table.");
    REPORT("Ending t_005");
    return (ret_val);
}
Also used : ScanController(org.apache.derby.iapi.store.access.ScanController) ConglomerateController(org.apache.derby.iapi.store.access.ConglomerateController) SQLLongint(org.apache.derby.iapi.types.SQLLongint) FormatableBitSet(org.apache.derby.iapi.services.io.FormatableBitSet) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) RowLocation(org.apache.derby.iapi.types.RowLocation) SQLLongint(org.apache.derby.iapi.types.SQLLongint) RawStoreFactory(org.apache.derby.iapi.store.raw.RawStoreFactory)

Aggregations

SQLLongint (org.apache.derby.iapi.types.SQLLongint)50 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)28 RowLocation (org.apache.derby.iapi.types.RowLocation)24 ConglomerateController (org.apache.derby.iapi.store.access.ConglomerateController)21 ScanController (org.apache.derby.iapi.store.access.ScanController)19 FormatableBitSet (org.apache.derby.iapi.services.io.FormatableBitSet)13 SQLChar (org.apache.derby.iapi.types.SQLChar)10 Properties (java.util.Properties)7 HashSet (java.util.HashSet)5 ExecRow (org.apache.derby.iapi.sql.execute.ExecRow)5 GroupFetchScanController (org.apache.derby.iapi.store.access.GroupFetchScanController)4 StandardException (org.apache.derby.shared.common.error.StandardException)4 ColumnOrdering (org.apache.derby.iapi.store.access.ColumnOrdering)3 SQLVarchar (org.apache.derby.iapi.types.SQLVarchar)3 ContextManager (org.apache.derby.iapi.services.context.ContextManager)2 ContextService (org.apache.derby.iapi.services.context.ContextService)2 BackingStoreHashtable (org.apache.derby.iapi.store.access.BackingStoreHashtable)2 NumberDataValue (org.apache.derby.iapi.types.NumberDataValue)2 UserType (org.apache.derby.iapi.types.UserType)2 Enumeration (java.util.Enumeration)1