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

    https://github.com/apache/incubator-phoenix/pull/22#discussion_r10854983
  
    --- Diff: 
phoenix-pig/src/main/java/org/apache/phoenix/pig/hadoop/PhoenixRecordReader.java
 ---
    @@ -0,0 +1,116 @@
    +/*
    + * 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.SQLException;
    +import java.util.List;
    +
    +import org.apache.phoenix.pig.PhoenixPigConfiguration;
    +
    +/**
    + * 
    + * Describe your class here.
    + *
    + * @since 138
    + */
    +public final class PhoenixRecordReader extends 
RecordReader<NullWritable,PhoenixRecord>{
    +    
    +    private static final Log LOG = 
LogFactory.getLog(PhoenixRecordReader.class);
    +    private NullWritable key =  NullWritable.get();
    +    private PhoenixRecord value = null;
    +    private List<? extends ColumnProjector> projectedColumns;
    +    private HTableInterface htable;
    +    private ResultIterator resultIterator = null;
    +    private ImmutableBytesWritable ptr = new ImmutableBytesWritable();
    +    
    +    public PhoenixRecordReader(PhoenixPigConfiguration config) {
    +        
    +        Preconditions.checkNotNull(config);
    +        try {
    +            this.htable = new HTable(config.getConfiguration(), 
config.getTableName());
    +        } catch (IOException e) {
    +            LOG.error(StringUtils.stringifyException(e));
    +            Throwables.propagate(e);
    +        }
    +    }
    +
    +    @Override
    +    public void close() throws IOException {
    +       if(resultIterator != null) {
    +           try {
    +               resultIterator.close();
    +        } catch (SQLException e) {
    +           LOG.error(" Error closing resultset.");
    +        }
    +       }
    +       Closeables.close(this.htable, true);
    +    }
    +
    +    @Override
    +    public NullWritable getCurrentKey() throws IOException, 
InterruptedException {
    +        return key;
    +    }
    +
    +    @Override
    +    public PhoenixRecord getCurrentValue() throws IOException, 
InterruptedException {
    +        return value;
    +    }
    +
    +    @Override
    +    public float getProgress() throws IOException, InterruptedException {
    +        return 0;
    +    }
    +
    +    @Override
    +    public void initialize(InputSplit split, TaskAttemptContext context) 
throws IOException, InterruptedException {
    +            final PhoenixInputSplit pSplit = (PhoenixInputSplit)split;
    +            final Scan scan = pSplit.getScan();
    +            this.projectedColumns = pSplit.getColumnProjectors();
    +            try {
    +                resultIterator = new 
ScanningResultIterator(htable.getScanner(scan));
    +            } catch (IOException e) {
    +                Closeables.closeQuietly(htable);
    --- End diff --
    
    @mravi @JamesRTaylor  is it cool to close quietly an HTable? Javadoc says 
"When a HTable instance is no longer required, it *should* be closed in order 
to ensure that the underlying resources are promptly released. Please note that 
the close method can throw java.io.IOException that must be handled."
    
    I'm not sure what the best way is to handle that. 


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to