Skip to content

Commit

Permalink
Merge branch 'main' into fix-any-type-in-anyoftype
Browse files Browse the repository at this point in the history
  • Loading branch information
RCHowell authored Mar 29, 2024
2 parents 16a5220 + 327ea86 commit 7d1ff16
Show file tree
Hide file tree
Showing 9 changed files with 995 additions and 3 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Deprecated
### Fixed
- Fixes typing of CASE-WHEN by applying the rules from SQL-99 9.3 for minimal common supertype.
### Removed
### Security
### Contributors
Thank you to all who have contributed!
- @<your-username>
- @rchowell
-->

Expand All @@ -33,9 +34,12 @@ Thank you to all who have contributed!
- Change `StaticType.AnyOfType`'s `.toString` to not perform `.flatten()`

### Deprecated
- The current SqlBlock, SqlDialect, and SqlLayout are marked as deprecated and will be slightly changed in the next release.

### Fixed
- `StaticType.flatten()` on an `AnyOfType` with `AnyType` will return `AnyType`
- Updates the default `.sql()` method to use a more efficient (internal) printer implementation.


### Removed

Expand All @@ -44,6 +48,8 @@ Thank you to all who have contributed!
### Contributors
Thank you to all who have contributed!
- @<your-username>
- @rchowell
- @alancai98

## [0.14.4]

Expand Down
30 changes: 28 additions & 2 deletions partiql-ast/src/main/kotlin/org/partiql/ast/sql/Sql.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,41 @@
package org.partiql.ast.sql

import org.partiql.ast.AstNode
import org.partiql.ast.sql.internal.InternalSqlDialect
import org.partiql.ast.sql.internal.InternalSqlLayout

/**
* No argument uses optimized internal. Leaving older ones for backwards-compatibility.
*/
public fun AstNode.sql(): String {
val head = InternalSqlDialect.PARTIQL.apply(this)
return InternalSqlLayout.format(head)
}

/**
* Pretty-print this [AstNode] as SQL text with the given [SqlLayout]
*/
@JvmOverloads
@Deprecated("To be removed in the next major version")
public fun AstNode.sql(
layout: SqlLayout = SqlLayout.DEFAULT,
): String = SqlDialect.PARTIQL.apply(this).sql(layout)

/**
* Pretty-print this [AstNode] as SQL text with the given [SqlDialect]
*/
@Deprecated("To be removed in the next major version")
public fun AstNode.sql(
dialect: SqlDialect = SqlDialect.PARTIQL,
): String = accept(dialect, SqlBlock.Nil).sql(layout)
): String = dialect.apply(this).sql(SqlLayout.DEFAULT)

/**
* Pretty-print this [AstNode] as SQL text with the given [SqlLayout] and [SqlDialect]
*/
@Deprecated("To be removed in the next major version")
public fun AstNode.sql(
layout: SqlLayout,
dialect: SqlDialect,
): String = dialect.apply(this).sql(layout)

// a <> b <-> a concat b

Expand Down
4 changes: 4 additions & 0 deletions partiql-ast/src/main/kotlin/org/partiql/ast/sql/SqlBlock.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ package org.partiql.ast.sql
* @param layout SQL formatting ruleset
* @return SQL text
*/
@Deprecated("To be removed in the next major version")
public fun SqlBlock.sql(layout: SqlLayout = SqlLayout.DEFAULT): String = layout.format(this)

/**
* Representation of some textual corpus; akin to Wadler's "A prettier printer" Document type.
*/
@Deprecated("This will be changed in the next major version")
sealed interface SqlBlock {

public override fun toString(): String
Expand Down Expand Up @@ -54,6 +56,7 @@ sealed interface SqlBlock {
}
}

@Deprecated("This will be changed in the next major version")
public interface BlockVisitor<R, C> {

public fun visit(block: SqlBlock, ctx: C): R
Expand All @@ -69,6 +72,7 @@ public interface BlockVisitor<R, C> {
public fun visitLink(block: SqlBlock.Link, ctx: C): R
}

@Deprecated("This will be changed in the next major version")
public abstract class BlockBaseVisitor<R, C> : BlockVisitor<R, C> {

public abstract fun defaultReturn(block: SqlBlock, ctx: C): R
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import java.io.PrintStream
/**
* SqlDialect represents the base behavior for transforming an [AstNode] tree into a [SqlBlock] tree.
*/
@Deprecated("This will be changed in the next major version")
@Suppress("PARAMETER_NAME_CHANGED_ON_OVERRIDE")
public abstract class SqlDialect : AstBaseVisitor<SqlBlock, SqlBlock>() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.partiql.ast.sql
/**
* [SqlLayout] determines how an [SqlBlock] tree is transformed in SQL text.
*/
@Deprecated("This will be changed in the next major version")
public abstract class SqlLayout {

abstract val indent: Indent
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at:
*
* http://aws.amazon.com/apache2.0/
*
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/

package org.partiql.ast.sql.internal

/**
* Representation of some textual elements as a token (singly-linked) list.
*/
internal sealed class InternalSqlBlock {

/**
* Next token (if any) in the list.
*/
internal var next: InternalSqlBlock? = null

/**
* A newline / link break token.
*/
internal class NL : InternalSqlBlock()

/**
* A raw text token. Cannot be broken.
*/
internal class Text(val text: String) : InternalSqlBlock()

/**
* A nest token representing a (possible indented) token sublist.
*
* @property prefix A prefix character such as '{', '(', or '['.
* @property postfix A postfix character such as '}', ')', or ']].
* @property child
*/
internal class Nest(
val prefix: String?,
val postfix: String?,
val child: InternalSqlBlock,
) : InternalSqlBlock()

companion object {

/**
* Helper function to create root node (empty).
*/
@JvmStatic
internal fun root(): InternalSqlBlock = Text("")
}
}
Loading

0 comments on commit 7d1ff16

Please sign in to comment.