Skip to content

Commit

Permalink
Almost done with AST modeling
Browse files Browse the repository at this point in the history
TODO: WindowSpec, Partition, Order
  • Loading branch information
johnedquinn committed Feb 25, 2025
1 parent 5a1eda2 commit ff78d50
Show file tree
Hide file tree
Showing 6 changed files with 532 additions and 40 deletions.
76 changes: 76 additions & 0 deletions partiql-ast/src/main/java/org/partiql/ast/AstVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -324,10 +324,86 @@ public R visitExprArray(ExprArray node, C ctx) {
return defaultVisit(node, ctx);
}

/**
* TODO
* @param node TODO
* @param ctx TODO
* @return TODO
*/
public R visitExprWindowFunction(ExprWindowFunction node, C ctx) {
return defaultVisit(node, ctx);
}

/**
* TODO
* @param node TODO
* @param ctx TODO
* @return TODO
*/
public R visitWindowFunctionType(WindowFunctionType node, C ctx) {
return node.accept(this, ctx);
}

/**
* TODO
* @param node TODO
* @param ctx TODO
* @return TODO
*/
public R visitWindowFunctionTypeNoArg(WindowFunctionType.NoArg node, C ctx) {
return defaultVisit(node, ctx);
}

/**
* TODO
* @param node TODO
* @param ctx TODO
* @return TODO
*/
public R visitWindowReference(WindowReference node, C ctx) {
return node.accept(this, ctx);
}

/**
* TODO
* @param node TODO
* @param ctx TODO
* @return TODO
*/
public R visitWindowReferenceName(WindowReference.Name node, C ctx) {
return defaultVisit(node, ctx);
}

/**
* TODO
* @param node TODO
* @param ctx TODO
* @return TODO
*/
public R visitWindowReferenceInLineSpecification(WindowReference.InLineSpecification node, C ctx) {
return defaultVisit(node, ctx);
}

/**
* TODO
* @param node TODO
* @param ctx TODO
* @return TODO
*/
public R visitWindowFunctionTypeLagOrLead(WindowFunctionType.LagOrLead node, C ctx) {
return defaultVisit(node, ctx);
}

/**
* TODO
* @param node TODO
* @param ctx TODO
* @return TODO
*/
public R visitWindowSpecification(WindowSpecification node, C ctx) {
return defaultVisit(node, ctx);
}

public R visitExprBag(ExprBag node, C ctx) {
return defaultVisit(node, ctx);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package org.partiql.ast;

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

import java.util.Collections;
import java.util.List;

/**
* TODO
*/
@EqualsAndHashCode(callSuper = false)
public final class WindowFunctionNullTreatment extends AstEnum {
/**
* TODO
*/
public static final int RESPECT_NULLS = 0;

/**
* TODO
*/
public static final int IGNORE_NULLS = 1;

/**
* TODO
* @return TODO
*/
public static WindowFunctionNullTreatment RESPECT_NULLS() {
return new WindowFunctionNullTreatment(RESPECT_NULLS);
}

/**
* TODO
* @return TODO
*/
public static WindowFunctionNullTreatment IGNORE_NULLS() {
return new WindowFunctionNullTreatment(IGNORE_NULLS);
}

private final int code;

private WindowFunctionNullTreatment(int code) {
this.code = code;
}

@Override
public int code() {
return code;
}

@NotNull
@Override
public String name() {
switch (code) {
case RESPECT_NULLS: return "RESPECT_NULLS";
case IGNORE_NULLS: return "DISTINCT";
default: throw new IllegalStateException("Invalid code: " + code);
}
}

@NotNull
private static final int[] codes = {
RESPECT_NULLS,
IGNORE_NULLS
};

@NotNull
public static int[] codes() {
return codes;
}

@NotNull
@Override
public List<AstNode> getChildren() {
return Collections.emptyList();
}

@Override
public <R, C> R accept(@NotNull AstVisitor<R, C> visitor, C ctx) {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package org.partiql.ast;

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

import java.util.Collections;
import java.util.List;

/**
* TODO
*/
@EqualsAndHashCode(callSuper = false)
public final class WindowFunctionSimpleName extends AstEnum {
/**
* TODO
*/
public static final int RANK = 0;

/**
* TODO
*/
public static final int DENSE_RANK = 1;

/**
* TODO
*/
public static final int PERCENT_RANK = 2;

/**
* TODO
*/
public static final int CUME_DIST = 3;

/**
* TODO
*/
public static final int ROW_NUMBER = 4;

/**
* TODO
* @return TODO
*/
public static WindowFunctionSimpleName RANK() {
return new WindowFunctionSimpleName(RANK);
}

/**
* TODO
* @return TODO
*/
public static WindowFunctionSimpleName DENSE_RANK() {
return new WindowFunctionSimpleName(DENSE_RANK);
}

private final int code;

private WindowFunctionSimpleName(int code) {
this.code = code;
}

@Override
public int code() {
return code;
}

@NotNull
@Override
public String name() {
switch (code) {
case RANK: return "RANK";
case DENSE_RANK: return "DENSE_RANK";
case PERCENT_RANK: return "PERCENT_RANK";
case CUME_DIST: return "CUME_DIST";
case ROW_NUMBER: return "ROW_NUMBER";
default: throw new IllegalStateException("Invalid code: " + code);
}
}

@NotNull
private static final int[] codes = {
RANK,
DENSE_RANK,
PERCENT_RANK,
CUME_DIST,
ROW_NUMBER
};

@NotNull
public static int[] codes() {
return codes;
}

@NotNull
@Override
public List<AstNode> getChildren() {
return Collections.emptyList();
}

@Override
public <R, C> R accept(@NotNull AstVisitor<R, C> visitor, C ctx) {
return null;
}
}
Loading

0 comments on commit ff78d50

Please sign in to comment.