国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

數(shù)倉報表數(shù)據(jù)導(dǎo)出——Hive數(shù)據(jù)導(dǎo)出至Clickhouse

這篇具有很好參考價值的文章主要介紹了數(shù)倉報表數(shù)據(jù)導(dǎo)出——Hive數(shù)據(jù)導(dǎo)出至Clickhouse。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點(diǎn)擊"舉報違法"按鈕提交疑問。

1. Clickhouse建表

  1. 創(chuàng)建database
create database ad_report;
use ad_report;
  1. 創(chuàng)建table
drop table if exists dwd_ad_event_inc;
create table if not exists dwd_ad_event_inc
(
    event_time             Int64 comment '事件時間',
    event_type             String comment '事件類型',
    ad_id                  String comment '廣告id',
    ad_name                String comment '廣告名稱',
    ad_product_id          String comment '廣告產(chǎn)品id',
    ad_product_name        String comment '廣告產(chǎn)品名稱',
    ad_product_price       Decimal(16, 2) comment '廣告產(chǎn)品價格',
    ad_material_id         String comment '廣告素材id',
    ad_material_url        String comment '廣告素材url',
    ad_group_id            String comment '廣告組id',
    platform_id            String comment '推廣平臺id',
    platform_name_en       String comment '推廣平臺名稱(英文)',
    platform_name_zh       String comment '推廣平臺名稱(中文)',
    client_country         String comment '客戶端所處國家',
    client_area            String comment '客戶端所處地區(qū)',
    client_province        String comment '客戶端所處省份',
    client_city            String comment '客戶端所處城市',
    client_ip              String comment '客戶端ip地址',
    client_device_id       String comment '客戶端設(shè)備id',
    client_os_type         String comment '客戶端操作系統(tǒng)類型',
    client_os_version      String comment '客戶端操作系統(tǒng)版本',
    client_browser_type    String comment '客戶端瀏覽器類型',
    client_browser_version String comment '客戶端瀏覽器版本',
    client_user_agent      String comment '客戶端UA',
    is_invalid_traffic     UInt8 comment '是否是異常流量'
) ENGINE = MergeTree()
 ORDER BY (event_time, ad_name, event_type, client_province, client_city, client_os_type,
 client_browser_type, is_invalid_traffic);

2. Hive數(shù)據(jù)導(dǎo)出至Clickhouse

使用spark-sql查詢數(shù)據(jù),然后通過jdbc寫入Clickhouse。文章來源地址http://www.zghlxwxcb.cn/news/detail-574125.html

  1. 創(chuàng)建Maven項(xiàng)目,pom.xml文件如下
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.yt</groupId>
    <artifactId>hive-to-clickhouse</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
    </properties>

    <dependencies>

        <!-- 引入mysql驅(qū)動,目的是訪問hive的metastore元數(shù)據(jù)-->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.28</version>
        </dependency>

        <!-- 引入spark-hive模塊-->
        <dependency>
            <groupId>org.apache.spark</groupId>
            <artifactId>spark-hive_2.12</artifactId>
            <version>3.3.1</version>
            <scope>provided</scope>
        </dependency>

        <!--引入clickhouse-jdbc驅(qū)動,為解決依賴沖突,需排除jackson的兩個依賴-->
        <dependency>
            <groupId>ru.yandex.clickhouse</groupId>
            <artifactId>clickhouse-jdbc</artifactId>
            <version>0.2.4</version>
            <exclusions>
                <exclusion>
                    <artifactId>jackson-databind</artifactId>
                    <groupId>com.fasterxml.jackson.core</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>jackson-core</artifactId>
                    <groupId>com.fasterxml.jackson.core</groupId>
                </exclusion>
            </exclusions>
        </dependency>

        <!-- 引入commons-cli,目的是方便處理程序的輸入?yún)?shù) -->
        <dependency>
            <groupId>commons-cli</groupId>
            <artifactId>commons-cli</artifactId>
            <version>1.2</version>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>3.0.0</version>
                <configuration>
                    <!--將依賴編譯到j(luò)ar包中-->
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
                <executions>
                    <!--配置執(zhí)行器-->
                    <execution>
                        <id>make-assembly</id>
                        <!--綁定到package執(zhí)行周期上-->
                        <phase>package</phase>
                        <goals>
                            <!--只運(yùn)行一次-->
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

  1. 創(chuàng)建HiveToClickhouse類
public class HiveToClickhouse {
    public static void main(String[] args) {

        //使用 commons-cli 解析參數(shù)
        //1.定義參數(shù)
        Options options = new Options();
        options.addOption(OptionBuilder.withLongOpt("hive_db").withDescription("hive數(shù)據(jù)庫名稱(required)").hasArg(true).isRequired(true).create());
        options.addOption(OptionBuilder.withLongOpt("hive_table").withDescription("hive表名稱(required)").hasArg(true).isRequired(true).create());
        options.addOption(OptionBuilder.withLongOpt("hive_partition").withDescription("hive分區(qū)(required)").hasArg(true).isRequired(true).create());
        options.addOption(OptionBuilder.withLongOpt("ck_url").withDescription("clickhouse的jdbc url(required)").hasArg(true).isRequired(true).create());
        options.addOption(OptionBuilder.withLongOpt("ck_table").withDescription("clickhouse表名稱(required)").hasArg(true).isRequired(true).create());
        options.addOption(OptionBuilder.withLongOpt("batch_size").withDescription("數(shù)據(jù)寫入clickhouse時的批次大小(required)").hasArg(true).isRequired(true).create());

        //2.解析參數(shù)
        CommandLineParser parser = new GnuParser();
        CommandLine cmd = null;
        try {
            cmd = parser.parse(options, args);
        } catch (ParseException e) {
            //若catch到參數(shù)解析異常(即傳入的參數(shù)非法),則打印幫助信息,并return
            System.out.println(e.getMessage());
            HelpFormatter helpFormatter = new HelpFormatter();
            helpFormatter.printHelp("--option argument", options);
            return;
        }

        //3.創(chuàng)建SparkConf
        SparkConf sparkConf = new SparkConf().setAppName("hive2clickhouse");

        //4.創(chuàng)建SparkSession,并啟動Hive支持
        SparkSession sparkSession = SparkSession.builder().enableHiveSupport().config(sparkConf).getOrCreate();

        //5.設(shè)置如下參數(shù),支持使用正則表達(dá)式匹配查詢字段
        sparkSession.sql("set spark.sql.parser.quotedRegexColumnNames=true");

        //6.執(zhí)行如下查詢語句,查詢hive表中除去dt分區(qū)字段外的所有字段
        String sql = "select `(dt)?+.+` from " + cmd.getOptionValue("hive_db") + "." + cmd.getOptionValue("hive_table") + " where dt='" + cmd.getOptionValue("hive_partition") + "'";
        Dataset<Row> hive = sparkSession.sql(sql);

        //7.將數(shù)據(jù)通過jdbc模式寫入clickhouse
        hive.write().mode(SaveMode.Append)
                .format("jdbc")
                .option("url", cmd.getOptionValue("ck_url"))
                .option("dbtable", cmd.getOptionValue("ck_table"))
                .option("driver", "ru.yandex.clickhouse.ClickHouseDriver")
                .option("batchsize", cmd.getOptionValue("batch_size"))
                .save();

        //8.關(guān)閉SparkSession
        sparkSession.close();
    }

}

  1. 上傳hive.xml,hdfs.xml 以及core-site.xml文件到項(xiàng)目的resource目錄下
    數(shù)倉報表數(shù)據(jù)導(dǎo)出——Hive數(shù)據(jù)導(dǎo)出至Clickhouse,大數(shù)據(jù),hive,clickhouse,hadoop
  2. 打包,并上傳hive-to-clickhouse-1.0-SNAPSHOT-jar-with-dependencies.jar到hadoop節(jié)點(diǎn)
  3. 執(zhí)行如下命令測試
spark-submit   \
--class com.atguigu.ad.spark.HiveToClickhouse \
--master yarn   \
ad_hive_to_clickhouse-1.0-SNAPSHOT-jar-with-dependencies.jar   \
--hive_db ad   \
--hive_table dwd_ad_event_inc \
--hive_partition 2023-06-07   \
--ck_url  jdbc:clickhouse://hadoop102:8123/ad_report   \
--ck_table dwd_ad_event_inc   \
--batch_size 1000

PS:

  1. 為保證任務(wù)可提交到y(tǒng)arn運(yùn)行,需要在$SPARK_HOME/conf/spark-env.sh文件中增加如下參數(shù):
export HADOOP_CONF_DIR=/opt/module/hadoop-3.1.3/etc/hadoop/

到了這里,關(guān)于數(shù)倉報表數(shù)據(jù)導(dǎo)出——Hive數(shù)據(jù)導(dǎo)出至Clickhouse的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請點(diǎn)擊違法舉報進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • Hive與ClickHouse的區(qū)別

    Hive是Hadoop生態(tài)系統(tǒng)中事實(shí)上的數(shù)據(jù)倉庫標(biāo)準(zhǔn)。Hive是建立在Hadoop生態(tài)中的數(shù)據(jù)倉庫中間件,其本身并不提供存儲與計(jì)算能力。Hive的存儲引擎使用HDFS,計(jì)算引擎使用MapReduce或Spark。 Hive本質(zhì)上是一個元數(shù)據(jù)管理平臺,通過對存儲于HDFS上的數(shù)據(jù)文件附加元數(shù)據(jù),賦予HDFS上的文件以

    2024年02月11日
    瀏覽(13)
  • 二百二十三、Kettle——從Hive增量導(dǎo)入到ClickHouse(根據(jù)day字段判斷)

    二百二十三、Kettle——從Hive增量導(dǎo)入到ClickHouse(根據(jù)day字段判斷)

    需要用Kettle從Hive的DWS層庫表數(shù)據(jù)增量同步到ClickHouse的ADS層庫表中,不過這次的增量判斷字段是day字段,不像之前的create_time字段 因?yàn)閐ay字段需要轉(zhuǎn)換類型,而?create_time字段字段不需要轉(zhuǎn)換類型,因此兩者的Kettle任務(wù)配置有所不同,也踩了一些坑,因此再寫一篇博客整理一下

    2024年02月20日
    瀏覽(30)
  • 二百二十四、Kettle——曲線實(shí)現(xiàn)從Hive插入更新到ClickHouse(分區(qū)字段是month或year)

    二百二十四、Kettle——曲線實(shí)現(xiàn)從Hive插入更新到ClickHouse(分區(qū)字段是month或year)

    對于以month、year為分區(qū)字段的數(shù)據(jù),不是像day字段分區(qū)那樣每天增量插入更新即可,而是要以部分字段查詢、部分字段更新,但是ClickHouse數(shù)據(jù)庫并不適合更新操作,直接使用Kettle的插入更新控件會導(dǎo)致問題,必須曲線實(shí)現(xiàn)這個功能 對于這類表,每天執(zhí)行任務(wù)時scene_name、dev

    2024年02月21日
    瀏覽(18)
  • clickhouse-數(shù)據(jù)導(dǎo)入導(dǎo)出方案

    clickhouse有多種數(shù)據(jù)的導(dǎo)入導(dǎo)出方式,可以靈活使用,下面對這些方式分別做些介紹,導(dǎo)入導(dǎo)出的寫法與格式和格式設(shè)置有關(guān)。 詳情可查看官網(wǎng),也可以在這里獲取數(shù)據(jù)集 s3的表達(dá)式如下 path — 包含文件路徑的存儲桶 URL。 這在只讀模式下支持以下通配符:*、?、{abc,def} 和

    2024年02月12日
    瀏覽(14)
  • clickhouse 數(shù)據(jù)導(dǎo)入導(dǎo)出操作

    在ClickHouse中處理CSV和TSV數(shù)據(jù) ClickHouse支持從CSV導(dǎo)入和導(dǎo)出數(shù)據(jù)。由于 CSV 文件可以具有不同的格式細(xì)節(jié),包括標(biāo)題行、自定義分隔符和轉(zhuǎn)義符號,因此 ClickHouse 提供了格式和設(shè)置來有效地解決每種情況。 從 CSV 文件導(dǎo)入數(shù)據(jù) 在導(dǎo)入數(shù)據(jù)之前,讓我們創(chuàng)建一個具有相關(guān)結(jié)構(gòu)的表

    2024年01月20日
    瀏覽(28)
  • Clickhouse基礎(chǔ)-導(dǎo)入導(dǎo)出數(shù)據(jù)

    https://blog.csdn.net/qq_39512532/article/details/127577952 注意:如果執(zhí)行語句后面不加FORMAT CSV或FORMAT CSVWithNames,默認(rèn)是t作為分隔符。只有指定FORMAT CSV或FORMAT CSVWithNames后,指定–format_csv_delimiter才生效。

    2024年02月11日
    瀏覽(21)
  • ClickHouse--10--臨時表、視圖、向表中導(dǎo)入導(dǎo)出數(shù)據(jù)

    ClickHouse--10--臨時表、視圖、向表中導(dǎo)入導(dǎo)出數(shù)據(jù)

    提示:文章寫完后,目錄可以自動生成,如何生成可參考右邊的幫助文檔 ClickHouse 支持臨時表,臨時表具備以下特征: 當(dāng)會話結(jié)束或者鏈接中斷時, 臨時表將隨會話一起消失 。 臨時表僅能夠使用 Memory 表引擎,創(chuàng)建臨時表時不需要指定表引擎。 無法為臨時表指定數(shù)據(jù)庫。它

    2024年02月20日
    瀏覽(25)
  • hive數(shù)倉-數(shù)據(jù)的質(zhì)量管理

    hive數(shù)倉-數(shù)據(jù)的質(zhì)量管理

    版本20231116 要理解數(shù)據(jù)的質(zhì)量管理,應(yīng)具備hive數(shù)據(jù)倉庫的相關(guān)知識 數(shù)據(jù)的質(zhì)量管理,表現(xiàn)保障在數(shù)據(jù)的健康性,即滿足消費(fèi)者期望程度,體現(xiàn)在他們對數(shù)據(jù)的使用預(yù)期,只有達(dá)到預(yù)期才能滿足決策層的參考。 大數(shù)據(jù)大而價值密度低,在有效信息數(shù)據(jù)挖掘上,可能會出現(xiàn)錯誤

    2024年01月20日
    瀏覽(18)
  • Hive基礎(chǔ)知識(十一):Hive的數(shù)據(jù)導(dǎo)出方法示例

    Hive基礎(chǔ)知識(十一):Hive的數(shù)據(jù)導(dǎo)出方法示例

    1)將查詢的結(jié)果導(dǎo)出到本地 2)將查詢的結(jié)果格式化導(dǎo)出到本地(加上一個以“,”隔開數(shù)據(jù)的格式) 3)將查詢的結(jié)果導(dǎo)出到 HDFS 上(沒有 local) 基本語法:(hive -f/-e 執(zhí)行語句或者腳本 file) 導(dǎo)出的數(shù)據(jù)中有兩個數(shù)據(jù)源,其中除了主信息之外,還包括記錄主數(shù)據(jù)信息的元數(shù)據(jù)

    2024年01月22日
    瀏覽(21)
  • 使用Python創(chuàng)建faker實(shí)例生成csv大數(shù)據(jù)測試文件并導(dǎo)入Hive數(shù)倉

    使用Python創(chuàng)建faker實(shí)例生成csv大數(shù)據(jù)測試文件并導(dǎo)入Hive數(shù)倉

    這段Python代碼用于生成模擬的個人信息數(shù)據(jù),并將數(shù)據(jù)保存為CSV文件。 導(dǎo)入必要的模塊: csv :用于處理CSV文件的模塊。 random :用于生成隨機(jī)數(shù)。 faker :用于生成模擬數(shù)據(jù)的庫。 定義生成數(shù)據(jù)所需的基本信息: file_base_path :生成的CSV文件的基本路徑。 rows_per_file :每個C

    2024年02月07日
    瀏覽(20)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包