-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added full Postgres AST to Vitess AST conversion
- Loading branch information
1 parent
b8bbaad
commit 4eda5d4
Showing
148 changed files
with
6,646 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// Copyright 2023 Dolthub, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License 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 ast | ||
|
||
import ( | ||
"fmt" | ||
"sync/atomic" | ||
|
||
vitess "github.com/dolthub/vitess/go/vt/sqlparser" | ||
|
||
"github.com/dolthub/doltgresql/postgres/parser/sem/tree" | ||
) | ||
|
||
// uniqueAliasCounter is used to create unique aliases. Aliases are required by GMS when some expressions are contained | ||
// within a vitess.AliasedTableExpr. The Postgres AST does not have this restriction, so we must do this for | ||
// compatibility. Callers are free to change the alias if need be, but we'll always set an alias to be safe. | ||
var uniqueAliasCounter atomic.Uint64 | ||
|
||
// nodeAliasedTableExpr handles *tree.AliasedTableExpr nodes. | ||
func nodeAliasedTableExpr(node *tree.AliasedTableExpr) (*vitess.AliasedTableExpr, error) { | ||
if node.Ordinality { | ||
return nil, fmt.Errorf("ordinality is not yet supported") | ||
} | ||
if node.IndexFlags != nil { | ||
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 | ||
aliasExpr, err = nodeTableName(expr) | ||
if err != nil { | ||
return nil, err | ||
} | ||
default: | ||
tableExpr, err := nodeTableExpr(expr) | ||
if err != nil { | ||
return nil, err | ||
} | ||
subquery := &vitess.Subquery{ | ||
Select: &vitess.Select{ | ||
From: vitess.TableExprs{tableExpr}, | ||
}, | ||
} | ||
//TODO: make sure that this actually works | ||
if len(node.As.Cols) > 0 { | ||
columns := make([]vitess.ColIdent, len(node.As.Cols)) | ||
for i := range node.As.Cols { | ||
columns[i] = vitess.NewColIdent(string(node.As.Cols[i])) | ||
} | ||
subquery.Columns = columns | ||
} | ||
aliasExpr = subquery | ||
} | ||
alias := string(node.As.Alias) | ||
if len(alias) == 0 { | ||
alias = generateUniqueAlias() | ||
} | ||
return &vitess.AliasedTableExpr{ | ||
Expr: aliasExpr, | ||
As: vitess.NewTableIdent(alias), | ||
AsOf: nil, | ||
Lateral: node.Lateral, | ||
}, nil | ||
} | ||
|
||
// generateUniqueAlias generates a unique alias. This is thread-safe. | ||
func generateUniqueAlias() string { | ||
return fmt.Sprintf("doltgres!|alias|%d", uniqueAliasCounter.Add(1)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright 2023 Dolthub, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License 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 ast | ||
|
||
import ( | ||
"fmt" | ||
|
||
vitess "github.com/dolthub/vitess/go/vt/sqlparser" | ||
|
||
"github.com/dolthub/doltgresql/postgres/parser/sem/tree" | ||
) | ||
|
||
// nodeAlterDatabaseOwner handles *tree.AlterDatabaseOwner nodes. | ||
func nodeAlterDatabaseOwner(node *tree.AlterDatabaseOwner) (vitess.Statement, error) { | ||
if node == nil { | ||
return nil, nil | ||
} | ||
return nil, fmt.Errorf("ALTER DATABASE OWNER is not yet supported") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright 2023 Dolthub, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License 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 ast | ||
|
||
import ( | ||
"fmt" | ||
|
||
vitess "github.com/dolthub/vitess/go/vt/sqlparser" | ||
|
||
"github.com/dolthub/doltgresql/postgres/parser/sem/tree" | ||
) | ||
|
||
// nodeAlterIndex handles *tree.AlterIndex nodes. | ||
func nodeAlterIndex(node *tree.AlterIndex) (vitess.Statement, error) { | ||
if node == nil { | ||
return nil, nil | ||
} | ||
// Only PARTITION alterations are supported by the parser, so there's nothing to convert to yet | ||
return nil, fmt.Errorf("ALTER INDEX is not yet supported") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright 2023 Dolthub, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License 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 ast | ||
|
||
import ( | ||
"fmt" | ||
|
||
vitess "github.com/dolthub/vitess/go/vt/sqlparser" | ||
|
||
"github.com/dolthub/doltgresql/postgres/parser/sem/tree" | ||
) | ||
|
||
// nodeAlterRole handles *tree.AlterRole nodes. | ||
func nodeAlterRole(node *tree.AlterRole) (vitess.Statement, error) { | ||
if node == nil { | ||
return nil, nil | ||
} | ||
return nil, fmt.Errorf("ALTER ROLE is not yet supported") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright 2023 Dolthub, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License 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 ast | ||
|
||
import ( | ||
"fmt" | ||
|
||
vitess "github.com/dolthub/vitess/go/vt/sqlparser" | ||
|
||
"github.com/dolthub/doltgresql/postgres/parser/sem/tree" | ||
) | ||
|
||
// nodeAlterSchema handles *tree.AlterSchema nodes. | ||
func nodeAlterSchema(node *tree.AlterSchema) (vitess.Statement, error) { | ||
if node == nil { | ||
return nil, nil | ||
} | ||
return nil, fmt.Errorf("ALTER SCHEMA is not yet supported") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright 2023 Dolthub, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License 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 ast | ||
|
||
import ( | ||
"fmt" | ||
|
||
vitess "github.com/dolthub/vitess/go/vt/sqlparser" | ||
|
||
"github.com/dolthub/doltgresql/postgres/parser/sem/tree" | ||
) | ||
|
||
// nodeAlterSequence handles *tree.AlterSequence nodes. | ||
func nodeAlterSequence(node *tree.AlterSequence) (vitess.Statement, error) { | ||
if node == nil { | ||
return nil, nil | ||
} | ||
return nil, fmt.Errorf("ALTER SEQUENCE is not yet supported") | ||
} |
Oops, something went wrong.