Recently because of work and life some things for a long time not to blog Park, but the habit of blogging is to insist, the new year needs more efforts, sleepy know Mian line, lifelong learning, every day to maintain empty cup mentality. Nonsense, write some of the most recently used Presto SQL and hive SQL experience and contrast.
One. JSON processing comparison
Select Get_json_object (JSON, ' $.book ');
Select Json_extract_scalar (JSON, ' $.book ');
Notice here that the Json_extract_scalar return value in Presto is a string type, and there is a function json_extract that returns a JSON string directly, so when you use it you have to know exactly what type of value to take.
Two. Column change comparison
Select student, score from tests lateral view explode (split (scores, ', ')) T as score;
Select student, score from Tests cross JSON Unnest (split (scores, ', ') as T (score);
In a nutshell, a comma-separated fractional column in the scores field, such as
80,90,99,80
This single-column value is converted to a value mapping with a one-to-many row for the student column.
Three. Complex grouping contrast
Select Origin_state, Origin_zip, sum (package_weight) from shipping GROUP by Origin_state,origin_zip with rollup;
Select Origin_state, Origin_zip, sum (package_weight) from shipping GROUP by rollup (Origin_state, origin_zip);
Used rollup know, this is a right-to-left descending multilevel statistic aggregation, equivalent to (as follows Presto notation)
Select Origin_state, Origin_zip, sum (package_weight) from shipping Group BY grouping sets ((Origin_state, Origin_zip), (or Igin_state), ());
Some of the other syntaxes have subtle differences that can be understood slowly, but the fact that hive is not the same as the Presto underlying architecture causes Presto to be much faster than hive operations, plus the open source Alluxio cache.
Some comparisons of Hive SQL and Presto sql