MCPcopy Create free account
hub / github.com/cockroachdb/cockroachdb-parser / Format

Method Format

pkg/sql/sem/tree/create.go:758–896  ·  view source on GitHub ↗

Format implements the NodeFormatter interface.

(ctx *FmtCtx)

Source from the content-addressed store, hash-verified

756
757// Format implements the NodeFormatter interface.
758func (node *ColumnTableDef) Format(ctx *FmtCtx) {
759 ctx.FormatNode(&node.Name)
760
761 // ColumnTableDef node type will not be specified if it represents a CREATE
762 // TABLE ... AS query.
763 if !node.IsCreateAs && node.Type != nil {
764 ctx.WriteByte(' ')
765 node.formatColumnType(ctx)
766 }
767
768 if node.Nullable.Nullability != SilentNull && node.Nullable.ConstraintName != "" {
769 ctx.WriteString(" CONSTRAINT ")
770 ctx.FormatNode(&node.Nullable.ConstraintName)
771 }
772 switch node.Nullable.Nullability {
773 case Null:
774 ctx.WriteString(" NULL")
775 case NotNull:
776 ctx.WriteString(" NOT NULL")
777 }
778 if node.Hidden {
779 ctx.WriteString(" NOT VISIBLE")
780 }
781 if node.PrimaryKey.IsPrimaryKey || node.Unique.IsUnique {
782 if node.Unique.ConstraintName != "" {
783 ctx.WriteString(" CONSTRAINT ")
784 ctx.FormatNode(&node.Unique.ConstraintName)
785 }
786 if node.PrimaryKey.IsPrimaryKey {
787 ctx.WriteString(" PRIMARY KEY")
788
789 // Always prefer to output hash sharding bucket count as a storage param.
790 pkStorageParams := node.PrimaryKey.StorageParams
791 if node.PrimaryKey.Sharded {
792 ctx.WriteString(" USING HASH")
793 bcStorageParam := node.PrimaryKey.StorageParams.GetVal(`bucket_count`)
794 if _, ok := node.PrimaryKey.ShardBuckets.(DefaultVal); !ok && bcStorageParam == nil {
795 pkStorageParams = append(
796 pkStorageParams,
797 StorageParam{
798 Key: `bucket_count`,
799 Value: node.PrimaryKey.ShardBuckets,
800 },
801 )
802 }
803 }
804 if len(pkStorageParams) > 0 {
805 ctx.WriteString(" WITH (")
806 ctx.FormatNode(&pkStorageParams)
807 ctx.WriteString(")")
808 }
809 } else if node.Unique.IsUnique {
810 ctx.WriteString(" UNIQUE")
811 if node.Unique.WithoutIndex {
812 ctx.WriteString(" WITHOUT INDEX")
813 }
814 }
815 }

Callers

nothing calls this directly

Calls 10

formatColumnTypeMethod · 0.95
HasDefaultExprMethod · 0.95
HasOnUpdateExprMethod · 0.95
HasFKConstraintMethod · 0.95
IsComputedMethod · 0.95
HasColumnFamilyMethod · 0.95
FormatNodeMethod · 0.80
GetValMethod · 0.80
FormatMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected