私はJDBC経由でいくつかのSQLテーブルをフェッチしました。私は新しいテーブルを作成して値を挿入する前に別の変換を行う必要があります。ハッシュマップから値を結合する方法は?
章:
(
{:chapter_uuid "b7984dde-50a1-4147-bfee-95bbd068e031", :l1_chapter_text
120876M, :l2_chapter_text nil, :l3_chapter_text nil, :l4_chapter_text nil}
{:chapter_uuid "23df4f27-534b-4cdb-81ed-dbdc8b9b140c", :l1_chapter_text
120880M, :l2_chapter_text 120876M, :l3_chapter_text nil, :l4_chapter_text
121621M}
)
が翻訳:
(
{:translation_id 3258779M, :translation_text 120876M, :translation_language "cs",
:translation_name "Vnější fasáda"}
{:translation_id 3258780M, :translation_text 120876M, :translation_language "en",
:translation_name "Exterior Signage"}
{:translation_id 3258782M, :translation_text 120880M, :translation_language "cs",
:translation_name "Čistá výloha"}
{:translation_id 3258783M, :translation_text 121621M, :translation_language "cs",
:translation_name "Vnější signalizace"}
{:translation_id 3258784M, :translation_text 121621M, :translation_language "en",
:translation_name "Pre-signalization"}
)
これは私が取得するために必要なものです:
私は、これら2つのハッシュマップを得ましたChapters.lx_chapter_text = Tran slation.translation_text - > translation_nameでChapters.lx_chapter_textを入れ替え、挿入:言語の値 - >すべての言語に独自のハッシュマップがあることを確認してください!
(
{:chapter_uuid "b7984dde-50a1-4147-bfee-95bbd068e031", :l1_chapter_text
"Vnější fasáda", :l2_chapter_text nil, :l3_chapter_text nil, :l4_chapter_text nil
:language "cs"}
{:chapter_uuid "b7984dde-50a1-4147-bfee-95bbd068e031", :l1_chapter_text
"Exterior Signage", :l2_chapter_text nil, :l3_chapter_text nil, :l4_chapter_text nil
:language "en"}
{:chapter_uuid "23df4f27-534b-4cdb-81ed-dbdc8b9b140c", :l1_chapter_text
"Čistá výloha", :l2_chapter_text "Vnější fasáda", :l3_chapter_text nil, :l4_chapter_text
"Vnější signalizace" :language "cs"}
{:chapter_uuid "23df4f27-534b-4cdb-81ed-dbdc8b9b140c", :l1_chapter_text
120880M, :l2_chapter_text "Exterior Signage", :l3_chapter_text nil, :l4_chapter_text
"Pre-signalization" :language "en"}
)
これはi'veが得たどのくらいです:
をいますが、これは(悪いネストされた)右ではありません見ることができるよう
あなたがそれを行う方法を教えてもらえます右?ありがとうございました!
(defn test_table []
(for [language (distinct(map #(:translation_language %) translation))]
(for [chapter chapters]
(for [text translation]
(cond
(and (= (:l1_chapter_text chapter) (:translation_text text)) (= (:translation_language text) language))
(assoc chapter :l1_chapter_text (:translation_name text) :language (:translation_language text))
(and (= (:l2_chapter_text chapter) (:translation_text text)) (= (:translation_language text) language))
(assoc chapter :l2_chapter_text (:translation_name text) :language (:translation_language text))
(and (= (:l3_chapter_text chapter) (:translation_text text)) (= (:translation_language text) language))
(assoc chapter :l3_chapter_text (:translation_name text) :language (:translation_language text))
(and (= (:l4_chapter_text chapter) (:translation_text text)) (= (:translation_language text) language))
(assoc chapter :l4_chapter_text (:translation_name text) :language (:translation_language text))))))
(test-table)
->
((({:chapter_uuid "b7984dde-50a1-4147-bfee-95bbd068e031", :l1_chapter_text "Vnější fasáda",
:l2_chapter_text nil, :l3_chapter_text nil, :l4_chapter_text nil, :language "cs"}
nil nil nil nil)
({:chapter_uuid "23df4f27-534b-4cdb-81ed-dbdc8b9b140c", :l1_chapter_text 120880M,
:l2_chapter_text "Vnější fasáda", :l3_chapter_text nil, :l4_chapter_text 121621M, :language "cs"}
nil
{:chapter_uuid "23df4f27-534b-4cdb-81ed-dbdc8b9b140c", :l1_chapter_text "Čistá výloha",
:l2_chapter_text 120876M, :l3_chapter_text nil, :l4_chapter_text 121621M, :language "cs"}
{:chapter_uuid "23df4f27-534b-4cdb-81ed-dbdc8b9b140c", :l1_chapter_text 120880M,
:l2_chapter_text 120876M, :l3_chapter_text nil, :l4_chapter_text "Vnější signalizace", :language "cs"}
nil))
((nil
{:chapter_uuid "b7984dde-50a1-4147-bfee-95bbd068e031", :l1_chapter_text "Exterior Signage",
:l2_chapter_text nil, :l3_chapter_text nil, :l4_chapter_text nil, :language "en"}
nil nil nil)
(nil
{:chapter_uuid "23df4f27-534b-4cdb-81ed-dbdc8b9b140c", :l1_chapter_text 120880M,
:l2_chapter_text "Exterior Signage", :l3_chapter_text nil, :l4_chapter_text 121621M, :language "en"}
nil nil
{:chapter_uuid "23df4f27-534b-4cdb-81ed-dbdc8b9b140c", :l1_chapter_text 120880M,
:l2_chapter_text 120876M, :l3_chapter_text nil, :l4_chapter_text "Pre-signalization", :language "en"})))
どのように値を結合しますか?何に応じて?あなたが{:a 1}と{:a 2}を持っていれば、「a」は何になるでしょうか? –
申し訳ありませんが、私はあなたの質問を理解していません。 l * _chapter_textを割り当てることができます:translation_text すべての言語で一度... – Akiz
これはdb/sqlにすぐに参加できませんか? – cfrick