/*
 * Copyright (c) 2013, Cloudera, Inc. All Rights Reserved.
 *
 * Cloudera, Inc. licenses this file to you 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
 *
 * This software 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 com.cloudera.oryx.als.computation.merge;

import org.apache.crunch.Emitter;
import org.apache.crunch.Pair;

import com.cloudera.oryx.als.common.StringLongMapping;
import com.cloudera.oryx.common.io.DelimitedDataUtils;
import com.cloudera.oryx.computation.common.fn.OryxDoFn;

public final class MappingParseFn extends OryxDoFn<String, Pair<Long, String>> {

  @Override
  public void process(String line, Emitter<Pair<Long, String>> emitter) {
    String[] columns = DelimitedDataUtils.decode(line);

    String userID = columns[0];
    String itemID = columns[1];
    long numericUserID = StringLongMapping.toLong(userID);
    long numericItemID = StringLongMapping.toLong(itemID);

    if (!Long.toString(numericUserID).equals(userID)) {
      emitter.emit(Pair.of(numericUserID, userID));
    }
    if (!Long.toString(numericItemID).equals(itemID)) {
      emitter.emit(Pair.of(numericItemID, itemID));
    }
  }

}

@@ -613,16 +613,61 @@
 merge;%0A%0A
+import com.google.common.base.Preconditions;%0A
 import o
@@ -1115,16 +1115,123 @@
 e(line);
+%0A    Preconditions.checkArgument(columns.length %3E= 2, %22Line does not have at least two columns: %25s%22, line);
 %0A%0A    St

Add a better error on bad column