Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to customize types in Hadoop

2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

In this issue, the editor will bring you about how to customize the type in Hadoop. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.

The code is as follows.

Public interface Comparable {public int compareTo (To);}

Specifies the method of internal comparison of objects

Public interface Comparator {int compare (T1, T2); boolean equals (Object obj);}

The basic method for defining external comparators, where equals is used to determine whether two comparators are equal

The differences and usage scenarios between internal comparison and external comparison of objects are as follows:

Personal summary:

Comparable is an inherent comparison within an object. Different objects of a class certainly need to be compared naturally. No matter where it is used, Comparator is an external comparison, adding new comparison behavior, especially for existing types, String,Integer, etc., without changing the inherent comparison criteria within the object. If we want different comparison behavior, such as absolute value comparison Then we can not modify the inherent comparison standard of this writing class, but add a custom external comparator, define new comparison rules in the external comparator, and insert our custom external comparator instance where we need to compare.

We know that there are custom types in hadoop that need to be implemented, the WritableComparable interface, and one of the inheritance of the WritableComparable interface is the Comparable interface.

Therefore, the custom type needs to implement the compareTo method

For example, LongWrite.class

@ Override public int compareTo (LongWritable o) {long thisValue = this.value; long thatValue = o.value; return (thisValue

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 206

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report