hive和hbase的一些数据导入导出操作

您所在的位置:网站首页 hbase的理解 hive和hbase的一些数据导入导出操作

hive和hbase的一些数据导入导出操作

#hive和hbase的一些数据导入导出操作| 来源: 网络整理| 查看: 265

一、hive 数据导入导出

如果可以在新旧集群之间直接通信,最方便的方式是使用分布式复制,不考虑对业务的影响,但分为相同版本和不同版本直接复制。以下是在相同版本之间进行复制的方法。

[En]

If you can communicate directly between new and old clusters, the most convenient way is to use distributed copy without considering the impact on business, but it is divided into the same version and different versions to copy directly. The following is the way to copy between the same version.

hadoop distcp -D ipc.client.fallback-to-simple-auth-allowed=true hdfs://10.1.42.51:8020/user/hive/warehouse/default/guangxi_live.db hdfs:// 10.1.42.60:8020/user/hive/warehouse/default

简单导入和导出

export table department to 'hdfs_exports_location/department'; import from 'hdfs_exports_location/department';

导出分区并且导入

export table employee partition (emp_country="in", emp_state="ka") to 'hdfs_exports_location/employee'; import from 'hdfs_exports_location/employee';

导出表并将其导入到分区表分区

[En]

Export the table and import it to the partition table partition

export table employee to 'hdfs_exports_location/employee'; import table employee partition (emp_country="us", emp_state="tn") from 'hdfs_exports_location/employee';

在工作中,由于数据表数据量超级大,无法全量导出,可以通过kettle去连接hive或者impala,用sql语句查出目标数据,然后导出到文本文件(CSV表)

为了让数据导入分区表中,我们需要设定一些参数,让数据库支持动态分区,在hive终端输入以下命令:

set hive.exec.dynamic.partition=true; set hive.exec.dynamic.partition.mode=nonstrict; set hive.exec.max.dynamic.partitions.pernode =1000000;

另外,在hive中创建表的时候,需要创建一张已,默认格式TEXTFILE的中间表,这样才能把csv格式文件导入表中,其他格式的都不支持。

其中TEXTFILE为默认格式,建表时不指定默认为这个格式,导入数据时会直接把数据文件拷贝到hdfs上不进行处理; SEQUENCEFILE,RCFILE,ORCFILE,PARQUET格式的表不能直接从本地文件导入数据,数据要先导入到textfile格式的表中, 然后再从表中用insert导入SequenceFile,RCFile,ORCFile,PARQUET各自表中;或者用复制表结构及数据的方式(create table as select * from table )。一言以蔽之:如果为textfile的文件格式,直接load就OK,不需要走MapReduce;如果是其他的类型就需要走MapReduce了,因为其他的类型都涉及到了文件的压缩,这需要借助MapReduce的压缩方式来实现。

CREATE TABLE guangxi_test2( stbid string, areacode string, starttime string, endtime string, day string, content string) ROW FORMAT DELIMITED FIELDS TERMINATED BY ',';

把数据导入hdfs—insert进临时表—查询结果:

load data local inpath '/opt/query.csv' into table test ; insert into table formmart partition (day,content) select * from test; select count(*) from guangxi_test; 二、hbase

hbase org.apache.hadoop.hbase.mapreduce.Export tsdb-uid /copy/tsdb-uid例如:从dt_gpsdata表中导出2018-01-01至2018-02-01的数据(中间记得加上version)

hbase org.apache.hadoop.hbase.mapreduce.Export dt_gpsdata /copy/dt_gpsdata 1 1514736000000 1517414400000

hbase org.apache.hadoop.hbase.mapreduce.Import tsdb-uid /copy/tsdb-uid

按时间段查询hbase

scan 'test',{COLUMNS=>'info',TIMERANGE=>[1667463331656,1667463389253]}

模糊查询,类似like

scan 'guangxi_live_test',{FILTER=>"RowFilter(=,'substring:02')"}

substring筛选时使用=来筛选,否则会出错;binary筛选时可以用=、>=、

Original: https://blog.csdn.net/quantam/article/details/127966649Author: quantamTitle: hive和hbase的一些数据导入导出操作

相关阅读 Title: Sqlite sql查询数据数据类型转换 一、SQL数据类型转换代码 SELECT CAST('3.02' as decimal) -- they aren't real decimals in sqlite, though. beware floats. 二、sqlite数据类型转换参考

Affinity of type-name

Conversion Processing 转换处理

NONE

没有

Casting a value to a type-name with no affinity causes the value to be converted into a BLOB. Casting to a BLOB consists of first casting the value to TEXT in the encoding of the database connection, then interpreting the resulting byte sequence as a BLOB instead of as TEXT.

将一个值转换为一个 类型名称 没有关联将导致值转换为BLOB。强制转换为BLOB包括首先将值强制转换为 编码 然后将结果字节序列解释为BLOB而不是文本。

TEXT

文本

To cast a BLOB value to TEXT, the sequence of bytes that make up the BLOB is interpreted as text encoded using the database encoding.

Casting an INTEGER or REAL value into TEXT renders the value as if via sqlite3_snprintf() except that the resulting TEXT uses the encoding of the database connection.

若要将BLOB值强制转换为文本,组成BLOB的字节序列将被解释为使用数据库编码的文本编码。将整数值或实数值强制转换为文本将使该值如同通过 sqlite3\u snprintf() 除了结果文本使用 编码 数据库连接的名称。

REAL

When casting a BLOB value to a REAL, the value is first converted to TEXT.

When casting a TEXT value to REAL, the longest possible prefix of the value that can be interpreted as a real number is extracted from the TEXT value and the remainder ignored. Any leading spaces in the TEXT value are ignored when converging from TEXT to REAL. If there is no prefix that can be interpreted as a real number, the result of the conversion is 0.0.

将BLOB值强制转换为实数时,首先将该值转换为文本。

将文本值强制转换为实数时,将从文本值中提取可解释为实数的值的最长前缀,并忽略其余部分。从文本聚合到实数时,将忽略文本值中的任何前导空格。如果没有可以解释为实数的前缀,则转换的结果为0.0。

INTEGER

整数

When casting a BLOB value to INTEGER, the value is first converted to TEXT.

When casting a TEXT value to INTEGER, the longest possible prefix of the value that can be interpreted as an integer number is extracted from the TEXT value and the remainder ignored. Any leading spaces in the TEXT value when converting from TEXT to INTEGER are ignored. If there is no prefix that can be interpreted as an integer number, the result of the conversion is 0. If the prefix integer is greater than +9223372036854775807 then the result of the cast is exactly +9223372036854775807. Similarly, if the prefix integer is less than -9223372036854775808 then the result of the cast is exactly -9223372036854775808.

When casting to INTEGER, if the text looks like a floating point value with an exponent, the exponent will be ignored because it is no part of the integer prefix. For example, “(CAST ‘123e+5’ AS INTEGER)” results in 123, not in 12300000.

The CAST operator understands decimal integers only — conversion of hexadecimal integers stops at the “x” in the “0x” prefix of the hexadecimal integer string and thus result of the CAST is always zero.

A cast of a REAL value into an INTEGER results in the integer between the REAL value and zero that is closest to the REAL value. If a REAL is greater than the greatest possible signed integer (+9223372036854775807) then the result is the greatest possible signed integer and if the REAL is less than the least possible signed integer (-9223372036854775808) then the result is the least possible signed integer.

Prior to SQLite version 3.8.2 (2013-12-06), casting a REAL value greater than +9223372036854775807.0 into an integer resulted in the most negative integer, -9223372036854775808. This behavior was meant to emulate the behavior of x86/x64 hardware when doing the equivalent cast.

将BLOB值强制转换为整数时,首先将该值转换为文本。

将文本值强制转换为整数时,将从文本值中提取可解释为整数的值的最长前缀,并忽略余数。从文本转换为整数时,文本值中的任何前导空格都将被忽略。如果没有可解释为整数的前缀,则转换结果为0。如果前缀整数大于+9223372036854775807,则强制转换的结果正好是+9223372036854775807。类似地,如果前缀整数小于-9223372036854775808,则强制转换的结果正好是-9223372036854775808。

强制转换为整数时,如果文本看起来像带指数的浮点值,则指数将被忽略,因为它不是整数前缀的一部分。例如,”(将’123e+5’转换为整数)”结果是123,而不是12300000。

CAST运算符只理解十进制整数-的转换 十六进制整数 在十六进制整数字符串的”0x”前缀中的”x”处停止,因此强制转换的结果始终为零。

将实值转换为整数将导致实值和零之间的整数最接近实值。如果实数大于最大可能有符号整数(+9223372036854775807),则结果为最大可能有符号整数,如果实数小于最小可能有符号整数(-9223372036854775808),则结果为最小可能有符号整数。

在SQLite版本3.8.2(2013-12-06)之前,将大于+9223372036854775807.0的实值强制转换为整数会导致最负的整数-9223372036854775808。此行为旨在模拟执行等效转换时x86/x64硬件的行为。

NUMERIC

数字

Casting a TEXT or BLOB value into NUMERIC yields either an INTEGER or a REAL result. If the input text looks like an integer (there is no decimal point nor exponent) and the value is small enough to fit in a 64-bit signed integer, then the result will be INTEGER. Input text that looks like floating point (there is a decimal point and/or an exponent) and the text describes a value that can be losslessly converted back and forth between IEEE 754 64-bit float and a 51-bit signed integer, then the result is INTEGER. (In the previous sentence, a 51-bit integer is specified since that is one bit less than the length of the mantissa of an IEEE 754 64-bit float and thus provides a 1-bit of margin for the text-to-float conversion operation.) Any text input that describes a value outside the range of a 64-bit signed integer yields a REAL result.

Casting a REAL or INTEGER value to NUMERIC is a no-op, even if a real value could be losslessly converted to an integer.

将文本或BLOB值转换为数字将产生整数或实数结果。如果输入文本看起来像一个整数(没有小数点或指数),并且该值足够小,可以容纳64位有符号整数,那么结果将是整数。输入看起来像浮点的文本(有一个小数点和/或一个指数),该文本描述了一个值,该值可以在IEEE 754 64位浮点和51位有符号整数之间无损地来回转换,然后结果是整数(在前面的句子中,指定了一个51位整数,因为它比ieee754 64位浮点的尾数长度少一位,因此为文本到浮点的转换操作提供了1位的余量。)任何描述64位有符号整数范围之外的值的文本输入都会产生一个实际结果。

将实数或整数值转换为数值是不可操作的,即使实数可以无损地转换为整数。

decimal

十进制

hive和hbase的一些数据导入导出操作

Original: https://blog.csdn.net/qh0526wy/article/details/116378789Author: qh0526wyTitle: Sqlite sql查询数据数据类型转换

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/380742/

转载文章受原作者版权保护。转载请注明原作者出处!



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3