• 常见数据类型-HadoopDataType(仅仅作为记录)


     1 package mapred;
     2 
     3 import org.apache.hadoop.io.ArrayWritable;
     4 import org.apache.hadoop.io.IntWritable;
     5 import org.apache.hadoop.io.MapWritable;
     6 import org.apache.hadoop.io.NullWritable;
     7 import org.apache.hadoop.io.Text;
     8 
     9 /** hadoop数据类型与java数据类型 */
    10 public class HadoopDataType {
    11     /** 使用hadoop的Text类型数据 */
    12     public static void testText() {
    13         System.out.println("testText");
    14         Text text = new Text("hello hadoop!");
    15         System.out.println(text.getLength());
    16         System.out.println(text.find("a"));
    17         System.out.println(text.toString());
    18     }
    19 
    20     /** 使用ArrayWritable */
    21     public static void testArrayWritable() {
    22         System.out.println("testArrayWritable");
    23         ArrayWritable arr = new ArrayWritable(IntWritable.class);
    24         IntWritable year = new IntWritable(2017);
    25         IntWritable month = new IntWritable(07);
    26         IntWritable date = new IntWritable(01);
    27         arr.set(new IntWritable[] { year, month, date });
    28         System.out.println(String.format("year=%d,month=%d,date=%d",
    29                 ((IntWritable) arr.get()[0]).get(),
    30                 ((IntWritable) arr.get()[1]).get(),
    31                 ((IntWritable) arr.get()[2]).get()));
    32     }
    33 
    34     /** 使用MapWritable */
    35     public static void testMapWritable() {
    36         System.out.println("testMapWritable");
    37         MapWritable map = new MapWritable();
    38         Text k1 = new Text("name");
    39         Text v1 = new Text("tonny");
    40         Text k2 = new Text("password");
    41         map.put(k1, v1);
    42         map.put(k2, NullWritable.get());
    43         System.out.println(map.get(k1).toString());
    44         System.out.println(map.get(k2).toString());
    45     }
    46 
    47     // 入口 main
    48     public static void main(String[] args) {
    49         testText();
    50         testArrayWritable();
    51         testMapWritable();
    52     }
    53 }
    13
    7
    hello hadoop!
    testArrayWritable
    year=2017,month=7,date=1
    testMapWritable
    tonny
    (null)
    个人学习记录
  • 相关阅读:
    数据结构-栈与队列
    数据结构-选择排序
    数据结构-冒泡排序
    数据结构-插入排序
    mysql安装最后一步不响应解决
    ScvQ常用的网站(持续更新...)
    排序算法(二)
    排序算法(一)
    原码、反码、补码
    进制转换
  • 原文地址:https://www.cnblogs.com/jeshy/p/15244702.html
Copyright © 2020-2023  润新知