Skip to content

Commit

Permalink
Move datatype folders to super folder (#1583)
Browse files Browse the repository at this point in the history
Moves geo, hstore, interval and numeric files where we do special
operations on those types, to a `datatypes` folder
  • Loading branch information
Amogh-Bharadwaj authored Apr 8, 2024
1 parent 55d5b3f commit d8a10c3
Show file tree
Hide file tree
Showing 19 changed files with 28 additions and 29 deletions.
2 changes: 1 addition & 1 deletion flow/connectors/bigquery/bigquery.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ import (

metadataStore "github.com/PeerDB-io/peer-flow/connectors/external_metadata"
"github.com/PeerDB-io/peer-flow/connectors/utils"
numeric "github.com/PeerDB-io/peer-flow/datatypes"
"github.com/PeerDB-io/peer-flow/generated/protos"
"github.com/PeerDB-io/peer-flow/logger"
"github.com/PeerDB-io/peer-flow/model"
"github.com/PeerDB-io/peer-flow/model/numeric"
"github.com/PeerDB-io/peer-flow/model/qvalue"
"github.com/PeerDB-io/peer-flow/peerdbenv"
"github.com/PeerDB-io/peer-flow/shared"
Expand Down
2 changes: 1 addition & 1 deletion flow/connectors/bigquery/qrep_avro_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import (
"go.temporal.io/sdk/activity"

avro "github.com/PeerDB-io/peer-flow/connectors/utils/avro"
numeric "github.com/PeerDB-io/peer-flow/datatypes"
"github.com/PeerDB-io/peer-flow/generated/protos"
"github.com/PeerDB-io/peer-flow/model"
"github.com/PeerDB-io/peer-flow/model/numeric"
"github.com/PeerDB-io/peer-flow/model/qvalue"
"github.com/PeerDB-io/peer-flow/shared"
)
Expand Down
8 changes: 4 additions & 4 deletions flow/connectors/clickhouse/normalize.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
"strconv"
"strings"

"github.com/PeerDB-io/peer-flow/datatypes"
"github.com/PeerDB-io/peer-flow/generated/protos"
"github.com/PeerDB-io/peer-flow/model"
"github.com/PeerDB-io/peer-flow/model/numeric"
"github.com/PeerDB-io/peer-flow/model/qvalue"
)

Expand Down Expand Up @@ -84,10 +84,10 @@ func generateCreateTableSQLForNormalizedTable(

switch colType {
case qvalue.QValueKindNumeric:
precision, scale := numeric.ParseNumericTypmod(column.TypeModifier)
precision, scale := datatypes.ParseNumericTypmod(column.TypeModifier)
if column.TypeModifier == -1 || precision > 76 || scale > precision {
precision = numeric.PeerDBClickhousePrecision
scale = numeric.PeerDBClickhouseScale
precision = datatypes.PeerDBClickhousePrecision
scale = datatypes.PeerDBClickhouseScale
}
stmtBuilder.WriteString(fmt.Sprintf("`%s` DECIMAL(%d, %d), ",
colName, precision, scale))
Expand Down
2 changes: 1 addition & 1 deletion flow/connectors/postgres/cdc.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (

"github.com/PeerDB-io/peer-flow/connectors/utils"
"github.com/PeerDB-io/peer-flow/connectors/utils/cdc_records"
geo "github.com/PeerDB-io/peer-flow/datatypes"
"github.com/PeerDB-io/peer-flow/generated/protos"
"github.com/PeerDB-io/peer-flow/geo"
"github.com/PeerDB-io/peer-flow/logger"
"github.com/PeerDB-io/peer-flow/model"
"github.com/PeerDB-io/peer-flow/model/qvalue"
Expand Down
2 changes: 1 addition & 1 deletion flow/connectors/postgres/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import (
"github.com/lib/pq/oid"

"github.com/PeerDB-io/peer-flow/connectors/utils"
numeric "github.com/PeerDB-io/peer-flow/datatypes"
"github.com/PeerDB-io/peer-flow/generated/protos"
"github.com/PeerDB-io/peer-flow/model"
"github.com/PeerDB-io/peer-flow/model/numeric"
"github.com/PeerDB-io/peer-flow/shared"
)

Expand Down
7 changes: 3 additions & 4 deletions flow/connectors/postgres/qrep_query_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ import (
"github.com/jackc/pgx/v5/pgtype"
"go.temporal.io/sdk/log"

"github.com/PeerDB-io/peer-flow/geo"
datatypes "github.com/PeerDB-io/peer-flow/datatypes"
"github.com/PeerDB-io/peer-flow/model"
"github.com/PeerDB-io/peer-flow/model/numeric"
"github.com/PeerDB-io/peer-flow/model/qvalue"
"github.com/PeerDB-io/peer-flow/shared"
)
Expand Down Expand Up @@ -79,7 +78,7 @@ func (qe *QRepQueryExecutor) fieldDescriptionsToSchema(fds []pgconn.FieldDescrip
// TODO fix this.
cnullable := true
if ctype == qvalue.QValueKindNumeric {
precision, scale := numeric.ParseNumericTypmod(fd.TypeModifier)
precision, scale := datatypes.ParseNumericTypmod(fd.TypeModifier)
qfields[i] = qvalue.QField{
Name: cname,
Type: ctype,
Expand Down Expand Up @@ -426,7 +425,7 @@ func (qe *QRepQueryExecutor) mapRowToQRecord(
switch customQKind {
case qvalue.QValueKindGeography, qvalue.QValueKindGeometry:
wkbString, ok := values[i].(string)
wkt, err := geo.GeoValidate(wkbString)
wkt, err := datatypes.GeoValidate(wkbString)
if err != nil || !ok {
record[i] = qvalue.QValueNull(qvalue.QValueKindGeography)
} else if customQKind == qvalue.QValueKindGeography {
Expand Down
4 changes: 2 additions & 2 deletions flow/connectors/postgres/qvalue_convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/lib/pq/oid"
"github.com/shopspring/decimal"

peerdb_interval "github.com/PeerDB-io/peer-flow/interval"
datatypes "github.com/PeerDB-io/peer-flow/datatypes"
"github.com/PeerDB-io/peer-flow/model/qvalue"
"github.com/PeerDB-io/peer-flow/shared"
)
Expand Down Expand Up @@ -229,7 +229,7 @@ func parseFieldFromQValueKind(qvalueKind qvalue.QValueKind, value interface{}) (
return qvalue.QValueTimestampTZ{Val: timestamp}, nil
case qvalue.QValueKindInterval:
intervalObject := value.(pgtype.Interval)
var interval peerdb_interval.PeerDBInterval
var interval datatypes.PeerDBInterval
interval.Hours = int(intervalObject.Microseconds / 3600000000)
interval.Minutes = int((intervalObject.Microseconds % 3600000000) / 60000000)
interval.Seconds = float64(intervalObject.Microseconds%60000000) / 1000000.0
Expand Down
2 changes: 1 addition & 1 deletion flow/connectors/snowflake/merge_stmt_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"strings"

"github.com/PeerDB-io/peer-flow/connectors/utils"
numeric "github.com/PeerDB-io/peer-flow/datatypes"
"github.com/PeerDB-io/peer-flow/generated/protos"
"github.com/PeerDB-io/peer-flow/model/numeric"
"github.com/PeerDB-io/peer-flow/model/qvalue"
"github.com/PeerDB-io/peer-flow/shared"
)
Expand Down
2 changes: 1 addition & 1 deletion flow/connectors/snowflake/snowflake.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ import (

metadataStore "github.com/PeerDB-io/peer-flow/connectors/external_metadata"
"github.com/PeerDB-io/peer-flow/connectors/utils"
numeric "github.com/PeerDB-io/peer-flow/datatypes"
"github.com/PeerDB-io/peer-flow/generated/protos"
"github.com/PeerDB-io/peer-flow/logger"
"github.com/PeerDB-io/peer-flow/model"
"github.com/PeerDB-io/peer-flow/model/numeric"
"github.com/PeerDB-io/peer-flow/model/qvalue"
"github.com/PeerDB-io/peer-flow/peerdbenv"
"github.com/PeerDB-io/peer-flow/shared"
Expand Down
2 changes: 1 addition & 1 deletion flow/geo/geo.go → flow/datatypes/geo.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package geo
package datatypes

import (
"encoding/hex"
Expand Down
2 changes: 1 addition & 1 deletion flow/hstore/hstore.go → flow/datatypes/hstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ https://github.com/postgres/postgres/blob/bea18b1c949145ba2ca79d4765dba3cc9494a4
This package is an implementation based on the above code.
It's simplified to only parse the subset which `hstore_out` outputs.
*/
package hstore_util
package datatypes

import (
"encoding/json"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package hstore_util
package datatypes

import (
"testing"
Expand Down
2 changes: 1 addition & 1 deletion flow/interval/interval.go → flow/datatypes/interval.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package peerdb_interval
package datatypes

type PeerDBInterval struct {
Hours int `json:"hours,omitempty"`
Expand Down
2 changes: 1 addition & 1 deletion flow/model/numeric/scale.go → flow/datatypes/numeric.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package numeric
package datatypes

const (
PeerDBNumericPrecision = 38
Expand Down
2 changes: 1 addition & 1 deletion flow/model/qrecord_batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/google/uuid"
"github.com/jackc/pgx/v5/pgtype"

"github.com/PeerDB-io/peer-flow/geo"
geo "github.com/PeerDB-io/peer-flow/datatypes"
"github.com/PeerDB-io/peer-flow/model/qvalue"
)

Expand Down
4 changes: 2 additions & 2 deletions flow/model/qvalue/avro_converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
"github.com/shopspring/decimal"
"go.temporal.io/sdk/log"

"github.com/PeerDB-io/peer-flow/datatypes"
"github.com/PeerDB-io/peer-flow/generated/protos"
hstore_util "github.com/PeerDB-io/peer-flow/hstore"
)

// https://avro.apache.org/docs/1.11.0/spec.html
Expand Down Expand Up @@ -544,7 +544,7 @@ func (c *QValueAvroConverter) processArrayDate(arrayDate []time.Time) interface{
}

func (c *QValueAvroConverter) processHStore(hstore string) (interface{}, error) {
jsonString, err := hstore_util.ParseHstore(hstore)
jsonString, err := datatypes.ParseHstore(hstore)
if err != nil {
return "", fmt.Errorf("cannot parse %s: %w", hstore, err)
}
Expand Down
2 changes: 1 addition & 1 deletion flow/model/qvalue/dwh.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (

"go.temporal.io/sdk/log"

numeric "github.com/PeerDB-io/peer-flow/datatypes"
"github.com/PeerDB-io/peer-flow/generated/protos"
"github.com/PeerDB-io/peer-flow/model/numeric"
)

func DetermineNumericSettingForDWH(precision int16, scale int16, dwh protos.DBType) (int16, int16) {
Expand Down
4 changes: 2 additions & 2 deletions flow/model/qvalue/equals.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/shopspring/decimal"
geom "github.com/twpayne/go-geos"

hstore_util "github.com/PeerDB-io/peer-flow/hstore"
"github.com/PeerDB-io/peer-flow/datatypes"
)

func valueEmpty(value any) bool {
Expand Down Expand Up @@ -174,7 +174,7 @@ func compareHStore(str1 string, value2 interface{}) bool {
if str1 == str2 {
return true
}
parsedHStore1, err := hstore_util.ParseHstore(str1)
parsedHStore1, err := datatypes.ParseHstore(str1)
if err != nil {
panic(err)
}
Expand Down
4 changes: 2 additions & 2 deletions flow/model/record_items.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/google/uuid"

hstore_util "github.com/PeerDB-io/peer-flow/hstore"
"github.com/PeerDB-io/peer-flow/datatypes"
"github.com/PeerDB-io/peer-flow/model/qvalue"
)

Expand Down Expand Up @@ -132,7 +132,7 @@ func (r RecordItems) toMap(hstoreAsJSON bool, opts ToJSONOptions) (map[string]in
if !hstoreAsJSON {
jsonStruct[col] = hstoreVal
} else {
jsonVal, err := hstore_util.ParseHstore(hstoreVal)
jsonVal, err := datatypes.ParseHstore(hstoreVal)
if err != nil {
return nil, fmt.Errorf("unable to convert hstore column %s to json for value %T: %w", col, v, err)
}
Expand Down

0 comments on commit d8a10c3

Please sign in to comment.