0
Rスクリプトを実行するためにHiveでクエリを作成しています。私はテーブルを渡すために変換関数を使用しています。しかし、私がRでテーブルを受け取ったとき、それはヘッダーなしで来る。私は、変数を作成し、手動でヘッダを挿入するように頼むことができますが、私はそれをしたくありません。 は私が自動的に何かをしたい、私は2つのオプションを検討しています:)Hive変換でテーブルヘッダーを渡す
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;
私はすでに試してみましたが動作しません:/ –