zoukankan      html  css  js  c++  java
  • Hive的存储和MapReduce处理——数据清洗(Part3)

    日期:2019.11.15

    博客期:117

    星期五

      这两天因为有课,其他的课程需要做实验,所以课下都在做其他科目的实验。

      不过还是有新的进度的。

      我研究了IP到城市的格式转换

      

     1 public class IPUtil {
     2  
     3     public static String getCityInfo(String ip){
     4  
     5         //db
     6         //String dbPath = "data/ip2region.db";
     7         String dbPath = IPUtil.class.getResource("../data/ip2region.db").getPath();
     8  
     9         File file = new File(dbPath);
    10         if ( file.exists() == false ) {
    11             System.out.println("Error: Invalid ip2region.db file");
    12         }
    13  
    14         //查询算法
    15         int algorithm = DbSearcher.BTREE_ALGORITHM; //B-tree
    16                         //DbSearcher.BINARY_ALGORITHM //Binary
    17                         //DbSearcher.MEMORY_ALGORITYM //Memory
    18         try {
    19             DbConfig config = new DbConfig();
    20             DbSearcher searcher = new DbSearcher(config, dbPath);
    21  
    22             //define the method
    23             Method method = null;
    24             switch ( algorithm )
    25             {
    26             case DbSearcher.BTREE_ALGORITHM:
    27                 method = searcher.getClass().getMethod("btreeSearch", String.class);
    28                 break;
    29             case DbSearcher.BINARY_ALGORITHM:
    30                 method = searcher.getClass().getMethod("binarySearch", String.class);
    31                 break;
    32             case DbSearcher.MEMORY_ALGORITYM:
    33                 method = searcher.getClass().getMethod("memorySearch", String.class);
    34                 break;
    35             }
    36  
    37             DataBlock dataBlock = null;
    38             if ( Util.isIpAddress(ip) == false ) {
    39                 System.out.println("Error: Invalid ip address");
    40             }
    41  
    42             dataBlock  = (DataBlock) method.invoke(searcher, ip);
    43  
    44             return dataBlock.getRegion();
    45  
    46         } catch (Exception e) {
    47             e.printStackTrace();
    48         }
    49  
    50         return null;
    51     }
    52  
    53     public static void main(String[] args)  throws Exception{
    54         System.out.println(getCityInfo("106.39.41.166"));
    55     }
    56 }
    代码非个人所写,但是由博主修改了很多地方的

      result.txt资源我已上传至我的资源文件里。

  • 相关阅读:
    php 三级连动及 php+ajax的调试方法
    ajax传值 乱码问题
    ajax传值给php
    php连接mssql pdo
    语法正确的情况下报错的原因
    Mina传递对象
    Mina小例子
    基于MINA构建简单高性能的NIO应用
    点与不规则图形关系判断
    Postman----基础使用篇(没有接口文档的情况下如何着手做接口测试)
  • 原文地址:https://www.cnblogs.com/onepersonwholive/p/11869612.html
Copyright © 2011-2022 走看看