📄 t_qualifiertest.java
字号:
return(fail("(t_scanFetchNext) wrong number of rows. Expected " + expect_numrows + " rows, but got " + numrows + "rows.")); } /********************************************************************** * Backward scan test case ********************************************************************** */ /* if (!ordered) { set = create_hash_set(expect_key, expect_numrows, order); } scan = tc.openBackwardScan( conglomid, false, 0, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE, (FormatableBitSet) fetch_row_validColumns, stop_key, flip_scan_op(stop_op), qualifier, start_key, flip_scan_op(start_op)); expect_key = input_expect_key + expect_numrows - 1; key = -42; key2 = -42; numrows = 0; while (scan.fetchNext(fetch_template)) { // see if we are getting the right keys. key = key_column.getValue(); // make sure a subsequent fetch also works. key_column.setValue(-42); scan.fetch(fetch_template); key2 = key_column.getValue(); if (ordered) { if ((key != expect_key) || (key2 != expect_key)) { return( fail("(t_scanFetchNext) wrong key, expected (" + expect_key + ")" + "but got (" + key + ").")); } else { expect_key--; } } else { if (!set.remove(new Long(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); } /** * 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, -1, // no limit on total rows. keyColumns, // first column is hash key column false, // don't remove duplicates -1, // no estimate of rows -1, // put it all into memory -1, // use default initial capacity -1, // use default load factor false, // don't maintain runtime statistics false); // don't skip null key columns // make sure the expected result set is the same as the actual result // set. Enumeration enum = result_set.elements(); while (enum.hasMoreElements()) { Object obj; DataValueDescriptor[] row = null; if ((obj = enum.nextElement()) instanceof DataValueDescriptor[] ) { row = (DataValueDescriptor[] ) obj; key = ((SQLLongint)(row[2])).getLong(); if (!set.remove(new Long(key))) { return( fail("(t_scanFetchHashtable-obj) wrong key, expected (" + input_expect_key + ")" + "but got (" + key + ").")); } numrows++; } else if (obj instanceof Vector) { Vector row_vect = (Vector) obj; for (int i = 0; i < row_vect.size(); i++) { row = (DataValueDescriptor[] ) row_vect.elementAt(i); key = ((SQLLongint)(row[2])).getLong(); if (!set.remove(new Long(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, -1, // no limit on total rows. keyColumns, // third column is hash key column false, // don't remove duplicates -1, // no estimate of rows -1, // put it all into memory -1, // use default initial capacity -1, // use default load factor false, // don't maintain runtime statistics false); // don't skip null key columns 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); } /* 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, 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, 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, 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,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -