Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * 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.facebook.presto.tpch;
 
 
 import java.util.List;
 
 import static com.facebook.presto.tpch.TpchMetadata.getPrestoType;
 import static com.google.common.base.Preconditions.checkState;
 import static com.google.common.collect.Iterables.transform;
 
 public class TpchRecordSet<E extends TpchEntity>
         implements RecordSet
 {
     public static <E extends TpchEntityTpchRecordSet<E> createTpchRecordSet(TpchTable<E> tabledouble scaleFactor)
     {
         return createTpchRecordSet(tabletable.getColumns(), scaleFactor, 1, 1);
     }
 
     public static <E extends TpchEntityTpchRecordSet<E> createTpchRecordSet(
             TpchTable<E> table,
             Iterable<TpchColumn<E>> columns,
             double scaleFactor,
             int part,
             int partCount)
     {
         return new TpchRecordSet<>(table.createGenerator(scaleFactorpartpartCount), columns);
     }
 
     private final Iterable<E> table;
     private final List<TpchColumn<E>> columns;
     private final List<TypecolumnTypes;
 
     public TpchRecordSet(Iterable<E> tableIterable<TpchColumn<E>> columns)
     {
         Preconditions.checkNotNull(table"readerSupplier is null");
 
         this. = table;
         this. = ImmutableList.copyOf(columns);
 
         this. = ImmutableList.copyOf(transform(columnscolumn -> getPrestoType(column.getType())));
     }
 
     @Override
     public List<TypegetColumnTypes()
     {
         return ;
     }
 
     @Override
     public RecordCursor cursor()
     {
         return new TpchRecordCursor<>(.iterator(), );
     }
 
     public class TpchRecordCursor<E extends TpchEntity>
             implements RecordCursor
     {
         private final Iterator<E> rows;
         private final List<TpchColumn<E>> columns;
         private E row;
         private boolean closed;
 
         public TpchRecordCursor(Iterator<E> rowsList<TpchColumn<E>> columns)
         {
             this. = rows;
             this. = columns;
         }
 
         @Override
         public long getTotalBytes()
         {
             return 0;
         }
 
         @Override
        public long getCompletedBytes()
        {
            return 0;
        }
        @Override
        public long getReadTimeNanos()
        {
            return 0;
        }
        @Override
        public Type getType(int field)
        {
            return getPrestoType(getTpchColumn(field).getType());
        }
        @Override
        public boolean advanceNextPosition()
        {
            if ( || !.hasNext()) {
                 = true;
                 = null;
                return false;
            }
             = .next();
            return true;
        }
        @Override
        public boolean getBoolean(int field)
        {
            throw new UnsupportedOperationException();
        }
        @Override
        public long getLong(int field)
        {
            checkState( != null"No current row");
            TpchColumn<E> tpchColumn = getTpchColumn(field);
            if (tpchColumn.getType() == .) {
                return tpchColumn.getDate();
            }
            return tpchColumn.getLong();
        }
        @Override
        public double getDouble(int field)
        {
            checkState( != null"No current row");
            return getTpchColumn(field).getDouble();
        }
        @Override
        public Slice getSlice(int field)
        {
            checkState( != null"No current row");
            return Slices.utf8Slice(getTpchColumn(field).getString());
        }
        @Override
        public boolean isNull(int field)
        {
            return false;
        }
        @Override
        public void close()
        {
             = null;
             = true;
        }
        private TpchColumn<E> getTpchColumn(int field)
        {
            return .get(field);
        }
    }
New to GrepCode? Check out our FAQ X