Skip to content

Commit

Permalink
fix: go syntax (#1410)
Browse files Browse the repository at this point in the history
* fix: increment-decrement

* fix: remove underscore
  • Loading branch information
mnagaa authored Dec 22, 2022
1 parent be81aea commit c5f6b9f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 38 deletions.
10 changes: 5 additions & 5 deletions pkg/snowflake/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (e *ViewSelectStatementExtractor) consumeToken(t string) bool {
if e.pos+i > len(e.input) || !strings.EqualFold(string(r), string(e.input[e.pos+i])) {
break
}
found += 1
found++
}

if found == len(t) {
Expand All @@ -112,7 +112,7 @@ func (e *ViewSelectStatementExtractor) consumeSpace() {
if e.pos+found > len(e.input)-1 || !unicode.IsSpace(e.input[e.pos+found]) {
break
}
found += 1
found++
}
e.pos += found
}
Expand All @@ -127,7 +127,7 @@ func (e *ViewSelectStatementExtractor) consumeNonSpace() {
if e.pos+found > len(e.input)-1 || unicode.IsSpace(e.input[e.pos+found]) {
break
}
found += 1
found++
}
e.pos += found
}
Expand Down Expand Up @@ -163,7 +163,7 @@ func (e *ViewSelectStatementExtractor) consumeComment() {
} else if e.input[e.pos+found] == '\'' {
break
}
found += 1
found++
}
e.pos += found

Expand All @@ -181,7 +181,7 @@ func (e *ViewSelectStatementExtractor) consumeClusterBy() {
if e.pos+found > len(e.input)-1 || e.input[e.pos+found-1] == ')' {
break
}
found += 1
found++
}
e.pos += found
}
50 changes: 25 additions & 25 deletions pkg/snowflake/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,13 @@ func (d *ColumnDefault) UnescapeConstantSnowflakeString(columnType string) strin

// Column structure that represents a table column.
type Column struct {
name string
_type string // type is reserved
nullable bool
_default *ColumnDefault // default is reserved
identity *ColumnIdentity
comment string // pointer as value is nullable
masking_policy string
name string
_type string // type is reserved
nullable bool
_default *ColumnDefault // default is reserved
identity *ColumnIdentity
comment string // pointer as value is nullable
maskingPolicy string
}

// WithName set the column name.
Expand Down Expand Up @@ -148,7 +148,7 @@ func (c *Column) WithComment(comment string) *Column {
}

func (c *Column) WithMaskingPolicy(maskingPolicy string) *Column {
c.masking_policy = maskingPolicy
c.maskingPolicy = maskingPolicy
return c
}

Expand Down Expand Up @@ -178,8 +178,8 @@ func (c *Column) getColumnDefinition(withInlineConstraints bool, withComment boo
colDef.WriteString(fmt.Sprintf(` IDENTITY(%v, %v)`, c.identity.startNum, c.identity.stepNum))
}

if strings.TrimSpace(c.masking_policy) != "" {
colDef.WriteString(fmt.Sprintf(` WITH MASKING POLICY %v`, EscapeString(c.masking_policy)))
if strings.TrimSpace(c.maskingPolicy) != "" {
colDef.WriteString(fmt.Sprintf(` WITH MASKING POLICY %v`, EscapeString(c.maskingPolicy)))
}

if withComment {
Expand Down Expand Up @@ -238,13 +238,13 @@ func NewColumns(tds []tableDescription) Columns {
}

cs = append(cs, Column{
name: td.Name.String,
_type: td.Type.String,
nullable: td.IsNullable(),
_default: td.ColumnDefault(),
identity: td.ColumnIdentity(),
comment: td.Comment.String,
masking_policy: td.MaskingPolicy.String,
name: td.Name.String,
_type: td.Type.String,
nullable: td.IsNullable(),
_default: td.ColumnDefault(),
identity: td.ColumnIdentity(),
comment: td.Comment.String,
maskingPolicy: td.MaskingPolicy.String,
})
}
return Columns(cs)
Expand All @@ -258,7 +258,7 @@ func (c Columns) Flatten() []interface{} {
flat["type"] = col._type
flat["nullable"] = col.nullable
flat["comment"] = col.comment
flat["masking_policy"] = col.masking_policy
flat["masking_policy"] = col.maskingPolicy

if col._default != nil {
def := map[string]interface{}{}
Expand Down Expand Up @@ -540,13 +540,13 @@ func (tb *TableBuilder) ChangeChangeTracking(changeTracking bool) string {
// AddColumn returns the SQL query that will add a new column to the table.
func (tb *TableBuilder) AddColumn(name string, dataType string, nullable bool, _default *ColumnDefault, identity *ColumnIdentity, comment string, maskingPolicy string) string {
col := Column{
name: name,
_type: dataType,
nullable: nullable,
_default: _default,
identity: identity,
comment: comment,
masking_policy: maskingPolicy,
name: name,
_type: dataType,
nullable: nullable,
_default: _default,
identity: identity,
comment: comment,
maskingPolicy: maskingPolicy,
}
return fmt.Sprintf(`ALTER TABLE %s ADD COLUMN %s`, tb.QualifiedName(), col.getColumnDefinition(true, true))
}
Expand Down
16 changes: 8 additions & 8 deletions pkg/snowflake/table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ func TestTableCreate(t *testing.T) {
_default: NewColumnDefaultWithExpression("CURRENT_TIMESTAMP()"),
},
{
name: "column6",
_type: "VARCHAR",
nullable: true,
masking_policy: "TEST_MP",
name: "column6",
_type: "VARCHAR",
nullable: true,
maskingPolicy: "TEST_MP",
},
}

Expand Down Expand Up @@ -109,10 +109,10 @@ func TestTableCreateIdentity(t *testing.T) {
identity: &ColumnIdentity{2, 5},
},
{
name: "column4",
_type: "VARCHAR",
nullable: true,
masking_policy: "TEST_MP",
name: "column4",
_type: "VARCHAR",
nullable: true,
maskingPolicy: "TEST_MP",
},
}

Expand Down

0 comments on commit c5f6b9f

Please sign in to comment.