2024年全国职业院校技能大赛中职组大数据应用与服务赛项题库参考答案陆续更新中,敬请期待…_behavior2024-01-01

img
img
img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上大数据知识点,真正体系化!

由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新

需要这份系统化资料的朋友,可以戳这里获取

    // 检查参数数量是否为1,如果不是则抛出异常
    if (arguments.length != 1) {
        throw new UDFArgumentLengthException(
                "The function iptoloc(ip) takes exactly 1 argument.");
    }

    // 检查第一个参数是否为StringObjectInspector类型,如果不是则抛出异常
    if (!(arguments[0] instanceof StringObjectInspector)) {
        throw new UDFArgumentTypeException(0,
                "The argument must be a string, but " + arguments[0].getTypeName()
                        + " was given.");
    }

    // 将第一个参数设置为字符串类型的ObjectInspector
    this.stringInspector = (StringObjectInspector) arguments[0];

    // 设置输出类型为字符串,通过反射创建ObjectInspector实例
    this.outputOI = ObjectInspectorFactory.getReflectionObjectInspector(String.class,
            ObjectInspectorFactory.ObjectInspectorOptions.JAVA);

    // 打印输出类型的ObjectInspector信息
    System.out.println(outputOI);
    return outputOI; // 返回输出类型的ObjectInspector,供其他方法使用
}

@Override
public Object evaluate(DeferredObject[] arguments) throws HiveException {
    // 获取传入的IP地址参数
    String ip = stringInspector.getPrimitiveJavaObject(arguments[0].get());

    // 从指定文件中读取地区信息
    //File file = new File("/root/eduhq/data/area.json");
    File file = new File("/resources/area.json");
    ObjectMapper mapper = new ObjectMapper();
    List<String> provinces = new ArrayList<>();
    List<String> cities = new ArrayList<>();

    try {
        // 解析JSON文件
        JsonNode rootNode = mapper.readTree(file);

        // 遍历JSON节点,获取省份和城市信息
        for (JsonNode node : rootNode) {
            String province = node.path("province").getTextValue();
            String city = node.path("city").getTextValue();

            provinces.add(province);
            cities.add(city);
        }
    } catch (IOException e) {
        throw new HiveException("Failed to read area.json file: " + e.getMessage(), e);
    }

    // 根据IP地址进行分类标注
    int index = ipToIndex(ip);
    String province = provinces.get(index);
    String city = cities.get(index);

    // 返回分类标注结果
    ObjectNode result = mapper.createObjectNode();
    result.put("province", province);
    result.put("city", city);

    return result.toString();
}
@Override
public String getDisplayString(String[] children) {
    return "iptoloc(" + children[0] + ")";
}

private int ipToIndex(String ip) {
    // 根据IP地址的某种算法得到索引值
    // 这里简单地使用IP地址的字符长度模拟算法
    return ip.length() % 7;
}

}

org.apache.hive
hive-exec
3.1.2


### (三)任务三:数据统计


**1.子任务一:HDFS 文件上传下载**  
 ( 1 ) 将包“ com.hive.udf ”导出为名为 hive-udf- behavior-1.0.0.jar 的 JAR 文件, 并 保 存在 本地 的  
 /root/eduhq/udf\_jars 目录中;  
 **答:**`https://blog.csdn.net/gb4215287/article/details/132793531`  
 (2)将打包文件 hive-udf-behavior-1.0.0.jar 上传到HDFS 的/hive/udf\_jars 目录下;  
 **答:**`hadoop fs -put hive-udf-behavior-1.0.0.jar /hive/udf_jars`  
 (3)在 Hive 客户端,创建永久函数 url\_trans 和get\_city\_by\_ip,并将它们与开发好的 class 相关联;  
 **答:**



add jar /root/eduhq/udf_jars/hive-udf-behavior-1.0.0.jar
create function url_trans as com.hive.udf.url_trans;
create function get_city_by_ip as com.hive.udf.get_city_by_ip;


(4)在 Hive 客户端,使用 select 语句测试url\_trans和get\_city\_by\_ip 函数;  
 \*\*答:\*\*根据具体作用使用。例如:



select get_city_by_ip(ip);


(5)启动 Hive 的动态分区功能,并将 Hive 设置为非严格模式;  
 **答:**



set hive.exec.dynamic.partition=true;
set hive.exec.dynamic.partition.mode=nostrict;


(6)使用 insert overwrite … select …子句将ods\_behavior\_log 表中数据插入分区表 dwd\_behavior\_log中,并实现根据 dt 进行动态分区。  
 **答:**`insert overwrite table dwd_behavior_log PARTITION (dt) select *,date_format(dt,'yyyy-MM-dd') from ods_behavior_log;`  
 **2.子任务二:数据统计**  
 (1)查看dwd\_behavior\_log表的所有现有分区;  
 **答:**`SHOW PARTITIONS dwd_behavior_log;`  
 (2)查看外部表dwd\_behavior\_log的前3行数据,并验证URL协议是否被统一为“http”,以及通过IP是否能够获取到“省份”和“城市”信息;  
 **答:**



SELECT * FROM dwd_behavior_log LIMIT 3;
SELECT URL FROM dwd_behavior_log WHERE URL LIKE ‘http://%’;
返回所有以“http://”开头的URL。如果返回的行数大于0,则说明URL协议被统一为“http”。
通过ip获取省份,例如:select get_city_by_ip(ip);


(3)统计外部表dwd\_behavior\_log数据总行数。  


![img](https://img-blog.csdnimg.cn/img_convert/bddae67717c590de2fb8dc80f5affeb5.png)
![img](https://img-blog.csdnimg.cn/img_convert/02e492c650a6211bfee56b00775aa04c.png)
![img](https://img-blog.csdnimg.cn/img_convert/1ed6c29895430247ed8925534377a703.png)

**既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上大数据知识点,真正体系化!**

**由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新**

**[需要这份系统化资料的朋友,可以戳这里获取](https://bbs.csdn.net/topics/618545628)**

,涵盖了95%以上大数据知识点,真正体系化!**

**由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新**

**[需要这份系统化资料的朋友,可以戳这里获取](https://bbs.csdn.net/topics/618545628)**

  • 4
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值