|
| 1 | +package flink |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/spf13/cobra" |
| 5 | + |
| 6 | + pcmd "github.com/confluentinc/cli/v4/pkg/cmd" |
| 7 | +) |
| 8 | + |
| 9 | +type materializedTableOut struct { |
| 10 | + Name string `human:"Name" serialized:"name"` |
| 11 | + ClusterID string `human:"Database" serialized:"database"` |
| 12 | + Environment string `human:"Environment" serialized:"environment"` |
| 13 | + ComputePool string `human:"Compute Pool" serialized:"compute_pool"` |
| 14 | + ServiceAccount string `human:"Principal" serialized:"principal"` |
| 15 | + Stopped bool `human:"Stopped" serialized:"stopped"` |
| 16 | + Query string `human:"Query,omitempty" serialized:"query,omitempty"` |
| 17 | + Columns []string `human:"Columns,omitempty" serialized:"columns,omitempty"` |
| 18 | + WaterMarkColumnName string `human:"Watermark Column,omitempty" serialized:"watermark_column,omitempty"` |
| 19 | + WaterMarkExpression string `human:"Watermark Expression,omitempty" serialized:"watermark_expression,omitempty"` |
| 20 | + Constraints []string `human:"Constraints,omitempty" serialized:"constraints,omitempty"` |
| 21 | + DistributionKeys []string `human:"Distribution Keys,omitempty" serialized:"distribution_keys,omitempty"` |
| 22 | + DistributionBucketCount int `human:"Distribution Bucket Count,omitempty" serialized:"distribution_bucket_count,omitempty"` |
| 23 | +} |
| 24 | + |
| 25 | +func (c *command) newMaterializedTableCommand() *cobra.Command { |
| 26 | + cmd := &cobra.Command{ |
| 27 | + Use: "materialized-table", |
| 28 | + Short: "Manage Flink materialized tables.", |
| 29 | + Annotations: map[string]string{pcmd.RunRequirement: pcmd.RequireNonAPIKeyCloudLogin}, |
| 30 | + } |
| 31 | + |
| 32 | + cmd.AddCommand(c.newMaterializedTableCreateCommand()) |
| 33 | + cmd.AddCommand(c.newMaterializedTableDeleteCommand()) |
| 34 | + cmd.AddCommand(c.newMaterializedTableDescribeCommand()) |
| 35 | + cmd.AddCommand(c.newMaterializedTableListCommand()) |
| 36 | + cmd.AddCommand(c.newMaterializedTableUpdateCommand()) |
| 37 | + |
| 38 | + return cmd |
| 39 | +} |
| 40 | + |
| 41 | +func (c *command) validMaterializedTableArgs(cmd *cobra.Command, args []string) []string { |
| 42 | + if len(args) > 0 { |
| 43 | + return nil |
| 44 | + } |
| 45 | + |
| 46 | + return c.validMaterializedTablesArgsMultiple(cmd, args) |
| 47 | +} |
| 48 | + |
| 49 | +func (c *command) validMaterializedTablesArgsMultiple(cmd *cobra.Command, args []string) []string { |
| 50 | + if err := c.PersistentPreRunE(cmd, args); err != nil { |
| 51 | + return nil |
| 52 | + } |
| 53 | + |
| 54 | + environmentId, err := c.Context.EnvironmentId() |
| 55 | + if err != nil { |
| 56 | + return nil |
| 57 | + } |
| 58 | + |
| 59 | + client, err := c.GetFlinkGatewayClient(false) |
| 60 | + if err != nil { |
| 61 | + return nil |
| 62 | + } |
| 63 | + |
| 64 | + tables, err := client.ListMaterializedTables(environmentId, c.Context.GetCurrentOrganization()) |
| 65 | + if err != nil { |
| 66 | + return nil |
| 67 | + } |
| 68 | + |
| 69 | + suggestions := make([]string, len(tables)) |
| 70 | + for i, table := range tables { |
| 71 | + suggestions[i] = table.GetName() |
| 72 | + } |
| 73 | + return suggestions |
| 74 | +} |
| 75 | + |
| 76 | +func (c *command) addOptionalMaterializedTableFlags(cmd *cobra.Command) { |
| 77 | + cmd.Flags().String("columns-physical", "", "Path to the columns data for type physical.") |
| 78 | + cmd.Flags().String("columns-metadata", "", "Path to the columns data for type metadata.") |
| 79 | + cmd.Flags().String("columns-computed", "", "Path to the columns data for type computed.") |
| 80 | + cmd.Flags().String("watermark-column", "", "The name of the watermark columns.") |
| 81 | + cmd.Flags().String("watermark-expression", "", "The watermark expression.") |
| 82 | + cmd.Flags().String("constraints", "", "Path to the constraints.") |
| 83 | + cmd.Flags().String("distribution-keys", "", "The names of the columns the table is distributed by.") |
| 84 | + cmd.Flags().Int("distribution-bucket-count", 0, "The number of buckets.") |
| 85 | +} |
0 commit comments