为嵌套的CSV数据创建Hive表

时间:2018-05-07 05:25:52

标签: hadoop hive hql impala

我有以下数据如何为下面的数据创建hive表,上面的数据应该只由3列id,sal,name创建。

1,1000,sdadada
2,2000,sadssaa
3,3000,dasasa,daaaas

1 个答案:

答案 0 :(得分:0)

试一试,它会解决您的问题。

这是我的数据文件包含:

hive> create table table_1(
    > id int,
    > sal int,
    > name string)
    > row format serde 'org.apache.hadoop.hive.serde2.RegexSerDe' 
    > WITH SERDEPROPERTIES ('input.regex'='^(\\d+)\\,([^\\,]*)\\,(\\S+).*');
OK
Time taken: 0.331 seconds
hive> load data local inpath '/home/vivekanand/vivek/stack/test.dat' into table table_1;
Loading data to table default.table_1
OK
Time taken: 0.162 seconds
hive> select * from table_1;
OK
1   1000    sdadada
2   2000    sadssaa
3   3000    dasasa,daaaas
Time taken: 0.067 seconds, Fetched: 3 row(s)

现在您的解决方案就在这里。

class BasePlan 
{
private: 
   int minutesPrice; 
   int SMSPrice;
public:
    setMinutesPrice(int x) { minutesPrice = x; }
    setSMSPrice(int x) { SMSPrice = x; }
    virtual int calculateBill(int minutesTalked, int smsSent) = 0;
};

class Basic : public BasePlan 
{
public:
    Basic()
    {
        setMinutesPrice(10);
        setSMSPrice(5);
    }
    virtual int calculateBill(int minutesTalked, int smsSent) { return minutesTalked * minutesPrice + smsSent * SMSPrice;}
}

class SMSPlan : public BasePlan
{ 
private: 
   int freeSMS;
public: 
   SMSPlan(int minutesPrice, int smsPrice, int freeSMS) 
   {
       setMinutesPrice(minutesPrice);
       setSMSPrice(smsPrice);
       setFreeSMS(freeSMS);
   }

   public setFreeSMS(int free) { this.freeSMS = free; }

   virtual int calculateBill(int minutesTalked, int smsSent) { 
      int billedSMS = (freeSMS > sentSMS) ? 0 : sentSMS - freeSMS;
      return minutesTalked * minutesPrice + billedSMS * SMSPrice;}
}

class SMSGod : public SMSPlan 
{
public: 
   SMSGod() : SMSPlan(10, 1, 150)
   {
   }
}

class Upgraded: public SMSPlan 
{
public: 
   Upgraded() : SMSPlan(5, 3, 25) 
   {
   }
}

class Client
{
public:
    string name;
    string phoneNumber;
    BasePlan* currentPlan;
    int talkedMinutes;
    int sentSMS;
public:
Client(...){...}
void setPlan(BasePlan* plan) { this->currentPlan = setPlan(plan);}
int getBill() { return this->currentPlan->calculateBill(talkedMinutes, sentSMS); }
};