Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unskip tests for dolt_revert #820

Merged
merged 21 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from 19 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
117 changes: 98 additions & 19 deletions postgres/parser/parser/sql.y
Original file line number Diff line number Diff line change
Expand Up @@ -1261,7 +1261,7 @@ func (u *sqlSymUnion) aggregatesToDrop() []tree.AggregateToDrop {
%type <bool> opt_ordinality opt_compact
%type <*tree.Order> sortby
%type <tree.IndexElem> index_elem index_elem_name_only partition_index_elem
%type <tree.TableExpr> table_ref numeric_table_ref func_table
%type <tree.TableExpr> table_ref numeric_table_ref func_table table_ref_options
%type <tree.Exprs> rowsfrom_list
%type <tree.Expr> rowsfrom_item
%type <tree.TableExpr> joined_table
Expand Down Expand Up @@ -10764,9 +10764,9 @@ values_clause:
// where_clause - qualifications for joins or restrictions

from_clause:
FROM from_list opt_as_of_clause
FROM from_list
{
$$.val = tree.From{Tables: $2.tblExprs(), AsOf: $3.asOfClause()}
$$.val = tree.From{Tables: $2.tblExprs()}
}
| FROM error // SHOW HELP: <SOURCE>
| /* EMPTY */
Expand Down Expand Up @@ -10880,25 +10880,18 @@ opt_index_flags:
//
// %SeeAlso: WEBDOCS/table-expressions.html
table_ref:
numeric_table_ref opt_index_flags opt_ordinality opt_alias_clause
numeric_table_ref table_ref_options
{
/* SKIP DOC */
$$.val = &tree.AliasedTableExpr{
Expr: $1.tblExpr(),
IndexFlags: $2.indexFlags(),
Ordinality: $3.bool(),
As: $4.aliasClause(),
}
$$ = $2
$$.val.(*tree.AliasedTableExpr).Expr = $1.tblExpr()
}
| relation_expr opt_index_flags opt_ordinality opt_alias_clause
| relation_expr table_ref_options
{
/* SKIP DOC */
$$ = $2
name := $1.unresolvedObjectName().ToTableName()
$$.val = &tree.AliasedTableExpr{
Expr: &name,
IndexFlags: $2.indexFlags(),
Ordinality: $3.bool(),
As: $4.aliasClause(),
}
$$.val.(*tree.AliasedTableExpr).Expr = &name
}
| select_with_parens opt_ordinality opt_alias_clause
{
Expand Down Expand Up @@ -10965,6 +10958,61 @@ table_ref:
$$.val = &tree.AliasedTableExpr{Expr: &tree.StatementSource{ Statement: $2.stmt() }, Ordinality: $4.bool(), As: $5.aliasClause() }
}

// table_ref_options is the set of all possible combinations of AS OF and alias, since the optional versions of those
// rules create shift/reduce conflicts if they're combined in same rule
table_ref_options:
opt_index_flags opt_ordinality
{
/* SKIP DOC */
$$.val = &tree.AliasedTableExpr{
IndexFlags: $1.indexFlags(),
Ordinality: $2.bool(),
}
}
| opt_index_flags opt_ordinality alias_clause
{
/* SKIP DOC */
$$.val = &tree.AliasedTableExpr{
IndexFlags: $1.indexFlags(),
Ordinality: $2.bool(),
As: $3.aliasClause(),
}
}
| opt_index_flags opt_ordinality as_of_clause
{
/* SKIP DOC */
asOf := $3.asOfClause()
$$.val = &tree.AliasedTableExpr{
IndexFlags: $1.indexFlags(),
Ordinality: $2.bool(),
AsOf: &asOf,
}
}
| opt_index_flags opt_ordinality as_of_clause AS table_alias_name opt_column_list
{
/* SKIP DOC */
alias := tree.AliasClause{Alias: tree.Name($5), Cols: $6.nameList()}
asOf := $3.asOfClause()
$$.val = &tree.AliasedTableExpr{
IndexFlags: $1.indexFlags(),
Ordinality: $2.bool(),
AsOf: &asOf,
As: alias,
}
}
| opt_index_flags opt_ordinality as_of_clause table_alias_name opt_column_list
{
/* SKIP DOC */
alias := tree.AliasClause{Alias: tree.Name($4), Cols: $5.nameList()}
asOf := $3.asOfClause()
$$.val = &tree.AliasedTableExpr{
IndexFlags: $1.indexFlags(),
Ordinality: $2.bool(),
AsOf: &asOf,
As: alias,
}
}

numeric_table_ref:
'[' iconst64 opt_tableref_col_list alias_clause ']'
{
Expand Down Expand Up @@ -11086,12 +11134,43 @@ opt_alias_clause:
$$.val = tree.AliasClause{}
}

// as_of_clause is limited to constants and a few function expressions. The entire expressoin tree is too permissive,
// and causes many conflicts elsewhere in the rest of the grammar.
// These clauses are chosen carefully from the d_expr list.
as_of_clause:
AS_LA OF SYSTEM TIME a_expr
AS_LA OF SYSTEM TIME SCONST
{
$$.val = tree.AsOfClause{Expr: tree.NewStrVal($5)}
}
| AS_LA OF SYSTEM TIME typed_literal
{
$$.val = tree.AsOfClause{Expr: $5.expr()}
}

| AS_LA OF SYSTEM TIME func_expr_common_subexpr
{
$$.val = tree.AsOfClause{Expr: $5.expr()}
}
| AS_LA OF SYSTEM TIME func_application
{
$$.val = tree.AsOfClause{Expr: $5.expr()}
}
| AS_LA OF SCONST
{
$$.val = tree.AsOfClause{Expr: tree.NewStrVal($3)}
}
| AS_LA OF typed_literal
{
$$.val = tree.AsOfClause{Expr: $3.expr()}
}
| AS_LA OF func_expr_common_subexpr
{
$$.val = tree.AsOfClause{Expr: $3.expr()}
}
| AS_LA OF func_application
{
$$.val = tree.AsOfClause{Expr: $3.expr()}
}

opt_as_of_clause:
as_of_clause
| /* EMPTY */
Expand Down
15 changes: 9 additions & 6 deletions postgres/parser/sem/tree/pretty.go
Original file line number Diff line number Diff line change
Expand Up @@ -597,12 +597,6 @@ func (node *From) docRow(p *PrettyCfg) pretty.TableRow {
return emptyRow
}
d := node.Tables.doc(p)
if node.AsOf.Expr != nil {
d = p.nestUnder(
d,
p.Doc(&node.AsOf),
)
}
return p.row("FROM", d)
}

Expand Down Expand Up @@ -688,6 +682,15 @@ func (node *AliasedTableExpr) doc(p *PrettyCfg) pretty.Doc {
p.keywordWithText(" ", "WITH ORDINALITY", ""),
)
}
if node.AsOf != nil {
d = p.nestUnder(
d,
pretty.Concat(
p.keywordWithText("", "AS OF SYSTEM TIME", " "),
p.Doc(node.AsOf),
),
)
}
if node.As.Alias != "" {
d = p.nestUnder(
d,
Expand Down
10 changes: 5 additions & 5 deletions postgres/parser/sem/tree/select.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,17 +222,12 @@ func (a *AsOfClause) Format(ctx *FmtCtx) {
// From represents a FROM clause.
type From struct {
Tables TableExprs
AsOf AsOfClause
}

// Format implements the NodeFormatter interface.
func (node *From) Format(ctx *FmtCtx) {
ctx.WriteString("FROM ")
ctx.FormatNode(&node.Tables)
if node.AsOf.Expr != nil {
ctx.WriteByte(' ')
ctx.FormatNode(&node.AsOf)
}
}

// TableExprs represents a list of table expressions.
Expand Down Expand Up @@ -400,6 +395,7 @@ type AliasedTableExpr struct {
Ordinality bool
Lateral bool
As AliasClause
AsOf *AsOfClause
}

// Format implements the NodeFormatter interface.
Expand All @@ -414,6 +410,10 @@ func (node *AliasedTableExpr) Format(ctx *FmtCtx) {
if node.Ordinality {
ctx.WriteString(" WITH ORDINALITY")
}
if node.AsOf != nil {
ctx.WriteString(" AS OF SYSTEM TIME ")
ctx.FormatNode(node.AsOf)
}
if node.As.Alias != "" {
ctx.WriteString(" AS ")
ctx.FormatNode(&node.As)
Expand Down
11 changes: 0 additions & 11 deletions postgres/parser/sem/tree/walk.go
Original file line number Diff line number Diff line change
Expand Up @@ -1178,7 +1178,6 @@ func (stmt *SelectClause) copyNode() *SelectClause {
stmtCopy.Exprs = append(SelectExprs(nil), stmt.Exprs...)
stmtCopy.From = From{
Tables: append(TableExprs(nil), stmt.From.Tables...),
AsOf: stmt.From.AsOf,
}
if stmt.Where != nil {
wCopy := *stmt.Where
Expand Down Expand Up @@ -1207,16 +1206,6 @@ func (stmt *SelectClause) walkStmt(v Visitor) Statement {
}
}

if stmt.From.AsOf.Expr != nil {
e, changed := WalkExpr(v, stmt.From.AsOf.Expr)
if changed {
if ret == stmt {
ret = stmt.copyNode()
}
ret.From.AsOf.Expr = e
}
}

if stmt.Where != nil {
e, changed := WalkExpr(v, stmt.Where.Expr)
if changed {
Expand Down
16 changes: 15 additions & 1 deletion server/ast/aliased_table_expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func nodeAliasedTableExpr(node *tree.AliasedTableExpr) (*vitess.AliasedTableExpr
return nil, fmt.Errorf("index flags are not yet supported")
}
var aliasExpr vitess.SimpleTableExpr

switch expr := node.Expr.(type) {
case *tree.TableName:
var err error
Expand Down Expand Up @@ -94,10 +95,23 @@ func nodeAliasedTableExpr(node *tree.AliasedTableExpr) (*vitess.AliasedTableExpr
return nil, fmt.Errorf("unhandled table expression: `%T`", expr)
}
alias := string(node.As.Alias)

var asOf *vitess.AsOf
if node.AsOf != nil {
asOfExpr, err := nodeExpr(node.AsOf.Expr)
if err != nil {
return nil, err
}
// TODO: other forms of AS OF (not just point in time)
asOf = &vitess.AsOf{
Time: asOfExpr,
}
}

return &vitess.AliasedTableExpr{
Expr: aliasExpr,
As: vitess.NewTableIdent(alias),
AsOf: nil,
AsOf: asOf,
Lateral: node.Lateral,
}, nil
}
19 changes: 0 additions & 19 deletions server/ast/from.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
package ast

import (
"fmt"

vitess "github.com/dolthub/vitess/go/vt/sqlparser"

"github.com/dolthub/doltgresql/postgres/parser/sem/tree"
Expand All @@ -27,26 +25,9 @@ func nodeFrom(node tree.From) (vitess.TableExprs, error) {
if len(node.Tables) == 0 {
return nil, nil
}
asOfExpr, err := nodeExpr(node.AsOf.Expr)
if err != nil {
return nil, err
}
tableExprs, err := nodeTableExprs(node.Tables)
if err != nil {
return nil, err
}
if asOfExpr != nil {
//TODO: determine if this will always be Time
asOf := &vitess.AsOf{
Time: asOfExpr,
}
for _, tableExpr := range tableExprs {
if aliasedTableExpr, ok := tableExpr.(*vitess.AliasedTableExpr); ok {
aliasedTableExpr.AsOf = asOf
} else {
return nil, fmt.Errorf("this particular usage of AS OF is not yet supported")
}
}
}
return tableExprs, err
}
4 changes: 0 additions & 4 deletions server/ast/select_clause.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ func nodeSelectClause(node *tree.SelectClause) (*vitess.Select, error) {
// pass along a join node.
// TODO: handle more than two tables, also make this more robust with handling more node types
if len(node.From.Tables) == 2 && node.Where != nil {
// We don't yet handle AS OF for rewrites
if node.From.AsOf.Expr != nil {
goto PostJoinRewrite
}
tableNames := make(map[tree.TableName]int)
tableAliases := make(map[tree.TableName]int)
// First we need to get the table names and aliases, since they'll be referenced by the filters
Expand Down
Loading
Loading