• 常见数据类型-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)
    个人学习记录
  • 相关阅读:
    在.wxml文件中使用方法
    Element日期区间选择器限制选择范围
    规定段落中的文本不进行换行
    文件大小换算
    elementUI的message消息提示改成只能同时存在一个
    SQL 执行顺序
    SQL Left join
    wpf datagrid 行双击事件
    关于Infragistics.WebUI.UltraWebGrid的使用
    ASP.NET 根据汉字获取汉字拼音的首字母(含多音字)
  • 原文地址:https://www.cnblogs.com/jeshy/p/15244702.html
Copyright © 2020-2023  润新知