Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * 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 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 org.apache.pig.impl.plan;
 
 import java.util.List;
 
A struct detailing how a projection is altered by an operator.
 
 public class RequiredFields {
    
    
Quick way for an operator to note that all columns from an input are required.
 
     private boolean mNeedAllFields = false;
    
    
Quick way for an operator to note that no columns from an input are required.
 
     private boolean mNeedNoFields = false;


    
List of fields required from the input. This includes fields that are transformed, and thus are no longer the same fields. Using the example 'B = foreach A generate $0, $2, $3, udf($1)' would produce the list (0, 0), (0, 2), (0, 3), (0, 1). Note that the order is not guaranteed.
 
     private List<Pair<IntegerInteger>> mFields;
     
     /*
      * Required map keys information
      */
     private List<MapKeysInfomMapKeysInfoList;

    

Parameters:
needAllFields to indicate if this required fields needs all the fields from its input
 
     public RequiredFields(boolean needAllFields) {
         this(nullneedAllFieldsfalse);
     }
    
    

Parameters:
needAllFields to indicate if this required fields needs no fields from its input
 
     public RequiredFields(boolean needAllFieldsboolean needNoFields) {
         this(nullneedAllFieldsneedNoFields);
     }

    

Parameters:
fields the list of input columns that are required
 
     public RequiredFields(List<Pair<IntegerInteger>> fields) {
         this(fieldsfalsefalse);
     }

    

Parameters:
fields the list of input columns that are required
needAllFields to indicate if this required fields needs all the fields from its input; cannot be true if needNoFields is true
needNoFields to indicate if this required fields needs no fields from its input; cannot be true if needAllFields is true
 
     private RequiredFields(List<Pair<IntegerInteger>> fields,
             boolean needAllFields,
             boolean needNoFields) {
          = fields;
        if(needAllFields && needNoFields) {
            //both cannot be true
            //set both of them to false
             = false;
             = false;
        } else {
             = needAllFields;
             = needNoFields;
        }
        if (!=null)
        {
             = new ArrayList<MapKeysInfo>();
            for (int i=0;i<.size();i++)
                .add(null);
        }
    }

    

Returns:
the list of input columns that are required
    public List<Pair<IntegerInteger>> getFields() {
        return ;
    }
    
    

Parameters:
i the index of the required field
Returns:
the ith required input column
    public Pair<IntegerIntegergetField(int i) {
        return .get(i);
    }
    
    

Returns:
the size of required input columns
    public int size() {
        if (==null)
            return 0;
        return .size();
    }

    

Parameters:
fields the list of input columns that are required
    public void setFields(List<Pair<IntegerInteger>> fields) {
         = fields;
        if (!=null)
        {
             = new ArrayList<MapKeysInfo>();
            for (int i=0;i<.size();i++)
                .add(null);
        }
    }

    

Returns:
if this required fields needs all the fields from its input(s)
    public boolean needAllFields() {
        return getNeedAllFields();
    }

    

Returns:
if this required fields needs all the fields from its input(s)
    public boolean getNeedAllFields() {
        return ;
    }

    

Parameters:
needAllFields to indicate if this required fields needs all the fields from its input; cannot be true if needNoFields() is true
    public void setNeedAllFields(boolean needAllFields) {
        if(needAllFields && needNoFields()) return;
         = needAllFields;
    }

    

Returns:
if this required fields needs no fields from its input(s)
    public boolean needNoFields() {
        return getNeedNoFields();
    }

    

Returns:
if this required fields needs no fields from its input(s)
    public boolean getNeedNoFields() {
        return ;
    }

    

Parameters:
needNoFields to indicate if this required fields needs no fields from its input; cannot be true if needAllFields() is true
    public void setNeedNoFields(boolean needNoFields) {
        if(needNoFields && needAllFields()) return;
         = needNoFields;
    }
    
    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("needAllFields: " + );
        sb.append(" needNoFields: " + );
        sb.append(" fields: " + );
        return sb.toString();
    }

    
Merge with RequiredFields r2. Merge both required fields and required map keys

Parameters:
r2 Required fields to merge
    public void merge(RequiredFields r2) {
        if (r2 == null)
            return;
        if (getNeedAllFields())
            return;
        if (r2.getNeedAllFields()) {
             = true;
            return;
        }
        if (getNeedNoFields() && !r2.getNeedNoFields()) {
             = false;
        }
        if (r2.getFields() == null)
            return;
        for (int i=0;i<r2.size();i++) {
            Pair<IntegerIntegerf = r2.getField(i);
            MapKeysInfo m = r2.getMapKeysInfo(i);
            if ( == null)
            {
                 = new ArrayList<Pair<IntegerInteger>>();
                 = new ArrayList<MapKeysInfo>();
            }
            if (!.contains(f)) {
                .add(f);
                .add(m);
                 = false;
            }
            else
            {
                if (m!=null)
                {
                    int index = .indexOf(new Pair<IntegerInteger>(f.firstf.second));
                    MapKeysInfo mapKeys = .get(index);
                    if (mapKeys == null)
                        mapKeys = new MapKeysInfo();
                    if (m.needAllKeys)
                    {
                        mapKeys.needAllKeys = true;
                        mapKeys.keys = null;
                    }
                    else if (mapKeys.keys!=null)
                    {
                        if (m.keys!=null)
                            mapKeys.keys.addAll(m.keys);
                    }
                    else
                    {
                        mapKeys.keys = m.keys;
                    }
                    .set(indexmapKeys);
                }
            }
        }
        return;
    }
    
    
Set the index of all fields to i

Parameters:
i New index to set
    public void reIndex(int i)
    {
        if (!=null)
        {
            for (Pair<IntegerIntegerp:)
            {
                p.first = i;
            }
        }
    }
    
    
Merge another map key into existing required map keys list

Parameters:
input The input of the field to merge
column The column of the field to merge
key The key to merge
    public void mergeMapKey(int inputint columnString key)
    {
        int index = .indexOf(new Pair<IntegerInteger>(inputcolumn));
        if (index==-1)
            return;
        if (.get(index)==null)
            .set(indexnew MapKeysInfo());
        MapKeysInfo keysInfo = .get(index);
        if (keysInfo.needAllKeys)
            return;
        if (!keysInfo.keys.contains(key))
            keysInfo.keys.add(key);
    }
    
    
Merge a MapKeysInfo structure to existing required map keys list

Parameters:
input The input of the field to merge
column The column of the field to merge
mapKeysInfo The MapKeysInfo structure to merge
    public void mergeMapKeysInfo(int inputint columnMapKeysInfo mapKeysInfo)
    {
        if (mapKeysInfo == null)
            return;
        int index = .indexOf(new Pair<IntegerInteger>(inputcolumn));
        if (index==-1)
            return;
        if (.get(index)==null)
        {
            .set(indexmapKeysInfo);
            return;
        }
        if (mapKeysInfo.needAllKeys)
        {
            .get(index). = true;
            .get(index). = null;
        }
        if (mapKeysInfo.keys!=null)
        {
            for (String key : mapKeysInfo.keys)
                mergeMapKey(inputcolumnkey);
        }
    }
    
    
Set a MapKeysInfo structure to the required map keys list

Parameters:
input The input of the field to set
column The column of the field to set
mapKeysInfo The MapKeysInfo structure to set
    public void setMapKeysInfo(int inputint columnMapKeysInfo mapKeysInfo)
    {
        int index = .indexOf(new Pair<IntegerInteger>(inputcolumn));
        if (index==-1)
            return;
        .set(indexmapKeysInfo);
    }
    
    
Get the ith MapKeysInfo structure

Parameters:
i The index of the MapKeysInfo, the index of MapKeysInfo is synchronized with mFields
    public MapKeysInfo getMapKeysInfo(int i)
    {
        return .get(i);
    }

    
Set the ith MapKeysInfo structure

Parameters:
i The index of the MapKeysInfo, the index of MapKeysInfo is synchronized with mFields
mapKeysInfo The MapKeysInfo to set
    public void setMapKeysInfo(int iMapKeysInfo mapKeysInfo)
    {
        .set(imapKeysInfo);
    }
New to GrepCode? Check out our FAQ X