Skip to content
Merged
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
360 changes: 311 additions & 49 deletions pkg/partitionservice/service.go

Large diffs are not rendered by default.

10 changes: 1 addition & 9 deletions pkg/partitionservice/service_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,6 @@ func (s *Service) getMetadataByListType(
def,
desc,
partition.PartitionMethod_List,
func(p *tree.Partition) string {
ctx := tree.NewFmtCtx(
dialect.MYSQL,
tree.WithQuoteIdentifier(),
tree.WithSingleQuoteString(),
)
p.Values.Format(ctx)
return ctx.String()
},
getExpr,
)
}
10 changes: 1 addition & 9 deletions pkg/partitionservice/service_range.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,6 @@ func (s *Service) getMetadataByRangeType(
def,
desc,
partition.PartitionMethod_Range,
func(p *tree.Partition) string {
ctx := tree.NewFmtCtx(
dialect.MYSQL,
tree.WithQuoteIdentifier(),
tree.WithSingleQuoteString(),
)
p.Values.Format(ctx)
return ctx.String()
},
getExpr,
)
}
92 changes: 91 additions & 1 deletion pkg/partitionservice/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,103 @@ func TestDelete(t *testing.T) {
assert.NoError(t, s.Create(ctx, tableID, stmt, txnOp))

require.NoError(t, txnOp.Commit(ctx))
require.Empty(t, s.mu.tables)

require.NoError(t, s.Delete(ctx, tableID, nil))
},
)
}

func TestRedefine(t *testing.T) {
runTestPartitionServiceTest(
func(
ctx context.Context,
txnOp client.TxnOperator,
s *Service,
store PartitionStorage,
) {
require.Error(t, s.Redefine(ctx, 1, nil, txnOp))
},
)
}

func TestRenamePartition(t *testing.T) {
runTestPartitionServiceTest(
func(
ctx context.Context,
txnOp client.TxnOperator,
s *Service,
store PartitionStorage,
) {
require.Error(t, s.Rename(ctx, 1, "old", "new", txnOp))
},
)
}

func TestAddPartitions(t *testing.T) {
runTestPartitionServiceTest(
func(
ctx context.Context,
txnOp client.TxnOperator,
s *Service,
store PartitionStorage,
) {
require.Error(t, s.AddPartitions(ctx, 1, nil, txnOp))

tableID := uint64(1)
num := uint64(2)
columns := []string{"a"}
def := newTestTablePartitionDefine(1, columns, []types.T{types.T_int8}, num, partition.PartitionMethod_Hash)
memStore := store.(*memStorage)
memStore.addUncommittedTable(def)

stmt := newTestHashOption(t, columns[0], num)
assert.NoError(t, s.Create(ctx, tableID, stmt, txnOp))
require.NoError(t, txnOp.Commit(ctx))

require.Error(t, s.AddPartitions(ctx, tableID, nil, txnOp))
},
)
}

func TestDropPartitions(t *testing.T) {
runTestPartitionServiceTest(
func(
ctx context.Context,
txnOp client.TxnOperator,
s *Service,
store PartitionStorage,
) {
require.Error(t, s.DropPartitions(ctx, 1, nil, txnOp))

tableID := uint64(1)
num := uint64(2)
columns := []string{"a"}
def := newTestTablePartitionDefine(1, columns, []types.T{types.T_int8}, num, partition.PartitionMethod_Hash)
memStore := store.(*memStorage)
memStore.addUncommittedTable(def)

stmt := newTestHashOption(t, columns[0], num)
assert.NoError(t, s.Create(ctx, tableID, stmt, txnOp))
require.NoError(t, txnOp.Commit(ctx))

require.Error(t, s.DropPartitions(ctx, tableID, nil, txnOp))
},
)
}

func TestTruncatePartitions(t *testing.T) {
runTestPartitionServiceTest(
func(
ctx context.Context,
txnOp client.TxnOperator,
s *Service,
store PartitionStorage,
) {
require.Error(t, s.TruncatePartitions(ctx, 1, nil, txnOp))
},
)
}

func TestIterResult(t *testing.T) {
res := PruneResult{
batches: make([]*batch.Batch, 10),
Expand Down
Loading
Loading