028-86922220

建站动态

根据您的个性需求进行定制 先人一步 抢占小程序红利时代

Hive动态分区表的作用是什么

本篇内容主要讲解“Hive动态分区表的作用是什么”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“Hive动态分区表的作用是什么”吧!

成都创新互联公司2013年至今,是专业互联网技术服务公司,拥有项目做网站、成都网站建设网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元玉州做网站,已为上家服务,为玉州各地企业和个人服务,联系电话:18982081108

1.对于分区数量很多的分区表,可以使用动态分区让hive帮你自动创建所需的分区表:

Hive动态分区表的作用是什么

以上两个参数分别表示:

如果使用非严格模式,则插入的时候需要指定一个额外的数据列来表示虚拟分区列的值,如:

set hive.exec.dynamic.partition=true;
set hive.exec.dynamic.partition.mode=nonstrict;
create table test1(a int);
create table test2(a int) partitioned by (parid int);
insert into table test2 partition (parid) select *,par_id from test1;

否则会出现类似如下错误:

Error: Error while processing statement: FAILED: SemanticException [Error 10044]: Line 1:18 Cannot insert into target table because column number/types are different 'parid': Table insclause-0 has 2 columns, but query has 1 columns. (state=42000,code=10044)

最后执行命令:hdfs dfs -ls /user/hive/warehouse/test2,便可查看到hdfs中自动创建好了分区文件夹。

注意:

2.上面简单介绍了hive动态分区表的使用,接下来的一个小demo是使用Java连接hive。hive不等同于关系型数据库,本身不存储数据也不提供对数据的操作方法,如果要使用jdbc连接hive,必须启动了hive-server,默认连接端口是10000。代码如下所示:

private static void hive() throws Exception {
//		Class.forName("org.apache.hadoop.hive.jdbc.HiveDriver");
		Class.forName("org.apache.hive.jdbc.HiveDriver");
		Connection con = DriverManager.getConnection("jdbc:hive2://127.0.0.1:10000/default", "hive", "");
		PreparedStatement ps = con.prepareStatement("insert into table test select ? from test2 limit 1");
		ps.setString(1, new Timestamp(new java.util.Date().getTime()).toString());
		ps.executeUpdate();
		ps.setString(1, "2011-11-11 11:11:11");
		ps.executeUpdate();
//		stmt.execute("set hive.support.concurrency=true");
		Statement stmt = con.createStatement();
		ResultSet rs = stmt.executeQuery("select * from test");
		int columnSize = rs.getMetaData().getColumnCount();
		while (rs.next()) {
			for (int i = 1; i <= columnSize; i++)
				System.out.print(rs.getString(i) + ",");
			System.out.println();
		}
		rs.close();
		stmt.close();
		con.close();
	}

注意:

Hiveserver1:Hive动态分区表的作用是什么

Hiveserver2:Hive动态分区表的作用是什么Hive动态分区表的作用是什么

到此,相信大家对“Hive动态分区表的作用是什么”有了更深的了解,不妨来实际操作一番吧!这里是创新互联网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!


标题名称:Hive动态分区表的作用是什么
当前路径:http://www.tsicrk.com/article/gdhshp.html

其他资讯

让你的专属顾问为你服务

1.9339s