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

Adds support for the interval type #1741

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,27 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
Thank you to all who have contributed!
-->

## [Unreleased](https://TODO.com) - YYYY-MM-DD

### Added
- Added parsing, planning, and execution of the interval type and interval values.
- Added multiple operations involving datetime and interval values.

### Changed

### Deprecated

### Fixed

### Removed

### Security

### Contributors

Thank you to all who have contributed!
- @johnedquinn

## [1.1.0](https://github.com/partiql/partiql-lang-kotlin/releases/tag/v1.1.0) - 2025-02-14

### Added
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group=org.partiql
version=1.1.0
version=1.2.0-SNAPSHOT

ossrhUsername=EMPTY
ossrhPassword=EMPTY
Expand Down
51 changes: 51 additions & 0 deletions partiql-ast/api/partiql-ast.api
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,9 @@ public abstract class org/partiql/ast/AstVisitor {
public fun visitInsertSource (Lorg/partiql/ast/dml/InsertSource;Ljava/lang/Object;)Ljava/lang/Object;
public fun visitInsertSourceFromDefault (Lorg/partiql/ast/dml/InsertSource$FromDefault;Ljava/lang/Object;)Ljava/lang/Object;
public fun visitInsertSourceFromExpr (Lorg/partiql/ast/dml/InsertSource$FromExpr;Ljava/lang/Object;)Ljava/lang/Object;
public fun visitIntervalQualifier (Lorg/partiql/ast/IntervalQualifier;Ljava/lang/Object;)Ljava/lang/Object;
public fun visitIntervalQualifierRange (Lorg/partiql/ast/IntervalQualifier$Range;Ljava/lang/Object;)Ljava/lang/Object;
public fun visitIntervalQualifierSingle (Lorg/partiql/ast/IntervalQualifier$Single;Ljava/lang/Object;)Ljava/lang/Object;
public fun visitKeyValue (Lorg/partiql/ast/ddl/KeyValue;Ljava/lang/Object;)Ljava/lang/Object;
public fun visitLet (Lorg/partiql/ast/Let;Ljava/lang/Object;)Ljava/lang/Object;
public fun visitLetBinding (Lorg/partiql/ast/Let$Binding;Ljava/lang/Object;)Ljava/lang/Object;
Expand Down Expand Up @@ -678,6 +681,7 @@ public final class org/partiql/ast/DataType : org/partiql/ast/AstEnum {
public static fun INTEGER4 ()Lorg/partiql/ast/DataType;
public static fun INTEGER8 ()Lorg/partiql/ast/DataType;
public static fun INTERVAL ()Lorg/partiql/ast/DataType;
public static fun INTERVAL (Lorg/partiql/ast/IntervalQualifier;)Lorg/partiql/ast/DataType;
public static fun LIST ()Lorg/partiql/ast/DataType;
public static fun NUMERIC ()Lorg/partiql/ast/DataType;
public static fun NUMERIC (I)Lorg/partiql/ast/DataType;
Expand Down Expand Up @@ -711,6 +715,7 @@ public final class org/partiql/ast/DataType : org/partiql/ast/AstEnum {
public fun getChildren ()Ljava/util/List;
public fun getElementType ()Lorg/partiql/ast/DataType;
public fun getFields ()Ljava/util/List;
public fun getIntervalQualifier ()Lorg/partiql/ast/IntervalQualifier;
public fun getLength ()Ljava/lang/Integer;
public fun getName ()Lorg/partiql/ast/Identifier;
public fun getPrecision ()Ljava/lang/Integer;
Expand Down Expand Up @@ -1061,6 +1066,52 @@ public class org/partiql/ast/Identifier$Simple$Builder {
public fun toString ()Ljava/lang/String;
}

public abstract class org/partiql/ast/IntervalQualifier : org/partiql/ast/AstNode {
public fun <init> ()V
}

public final class org/partiql/ast/IntervalQualifier$Range : org/partiql/ast/IntervalQualifier {
public fun <init> (Lorg/partiql/ast/DatetimeField;Ljava/lang/Integer;Lorg/partiql/ast/DatetimeField;Ljava/lang/Integer;)V
public fun accept (Lorg/partiql/ast/AstVisitor;Ljava/lang/Object;)Ljava/lang/Object;
public static fun builder ()Lorg/partiql/ast/IntervalQualifier$Range$Builder;
public fun equals (Ljava/lang/Object;)Z
public fun getChildren ()Ljava/util/List;
public fun getEndField ()Lorg/partiql/ast/DatetimeField;
public fun getEndFieldFractionalPrecision ()Ljava/lang/Integer;
public fun getStartField ()Lorg/partiql/ast/DatetimeField;
public fun getStartFieldPrecision ()Ljava/lang/Integer;
public fun hashCode ()I
}

public class org/partiql/ast/IntervalQualifier$Range$Builder {
public fun build ()Lorg/partiql/ast/IntervalQualifier$Range;
public fun endField (Lorg/partiql/ast/DatetimeField;)Lorg/partiql/ast/IntervalQualifier$Range$Builder;
public fun endFieldFractionalPrecision (Ljava/lang/Integer;)Lorg/partiql/ast/IntervalQualifier$Range$Builder;
public fun leadingFieldPrecision (Ljava/lang/Integer;)Lorg/partiql/ast/IntervalQualifier$Range$Builder;
public fun startField (Lorg/partiql/ast/DatetimeField;)Lorg/partiql/ast/IntervalQualifier$Range$Builder;
public fun toString ()Ljava/lang/String;
}

public final class org/partiql/ast/IntervalQualifier$Single : org/partiql/ast/IntervalQualifier {
public fun <init> (Lorg/partiql/ast/DatetimeField;Ljava/lang/Integer;Ljava/lang/Integer;)V
public fun accept (Lorg/partiql/ast/AstVisitor;Ljava/lang/Object;)Ljava/lang/Object;
public static fun builder ()Lorg/partiql/ast/IntervalQualifier$Single$Builder;
public fun equals (Ljava/lang/Object;)Z
public fun getChildren ()Ljava/util/List;
public fun getField ()Lorg/partiql/ast/DatetimeField;
public fun getFractionalPrecision ()Ljava/lang/Integer;
public fun getPrecision ()Ljava/lang/Integer;
public fun hashCode ()I
}

public class org/partiql/ast/IntervalQualifier$Single$Builder {
public fun build ()Lorg/partiql/ast/IntervalQualifier$Single;
public fun field (Lorg/partiql/ast/DatetimeField;)Lorg/partiql/ast/IntervalQualifier$Single$Builder;
public fun fractionalPrecision (Ljava/lang/Integer;)Lorg/partiql/ast/IntervalQualifier$Single$Builder;
public fun precision (Ljava/lang/Integer;)Lorg/partiql/ast/IntervalQualifier$Single$Builder;
public fun toString ()Ljava/lang/String;
}

public final class org/partiql/ast/JoinType : org/partiql/ast/AstEnum {
public static final field CROSS I
public static final field FULL I
Expand Down
12 changes: 12 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 @@ -423,6 +423,18 @@ public R visitLiteral(Literal node, C ctx) {
return defaultVisit(node, ctx);
}

public R visitIntervalQualifier(IntervalQualifier node, C ctx) {
return node.accept(this, ctx);
}

public R visitIntervalQualifierRange(IntervalQualifier.Range node, C ctx) {
return defaultVisit(node, ctx);
}

public R visitIntervalQualifierSingle(IntervalQualifier.Single node, C ctx) {
return defaultVisit(node, ctx);
}

public R visitQueryBody(QueryBody node, C ctx) {
return node.accept(this, ctx);
}
Expand Down
69 changes: 69 additions & 0 deletions partiql-ast/src/main/java/org/partiql/ast/DataType.java
Original file line number Diff line number Diff line change
Expand Up @@ -427,10 +427,25 @@ public static DataType TIMESTAMP_WITH_TIME_ZONE(int precision) {
return new DataType(TIMESTAMP_WITH_TIME_ZONE, precision, null, null);
}

/**
* Returns a data type with code {@link #INTERVAL}, however, the interval qualifier is null.
* @deprecated Use {@link #INTERVAL(IntervalQualifier)} instead.
* @return a data type with code {@link #INTERVAL}, however, the interval qualifier is null.
*/
@Deprecated
public static DataType INTERVAL() {
return new DataType(INTERVAL);
}

/**
* Returns a data type with code {@link #INTERVAL} and the specified interval qualifier.
* @param qualifier The interval qualifier.
* @return a data type with code {@link #INTERVAL} and the specified interval qualifier.
*/
public static DataType INTERVAL(@NotNull IntervalQualifier qualifier) {
return new DataType(qualifier);
}

public static DataType USER_DEFINED() {
return new DataType(USER_DEFINED);
}
Expand All @@ -455,6 +470,7 @@ public static DataType STRUCT(List<StructField> fields) {
private final DataType elementType;
private final List<StructField> fields;
private final Identifier name;
private final IntervalQualifier intervalQualifier;

// Private constructor for no parameter DataTypes
private DataType(int code) {
Expand All @@ -465,6 +481,46 @@ private DataType(int code) {
this.elementType = null;
this.fields = null;
this.name = null;
this.intervalQualifier = null;
}

/**
* Creates a data type with code {@link #INTERVAL} and the specified interval qualifier.
* @param intervalQualifier the interval qualifier.
*/
private DataType(IntervalQualifier intervalQualifier) {
this(INTERVAL, null, null, null, null, null, null, intervalQualifier);
}

/**
* The constructor for DataTypes with all parameters.
* @param code the code of the data type
* @param precision the precision of the data type
* @param scale the scale of the data type
* @param length the length of the data type
* @param elementType the element type of the data type
* @param fields the fields of the data type
* @param name the name of the data type
* @param intervalQualifier the interval qualifier of the data type
*/
private DataType(
int code,
Integer precision,
Integer scale,
Integer length,
DataType elementType,
List<StructField> fields,
Identifier name,
IntervalQualifier intervalQualifier
) {
this.code = code;
this.precision = precision;
this.scale = scale;
this.length = length;
this.elementType = elementType;
this.fields = fields;
this.name = name;
this.intervalQualifier = intervalQualifier;
}

// Private constructor for DataTypes with Integer parameters; set `name` to null
Expand All @@ -476,6 +532,7 @@ private DataType(int code, Integer precision, Integer scale, Integer length) {
this.elementType = null;
this.fields = null;
this.name = null;
this.intervalQualifier = null;
}

// Private constructor for DataTypes with elementType parameter; set `name` to null
Expand All @@ -487,6 +544,7 @@ private DataType(int code, DataType elementType) {
this.elementType = elementType;
this.fields = null;
this.name = null;
this.intervalQualifier = null;
}

private DataType(int code, List<StructField> fields) {
Expand All @@ -497,6 +555,7 @@ private DataType(int code, List<StructField> fields) {
this.elementType = null;
this.fields = fields;
this.name = null;
this.intervalQualifier = null;
}

// Private constructor for user-defined type w/ an `IdentifierChain` `name`; other parameters set to null
Expand All @@ -508,6 +567,7 @@ private DataType(int code, Identifier name) {
this.length = null;
this.elementType = null;
this.fields = null;
this.intervalQualifier = null;
}

@Override
Expand Down Expand Up @@ -718,6 +778,15 @@ public List<StructField> getFields() {
return fields;
}

/**
* Returns the interval qualifier of this data type. If there is no interval qualifier, null is returned.
* @return the interval qualifier of this data type. If there is no interval qualifier, null is returned.
*/
@Nullable
public IntervalQualifier getIntervalQualifier() {
return intervalQualifier;
}

@NotNull
@Override
public List<AstNode> getChildren() {
Expand Down
Loading
Loading