Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/dolthub/dolt/go v0.40.5-0.20260710173237-7bdcf6ee8148
github.com/dolthub/eventsapi_schema v0.0.0-20260310172945-37a9265ade69
github.com/dolthub/flatbuffers/v23 v23.3.3-dh.2
github.com/dolthub/go-mysql-server v0.20.1-0.20260709233935-b8ef331dca43
github.com/dolthub/go-mysql-server v0.20.1-0.20260709234404-e06e93647d00
github.com/dolthub/pg_query_go/v6 v6.0.0-20251215122834-fb20be4254d1
github.com/dolthub/sqllogictest/go v0.0.0-20260624223518-788480b24166
github.com/dolthub/vitess v0.0.0-20260624214226-81d034e0fde8
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,10 @@ github.com/dolthub/fslock v0.0.5 h1:QoXhBhgY1oumHE26qyE7tgmXUT8qjJwxsIzo54O/B/k=
github.com/dolthub/fslock v0.0.5/go.mod h1:sdofYYqE0D79zNZyB4/kmlnsQOVap1C2yByjGKSirEM=
github.com/dolthub/go-icu-regex v0.0.0-20260610153742-72563bc7ca83 h1:FEMjCGEroDnY/BXyAffVZxUpXhP2GpoUJyyq5KaLn8c=
github.com/dolthub/go-icu-regex v0.0.0-20260610153742-72563bc7ca83/go.mod h1:F3cnm+vMRK1HaU6+rNqQrOCyR03HHhR1GWG2gnPOqaE=
github.com/dolthub/go-mysql-server v0.20.1-0.20260709233935-b8ef331dca43 h1:BrDle6fyYfw4wxfzD4mD0R+PXT80e7Vl9UHWtKA58qw=
github.com/dolthub/go-mysql-server v0.20.1-0.20260709233935-b8ef331dca43/go.mod h1:mj5/QX3V8i92REbA1w6CzyknJAFdKtdE7l931405C/E=
github.com/dolthub/go-mysql-server v0.20.1-0.20260709224106-fecf6bb54eb0 h1:IUbkgDsRcl3pNZB3AhdLQo5DGPijmwa6f9f40Qi3WxY=
github.com/dolthub/go-mysql-server v0.20.1-0.20260709224106-fecf6bb54eb0/go.mod h1:mj5/QX3V8i92REbA1w6CzyknJAFdKtdE7l931405C/E=
github.com/dolthub/go-mysql-server v0.20.1-0.20260709234404-e06e93647d00 h1:tQY5FOiUFKzcSqJQleh0NCVUXuPLvxl1iPQ5KtFvrbo=
github.com/dolthub/go-mysql-server v0.20.1-0.20260709234404-e06e93647d00/go.mod h1:mj5/QX3V8i92REbA1w6CzyknJAFdKtdE7l931405C/E=
github.com/dolthub/gozstd v0.0.0-20240423170813-23a2903bca63 h1:OAsXLAPL4du6tfbBgK0xXHZkOlos63RdKYS3Sgw/dfI=
github.com/dolthub/gozstd v0.0.0-20240423170813-23a2903bca63/go.mod h1:lV7lUeuDhH5thVGDCKXbatwKy2KW80L4rMT46n+Y2/Q=
github.com/dolthub/ishell v0.0.0-20260414231531-5f031e3e9037 h1:oIW9HwuWrhxv+4HZxA+QQSKHLqWFyXZ2FmNjUYwkdiM=
Expand Down
2 changes: 1 addition & 1 deletion postgres/parser/parser/sql.y
Original file line number Diff line number Diff line change
Expand Up @@ -13630,7 +13630,7 @@ over_clause:
}
| OVER window_name
{
$$.val = &tree.WindowDef{Name: tree.Name($2)}
$$.val = &tree.WindowDef{RefName: tree.Name($2)}
}
| /* EMPTY */
{
Expand Down
16 changes: 16 additions & 0 deletions server/analyzer/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ func initEngine() {
plan.ValidateForeignKeyDefinition = validateForeignKeyDefinition

planbuilder.IsAggregateFunc = IsAggregateFunc
planbuilder.IsWindowFunc = IsWindowFunc

expression.DefaultExpressionFactory = pgexpression.PostgresExpressionFactory{}

Expand All @@ -148,6 +149,21 @@ func IsAggregateFunc(name string) bool {
return false
}

// IsWindowFunc checks if the given function name is a window function. This is the entire set supported by
// MySQL plus some postgres specific ones.
func IsWindowFunc(name string) bool {
if planbuilder.IsMySQLWindowFuncName(name) {
return true
}

switch name {
case "array_agg", "bool_and", "bool_or":
return true
}

return false
}

// insertAnalyzerRules inserts the given rule(s) before or after the given analyzer.RuleId, returning an updated slice.
func insertAnalyzerRules(rules []analyzer.Rule, id analyzer.RuleId, before bool, additionalRules ...analyzer.Rule) []analyzer.Rule {
inserted := false
Expand Down
12 changes: 10 additions & 2 deletions server/analyzer/type_sanitizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,17 @@ func TypeSanitizer(ctx *sql.Context, a *analyzer.Analyzer, node sql.Node, scope
case sql.FunctionExpression:
// Compiled functions are Doltgres functions. We're only concerned with GMS functions.
if _, ok := expr.(framework.Function); !ok {
// Some aggregation functions cannot be wrapped due to expectations in the analyzer, so we exclude them here.
// Aggregation/window-only expressions (Sum, Avg, Count, BitAnd, Rank, ...) can't be
// Eval()'d directly - only via NewBuffer/NewWindowFunction - so wrapping one in
// GMSCast (which evaluates its child directly) breaks it.
// sql.WindowAdaptableExpression is the common parent interface for both sql.Aggregation
// and sql.WindowAggregation, so checking it covers every current and future case in one
// shot. Only the *outer* reference to an aggregate's result (a GetField, handled
// elsewhere in this function) still needs its declared type corrected.
if _, ok := expr.(sql.WindowAdaptableExpression); ok {
return expr, transform.SameTree, nil
}
switch expr.FunctionName() {
case "Count", "CountDistinct", "group_concat", "JSONObjectAgg", "Sum":
case "coalesce":
// Replace GMS Coalesce with a Doltgres-native implementation that uses
// Postgres type-resolution rules (FindCommonType) to infer the result type.
Expand Down
Loading
Loading