Q: Split a string based on spacein Hive This is the format of my CSV file:
Chevrolet C10,13.0,8,350.0,145.0,4055,12.0,76,US
Ford F108,13.0,8,302.0,130.0,3870,15.0,76,US
Dodge D100,13.0,8,318.0,150.0,3755,14.0,76,US
Honda Accord CVCC,31.5,4,98.00,68.00,2045,18.5,77,Japan
Buick Opel Isuzu Deluxe,30.0,4,111.0,80.00,2155,14.8,77,US
Renault 5 GTL,36.0,4,79.00,58.00,1825,18.6,77,Europe
Plymouth Arrow GS,25.5,4,122.0,96.00,2300,15.5,77,US

I want to split the first field like, 
Chevrolet C10 should be Chevrolet
Ford F108 should be Ford
Honda Accord CVCC should be Honda etc and then I will use the car name for further processing.

A: Solution in Pig  
Code :
read = LOAD 'test.data' USING PigStorage(',') AS (name:chararray, val1:long, val2:long, val3:long, val4:long, val5:long, val6:long, country:chararray);
sub_data = FOREACH read GENERATE SUBSTRING(name,0,(INDEXOF(name, ' ',0)))  AS (subname:chararray);
DUMP sub_data;

Output :
(Chevrolet)
(Ford)
(Dodge)
(Honda)
(Buick)
(Renault)
(Plymouth)


A: select
  case when MODEL like 'US % %' or MODEL like 'Europe % %'
        then regexp_extract(MODEL, '^([^ ]* [^ ]*) ', 1)
        when MODEL like '% %'
        then regexp_extract(MODEL, '^([^ ]*) ', 1)
        else MODEL
  end as BRAND
from WHATEVER



*

*Chevrolet C10 => Chevrolet

*US Honda Accord => US Honda

*Zorglub => Zorglub


A: Use the below UDF - 
substring_index(string A, string delim, int count)

Reference

A: Create a table with the schema which you want for your table.
CREATE TABLE carinfo (carname STRING, val1 DOUBLE, val2 INT, val3 DOUBLE, val4 DOUBLE, val5 INT, val6 DOUBLE, val7 INT, country STRING) 
ROW FORMAT DELIMITED 
FIELDS TERMINATED BY ',';

load the data into the above table
LOAD DATA LOCAL INPATH '/hivesamples/splitstr.txt' OVERWRITE INTO TABLE carinfo;

Use CTAS to split the carname and get the brand name. This new table will have the same schema which you defined earlier.
CREATE TABLE modified_carinfo 
AS 
SELECT split(carname, ' ')[0] as carname, val1, val2, val3, val4, val5 ,val6, val7, country 
FROM carinfo;

