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

Initial implementation of partitions (Create statement) #8691

Merged
merged 16 commits into from
Nov 17, 2021
Merged
Show file tree
Hide file tree
Changes from 7 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
47 changes: 40 additions & 7 deletions go/vt/sqlparser/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,13 +464,14 @@ type (

// CreateTable represents a CREATE TABLE statement.
CreateTable struct {
Temp bool
Table TableName
IfNotExists bool
TableSpec *TableSpec
OptLike *OptLike
Comments Comments
FullyParsed bool
Temp bool
Table TableName
IfNotExists bool
TableSpec *TableSpec
OptLike *OptLike
Comments Comments
FullyParsed bool
PartitionOption *PartitionOption
Thirumalai-Shaktivel marked this conversation as resolved.
Show resolved Hide resolved
}

// CreateView represents a CREATE VIEW query
Expand Down Expand Up @@ -1471,6 +1472,38 @@ type PartitionDefinition struct {
Maxvalue bool
}

// PartitionOption describes partitioning control (for create table statements)
type PartitionOption struct {
Linear string
HASH ColIdent
isKEY bool
KeyAlgorithm string
KeyColList Columns
RangeOrList string
ExprOrCol *ExprOrColumns
Expr Expr
Partitions string
SubPartition *SubPartition
Definitions []*PartitionDefinition
}

// ExprOrColumns describes expression and columnlist in the partition
type ExprOrColumns struct {
Expr Expr
ColumnList Columns
}

// SubPartition describes subpartitions control
type SubPartition struct {
Linear string
HASH ColIdent
isKEY bool
KeyAlgorithm string
KeyColList Columns
Expr Expr
SubPartitions string
}

// TableOptions specifies a list of table options
type TableOptions []*TableOption

Expand Down
45 changes: 45 additions & 0 deletions go/vt/sqlparser/ast_clone.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

71 changes: 70 additions & 1 deletion go/vt/sqlparser/ast_equals.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

88 changes: 88 additions & 0 deletions go/vt/sqlparser/ast_format.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,91 @@ func (node *PartitionDefinition) Format(buf *TrackedBuffer) {
}
}

// Format formats the node.
func (node *PartitionOption) Format(buf *TrackedBuffer) {
buf.WriteString("partition by")
if !node.HASH.IsEmpty() {
if node.Linear != "" {
buf.astPrintf(node, " %s", node.Linear)
}
buf.astPrintf(node, " %v", node.HASH)
if node.Expr != nil {
buf.astPrintf(node, " (%v)", node.Expr)
}
}
if node.isKEY {
if node.Linear != "" {
buf.astPrintf(node, " %s", node.Linear)
}
buf.WriteString(" key")
if node.KeyAlgorithm != "" {
buf.astPrintf(node, " algorithm = %s", node.KeyAlgorithm)
}
if node.KeyColList != nil {
buf.astPrintf(node, " %v", node.KeyColList)
}
}
if node.RangeOrList != "" {
buf.astPrintf(node, " %s", node.RangeOrList)
buf.astPrintf(node, " %v", node.ExprOrCol)
}
if node.Partitions != "" {
buf.astPrintf(node, " partitions %s", node.Partitions)
}
if node.SubPartition != nil {
buf.astPrintf(node, " %v", node.SubPartition)
}
if node.Definitions != nil {
buf.WriteString(" (")
for i, pd := range node.Definitions {
if i != 0 {
buf.WriteString(", ")
}
buf.astPrintf(node, "%v", pd)
}
buf.WriteString(")")
}
}

// Format formats the node.
func (node *SubPartition) Format(buf *TrackedBuffer) {
buf.WriteString("subpartition by")
if !node.HASH.IsEmpty() {
if node.Linear != "" {
buf.astPrintf(node, " %s", node.Linear)
}
buf.astPrintf(node, " %v", node.HASH)
if node.Expr != nil {
buf.astPrintf(node, " (%v)", node.Expr)
}
}
if node.isKEY {
if node.Linear != "" {
buf.astPrintf(node, " %s", node.Linear)
}
buf.WriteString(" key")
if node.KeyAlgorithm != "" {
buf.astPrintf(node, " algorithm = %s", node.KeyAlgorithm)
}
if node.KeyColList != nil {
buf.astPrintf(node, " (%v)", node.KeyColList)
}
}
if node.SubPartitions != "" {
buf.astPrintf(node, " subpartitions %s", node.SubPartitions)
}
}

// Format formats the node.
func (node *ExprOrColumns) Format(buf *TrackedBuffer) {
if node.Expr != nil {
buf.astPrintf(node, "(%v)", node.Expr)
}
if node.ColumnList != nil {
buf.astPrintf(node, "columns %v", node.ColumnList)
}
}

// Format formats the node.
func (ts *TableSpec) Format(buf *TrackedBuffer) {
buf.astPrintf(ts, "(\n")
Expand Down Expand Up @@ -1435,6 +1520,9 @@ func (node *CreateTable) Format(buf *TrackedBuffer) {
if node.TableSpec != nil {
buf.astPrintf(node, " %v", node.TableSpec)
}
if node.PartitionOption != nil {
buf.astPrintf(node, " %v", node.PartitionOption)
}
}

// Format formats the node.
Expand Down
Loading