Skip to content

Commit e7bdc78

Browse files
committed
Adds PError.EXPERIMENTAL, and adds to window parsing/planning
Adds deprecation notices to APIs
1 parent 1767018 commit e7bdc78

File tree

17 files changed

+110
-5
lines changed

17 files changed

+110
-5
lines changed

partiql-ast/src/main/java/org/partiql/ast/WindowClause.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111
* Represents a PartiQL WINDOW clause.
1212
* @see WindowDefinition
1313
* @see org.partiql.ast.expr.ExprWindowFunction
14+
* @deprecated This feature is experimental and is subject to change.
1415
*/
1516
@Builder(builderClassName = "Builder")
1617
@EqualsAndHashCode(callSuper = false)
18+
@Deprecated
1719
public final class WindowClause extends AstNode {
1820

1921
@NotNull

partiql-ast/src/main/java/org/partiql/ast/WindowFunctionNullTreatment.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
/**
1010
* The null treatment for window functions.
1111
* @see WindowFunctionType.LeadOrLag#getNullTreatment()
12+
* @deprecated This feature is experimental and is subject to change.
1213
*/
1314
@EqualsAndHashCode(callSuper = false)
15+
@Deprecated
1416
public final class WindowFunctionNullTreatment extends AstEnum {
1517
/**
1618
* The RESPECT NULLS variant of the null treatment.

partiql-ast/src/main/java/org/partiql/ast/WindowFunctionType.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,20 @@
1212

1313
/**
1414
* Represents a window function type.
15-
* @see ExprWindowFunction#getFunctionType()
15+
* @see ExprWindowFunction#getFunctionType()
16+
* @deprecated This feature is experimental and is subject to change.
1617
*/
18+
@Deprecated
1719
public abstract class WindowFunctionType extends AstNode {
1820

1921
/**
2022
* The RANK window function.
2123
* @see ExprWindowFunction#getFunctionType()
24+
* @deprecated This feature is experimental and is subject to change.
2225
*/
2326
@Builder(builderClassName = "Builder")
2427
@EqualsAndHashCode(callSuper = false)
28+
@Deprecated
2529
public static final class Rank extends WindowFunctionType {
2630
private int _type;
2731

@@ -71,9 +75,11 @@ public <R, C> R accept(@NotNull AstVisitor<R, C> visitor, C ctx) {
7175
/**
7276
* The CUME_DIST window function.
7377
* @see ExprWindowFunction#getFunctionType()
78+
* @deprecated This feature is experimental and is subject to change.
7479
*/
7580
@Builder(builderClassName = "Builder")
7681
@EqualsAndHashCode(callSuper = false)
82+
@Deprecated
7783
public static final class CumeDist extends WindowFunctionType {
7884
/**
7985
* Constructs a CUME_DIST window function.
@@ -95,9 +101,11 @@ public <R, C> R accept(@NotNull AstVisitor<R, C> visitor, C ctx) {
95101
/**
96102
* The ROW_NUMBER window function.
97103
* @see ExprWindowFunction#getFunctionType()
104+
* @deprecated This feature is experimental and is subject to change.
98105
*/
99106
@Builder(builderClassName = "Builder")
100107
@EqualsAndHashCode(callSuper = false)
108+
@Deprecated
101109
public static final class RowNumber extends WindowFunctionType {
102110

103111
/**
@@ -122,7 +130,9 @@ public <R, C> R accept(@NotNull AstVisitor<R, C> visitor, C ctx) {
122130
* @see ExprWindowFunction#getFunctionType()
123131
* @see Lead
124132
* @see Lag
133+
* @deprecated This feature is experimental and is subject to change.
125134
*/
135+
@Deprecated
126136
public interface LeadOrLag {
127137
/**
128138
* Returns the extent of the window function.
@@ -156,9 +166,11 @@ public interface LeadOrLag {
156166
/**
157167
* Represents the LEAD window function.
158168
* @see ExprWindowFunction#getFunctionType()
169+
* @deprecated This feature is experimental and is subject to change.
159170
*/
160171
@Builder(builderClassName = "Builder")
161172
@EqualsAndHashCode(callSuper = false)
173+
@Deprecated
162174
public static final class Lead extends WindowFunctionType implements LeadOrLag {
163175
private final Expr extent;
164176
private final Long offset;
@@ -226,9 +238,11 @@ public <R, C> R accept(@NotNull AstVisitor<R, C> visitor, C ctx) {
226238
/**
227239
* Represents the LAG window function.
228240
* @see ExprWindowFunction#getFunctionType()
241+
* @deprecated This feature is experimental and is subject to change.
229242
*/
230243
@Builder(builderClassName = "Builder")
231244
@EqualsAndHashCode(callSuper = false)
245+
@Deprecated
232246
public static final class Lag extends WindowFunctionType implements LeadOrLag {
233247
private final Expr extent;
234248
private final Long offset;

partiql-ast/src/main/java/org/partiql/ast/WindowPartition.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,18 @@
1111
* Represents a partition specified by a window specification.
1212
* @see Name
1313
* @see WindowSpecification#getPartitionClause()
14+
* @deprecated This feature is experimental and is subject to change.
1415
*/
16+
@Deprecated
1517
public abstract class WindowPartition extends AstNode {
1618
/**
1719
* Represents a partition specified by a name.
1820
* @see WindowSpecification#getPartitionClause()
21+
* @deprecated This feature is experimental and is subject to change.
1922
*/
2023
@Builder(builderClassName = "Builder")
2124
@EqualsAndHashCode(callSuper = false)
25+
@Deprecated
2226
public static final class Name extends WindowPartition {
2327
private final Identifier columnReference;
2428

partiql-ast/src/main/java/org/partiql/ast/WindowSpecification.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111
/**
1212
* Represents a window specification or a window reference.
1313
* @see WindowClause.WindowDefinition#getSpecification()
14+
* @deprecated This feature is experimental and is subject to change.
1415
*/
1516
@Builder(builderClassName = "Builder")
1617
@EqualsAndHashCode(callSuper = false)
18+
@Deprecated
1719
public final class WindowSpecification extends AstNode {
1820
// TODO: In the future: @Nullable private final WindowFrameClause frameClause;
1921

partiql-cli/src/main/kotlin/org/partiql/cli/ErrorCodeString.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,6 @@ enum class ErrorCodeString(val code: Int) {
2828
NUMERIC_VALUE_OUT_OF_RANGE(PError.NUMERIC_VALUE_OUT_OF_RANGE),
2929
INVALID_CHAR_VALUE_FOR_CAST(PError.INVALID_CHAR_VALUE_FOR_CAST),
3030
DIVISION_BY_ZERO(PError.DIVISION_BY_ZERO),
31-
DEGREE_VIOLATION_SCALAR_SUBQUERY(PError.DEGREE_VIOLATION_SCALAR_SUBQUERY)
31+
DEGREE_VIOLATION_SCALAR_SUBQUERY(PError.DEGREE_VIOLATION_SCALAR_SUBQUERY),
32+
EXPERIMENTAL(PError.EXPERIMENTAL),
3233
}

partiql-cli/src/main/kotlin/org/partiql/cli/pipeline/ErrorMessageFormatter.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ object ErrorMessageFormatter {
3737
ErrorCodeString.DIVISION_BY_ZERO -> divisionByZero(error)
3838
ErrorCodeString.TYPE_UNEXPECTED -> typeUnexpected(error)
3939
ErrorCodeString.DEGREE_VIOLATION_SCALAR_SUBQUERY -> degreeViolationScalarSubquery(error)
40+
ErrorCodeString.EXPERIMENTAL -> experimental(error)
4041
ErrorCodeString.ALL -> "INTERNAL ERROR: This should never have occurred."
4142
null -> "Unrecognized error code received: ${error.code()}"
4243
}
@@ -141,6 +142,15 @@ object ErrorMessageFormatter {
141142
return "Degree of scalar subquery must be 1 (one).$actualTypeStr"
142143
}
143144

145+
/**
146+
* @see PError.EXPERIMENTAL
147+
*/
148+
private fun experimental(error: PError): String {
149+
val actualType = error.getOrNull("FEATURE", String::class.java)
150+
val actualTypeStr = prepare(actualType.toString(), " (", ")")
151+
return "Feature$actualTypeStr is experimental and is subject to change."
152+
}
153+
144154
/**
145155
* @see PError.TYPE_UNEXPECTED
146156
*/

partiql-parser/src/main/kotlin/org/partiql/parser/internal/PErrors.kt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.partiql.parser.internal
22

3+
import org.antlr.v4.runtime.ParserRuleContext
34
import org.partiql.spi.SourceLocation
45
import org.partiql.spi.errors.PError
56
import org.partiql.spi.errors.PErrorKind
@@ -51,4 +52,33 @@ internal object PErrors {
5152
)
5253
)
5354
}
55+
56+
/**
57+
* @return an error representing [PError.EXPERIMENTAL]
58+
*/
59+
internal fun experimental(
60+
feature: String,
61+
ctx: ParserRuleContext,
62+
): PError {
63+
val location = ctxToLocation(ctx)
64+
return PError(
65+
PError.EXPERIMENTAL,
66+
Severity.WARNING(),
67+
PErrorKind.SYNTAX(),
68+
location,
69+
mapOf(
70+
"FEATURE" to feature
71+
)
72+
)
73+
}
74+
75+
private fun ctxToLocation(ctx: ParserRuleContext): SourceLocation? {
76+
val start = ctx.start
77+
val stop = ctx.stop
78+
if (start == null || stop == null) {
79+
return null
80+
}
81+
val length = ctx.sourceInterval.length()
82+
return SourceLocation(start.line.toLong(), start.charPositionInLine + 1L, length.toLong())
83+
}
5484
}

partiql-parser/src/main/kotlin/org/partiql/parser/internal/PartiQLParserDefault.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ internal class PartiQLParserDefault : PartiQLParser {
287287
else -> throw IllegalArgumentException("Unsupported parser mode: $mode")
288288
}
289289
val tree = parser.statements()
290-
return Visitor.translate(tokens, tree)
290+
return Visitor.translate(tokens, tree, listener)
291291
}
292292

293293
private fun createTokenStream(source: String, listener: PErrorListener): CountingTokenStream {
@@ -391,6 +391,7 @@ internal class PartiQLParserDefault : PartiQLParser {
391391
private val tokens: CommonTokenStream,
392392
private val locations: MutableMap<Int, SourceLocation>,
393393
private val parameters: Map<Int, Int> = mapOf(),
394+
private val listener: PErrorListener
394395
) : PartiQLParserBaseVisitor<AstNode>() {
395396
// Counter to store unique AstNode tags
396397
private var counter = 0
@@ -415,9 +416,10 @@ internal class PartiQLParserDefault : PartiQLParser {
415416
fun translate(
416417
tokens: CountingTokenStream,
417418
tree: GeneratedParser.StatementsContext,
419+
listener: PErrorListener
418420
): PartiQLParser.Result {
419421
val locations = mutableMapOf<Int, SourceLocation>()
420-
val visitor = Visitor(tokens, locations, tokens.parameterIndexes)
422+
val visitor = Visitor(tokens, locations, tokens.parameterIndexes, listener)
421423
val statements = tree.statement().map { statementCtx ->
422424
visitor.visit(statementCtx) as Statement
423425
}
@@ -1080,6 +1082,7 @@ internal class PartiQLParserDefault : PartiQLParser {
10801082
*/
10811083

10821084
override fun visitWindowClause(ctx: GeneratedParser.WindowClauseContext) = translate(ctx) {
1085+
listener.report(PErrors.experimental("Window Clause", ctx))
10831086
val definitions = visitOrEmpty<WindowClause.WindowDefinition>(ctx.windowDefinition())
10841087
WindowClause(definitions)
10851088
}
@@ -2000,6 +2003,7 @@ internal class PartiQLParserDefault : PartiQLParser {
20002003
* Window Functions
20012004
*/
20022005
override fun visitWindowFunction(ctx: GeneratedParser.WindowFunctionContext) = translate(ctx) {
2006+
listener.report(PErrors.experimental("Window Function", ctx))
20032007
val type = visitAs<WindowFunctionType>(ctx.windowFunctionType())
20042008
val ref = visit(ctx.windowNameOrSpecification()) as WindowSpecification
20052009
ExprWindowFunction(type, ref)

partiql-plan/src/main/java/org/partiql/plan/WindowFunctionNode.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
/**
99
* Represents a window function node.
1010
* @see WindowFunctionSignature
11+
* @deprecated This feature is experimental and is subject to change.
1112
*/
13+
@Deprecated
1214
public final class WindowFunctionNode {
1315

1416
private final WindowFunctionSignature signature;

0 commit comments

Comments
 (0)