loonglee
loonglee

Reputation: 103

hive and presto,Integer division truncation problem

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

Upvotes: 10

Views: 26314

Answers (2)

Ravi Teja
Ravi Teja

Reputation: 192

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

Upvotes: 6

Archon
Archon

Reputation: 1477

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

Upvotes: 21

Related Questions