• 07 友盟项目--拆分日志为五个表---动态生成日志类对应的建日志表的sql 语句-创建表


    拆分日志为五个表---动态生成日志类对应的建日志表的sql 语句

    1.util包下 ---》 LogUtil  通过内省的方式的到成员变量 

     1     /**
     2      * 生成日志类对应的日志表sql语句
     3      */
     4     public static <T extends  AppBaseLog> String genDDL(Class<T> clazz) throws Exception {
     5         String classname = clazz.getSimpleName().toLowerCase() ;
     6         StringBuffer buffer = new StringBuffer() ;
     7         buffer.append("create table if not exists ") ;
     8         buffer.append(classname + "s (
    ") ;
     9         //内省 --》 JavaBean
    10         BeanInfo bi = Introspector.getBeanInfo(clazz) ;
    11         PropertyDescriptor[] pps = bi.getPropertyDescriptors() ;
    12         for(int i =0 ; i < pps.length ; i ++ ){
    13             String name = pps[i].getName();
    14             Method get = pps[i].getReadMethod() ;
    15             Method set = pps[i].getWriteMethod();
    16             if(get != null && set != null){
    17                 if(name.equalsIgnoreCase("createdAtMs")){
    18                     buffer.append("  createdatms bigint") ;
    19                 }
    20                 else{
    21                     buffer.append("  " + name.toLowerCase() + " string") ;
    22                 }
    23                 //最后一个
    24                 if(i != (pps.length - 1)){
    25                     buffer.append(" ,
    ");
    26                 }
    27             }
    28         }
    29         buffer.append(")
    ");
    30         buffer.append("PARTITIONED BY (ym string, day string) 
    ");
    31         buffer.append("stored as parquet ;
    ");
    32         return buffer.toString() ;
    33     }

    2.测试并生成五个类对应的5个表的建表sql语句

    代码

    @Test
    public void testGenDDL() throws Exception {
    System.out.println(LogUtil.genDDL(AppStartupLog.class));
    System.out.println(LogUtil.genDDL(AppEventLog.class));
    System.out.println(LogUtil.genDDL(AppErrorLog.class));
    System.out.println(LogUtil.genDDL(AppUsageLog.class));
    System.out.println(LogUtil.genDDL(AppPageLog.class));
    }

    3.生成的建表sql语句如下
    create table if not exists appstartuplogs (
      appchannel string ,
      appid string ,
      appplatform string ,
      appversion string ,
      brand string ,
      carrier string ,
      country string ,
      createdatms bigint ,
      deviceid string ,
      devicestyle string ,
      ipaddress string ,
      network string ,
      ostype string ,
      province string ,
      screensize string ,
      tenantid string)
    PARTITIONED BY (ym string, day string)
    stored as parquet ;
    
    create table if not exists appeventlogs (
      appchannel string ,
      appid string ,
      appplatform string ,
      appversion string ,
      brand string ,
      createdatms bigint ,
      deviceid string ,
      devicestyle string ,
      eventdurationsecs string ,
      eventid string ,
      ostype string ,
      paramkeyvaluemap string ,
      tenantid string)
    PARTITIONED BY (ym string, day string)
    stored as parquet ;
    
    create table if not exists apperrorlogs (
      appchannel string ,
      appid string ,
      appplatform string ,
      appversion string ,
      brand string ,
      createdatms bigint ,
      deviceid string ,
      devicestyle string ,
      errorbrief string ,
      errordetail string ,
      ostype string ,
      tenantid string)
    PARTITIONED BY (ym string, day string)
    stored as parquet ;
    
    create table if not exists appusagelogs (
      appchannel string ,
      appid string ,
      appplatform string ,
      appversion string ,
      brand string ,
      createdatms bigint ,
      deviceid string ,
      devicestyle string ,
      ostype string ,
      singledownloadtraffic string ,
      singleuploadtraffic string ,
      singleusedurationsecs string ,
      tenantid string)
    PARTITIONED BY (ym string, day string)
    stored as parquet ;
    
    create table if not exists apppagelogs (
      appchannel string ,
      appid string ,
      appplatform string ,
      appversion string ,
      brand string ,
      createdatms bigint ,
      deviceid string ,
      devicestyle string ,
      nextpage string ,
      ostype string ,
      pageid string ,
      pageviewcntinsession string ,
      staydurationsecs string ,
      tenantid string ,
      visitindex string)
    PARTITIONED BY (ym string, day string)
    stored as parquet ;
    5个子表-建表sql语句

     注意

    上面建表语句  appeventlogs中有错误   删除paramKeyValueMap  字段

    4. sql脚本
    nano create_logs.sql

    5。执行脚本

    hive -f create_logs_table.sql





















  • 相关阅读:
    cocos2dx图片加密解密(npk方式)
    C#吾日三省吾身
    重写窗体的Enter事件(可对窗口的Enter事件做自己想做的事情)
    c#中显示Excel控件使用说明
    c# datagridview合并单元格
    AxSpreadsheet属性与方法说明
    c#实现货币转中文大写类
    jquery常用的插件1000收集
    [原创]站长自助平台一个帮助站长全自动实现一键采集、发贴(伪原创)、会员注册、交换连接的平台
    c#操作XML常用方法
  • 原文地址:https://www.cnblogs.com/star521/p/9878886.html
Copyright © 2020-2023  润新知