Skip to content

Commit

Permalink
Refactor splits to partitions (#6045)
Browse files Browse the repository at this point in the history
* Refactor `splits` to `partitions`

* Rename files

* Pretty prettier

* Backwards compatibility
  • Loading branch information
begelundmuller authored Nov 7, 2024
1 parent e7b1b3a commit 56e210b
Show file tree
Hide file tree
Showing 71 changed files with 1,914 additions and 1,698 deletions.
77 changes: 77 additions & 0 deletions cli/cmd/project/partitions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package project

import (
"fmt"

"github.com/rilldata/rill/cli/pkg/cmdutil"
runtimev1 "github.com/rilldata/rill/proto/gen/rill/runtime/v1"
"github.com/spf13/cobra"
)

func PartitionsCmd(ch *cmdutil.Helper) *cobra.Command {
var project, path, model string
var pending, errored, local bool
var pageSize uint32
var pageToken string

partitionsCmd := &cobra.Command{
Use: "partitions [<project>] <model>",
Args: cobra.RangeArgs(1, 2),
Short: "List partitions for a model",
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) == 1 {
model = args[0]
} else if len(args) == 2 {
project = args[0]
model = args[1]
}

if !local && !cmd.Flags().Changed("project") && len(args) <= 1 && ch.Interactive {
var err error
project, err = ch.InferProjectName(cmd.Context(), ch.Org, path)
if err != nil {
return err
}
}

rt, instanceID, err := ch.OpenRuntimeClient(cmd.Context(), ch.Org, project, local)
if err != nil {
return err
}

res, err := rt.GetModelPartitions(cmd.Context(), &runtimev1.GetModelPartitionsRequest{
InstanceId: instanceID,
Model: model,
Pending: pending,
Errored: errored,
PageSize: pageSize,
PageToken: pageToken,
})
if err != nil {
return fmt.Errorf("failed to get model partitions: %w", err)
}

ch.PrintModelPartitions(res.Partitions)

if res.NextPageToken != "" {
cmd.Println()
cmd.Printf("Next page token: %s\n", res.NextPageToken)
}

return nil
},
}

partitionsCmd.Flags().SortFlags = false
partitionsCmd.Flags().StringVar(&project, "project", "", "Project Name")
partitionsCmd.Flags().StringVar(&path, "path", ".", "Project directory")
partitionsCmd.Flags().StringVar(&model, "model", "", "Model Name")
partitionsCmd.Flags().BoolVar(&pending, "pending", false, "Only fetch pending partitions")
partitionsCmd.Flags().BoolVar(&errored, "errored", false, "Only fetch errored partitions")
partitionsCmd.MarkFlagsMutuallyExclusive("pending", "errored")
partitionsCmd.Flags().BoolVar(&local, "local", false, "Target locally running Rill")
partitionsCmd.Flags().Uint32Var(&pageSize, "page-size", 50, "Number of partitions to return per page")
partitionsCmd.Flags().StringVar(&pageToken, "page-token", "", "Pagination token")

return partitionsCmd
}
2 changes: 1 addition & 1 deletion cli/cmd/project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func ProjectCmd(ch *cmdutil.Helper) *cobra.Command {
projectCmd.AddCommand(HibernateCmd(ch))
projectCmd.AddCommand(DeleteCmd(ch))
projectCmd.AddCommand(StatusCmd(ch))
projectCmd.AddCommand(SplitsCmd(ch))
projectCmd.AddCommand(PartitionsCmd(ch))
projectCmd.AddCommand(LogsCmd(ch))
projectCmd.AddCommand(DescribeCmd(ch))
projectCmd.AddCommand(RefreshCmd(ch))
Expand Down
24 changes: 12 additions & 12 deletions cli/cmd/project/refresh.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
func RefreshCmd(ch *cmdutil.Helper) *cobra.Command {
var project, path string
var local bool
var models, modelSplits, sources, alerts, reports []string
var all, full, erroredSplits, parser bool
var models, modelPartitions, sources, alerts, reports []string
var all, full, erroredPartitions, parser bool

refreshCmd := &cobra.Command{
Use: "refresh [<project-name>]",
Expand Down Expand Up @@ -67,10 +67,10 @@ func RefreshCmd(ch *cmdutil.Helper) *cobra.Command {
}

// Build model triggers
if len(modelSplits) > 0 || erroredSplits {
// If splits are specified, ensure exactly one model is specified.
if len(modelPartitions) > 0 || erroredPartitions {
// If partitions are specified, ensure exactly one model is specified.
if len(models) != 1 {
return fmt.Errorf("must specify exactly one --model when using --split or --errored-splits")
return fmt.Errorf("must specify exactly one --model when using --partition or --errored-partitions")
}

// Since it's a common error, do an early check to ensure the model is incremental.
Expand All @@ -85,16 +85,16 @@ func RefreshCmd(ch *cmdutil.Helper) *cobra.Command {
}
m := resp.Resource.GetModel()
if !m.Spec.Incremental {
return fmt.Errorf("can't refresh splits on model %q because it is not incremental", mn)
return fmt.Errorf("can't refresh partitions on model %q because it is not incremental", mn)
}
}
var modelTriggers []*runtimev1.RefreshModelTrigger
for _, m := range models {
modelTriggers = append(modelTriggers, &runtimev1.RefreshModelTrigger{
Model: m,
Full: full,
AllErroredSplits: erroredSplits,
Splits: modelSplits,
Model: m,
Full: full,
AllErroredPartitions: erroredPartitions,
Partitions: modelPartitions,
})
}

Expand Down Expand Up @@ -129,8 +129,8 @@ func RefreshCmd(ch *cmdutil.Helper) *cobra.Command {
refreshCmd.Flags().BoolVar(&all, "all", false, "Refresh all sources and models (default)")
refreshCmd.Flags().BoolVar(&full, "full", false, "Fully reload the targeted models (use with --all or --model)")
refreshCmd.Flags().StringSliceVar(&models, "model", nil, "Refresh a model")
refreshCmd.Flags().StringSliceVar(&modelSplits, "split", nil, "Refresh a model split (must set --model)")
refreshCmd.Flags().BoolVar(&erroredSplits, "errored-splits", false, "Refresh all model splits with errors (must set --model)")
refreshCmd.Flags().StringSliceVar(&modelPartitions, "partition", nil, "Refresh a model partition (must set --model)")
refreshCmd.Flags().BoolVar(&erroredPartitions, "errored-partitions", false, "Refresh all model partitions with errors (must set --model)")
refreshCmd.Flags().StringSliceVar(&sources, "source", nil, "Refresh a source")
refreshCmd.Flags().StringSliceVar(&alerts, "alert", nil, "Refresh an alert")
refreshCmd.Flags().StringSliceVar(&reports, "report", nil, "Refresh a report")
Expand Down
77 changes: 0 additions & 77 deletions cli/cmd/project/splits.go

This file was deleted.

22 changes: 11 additions & 11 deletions cli/pkg/printer/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,24 +458,24 @@ type usergroupMember struct {
Email string `header:"email" json:"email"`
}

func (p *Printer) PrintModelSplits(splits []*runtimev1.ModelSplit) {
if len(splits) == 0 {
p.PrintfWarn("No splits found\n")
func (p *Printer) PrintModelPartitions(partitions []*runtimev1.ModelPartition) {
if len(partitions) == 0 {
p.PrintfWarn("No partitions found\n")
return
}

p.PrintData(toModelSplitsTable(splits))
p.PrintData(toModelPartitionsTable(partitions))
}

func toModelSplitsTable(splits []*runtimev1.ModelSplit) []*modelSplit {
res := make([]*modelSplit, 0, len(splits))
for _, s := range splits {
res = append(res, toModelSplitRow(s))
func toModelPartitionsTable(partitions []*runtimev1.ModelPartition) []*modelPartition {
res := make([]*modelPartition, 0, len(partitions))
for _, s := range partitions {
res = append(res, toModelPartitionRow(s))
}
return res
}

func toModelSplitRow(s *runtimev1.ModelSplit) *modelSplit {
func toModelPartitionRow(s *runtimev1.ModelPartition) *modelPartition {
data, err := json.Marshal(s.Data)
if err != nil {
panic(err)
Expand All @@ -486,7 +486,7 @@ func toModelSplitRow(s *runtimev1.ModelSplit) *modelSplit {
executedOn = s.ExecutedOn.AsTime().Format(time.RFC3339)
}

return &modelSplit{
return &modelPartition{
Key: s.Key,
DataJSON: string(data),
ExecutedOn: executedOn,
Expand All @@ -495,7 +495,7 @@ func toModelSplitRow(s *runtimev1.ModelSplit) *modelSplit {
}
}

type modelSplit struct {
type modelPartition struct {
Key string `header:"key" json:"key"`
DataJSON string `header:"data" json:"data"`
ExecutedOn string `header:"executed_on,timestamp(ms|utc|human)" json:"executed_on"`
Expand Down
1 change: 1 addition & 0 deletions docs/docs/reference/cli/billing/billing.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Billing related commands for org
### SEE ALSO

* [rill](../cli.md) - Rill CLI
* [rill billing list-issues](list-issues.md) - List billing issues for an organization
* [rill billing plan](plan/plan.md) - Get billing plans
* [rill billing subscription](subscription/subscription.md) - Manage organisation subscription

31 changes: 31 additions & 0 deletions docs/docs/reference/cli/billing/list-issues.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
note: GENERATED. DO NOT EDIT.
title: rill billing list-issues
---
## rill billing list-issues

List billing issues for an organization

```
rill billing list-issues [flags]
```

### Flags

```
--org string Organization Name
```

### Global flags

```
--api-token string Token for authenticating with the cloud API
--format string Output format (options: "human", "json", "csv") (default "human")
-h, --help Print usage
--interactive Prompt for missing required parameters (default true)
```

### SEE ALSO

* [rill billing](billing.md) - Billing related commands for org

26 changes: 26 additions & 0 deletions docs/docs/reference/cli/billing/subscription/cancel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
note: GENERATED. DO NOT EDIT.
title: rill billing subscription cancel
---
## rill billing subscription cancel

Cancel subscription for an organization

```
rill billing subscription cancel [flags]
```

### Global flags

```
--api-token string Token for authenticating with the cloud API
--format string Output format (options: "human", "json", "csv") (default "human")
-h, --help Print usage
--interactive Prompt for missing required parameters (default true)
--org string Organization Name
```

### SEE ALSO

* [rill billing subscription](subscription.md) - Manage organisation subscription

2 changes: 1 addition & 1 deletion docs/docs/reference/cli/billing/subscription/edit.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ rill billing subscription edit [flags]
### Flags

```
--org string Organization name
--plan string Plan Name to change subscription to
```

Expand All @@ -24,6 +23,7 @@ rill billing subscription edit [flags]
--format string Output format (options: "human", "json", "csv") (default "human")
-h, --help Print usage
--interactive Prompt for missing required parameters (default true)
--org string Organization Name
```

### SEE ALSO
Expand Down
7 changes: 1 addition & 6 deletions docs/docs/reference/cli/billing/subscription/list.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,14 @@ List subscription for an organization
rill billing subscription list [flags]
```

### Flags

```
--org string Organization Name
```

### Global flags

```
--api-token string Token for authenticating with the cloud API
--format string Output format (options: "human", "json", "csv") (default "human")
-h, --help Print usage
--interactive Prompt for missing required parameters (default true)
--org string Organization Name
```

### SEE ALSO
Expand Down
Loading

1 comment on commit 56e210b

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.