Skip to content

Commit

Permalink
Flatten class hierarchy for IR JSON-path nodes
Browse files Browse the repository at this point in the history
Abstract classes `IrAccessor` and `IrMethod` are removed.
  • Loading branch information
kasiafi committed Apr 21, 2023
1 parent 0b0ff96 commit 1be256c
Show file tree
Hide file tree
Showing 15 changed files with 155 additions and 124 deletions.
15 changes: 13 additions & 2 deletions core/trino-main/src/main/java/io/trino/json/ir/IrAbsMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,29 @@

import java.util.Optional;

import static java.util.Objects.requireNonNull;

public class IrAbsMethod
extends IrMethod
extends IrPathNode
{
private final IrPathNode base;

@JsonCreator
public IrAbsMethod(@JsonProperty("base") IrPathNode base, @JsonProperty("type") Optional<Type> type)
{
super(base, type);
super(type);
this.base = requireNonNull(base, "abs() method base is null");
}

@Override
protected <R, C> R accept(IrJsonPathVisitor<R, C> visitor, C context)
{
return visitor.visitIrAbsMethod(this, context);
}

@JsonProperty
public IrPathNode getBase()
{
return base;
}
}
45 changes: 0 additions & 45 deletions core/trino-main/src/main/java/io/trino/json/ir/IrAccessor.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,18 @@
import static java.util.Objects.requireNonNull;

public class IrArrayAccessor
extends IrAccessor
extends IrPathNode
{
private final IrPathNode base;

// list of subscripts or empty list for wildcard array accessor
private final List<Subscript> subscripts;

@JsonCreator
public IrArrayAccessor(@JsonProperty("base") IrPathNode base, @JsonProperty("subscripts") List<Subscript> subscripts, @JsonProperty("type") Optional<Type> type)
{
super(base, type);
super(type);
this.base = requireNonNull(base, "array accessor base is null");
this.subscripts = requireNonNull(subscripts, "subscripts is null");
}

Expand All @@ -41,6 +44,12 @@ protected <R, C> R accept(IrJsonPathVisitor<R, C> visitor, C context)
return visitor.visitIrArrayAccessor(this, context);
}

@JsonProperty
public IrPathNode getBase()
{
return base;
}

@JsonProperty
public List<Subscript> getSubscripts()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,29 @@

import java.util.Optional;

import static java.util.Objects.requireNonNull;

public class IrCeilingMethod
extends IrMethod
extends IrPathNode
{
private final IrPathNode base;

@JsonCreator
public IrCeilingMethod(@JsonProperty("base") IrPathNode base, @JsonProperty("type") Optional<Type> type)
{
super(base, type);
super(type);
this.base = requireNonNull(base, "ceiling() method base is null");
}

@Override
protected <R, C> R accept(IrJsonPathVisitor<R, C> visitor, C context)
{
return visitor.visitIrCeilingMethod(this, context);
}

@JsonProperty
public IrPathNode getBase()
{
return base;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@
import static java.util.Objects.requireNonNull;

public class IrDatetimeMethod
extends IrMethod
extends IrPathNode
{
private final IrPathNode base;
private final Optional<String> format; // this is a string literal

@JsonCreator
public IrDatetimeMethod(@JsonProperty("base") IrPathNode base, @JsonProperty("format") Optional<String> format, @JsonProperty("type") Optional<Type> type)
{
super(base, type);
super(type);
this.base = requireNonNull(base, "datetime() method base is null");
this.format = requireNonNull(format, "format is null");
}

Expand All @@ -39,6 +41,12 @@ protected <R, C> R accept(IrJsonPathVisitor<R, C> visitor, C context)
return visitor.visitIrDatetimeMethod(this, context);
}

@JsonProperty
public IrPathNode getBase()
{
return base;
}

@JsonProperty
public Optional<String> getFormat()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@
import static java.util.Objects.requireNonNull;

public class IrDescendantMemberAccessor
extends IrAccessor
extends IrPathNode
{
private final IrPathNode base;
private final String key;

@JsonCreator
public IrDescendantMemberAccessor(@JsonProperty("base") IrPathNode base, @JsonProperty("key") String key, @JsonProperty("type") Optional<Type> type)
{
super(base, type);
super(type);
this.base = requireNonNull(base, "descendant member accessor base is null");
this.key = requireNonNull(key, "key is null");
}

Expand All @@ -39,6 +41,12 @@ protected <R, C> R accept(IrJsonPathVisitor<R, C> visitor, C context)
return visitor.visitIrDescendantMemberAccessor(this, context);
}

@JsonProperty
public IrPathNode getBase()
{
return base;
}

@JsonProperty
public String getKey()
{
Expand Down
15 changes: 13 additions & 2 deletions core/trino-main/src/main/java/io/trino/json/ir/IrDoubleMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,29 @@

import java.util.Optional;

import static java.util.Objects.requireNonNull;

public class IrDoubleMethod
extends IrMethod
extends IrPathNode
{
private final IrPathNode base;

@JsonCreator
public IrDoubleMethod(@JsonProperty("base") IrPathNode base, @JsonProperty("type") Optional<Type> type)
{
super(base, type);
super(type);
this.base = requireNonNull(base, "double() method base is null");
}

@Override
protected <R, C> R accept(IrJsonPathVisitor<R, C> visitor, C context)
{
return visitor.visitIrDoubleMethod(this, context);
}

@JsonProperty
public IrPathNode getBase()
{
return base;
}
}
12 changes: 10 additions & 2 deletions core/trino-main/src/main/java/io/trino/json/ir/IrFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@
import static java.util.Objects.requireNonNull;

public class IrFilter
extends IrAccessor
extends IrPathNode
{
private final IrPathNode base;
private final IrPredicate predicate;

@JsonCreator
public IrFilter(@JsonProperty("base") IrPathNode base, @JsonProperty("predicate") IrPredicate predicate, @JsonProperty("type") Optional<Type> type)
{
super(base, type);
super(type);
this.base = requireNonNull(base, "filter base is null");
this.predicate = requireNonNull(predicate, "predicate is null");
}

Expand All @@ -39,6 +41,12 @@ protected <R, C> R accept(IrJsonPathVisitor<R, C> visitor, C context)
return visitor.visitIrFilter(this, context);
}

@JsonProperty
public IrPathNode getBase()
{
return base;
}

@JsonProperty
public IrPredicate getPredicate()
{
Expand Down
15 changes: 13 additions & 2 deletions core/trino-main/src/main/java/io/trino/json/ir/IrFloorMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,29 @@

import java.util.Optional;

import static java.util.Objects.requireNonNull;

public class IrFloorMethod
extends IrMethod
extends IrPathNode
{
private final IrPathNode base;

@JsonCreator
public IrFloorMethod(@JsonProperty("base") IrPathNode base, @JsonProperty("type") Optional<Type> type)
{
super(base, type);
super(type);
this.base = requireNonNull(base, "floor() method base is null");
}

@Override
protected <R, C> R accept(IrJsonPathVisitor<R, C> visitor, C context)
{
return visitor.visitIrFloorMethod(this, context);
}

@JsonProperty
public IrPathNode getBase()
{
return base;
}
}
Loading

0 comments on commit 1be256c

Please sign in to comment.