Skip to content

Commit

Permalink
Rename CurrentTime.Type to Function
Browse files Browse the repository at this point in the history
  • Loading branch information
martint committed Jul 9, 2018
1 parent d83f9be commit 50e4bd4
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ protected Type visitCurrentTime(CurrentTime node, StackableAstVisitorContext<Con
}

Type type;
switch (node.getType()) {
switch (node.getFunction()) {
case DATE:
type = DATE;
break;
Expand All @@ -361,7 +361,7 @@ protected Type visitCurrentTime(CurrentTime node, StackableAstVisitorContext<Con
type = TIMESTAMP;
break;
default:
throw new SemanticException(NOT_SUPPORTED, node, "%s not yet supported", node.getType().getName());
throw new SemanticException(NOT_SUPPORTED, node, "%s not yet supported", node.getFunction().getName());
}

return setExpressionType(node, type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public Expression rewriteCurrentTime(CurrentTime node, Void context, ExpressionT
throw new UnsupportedOperationException("not yet implemented: non-default precision");
}

switch (node.getType()) {
switch (node.getFunction()) {
case DATE:
return new FunctionCall(QualifiedName.of("current_date"), ImmutableList.of());
case TIME:
Expand All @@ -79,7 +79,7 @@ public Expression rewriteCurrentTime(CurrentTime node, Void context, ExpressionT
case LOCALTIMESTAMP:
return new FunctionCall(QualifiedName.of("localtimestamp"), ImmutableList.of());
default:
throw new UnsupportedOperationException("not yet implemented: " + node.getType());
throw new UnsupportedOperationException("not yet implemented: " + node.getFunction());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ protected String visitCurrentTime(CurrentTime node, Void context)
{
StringBuilder builder = new StringBuilder();

builder.append(node.getType().getName());
builder.append(node.getFunction().getName());

if (node.getPrecision() != null) {
builder.append('(')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1222,13 +1222,13 @@ public Node visitCast(SqlBaseParser.CastContext context)
@Override
public Node visitSpecialDateTimeFunction(SqlBaseParser.SpecialDateTimeFunctionContext context)
{
CurrentTime.Type type = getDateTimeFunctionType(context.name);
CurrentTime.Function function = getDateTimeFunctionType(context.name);

if (context.precision != null) {
return new CurrentTime(getLocation(context), type, Integer.parseInt(context.precision.getText()));
return new CurrentTime(getLocation(context), function, Integer.parseInt(context.precision.getText()));
}

return new CurrentTime(getLocation(context), type);
return new CurrentTime(getLocation(context), function);
}

@Override
Expand Down Expand Up @@ -1905,19 +1905,19 @@ private static ComparisonExpression.Operator getComparisonOperator(Token symbol)
throw new IllegalArgumentException("Unsupported operator: " + symbol.getText());
}

private static CurrentTime.Type getDateTimeFunctionType(Token token)
private static CurrentTime.Function getDateTimeFunctionType(Token token)
{
switch (token.getType()) {
case SqlBaseLexer.CURRENT_DATE:
return CurrentTime.Type.DATE;
return CurrentTime.Function.DATE;
case SqlBaseLexer.CURRENT_TIME:
return CurrentTime.Type.TIME;
return CurrentTime.Function.TIME;
case SqlBaseLexer.CURRENT_TIMESTAMP:
return CurrentTime.Type.TIMESTAMP;
return CurrentTime.Function.TIMESTAMP;
case SqlBaseLexer.LOCALTIME:
return CurrentTime.Type.LOCALTIME;
return CurrentTime.Function.LOCALTIME;
case SqlBaseLexer.LOCALTIMESTAMP:
return CurrentTime.Type.LOCALTIMESTAMP;
return CurrentTime.Function.LOCALTIMESTAMP;
}

throw new IllegalArgumentException("Unsupported special function: " + token.getText());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
public class CurrentTime
extends Expression
{
private final Type type;
private final Function function;
private final Integer precision;

public enum Type
public enum Function
{
TIME("current_time"),
DATE("current_date"),
Expand All @@ -37,7 +37,7 @@ public enum Type

private final String name;

Type(String name)
Function(String name)
{
this.name = name;
}
Expand All @@ -48,37 +48,37 @@ public String getName()
}
}

public CurrentTime(Type type)
public CurrentTime(Function function)
{
this(Optional.empty(), type, null);
this(Optional.empty(), function, null);
}

public CurrentTime(NodeLocation location, Type type)
public CurrentTime(NodeLocation location, Function function)
{
this(Optional.of(location), type, null);
this(Optional.of(location), function, null);
}

public CurrentTime(Type type, Integer precision)
public CurrentTime(Function function, Integer precision)
{
this(Optional.empty(), type, precision);
this(Optional.empty(), function, precision);
}

public CurrentTime(NodeLocation location, Type type, Integer precision)
public CurrentTime(NodeLocation location, Function function, Integer precision)
{
this(Optional.of(location), type, precision);
this(Optional.of(location), function, precision);
}

private CurrentTime(Optional<NodeLocation> location, Type type, Integer precision)
private CurrentTime(Optional<NodeLocation> location, Function function, Integer precision)
{
super(location);
requireNonNull(type, "type is null");
this.type = type;
requireNonNull(function, "type is null");
this.function = function;
this.precision = precision;
}

public Type getType()
public Function getFunction()
{
return type;
return function;
}

public Integer getPrecision()
Expand Down Expand Up @@ -108,13 +108,13 @@ public boolean equals(Object o)
return false;
}
CurrentTime that = (CurrentTime) o;
return (type == that.type) &&
return (function == that.function) &&
Objects.equals(precision, that.precision);
}

@Override
public int hashCode()
{
return Objects.hash(type, precision);
return Objects.hash(function, precision);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ public void testTime()
@Test
public void testCurrentTimestamp()
{
assertExpression("CURRENT_TIMESTAMP", new CurrentTime(CurrentTime.Type.TIMESTAMP));
assertExpression("CURRENT_TIMESTAMP", new CurrentTime(CurrentTime.Function.TIMESTAMP));
}

@Test
Expand Down

0 comments on commit 50e4bd4

Please sign in to comment.