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.sql.analyzer;
 
 
 
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
 import static com.facebook.presto.util.ImmutableCollectors.toImmutableList;
 import static com.facebook.presto.util.ImmutableCollectors.toImmutableSet;
 import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.base.Preconditions.checkElementIndex;
 import static com.google.common.base.Preconditions.checkNotNull;
 import static com.google.common.base.Predicates.not;
 
 public class TupleDescriptor
 {
     private final List<FieldvisibleFields;
     private final List<FieldallFields;
 
     private final Map<FieldIntegerfieldIndexes;
 
     public TupleDescriptor(Field... fields)
     {
         this(ImmutableList.copyOf(fields));
     }
 
     public TupleDescriptor(List<Fieldfields)
     {
         checkNotNull(fields"fields is null");
         this. = ImmutableList.copyOf(fields);
         this. = ImmutableList.copyOf(Iterables.filter(fieldsnot(Field::isHidden)));
 
         int index = 0;
         ImmutableMap.Builder<FieldIntegerbuilder = ImmutableMap.builder();
         for (Field field : fields) {
             builder.put(fieldindex++);
         }
          = builder.build();
     }

    
Gets the index of the specified field or -1 if not found.
 
     public int indexOf(Field field)
     {
         return .get(field);
     }

    
Gets the field at the specified index.
 
     public Field getFieldByIndex(int fieldIndex)
     {
         checkElementIndex(fieldIndex.size(), "fieldIndex");
         return .get(fieldIndex);
     }

    
Gets only the visible fields. No assumptions should be made about the order of the fields returned from this method. To obtain the index of a field, call indexOf.
 
     public Collection<FieldgetVisibleFields()
     {
         return ;
     }
 
     public int getVisibleFieldCount()
     {
         return .size();
     }

    
Gets all fields including hidden fields. No assumptions should be made about the order of the fields returned from this method. To obtain the index of a field, call indexOf.
    public Collection<FieldgetAllFields()
    {
        return ImmutableSet.copyOf();
    }

    
Gets the count of all fields including hidden fields.
    public int getAllFieldCount()
    {
        return .size();
    }

    
Returns all unique relations in this tuple. For detecting detecting duplicate relations in a Join.
    {
        return .stream()
                .map(Field::getRelationAlias)
                .filter(Optional::isPresent)
                .map(Optional::get)
                .collect(toImmutableSet());
    }

    
This method is used for SELECT * or x.* queries
    {
        return .stream()
                .filter(input -> input.matchesPrefix(prefix))
                .collect(toImmutableList());
    }

    
Gets the index of all columns matching the specified name
    public List<FieldresolveFields(QualifiedName name)
    {
        return .stream()
                .filter(input -> input.canResolve(name))
                .collect(toImmutableList());
    }
    {
        return input -> !resolveFields(input).isEmpty();
    }

    
Creates a new tuple descriptor containing all fields from this tuple descriptor and all fields from the specified tuple decriptor.
    {
        List<Fieldfields = ImmutableList.<Field>builder()
                .addAll(this.)
                .addAll(other.allFields)
                .build();
        return new TupleDescriptor(fields);
    }

    
Creates a new tuple descriptor with the relation, and, optionally, the columns aliased.
    public TupleDescriptor withAlias(String relationAliasList<StringcolumnAliases)
    {
        if (columnAliases != null) {
            checkArgument(columnAliases.size() == .size(),
                    "Column alias list has %s entries but '%s' has %s columns available",
                    columnAliases.size(),
                    relationAlias,
                    .size());
        }
        ImmutableList.Builder<FieldfieldsBuilder = ImmutableList.builder();
        for (int i = 0; i < .size(); i++) {
            Field field = .get(i);
            Optional<StringcolumnAlias = field.getName();
            if (columnAliases == null) {
                fieldsBuilder.add(Field.newQualified(QualifiedName.of(relationAlias), columnAliasfield.getType(), field.isHidden()));
            }
            else if (!field.isHidden()) {
                // hidden fields are not exposed when there are column aliases
                columnAlias = Optional.of(columnAliases.get(i));
                fieldsBuilder.add(Field.newQualified(QualifiedName.of(relationAlias), columnAliasfield.getType(), false));
            }
        }
        return new TupleDescriptor(fieldsBuilder.build());
    }

    
Creates a new tuple descriptor containing only the visible fields.
    {
        return new TupleDescriptor();
    }
    @Override
    public String toString()
    {
        return .toString();
    }
New to GrepCode? Check out our FAQ X