// Path: src/main/java/com/qubole/presto/kinesis/decoder/KinesisFieldDecoder.java
// public interface KinesisFieldDecoder<T>
// {
//     /**
//      * Default name. Each decoder type *must* have a default decoder as fallback.
//      */
//     String DEFAULT_FIELD_DECODER_NAME = "_default";
// 
//     /**
//      * Returns the types which the field decoder can process.
//      *
//      * @return  Returns the types which the field decoder can process
//      */
//     Set<Class<?>> getJavaTypes();
// 
//     /**
//      * Returns the name of the row decoder to which this field decoder belongs.
//      *
//      * @return Returns the name of the row decoder to which this field decoder belongs
//      */
//     String getRowDecoderName();
// 
//     /**
//      * Returns the field decoder specific name. This name will be selected with the stream description value.
//      *
//      * @return Returns the field decoder specific name.
//      */
//     String getFieldDecoderName();
// 
//     /**
//      * Decode a value for the given column handle.
//      *
//      * @param value The raw value as generated by the row decoder.
//      * @param columnHandle The column for which the value is decoded.
//      * @return A {@link KinesisFieldDecoder} instance which returns a captured value for this specific column.
//      */
//     KinesisFieldValueProvider decode(T value, KinesisColumnHandle columnHandle);
// }
// 
// Path: src/main/java/com/qubole/presto/kinesis/decoder/KinesisRowDecoder.java
// public interface KinesisRowDecoder
// {
//     /**
//      * Returns the row decoder specific name.
//      *
//      * @return Return the row decoder specific name
//      */
//     String getName();
// 
//     /**
//      * Decodes a given set of bytes into field values.
//      *
//      * @param data The row data (Kinesis message) to decode.
//      * @param fieldValueProviders Must be a mutable set. Any field value provider created by this row decoder is put into this set.
//      * @param columnHandles List of column handles for which field values are required.
//      * @param fieldDecoders Map from column handles to decoders. This map should be used to look up the field decoder that generates the field value provider for a given column handle.
//      * @return true if the row was decoded successfully, false if it could not be decoded (was corrupt). TODO - reverse this boolean.
//      */
//     boolean decodeRow(
//             byte[] data,
//             Set<KinesisFieldValueProvider> fieldValueProviders,
//             List<KinesisColumnHandle> columnHandles,
//             Map<KinesisColumnHandle, KinesisFieldDecoder<?>> fieldDecoders);
// }


import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import com.qubole.presto.kinesis.decoder.KinesisFieldDecoder;
import com.qubole.presto.kinesis.decoder.KinesisRowDecoder;
import io.airlift.log.Logger;
import io.airlift.slice.Slice;
import io.airlift.slice.Slices;
import java.nio.ByteBuffer;
import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient;
import com.amazonaws.services.kinesis.model.GetRecordsRequest;
import com.amazonaws.services.kinesis.model.GetRecordsResult;
import com.amazonaws.services.kinesis.model.GetShardIteratorRequest;
import com.amazonaws.services.kinesis.model.GetShardIteratorResult;
import com.amazonaws.services.kinesis.model.Record;
import com.amazonaws.services.kinesis.model.ResourceNotFoundException;
import com.facebook.presto.spi.ConnectorSession;
import com.facebook.presto.spi.RecordCursor;
import com.facebook.presto.spi.RecordSet;
import com.facebook.presto.spi.type.Type;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
/*
 * Licensed 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.qubole.presto.kinesis;






public class KinesisRecordSet
        implements RecordSet
{
    /** Indicates how close to current we want to be before stopping the fetch of records in a query. */
    public static final int MILLIS_BEHIND_LIMIT = 10000;

    private static final Logger log = Logger.get(KinesisRecordSet.class);

    private static final byte [] EMPTY_BYTE_ARRAY = new byte [0];

    private final KinesisSplit split;
    private final ConnectorSession session;
    private final KinesisClientProvider clientManager;
    private final KinesisConnectorConfig kinesisConnectorConfig;

    private final KinesisRowDecoder messageDecoder;
// Path: src/main/java/com/qubole/presto/kinesis/decoder/KinesisFieldDecoder.java
// public interface KinesisFieldDecoder<T>
// {
//     /**
//      * Default name. Each decoder type *must* have a default decoder as fallback.
//      */
//     String DEFAULT_FIELD_DECODER_NAME = "_default";
// 
//     /**
//      * Returns the types which the field decoder can process.
//      *
//      * @return  Returns the types which the field decoder can process
//      */
//     Set<Class<?>> getJavaTypes();
// 
//     /**
//      * Returns the name of the row decoder to which this field decoder belongs.
//      *
//      * @return Returns the name of the row decoder to which this field decoder belongs
//      */
//     String getRowDecoderName();
// 
//     /**
//      * Returns the field decoder specific name. This name will be selected with the stream description value.
//      *
//      * @return Returns the field decoder specific name.
//      */
//     String getFieldDecoderName();
// 
//     /**
//      * Decode a value for the given column handle.
//      *
//      * @param value The raw value as generated by the row decoder.
//      * @param columnHandle The column for which the value is decoded.
//      * @return A {@link KinesisFieldDecoder} instance which returns a captured value for this specific column.
//      */
//     KinesisFieldValueProvider decode(T value, KinesisColumnHandle columnHandle);
// }
// 
// Path: src/main/java/com/qubole/presto/kinesis/decoder/KinesisRowDecoder.java
// public interface KinesisRowDecoder
// {
//     /**
//      * Returns the row decoder specific name.
//      *
//      * @return Return the row decoder specific name
//      */
//     String getName();
// 
//     /**
//      * Decodes a given set of bytes into field values.
//      *
//      * @param data The row data (Kinesis message) to decode.
//      * @param fieldValueProviders Must be a mutable set. Any field value provider created by this row decoder is put into this set.
//      * @param columnHandles List of column handles for which field values are required.
//      * @param fieldDecoders Map from column handles to decoders. This map should be used to look up the field decoder that generates the field value provider for a given column handle.
//      * @return true if the row was decoded successfully, false if it could not be decoded (was corrupt). TODO - reverse this boolean.
//      */
//     boolean decodeRow(
//             byte[] data,
//             Set<KinesisFieldValueProvider> fieldValueProviders,
//             List<KinesisColumnHandle> columnHandles,
//             Map<KinesisColumnHandle, KinesisFieldDecoder<?>> fieldDecoders);
// }


// Path: src/main/java/com/qubole/presto/kinesis/KinesisRecordSet.java
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import com.qubole.presto.kinesis.decoder.KinesisFieldDecoder;
import com.qubole.presto.kinesis.decoder.KinesisRowDecoder;
import io.airlift.log.Logger;
import io.airlift.slice.Slice;
import io.airlift.slice.Slices;
import java.nio.ByteBuffer;
import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient;
import com.amazonaws.services.kinesis.model.GetRecordsRequest;
import com.amazonaws.services.kinesis.model.GetRecordsResult;
import com.amazonaws.services.kinesis.model.GetShardIteratorRequest;
import com.amazonaws.services.kinesis.model.GetShardIteratorResult;
import com.amazonaws.services.kinesis.model.Record;
import com.amazonaws.services.kinesis.model.ResourceNotFoundException;
import com.facebook.presto.spi.ConnectorSession;
import com.facebook.presto.spi.RecordCursor;
import com.facebook.presto.spi.RecordSet;
import com.facebook.presto.spi.type.Type;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;

/*
 * Licensed 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.qubole.presto.kinesis;






public class KinesisRecordSet
        implements RecordSet
{
    /** Indicates how close to current we want to be before stopping the fetch of records in a query. */
    public static final int MILLIS_BEHIND_LIMIT = 10000;

    private static final Logger log = Logger.get(KinesisRecordSet.class);

    private static final byte [] EMPTY_BYTE_ARRAY = new byte [0];

    private final KinesisSplit split;
    private final ConnectorSession session;
    private final KinesisClientProvider clientManager;
    private final KinesisConnectorConfig kinesisConnectorConfig;

    private final KinesisRowDecoder messageDecoder;
    private final Map<KinesisColumnHandle, KinesisFieldDecoder<?>> messageFieldDecoders;