本文整理汇总了Java中org.apache.avro.util.Utf8类的典型用法代码示例。如果您正苦于以下问题:Java Utf8类的具体用法?Java Utf8怎么用?Java Utf8使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Utf8类属于org.apache.avro.util包,在下文中一共展示了Utf8类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: TaskAttemptStartedEvent
import org.apache.avro.util.Utf8; //导入依赖的package包/类
/**
* Create an event to record the start of an attempt
* @param attemptId Id of the attempt
* @param taskType Type of task
* @param startTime Start time of the attempt
* @param trackerName Name of the Task Tracker where attempt is running
* @param httpPort The port number of the tracker
* @param shufflePort The shuffle port number of the container
* @param containerId The containerId for the task attempt.
* @param locality The locality of the task attempt
* @param avataar The avataar of the task attempt
*/
public TaskAttemptStartedEvent( TaskAttemptID attemptId,
TaskType taskType, long startTime, String trackerName,
int httpPort, int shufflePort, ContainerId containerId,
String locality, String avataar) {
datum.attemptId = new Utf8(attemptId.toString());
datum.taskid = new Utf8(attemptId.getTaskID().toString());
datum.startTime = startTime;
datum.taskType = new Utf8(taskType.name());
datum.trackerName = new Utf8(trackerName);
datum.httpPort = httpPort;
datum.shufflePort = shufflePort;
datum.containerId = new Utf8(containerId.toString());
if (locality != null) {
datum.locality = new Utf8(locality);
}
if (avataar != null) {
datum.avataar = new Utf8(avataar);
}
}
示例2: getDatum
import org.apache.avro.util.Utf8; //导入依赖的package包/类
public Object getDatum() {
if (datum == null) {
datum = new TaskAttemptFinished();
datum.taskid = new Utf8(attemptId.getTaskID().toString());
datum.attemptId = new Utf8(attemptId.toString());
datum.taskType = new Utf8(taskType.name());
datum.taskStatus = new Utf8(taskStatus);
datum.finishTime = finishTime;
if (rackName != null) {
datum.rackname = new Utf8(rackName);
}
datum.hostname = new Utf8(hostname);
datum.state = new Utf8(state);
datum.counters = EventWriter.toAvro(counters);
}
return datum;
}
示例3: toAvro
import org.apache.avro.util.Utf8; //导入依赖的package包/类
static JhCounters toAvro(Counters counters, String name) {
JhCounters result = new JhCounters();
result.name = new Utf8(name);
result.groups = new ArrayList<JhCounterGroup>(0);
if (counters == null) return result;
for (CounterGroup group : counters) {
JhCounterGroup g = new JhCounterGroup();
g.name = new Utf8(group.getName());
g.displayName = new Utf8(group.getDisplayName());
g.counts = new ArrayList<JhCounter>(group.size());
for (Counter counter : group) {
JhCounter c = new JhCounter();
c.name = new Utf8(counter.getName());
c.displayName = new Utf8(counter.getDisplayName());
c.value = counter.getValue();
g.counts.add(c);
}
result.groups.add(g);
}
return result;
}
示例4: JobUnsuccessfulCompletionEvent
import org.apache.avro.util.Utf8; //导入依赖的package包/类
/**
* Create an event to record unsuccessful completion (killed/failed) of jobs
* @param id Job ID
* @param finishTime Finish time of the job
* @param finishedMaps Number of finished maps
* @param finishedReduces Number of finished reduces
* @param status Status of the job
* @param diagnostics job runtime diagnostics
*/
public JobUnsuccessfulCompletionEvent(JobID id, long finishTime,
int finishedMaps,
int finishedReduces,
String status,
Iterable<String> diagnostics) {
datum.setJobid(new Utf8(id.toString()));
datum.setFinishTime(finishTime);
datum.setFinishedMaps(finishedMaps);
datum.setFinishedReduces(finishedReduces);
datum.setJobStatus(new Utf8(status));
if (diagnostics == null) {
diagnostics = NODIAGS_LIST;
}
datum.setDiagnostics(new Utf8(Joiner.on('\n').skipNulls()
.join(diagnostics)));
}
示例5: getDatum
import org.apache.avro.util.Utf8; //导入依赖的package包/类
public Object getDatum() {
if(datum == null) {
datum = new TaskFailed();
datum.taskid = new Utf8(id.toString());
datum.error = new Utf8(error);
datum.finishTime = finishTime;
datum.taskType = new Utf8(taskType.name());
datum.failedDueToAttempt =
failedDueToAttempt == null
? null
: new Utf8(failedDueToAttempt.toString());
datum.status = new Utf8(status);
datum.counters = EventWriter.toAvro(counters);
}
return datum;
}
示例6: getDatum
import org.apache.avro.util.Utf8; //导入依赖的package包/类
public Object getDatum() {
if (datum == null) {
datum = new JobFinished();
datum.jobid = new Utf8(jobId.toString());
datum.finishTime = finishTime;
datum.finishedMaps = finishedMaps;
datum.finishedReduces = finishedReduces;
datum.failedMaps = failedMaps;
datum.failedReduces = failedReduces;
datum.mapCounters = EventWriter.toAvro(mapCounters, "MAP_COUNTERS");
datum.reduceCounters = EventWriter.toAvro(reduceCounters,
"REDUCE_COUNTERS");
datum.totalCounters = EventWriter.toAvro(totalCounters, "TOTAL_COUNTERS");
}
return datum;
}
示例7: processRequests
import org.apache.avro.util.Utf8; //导入依赖的package包/类
public void processRequests( List<Iote2eRequest> iote2eRequests ) throws Exception {
try {
for( Iote2eRequest iote2eRequest : iote2eRequests ) {
if (iote2eRequest != null) {
List<RuleEvalResult> ruleEvalResults = ruleSvc.process( iote2eRequest);
if (ruleEvalResults != null && ruleEvalResults.size() > 0 ) {
iote2eSvc.processRuleEvalResults( iote2eRequest, ruleEvalResults);
}
// Near real time temperature display
final Utf8 sourceTypeTemperature = new Utf8("temperature");
if( iote2eRequest.getSourceType().equals(sourceTypeTemperature) ) {
nearRealTimeTemperature( iote2eRequest );
}
}
}
} catch (Exception e) {
logger.error(e.getMessage(),e);
throw e;
}
}
示例8: toAvro
import org.apache.avro.util.Utf8; //导入依赖的package包/类
static JhCounters toAvro(Counters counters, String name) {
JhCounters result = new JhCounters();
result.setName(new Utf8(name));
result.setGroups(new ArrayList<JhCounterGroup>(0));
if (counters == null) return result;
for (CounterGroup group : counters) {
JhCounterGroup g = new JhCounterGroup();
g.setName(new Utf8(group.getName()));
g.setDisplayName(new Utf8(group.getDisplayName()));
g.setCounts(new ArrayList<JhCounter>(group.size()));
for (Counter counter : group) {
JhCounter c = new JhCounter();
c.setName(new Utf8(counter.getName()));
c.setDisplayName(new Utf8(counter.getDisplayName()));
c.setValue(counter.getValue());
g.getCounts().add(c);
}
result.getGroups().add(g);
}
return result;
}
示例9: buildKryoRegistrations
import org.apache.avro.util.Utf8; //导入依赖的package包/类
private static <T> LinkedHashMap<String, KryoRegistration> buildKryoRegistrations(Class<T> serializedDataType) {
final LinkedHashMap<String, KryoRegistration> registrations = new LinkedHashMap<>();
// register Avro types.
registrations.put(
GenericData.Array.class.getName(),
new KryoRegistration(
GenericData.Array.class,
new ExecutionConfig.SerializableSerializer<>(new Serializers.SpecificInstanceCollectionSerializerForArrayList())));
registrations.put(Utf8.class.getName(), new KryoRegistration(Utf8.class));
registrations.put(GenericData.EnumSymbol.class.getName(), new KryoRegistration(GenericData.EnumSymbol.class));
registrations.put(GenericData.Fixed.class.getName(), new KryoRegistration(GenericData.Fixed.class));
registrations.put(GenericData.StringType.class.getName(), new KryoRegistration(GenericData.StringType.class));
// register the serialized data type
registrations.put(serializedDataType.getName(), new KryoRegistration(serializedDataType));
return registrations;
}
示例10: getDatum
import org.apache.avro.util.Utf8; //导入依赖的package包/类
public Object getDatum() {
if (datum == null) {
datum = new JobFinished();
datum.setJobid(new Utf8(jobId.toString()));
datum.setFinishTime(finishTime);
datum.setFinishedMaps(finishedMaps);
datum.setFinishedReduces(finishedReduces);
datum.setFailedMaps(failedMaps);
datum.setFailedReduces(failedReduces);
datum.setMapCounters(EventWriter.toAvro(mapCounters, "MAP_COUNTERS"));
datum.setReduceCounters(EventWriter.toAvro(reduceCounters,
"REDUCE_COUNTERS"));
datum.setTotalCounters(EventWriter.toAvro(totalCounters,
"TOTAL_COUNTERS"));
}
return datum;
}
示例11: TaskAttemptStartedEvent
import org.apache.avro.util.Utf8; //导入依赖的package包/类
/**
* Create an event to record the start of an attempt
* @param attemptId Id of the attempt
* @param taskType Type of task
* @param startTime Start time of the attempt
* @param trackerName Name of the Task Tracker where attempt is running
* @param httpPort The port number of the tracker
* @param shufflePort The shuffle port number of the container
* @param containerId The containerId for the task attempt.
* @param locality The locality of the task attempt
* @param avataar The avataar of the task attempt
*/
public TaskAttemptStartedEvent( TaskAttemptID attemptId,
TaskType taskType, long startTime, String trackerName,
int httpPort, int shufflePort, ContainerId containerId,
String locality, String avataar) {
datum.setAttemptId(new Utf8(attemptId.toString()));
datum.setTaskid(new Utf8(attemptId.getTaskID().toString()));
datum.setStartTime(startTime);
datum.setTaskType(new Utf8(taskType.name()));
datum.setTrackerName(new Utf8(trackerName));
datum.setHttpPort(httpPort);
datum.setShufflePort(shufflePort);
datum.setContainerId(new Utf8(containerId.toString()));
if (locality != null) {
datum.setLocality(new Utf8(locality));
}
if (avataar != null) {
datum.setAvataar(new Utf8(avataar));
}
}
示例12: convertToTypeInformation
import org.apache.avro.util.Utf8; //导入依赖的package包/类
/**
* Recursively converts extracted AvroTypeInfo into a RowTypeInfo nested structure with deterministic field order.
* Replaces generic Utf8 with basic String type information.
*/
private static TypeInformation<?> convertToTypeInformation(TypeInformation<?> extracted, Schema schema) {
if (schema.getType() == Schema.Type.RECORD) {
final List<Schema.Field> fields = schema.getFields();
final AvroTypeInfo<?> avroTypeInfo = (AvroTypeInfo<?>) extracted;
final TypeInformation<?>[] types = new TypeInformation<?>[fields.size()];
final String[] names = new String[fields.size()];
for (int i = 0; i < fields.size(); i++) {
final Schema.Field field = fields.get(i);
types[i] = convertToTypeInformation(avroTypeInfo.getTypeAt(field.name()), field.schema());
names[i] = field.name();
}
return new RowTypeInfo(types, names);
} else if (extracted instanceof GenericTypeInfo<?>) {
final GenericTypeInfo<?> genericTypeInfo = (GenericTypeInfo<?>) extracted;
if (genericTypeInfo.getTypeClass() == Utf8.class) {
return BasicTypeInfo.STRING_TYPE_INFO;
}
}
return extracted;
}
示例13: serialize
import org.apache.avro.util.Utf8; //导入依赖的package包/类
public Record serialize(AdvancedEmployee employee)
{
Record record = new Record(schema);
AvroUtils.put("name", employee.getName(), record);
AvroUtils.put("age", employee.getAge(), record);
AvroUtils.put("gender", employee.getGender(), record);
int numberOfEmails = (employee.getMails() != null) ? employee.getMails().size() : 0;
GenericData.Array<Utf8> emails = new GenericData.Array<>(numberOfEmails, schema.getField("emails").schema());
for(int i = 0; i < numberOfEmails; ++i)
{
emails.add(new Utf8(employee.getMails().get(i)));
}
record.put("emails", emails);
return record;
}
示例14: followingKey
import org.apache.avro.util.Utf8; //导入依赖的package包/类
/**
* @param keyClass
* @param bytes
* @return
*/
@SuppressWarnings("unchecked")
static <K> K followingKey(Encoder encoder, Class<K> clazz, byte[] per) {
if (clazz.equals(Byte.TYPE) || clazz.equals(Byte.class)) {
return (K) Byte.valueOf(encoder.followingKey(1, per)[0]);
} else if (clazz.equals(Boolean.TYPE) || clazz.equals(Boolean.class)) {
throw new UnsupportedOperationException();
} else if (clazz.equals(Short.TYPE) || clazz.equals(Short.class)) {
return fromBytes(encoder, clazz, encoder.followingKey(2, per));
} else if (clazz.equals(Integer.TYPE) || clazz.equals(Integer.class)) {
return fromBytes(encoder, clazz, encoder.followingKey(4, per));
} else if (clazz.equals(Long.TYPE) || clazz.equals(Long.class)) {
return fromBytes(encoder, clazz, encoder.followingKey(8, per));
} else if (clazz.equals(Float.TYPE) || clazz.equals(Float.class)) {
return fromBytes(encoder, clazz, encoder.followingKey(4, per));
} else if (clazz.equals(Double.TYPE) || clazz.equals(Double.class)) {
return fromBytes(encoder, clazz, encoder.followingKey(8, per));
} else if (clazz.equals(String.class)) {
throw new UnsupportedOperationException();
} else if (clazz.equals(Utf8.class)) {
return fromBytes(encoder, clazz, Arrays.copyOf(per, per.length + 1));
}
throw new IllegalArgumentException("Unknown type " + clazz.getName());
}
示例15: fromBytes
import org.apache.avro.util.Utf8; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static <T> T fromBytes( byte[] val, Schema schema
, SpecificDatumReader<T> datumReader, T object)
throws IOException {
Type type = schema.getType();
switch (type) {
case ENUM:
String symbol = schema.getEnumSymbols().get(val[0]);
return (T)Enum.valueOf(ReflectData.get().getClass(schema), symbol);
case STRING: return (T)new Utf8(toString(val));
case BYTES: return (T)ByteBuffer.wrap(val);
case INT: return (T)Integer.valueOf(bytesToVint(val));
case LONG: return (T)Long.valueOf(bytesToVlong(val));
case FLOAT: return (T)Float.valueOf(toFloat(val));
case DOUBLE: return (T)Double.valueOf(toDouble(val));
case BOOLEAN: return (T)Boolean.valueOf(val[0] != 0);
case RECORD: //fall
case MAP:
case ARRAY: return (T)IOUtils.deserialize(val, (SpecificDatumReader<SpecificRecord>)datumReader, schema, (SpecificRecord)object);
default: throw new RuntimeException("Unknown type: "+type);
}
}