我在Hive中创建一个查询来执行R脚本。我正在使用转换函数来传递表。但是,当我收到R中的表时,它没有标题。我知道我可以创建一个变量并要求用户手动插入标题,但我不想这样做。 我想自动做一些事情,我正在考虑两种选择:
1)找出一种在使用转换函数
时传递包含头的表的方法2)将标题保存在变量中并将其传递给变换(我已经尝试过不同的方式,但不是传递查询结果而是传递查询字符串 - 如下所示)
这就是我所拥有的:
--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;
答案 0 :(得分:0)
您可以添加此行
hive -e 'set hive.cli.print.header=true;select * from tablename;'
表格名称指的是表格名称
如果您希望默认为每个表工作,那么您需要使用
更新$ HOME / .hiverc文件 hive> set hive.cli.print.header=true;
在第一行。