Github user mravi commented on a diff in the pull request:

    https://github.com/apache/incubator-phoenix/pull/27#discussion_r11746726
  
    --- Diff: 
phoenix-pig/src/main/java/org/apache/phoenix/pig/hadoop/PhoenixInputFormat.java 
---
    @@ -0,0 +1,168 @@
    +/*
    + * Copyright 2010 The Apache Software Foundation
    + *
    + * 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 maynot 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 applicablelaw 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.apache.phoenix.pig.hadoop;
    +
    +import java.io.IOException;
    +import java.sql.Connection;
    +import java.sql.SQLException;
    +import java.sql.Statement;
    +import java.util.List;
    +
    +import org.apache.commons.logging.Log;
    +import org.apache.commons.logging.LogFactory;
    +import org.apache.hadoop.conf.Configuration;
    +import org.apache.hadoop.hbase.client.Scan;
    +import org.apache.hadoop.io.NullWritable;
    +import org.apache.hadoop.mapreduce.InputFormat;
    +import org.apache.hadoop.mapreduce.InputSplit;
    +import org.apache.hadoop.mapreduce.JobContext;
    +import org.apache.hadoop.mapreduce.RecordReader;
    +import org.apache.hadoop.mapreduce.TaskAttemptContext;
    +import org.apache.phoenix.compile.QueryPlan;
    +import org.apache.phoenix.compile.StatementContext;
    +import org.apache.phoenix.iterate.ResultIterator;
    +import org.apache.phoenix.jdbc.PhoenixStatement;
    +import org.apache.phoenix.pig.PhoenixPigConfiguration;
    +import org.apache.phoenix.query.KeyRange;
    +import org.apache.phoenix.schema.SaltingUtil;
    +import org.apache.phoenix.schema.TableRef;
    +import org.apache.phoenix.util.ScanUtil;
    +
    +import com.google.common.base.Preconditions;
    +import com.google.common.base.Throwables;
    +import com.google.common.collect.Lists;
    +
    +/**
    + * The InputFormat class for generating the splits and creating the record 
readers.
    + * 
    + */
    +public final class PhoenixInputFormat extends InputFormat<NullWritable, 
PhoenixRecord> {
    +
    +    private static final Log LOG = 
LogFactory.getLog(PhoenixInputFormat.class);
    +    private PhoenixPigConfiguration phoenixConfiguration;
    +    private Connection connection;
    +    private QueryPlan  queryPlan;
    +    
    +    /**
    +     * instantiated by framework
    +     */
    +    public PhoenixInputFormat() {
    +    }
    +
    +    @Override
    +    public RecordReader<NullWritable, PhoenixRecord> 
createRecordReader(InputSplit split, TaskAttemptContext context)
    +            throws IOException, InterruptedException {       
    +         setConf(context.getConfiguration());
    +         final QueryPlan queryPlan = getQueryPlan(context);
    +         try {
    +             return new 
PhoenixRecordReader(phoenixConfiguration,queryPlan);    
    +         }catch(SQLException sqle) {
    +             throw new IOException(sqle);
    +         }
    +         
    +    }
    +    
    +   
    +
    +    @Override
    +    public List<InputSplit> getSplits(JobContext context) throws 
IOException, InterruptedException {        
    +        List<InputSplit> splits = null;
    +        try{
    +            setConf(context.getConfiguration());
    +            final QueryPlan queryPlan = getQueryPlan(context);
    +            @SuppressWarnings("unused")
    +            final ResultIterator iterator = queryPlan.iterator();
    +            final List<KeyRange> allSplits = queryPlan.getSplits();
    +            splits = generateSplits(queryPlan,allSplits);
    --- End diff --
    
    Currently, when users specify just the table name as part of LOAD func, we 
just need to know all region boundaries. However , if they specify a SELECT 
statement with a WHERE clause, we need to call the generateSplits.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to