When data volume is extra large, we may need to find a subset of data to speed up data analysis. Here it comes to a technique used to select and analyze a subset of data in order to identify patterns and trends. In Hive, there are three ways of sampling data: random sampling, bucket table sampling, and block sampling.
Random sampling uses the
RAND() function and
LIMIT keyword to get the sampling of data as shown in the following example. The
SORT keywords are used here to make sure the data is also randomly distributed among mappers and reducers efficiently. The
ORDER BY RAND() statement can also achieve the same purpose, but the performance is not good:
SELECT * FROM <Table_Name> DISTRIBUTE BY RAND() SORT BY RAND() LIMIT ...