0001: /*
0002:
0003: Derby - Class org.apache.derbyTesting.unitTests.store.T_QualifierTest
0004:
0005: Licensed to the Apache Software Foundation (ASF) under one or more
0006: contributor license agreements. See the NOTICE file distributed with
0007: this work for additional information regarding copyright ownership.
0008: The ASF licenses this file to You under the Apache License, Version 2.0
0009: (the "License"); you may not use this file except in compliance with
0010: the License. You may obtain a copy of the License at
0011:
0012: http://www.apache.org/licenses/LICENSE-2.0
0013:
0014: Unless required by applicable law or agreed to in writing, software
0015: distributed under the License is distributed on an "AS IS" BASIS,
0016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0017: See the License for the specific language governing permissions and
0018: limitations under the License.
0019:
0020: */
0021:
0022: package org.apache.derbyTesting.unitTests.store;
0023:
0024: import org.apache.derbyTesting.unitTests.harness.T_Fail;
0025:
0026: import org.apache.derby.impl.store.access.conglomerate.*;
0027:
0028: import java.util.Properties;
0029: import java.util.HashSet;
0030:
0031: import java.io.PrintWriter;
0032: import org.apache.derby.iapi.services.stream.HeaderPrintWriter;
0033: import org.apache.derby.iapi.error.StandardException;
0034: import org.apache.derby.iapi.store.access.ConglomerateController;
0035: import org.apache.derby.iapi.store.access.GroupFetchScanController;
0036: import org.apache.derby.iapi.store.access.Qualifier;
0037: import org.apache.derby.iapi.store.access.RowUtil;
0038: import org.apache.derby.iapi.store.access.ScanController;
0039: import org.apache.derby.iapi.store.access.TransactionController;
0040:
0041: import org.apache.derby.iapi.types.DataValueDescriptor;
0042:
0043: import org.apache.derby.iapi.types.Orderable;
0044: import org.apache.derby.iapi.types.RowLocation;
0045:
0046: import org.apache.derby.iapi.types.SQLLongint;
0047:
0048: import org.apache.derby.iapi.store.access.BackingStoreHashtable;
0049: import org.apache.derby.iapi.services.io.FormatableBitSet;
0050: import java.util.Enumeration;
0051: import java.util.Vector;
0052:
0053: public class T_QualifierTest {
0054: private String init_conglomerate_type;
0055: private Properties init_properties;
0056: private boolean init_temporary;
0057: private HeaderPrintWriter init_out;
0058: private int init_order = ORDER_NONE;
0059:
0060: public static final int ORDER_FORWARD = 1;
0061: public static final int ORDER_BACKWARD = 2;
0062: public static final int ORDER_NONE = 3;
0063: public static final int ORDER_DESC = 4; // ordered in descending order
0064:
0065: /* Constructor */
0066: public T_QualifierTest(String conglomerate_type,
0067: Properties properties, boolean temporary,
0068: HeaderPrintWriter out, int order) {
0069: this .init_conglomerate_type = conglomerate_type;
0070: this .init_properties = properties;
0071: this .init_temporary = temporary;
0072: this .init_out = out;
0073: this .init_order = order;
0074:
0075: return;
0076: }
0077:
0078: /**************************************************************************
0079: * Private/Protected methods of This class:
0080: **************************************************************************
0081: */
0082: private static HashSet create_hash_set(int expect_key,
0083: int expect_numrows, int order) {
0084: HashSet set = new HashSet(10, 0.8f);
0085:
0086: int key_val = expect_key;
0087: for (int i = 0; i < expect_numrows; i++) {
0088: set.add(new Long(key_val));
0089: if (order == ORDER_DESC)
0090: key_val--;
0091: else
0092: key_val++;
0093: }
0094:
0095: return (set);
0096: }
0097:
0098: private static int flip_scan_op(int op) {
0099: int ret_op = -42;
0100:
0101: if (op == ScanController.GE)
0102: ret_op = ScanController.GT;
0103: else if (op == ScanController.GT)
0104: ret_op = ScanController.GE;
0105:
0106: return (ret_op);
0107: }
0108:
0109: /**
0110: * Test a single scan.
0111: */
0112: public static boolean t_scan(TransactionController tc,
0113: long conglomid, DataValueDescriptor[] init_scan_template,
0114: DataValueDescriptor[] fetch_template,
0115: DataValueDescriptor[] start_key, int start_op,
0116: Qualifier qualifier[][], DataValueDescriptor[] stop_key,
0117: int stop_op, int expect_numrows, int lowest_expect_key,
0118: int order) throws StandardException, T_Fail {
0119: boolean ret_val;
0120:
0121: // call scan which does next(), fetch(row)
0122: ret_val = t_scanNext(tc, conglomid, fetch_template, start_key,
0123: start_op, qualifier, stop_key, stop_op, expect_numrows,
0124: lowest_expect_key, order);
0125:
0126: if (!ret_val)
0127: return (ret_val);
0128:
0129: // call scan which does fetchNext(row), fetch(row)
0130: ret_val = t_scanFetchNext(tc, conglomid, init_scan_template,
0131: fetch_template, start_key, start_op, qualifier,
0132: stop_key, stop_op, expect_numrows, lowest_expect_key,
0133: order);
0134:
0135: if (!ret_val)
0136: return (ret_val);
0137:
0138: // call scan which does fetchNext(partial_row), fetch(partial_row)
0139:
0140: ret_val = t_scanFetchNextPartial(tc, conglomid, fetch_template,
0141: start_key, start_op, qualifier, stop_key, stop_op,
0142: expect_numrows, lowest_expect_key, order);
0143:
0144: if (!ret_val)
0145: return (ret_val);
0146:
0147: // call scan which does createBackingStoreHashtable()
0148: ret_val = t_scanFetchHashtable(tc, conglomid, fetch_template,
0149: start_key, start_op, qualifier, stop_key, stop_op,
0150: expect_numrows, lowest_expect_key, order);
0151:
0152: if (!ret_val)
0153: return (ret_val);
0154:
0155: // call scan which does fetchNextGroup() - fetching 1 at a time.
0156: // this tests the edge case.
0157: ret_val = t_scanFetchNextGroup(tc, 1, conglomid,
0158: fetch_template, start_key, start_op, qualifier,
0159: stop_key, stop_op, expect_numrows, lowest_expect_key,
0160: order);
0161:
0162: if (!ret_val)
0163: return (ret_val);
0164:
0165: // call scan which does fetchNextGroup() - fetching 2 at a time.
0166: // this tests the general case of fetching N rows which is usually
0167: // less than the remaining rows in the result set.
0168: ret_val = t_scanFetchNextGroup(tc, 2, conglomid,
0169: fetch_template, start_key, start_op, qualifier,
0170: stop_key, stop_op, expect_numrows, lowest_expect_key,
0171: order);
0172:
0173: if (!ret_val)
0174: return (ret_val);
0175:
0176: // call scan which does fetchNextGroup() - fetching 1000 at a time.
0177: // this will get the entire result set in one fetch.
0178: ret_val = t_scanFetchNextGroup(tc, 1000, conglomid,
0179: fetch_template, start_key, start_op, qualifier,
0180: stop_key, stop_op, expect_numrows, lowest_expect_key,
0181: order);
0182:
0183: if (!ret_val)
0184: return (ret_val);
0185:
0186: return (ret_val);
0187:
0188: }
0189:
0190: private static boolean t_scanNext(TransactionController tc,
0191: long conglomid, DataValueDescriptor[] fetch_template,
0192: DataValueDescriptor[] start_key, int start_op,
0193: Qualifier qualifier[][], DataValueDescriptor[] stop_key,
0194: int stop_op, int expect_numrows, int input_expect_key,
0195: int order) throws StandardException, T_Fail {
0196: HashSet set = null;
0197: boolean ordered = (order == T_QualifierTest.ORDER_FORWARD || order == T_QualifierTest.ORDER_DESC);
0198: int expect_key = input_expect_key;
0199:
0200: if (!ordered) {
0201: set = create_hash_set(input_expect_key, expect_numrows,
0202: order);
0203: }
0204:
0205: /**********************************************************************
0206: * Forward scan test case
0207: **********************************************************************
0208: */
0209:
0210: ScanController scan = tc.openScan(conglomid, false, 0,
0211: TransactionController.MODE_RECORD,
0212: TransactionController.ISOLATION_SERIALIZABLE,
0213: (FormatableBitSet) null, start_key, start_op,
0214: qualifier, stop_key, stop_op);
0215:
0216: long key = -42;
0217: int numrows = 0;
0218:
0219: while (scan.next()) {
0220: scan.fetch(fetch_template);
0221:
0222: key = ((SQLLongint) (fetch_template[2])).getLong();
0223:
0224: if (ordered) {
0225: if (key != expect_key) {
0226: return (fail("(t_scanNext) wrong key, expected ("
0227: + expect_key + ")" + "but got (" + key
0228: + ")."));
0229: } else {
0230: if (order == ORDER_DESC)
0231: expect_key--;
0232: else
0233: expect_key++;
0234: }
0235: } else {
0236: if (!set.remove(new Long(key))) {
0237: return (fail("(t_scanNext) wrong key, expected ("
0238: + expect_key + ")" + "but got (" + key
0239: + ")."));
0240: }
0241: }
0242: numrows++;
0243:
0244: }
0245:
0246: scan.close();
0247:
0248: if (numrows != expect_numrows) {
0249: return (fail("(t_scanNext) wrong number of rows. Expected "
0250: + expect_numrows + " rows, but got " + numrows
0251: + "rows."));
0252: }
0253:
0254: /**********************************************************************
0255: * Backward scan test case
0256: **********************************************************************
0257: */
0258: /*
0259:
0260: if (!ordered)
0261: {
0262: set = create_hash_set(input_expect_key, expect_numrows, order);
0263: }
0264:
0265: // flip start and stop keys for backward scan and also flip
0266: // start and stop operators (ie. GE->GT and GT->GE).
0267: scan =
0268: tc.openBackwardScan(
0269: conglomid, false,
0270: 0,
0271: TransactionController.MODE_RECORD,
0272: TransactionController.ISOLATION_SERIALIZABLE,
0273: (FormatableBitSet) null,
0274: stop_key, flip_scan_op(stop_op),
0275: qualifier,
0276: start_key, flip_scan_op(start_op));
0277:
0278: key = -42;
0279: numrows = 0;
0280:
0281: // rows are going to come back in reverse order in the ordered case.
0282: expect_key = input_expect_key + expect_numrows - 1;
0283:
0284: while (scan.next())
0285: {
0286: scan.fetch(fetch_template);
0287:
0288: key = ((SQLLongint)(fetch_template[2])).getLong();
0289:
0290: if (ordered)
0291: {
0292: if (key != expect_key)
0293: {
0294: return(
0295: fail("(t_scanNext-backward) wrong key, expected (" +
0296: expect_key + ")" + "but got (" + key + ")."));
0297: }
0298: else
0299: {
0300: expect_key--;
0301: }
0302: }
0303: else
0304: {
0305: if (!set.remove(new Long(key)))
0306: {
0307: return(
0308: fail("(t_scanNext-backward) wrong key, expected (" +
0309: expect_key + ")" + "but got (" + key + ")."));
0310: }
0311: }
0312: numrows++;
0313: }
0314:
0315: if (numrows != expect_numrows)
0316: {
0317: return(fail("(t_scanNext-backward) wrong num of rows. Expected " +
0318: expect_numrows + " rows, but got " + numrows + "rows."));
0319: }
0320:
0321: scan.close();
0322: */
0323:
0324: return (true);
0325: }
0326:
0327: /**
0328: * Test scan which does FetchNext with all of the fields.
0329: * <p>
0330: * FetchNext() may be optimized by the underlying scan code to try and
0331: * not do multiple fetches of the same row for the user, but if the user
0332: * asks for one column, but the stop position depends on the whole row
0333: * this optimization is not possible.
0334: * <p>
0335: *
0336: * @return Whether the test succeeded or not.
0337: *
0338: * @exception StandardException Standard exception policy.
0339: **/
0340: public static boolean t_scanFetchNext(TransactionController tc,
0341: long conglomid, DataValueDescriptor[] init_scan_template,
0342: DataValueDescriptor[] fetch_template,
0343: DataValueDescriptor[] start_key, int start_op,
0344: Qualifier qualifier[][], DataValueDescriptor[] stop_key,
0345: int stop_op, int expect_numrows, int input_expect_key,
0346: int order) throws StandardException, T_Fail {
0347: HashSet set = null;
0348: boolean ordered = (order == ORDER_FORWARD || order == ORDER_DESC);
0349:
0350: if (!ordered) {
0351: set = create_hash_set(input_expect_key, expect_numrows,
0352: order);
0353: }
0354:
0355: /**********************************************************************
0356: * Forward scan test case
0357: **********************************************************************
0358: */
0359:
0360: ScanController scan = tc.openScan(conglomid, false, 0,
0361: TransactionController.MODE_RECORD,
0362: TransactionController.ISOLATION_SERIALIZABLE,
0363: (FormatableBitSet) null, start_key, start_op,
0364: qualifier, stop_key, stop_op);
0365:
0366: int expect_key = input_expect_key;
0367: long key = -42;
0368: long numrows = 0;
0369:
0370: while (scan.fetchNext(fetch_template)) {
0371: scan.fetch(init_scan_template);
0372:
0373: // make sure all columns from fetchNext() match subsequent fetch().
0374: for (int i = 0; i < init_scan_template.length; i++) {
0375: if ((fetch_template[i])
0376: .compare((init_scan_template[i])) != 0) {
0377: return (fail("(t_scanFetchNext) wrong key, expected ("
0378: + fetch_template[i]
0379: + ")"
0380: + "but got ("
0381: + init_scan_template[i] + ")."));
0382: }
0383: }
0384:
0385: // see if we are getting the right keys.
0386: key = ((SQLLongint) (init_scan_template[2])).getLong();
0387:
0388: if (ordered) {
0389: if (key != expect_key) {
0390: return (fail("(t_scanFetchNext) wrong key, expected ("
0391: + expect_key
0392: + ")"
0393: + "but got ("
0394: + key
0395: + ")."));
0396: } else {
0397: if (order == ORDER_DESC)
0398: expect_key--;
0399: else
0400: expect_key++;
0401: }
0402: } else {
0403: if (!set.remove(new Long(key))) {
0404: return (fail("(t_scanFetchNext) wrong key, expected ("
0405: + expect_key
0406: + ")"
0407: + "but got ("
0408: + key
0409: + ")."));
0410: }
0411: }
0412: numrows++;
0413:
0414: }
0415:
0416: scan.close();
0417:
0418: if (numrows != expect_numrows) {
0419: return (fail("(t_scanFetchNext) wrong number of rows. Expected "
0420: + expect_numrows
0421: + " rows, but got "
0422: + numrows
0423: + "rows."));
0424: }
0425:
0426: /**********************************************************************
0427: * Backward scan test case
0428: **********************************************************************
0429: */
0430:
0431: /*
0432: if (!ordered)
0433: {
0434: set = create_hash_set(input_expect_key, expect_numrows, order);
0435: }
0436:
0437: scan =
0438: tc.openBackwardScan(
0439: conglomid, false,
0440: 0,
0441: TransactionController.MODE_RECORD,
0442: TransactionController.ISOLATION_SERIALIZABLE,
0443: (FormatableBitSet) null,
0444: stop_key, flip_scan_op(stop_op),
0445: qualifier,
0446: start_key, flip_scan_op(start_op));
0447:
0448: expect_key = input_expect_key + expect_numrows - 1;
0449: key = -42;
0450: numrows = 0;
0451:
0452: while (scan.fetchNext(fetch_template))
0453: {
0454: scan.fetch(init_scan_template);
0455:
0456: // make sure all columns from fetchNext() match subsequent fetch().
0457: for (int i = 0; i < init_scan_template.length; i++)
0458: {
0459: if (((Orderable)fetch_template[i]).compare(
0460: ((Orderable)init_scan_template[i])) != 0)
0461: {
0462: return(
0463: fail("(t_scanFetchNext) wrong key, expected (" +
0464: fetch_template[i] + ")" + "but got (" +
0465: init_scan_template[i] + ")."));
0466: }
0467: }
0468:
0469: // see if we are getting the right keys.
0470: key = ((SQLLongint)(init_scan_template[2])).getLong();
0471:
0472: if (ordered)
0473: {
0474: if (key != expect_key)
0475: {
0476: return(
0477: fail("(t_scanFetchNext) wrong key, expected (" +
0478: expect_key + ")" + "but got (" + key + ")."));
0479: }
0480: else
0481: {
0482: expect_key--;
0483: }
0484: }
0485: else
0486: {
0487: if (!set.remove(new Long(key)))
0488: {
0489: return(
0490: fail("(t_scanFetchNext) wrong key, expected (" +
0491: expect_key + ")" + "but got (" + key + ")."));
0492: }
0493: }
0494: numrows++;
0495:
0496: }
0497:
0498: scan.close();
0499:
0500: if (numrows != expect_numrows)
0501: {
0502: return(fail("(t_scanFetchNext) wrong number of rows. Expected " +
0503: expect_numrows + " rows, but got " + numrows + "rows."));
0504: }
0505: */
0506:
0507: return (true);
0508: }
0509:
0510: /**
0511: * Test scan which does FetchNextGroup with all of the fields.
0512: * <p>
0513: *
0514: * @return Whether the test succeeded or not.
0515: *
0516: * @exception StandardException Standard exception policy.
0517: **/
0518: public static boolean t_scanFetchNextGroup(
0519: TransactionController tc, int group_size, long conglomid,
0520: DataValueDescriptor[] fetch_template,
0521: DataValueDescriptor[] start_key, int start_op,
0522: Qualifier qualifier[][], DataValueDescriptor[] stop_key,
0523: int stop_op, int expect_numrows, int input_expect_key,
0524: int order) throws StandardException, T_Fail {
0525: HashSet set = null;
0526: boolean ordered = (order == ORDER_FORWARD || order == ORDER_DESC);
0527:
0528: if (!ordered) {
0529: set = create_hash_set(input_expect_key, expect_numrows,
0530: order);
0531: }
0532:
0533: /**********************************************************************
0534: * Forward scan test case
0535: **********************************************************************
0536: */
0537:
0538: GroupFetchScanController scan = tc.openGroupFetchScan(
0539: conglomid, false, 0, TransactionController.MODE_RECORD,
0540: TransactionController.ISOLATION_SERIALIZABLE,
0541: (FormatableBitSet) null, start_key, start_op,
0542: qualifier, stop_key, stop_op);
0543:
0544: // create an array of "group_size" rows to use in the fetch group call.
0545: DataValueDescriptor[][] row_array = new DataValueDescriptor[group_size][];
0546: row_array[0] = TemplateRow.newRow(fetch_template);
0547:
0548: int expect_key = input_expect_key;
0549: long key = -42;
0550: long numrows = 0;
0551: int group_row_count = 0;
0552:
0553: // loop asking for "group_size" rows at a time.
0554: while ((group_row_count = scan.fetchNextGroup(row_array,
0555: (RowLocation[]) null)) != 0) {
0556:
0557: // loop through the rows returned into the row_array.
0558: for (int i = 0; i < group_row_count; i++) {
0559: // see if we are getting the right keys.
0560: key = ((SQLLongint) (row_array[i][2])).getLong();
0561:
0562: if (ordered) {
0563: if (key != expect_key) {
0564: return (fail("(t_scanFetchNextGroup-forward) wrong key, expect ("
0565: + expect_key
0566: + ")"
0567: + "but got ("
0568: + key
0569: + "). num rows = " + numrows));
0570: } else {
0571: if (order == ORDER_DESC)
0572: expect_key--;
0573: else
0574: expect_key++;
0575: }
0576: } else {
0577: if (!set.remove(new Long(key))) {
0578: return (fail("(t_scanFetchNextGroup-forward) wrong key, expected ("
0579: + expect_key
0580: + ")"
0581: + "but got ("
0582: + key
0583: + ")."));
0584: }
0585: }
0586: numrows++;
0587: }
0588: }
0589:
0590: scan.close();
0591:
0592: if (numrows != expect_numrows) {
0593: return (fail("(t_scanFetchNextGroup-forward) wrong number of rows. Expected "
0594: + expect_numrows
0595: + " rows, but got "
0596: + numrows
0597: + "rows."));
0598: }
0599:
0600: /**********************************************************************
0601: * Backward scan test case
0602: **********************************************************************
0603: */
0604:
0605: /*
0606: if (!ordered)
0607: {
0608: set = create_hash_set(input_expect_key, expect_numrows, order);
0609: }
0610:
0611: scan =
0612: tc.openGroupFetchBackwardScan(
0613: conglomid, false,
0614: 0,
0615: TransactionController.MODE_RECORD,
0616: TransactionController.ISOLATION_SERIALIZABLE,
0617: (FormatableBitSet) null,
0618: stop_key, flip_scan_op(stop_op),
0619: qualifier,
0620: start_key, flip_scan_op(start_op));
0621:
0622: // create an array of "group_size" rows to use in the fetch group call.
0623: expect_key = input_expect_key + expect_numrows - 1;
0624: key = -42;
0625: numrows = 0;
0626: group_row_count = 0;
0627:
0628: // loop asking for "group_size" rows at a time.
0629: while ((group_row_count =
0630: scan.fetchNextGroup(row_array, (RowLocation[]) null)) != 0)
0631: {
0632: // loop through the rows returned into the row_array.
0633: for (int i = 0; i < group_row_count; i++)
0634: {
0635: // see if we are getting the right keys.
0636: key = ((SQLLongint)(row_array[i][2])).getLong();
0637:
0638: if (ordered)
0639: {
0640: if (key != expect_key)
0641: {
0642: return(fail(
0643: "(t_scanFetchNextGroup-backward) wrong key, expected (" +
0644: expect_key + ")" + "but got (" + key + ")."));
0645: }
0646: else
0647: {
0648: expect_key--;
0649: }
0650: }
0651: else
0652: {
0653: if (!set.remove(new Long(key)))
0654: {
0655: return(fail(
0656: "(t_scanFetchNextGroup-backward) wrong key, expected (" +
0657: expect_key + ")" + "but got (" + key + ")."));
0658: }
0659: }
0660: numrows++;
0661: }
0662: }
0663:
0664: scan.close();
0665:
0666: if (numrows != expect_numrows)
0667: {
0668: return(
0669: fail("(t_scanFetchNextGroup-backward) wrong number of rows. Expected " +
0670: expect_numrows + " rows, but got " + numrows + "rows."));
0671: }
0672:
0673: */
0674:
0675: return (true);
0676: }
0677:
0678: /**
0679: * Test scan which does FetchNext with subset of fields.
0680: * <p>
0681: * FetchNext() may be optimized by the underlying scan code to try and
0682: * not do multiple fetches of the same row for the user, but if the user
0683: * asks for one column, but the stop position depends on the whole row
0684: * this optimization is not possible.
0685: * <p>
0686: *
0687: * @return Whether the test succeeded or not.
0688: *
0689: * @exception StandardException Standard exception policy.
0690: **/
0691: public static boolean t_scanFetchNextPartial(
0692: TransactionController tc, long conglomid,
0693: DataValueDescriptor[] fetch_template,
0694: DataValueDescriptor[] start_key, int start_op,
0695: Qualifier qualifier[][], DataValueDescriptor[] stop_key,
0696: int stop_op, int expect_numrows, int input_expect_key,
0697: int order) throws StandardException, T_Fail {
0698: HashSet set = null;
0699: boolean ordered = (order == ORDER_FORWARD || order == ORDER_DESC);
0700:
0701: /**********************************************************************
0702: * setup shared by both.
0703: **********************************************************************
0704: */
0705:
0706: // In the fetchNext call only ask the minimum set of columns
0707: // necessary, which is the union of the "key" (col[2]) and other
0708: // columns referenced in the qualifier list.
0709: FormatableBitSet fetch_row_validColumns = RowUtil
0710: .getQualifierBitSet(qualifier);
0711:
0712: // now add in column 2, as we always need the key field.
0713: fetch_row_validColumns.grow(3);// grow to length of 3
0714: fetch_row_validColumns.set(2);
0715:
0716: // add in any fields in start and stop positions
0717: if (start_key != null) {
0718: for (int i = 0; i < start_key.length; i++) {
0719: fetch_row_validColumns.set(i);
0720: }
0721: }
0722: if (stop_key != null) {
0723: for (int i = 0; i < stop_key.length; i++) {
0724: fetch_row_validColumns.set(i);
0725: }
0726: }
0727:
0728: // point key at the right column in the fetch_template
0729: SQLLongint key_column = (SQLLongint) fetch_template[2];
0730:
0731: /**********************************************************************
0732: * Forward scan test case
0733: **********************************************************************
0734: */
0735:
0736: if (!ordered) {
0737: set = create_hash_set(input_expect_key, expect_numrows,
0738: order);
0739: }
0740:
0741: ScanController scan = tc.openScan(conglomid, false, 0,
0742: TransactionController.MODE_RECORD,
0743: TransactionController.ISOLATION_SERIALIZABLE,
0744: (FormatableBitSet) fetch_row_validColumns, start_key,
0745: start_op, qualifier, stop_key, stop_op);
0746:
0747: int expect_key = input_expect_key;
0748: long key = -42;
0749: long key2 = -42;
0750: long numrows = 0;
0751:
0752: while (scan.fetchNext(fetch_template)) {
0753: // see if we are getting the right keys.
0754: key = key_column.getLong();
0755:
0756: // make sure a subsequent fetch also works.
0757: key_column.setValue(-42);
0758:
0759: scan.fetch(fetch_template);
0760: key2 = key_column.getLong();
0761:
0762: if (ordered) {
0763: if ((key != expect_key) || (key2 != expect_key)) {
0764: return (fail("(t_scanFetchNext) wrong key, expected ("
0765: + expect_key
0766: + ")"
0767: + "but got ("
0768: + key
0769: + ")."));
0770: } else {
0771: if (order == ORDER_DESC)
0772: expect_key--;
0773: else
0774: expect_key++;
0775: }
0776: } else {
0777: if (!set.remove(new Long(key))) {
0778: return (fail("(t_scanFetchNext) wrong key, expected ("
0779: + expect_key
0780: + ")"
0781: + "but got ("
0782: + key
0783: + ")."));
0784: }
0785: }
0786: numrows++;
0787:
0788: }
0789:
0790: scan.close();
0791:
0792: if (numrows != expect_numrows) {
0793: return (fail("(t_scanFetchNext) wrong number of rows. Expected "
0794: + expect_numrows
0795: + " rows, but got "
0796: + numrows
0797: + "rows."));
0798: }
0799:
0800: /**********************************************************************
0801: * Backward scan test case
0802: **********************************************************************
0803: */
0804:
0805: /*
0806: if (!ordered)
0807: {
0808: set = create_hash_set(expect_key, expect_numrows, order);
0809: }
0810:
0811: scan =
0812: tc.openBackwardScan(
0813: conglomid, false,
0814: 0,
0815: TransactionController.MODE_RECORD,
0816: TransactionController.ISOLATION_SERIALIZABLE,
0817: (FormatableBitSet) fetch_row_validColumns,
0818: stop_key, flip_scan_op(stop_op),
0819: qualifier,
0820: start_key, flip_scan_op(start_op));
0821:
0822: expect_key = input_expect_key + expect_numrows - 1;
0823: key = -42;
0824: key2 = -42;
0825: numrows = 0;
0826:
0827: while (scan.fetchNext(fetch_template))
0828: {
0829: // see if we are getting the right keys.
0830: key = key_column.getValue();
0831:
0832: // make sure a subsequent fetch also works.
0833: key_column.setValue(-42);
0834:
0835: scan.fetch(fetch_template);
0836: key2 = key_column.getValue();
0837:
0838: if (ordered)
0839: {
0840: if ((key != expect_key) || (key2 != expect_key))
0841: {
0842: return(
0843: fail("(t_scanFetchNext) wrong key, expected (" +
0844: expect_key + ")" + "but got (" + key + ")."));
0845: }
0846: else
0847: {
0848: expect_key--;
0849: }
0850: }
0851: else
0852: {
0853: if (!set.remove(new Long(key)))
0854: {
0855: return(
0856: fail("(t_scanFetchNext) wrong key, expected (" +
0857: expect_key + ")" + "but got (" + key + ")."));
0858: }
0859: }
0860: numrows++;
0861:
0862: }
0863:
0864: scan.close();
0865:
0866: if (numrows != expect_numrows)
0867: {
0868: return(fail("(t_scanFetchNext) wrong number of rows. Expected " +
0869: expect_numrows + " rows, but got " + numrows + "rows."));
0870: }
0871: */
0872:
0873: return (true);
0874: }
0875:
0876: /**
0877: * Test scan which does FetchSet.
0878: * <p>
0879: * FetchSet() returns the entire result set in the hash table.
0880: * <p>
0881: *
0882: * @return Whether the test succeeded or not.
0883: *
0884: * @exception StandardException Standard exception policy.
0885: **/
0886: public static boolean t_scanFetchHashtable(
0887: TransactionController tc,
0888: long conglomid,
0889: DataValueDescriptor[] fetch_template,
0890: DataValueDescriptor[] start_key,
0891: int start_op,
0892: Qualifier qualifier[][],
0893: DataValueDescriptor[] stop_key,
0894: int stop_op,
0895: int expect_numrows,
0896: int input_expect_key,
0897: int order)
0898: throws StandardException, T_Fail
0899: {
0900: HashSet set = null;
0901: long key;
0902: long numrows = 0;
0903: boolean ordered = (order == ORDER_FORWARD || order == ORDER_DESC);
0904:
0905: set = create_hash_set(input_expect_key, expect_numrows, order);
0906:
0907: // select entire data set into a hash table, with first column key
0908: int[] keyColumns = new int[1];
0909: keyColumns[0] = 0;
0910:
0911: BackingStoreHashtable result_set =
0912: tc.createBackingStoreHashtableFromScan(
0913: conglomid,
0914: 0,
0915: TransactionController.MODE_TABLE,
0916: TransactionController.ISOLATION_SERIALIZABLE,
0917: (FormatableBitSet) null,
0918: start_key, start_op,
0919: qualifier,
0920: stop_key, stop_op,
0921: -1, // no limit on total rows.
0922: keyColumns, // first column is hash key column
0923: false, // don't remove duplicates
0924: -1, // no estimate of rows
0925: -1, // put it all into memory
0926: -1, // use default initial capacity
0927: -1, // use default load factor
0928: false, // don't maintain runtime statistics
0929: false); // don't skip null key columns
0930:
0931: // make sure the expected result set is the same as the actual result
0932: // set.
0933:
0934: Enumeration enum = result_set.elements();
0935:
0936: while (enum.hasMoreElements())
0937: {
0938: Object obj;
0939: DataValueDescriptor[] row = null;
0940:
0941: if ((obj = enum.nextElement()) instanceof DataValueDescriptor[] )
0942: {
0943: row = (DataValueDescriptor[] ) obj;
0944: key = ((SQLLongint)(row[2])).getLong();
0945:
0946: if (!set.remove(new Long(key)))
0947: {
0948: return(
0949: fail("(t_scanFetchHashtable-obj) wrong key, expected (" +
0950: input_expect_key + ")" +
0951: "but got (" + key + ")."));
0952: }
0953: numrows++;
0954: }
0955: else if (obj instanceof Vector)
0956: {
0957:
0958:
0959: Vector row_vect = (Vector) obj;
0960:
0961: for (int i = 0; i < row_vect.size(); i++)
0962: {
0963: row = (DataValueDescriptor[] ) row_vect.elementAt(i);
0964:
0965: key = ((SQLLongint)(row[2])).getLong();
0966:
0967: if (!set.remove(new Long(key)))
0968: {
0969: return(fail(
0970: "(t_scanFetchHashtable-vector) wrong key, expected (" +
0971: input_expect_key + ")" +
0972: "but got (" + key + ")."));
0973: }
0974: numrows++;
0975: }
0976: }
0977: else
0978: {
0979: return(fail(
0980: "(t_scanFetchHashtable) got bad type for data: " + obj));
0981: }
0982: }
0983:
0984: if (numrows != expect_numrows)
0985: {
0986: return(
0987: fail(
0988: "(t_scanFetchHashtable) wrong number of rows. Expected " +
0989: expect_numrows + " rows, but got " + numrows + "rows."));
0990: }
0991:
0992: result_set.close();
0993:
0994: // select entire data set into a hash table, with key being
0995: // the third column, which is the unique id used to verify the
0996: // right result set is being returned.:
0997:
0998: // open a new scan
0999: keyColumns[0] = 2;
1000:
1001: result_set =
1002: tc.createBackingStoreHashtableFromScan(
1003: conglomid,
1004: 0,
1005: TransactionController.MODE_TABLE,
1006: TransactionController.ISOLATION_SERIALIZABLE,
1007: (FormatableBitSet) null,
1008: start_key, start_op,
1009: qualifier,
1010: stop_key, stop_op,
1011: -1, // no limit on total rows.
1012: keyColumns, // third column is hash key column
1013: false, // don't remove duplicates
1014: -1, // no estimate of rows
1015: -1, // put it all into memory
1016: -1, // use default initial capacity
1017: -1, // use default load factor
1018: false, // don't maintain runtime statistics
1019: false); // don't skip null key columns
1020:
1021:
1022: Object removed_obj;
1023: for (numrows = 0; numrows < expect_numrows; numrows++)
1024: {
1025: long exp_key ;
1026: if (order == ORDER_DESC)
1027: exp_key = input_expect_key - numrows;
1028: else
1029: exp_key = input_expect_key + numrows;
1030: if ((removed_obj =
1031: result_set.remove(
1032: new SQLLongint(exp_key))) == null)
1033: {
1034: fail("(t_scanFetchHashtable-2-vector) wrong key, expected (" +
1035: (exp_key) + ")" +
1036: "but did not find it.");
1037: }
1038: }
1039:
1040: if (numrows != expect_numrows)
1041: {
1042: return(fail("(t_scanFetchHashtable-2) wrong number of rows. Expected " +
1043: expect_numrows + " rows, but got " + numrows + "rows."));
1044: }
1045:
1046: return(true);
1047: }
1048:
1049: /* public methods of T_QualifierTest */
1050:
1051: public boolean t_testqual(TransactionController tc)
1052: throws StandardException, T_Fail {
1053: boolean ret_val = true;
1054: DataValueDescriptor[] openscan_template = null;
1055: DataValueDescriptor[] fetch_template = null;
1056: DataValueDescriptor[] base_row = null;
1057: T_SecondaryIndexRow index_row = null;
1058: long value = -1;
1059: long col1[] = { 1, 3, 4, 4, 4, 5, 5, 5, 6, 7, 9 };
1060: long col2[] = { 1, 1, 2, 4, 6, 2, 4, 6, 1, 1, 1 };
1061: long col3[] = { 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21 };
1062: long conglomid;
1063: long base_conglomid;
1064: long index_conglomid;
1065: ConglomerateController base_cc = null;
1066: ConglomerateController index_cc = null;
1067: RowLocation base_rowloc = null;
1068:
1069: base_row = TemplateRow.newU8Row(3);
1070:
1071: if (init_conglomerate_type.compareTo("BTREE") == 0) {
1072: base_conglomid = tc.createConglomerate("heap", base_row,
1073: null, null, TransactionController.IS_DEFAULT);
1074:
1075: index_row = new T_SecondaryIndexRow();
1076:
1077: base_cc = tc.openConglomerate(base_conglomid, false,
1078: TransactionController.OPENMODE_FORUPDATE,
1079: TransactionController.MODE_RECORD,
1080: TransactionController.ISOLATION_SERIALIZABLE);
1081:
1082: base_rowloc = base_cc.newRowLocationTemplate();
1083:
1084: index_row.init(base_row, base_rowloc, 4);
1085:
1086: index_conglomid = tc.createConglomerate(
1087: init_conglomerate_type, index_row.getRow(), null,
1088: init_properties,
1089: init_temporary ? TransactionController.IS_TEMPORARY
1090: : TransactionController.IS_DEFAULT);
1091:
1092: index_cc = tc.openConglomerate(index_conglomid, false,
1093: TransactionController.OPENMODE_FORUPDATE,
1094: TransactionController.MODE_RECORD,
1095: TransactionController.ISOLATION_SERIALIZABLE);
1096:
1097: conglomid = index_conglomid;
1098: openscan_template = index_row.getRow();
1099:
1100: // make another template
1101: T_SecondaryIndexRow fetch_index_row = new T_SecondaryIndexRow();
1102: fetch_index_row.init(TemplateRow.newU8Row(3), base_cc
1103: .newRowLocationTemplate(), 4);
1104: fetch_template = fetch_index_row.getRow();
1105: } else {
1106: base_conglomid = tc.createConglomerate(
1107: init_conglomerate_type, base_row, null,
1108: init_properties,
1109: init_temporary ? TransactionController.IS_TEMPORARY
1110: : TransactionController.IS_DEFAULT);
1111:
1112: base_cc = tc.openConglomerate(base_conglomid, false,
1113: TransactionController.OPENMODE_FORUPDATE,
1114: TransactionController.MODE_RECORD,
1115: TransactionController.ISOLATION_SERIALIZABLE);
1116:
1117: base_rowloc = base_cc.newRowLocationTemplate();
1118:
1119: conglomid = base_conglomid;
1120: openscan_template = base_row;
1121: fetch_template = TemplateRow.newU8Row(3);
1122: }
1123:
1124: // insert them in reverse order just to make sure btree is sorting them
1125: for (int i = col1.length - 1; i >= 0; i--) {
1126: ((SQLLongint) (base_row[0])).setValue(col1[i]);
1127: ((SQLLongint) (base_row[1])).setValue(col2[i]);
1128: ((SQLLongint) (base_row[2])).setValue(col3[i]);
1129:
1130: base_cc.insertAndFetchLocation(base_row, base_rowloc);
1131:
1132: if (init_conglomerate_type.compareTo("BTREE") == 0) {
1133: index_cc.insert(index_row.getRow());
1134: }
1135: }
1136:
1137: tc.commit();
1138:
1139: // run through a predicates as described in the openScan() interface,
1140: // and implement them in qualifiers rather than start and stop.
1141: //
1142:
1143: // Use the following SQLLongint's for qualifier values //
1144: SQLLongint qual_col1 = new SQLLongint(-1);
1145: SQLLongint qual_col2 = new SQLLongint(-1);
1146: SQLLongint qual_col3 = new SQLLongint(-1);
1147: SQLLongint qual_col4 = new SQLLongint(-1);
1148: SQLLongint qual_col5 = new SQLLongint(-1);
1149: SQLLongint qual_col6 = new SQLLongint(-1);
1150: SQLLongint qual_col7 = new SQLLongint(-1);
1151:
1152: // test predicate x = 5
1153: //
1154: // result set should be: {5,2,16}, {5,4,17}, {5,6,18}
1155: //
1156: progress("qual scan (x = 5)");
1157: qual_col1.setValue(5);
1158: Qualifier q1[][] = { { new QualifierUtil(0, qual_col1,
1159: Orderable.ORDER_OP_EQUALS, false, true, true) } };
1160: if (!t_scan(tc, conglomid, openscan_template, fetch_template,
1161: null, ScanController.NA, q1, null, ScanController.NA,
1162: 3, 16, init_order)) {
1163: ret_val = false;
1164: }
1165:
1166: // +---------------------------------------------------------+
1167: // |pred |start|key|stop |key|rows returned |rows locked |
1168: // | |value|op |value|op | |(serialization)|
1169: // +------+-----+---+-----+---+--------------+---------------+
1170: // |x > 5 |{5} |GT |null | |{6,1} .. {9,1}|{5,6} .. {9,1} |
1171: // +-----------------------------------------+---------------+
1172: progress("qual scan (x > 5)");
1173: qual_col1.setValue(5);
1174: Qualifier q2[][] = { { new QualifierUtil(0, qual_col1,
1175: Orderable.ORDER_OP_LESSOREQUALS, true, true, true) } };
1176: if (!t_scan(tc, conglomid, openscan_template, fetch_template,
1177: null, ScanController.NA, q2, null, ScanController.NA,
1178: 3, 19, init_order)) {
1179: ret_val = false;
1180: }
1181:
1182: // +---------------------------------------------------------+
1183: // |pred |start|key|stop |key|rows returned |rows locked |
1184: // | |value|op |value|op | |(serialization)|
1185: // +------+-----+---+-----+---+--------------+---------------+
1186: // |x >= 5|{5} |GE |null | |{5,2} .. {9,1}|{4,6} .. {9,1} |
1187: // +-----------------------------------------+---------------+
1188: progress("qual scan (x >= 5)");
1189: qual_col1.setValue(5);
1190: Qualifier q3[][] = { { new QualifierUtil(0, qual_col1,
1191: Orderable.ORDER_OP_LESSTHAN, true, true, true) } };
1192: if (!t_scan(tc, conglomid, openscan_template, fetch_template,
1193: null, ScanController.NA, q3, null, ScanController.NA,
1194: 6, 16, init_order)) {
1195: ret_val = false;
1196: }
1197:
1198: //
1199: // +---------------------------------------------------------+
1200: // |pred |start|key|stop |key|rows returned |rows locked |
1201: // | |value|op |value|op | |(serialization)|
1202: // +------+-----+---+-----+---+--------------+---------------+
1203: // |x <= 5|null | |{5} |GT |{1,1} .. {5,6}|first .. {5,6} |
1204: // +-----------------------------------------+---------------+
1205: progress("qual scan (x <= 5)");
1206: qual_col1.setValue(5);
1207: Qualifier q4[][] = { { new QualifierUtil(0, qual_col1,
1208: Orderable.ORDER_OP_LESSOREQUALS, false, true, true) } };
1209: if (!t_scan(tc, conglomid, openscan_template, fetch_template,
1210: null, ScanController.NA, q4, null, ScanController.NA,
1211: 8, 11, init_order)) {
1212: ret_val = false;
1213: }
1214:
1215: //
1216: // +---------------------------------------------------------+
1217: // |pred |start|key|stop |key|rows returned |rows locked |
1218: // | |value|op |value|op | |(serialization)|
1219: // +------+-----+---+-----+---+--------------+---------------+
1220: // |x < 5 |null | |{5} |GE |{1,1} .. {4,6}|first .. {4,6} |
1221: // +-----------------------------------------+---------------+
1222: progress("qual scan (x < 5)");
1223: qual_col1.setValue(5);
1224: Qualifier q5[][] = { { new QualifierUtil(0, qual_col1,
1225: Orderable.ORDER_OP_LESSTHAN, false, true, true) } };
1226: if (!t_scan(tc, conglomid, openscan_template, fetch_template,
1227: null, ScanController.NA, q5, null, ScanController.NA,
1228: 5, 11, init_order)) {
1229: ret_val = false;
1230: }
1231:
1232: // +------------------------------------------------------------------+
1233: // |pred |start|key|stop |key|rows returned|rows locked |
1234: // | |value|op |value|op | |(serialized) |
1235: // +-----------------+------+--+-----+--+--------------+--------------+
1236: // |x >= 5 and x <= 7|{5}, |GE|{7} |GT|{5,2} .. {7,1}|{4,6} .. {7,1}|
1237: // +------------------------------------------------------------------+
1238: progress("qual scan (x >= 5 and x <= 7)");
1239: qual_col1.setValue(5);
1240: qual_col2.setValue(7);
1241: Qualifier q6[][] = { {
1242: new QualifierUtil(0, qual_col1,
1243: Orderable.ORDER_OP_LESSTHAN, true, true, true),
1244: new QualifierUtil(0, qual_col2,
1245: Orderable.ORDER_OP_LESSOREQUALS, false, true,
1246: true) } };
1247: if (!t_scan(tc, conglomid, openscan_template, fetch_template,
1248: null, ScanController.NA, q6, null, ScanController.NA,
1249: 5, 16, init_order)) {
1250: ret_val = false;
1251: }
1252:
1253: // passing qualifier in q6[0][0], q6[0][1] should evaluate same as
1254: // passing in q6[0][0], q6[1][0]
1255:
1256: // +------------------------------------------------------------------+
1257: // |pred |start|key|stop |key|rows returned|rows locked |
1258: // | |value|op |value|op | |(serialized) |
1259: // +-----------------+------+--+-----+--+--------------+--------------+
1260: // |x >= 5 and x <= 7|{5}, |GE|{7} |GT|{5,2} .. {7,1}|{4,6} .. {7,1}|
1261: // +------------------------------------------------------------------+
1262: progress("qual scan (x >= 5 and x <= 7)");
1263: qual_col1.setValue(5);
1264: qual_col2.setValue(7);
1265: Qualifier q6_2[][] = {
1266: { new QualifierUtil(0, qual_col1,
1267: Orderable.ORDER_OP_LESSTHAN, true, true, true) },
1268: { new QualifierUtil(0, qual_col2,
1269: Orderable.ORDER_OP_LESSOREQUALS, false, true,
1270: true) } };
1271: if (!t_scan(tc, conglomid, openscan_template, fetch_template,
1272: null, ScanController.NA, q6_2, null, ScanController.NA,
1273: 5, 16, init_order)) {
1274: ret_val = false;
1275: }
1276:
1277: // +------------------------------------------------------------------+
1278: // |pred |start|key|stop |key|rows returned|rows locked |
1279: // | |value|op |value|op | |(serialized) |
1280: // +-----------------+------+--+-----+--+--------------+--------------+
1281: // |x = 5 and y > 2 |{5,2} |GT|{5} |GT|{5,4} .. {5,6}|{5,2} .. {9,1}|
1282: // +------------------------------------------------------------------+
1283: progress("qual scan (x = 5 and y > 2)");
1284: qual_col1.setValue(5);
1285: qual_col2.setValue(2);
1286: Qualifier q7[][] = { {
1287: new QualifierUtil(0, qual_col1,
1288: Orderable.ORDER_OP_EQUALS, false, true, true),
1289: new QualifierUtil(1, qual_col2,
1290: Orderable.ORDER_OP_LESSOREQUALS, true, true,
1291: true) } };
1292: if (!t_scan(tc, conglomid, openscan_template, fetch_template,
1293: null, ScanController.NA, q7, null, ScanController.NA,
1294: 2, 17, init_order)) {
1295: ret_val = false;
1296: }
1297:
1298: // +------------------------------------------------------------------+
1299: // |pred |start|key|stop |key|rows returned|rows locked |
1300: // | |value|op |value|op | |(serialized) |
1301: // +-----------------+------+--+-----+--+--------------+--------------+
1302: // |x = 5 and y >= 2 | {5,2}|GE| {5} |GT|{5,2} .. {5,6}|{4,6} .. {9,1}|
1303: // +------------------------------------------------------------------+
1304: progress("qual scan (x = 5 and y >= 2)");
1305: qual_col1.setValue(5);
1306: qual_col2.setValue(2);
1307: Qualifier q8[][] = { {
1308: new QualifierUtil(0, qual_col1,
1309: Orderable.ORDER_OP_EQUALS, false, true, true),
1310: new QualifierUtil(1, qual_col2,
1311: Orderable.ORDER_OP_LESSTHAN, true, true, true) } };
1312: if (!t_scan(tc, conglomid, openscan_template, fetch_template,
1313: null, ScanController.NA, q8, null, ScanController.NA,
1314: 3, 16, init_order)) {
1315: ret_val = false;
1316: }
1317:
1318: // +------------------------------------------------------------------+
1319: // |pred |start|key|stop |key|rows returned|rows locked |
1320: // | |value|op |value|op | |(serialized) |
1321: // +-----------------+------+--+-----+--+--------------+--------------+
1322: // |x = 5 and y < 5 | {5} |GE|{5,5}|GE|{5,2} .. {5,4}|{4,6} .. {5,4}|
1323: // +------------------------------------------------------------------+
1324: progress("qual scan (x = 5 and y < 5)");
1325: qual_col1.setValue(5);
1326: qual_col2.setValue(5);
1327: Qualifier q9[][] = { {
1328: new QualifierUtil(0, qual_col1,
1329: Orderable.ORDER_OP_EQUALS, false, true, true),
1330: new QualifierUtil(1, qual_col1,
1331: Orderable.ORDER_OP_LESSTHAN, false, true, true) } };
1332: if (!t_scan(tc, conglomid, openscan_template, fetch_template,
1333: null, ScanController.NA, q9, null, ScanController.NA,
1334: 2, 16, init_order)) {
1335: ret_val = false;
1336: }
1337:
1338: // +------------------------------------------------------------------+
1339: // |pred |start|key|stop |key|rows returned|rows locked |
1340: // | |value|op |value|op | |(serialized) |
1341: // +-----------------+------+--+-----+--+--------------+--------------+
1342: // |x = 2 | {2} |GE| {2} |GT|none |{1,1} .. {1,1}|
1343: // +------------------------------------------------------------------+
1344: progress("qual scan (x = 2)");
1345: qual_col1.setValue(2);
1346: Qualifier q10[][] = { { new QualifierUtil(0, qual_col1,
1347: Orderable.ORDER_OP_EQUALS, false, true, true) } };
1348: if (!t_scan(tc, conglomid, openscan_template, fetch_template,
1349: null, ScanController.NA, q10, null, ScanController.NA,
1350: 0, 0, init_order)) {
1351: ret_val = false;
1352: }
1353:
1354: // +------------------------------------------------------------------+
1355: // |pred |start|key|stop |key|rows returned |rows locked |
1356: // | |value|op |value|op | |(serialized) |
1357: // +----------------+-----+---+-----+-- +--------------+--------------+
1358: // |x >= 5 or y = 6 | null| | null| |{4,6} .. {9,1}|{1,1} .. {9,1}|
1359: // +------------------------------------------------------------------+
1360: progress("qual scan (x >= 5) or (y = 6)");
1361: qual_col1.setValue(5);
1362: qual_col2.setValue(6);
1363: Qualifier q11[][] = new Qualifier[2][];
1364: q11[0] = new Qualifier[0];
1365: q11[1] = new Qualifier[2];
1366:
1367: q11[1][0] = new QualifierUtil(0, qual_col1,
1368: Orderable.ORDER_OP_GREATEROREQUALS, false, true, true);
1369: q11[1][1] = new QualifierUtil(1, qual_col2,
1370: Orderable.ORDER_OP_EQUALS, false, true, true);
1371:
1372: if (!t_scan(tc, conglomid, openscan_template, fetch_template,
1373: null, ScanController.NA, q11, null, ScanController.NA,
1374: 7, 15, init_order)) {
1375: ret_val = false;
1376: }
1377:
1378: // +------------------------------------------------------------------+
1379: // |pred |start|key|stop |key|rows returned |rows locked |
1380: // | |value|op |value|op | |(serialized) |
1381: // +----------------+-----+---+-----+-- +--------------+--------------+
1382: // |(x = 1 or y = 1 or y = 6)|
1383: // | and |
1384: // |(x > 5 or y = 1)|
1385: // | and |
1386: // |(x = 9 or x = 7)|null | | null| |{7,1} .. {9,1}|{1,1} .. {9,1}|
1387: // +------------------------------------------------------------------+
1388:
1389: progress("qual scan (x = 1 or y = 1 or y = 6) and (x > 5 or y = 1) and (x = 9 or x = 7)");
1390: qual_col1.setValue(1);
1391: qual_col2.setValue(1);
1392: qual_col3.setValue(6);
1393: qual_col4.setValue(5);
1394: qual_col5.setValue(1);
1395: qual_col6.setValue(9);
1396: qual_col7.setValue(7);
1397:
1398: Qualifier q12[][] = new Qualifier[4][];
1399: q12[0] = new Qualifier[0];
1400: q12[1] = new Qualifier[3];
1401: q12[2] = new Qualifier[2];
1402: q12[3] = new Qualifier[2];
1403:
1404: q12[1][0] = new QualifierUtil(0, qual_col1,
1405: Orderable.ORDER_OP_EQUALS, false, true, true);
1406:
1407: q12[1][1] = new QualifierUtil(1, qual_col2,
1408: Orderable.ORDER_OP_EQUALS, false, true, true);
1409:
1410: q12[1][2] = new QualifierUtil(1, qual_col3,
1411: Orderable.ORDER_OP_EQUALS, false, true, true);
1412:
1413: q12[2][0] = new QualifierUtil(0, qual_col4,
1414: Orderable.ORDER_OP_GREATERTHAN, false, true, true);
1415:
1416: q12[2][1] = new QualifierUtil(1, qual_col5,
1417: Orderable.ORDER_OP_EQUALS, false, true, true);
1418:
1419: q12[3][0] = new QualifierUtil(0, qual_col6,
1420: Orderable.ORDER_OP_EQUALS, false, true, true);
1421:
1422: q12[3][1] = new QualifierUtil(0, qual_col7,
1423: Orderable.ORDER_OP_EQUALS, false, true, true);
1424:
1425: if (!t_scan(tc, conglomid, openscan_template, fetch_template,
1426: null, ScanController.NA, q12, null, ScanController.NA,
1427: 2, 20, init_order)) {
1428: ret_val = false;
1429: }
1430:
1431: // +------------------------------------------------------------------+
1432: // |pred |start|key|stop |key|rows returned |rows locked |
1433: // | |value|op |value|op | |(serialized) |
1434: // +----------------+-----+---+-----+-- +--------------+--------------+
1435: // |(y = 4 or y = 1)|
1436: // | and |
1437: // |(x = 1 or x = 4 or x= 9)|
1438: // | and |
1439: // |(z = 15 or z = 14)|null | | null| |{4,4} .. {4,4}| ALL |
1440: // +------------------------------------------------------------------+
1441:
1442: progress("qual scan (x = 1 or x = 4 or x= 9) and (y = 4 or y = 1) and (z = 15 or z = 14)");
1443:
1444: qual_col1.setValue(4);
1445: qual_col2.setValue(1);
1446: qual_col3.setValue(1);
1447: qual_col4.setValue(4);
1448: qual_col5.setValue(9);
1449: qual_col6.setValue(15);
1450: qual_col7.setValue(14);
1451:
1452: Qualifier q13[][] = new Qualifier[4][];
1453: q13[0] = new Qualifier[0];
1454: q13[1] = new Qualifier[2];
1455: q13[2] = new Qualifier[3];
1456: q13[3] = new Qualifier[2];
1457:
1458: q13[1][0] = new QualifierUtil(1, qual_col1,
1459: Orderable.ORDER_OP_EQUALS, false, true, true);
1460:
1461: q13[1][1] = new QualifierUtil(1, qual_col2,
1462: Orderable.ORDER_OP_EQUALS, false, true, true);
1463:
1464: q13[2][0] = new QualifierUtil(0, qual_col4,
1465: Orderable.ORDER_OP_EQUALS, false, true, true);
1466:
1467: q13[2][1] = new QualifierUtil(0, qual_col5,
1468: Orderable.ORDER_OP_EQUALS, false, true, true);
1469:
1470: q13[2][2] = new QualifierUtil(0, qual_col3,
1471: Orderable.ORDER_OP_EQUALS, false, true, true);
1472:
1473: q13[3][0] = new QualifierUtil(2, qual_col6,
1474: Orderable.ORDER_OP_EQUALS, false, true, true);
1475:
1476: q13[3][1] = new QualifierUtil(2, qual_col7,
1477: Orderable.ORDER_OP_EQUALS, false, true, true);
1478:
1479: if (!t_scan(tc, conglomid, openscan_template, fetch_template,
1480: null, ScanController.NA, q13, null, ScanController.NA,
1481: 1, 14, init_order)) {
1482: ret_val = false;
1483: }
1484:
1485: tc.commit();
1486: progress("Ending t_testqual");
1487:
1488: return (ret_val);
1489: }
1490:
1491: private static boolean fail(String msg) throws T_Fail {
1492: throw T_Fail.testFailMsg("T_QualifierTest failure: " + msg);
1493: }
1494:
1495: private void progress(String msg) {
1496: this .init_out.println("T_QualifierTest progress: " + msg);
1497: }
1498: }
|