hadoop - 在Hive转换中传递表头

标签 hadoop header hive transform

我在Hive中创建查询以执行R脚本。我正在使用转换函数来传递表。但是,当我收到R中的表时,它没有标题。我知道我可以创建一个变量,并要求用户手动插入 header ,但我不想这样做。
我想自动执行某项操作,正在考虑两种选择:

1)在使用转换功能时想出一种传递带有标题的表的方法

2)将 header 保存在变量中,然后通过转换传递它(我已经以不同的方式尝试过它,但没有传递查询结果,而是传递了查询字符串-如下所示)

这是我所拥有的:

--Name of the origin table
set source_table = categ_table_small;
--Number of clusters
set k = "5";
--Distance to be used in the model
set distance = "euclidean";
--Folder where the results of the model will be saved
set dir_tar = "/output_r";
--Name of the model used in the naming of the files
set model_name ="testeclara_small";
--Samples: integer, number of samples to be drawn from the dataset.
set n_samples = "10";
--sampsize: integer, number of observations in each sample. This formula is suggested by the package. sampsize<-min(nrow(x), 40 + 2 * k)
set sampsize = "50";

--Creating a matrix which will store the sample number and the group of each sample according to the algorithm
CREATE TABLE IF NOT EXISTS  medoids_result AS SELECT * FROM categ_table_small;

--In the normal situation you don't have the output label, it means you just have 'x' and do not have 'y', so you need to add one extra column to receive
--the group of each observation
--ALTER TABLE medoids_result ADD COLUMNS (medoid INT);

set result_matrix = medoids_result;
set headerMatrix = show columns in categ_table_small;

--Trainning query
SET mapreduce.job.name = K medoids Clara- ${hiveconf:source_table};
SET mapreduce.job.reduces=1; 

INSERT OVERWRITE TABLE ${hiveconf:result_matrix} 
SELECT TRANSFORM ($begin(cols="${hiveconf:source_table}" delimiter= "," excludes="y")$column$end)
USING '/usr/bin/Rscript_10gb /programs_r/du8_dev_1.R ${hiveconf:k}${hiveconf:distance}${hiveconf:dir_tar}${hiveconf:model_name}${hiveconf:n_samples}${hiveconf:sampsize}${hiveconf:headerMatrix}'
AS 
(
$begin(table='${hiveconf:result_matrix}') $column$end
)
FROM
(SELECT *
FROM ${hiveconf:source_table}
DISTRIBUTE BY '1'
)t1;

最佳答案

您可以添加此行

hive -e 'set hive.cli.print.header=true;select * from tablename;'

表名是指您的表名

如果要默认为每个表工作,则需要使用以下命令更新$ HOME / .hiverc文件:
hive> set hive.cli.print.header=true;
在第一行。

关于hadoop - 在Hive转换中传递表头,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40400657/

相关文章:

hadoop - 在 Hadoop 中将多个文件合并为一个文件

sorting - 我可以为reducer中的记录分配序列号吗

hadoop - 如何加载hive表中的多行列数据?具有换行符的列

c++ - 将 header 包含到 OpenCL .cl 文件

regex - Hive 的 RegexSerDe 没有给出正确的输出

hadoop - 合并 Hive 表上的重复记录

java - 来自 Oozie Java 工作的电子邮件

c# - 将文件上传到 Hbase HDInsight

cuda - CUDA中实现float4运算的头文件是哪个?

C++ Wininet 自定义 http header