@WindowFunctionSignature(name = "row_number", returnType = "bigint") public class RowNumberFunction extends RankingWindowFunction { @Override public void processRow(BlockBuilder output, boolean newPeerGroup, int peerGroupCount, int currentPosition) { BIGINT.writeLong(output, currentPosition + 1); } }
private static SqlWindowFunction parse(Class<? extends WindowFunction> clazz, WindowFunctionSignature window) { List<TypeVariableConstraint> typeVariables = ImmutableList.of(); if (!window.typeVariable().isEmpty()) { typeVariables = ImmutableList.of(typeVariable(window.typeVariable())); } List<TypeSignature> argumentTypes = Stream.of(window.argumentTypes()) .map(TypeSignature::parseTypeSignature) .collect(toImmutableList()); Signature signature = new Signature( window.name(), WINDOW, typeVariables, ImmutableList.of(), parseTypeSignature(window.returnType()), argumentTypes, false); return new SqlWindowFunction(new ReflectionWindowFunctionSupplier<>(signature, clazz)); } }
@WindowFunctionSignature(name = "dense_rank", returnType = "bigint") public class DenseRankFunction extends RankingWindowFunction { private long rank; @Override public void reset() { rank = 0; } @Override public void processRow(BlockBuilder output, boolean newPeerGroup, int peerGroupCount, int currentPosition) { if (newPeerGroup) { rank++; } BIGINT.writeLong(output, rank); } }
@WindowFunctionSignature(name = "first_value", typeVariable = "T", returnType = "T", argumentTypes = "T") public class FirstValueFunction extends ValueWindowFunction { private final int argumentChannel; public FirstValueFunction(List<Integer> argumentChannels) { this.argumentChannel = getOnlyElement(argumentChannels); } @Override public void processRow(BlockBuilder output, int frameStart, int frameEnd, int currentPosition) { if (frameStart < 0) { output.appendNull(); return; } windowIndex.appendTo(argumentChannel, frameStart, output); } }
@WindowFunctionSignature(name = "last_value", typeVariable = "T", returnType = "T", argumentTypes = "T") public class LastValueFunction extends ValueWindowFunction { private final int argumentChannel; public LastValueFunction(List<Integer> argumentChannels) { this.argumentChannel = getOnlyElement(argumentChannels); } @Override public void processRow(BlockBuilder output, int frameStart, int frameEnd, int currentPosition) { if (frameStart < 0) { output.appendNull(); return; } windowIndex.appendTo(argumentChannel, frameEnd, output); } }
@WindowFunctionSignature(name = "cume_dist", returnType = "double") public class CumulativeDistributionFunction extends RankingWindowFunction { private long totalCount; private long count; @Override public void reset() { totalCount = windowIndex.size(); count = 0; } @Override public void processRow(BlockBuilder output, boolean newPeerGroup, int peerGroupCount, int currentPosition) { if (newPeerGroup) { count += peerGroupCount; } DOUBLE.writeDouble(output, ((double) count) / totalCount); } }
@WindowFunctionSignature(name = "custom_rank", returnType = "bigint") public class CustomRank extends RankingWindowFunction { private long rank; private long count; @Override public void reset() { rank = 0; count = 1; } @Override public void processRow(BlockBuilder output, boolean newPeerGroup, int peerGroupCount, int currentPosition) { if (newPeerGroup) { rank += count; count = 1; } else { count++; } BIGINT.writeLong(output, rank); } }
@WindowFunctionSignature(name = "rank", returnType = "bigint") public class RankFunction extends RankingWindowFunction { private long rank; private long count; @Override public void reset() { rank = 0; count = 1; } @Override public void processRow(BlockBuilder output, boolean newPeerGroup, int peerGroupCount, int currentPosition) { if (newPeerGroup) { rank += count; count = 1; } else { count++; } BIGINT.writeLong(output, rank); } }
@WindowFunctionSignature(name = "percent_rank", returnType = "double") public class PercentRankFunction extends RankingWindowFunction
@WindowFunctionSignature(name = "lag", typeVariable = "T", returnType = "T", argumentTypes = "T") @WindowFunctionSignature(name = "lag", typeVariable = "T", returnType = "T", argumentTypes = {"T", "bigint"}) @WindowFunctionSignature(name = "lag", typeVariable = "T", returnType = "T", argumentTypes = {"T", "bigint", "T"}) public class LagFunction extends ValueWindowFunction
@WindowFunctionSignature(name = "lead", typeVariable = "T", returnType = "T", argumentTypes = "T") @WindowFunctionSignature(name = "lead", typeVariable = "T", returnType = "T", argumentTypes = {"T", "bigint"}) @WindowFunctionSignature(name = "lead", typeVariable = "T", returnType = "T", argumentTypes = {"T", "bigint", "T"}) public class LeadFunction extends ValueWindowFunction
@WindowFunctionSignature(name = "nth_value", typeVariable = "T", returnType = "T", argumentTypes = {"T", "bigint"}) public class NthValueFunction extends ValueWindowFunction
@WindowFunctionSignature(name = "ntile", returnType = "bigint", argumentTypes = "bigint") public class NTileFunction extends RankingWindowFunction
/** * Created by shubham on 14/03/17. */ @WindowFunctionSignature(name = "first_non_null_value", typeVariable = "T", returnType = "T", argumentTypes = "T") public class FirstNonNullValueFunction extends FirstOrLastValueIgnoreNullFunction { public FirstNonNullValueFunction(List<Integer> argumentChannels) { super(argumentChannels, Direction.FIRST); } }
/** * Created by shubham on 14/03/17. */ @WindowFunctionSignature(name = "last_non_null_value", typeVariable = "T", returnType = "T", argumentTypes = "T") public class LastNonNullValueFunction extends FirstOrLastValueIgnoreNullFunction { public LastNonNullValueFunction(List<Integer> argumentChannels) { super(argumentChannels, Direction.LAST); } }
@WindowFunctionSignature(name = "custom_rank", returnType = "bigint") public class CustomRank extends RankingWindowFunction { private long rank; private long count; @Override public void reset() { rank = 0; count = 1; } @Override public void processRow(BlockBuilder output, boolean newPeerGroup, int peerGroupCount, int currentPosition) { if (newPeerGroup) { rank += count; count = 1; } else { count++; } BIGINT.writeLong(output, rank); } }