spark开发考题!面试题! 网络开发式运营人才选拔!
题目:
现有一批IP地址(详见文件ip.txt),需要根据IP地址库信息(详见文件iplib.txt),查询归属地信息,并统计每一个归属地IP地址的总数。请编写spark任务并在测试环境上提交运行。统计结果请以文本文件格式请保存在xxxx目录下,源代码请保存在xxxx目录下。运行结果格式示例:江苏 移动 241江西 电信 67河南 联通 89
IPLib_test格式:
1.1.1.0 1.1.1.255 广东 电信2.0.0.0 2.1.1.255 天津 电信
......
IPs_test 格式:
101.100.24.56144.0.1.100
......
package com.dt.spark.chinatelecomExam; public class IpUtil { public static boolean ipExistsInRange(String ip, String ipSection) { ipSection = ipSection.trim(); ip = ip.trim(); int idx = ipSection.indexOf('-'); String beginIP = ipSection.substring(0, idx); String endIP = ipSection.substring(idx + 1); return getIp2long(beginIP) { var ip = line.trim var exists = false var locationKey: String = "NoMatchIPQuery" var IPValue: Long = 0L val iplibSets: HashSet[String] = IPLibSetBroadcast.value for (iplib line._1 + "\t" + line._2).saveAsTextFile(dataPath + "IPQueryResult.txt") } }