Java 类org.apache.avro.generic.GenericData.Array 实例源码

项目:Pinot    文件:AvroQueryGenerator.java   
private static Object[] transformAvroArrayToObjectArray(Array arr) {
  if (arr == null) {
    return new Object[0];
  }
  final Object[] ret = new Object[arr.size()];
  final Iterator iterator = arr.iterator();
  int i = 0;
  while (iterator.hasNext()) {
    Object value = iterator.next();
    if (value instanceof Record) {
      value = ((Record) value).get(0);
    }
    if (value instanceof Utf8) {
      value = ((Utf8) value).toString();
    }
    ret[i++] = value;
  }
  return ret;
}
项目:Pinot    文件:AvroRecordReader.java   
public static Object[] transformAvroArrayToObjectArray(Array arr, FieldSpec spec) {
  if (arr == null) {
    return new Object[] { getDefaultNullValue(spec) };
  }
  if (arr.size() == 0) {
    return new Object[] { getDefaultNullValue(spec) };
  }

  final Object[] ret = new Object[arr.size()];
  final Iterator iterator = arr.iterator();
  int i = 0;
  while (iterator.hasNext()) {
    Object value = iterator.next();
    if (value instanceof Record) {
      value = ((Record) value).get(0);
    }
    if (value instanceof Utf8) {
      value = ((Utf8) value).toString();
    }
    if (value == null) {
      value = getDefaultNullValue(spec);
    }
    ret[i++] = value;
  }
  return ret;
}
项目:Pinot    文件:AvroRecordToPinotRowGenerator.java   
public GenericRow transform(GenericRecord avroRecord) {
  Map<String, Object> rowEntries = new HashMap<String, Object>();
  for (String column : indexingSchema.getColumnNames()) {
    Object entry = avroRecord.get(column);
    if (entry instanceof Utf8) {
      entry = ((Utf8) entry).toString();
    }
    if (entry instanceof Array) {
      entry = AvroRecordReader.transformAvroArrayToObjectArray((Array) entry, indexingSchema.getFieldSpecFor(column));
    }
    if (entry == null && indexingSchema.getFieldSpecFor(column).isSingleValueField()) {
      entry = AvroRecordReader.getDefaultNullValue(indexingSchema.getFieldSpecFor(column));
    }
    rowEntries.put(column, entry);
  }

  GenericRow row = new GenericRow();
  row.init(rowEntries);
  return row;
}
项目:Pinot    文件:SegmentTestUtils.java   
private static Object[] transformAvroArrayToObjectArray(Array arr) {
  if (arr == null) {
    return new Object[0];
  }
  final Object[] ret = new Object[arr.size()];
  final Iterator iterator = arr.iterator();
  int i = 0;
  while (iterator.hasNext()) {
    Object value = iterator.next();
    if (value instanceof Record) {
      value = ((Record) value).get(0);
    }
    if (value instanceof Utf8) {
      value = ((Utf8) value).toString();
    }
    ret[i++] = value;
  }
  return ret;
}
项目:pinot    文件:AvroQueryGenerator.java   
private static Object[] transformAvroArrayToObjectArray(Array arr) {
  if (arr == null) {
    return new Object[0];
  }
  final Object[] ret = new Object[arr.size()];
  final Iterator iterator = arr.iterator();
  int i = 0;
  while (iterator.hasNext()) {
    Object value = iterator.next();
    if (value instanceof Record) {
      value = ((Record) value).get(0);
    }
    if (value instanceof Utf8) {
      value = ((Utf8) value).toString();
    }
    ret[i++] = value;
  }
  return ret;
}
项目:pinot    文件:AvroRecordToPinotRowGenerator.java   
@Nonnull
public GenericRow transform(@Nonnull GenericData.Record from, @Nonnull GenericRow to) {
  for (FieldSpec fieldSpec : _schema.getAllFieldSpecs()) {
    FieldSpec incomingFieldSpec =
        fieldSpec.getFieldType() == FieldSpec.FieldType.TIME ? _incomingTimeFieldSpec : fieldSpec;
    String fieldName = incomingFieldSpec.getName();
    Object avroValue = from.get(fieldName);
    if (incomingFieldSpec.isSingleValueField()) {
      to.putField(fieldName, AvroUtils.transformAvroValueToObject(avroValue, incomingFieldSpec));
    } else {
      to.putField(fieldName, AvroUtils.transformAvroArrayToObjectArray((Array) avroValue, incomingFieldSpec));
    }
  }

  return to;
}
项目:pinot    文件:SegmentTestUtils.java   
private static Object[] transformAvroArrayToObjectArray(Array arr) {
  if (arr == null) {
    return new Object[0];
  }
  final Object[] ret = new Object[arr.size()];
  final Iterator iterator = arr.iterator();
  int i = 0;
  while (iterator.hasNext()) {
    Object value = iterator.next();
    if (value instanceof Record) {
      value = ((Record) value).get(0);
    }
    if (value instanceof Utf8) {
      value = ((Utf8) value).toString();
    }
    ret[i++] = value;
  }
  return ret;
}
项目:HBaseMate    文件:CharSequenceArrayToStringListTranslator.java   
/**
 * {@inheritDoc}
 */
@Override
public Array<CharSequence> convert(List<String> recommendationList) {
    List<CharSequence> recommendationArray = new ArrayList<CharSequence>();;
    for (String s : recommendationList) {
        recommendationArray.add(s);
    }
    Array<CharSequence> recomendationArray =  new Array<CharSequence>(Schema.createArray(Schema.create(Schema.Type.STRING)), recommendationArray);
    return recomendationArray;
}
项目:HBaseMate    文件:CharSequenceArrayToStringListTranslator.java   
/**
 * {@inheritDoc}
 */
@Override
public List<String> reverseConvert(Array<CharSequence> recommendationArray) {
    List<String> recommendationList = new ArrayList<String>();
    for (CharSequence ch : recommendationArray) {
        recommendationList.add(ch.toString());
    }

    return recommendationList;
}
项目:Pinot    文件:AvroRecordReader.java   
private GenericRow getGenericRow(GenericRecord rawRecord) {
  for (final Field field : _dataStream.getSchema().getFields()) {
    FieldSpec spec = _schemaExtractor.getSchema().getFieldSpecFor(field.name());
    if (spec == null) {
      continue;
    }
    Object value = rawRecord.get(field.name());
    if (value == null) {
      if (spec.isSingleValueField()) {
        value = spec.getDefaultNullValue();
      } else {
        value = transformAvroArrayToObjectArray((Array) value, spec);
      }
    } else {
      if (value instanceof Utf8) {
        value = ((Utf8) value).toString();
      }
      if (value instanceof Array) {
        value = transformAvroArrayToObjectArray((Array) value, spec);
      }
    }

    _fieldMap.put(field.name(), value);
  }
  _genericRow.init(_fieldMap);
  return _genericRow;
}
项目:Pinot    文件:AvroRecordToPinotRowGenerator.java   
public GenericRow transform(GenericData.Record record, org.apache.avro.Schema schema) {
  Map<String, Object> rowEntries = new HashMap<String, Object>();
  for (String column : indexingSchema.getColumnNames()) {
    Object entry = record.get(column);
    if (entry instanceof Array) {
      entry = AvroRecordReader.transformAvroArrayToObjectArray((Array) entry, indexingSchema.getFieldSpecFor(column));
      if (indexingSchema.getFieldSpecFor(column).getDataType() == DataType.STRING
          || indexingSchema.getFieldSpecFor(column).getDataType() == DataType.STRING_ARRAY) {
        for (int i = 0; i < ((Object[]) entry).length; ++i) {
          if (((Object[]) entry)[i] != null) {
            ((Object[]) entry)[i] = ((Object[]) entry)[i].toString();
          }
        }
      }
    } else {
      if (entry instanceof Utf8) {
        entry = ((Utf8) entry).toString();
      }
      if (indexingSchema.getFieldSpecFor(column).getDataType() == DataType.STRING) {
        if (entry != null) {
          entry = entry.toString();
        }
      }
    }
    if (entry == null && indexingSchema.getFieldSpecFor(column).isSingleValueField()) {
      entry = AvroRecordReader.getDefaultNullValue(indexingSchema.getFieldSpecFor(column));
    }
    rowEntries.put(column, entry);
  }

  GenericRow row = new GenericRow();
  row.init(rowEntries);
  return row;
}