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.testing;
 
 
 import java.util.List;
 
 import static com.facebook.presto.spi.type.BigintType.BIGINT;
 import static com.google.common.base.Preconditions.checkNotNull;
 
         extends TpchRecordSetProvider
 {
     private final TpchMetadata metadata;
     private final int sampleWeight;
 
     public SampledTpchRecordSetProvider(String connectorIdint sampleWeight)
     {
         this. = new TpchMetadata(connectorId);
         this. = sampleWeight;
     }
 
     @Override
     public RecordSet getRecordSet(ConnectorSplit splitList<? extends ConnectorColumnHandlecolumns)
     {
         int sampleWeightField = -1;
         for (int i = 0; i < columns.size(); i++) {
             ConnectorColumnHandle column = columns.get(i);
             if (column instanceof TpchColumnHandle && ((TpchColumnHandlecolumn).getColumnName().equals(.)) {
                 sampleWeightField = i;
                 break;
             }
         }
         List<? extends ConnectorColumnHandledelegatedColumns = new ArrayList<>(columns);
         if (sampleWeightField > -1) {
             delegatedColumns.remove(sampleWeightField);
             RecordSet recordSet;
             if (delegatedColumns.isEmpty()) {
                 // Pick a random column, so that we can figure out how many rows there are
                 TpchSplit tpchSplit = (TpchSplitsplit;
                 ConnectorColumnHandle column = Iterables.getFirst(.getColumnHandles(tpchSplit.getTableHandle()).values(), null);
                 checkNotNull(column"Could not find any columns");
                 recordSet = new EmptyRecordSet(super.getRecordSet(split, ImmutableList.of(column)));
             }
             else {
                 recordSet = super.getRecordSet(splitdelegatedColumns);
             }
             return new SampledTpchRecordSet(recordSetsampleWeightField);
         }
         else {
             return super.getRecordSet(splitcolumns);
         }
     }
 
     private static class EmptyRecordSet
             implements RecordSet
     {
         private final RecordSet delegate;
 
         EmptyRecordSet(RecordSet delegate)
         {
             this. = delegate;
         }
 
         @Override
         public List<TypegetColumnTypes()
         {
             return ImmutableList.of();
         }
 
         @Override
         public RecordCursor cursor()
         {
             return new EmptyRecordCursor(.cursor());
         }
    }
    private static class EmptyRecordCursor
            implements RecordCursor
    {
        private final RecordCursor delegate;
        EmptyRecordCursor(RecordCursor delegate)
        {
            this. = delegate;
        }
        @Override
        public long getTotalBytes()
        {
            return 0;
        }
        @Override
        public long getCompletedBytes()
        {
            return 0;
        }
        @Override
        public long getReadTimeNanos()
        {
            return 0;
        }
        @Override
        public Type getType(int field)
        {
            throw new RuntimeException("record cursor is empty");
        }
        @Override
        public boolean advanceNextPosition()
        {
            return .advanceNextPosition();
        }
        @Override
        public boolean getBoolean(int field)
        {
            throw new RuntimeException("record cursor is empty");
        }
        @Override
        public long getLong(int field)
        {
            throw new RuntimeException("record cursor is empty");
        }
        @Override
        public double getDouble(int field)
        {
            throw new RuntimeException("record cursor is empty");
        }
        @Override
        public Slice getSlice(int field)
        {
            throw new RuntimeException("record cursor is empty");
        }
        @Override
        public boolean isNull(int field)
        {
            throw new RuntimeException("record cursor is empty");
        }
        @Override
        public void close()
        {
        }
    }
    private static class SampledTpchRecordSet
            implements RecordSet
    {
        private final RecordSet delegate;
        private final int sampleWeightField;
        private final int sampleWeight;
        SampledTpchRecordSet(RecordSet delegateint sampleWeightFieldint sampleWeight)
        {
            this. = delegate;
            this. = sampleWeightField;
            this. = sampleWeight;
        }
        @Override
        public List<TypegetColumnTypes()
        {
            List<Typetypes = new ArrayList<>();
            types.addAll(.getColumnTypes());
            types.add();
            return ImmutableList.copyOf(types);
        }
        @Override
        public RecordCursor cursor()
        {
            return new SampledTpchRecordCursor(.cursor(), );
        }
    }
    private static class SampledTpchRecordCursor
            implements RecordCursor
    {
        private final RecordCursor delegate;
        private final int sampleWeightField;
        private final int sampleWeight;
        public SampledTpchRecordCursor(RecordCursor delegateint sampleWeightFieldint sampleWeight)
        {
            this. = delegate;
            this. = sampleWeightField;
            this. = sampleWeight;
        }
        @Override
        public boolean isNull(int field)
        {
            if (field == ) {
                return false;
            }
            else {
                return .isNull(field);
            }
        }
        @Override
        public void close()
        {
            .close();
        }
        @Override
        public long getLong(int field)
        {
            if (field == ) {
                return ;
            }
            else {
                return .getLong(field);
            }
        }
        @Override
        public double getDouble(int field)
        {
            return .getDouble(field);
        }
        @Override
        public Slice getSlice(int field)
        {
            return .getSlice(field);
        }
        @Override
        public long getTotalBytes()
        {
            return .getTotalBytes();
        }
        @Override
        public long getCompletedBytes()
        {
            return .getCompletedBytes();
        }
        @Override
        public long getReadTimeNanos()
        {
            return 0;
        }
        @Override
        public Type getType(int field)
        {
            if (field == ) {
                return ;
            }
            else {
                return .getType(field);
            }
        }
        @Override
        public boolean advanceNextPosition()
        {
            return .advanceNextPosition();
        }
        @Override
        public boolean getBoolean(int field)
        {
            return .getBoolean(field);
        }
    }
New to GrepCode? Check out our FAQ X