栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

Spark SQL 连接 hive

Spark SQL 连接 hive

添加依赖:

	
        
            junit
            junit
            4.12
            test
        
        
            org.apache.spark
            spark-core_2.11
            ${spark.core.version}
        
        
            org.apache.spark
            spark-sql_2.11
            ${spark.core.version}
        
        
            mysql
            mysql-connector-java
            5.1.38
        
        
            org.apache.spark
            spark-hive_2.11
            2.3.0
        
        
        
            log4j
            log4j
            1.2.16
        
    

Test 测试:

import org.apache.spark.sql.Dataset;
import org.apache.spark.sql.Row;
import org.apache.spark.sql.SparkSession;

public class Test {
    public static void main(String[] args) {
        SparkSession spark = SparkSession
                .builder()
                .master("local[*]")
                .appName("Java Spark Hive Example")
                .config("hive.metastore.uris", "thrift://192.168.0.4:9083")
                .config("spark.sql.warehouse.dir", "hdfs://192.168.0.2:9000/user/hive/warehouse")
                .enableHiveSupport()
                .getOrCreate();
        Long start = System.currentTimeMillis();
        Dataset sql = spark.sql("select * from test.fs142 union all select * from test.fs142");
        sql.show();
    }
}

日志打印:新建 log4j.properties 文件

#
#   Licensed to the Apache Software Foundation (ASF) under one or more
#   contributor license agreements.  See the NOTICE file distributed with
#   this work for additional information regarding copyright ownership.
#   The ASF licenses this file to You under the Apache License, Version 2.0
#   (the "License"); you may not use this file except in compliance with
#   the License.  You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR ConDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.
#
# log4j configuration used during build and unit tests

log4j.rootLogger=ERROR,stdout
log4j.threshold=ALL
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ISO8601} %-5p %c{2} (%F:%M(%L)) - %m%n
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/279837.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号