Home | About | Sematext search-lucene.com search-hadoop.com
NEW: Monitor These Apps!
elasticsearch, apache solr, apache hbase, hadoop, redis, casssandra, amazon cloudwatch, mysql, memcached, apache kafka, apache zookeeper, apache storm, ubuntu, centOS, red hat, debian, puppet labs, java, senseiDB
 Search Hadoop and all its subprojects:

Switch to Threaded View
Hive >> mail # user >> Re: How to set default value for a certain field?


Copy link to this message
-
Re: How to set default value for a certain field?
COALESCE how?
COALESCE(VALUE) will return VALUE or null.

I know this query works
select IF(VALUE is NULL,3,VALUE) from testtest;

But I have to do this conditional check on every possible field, every
time I perform queries. I mean, does Hive have something like
CREATE TABLE table (field INT NOT NULL) ?

On Wed, Sep 5, 2012 at 7:52 PM, Philip Tromans
<[EMAIL PROTECTED]> wrote:
> You could do something with the coalesce UDF?
>
> Phil.
>
> On Sep 5, 2012 12:24 AM, "MiaoMiao" <[EMAIL PROTECTED]> wrote:
>>
>> I have a file whose content is:
>> 1,1
>> 2,1
>> 3,2
>> 4,
>> 5,
>> Then I import in into a hive table.
>> create external table testtest (id int,value int) row format delimited
>> fields terminated by ',' stored as textfile location '/wtt/test/def';
>> select * from testtest;
>> 1       1
>> 2       1
>> 3       2
>> 4       NULL
>> 5       NULL
>>
>> I want to set default value for value, but seems hive simply doesn't
>> have this feature, any idea?
>> 1       1
>> 2       1
>> 3       2
>> 4       3
>> 5       3
NEW: Monitor These Apps!
elasticsearch, apache solr, apache hbase, hadoop, redis, casssandra, amazon cloudwatch, mysql, memcached, apache kafka, apache zookeeper, apache storm, ubuntu, centOS, red hat, debian, puppet labs, java, senseiDB