zoukankan      html  css  js  c++  java
  • 常见数据类型-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)
    个人学习记录
  • 相关阅读:
    el自定义函数库
    DOM4J
    【转载】SqlServer日期时间函数
    【原创】C#认识/理解/运用 StreamReader,StreamWriter,StringReader,StreamWriter
    【原创】C#认识/理解/运用 FileStream
    【原创】C#操作XML(带命名空间)
    【原创】ASP.NET MVC3使用html编辑器(kindeditor)
    【原创】ASP.NET MVC3 从零开始一步步构建Web
    【转载】MVC使用jqGrid
    【原创】C#使用HttpWebRequest,HttpWebResponse
  • 原文地址:https://www.cnblogs.com/jeshy/p/15244702.html
Copyright © 2011-2022 走看看