diff --git a/flow/connectors/bigquery/merge_statement_generator.go b/flow/connectors/bigquery/merge_statement_generator.go index f150e63ac4..e6082cd8ac 100644 --- a/flow/connectors/bigquery/merge_statement_generator.go +++ b/flow/connectors/bigquery/merge_statement_generator.go @@ -94,10 +94,13 @@ func (m *mergeStmtGenerator) generateFlattenedCTE() string { } flattenedProjs = append(flattenedProjs, castStmt) } - flattenedProjs = append(flattenedProjs, "_peerdb_timestamp") - flattenedProjs = append(flattenedProjs, "_peerdb_timestamp_nanos") - flattenedProjs = append(flattenedProjs, "_peerdb_record_type") - flattenedProjs = append(flattenedProjs, "_peerdb_unchanged_toast_columns") + flattenedProjs = append( + flattenedProjs, + "_peerdb_timestamp", + "_peerdb_timestamp_nanos", + "_peerdb_record_type", + "_peerdb_unchanged_toast_columns", + ) // normalize anything between last normalized batch id to last sync batchid return fmt.Sprintf(`WITH _peerdb_flattened AS @@ -126,8 +129,8 @@ func (m *mergeStmtGenerator) generateDeDupedCTE() string { // generateMergeStmt generates a merge statement. func (m *mergeStmtGenerator) generateMergeStmt(tempTable string) string { // comma separated list of column names - backtickColNames := make([]string, 0) - pureColNames := make([]string, 0) + backtickColNames := make([]string, 0, len(m.NormalizedTableSchema.Columns)) + pureColNames := make([]string, 0, len(m.NormalizedTableSchema.Columns)) for colName := range m.NormalizedTableSchema.Columns { backtickColNames = append(backtickColNames, fmt.Sprintf("`%s`", colName)) pureColNames = append(pureColNames, colName) diff --git a/flow/connectors/snowflake/qrep.go b/flow/connectors/snowflake/qrep.go index 34e0a9ca44..b099a54ff4 100644 --- a/flow/connectors/snowflake/qrep.go +++ b/flow/connectors/snowflake/qrep.go @@ -15,6 +15,7 @@ import ( "github.com/aws/aws-sdk-go/service/s3" "github.com/aws/aws-sdk-go/service/s3/s3manager" "github.com/jackc/pgx/v5/pgtype" + "golang.org/x/exp/maps" "google.golang.org/protobuf/encoding/protojson" ) @@ -308,14 +309,10 @@ func (c *SnowflakeConnector) getColsFromTable(tableName string) (*model.ColumnIn } columnMap[colName.String] = colType.String } - var cols []string - for k := range columnMap { - cols = append(cols, k) - } return &model.ColumnInformation{ ColumnMap: columnMap, - Columns: cols, + Columns: maps.Keys(columnMap), }, nil } diff --git a/flow/connectors/utils/array.go b/flow/connectors/utils/array.go index ec83d9a6a9..3fe95df21e 100644 --- a/flow/connectors/utils/array.go +++ b/flow/connectors/utils/array.go @@ -1,7 +1,7 @@ package utils func ArrayMinus(first []string, second []string) []string { - lookup := make(map[string]struct{}) + lookup := make(map[string]struct{}, len(second)) // Add elements from arrayB to the lookup map for _, element := range second { lookup[element] = struct{}{} diff --git a/flow/connectors/utils/map.go b/flow/connectors/utils/map.go index 769ef225a6..96cbea450c 100644 --- a/flow/connectors/utils/map.go +++ b/flow/connectors/utils/map.go @@ -1,15 +1,15 @@ package utils -import "strings" +import ( + "strings" + + "golang.org/x/exp/maps" +) func KeysToString(m map[string]struct{}) string { if m == nil { return "" } - var keys []string - for k := range m { - keys = append(keys, k) - } - return strings.Join(keys, ",") + return strings.Join(maps.Keys(m), ",") } diff --git a/flow/e2e/test_utils.go b/flow/e2e/test_utils.go index 8fd4e2dcae..0d6e434457 100644 --- a/flow/e2e/test_utils.go +++ b/flow/e2e/test_utils.go @@ -183,7 +183,7 @@ func CreateSourceTableQRep(pool *pgxpool.Pool, suffix string, tableName string) } func generate20MBJson() ([]byte, error) { - xn := make(map[string]interface{}) + xn := make(map[string]interface{}, 215000) for i := 0; i < 215000; i++ { xn[uuid.New().String()] = uuid.New().String() } diff --git a/flow/model/model.go b/flow/model/model.go index 7f97fb3ae4..320ad47e61 100644 --- a/flow/model/model.go +++ b/flow/model/model.go @@ -132,7 +132,7 @@ func (r *RecordItems) toMap() (map[string]interface{}, error) { return nil, errors.New("colToValIdx is nil") } - jsonStruct := make(map[string]interface{}) + jsonStruct := make(map[string]interface{}, len(r.ColToValIdx)) for col, idx := range r.ColToValIdx { v := r.Values[idx] if v.Value == nil { @@ -178,7 +178,7 @@ type ToJSONOptions struct { } func NewToJSONOptions(unnestCols []string) *ToJSONOptions { - unnestColumns := make(map[string]struct{}) + unnestColumns := make(map[string]struct{}, len(unnestCols)) for _, col := range unnestCols { unnestColumns[col] = struct{}{} }