7月20号day12总结

今天学习过程和小结

先进行了复习,主要

1hive导入数据的方式有

  本地导入  load data [local] inpath 'hdfs-dir' into table tablename;

    sqoop

2hive数据类型有  hive.apache.org

      简单类型  

         数字类型:int double  bigint smallint ...

         字符串类型  string  char(20) varchar(20)

          日期类型  date timestamp

      复杂类型-->数组、集合、结构体

扫描二维码关注公众号,回复: 2271526 查看本文章

3,使用Hive创建表emp   

    create table emp(fieldname type) 行分割符

4,将本地数据导入到hiveemp表中

  load data [local] inpath 'hdfs-dir' into table tablename;

5,检测sqoop是否与mysql连接成功

   sqoop list-databases --connect jdbc:mysql://127.0.0.1:3306/ --username root --password 123456

6,描述hive的体系架构

   1)用户接口主要有三个:CLIClient WUI。其中最常用的是CLICli启动的时候,会同时启动一个Hive副本。ClientHive的客户端,用户连接至Hive Server。在启动 Client模式的时候,需要指出Hive Server所在节点,并且在该节点启动Hive ServerWUI是通过浏览器访问Hive

    2Hive将元数据存储在数据库中,如mysqlderbyHive中的元数据包括表的名字,表的列和分区及其属性,表的属性(是否为外部表等),表的数据所在目录等。

    3)解释器、编译器、优化器完成HQL查询语句从词法分析、语法分析、编译、优化以及查询计划的生成。生成的查询计划存储在HDFS中,并在随后有MapReduce调用执行。

    4Hive的数据存储在HDFS中,大部分的查询、计算由MapReduce完成(包含*的查询,比如select * from tbl不会生成MapRedcue任务)。

7java中如何从文件emp.txt读取数据,使用BufferedReader,代码实现

   readLine()

                                      BufferedInputStream

      流: 字符流、字节流

           输入流 、输出流

           节点流、 转换流

   BufferedReader breader=new BufferedReader(new InputStreamReader(new FileInputStream("filename")));

   breader.readLine();

 FileInputStream

  File

8sqoop导入mysql数据到hdfs代码

    

   import -->导入  

   export-->导出

   --connect jdbc:mysql://ip:3306/dbname

   --username root

   --password root

  [ --columns 'ename,empno...']

   --table tablename

   --target-dir 'hdfs目录'

练习了sqoopd的命令。

下午学了用hive连接JDBC进行数据库的操作。

package com.neuedu.utils;

import java.sql.*;

public class HiveJDBCUtils {

    public static String driver="org.apache.hive.jdbc.HiveDriver";
    private static String url="jdbc:hive2://192.168.122.141:10000/default";

    static{
        try{
            Class.forName(driver);
        }catch(ClassNotFoundException e){
            e.printStackTrace();
        }
    }

    public static Connection getConnection() throws SQLException{
        return DriverManager.getConnection(url,"root","123456");
    }

    public static void close(Connection connection,Statement statement) throws SQLException{
        if (connection!=null){
            connection.close();
        }
        if (statement!=null){
            statement.close();
        }
    }

    public static void close(Connection connection, Statement statement, ResultSet resultSet) throws SQLException{
        if (connection!=null){
            connection.close();
        }
        if (statement!=null){
            statement.close();
        }
        if (resultSet!=null){
            resultSet.close();
        }
    }
}

搭建了springboot集成hive

 

遇到问题汇总

  1. 多加练习SQL语句和sqoop语句

2.Hive连接JDBC还不是熟悉。Springboot的搭建也要多多练习。

学习技能思维导图

猜你喜欢

转载自www.cnblogs.com/kangy123/p/9343194.html
今日推荐