Skip to content

Commit 66ad7fc

Browse files
committed
minor
1 parent d18162a commit 66ad7fc

File tree

1 file changed

+42
-33
lines changed

1 file changed

+42
-33
lines changed

partiql-ast/src/main/java/org/partiql/ast/sql/SqlDialect.kt

Lines changed: 42 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import org.partiql.ast.SetOpType
4949
import org.partiql.ast.SetQuantifier
5050
import org.partiql.ast.Sort
5151
import org.partiql.ast.WindowClause
52+
import org.partiql.ast.WindowFunctionNullTreatment
5253
import org.partiql.ast.WindowFunctionType
5354
import org.partiql.ast.WindowPartition
5455
import org.partiql.ast.WindowSpecification
@@ -201,6 +202,7 @@ public abstract class SqlDialect : AstVisitor<SqlBlock, SqlBlock>() {
201202
}
202203

203204
// Window Function Methods
205+
@Deprecated("This feature is experimental and is subject to change.")
204206
override fun visitExprWindowFunction(node: ExprWindowFunction, tail: SqlBlock): SqlBlock {
205207
var t = tail
206208
t = visitWindowFunctionType(node.functionType, t)
@@ -209,73 +211,52 @@ public abstract class SqlDialect : AstVisitor<SqlBlock, SqlBlock>() {
209211
return t
210212
}
211213

214+
@Deprecated("This feature is experimental and is subject to change.")
212215
override fun visitWindowFunctionType(node: WindowFunctionType, tail: SqlBlock): SqlBlock {
213216
return node.accept(this, tail)
214217
}
215218

219+
@Deprecated("This feature is experimental and is subject to change.")
216220
override fun visitWindowFunctionTypeRank(node: WindowFunctionType.Rank, tail: SqlBlock): SqlBlock {
217221
return tail concat "RANK()"
218222
}
219223

224+
@Deprecated("This feature is experimental and is subject to change.")
220225
override fun visitWindowFunctionTypeDenseRank(node: WindowFunctionType.DenseRank, tail: SqlBlock): SqlBlock {
221226
return tail concat "DENSE_RANK()"
222227
}
223228

229+
@Deprecated("This feature is experimental and is subject to change.")
224230
override fun visitWindowFunctionTypePercentRank(node: WindowFunctionType.PercentRank, tail: SqlBlock): SqlBlock {
225231
return tail concat "PERCENT_RANK()"
226232
}
227233

234+
@Deprecated("This feature is experimental and is subject to change.")
228235
override fun visitWindowFunctionTypeCumeDist(node: WindowFunctionType.CumeDist, tail: SqlBlock): SqlBlock {
229236
return tail concat "CUME_DIST()"
230237
}
231238

239+
@Deprecated("This feature is experimental and is subject to change.")
232240
override fun visitWindowFunctionTypeRowNumber(node: WindowFunctionType.RowNumber, tail: SqlBlock): SqlBlock {
233241
return tail concat "ROW_NUMBER()"
234242
}
235243

244+
@Deprecated("This feature is experimental and is subject to change.")
236245
override fun visitWindowFunctionTypeLead(node: WindowFunctionType.Lead, tail: SqlBlock): SqlBlock {
237-
var t = tail concat "LEAD("
238-
t = visitExpr(node.extent, t)
239-
node.offset?.let {
240-
t = t concat ", $it"
241-
}
242-
243-
node.defaultValue.let { defaultValue ->
244-
t = t concat ", "
245-
t = visitExpr(defaultValue, t)
246-
}
247-
248-
t = t concat ")"
249-
node.nullTreatment?.let { nullTreatment ->
250-
t = t concat " ${nullTreatment.name()}"
251-
}
252-
253-
return t
246+
return visitWindowFunctionTypeLeadOrLag("LEAD(", node.extent, node.offset, node.defaultValue, node.nullTreatment, tail)
254247
}
255248

249+
@Deprecated("This feature is experimental and is subject to change.")
256250
override fun visitWindowFunctionTypeLag(node: WindowFunctionType.Lag, tail: SqlBlock): SqlBlock {
257-
var t = tail concat "LAG("
258-
t = visitExpr(node.extent, t)
259-
node.offset?.let {
260-
t = t concat ", $it"
261-
}
262-
263-
node.defaultValue.let { defaultValue ->
264-
t = t concat ", "
265-
t = visitExpr(defaultValue, t)
266-
}
267-
268-
t = t concat ")"
269-
node.nullTreatment?.let { nullTreatment ->
270-
t = t concat " ${nullTreatment.name()}"
271-
}
272-
return t
251+
return visitWindowFunctionTypeLeadOrLag("LAG(", node.extent, node.offset, node.defaultValue, node.nullTreatment, tail)
273252
}
274253

254+
@Deprecated("This feature is experimental and is subject to change.")
275255
override fun visitWindowPartition(node: WindowPartition, tail: SqlBlock): SqlBlock {
276256
return visitExprWrapped(node.columnReference, tail)
277257
}
278258

259+
@Deprecated("This feature is experimental and is subject to change.")
279260
override fun visitWindowSpecification(node: WindowSpecification, tail: SqlBlock): SqlBlock {
280261
var t = tail
281262
if (node.existingName != null) {
@@ -302,12 +283,14 @@ public abstract class SqlDialect : AstVisitor<SqlBlock, SqlBlock>() {
302283
return t
303284
}
304285

286+
@Deprecated("This feature is experimental and is subject to change.")
305287
override fun visitWindowClause(node: WindowClause, tail: SqlBlock): SqlBlock {
306288
var t = tail concat "WINDOW "
307289
t = t concat list(start = null, end = null) { node.definitions }
308290
return t
309291
}
310292

293+
@Deprecated("This feature is experimental and is subject to change.")
311294
override fun visitWindowDefinition(node: WindowClause.Definition, tail: SqlBlock): SqlBlock {
312295
var t = tail
313296
t = visitIdentifierSimple(node.name, t)
@@ -1063,6 +1046,32 @@ public abstract class SqlDialect : AstVisitor<SqlBlock, SqlBlock>() {
10631046
return next!!
10641047
}
10651048

1049+
private fun visitWindowFunctionTypeLeadOrLag(
1050+
prefix: String,
1051+
extent: Expr,
1052+
offset: Long?,
1053+
defaultValue: Expr?,
1054+
nullTreatment: WindowFunctionNullTreatment?,
1055+
tail: SqlBlock
1056+
): SqlBlock {
1057+
var t = tail concat prefix
1058+
t = visitExpr(extent, t)
1059+
offset?.let {
1060+
t = t concat ", $it"
1061+
}
1062+
1063+
defaultValue?.let { defaultValue ->
1064+
t = t concat ", "
1065+
t = visitExpr(defaultValue, t)
1066+
}
1067+
1068+
t = t concat ")"
1069+
nullTreatment?.let { nullTreatment ->
1070+
t = t concat " ${nullTreatment.name()}"
1071+
}
1072+
return t
1073+
}
1074+
10661075
private fun type(symbol: String, vararg args: Int?, gap: Boolean = false): SqlBlock {
10671076
val p = args.filterNotNull()
10681077
val t = when {

0 commit comments

Comments
 (0)