Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

hive and presto,Integer division truncation problem

Tags:

sql

hive

presto

Why does the splitting of the two bigint type data in hive does not occur for integer division truncation, but occurs in presto

like image 262
loonglee Avatar asked Oct 31 '18 03:10

loonglee


2 Answers

Presto mechanics:

  1. Load data from various datasources via connectors into Presto JVM. (Hive connector, Mysql connector, etc. see this)

  2. Processing(scalar functions or aggregate functions) the data using Java code.

  3. Output the results from JVM (or disk if enable spill).

In Java 1/2=0 therefore Presto will be the same. In Hive, I think because of UDF like overrive operator: LanguageManual+UDF

To avoid truncation, just need to 'Thinking in Java':

int a = 1
int b = 2
c = 1.0*a/b

In Presto SQL

-- result: 0.3333333333333333
select cast(1 as double) / 3 from table_name 

see: Migrating From Hive

like image 151
Archon Avatar answered Sep 25 '22 04:09

Archon


It also can be done this way. select 1.0 * 1 / 3 from table_name Instead of casting the value

like image 43
Ravi Teja Avatar answered Sep 24 '22 04:09

Ravi Teja