zoukankan      html  css  js  c++  java
  • Spark 写Hive指定动态分区

    1、设置

       SparkSession.Builder builder = SparkSession
                    .builder()
                    .config(conf)
                    .master("yarn")
                    .config("hive.exec.dynamici.partition", true)
                    .config("hive.exec.dynamic.partition.mode", "nonstrict")
                    .appName(taskName)
                    .enableHiveSupport();
    

      

    2、sql
      

      /**
         * 同步数据到clickhouse
         * 按照日期分区
         *
         * @param dataFrame
         */
        private void sinkToHive(Dataset<Row> dataFrame) {
            dataFrame.createOrReplaceTempView("soh_tmp");
            String selectSql = "select " + getSelectHiveColumn() + " from soh_tmp";
            String sql = "INSERT INTO TABLE d_vehicle_data_charging_u_d partition(part_key) " + selectSql;
            sparkSession.sql(sql);
        }
    
        /**
         * @return
         */
        private String getSelectHiveColumn() {
            return
                    "vin,\n" +
                            "batch,\n" +
                            "tbox_type,\n" +
                            "collect_time,\n" +
                            "`current_timestamp` AS receive_time,\n" +
                            "battery_voltage_data,\n" +
                            "battery_temp_data,\n" +
                            "charging_status,\n" +
                            "total_current,\n" +
                            "battery_soc,\n" +
                            "max_temp,\n" +
                            "min_temp,\n" +
                            "partition_key,\n" +
                            "total_mileage,\n" +
                            "max_cell_voltage,\n" +
                            "min_cell_voltage,\n" +
                            "level_alarm,\n" +
                            "max_voltage_bat_sys_no,\n" +
                            "max_voltage_bat_cell_no," +
                            "mix_voltage_bat_sys_no,\n" +
                            "min_voltage_bat_cell_no,\n" +
                            "vehicle_status,\n" +
                            "insulation_resistance,\n" +
                            "insulation_Alarm, " +
                            "`current_timestamp`() as create_time,\n" +
                            " partition_key as part_key\n"
                    ;
        }
    

      



  • 相关阅读:
    经常使用的两个清爽的table样式
    wdcp新开站点或绑定域名打不开或无法访问的问题
    在线客服代码,可以用
    $smarty获取变量get,post等用法
    mysql 替换某个字段中的某个字符
    git 设置不需要输入密码
    linux批量查找文件内容
    使用PHP QR Code生成二维码
    RabbitMQ-2
    RabbitMQ-1
  • 原文地址:https://www.cnblogs.com/irobotzz/p/15561140.html
Copyright © 2011-2022 走看看