Skip to content
This repository was archived by the owner on May 12, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
3e2cfab
window frame ROWS support is added, RANGE is not supported yet
sirpkt Mar 22, 2015
ddd6797
Merge remote-tracking branch 'upstream/master' into TAJO-1415
sirpkt Mar 22, 2015
ddc7c1b
bug fix during master merge
sirpkt Mar 23, 2015
aa97dbb
support for RANGE window frame
sirpkt Mar 23, 2015
7b21415
Merge remote-tracking branch 'upstream/master' into TAJO-1415
sirpkt Mar 23, 2015
973d99f
Fix bug for no order by case, where window function SHOULD work on th…
sirpkt Mar 23, 2015
53edd69
Merge branch 'master' into TAJO-1415
sirpkt Mar 24, 2015
883ec99
fix typo
sirpkt Mar 25, 2015
ff21b1e
Merge remote-tracking branch 'upstream/master' into TAJO-1415
sirpkt Mar 25, 2015
7895593
remove comments
sirpkt Mar 25, 2015
5ece3a4
Merge remote-tracking branch 'upstream/master' into TAJO-1415
sirpkt Apr 7, 2015
35e9870
fix query result according to default window frame setting for aggreg…
sirpkt Apr 7, 2015
ac0cc75
Merge remote-tracking branch 'upstream/master' into TAJO-1415
sirpkt Apr 13, 2015
76caa39
Reflecting review comments
sirpkt Apr 13, 2015
3231f9a
Merge remote-tracking branch 'upstream/master' into TAJO-1415
sirpkt Apr 13, 2015
72a4519
Merge remote-tracking branch 'upstream/master' into TAJO-1415
sirpkt Apr 16, 2015
7f45445
Merge branch 'master' into TAJO-1415
sirpkt Apr 20, 2015
6dd02ac
Merge remote-tracking branch 'upstream/master' into TAJO-1415
sirpkt Apr 27, 2015
114f4c5
rebase and reflect comments from review
sirpkt Apr 27, 2015
a2d4def
Merge remote-tracking branch 'upstream/master' into TAJO-1415
sirpkt Apr 28, 2015
4d5916e
reflect recent comments on the patch
sirpkt Apr 28, 2015
c634c4b
Merge remote-tracking branch 'upstream/master' into TAJO-1415
sirpkt Apr 29, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 20 additions & 53 deletions tajo-algebra/src/main/java/org/apache/tajo/algebra/WindowSpec.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,69 +120,69 @@ public boolean equals(Object obj) {

}

public static enum WindowFrameUnit {
public enum WindowFrameUnit {
ROW,
RANGE
}

public static enum WindowFrameStartBoundType {
public enum WindowFrameBoundType {
UNBOUNDED_PRECEDING,
CURRENT_ROW,
PRECEDING
}

public static enum WindowFrameEndBoundType {
UNBOUNDED_FOLLOWING,
CURRENT_ROW,
PRECEDING,
FOLLOWING
}

public static class WindowFrame implements Cloneable {
@Expose private WindowFrameUnit unit;
@Expose private WindowStartBound startBound;
@Expose private WindowEndBound endBound;
@Expose private WindowBound startBound;
@Expose private WindowBound endBound;

public WindowFrame(WindowFrameUnit unit, WindowStartBound startBound) {
public WindowFrame(WindowFrameUnit unit, WindowBound startBound) {
this.unit = unit;
this.startBound = startBound;
}

public WindowFrame(WindowFrameUnit unit, WindowStartBound startBound, WindowEndBound endBound) {
public WindowFrame(WindowFrameUnit unit, WindowBound startBound, WindowBound endBound) {
this(unit, startBound);
this.endBound = endBound;
}

public WindowStartBound getStartBound() {
public WindowFrameUnit getFrameUnit() {
return unit;
}

public WindowBound getStartBound() {
return startBound;
}

public boolean hasEndBound() {
return endBound != null;
}

public WindowEndBound getEndBound() {
public WindowBound getEndBound() {
return endBound;
}

@Override
public Object clone() throws CloneNotSupportedException {
WindowFrame frame = (WindowFrame) super.clone();
frame.unit = unit;
frame.startBound = (WindowStartBound) startBound.clone();
frame.endBound = (WindowEndBound) endBound.clone();
frame.startBound = (WindowBound) startBound.clone();
frame.endBound = (WindowBound) endBound.clone();
return frame;
}
}

public static class WindowStartBound implements Cloneable {
@Expose private WindowFrameStartBoundType boundType;
public static class WindowBound implements Cloneable {
@Expose private WindowFrameBoundType boundType;
@Expose private Expr number;

public WindowStartBound(WindowFrameStartBoundType type) {
public WindowBound(WindowFrameBoundType type) {
this.boundType = type;
}

public WindowFrameStartBoundType getBoundType() {
public WindowFrameBoundType getBoundType() {
return boundType;
}

Expand All @@ -200,43 +200,10 @@ public Expr getNumber() {

@Override
public Object clone() throws CloneNotSupportedException {
WindowStartBound start = (WindowStartBound) super.clone();
WindowBound start = (WindowBound) super.clone();
start.boundType = boundType;
start.number = (Expr) number.clone();
return start;
}
}

public static class WindowEndBound implements Cloneable {
@Expose private WindowFrameEndBoundType boundType;
@Expose private Expr number;

public WindowEndBound(WindowFrameEndBoundType type) {
this.boundType = type;
}

public WindowFrameEndBoundType getBoundType() {
return boundType;
}

public boolean hasNumber() {
return this.number != null;
}

public void setNumber(Expr number) {
this.number = number;
}

public Expr getNumber() {
return number;
}

@Override
public Object clone() throws CloneNotSupportedException {
WindowEndBound end = (WindowEndBound) super.clone();
end.boundType = boundType;
end.number = (Expr) number.clone();
return end;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1197,6 +1197,7 @@ window_frame_extent
window_frame_start_bound
: UNBOUNDED PRECEDING
| unsigned_value_specification PRECEDING // window_frame_preceding
| unsigned_value_specification FOLLOWING // window_frame_following FOLLOWING
| CURRENT ROW
;

Expand All @@ -1206,6 +1207,7 @@ window_frame_between

window_frame_end_bound
: UNBOUNDED FOLLOWING
| unsigned_value_specification PRECEDING // window_frame_preceding
| unsigned_value_specification FOLLOWING // window_frame_following FOLLOWING
| CURRENT ROW
;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,41 +24,34 @@
import org.apache.tajo.plan.function.WindowAggFunc;
import org.apache.tajo.storage.Tuple;

public abstract class FirstValue extends WindowAggFunc<Datum> {
public abstract class CurrentValue extends WindowAggFunc<Datum> {

public FirstValue(Column[] columns) {
public CurrentValue(Column[] columns) {
super(columns);
}

@Override
public FunctionContext newContext() {
return new FirstValueContext();
return new CurrentValueContext();
}

@Override
public void eval(FunctionContext ctx, Tuple params) {
FirstValueContext firstValueCtx = (FirstValueContext)ctx;
if(firstValueCtx.isSet == false) {
firstValueCtx.isSet = true;
if (params.get(0).isNotNull()) {
firstValueCtx.first = params.get(0);
CurrentValueContext currentValueCtx = (CurrentValueContext)ctx;
if (params.get(0) == null || params.get(0).isNull()) {
currentValueCtx.current = NullDatum.get();
} else {
currentValueCtx.current = params.get(0);
}
}
}

@Override
public Datum terminate(FunctionContext ctx) {
if (((FirstValueContext) ctx).first == null) {
return NullDatum.get();
}
else {
return ((FirstValueContext) ctx).first;
}
return ((CurrentValueContext) ctx).current;
}

protected static class FirstValueContext implements FunctionContext {
boolean isSet = false;
Datum first = null;
protected static class CurrentValueContext implements FunctionContext {
Datum current = null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
returnType = Type.DATE,
paramTypes = {@ParamTypes(paramTypes = {Type.DATE})}
)
public class FirstValueDate extends FirstValue {
public class FirstValueDate extends CurrentValue {

public FirstValueDate() {
super(new Column[] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
returnType = Type.FLOAT8,
paramTypes = {@ParamTypes(paramTypes = {Type.FLOAT8})}
)
public class FirstValueDouble extends FirstValue {
public class FirstValueDouble extends CurrentValue {

public FirstValueDouble() {
super(new Column[] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
returnType = Type.FLOAT4,
paramTypes = {@ParamTypes(paramTypes = {Type.FLOAT4})}
)
public class FirstValueFloat extends FirstValue {
public class FirstValueFloat extends CurrentValue {

public FirstValueFloat() {
super(new Column[] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
returnType = Type.INT4,
paramTypes = {@ParamTypes(paramTypes = {Type.INT4})}
)
public class FirstValueInt extends FirstValue {
public class FirstValueInt extends CurrentValue {

public FirstValueInt() {
super(new Column[] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
returnType = Type.INT8,
paramTypes = {@ParamTypes(paramTypes = {Type.INT8})}
)
public class FirstValueLong extends FirstValue {
public class FirstValueLong extends CurrentValue {

public FirstValueLong() {
super(new Column[] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
returnType = Type.TEXT,
paramTypes = {@ParamTypes(paramTypes = {Type.TEXT})}
)
public class FirstValueString extends FirstValue {
public class FirstValueString extends CurrentValue {

public FirstValueString() {
super(new Column[] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
returnType = Type.TIME,
paramTypes = {@ParamTypes(paramTypes = {Type.TIME})}
)
public class FirstValueTime extends FirstValue {
public class FirstValueTime extends CurrentValue {

public FirstValueTime() {
super(new Column[] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
returnType = Type.TIMESTAMP,
paramTypes = {@ParamTypes(paramTypes = {Type.TIMESTAMP})}
)
public class FirstValueTimestamp extends FirstValue {
public class FirstValueTimestamp extends CurrentValue {

public FirstValueTimestamp() {
super(new Column[] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,25 @@
* limitations under the License.
*/

package org.apache.tajo.engine.function.builtin;
package org.apache.tajo.engine.function.window;

import org.apache.tajo.catalog.CatalogUtil;
import org.apache.tajo.catalog.Column;
import org.apache.tajo.common.TajoDataTypes;
import org.apache.tajo.engine.function.annotation.Description;
import org.apache.tajo.engine.function.annotation.ParamTypes;

@Description(
functionName = "last_value",
description = "the last value of expr",
example = "> SELECT last_value(expr);",
description = "the last value of retrieved rows",
example = "> SELECT last_value(column) OVER();",
returnType = TajoDataTypes.Type.DATE,
paramTypes = {@ParamTypes(paramTypes = {TajoDataTypes.Type.DATE})}
)
public class LastValueDate extends LastValue {
public class LastValueDate extends CurrentValue {

public LastValueDate() {
super(new Column[] {
new Column("expr", TajoDataTypes.Type.DATE)
});
}

@Override
public TajoDataTypes.DataType getPartialResultType() {
return CatalogUtil.newSimpleDataType(TajoDataTypes.Type.DATE);
}
}
Loading