Skip to content

Commit

Permalink
add linear hash partition support (#21331)
Browse files Browse the repository at this point in the history
add linear hash partition support

Approved by: @iamlinjunhong
  • Loading branch information
zhangxu19830126 authored Jan 23, 2025
1 parent 399c518 commit fa2ec45
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 145 deletions.
8 changes: 3 additions & 5 deletions pkg/partitionservice/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,8 @@ func (s *service) getManualPartitions(
TableName: def.Name,
DatabaseName: def.DbName,
Method: method,
// TODO: ???
Expression: "",
Description: partitionDesc,
Columns: validColumns,
Description: partitionDesc,
Columns: validColumns,
}

for i, p := range option.Partitions {
Expand All @@ -308,7 +306,7 @@ func (s *service) getManualPartitions(
Name: p.Name.String(),
PartitionTableName: fmt.Sprintf("%s_%s", def.Name, p.Name.String()),
Position: uint32(i),
Comment: applyPartitionComment(p),
Expression: applyPartitionComment(p),
},
)
}
Expand Down
14 changes: 8 additions & 6 deletions pkg/partitionservice/service_hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,18 @@ func (s *service) getMetadataByHashType(
)
method.Expr.Format(ctx)

pm := partition.PartitionMethod_Hash
if method.Linear {
pm = partition.PartitionMethod_LinearHash
}

metadata := partition.PartitionMetadata{
TableID: def.TblId,
TableName: def.Name,
DatabaseName: def.DbName,
Method: partition.PartitionMethod_Hash,
// TODO: ???
Expression: "",
Description: ctx.String(),
Columns: validColumns,
Method: pm,
Description: ctx.String(),
Columns: validColumns,
}

for i := uint64(0); i < option.PartBy.Num; i++ {
Expand All @@ -77,7 +80,6 @@ func (s *service) getMetadataByHashType(
Name: name,
PartitionTableName: fmt.Sprintf("%s_%s", def.Name, name),
Position: uint32(i),
Comment: "",
},
)
}
Expand Down
17 changes: 6 additions & 11 deletions pkg/partitionservice/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ func (s *storage) GetMetadata(
table_name,
database_name,
partition_method,
partition_expression,
partition_description,
partition_count
from %s
Expand Down Expand Up @@ -135,9 +134,8 @@ func (s *storage) GetMetadata(
metadata.Method = partition.PartitionMethod(
partition.PartitionMethod_value[executor.GetStringRows(cols[2])[i]],
)
metadata.Expression = executor.GetStringRows(cols[3])[i]
metadata.Description = executor.GetStringRows(cols[4])[i]
n = executor.GetFixedRows[uint32](cols[5])[i]
metadata.Description = executor.GetStringRows(cols[3])[i]
n = executor.GetFixedRows[uint32](cols[4])[i]
}
return true
},
Expand All @@ -156,7 +154,7 @@ func (s *storage) GetMetadata(
partition_table_name ,
partition_name ,
partition_ordinal_position,
partition_comment
partition_expression
from %s
where
primary_table_id = %d
Expand Down Expand Up @@ -187,7 +185,7 @@ func (s *storage) GetMetadata(
PartitionTableName: executor.GetStringRows(cols[1])[i],
Name: executor.GetStringRows(cols[2])[i],
Position: executor.GetFixedRows[uint32](cols[3])[i],
Comment: executor.GetStringRows(cols[4])[i],
Expression: executor.GetStringRows(cols[4])[i],
},
)
}
Expand Down Expand Up @@ -372,7 +370,7 @@ func (s *storage) createPartitionTable(
primary_table_id,
partition_name,
partition_ordinal_position,
partition_comment
partition_expression
)
values
(
Expand All @@ -390,7 +388,7 @@ func (s *storage) createPartitionTable(
metadata.TableID,
partition.Name,
partition.Position,
partition.Comment,
partition.Expression,
)

res, err := txn.Exec(
Expand Down Expand Up @@ -493,7 +491,6 @@ func getInsertMetadataSQL(
table_name,
database_name,
partition_method,
partition_expression,
partition_description,
partition_count
)
Expand All @@ -503,7 +500,6 @@ func getInsertMetadataSQL(
'%s',
'%s',
'%s',
'%s',
'%s',
%d
)`,
Expand All @@ -513,7 +509,6 @@ func getInsertMetadataSQL(
metadata.TableName,
metadata.DatabaseName,
metadata.Method.String(),
metadata.Expression,
metadata.Description,
len(metadata.Partitions),
)
Expand Down
3 changes: 1 addition & 2 deletions pkg/partitionservice/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ var (
table_name varchar(500) not null,
database_name varchar(500) not null,
partition_method varchar(13) not null,
partition_expression varchar(2048) not null,
partition_description text not null,
partition_count int unsigned
)`, catalog.MO_CATALOG, catalog.MOPartitionMetadata)
Expand All @@ -44,7 +43,7 @@ var (
primary_table_id bigint unsigned not null,
partition_name varchar(50) not null,
partition_ordinal_position int unsigned not null,
partition_comment text
partition_expression varchar(2048) not null
)`, catalog.MO_CATALOG, catalog.MOPartitionTables)

InitSQLs = []string{
Expand Down
Loading

0 comments on commit fa2ec45

Please sign in to comment.