001/* An operator for cross.
002 * 
003 * Copyright (c) 2014 The Regents of the University of California.
004 * All rights reserved.
005 *
006 * '$Author: crawl $'
007 * '$Date: 2014-06-05 00:10:40 +0000 (Thu, 05 Jun 2014) $' 
008 * '$Revision: 32755 $'
009 * 
010 * Permission is hereby granted, without written agreement and without
011 * license or royalty fees, to use, copy, modify, and distribute this
012 * software and its documentation for any purpose, provided that the above
013 * copyright notice and the following two paragraphs appear in all copies
014 * of this software.
015 *
016 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
017 * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
018 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
019 * THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
020 * SUCH DAMAGE.
021 *
022 * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
023 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
024 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
025 * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
026 * CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
027 * ENHANCEMENTS, OR MODIFICATIONS.
028 *
029 */
030package org.kepler.spark.operator;
031
032import java.util.Iterator;
033
034import org.apache.spark.api.java.JavaPairRDD;
035import org.apache.spark.api.java.function.PairFlatMapFunction;
036
037import scala.Tuple2;
038
039/** An operator for cross/cartesian/all-pairs.
040 * 
041 *  @author Daniel Crawl
042 *  @version $Id: CrossOperator.java 32755 2014-06-05 00:10:40Z crawl $
043 */
044public class CrossOperator extends Operator {
045
046    /** Create a new CrossOperator.
047     *  @param stub the stub class to run in the cross operator
048     *  @param name the operator name
049     */
050    public CrossOperator(PairFlatMapFunction<Iterator<Tuple2<Tuple2<?,?>,Tuple2<?,?>>>, ?, ?> stub, String name) {
051        super(2, stub, name);
052    }
053
054    /** Execute the operator. */
055    @Override
056    public JavaPairRDD<Object, ?> execute() {
057        // TODO _numInstances
058        return _inputData[0].cartesian(_inputData[1]).mapPartitionsToPair((PairFlatMapFunction)_stub);
059    }
060
061}