Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bigquery,mssql] Remove uppercaseEscapedNames support #483

Merged
merged 5 commits into from
Apr 22, 2024
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
4 changes: 2 additions & 2 deletions clients/bigquery/bigquery.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (s *Store) PrepareTemporaryTable(tableData *optimization.TableData, tableCo
}

func (s *Store) IdentifierFor(topicConfig kafkalib.TopicConfig, table string) types.TableIdentifier {
return NewTableIdentifier(s.config.BigQuery.ProjectID, topicConfig.Database, table, s.ShouldUppercaseEscapedNames())
return NewTableIdentifier(s.config.BigQuery.ProjectID, topicConfig.Database, table)
}

func (s *Store) GetTableConfig(tableData *optimization.TableData) (*types.DwhTableConfig, error) {
Expand Down Expand Up @@ -112,7 +112,7 @@ func (s *Store) Label() constants.DestinationKind {
}

func (s *Store) ShouldUppercaseEscapedNames() bool {
return s.config.SharedDestinationConfig.UppercaseEscapedNames
return false
}

func (s *Store) GetClient(ctx context.Context) *bigquery.Client {
Expand Down
2 changes: 1 addition & 1 deletion clients/bigquery/merge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func (b *BigQueryTestSuite) TestBackfillColumn() {
tableID := NewTableIdentifier("db", "public", "tableName", false)
tableID := NewTableIdentifier("db", "public", "tableName")
type _testCase struct {
name string
col columns.Column
Expand Down
20 changes: 9 additions & 11 deletions clients/bigquery/tableid.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,16 @@ import (
)

type TableIdentifier struct {
projectID string
dataset string
table string
uppercaseEscapedNames bool
projectID string
dataset string
table string
}

func NewTableIdentifier(projectID, dataset, table string, uppercaseEscapedNames bool) TableIdentifier {
func NewTableIdentifier(projectID, dataset, table string) TableIdentifier {
return TableIdentifier{
projectID: projectID,
dataset: dataset,
table: table,
uppercaseEscapedNames: uppercaseEscapedNames,
projectID: projectID,
dataset: dataset,
table: table,
}
}

Expand All @@ -37,7 +35,7 @@ func (ti TableIdentifier) Table() string {
}

func (ti TableIdentifier) WithTable(table string) types.TableIdentifier {
return NewTableIdentifier(ti.projectID, ti.dataset, table, ti.uppercaseEscapedNames)
return NewTableIdentifier(ti.projectID, ti.dataset, table)
}

func (ti TableIdentifier) FullyQualifiedName() string {
Expand All @@ -47,6 +45,6 @@ func (ti TableIdentifier) FullyQualifiedName() string {
"`%s`.`%s`.%s",
ti.projectID,
ti.dataset,
sql.EscapeNameIfNecessary(ti.table, ti.uppercaseEscapedNames, &sql.NameArgs{Escape: true, DestKind: constants.BigQuery}),
sql.EscapeNameIfNecessary(ti.table, false, &sql.NameArgs{Escape: true, DestKind: constants.BigQuery}),
)
}
9 changes: 3 additions & 6 deletions clients/bigquery/tableid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,19 @@ import (
)

func TestTableIdentifier_WithTable(t *testing.T) {
tableID := NewTableIdentifier("project", "dataset", "foo", true)
tableID := NewTableIdentifier("project", "dataset", "foo")
tableID2 := tableID.WithTable("bar")
typedTableID2, ok := tableID2.(TableIdentifier)
assert.True(t, ok)
assert.Equal(t, "project", typedTableID2.ProjectID())
assert.Equal(t, "dataset", typedTableID2.Dataset())
assert.Equal(t, "bar", tableID2.Table())
assert.True(t, typedTableID2.uppercaseEscapedNames)
}

func TestTableIdentifier_FullyQualifiedName(t *testing.T) {
// Table name that does not need escaping:
assert.Equal(t, "`project`.`dataset`.foo", NewTableIdentifier("project", "dataset", "foo", false).FullyQualifiedName())
assert.Equal(t, "`project`.`dataset`.foo", NewTableIdentifier("project", "dataset", "foo", true).FullyQualifiedName())
assert.Equal(t, "`project`.`dataset`.foo", NewTableIdentifier("project", "dataset", "foo").FullyQualifiedName())

// Table name that needs escaping:
assert.Equal(t, "`project`.`dataset`.`table`", NewTableIdentifier("project", "dataset", "table", false).FullyQualifiedName())
assert.Equal(t, "`project`.`dataset`.`TABLE`", NewTableIdentifier("project", "dataset", "table", true).FullyQualifiedName())
assert.Equal(t, "`project`.`dataset`.`table`", NewTableIdentifier("project", "dataset", "table").FullyQualifiedName())
}
4 changes: 2 additions & 2 deletions clients/mssql/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (s *Store) Label() constants.DestinationKind {
}

func (s *Store) ShouldUppercaseEscapedNames() bool {
return s.config.SharedDestinationConfig.UppercaseEscapedNames
return false
}

func (s *Store) Merge(tableData *optimization.TableData) error {
Expand All @@ -49,7 +49,7 @@ func (s *Store) Append(tableData *optimization.TableData) error {

// specificIdentifierFor returns a MS SQL [TableIdentifier] for a [TopicConfig] + table name.
func (s *Store) specificIdentifierFor(topicConfig kafkalib.TopicConfig, table string) TableIdentifier {
return NewTableIdentifier(getSchema(topicConfig.Schema), table, s.ShouldUppercaseEscapedNames())
return NewTableIdentifier(getSchema(topicConfig.Schema), table)
}

// IdentifierFor returns a generic [types.TableIdentifier] interface for a [TopicConfig] + table name.
Expand Down
13 changes: 6 additions & 7 deletions clients/mssql/tableid.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ import (
)

type TableIdentifier struct {
schema string
table string
uppercaseEscapedNames bool
schema string
table string
}

func NewTableIdentifier(schema, table string, uppercaseEscapedNames bool) TableIdentifier {
return TableIdentifier{schema: schema, table: table, uppercaseEscapedNames: uppercaseEscapedNames}
func NewTableIdentifier(schema, table string) TableIdentifier {
return TableIdentifier{schema: schema, table: table}
}

func (ti TableIdentifier) Schema() string {
Expand All @@ -27,13 +26,13 @@ func (ti TableIdentifier) Table() string {
}

func (ti TableIdentifier) WithTable(table string) types.TableIdentifier {
return NewTableIdentifier(ti.schema, table, ti.uppercaseEscapedNames)
return NewTableIdentifier(ti.schema, table)
}

func (ti TableIdentifier) FullyQualifiedName() string {
return fmt.Sprintf(
"%s.%s",
ti.schema,
sql.EscapeNameIfNecessary(ti.table, ti.uppercaseEscapedNames, &sql.NameArgs{Escape: true, DestKind: constants.MSSQL}),
sql.EscapeNameIfNecessary(ti.table, false, &sql.NameArgs{Escape: true, DestKind: constants.MSSQL}),
)
}
9 changes: 3 additions & 6 deletions clients/mssql/tableid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,18 @@ import (
)

func TestTableIdentifier_WithTable(t *testing.T) {
tableID := NewTableIdentifier("schema", "foo", true)
tableID := NewTableIdentifier("schema", "foo")
tableID2 := tableID.WithTable("bar")
typedTableID2, ok := tableID2.(TableIdentifier)
assert.True(t, ok)
assert.Equal(t, "schema", typedTableID2.Schema())
assert.Equal(t, "bar", tableID2.Table())
assert.True(t, typedTableID2.uppercaseEscapedNames)
}

func TestTableIdentifier_FullyQualifiedName(t *testing.T) {
// Table name that does not need escaping:
assert.Equal(t, "schema.foo", NewTableIdentifier("schema", "foo", false).FullyQualifiedName())
assert.Equal(t, "schema.foo", NewTableIdentifier("schema", "foo", true).FullyQualifiedName())
assert.Equal(t, "schema.foo", NewTableIdentifier("schema", "foo").FullyQualifiedName())

// Table name that needs escaping:
assert.Equal(t, `schema."table"`, NewTableIdentifier("schema", "table", false).FullyQualifiedName())
assert.Equal(t, `schema."TABLE"`, NewTableIdentifier("schema", "table", true).FullyQualifiedName())
assert.Equal(t, `schema."table"`, NewTableIdentifier("schema", "table").FullyQualifiedName())
}
8 changes: 8 additions & 0 deletions lib/config/bigquery.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,11 @@ func (b *BigQuery) DSN() string {

return dsn
}

func (c Config) ValidateBigQuery() error {
if c.SharedDestinationConfig.UppercaseEscapedNames {
return fmt.Errorf("uppercaseEscapedNames is not supported for BigQuery")
}

return nil
}
4 changes: 4 additions & 0 deletions lib/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,10 @@ func (c Config) Validate() error {
}

switch c.Output {
case constants.BigQuery:
if err := c.ValidateBigQuery(); err != nil {
return err
}
case constants.MSSQL:
if err := c.ValidateMSSQL(); err != nil {
return err
Expand Down
4 changes: 4 additions & 0 deletions lib/config/mssql.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,9 @@ func (c Config) ValidateMSSQL() error {
return fmt.Errorf("invalid mssql port: %d", c.MSSQL.Port)
}

if c.SharedDestinationConfig.UppercaseEscapedNames {
return fmt.Errorf("uppercaseEscapedNames is not supported for MS SQL")
}

return nil
}
4 changes: 2 additions & 2 deletions lib/destination/ddl/ddl_bq_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (d *DDLTestSuite) TestAlterTableDropColumnsBigQuery() {
}

func (d *DDLTestSuite) TestAlterTableAddColumns() {
tableID := bigquery.NewTableIdentifier("", "mock_dataset", "add_cols", true)
tableID := bigquery.NewTableIdentifier("", "mock_dataset", "add_cols")
fqName := tableID.FullyQualifiedName()
ts := time.Now()
existingColNameToKindDetailsMap := map[string]typing.KindDetails{
Expand Down Expand Up @@ -176,7 +176,7 @@ func (d *DDLTestSuite) TestAlterTableAddColumns() {
}

func (d *DDLTestSuite) TestAlterTableAddColumnsSomeAlreadyExist() {
tableID := bigquery.NewTableIdentifier("", "mock_dataset", "add_cols", true)
tableID := bigquery.NewTableIdentifier("", "mock_dataset", "add_cols")
fqName := tableID.FullyQualifiedName()
ts := time.Now()
existingColNameToKindDetailsMap := map[string]typing.KindDetails{
Expand Down
2 changes: 1 addition & 1 deletion lib/destination/ddl/ddl_create_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
)

func (d *DDLTestSuite) Test_CreateTable() {
bqTableID := bigquery.NewTableIdentifier("", "mock_dataset", "mock_table", true)
bqTableID := bigquery.NewTableIdentifier("", "mock_dataset", "mock_table")
d.bigQueryStore.GetConfigMap().AddTableToConfig(bqTableID, types.NewDwhTableConfig(&columns.Columns{}, nil, true, true))

snowflakeTableID := snowflake.NewTableIdentifier("", "mock_dataset", "mock_table", true)
Expand Down
2 changes: 1 addition & 1 deletion lib/destination/ddl/ddl_temp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (d *DDLTestSuite) TestCreateTemporaryTable() {
}
{
// BigQuery
tableID := bigquery.NewTableIdentifier("db", "schema", "tempTableName", false)
tableID := bigquery.NewTableIdentifier("db", "schema", "tempTableName")
d.bigQueryStore.GetConfigMap().AddTableToConfig(tableID, types.NewDwhTableConfig(&columns.Columns{}, nil, true, true))
bqTc := d.bigQueryStore.GetConfigMap().TableConfig(tableID)
args := ddl.AlterTableArgs{
Expand Down