org.apache.pig.LoadPushDown.RequiredField Java Examples

The following examples show how to use org.apache.pig.LoadPushDown.RequiredField. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PigSchemaConverter.java    From parquet-mr with Apache License 2.0 5 votes vote down vote up
@Override
public List<Type> filterTupleSchema(GroupType schemaToFilter, Schema pigSchema, RequiredFieldList requiredFieldsList) {
  List<Type> newFields = new ArrayList<Type>();
  List<Pair<FieldSchema,Integer>> indexedFields = new ArrayList<Pair<FieldSchema,Integer>>();

  try {
    if(requiredFieldsList == null) {
      int index = 0;
      for(FieldSchema fs : pigSchema.getFields()) {
        indexedFields.add(new Pair<FieldSchema, Integer>(fs, index++));
      }
    } else {
      for(RequiredField rf : requiredFieldsList.getFields()) {
        indexedFields.add(new Pair<FieldSchema, Integer>(pigSchema.getField(rf.getAlias()), rf.getIndex()));
      }
    }

    for (Pair<FieldSchema, Integer> p : indexedFields) {
      FieldSchema fieldSchema = pigSchema.getField(p.first.alias);
      if (p.second < schemaToFilter.getFieldCount()) {
        Type type = schemaToFilter.getFields().get(p.second);
        newFields.add(filter(type, fieldSchema));
      }
    }
  } catch (FrontendException e) {
      throw new RuntimeException("Failed to filter requested fields", e);
  }
  return newFields;
}
 
Example #2
Source File: PigUtils.java    From elasticsearch-hadoop with Apache License 2.0 5 votes vote down vote up
static String asProjection(RequiredFieldList list, Properties props) {
    List<String> fields = new ArrayList<String>();
    FieldAlias alias = alias(new PropertiesSettings(props));
    for (RequiredField field : list.getFields()) {
        addField(field, fields, alias, "");
    }

    return StringUtils.concatenate(fields, ",");
}
 
Example #3
Source File: PigUtils.java    From elasticsearch-hadoop with Apache License 2.0 5 votes vote down vote up
private static void addField(RequiredField field, List<String> fields, FieldAlias fa, String currentNode) {
    if (field.getSubFields() != null && !field.getSubFields().isEmpty()) {
        for (RequiredField subField : field.getSubFields()) {
            addField(subField, fields, fa, currentNode + "." + fa.toES(subField.getAlias()));
        }
    }

    else {
        fields.add(fa.toES(field.getAlias()));
    }
}