You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@hive.apache.org by Anup Tiwari <an...@gmail.com> on 2019/08/12 19:41:01 UTC

Less than(<) & Greater than(>) condition failing on string column but min/max is working

Hi All,

I have a use case where i wanted to store multiple columns into a single
map data type column but while doing so i came across a use case where i
have mainly 2 type of column bigint and string so i stored them in a map
column defined as <string,string> and then i queried the key which hold
integer values in a map column.

Case 1 :- when i am applying > , < conditional operator then returning
output is correct.
Case 2 :- Taking min/max on integer column and then it is giving me
incorrect output.

Now i understood that it is due datatype of map column which is "string"
but just a question, why min/max is working on string and <,> conditions
failing ?

Please note that the column which i am querying, will always contain int
value so let me know if you have any suggestions.

Combining and storing value in map datatype is necessary because each row
can have different-different number of metadata depending upon event name.

Please find table structure below :-

CREATE TABLE `anup.test_map`(
  `SID` string,
  `eventName` string,
  `timestamp` timestamp,
  `merge` map<string,string>)
STORED AS PARQUET;

Regards,
Anup Tiwari

Re: Less than(<) & Greater than(>) condition failing on string column but min/max is working

Posted by Anup Tiwari <an...@gmail.com>.
Hi Team,

Can someone look into this and help me to understand the behavior and
suggest other way around?

On Thu, 15 Aug 2019 08:02 Anup Tiwari, <an...@gmail.com> wrote:

> Hi Team,
>
> Can someone help me with this?
>
> On Tue, 13 Aug 2019 01:11 Anup Tiwari, <an...@gmail.com> wrote:
>
>> Hi All,
>>
>> I have a use case where i wanted to store multiple columns into a single
>> map data type column but while doing so i came across a use case where i
>> have mainly 2 type of column bigint and string so i stored them in a map
>> column defined as <string,string> and then i queried the key which hold
>> integer values in a map column.
>>
>> Case 1 :- when i am applying > , < conditional operator then returning
>> output is correct.
>> Case 2 :- Taking min/max on integer column and then it is giving me
>> incorrect output.
>>
>> Now i understood that it is due datatype of map column which is "string"
>> but just a question, why min/max is working on string and <,> conditions
>> failing ?
>>
>> Please note that the column which i am querying, will always contain int
>> value so let me know if you have any suggestions.
>>
>> Combining and storing value in map datatype is necessary because each row
>> can have different-different number of metadata depending upon event name.
>>
>> Please find table structure below :-
>>
>> CREATE TABLE `anup.test_map`(
>>   `SID` string,
>>   `eventName` string,
>>   `timestamp` timestamp,
>>   `merge` map<string,string>)
>> STORED AS PARQUET;
>>
>> Regards,
>> Anup Tiwari
>>
>

Re: Less than(<) & Greater than(>) condition failing on string column but min/max is working

Posted by Anup Tiwari <an...@gmail.com>.
Hi Team,

Can someone help me with this?

On Tue, 13 Aug 2019 01:11 Anup Tiwari, <an...@gmail.com> wrote:

> Hi All,
>
> I have a use case where i wanted to store multiple columns into a single
> map data type column but while doing so i came across a use case where i
> have mainly 2 type of column bigint and string so i stored them in a map
> column defined as <string,string> and then i queried the key which hold
> integer values in a map column.
>
> Case 1 :- when i am applying > , < conditional operator then returning
> output is correct.
> Case 2 :- Taking min/max on integer column and then it is giving me
> incorrect output.
>
> Now i understood that it is due datatype of map column which is "string"
> but just a question, why min/max is working on string and <,> conditions
> failing ?
>
> Please note that the column which i am querying, will always contain int
> value so let me know if you have any suggestions.
>
> Combining and storing value in map datatype is necessary because each row
> can have different-different number of metadata depending upon event name.
>
> Please find table structure below :-
>
> CREATE TABLE `anup.test_map`(
>   `SID` string,
>   `eventName` string,
>   `timestamp` timestamp,
>   `merge` map<string,string>)
> STORED AS PARQUET;
>
> Regards,
> Anup Tiwari
>

Re: Less than(<) & Greater than(>) condition failing on string column but min/max is working

Posted by Jörn Franke <jo...@gmail.com>.
You could just move the ints outside the Map.
Alternatively you can convert the String to Int : cast (strcolumn to int)
See:https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF#LanguageManualUDF-TypeConversionFunctions

> Am 12.08.2019 um 21:41 schrieb Anup Tiwari <an...@gmail.com>:
> 
> Hi All,
> 
> I have a use case where i wanted to store multiple columns into a single map data type column but while doing so i came across a use case where i have mainly 2 type of column bigint and string so i stored them in a map column defined as <string,string> and then i queried the key which hold integer values in a map column.
> 
> Case 1 :- when i am applying > , < conditional operator then returning output is correct.
> Case 2 :- Taking min/max on integer column and then it is giving me incorrect output.
> 
> Now i understood that it is due datatype of map column which is "string" but just a question, why min/max is working on string and <,> conditions failing ?
> 
> Please note that the column which i am querying, will always contain int value so let me know if you have any suggestions. 
> 
> Combining and storing value in map datatype is necessary because each row can have different-different number of metadata depending upon event name.
> 
> Please find table structure below :-
> 
> CREATE TABLE `anup.test_map`(
>   `SID` string, 
>   `eventName` string, 
>   `timestamp` timestamp, 
>   `merge` map<string,string>)
> STORED AS PARQUET;
> 
> Regards,
> Anup Tiwari