Skip to content

Commit 17a387f

Browse files
committed
Adds PError.EXPERIMENTAL, and adds to window parsing/planning
Adds deprecation notices to APIs
1 parent 2ea8a71 commit 17a387f

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
@@ -35,6 +35,7 @@ object ErrorMessageFormatter {
3535
ErrorCodeString.DIVISION_BY_ZERO -> divisionByZero(error)
3636
ErrorCodeString.TYPE_UNEXPECTED -> typeUnexpected(error)
3737
ErrorCodeString.DEGREE_VIOLATION_SCALAR_SUBQUERY -> degreeViolationScalarSubquery(error)
38+
ErrorCodeString.EXPERIMENTAL -> experimental(error)
3839
ErrorCodeString.ALL -> "INTERNAL ERROR: This should never have occurred."
3940
null -> "Unrecognized error code received: ${error.code()}"
4041
}
@@ -139,6 +140,15 @@ object ErrorMessageFormatter {
139140
return "Degree of scalar subquery must be 1 (one).$actualTypeStr"
140141
}
141142

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

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
@@ -286,7 +286,7 @@ internal class PartiQLParserDefault : PartiQLParser {
286286
else -> throw IllegalArgumentException("Unsupported parser mode: $mode")
287287
}
288288
val tree = parser.statements()
289-
return Visitor.translate(tokens, tree)
289+
return Visitor.translate(tokens, tree, listener)
290290
}
291291

292292
private fun createTokenStream(source: String, listener: PErrorListener): CountingTokenStream {
@@ -390,6 +390,7 @@ internal class PartiQLParserDefault : PartiQLParser {
390390
private val tokens: CommonTokenStream,
391391
private val locations: MutableMap<Int, SourceLocation>,
392392
private val parameters: Map<Int, Int> = mapOf(),
393+
private val listener: PErrorListener
393394
) : PartiQLParserBaseVisitor<AstNode>() {
394395
// Counter to store unique AstNode tags
395396
private var counter = 0
@@ -414,9 +415,10 @@ internal class PartiQLParserDefault : PartiQLParser {
414415
fun translate(
415416
tokens: CountingTokenStream,
416417
tree: GeneratedParser.StatementsContext,
418+
listener: PErrorListener
417419
): PartiQLParser.Result {
418420
val locations = mutableMapOf<Int, SourceLocation>()
419-
val visitor = Visitor(tokens, locations, tokens.parameterIndexes)
421+
val visitor = Visitor(tokens, locations, tokens.parameterIndexes, listener)
420422
val statements = tree.statement().map { statementCtx ->
421423
visitor.visit(statementCtx) as Statement
422424
}
@@ -1079,6 +1081,7 @@ internal class PartiQLParserDefault : PartiQLParser {
10791081
*/
10801082

10811083
override fun visitWindowClause(ctx: GeneratedParser.WindowClauseContext) = translate(ctx) {
1084+
listener.report(PErrors.experimental("Window Clause", ctx))
10821085
val definitions = visitOrEmpty<WindowClause.WindowDefinition>(ctx.windowDefinition())
10831086
WindowClause(definitions)
10841087
}
@@ -1993,6 +1996,7 @@ internal class PartiQLParserDefault : PartiQLParser {
19931996
* Window Functions
19941997
*/
19951998
override fun visitWindowFunction(ctx: GeneratedParser.WindowFunctionContext) = translate(ctx) {
1999+
listener.report(PErrors.experimental("Window Function", ctx))
19962000
val type = visitAs<WindowFunctionType>(ctx.windowFunctionType())
19972001
val ref = visit(ctx.windowNameOrSpecification()) as WindowSpecification
19982002
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)