NTile


🔷 NTile (Bucket Distribution)

🔍 Definition

NTile is used for:

➡️ Divide data into each group (partition)
➡️ Into several buckets (groups) evenly
➡️ Based on order (sorted data)

👉 Similar:

Divide data into Top 3 groups , Quartile , Percentile group

⚙️ Parameter

🎯 N (Bucket)

📥 Input & 📤 Output

Input Output ➕ Additional fields:

🧠 How it works

  1. Data is partitioned (usually using GroupBy)
  2. Data sorted (ascending / descending)
  3. Divided into N buckets evenly

📊 Example

The following sample data contains three fields: emp_name, dealer_id, and sales.

    emp_name        dealer_id   sales
    ---------------------------------
    Kameko French   2           16233
    Ursa George     3           15427
    Ferris Brown    1           19745
    Noel Meyer      1           19745
    Abel Kim        3           12369
    Raphael Hull    1           8227
    Jack Salazar    1           9710
    May Stout       3           9308
    Haviva Montoya  2           9308
Group And Sort
    Grouped Field       :dealer_id
    Sorted Field        :sales (ascending)
Processed with NTile, partitioned by dealer_id, ordered by sales, and using parameter :
   3
The output of NTile Buffer (field emp_name_new,dealer_id_new,sales_new, bucket) :
    emp_name_new    dealer_id_new   sales_new   bucket
    --------------------------------------------------
    Raphael Hull 	1               8227.0      1
    Jack Salazar 	1               9710.0      1
    Ferris Brown 	1               19745.0     2
    Noel Meyer   	1               19745.0     3
    Haviva Montoya	2               9308.0      1
    Kameko French	2               16233.0     2
    May Stout    	3               9308.0      1
    Abel Kim     	3               12369.0     2
    Ursa George  	3               15427.0     3

💡 Important Note:

The useful output fields from this buffer function are the grouped fields and new fields. Add a Transformator () assembly afterward to select these fields.

💡 Important Insights

1. Used for Analysis

✔ Data segmentation
✔ Class division (low, medium, high)
✔ Distribution analysis

3. Real Examples

🎯 Case:

Customer segmentation based on sales

Below is a sample workflow demonstrating the NTile process :

Description of Workflow : NTileProcess

Flow of Data Processing :

Hfs_source_1 :
HFS Source Hfs_source_1 reads flat file HDFS with properties :
Input Path : Arg[0]
File Type : Hfs
Combine Input : false
Fields in Lower Case : false
Delimiter :


Transformator_1 :
Transformator Transformator_1 transforms the output of 'Hfs_source_1' using the following transfromation function(s)
Input Field Operation Output Field Type
line
RegexSplitter(Splitter=|)
emp_name
dealer_id
sales
String
String
String


GroupBy_1 :
Group By GroupBy_1 groups the output of 'Transformator_1'

Grouped Field(s) :

  dealer_id

Sorted Field(s) :

  sales  Ascending

Buffer_2 :
Buffer Buffer_2 processes the output of 'GroupBy_1'

Using buffer operation pocesss :

  NTile

With paramter :

  3

Input Field Buffer Operation Output Field Type
emp_name
dealer_id
sales
NTile(3) emp_name
dealer_id
sales
emp_name_new
dealer_id_new
sales_new
BUCKET
String
Integer
Double
String
Integer
Double
Integer


Transformator_2 :
Transformator Transformator_2 transforms the output of 'Buffer_2' using the following transfromation function(s)
Input Field Operation Output Field Type
emp_name_new No Operation emp_name_new String
dealer_id_new No Operation dealer_id_new Integer
sales_new No Operation sales_new Double
BUCKET No Operation VALUE String


Hfs_sink_1 :
HFS Sink Hfs_sink_1 writes HDFS the output of 'Transformator_2' with properties :
Fields Name : emp_name_new,dealer_id_new,sales_new,VALUE
Output Path : Arg[1]
Output Name : hgrid247-#####
Sink Mode : SinkMode.REPLACE
Partition Field(s) :
Splitter :
Index :