hive-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thinker0 <think...@gmail.com>
Subject Re: HiveQL for 'rank() over (partition by ... order by ...)'?
Date Thu, 26 May 2011 13:04:49 GMT
Hi. 

----------------------------------------------------------------------------------------------------------------------------------------------------------------------
/**
 * @author thinker0
 * 
 *         TiaraUDFRank.
 */
@Description(name = "t_row_rank", value = "_FUNC_() - Returns a generated row rank sequence
number starting from 1")
@UDFType(deterministic = false)
public class TiaraRankUDF extends UDF {
	private final LongWritable	result		= new LongWritable();
	private final Text			keepKeys	= new Text();
	private final Text			keyArgs		= new Text();
	private static final byte[]	NULL		= "NULL".getBytes();
	private static final byte[]	SPLIT		= ";".getBytes();

	/**
	 * 
	 */
	public TiaraRankUDF() {
		keepKeys.clear();
		keyArgs.clear();
	}

	/**
	 * @param rslv
	 */
	public TiaraRankUDF(UDFMethodResolver rslv) {
		super(rslv);
	}

	/**
	 * 
	 * @param args
	 * @return rank number
	 */
	public LongWritable evaluate(Text... args) {
		keyArgs.clear();
		for (Text arg : args) {
			if (arg == null) {
				keyArgs.append(NULL, 0, NULL.length);
			} else {
				final byte[] keyByte = arg.getBytes();
				keyArgs.append(keyByte, 0, keyByte.length);
			}
			keyArgs.append(SPLIT, 0, SPLIT.length);
		}
		if (! keepKeys.toString().equals(keyArgs.toString())) {
			keepKeys.set(keyArgs);
			result.set(0);
		}
		result.set(result.get() + 1);
		return result;
	}

}
----------------------------------------------------------------------------------------------------------------------------------------------------------------------

On May 25, 2011, at 8:45 PM, 김영우 wrote:

> Hi All,
> 
> I'm trying to convert Oracle SQL to HiveQL, esp Oracle Analytic functions. Is it possible
to implement using Hive UDFs or workarounds?
> I would like to hear your experiences and advice.
> 
> Thanks in advance. 
> 
> - Youngwoo


Mime
View raw message