使用查找表将数据插入Hive表

时间:2018-05-29 21:38:52

标签: hadoop hive hive-query

有人可以在这种情况下帮助我吗?

如何通过查找其他Hive表中的值将数据插入Hive表?

我的input_source表如下所示:

A and A16 is "Excellet"
B and D44 is "Average"
A and L90 is "Good"
B and Y78 is "Fair"

我有上面每种类型的详细说明。 例如:

date    key   desc
29-May  1     Excellent
29-May  2     Average
29-May  3     Not bad
29-may  4     Good
29-May  5     Fine
29-may  6     Fair

依旧......

在我将数据插入结果表的过程中,我需要读取行并键入并在最终表中插入说明,如下所示:

using System;
using System.Net.Sockets;
using System.Net;
using System.IO;
using System.Threading;
using System.Text;

namespace RFLY_CMD
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Starting...");
            TcpListener server = new TcpListener(IPAddress.Parse("0.0.0.0"), 7362);
            server.Start();
            Console.WriteLine("Listening...");
            Console.WriteLine();
            while (true)
            {
                ClientWorking cw = new ClientWorking(server.AcceptTcpClient());
                new Thread(new ThreadStart(cw.DoSomethingWithClient)).Start();
            }
        }
    }

    class ClientWorking
    {
        private Stream ClientStream;
        private TcpClient Client;

        public ClientWorking(TcpClient Client)
        {
            this.Client = Client;
            ClientStream = Client.GetStream();
        }

        public void DoSomethingWithClient()
        {
            StreamWriter sw = new StreamWriter(ClientStream);
            StreamReader sr = new StreamReader(sw.BaseStream);
            string data;
            bool cap = false;
            string full_string = null;
            try
            {
                while (true)
                {
                    data = sr.ReadLine();
                    if (!string.IsNullOrEmpty(data) && !string.IsNullOrWhiteSpace(data) || cap)
                    {
                        if(data == "... start")
                        {
                            cap = true;
                            Console.WriteLine("---START FOUND!!!---");
                        }

                        if (cap)
                        {
                            Console.WriteLine(data);
                            full_string += data + "--:BREAK:--";
                        }

                        if (data == "... end")
                        {
                            cap = false;

                            Console.WriteLine("---END FOUND!!!---");
                            Console.WriteLine();
                            Console.WriteLine("-------------FULL STRING-------------");
                            Console.WriteLine(full_string);
                        }
                    }
                }
            }
            finally
            {
                Console.Write("Ending...");
                sw.Close();
            }
        }
    }
}

请你建议实现这个目标吗?

1 个答案:

答案 0 :(得分:0)

使用加入。这是可能需要的。

insert overwrite table target_table
select date,key,descrip
from 
(
select a.date,a.key,a.lines, a.type,b.descrip from 
input_source a 
join 
description_table b 
on a.lines = b.lines and a.type = b.type
)
t;

请告诉我这是否有帮助!