// Path: src/hbaseindex/src/main/java/org/lilycms/hbaseindex/Conjunction.java
// public class Conjunction extends BaseQueryResult {
//     private QueryResult result1;
//     private QueryResult result2;
// 
//     public Conjunction(QueryResult result1, QueryResult result2) {
//         this.result1 = result1;
//         this.result2 = result2;
//     }
// 
//     public byte[] next() throws IOException {
//         byte[] key1 = result1.next();
//         byte[] key2 = result2.next();
// 
//         if (key1 == null || key2 == null)
//             return null;
// 
//         int cmp = Bytes.compareTo(key1, key2);
// 
//         while (cmp != 0) {
//             if (cmp < 0) {
//                 while (cmp < 0) {
//                     key1 = result1.next();
//                     if (key1 == null)
//                         return null;
//                     cmp = Bytes.compareTo(key1, key2);
//                 }
//             } else if (cmp > 0) {
//                 while (cmp > 0) {
//                     key2 = result2.next();
//                     if (key2 == null)
//                         return null;
//                     cmp = Bytes.compareTo(key1, key2);
//                 }
//             }
//         }
// 
//         currentQResult = result1;
//         return key1;
//     }
// }
// 
// Path: src/hbaseindex/src/main/java/org/lilycms/hbaseindex/Disjunction.java
// public class Disjunction extends BaseQueryResult {
//     private QueryResult result1;
//     private QueryResult result2;
//     private byte[] key1;
//     private byte[] key2;
//     private boolean init = false;
// 
//     public Disjunction(QueryResult result1, QueryResult result2) {
//         this.result1 = result1;
//         this.result2 = result2;
//     }
// 
//     public byte[] next() throws IOException {
//         if (!init) {
//             key1 = result1.next();
//             key2 = result2.next();
//             init = true;
//         }
// 
//         if (key1 == null && key2 == null) {
//             return null;
//         } else if (key1 == null) {
//             byte[] result = key2;
//             currentQResult = result2;
//             key2 = result2.next();
//             return result;
//         } else if (key2 == null) {
//             byte[] result = key1;
//             currentQResult = result1;
//             key1 = result1.next();
//             return result;
//         }
// 
//         int cmp = Bytes.compareTo(key1, key2);
// 
//         if (cmp == 0) {
//             byte[] result = key1;
//             currentQResult = result1;
//             key1 = result1.next();
//             key2 = result2.next();
//             return result;
//         } else if (cmp < 0) {
//             byte[] result = key1;
//             currentQResult = result1;
//             key1 = result1.next();
//             return result;
//         } else { // cmp > 0
//             byte[] result = key2;
//             currentQResult = result2;
//             key2 = result2.next();
//             return result;
//         }
//     }
// }
// 
// Path: src/hbaseindex/src/main/java/org/lilycms/hbaseindex/QueryResult.java
// public interface QueryResult {
// 
//     /**
//      * Move to and return the next result.
//      *
//      * @return the identifier of the next matching query result, or null if the end is reached.
//      */
//     public byte[] next() throws IOException;
// 
//     /**
//      * Retrieves data that was stored as part of the {@link IndexEntry} from the current index
//      * entry (corresponding to the last {@link #next} call).
//      */
//     public byte[] getData(byte[] qualifier);
// 
//     public byte[] getData(String qualifier);
// 
//     public String getDataAsString(String qualifier);
// }


import org.apache.hadoop.hbase.util.Bytes;
import org.junit.Test;
import org.lilycms.hbaseindex.Conjunction;
import org.lilycms.hbaseindex.Disjunction;
import org.lilycms.hbaseindex.QueryResult;
import static org.junit.Assert.*;
import java.util.ArrayList;
import java.util.List;
/*
 * Copyright 2010 Outerthought bvba
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.lilycms.hbaseindex.test;



public class MergeJoinTest {
    @Test
    public void testConjunction() throws Exception {
        String[] values1 = {"a", "b", "c",           "f", "g"};
        String[] values2 = {     "b", "c", "d", "e", "f"};

// Path: src/hbaseindex/src/main/java/org/lilycms/hbaseindex/Conjunction.java
// public class Conjunction extends BaseQueryResult {
//     private QueryResult result1;
//     private QueryResult result2;
// 
//     public Conjunction(QueryResult result1, QueryResult result2) {
//         this.result1 = result1;
//         this.result2 = result2;
//     }
// 
//     public byte[] next() throws IOException {
//         byte[] key1 = result1.next();
//         byte[] key2 = result2.next();
// 
//         if (key1 == null || key2 == null)
//             return null;
// 
//         int cmp = Bytes.compareTo(key1, key2);
// 
//         while (cmp != 0) {
//             if (cmp < 0) {
//                 while (cmp < 0) {
//                     key1 = result1.next();
//                     if (key1 == null)
//                         return null;
//                     cmp = Bytes.compareTo(key1, key2);
//                 }
//             } else if (cmp > 0) {
//                 while (cmp > 0) {
//                     key2 = result2.next();
//                     if (key2 == null)
//                         return null;
//                     cmp = Bytes.compareTo(key1, key2);
//                 }
//             }
//         }
// 
//         currentQResult = result1;
//         return key1;
//     }
// }
// 
// Path: src/hbaseindex/src/main/java/org/lilycms/hbaseindex/Disjunction.java
// public class Disjunction extends BaseQueryResult {
//     private QueryResult result1;
//     private QueryResult result2;
//     private byte[] key1;
//     private byte[] key2;
//     private boolean init = false;
// 
//     public Disjunction(QueryResult result1, QueryResult result2) {
//         this.result1 = result1;
//         this.result2 = result2;
//     }
// 
//     public byte[] next() throws IOException {
//         if (!init) {
//             key1 = result1.next();
//             key2 = result2.next();
//             init = true;
//         }
// 
//         if (key1 == null && key2 == null) {
//             return null;
//         } else if (key1 == null) {
//             byte[] result = key2;
//             currentQResult = result2;
//             key2 = result2.next();
//             return result;
//         } else if (key2 == null) {
//             byte[] result = key1;
//             currentQResult = result1;
//             key1 = result1.next();
//             return result;
//         }
// 
//         int cmp = Bytes.compareTo(key1, key2);
// 
//         if (cmp == 0) {
//             byte[] result = key1;
//             currentQResult = result1;
//             key1 = result1.next();
//             key2 = result2.next();
//             return result;
//         } else if (cmp < 0) {
//             byte[] result = key1;
//             currentQResult = result1;
//             key1 = result1.next();
//             return result;
//         } else { // cmp > 0
//             byte[] result = key2;
//             currentQResult = result2;
//             key2 = result2.next();
//             return result;
//         }
//     }
// }
// 
// Path: src/hbaseindex/src/main/java/org/lilycms/hbaseindex/QueryResult.java
// public interface QueryResult {
// 
//     /**
//      * Move to and return the next result.
//      *
//      * @return the identifier of the next matching query result, or null if the end is reached.
//      */
//     public byte[] next() throws IOException;
// 
//     /**
//      * Retrieves data that was stored as part of the {@link IndexEntry} from the current index
//      * entry (corresponding to the last {@link #next} call).
//      */
//     public byte[] getData(byte[] qualifier);
// 
//     public byte[] getData(String qualifier);
// 
//     public String getDataAsString(String qualifier);
// }


// Path: src/hbaseindex/src/test/java/org/lilycms/hbaseindex/test/MergeJoinTest.java
import org.apache.hadoop.hbase.util.Bytes;
import org.junit.Test;
import org.lilycms.hbaseindex.Conjunction;
import org.lilycms.hbaseindex.Disjunction;
import org.lilycms.hbaseindex.QueryResult;
import static org.junit.Assert.*;
import java.util.ArrayList;
import java.util.List;

/*
 * Copyright 2010 Outerthought bvba
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.lilycms.hbaseindex.test;



public class MergeJoinTest {
    @Test
    public void testConjunction() throws Exception {
        String[] values1 = {"a", "b", "c",           "f", "g"};
        String[] values2 = {     "b", "c", "d", "e", "f"};

        QueryResult result = new Conjunction(buildQueryResult(values1), buildQueryResult(values2));