rowconv

package
v0.40.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 19, 2022 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const DatatypeCoercionFailureWarningCode int = 1105 // Since this our own custom warning we'll use 1105, the code for an unknown error

Variables

View Source
var DatatypeCoercionFailureWarning = "unable to coerce value from field '%s' into latest column schema"
View Source
var ErrEmptyMapping = errors.New("empty mapping error")

ErrEmptyMapping is an error returned when the mapping is empty (No src columns, no destination columns)

View Source
var ErrMappingFileRead = errors.New("error reading mapping file")

ErrMappingFileRead is an error returned when a mapping file cannot be read

View Source
var ErrUnmarshallingMapping = errors.New("error unmarshalling mapping")

ErrUnmarshallingMapping is an error used when a mapping file cannot be converted from json

View Source
var IdentityConverter = &RowConverter{nil, true, nil}

Functions

func IsBadMappingErr

func IsBadMappingErr(err error) bool

IsBadMappingErr returns true if the error is a BadMappingErr

func IsNecessary

func IsNecessary(srcSch, destSch schema.Schema, destToSrc map[uint64]uint64) (bool, error)

Types

type BadMappingErr

type BadMappingErr struct {
	// contains filtered or unexported fields
}

BadMappingErr is a struct which implements the error interface and is used when there is an error with a mapping.

func (*BadMappingErr) Error

func (err *BadMappingErr) Error() string

String representing the BadMappingError

type ColNamingFunc

type ColNamingFunc func(colName string) string

ColNamingFunc defines a function signature which takes the name of a column, and returns the name that should be used for the column in the joined dataset.

type FieldMapping

type FieldMapping struct {
	// SrcSch is the source schema being mapped from.
	SrcSch schema.Schema

	// DestSch is the destination schema being mapped to.
	DestSch schema.Schema

	// SrcToDest is a map from a tag in the source schema to a tag in the dest schema.
	SrcToDest map[uint64]uint64
}

FieldMapping defines a mapping from columns in a source schema to columns in a dest schema.

func IdentityMapping

func IdentityMapping(sch schema.Schema) *FieldMapping

Returns the identity mapping for the schema given.

func InvertMapping

func InvertMapping(fm *FieldMapping) *FieldMapping

func NameMapping

func NameMapping(srcSch, destSch schema.Schema, nameMapper NameMapper) (*FieldMapping, error)

NameMapping takes a source schema and a destination schema and maps all columns which have a matching name in the source and destination schemas.

func NewFieldMapping

func NewFieldMapping(srcSch, destSch schema.Schema, srcTagToDestTag map[uint64]uint64) (*FieldMapping, error)

NewFieldMapping creates a FieldMapping from a source schema, a destination schema, and a map from tags in the source schema to tags in the dest schema.

func TagMapping

func TagMapping(srcSch, destSch schema.Schema) (*FieldMapping, error)

TagMapping takes a source schema and a destination schema and maps all columns which have a matching tag in the source and destination schemas.

func TagMappingWithNameFallback

func TagMappingWithNameFallback(srcSch, destSch schema.Schema) (*FieldMapping, error)

TagMappingWithNameFallback takes a source schema and a destination schema and maps columns by matching tags first, then attempts to match by column name for any columns that didn't match with an exact tag.

func TypedToUntypedMapping

func TypedToUntypedMapping(sch schema.Schema) (*FieldMapping, error)

TypedToUntypedMapping takes a schema and creates a mapping to an untyped schema with all the same columns.

func (*FieldMapping) MapsAllDestPKs

func (fm *FieldMapping) MapsAllDestPKs() bool

MapsAllDestPKs checks that each PK column in DestSch has a corresponding column in SrcSch

type Joiner

type Joiner struct {
	// contains filtered or unexported fields
}

Joiner is an object that can be used to join multiple rows together into a single row (See Join), and also to reverse this operation by taking a joined row and getting back a map of rows (See Split).

func NewJoiner

func NewJoiner(namedSchemas []NamedSchema, namers map[string]ColNamingFunc) (*Joiner, error)

NewJoiner creates a joiner from a slice of NamedSchemas and a map of ColNamingFuncs. A new schema for joined rows will be created, and the columns for joined schemas will be named according to the ColNamingFunc associated with each schema name.

func (*Joiner) GetSchema

func (j *Joiner) GetSchema() schema.Schema

GetSchema returns the schema which all joined rows will have, and any row passed into split should have.

func (*Joiner) Join

func (j *Joiner) Join(namedRows map[string]row.Row) (row.Row, error)

Join takes a map from schema name to row which has that schema, and returns a single joined row containing all the data

func (*Joiner) SchemaForName

func (j *Joiner) SchemaForName(name string) schema.Schema

SchemaForName retrieves the original schema which has the given name.

func (*Joiner) Split

func (j *Joiner) Split(r row.Row) (map[string]row.Row, error)

Split takes a row which has the created joined schema, and splits it into a map of rows where the key of the map is the name of the schema for the associated row.

type NameMapper

type NameMapper map[string]string

NameMapper is a simple interface for mapping a string to another string

func NameMapperFromFile

func NameMapperFromFile(mappingFile string, FS filesys.ReadableFS) (NameMapper, error)

NameMapperFromFile reads a JSON file containing a name mapping and returns a NameMapper.

func (NameMapper) Map

func (nm NameMapper) Map(str string) string

Map maps a string to another string. If a string is not in the mapping ok will be false, otherwise it is true.

func (NameMapper) PreImage

func (nm NameMapper) PreImage(str string) string

PreImage searches the NameMapper for the string that maps to str, returns str otherwise

type NamedSchema

type NamedSchema struct {
	// Name the name given to the schema
	Name string

	// Sch is the schema
	Sch schema.Schema
}

NamedSchema is an object that associates a schema with a string

type RowConverter

type RowConverter struct {
	// FieldMapping is a mapping from source column to destination column
	*FieldMapping
	// IdentityConverter is a bool which is true if the converter is doing nothing.
	IdentityConverter bool
	ConvFuncs         map[uint64]types.MarshalCallback
}

RowConverter converts rows from one schema to another

func NewRowConverter

func NewRowConverter(ctx context.Context, vrw types.ValueReadWriter, mapping *FieldMapping) (*RowConverter, error)

NewRowConverter creates a row converter from a given FieldMapping.

func (*RowConverter) Convert

func (rc *RowConverter) Convert(inRow row.Row) (row.Row, error)

Convert takes an input row, maps its columns to destination columns, and performs any type conversion needed to create a row of the expected destination schema.

func (*RowConverter) ConvertWithWarnings

func (rc *RowConverter) ConvertWithWarnings(inRow row.Row, warnFn WarnFunction) (row.Row, error)

ConvertWithWarnings takes an input row, maps its columns to their destination columns, performing any type conversions needed to create a row of the expected destination schema, and uses the optional WarnFunction callback to let callers handle logging a warning when a field cannot be cleanly converted.

type WarnFunction

type WarnFunction func(int, string, ...string)

WarnFunction is a callback function that callers can optionally provide during row conversion to take an extra action when a value cannot be automatically converted to the output data type.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL