com.tuplejump.calliope.hadoop.cql3.CqlPagingInputFormat.java Source code

Java tutorial

Introduction

Here is the source code for com.tuplejump.calliope.hadoop.cql3.CqlPagingInputFormat.java

Source

/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF 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
 *
 * 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 com.tuplejump.calliope.hadoop.cql3;

import com.tuplejump.calliope.hadoop.AbstractColumnFamilyInputFormat;
import com.tuplejump.calliope.hadoop.HadoopCompat;
import com.tuplejump.calliope.hadoop.ReporterWrapper;
import org.apache.hadoop.mapred.InputSplit;
import org.apache.hadoop.mapred.JobConf;
import org.apache.hadoop.mapred.RecordReader;
import org.apache.hadoop.mapred.Reporter;
import org.apache.hadoop.mapreduce.TaskAttemptContext;
import org.apache.hadoop.mapreduce.TaskAttemptID;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.Map;

/**
 * Hadoop InputFormat allowing map/reduce against Cassandra rows within one ColumnFamily.
 * <p/>
 * At minimum, you need to set the KS and CF in your Hadoop job Configuration.
 * The ConfigHelper class is provided to make this
 * simple:
 * ConfigHelper.setInputColumnFamily
 * <p/>
 * You can also configure the number of rows per InputSplit with
 * ConfigHelper.setInputSplitSize. The default split size is 64k rows.
 * the number of CQL rows per page
 * <p/>
 * the number of CQL rows per page
 * CQLConfigHelper.setInputCQLPageRowSize. The default page row size is 1000. You
 * should set it to "as big as possible, but no bigger." It set the LIMIT for the CQL
 * query, so you need set it big enough to minimize the network overhead, and also
 * not too big to avoid out of memory issue.
 * <p/>
 * the column names of the select CQL query. The default is all columns
 * CQLConfigHelper.setInputColumns
 * <p/>
 * the user defined the where clause
 * CQLConfigHelper.setInputWhereClauses. The default is no user defined where clause
 */
public class CqlPagingInputFormat
        extends AbstractColumnFamilyInputFormat<Map<String, ByteBuffer>, Map<String, ByteBuffer>> {
    public RecordReader<Map<String, ByteBuffer>, Map<String, ByteBuffer>> getRecordReader(InputSplit split,
            JobConf jobConf, final Reporter reporter) throws IOException {
        TaskAttemptContext tac = HadoopCompat.newMapContext(jobConf,
                TaskAttemptID.forName(jobConf.get(MAPRED_TASK_ID)), null, null, null, new ReporterWrapper(reporter),
                null);

        CqlPagingRecordReader recordReader = new CqlPagingRecordReader();
        recordReader.initialize((org.apache.hadoop.mapreduce.InputSplit) split, tac);
        return recordReader;
    }

    @Override
    public org.apache.hadoop.mapreduce.RecordReader<Map<String, ByteBuffer>, Map<String, ByteBuffer>> createRecordReader(
            org.apache.hadoop.mapreduce.InputSplit arg0, TaskAttemptContext arg1)
            throws IOException, InterruptedException {
        return new CqlPagingRecordReader();
    }

}