Skip to content

Commit

Permalink
Fixes aggregation typing
Browse files Browse the repository at this point in the history
  • Loading branch information
RCHowell committed Nov 6, 2023
1 parent 930675f commit 8632024
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
6 changes: 3 additions & 3 deletions partiql-ast/src/main/kotlin/org/partiql/ast/sql/SqlDialect.kt
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,8 @@ public abstract class SqlDialect : AstBaseVisitor<SqlBlock, SqlBlock>() {
if (f is Identifier.Symbol && f.symbol == "COUNT_STAR") {
return h concat r("COUNT(*)")
}
val start = if (node.setq != null) "(${node.setq!!.name} " else "("
h = h concat visitIdentifier(f, h)
val start = if (node.setq != null) "(${node.setq.name} " else "("
h = visitIdentifier(f, h)
h = h concat list(start) { node.args }
return h
}
Expand Down Expand Up @@ -601,7 +601,7 @@ public abstract class SqlDialect : AstBaseVisitor<SqlBlock, SqlBlock>() {
override fun visitSelectProjectItemExpression(node: Select.Project.Item.Expression, head: SqlBlock): SqlBlock {
var h = head
h = visitExprWrapped(node.expr, h)
h = if (node.asAlias != null) h concat r(" AS ${node.asAlias!!.sql()}") else h
h = if (node.asAlias != null) h concat r(" AS ${node.asAlias.sql()}") else h
return h
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2533,6 +2533,12 @@ class PartiQLSchemaInferencerTests {
)
)
),
SuccessTestCase(
name = "Subquery scalar coercion",
catalog = "subqueries",
key = PartiQLTest.Key("subquery", "subquery-03"),
expected = BOOL,
),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import org.partiql.plan.fnResolved
import org.partiql.plan.identifierSymbol
import org.partiql.plan.rel
import org.partiql.plan.relBinding
import org.partiql.plan.relOpAggregate
import org.partiql.plan.relOpAggregateCall
import org.partiql.plan.relOpErr
import org.partiql.plan.relOpFilter
Expand Down Expand Up @@ -367,7 +368,9 @@ internal class PlanTyper(

// rewrite with typed calls and groups
val type = ctx!!.copyWithSchema(schema)
val op = node.copy(
val op = relOpAggregate(
input = input,
strategy = node.strategy,
calls = calls.map { it.first },
groups = groups,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ SELECT t.*, s.*
FROM T AS t
JOIN (SELECT * FROM S) AS s
ON t.x = s.a;

--#[subquery-03]
1 = (SELECT COUNT(*) FROM T);

0 comments on commit 8632024

Please sign in to comment.