Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v1] Change public fields to Lombok getters; make concrete classes final #1685

Merged
merged 6 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
692 changes: 308 additions & 384 deletions partiql-ast/api/partiql-ast.api

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions partiql-ast/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
plugins {
id(Plugins.conventions)
id(Plugins.publish)
// Need the Kotlin lombok plugin to allow for Kotlin code in partiql-ast to understand Java Lombok annotations.
// https://kotlinlang.org/docs/lombok.html
id(Plugins.kotlinLombok) version Versions.kotlinLombok
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(self-review): Kotlin lombok plugin required to allow Kotlin code to understand Java lombok annotations -- https://kotlinlang.org/docs/lombok.html. It is experimental but

  • seems pretty stable so far since its published by the Kotlin team
  • we could always use a fixed version or hand-write the getters if we encounter issues without breaking the public API

}

dependencies {
Expand Down
21 changes: 13 additions & 8 deletions partiql-ast/src/main/java/org/partiql/ast/DataType.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.partiql.ast;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.partiql.ast.ddl.AttributeConstraint;
Expand All @@ -9,7 +10,7 @@
import java.util.List;

@EqualsAndHashCode(callSuper = false)
public class DataType extends AstEnum {
public final class DataType extends AstEnum {
/**
* A field definition with in a Struct Type Definition
*/
Expand All @@ -28,26 +29,30 @@ public class DataType extends AstEnum {
@EqualsAndHashCode(callSuper = false)
public static class StructField extends AstNode {
@NotNull
public final Identifier name;
@Getter
private final Identifier name;

@NotNull
public final DataType type;
@Getter
private final DataType type;

public final boolean isOptional;
@Getter
private final boolean optional;

@Nullable
public final List<AttributeConstraint> constraints;
private final List<AttributeConstraint> constraints;
@Nullable
public final String comment;
private final String comment;
johnedquinn marked this conversation as resolved.
Show resolved Hide resolved

public StructField(
@NotNull Identifier name,
@NotNull DataType type,
boolean isOptional,
boolean optional,
@Nullable List<AttributeConstraint> constraints,
@Nullable String comment) {
this.name = name;
this.type = type;
this.isOptional = isOptional;
this.optional = optional;
this.constraints = constraints;
this.comment = comment;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* TODO docs, equals, hashcode
*/
@EqualsAndHashCode(callSuper = false)
public class DatetimeField extends AstEnum {
public final class DatetimeField extends AstEnum {
public static final int YEAR = 0;
public static final int MONTH = 1;
public static final int DAY = 2;
Expand Down
6 changes: 4 additions & 2 deletions partiql-ast/src/main/java/org/partiql/ast/Exclude.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
Expand All @@ -12,9 +13,10 @@
*/
@Builder(builderClassName = "Builder")
@EqualsAndHashCode(callSuper = false)
public class Exclude extends AstNode {
public final class Exclude extends AstNode {
@NotNull
public final List<ExcludePath> excludePaths;
@Getter
private final List<ExcludePath> excludePaths;

public Exclude(@NotNull List<ExcludePath> excludePaths) {
this.excludePaths = excludePaths;
Expand Down
9 changes: 6 additions & 3 deletions partiql-ast/src/main/java/org/partiql/ast/ExcludePath.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import org.jetbrains.annotations.NotNull;
import org.partiql.ast.expr.ExprVarRef;

Expand All @@ -13,12 +14,14 @@
*/
@Builder(builderClassName = "Builder")
@EqualsAndHashCode(callSuper = false)
public class ExcludePath extends AstNode {
public final class ExcludePath extends AstNode {
@NotNull
public final ExprVarRef root;
@Getter
private final ExprVarRef root;

@NotNull
public final List<ExcludeStep> excludeSteps;
@Getter
private final List<ExcludeStep> excludeSteps;

public ExcludePath(@NotNull ExprVarRef root, @NotNull List<ExcludeStep> excludeSteps) {
this.root = root;
Expand Down
7 changes: 5 additions & 2 deletions partiql-ast/src/main/java/org/partiql/ast/ExcludeStep.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
Expand All @@ -18,7 +19,8 @@ public abstract class ExcludeStep extends AstNode {
@EqualsAndHashCode(callSuper = false)
public static class StructField extends ExcludeStep {
@NotNull
public final Identifier symbol;
@Getter
private final Identifier symbol;

public StructField(@NotNull Identifier symbol) {
this.symbol = symbol;
Expand All @@ -44,7 +46,8 @@ public <R, C> R accept(@NotNull AstVisitor<R, C> visitor, C ctx) {
@Builder(builderClassName = "Builder")
@EqualsAndHashCode(callSuper = false)
public static class CollIndex extends ExcludeStep {
public final int index;
@Getter
private final int index;

public CollIndex(int index) {
this.index = index;
Expand Down
9 changes: 6 additions & 3 deletions partiql-ast/src/main/java/org/partiql/ast/Explain.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
Expand All @@ -13,12 +14,14 @@
*/
@Builder(builderClassName = "Builder")
@EqualsAndHashCode(callSuper = false)
public class Explain extends Statement {
public final class Explain extends Statement {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(self-review): change all of the concrete classes to be final.

@NotNull
public final Map<String, Literal> options;
@Getter
private final Map<String, Literal> options;

@NotNull
public final Statement statement;
@Getter
private final Statement statement;

public Explain(@NotNull Map<String, Literal> options, @NotNull Statement statement) {
this.options = options;
Expand Down
6 changes: 4 additions & 2 deletions partiql-ast/src/main/java/org/partiql/ast/From.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
Expand All @@ -12,9 +13,10 @@
*/
@Builder(builderClassName = "Builder")
@EqualsAndHashCode(callSuper = false)
public class From extends AstNode {
public final class From extends AstNode {
@NotNull
public final List<FromTableRef> tableRefs;
@Getter
private final List<FromTableRef> tableRefs;

public From(@NotNull List<FromTableRef> tableRefs) {
this.tableRefs = tableRefs;
Expand Down
15 changes: 10 additions & 5 deletions partiql-ast/src/main/java/org/partiql/ast/FromExpr.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.partiql.ast.expr.Expr;
Expand All @@ -14,18 +15,22 @@
*/
@Builder(builderClassName = "Builder")
@EqualsAndHashCode(callSuper = false)
public class FromExpr extends FromTableRef {
public final class FromExpr extends FromTableRef {
@NotNull
public final Expr expr;
@Getter
private final Expr expr;

@NotNull
public final FromType fromType;
@Getter
private final FromType fromType;

@Nullable
public final Identifier asAlias;
@Getter
private final Identifier asAlias;

@Nullable
public final Identifier atAlias;
@Getter
private final Identifier atAlias;

public FromExpr(@NotNull Expr expr, @NotNull FromType fromType, @Nullable Identifier asAlias,
@Nullable Identifier atAlias) {
Expand Down
15 changes: 10 additions & 5 deletions partiql-ast/src/main/java/org/partiql/ast/FromJoin.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.partiql.ast.expr.Expr;
Expand All @@ -14,18 +15,22 @@
*/
@Builder(builderClassName = "Builder")
@EqualsAndHashCode(callSuper = false)
public class FromJoin extends FromTableRef {
public final class FromJoin extends FromTableRef {
@NotNull
public final FromTableRef lhs;
@Getter
private final FromTableRef lhs;

@NotNull
public final FromTableRef rhs;
@Getter
private final FromTableRef rhs;

@Nullable
public final JoinType joinType;
@Getter
private final JoinType joinType;

@Nullable
public final Expr condition;
@Getter
private final Expr condition;

public FromJoin(@NotNull FromTableRef lhs, @NotNull FromTableRef rhs, @Nullable JoinType joinType, @Nullable Expr condition) {
this.lhs = lhs;
Expand Down
2 changes: 1 addition & 1 deletion partiql-ast/src/main/java/org/partiql/ast/FromType.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* TODO docs, equals, hashcode
*/
@EqualsAndHashCode(callSuper = false)
public class FromType extends AstEnum {
public final class FromType extends AstEnum {
public static final int SCAN = 0;
public static final int UNPIVOT = 1;

Expand Down
18 changes: 12 additions & 6 deletions partiql-ast/src/main/java/org/partiql/ast/GroupBy.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.partiql.ast.expr.Expr;
Expand All @@ -14,15 +15,18 @@
*/
@Builder(builderClassName = "Builder")
@EqualsAndHashCode(callSuper = false)
public class GroupBy extends AstNode {
public final class GroupBy extends AstNode {
@NotNull
public final GroupByStrategy strategy;
@Getter
private final GroupByStrategy strategy;

@NotNull
public final List<Key> keys;
@Getter
private final List<Key> keys;

@Nullable
public final Identifier asAlias;
@Getter
private final Identifier asAlias;

public GroupBy(@NotNull GroupByStrategy strategy, @NotNull List<Key> keys, @Nullable Identifier asAlias) {
this.strategy = strategy;
Expand Down Expand Up @@ -52,10 +56,12 @@ public <R, C> R accept(@NotNull AstVisitor<R, C> visitor, C ctx) {
@EqualsAndHashCode(callSuper = false)
public static class Key extends AstNode {
@NotNull
public final Expr expr;
@Getter
private final Expr expr;

@Nullable
public final Identifier asAlias;
@Getter
private final Identifier asAlias;

public Key(@NotNull Expr expr, @Nullable Identifier asAlias) {
this.expr = expr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* TODO docs, equals, hashcode
*/
@EqualsAndHashCode(callSuper = false)
public class GroupByStrategy extends AstEnum {
public final class GroupByStrategy extends AstEnum {
public static final int FULL = 0;
public static final int PARTIAL = 1;

Expand Down
13 changes: 8 additions & 5 deletions partiql-ast/src/main/java/org/partiql/ast/Identifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
Expand All @@ -12,15 +13,17 @@
*/
@Builder(builderClassName = "Builder")
@EqualsAndHashCode(callSuper = false)
public class Identifier extends AstNode {
public final class Identifier extends AstNode {
@NotNull
public final String symbol;
@Getter
private final String symbol;

public final boolean isDelimited;
@Getter
private final boolean delimited;

public Identifier(@NotNull String symbol, boolean isDelimited) {
public Identifier(@NotNull String symbol, boolean delimited) {
this.symbol = symbol;
this.isDelimited = isDelimited;
this.delimited = delimited;
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand All @@ -13,12 +14,14 @@
*/
@Builder(builderClassName = "Builder")
@EqualsAndHashCode(callSuper = false)
public class IdentifierChain extends AstNode {
public final class IdentifierChain extends AstNode {
@NotNull
public final Identifier root;
@Getter
private final Identifier root;

@Nullable
public final IdentifierChain next;
@Getter
private final IdentifierChain next;

public IdentifierChain(@NotNull Identifier root, @Nullable IdentifierChain next) {
this.root = root;
Expand Down
2 changes: 1 addition & 1 deletion partiql-ast/src/main/java/org/partiql/ast/JoinType.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* TODO docs, equals, hashcode
*/
@EqualsAndHashCode(callSuper = false)
public class JoinType extends AstEnum {
public final class JoinType extends AstEnum {
public static final int INNER = 0;
public static final int LEFT = 1;
public static final int LEFT_OUTER = 2;
Expand Down
Loading
Loading