transform

package module
v0.0.0-...-e9b43fb Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2023 License: Apache-2.0 Imports: 20 Imported by: 1

Documentation

Overview

Package transform contains methods to transform json trees as specified by the config.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DefaultTransformer

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

DefaultTransformer contains projectors initialized for a specific config, and receiver methods to perform transformations.

func NewDefaultTransformer

func NewDefaultTransformer(ctx context.Context, config *dhpb.DataHarmonizationConfig, tconfig TransformationConfig, setters ...Option) (*DefaultTransformer, error)

NewDefaultTransformer creates and initializes a default transformer.

func (*DefaultTransformer) HasPostProcessProjector

func (t *DefaultTransformer) HasPostProcessProjector() bool

HasPostProcessProjector returns true iff a post process projector is set.

func (*DefaultTransformer) JSONtoJSON

func (t *DefaultTransformer) JSONtoJSON(in json.RawMessage) (json.RawMessage, error)

JSONtoJSON converts the byte array (JSON format) using the specified config.

func (*DefaultTransformer) LoadMappingConfig

func (t *DefaultTransformer) LoadMappingConfig(config *dhpb.DataHarmonizationConfig) (*mappb.MappingConfig, error)

LoadMappingConfig loads the mapping config inline or from a GCS path.

func (*DefaultTransformer) LoadProjectors

func (t *DefaultTransformer) LoadProjectors(projectors []*mappb.ProjectorDefinition) error

LoadProjectors registers all given projectors.

func (*DefaultTransformer) ParseJSON

ParseJSON parses the given JSON into a JSONToken.

func (*DefaultTransformer) Project

func (t *DefaultTransformer) Project(projector string, args ...jsonutil.JSONMetaNode) (res jsonutil.JSONToken, err error)

Project is a convenience function to call a single projector out of context.

func (*DefaultTransformer) RegisterProjector

func (t *DefaultTransformer) RegisterProjector(name string, proj types.Projector) error

RegisterProjector adds the given Projector to this transformer's registry.

func (*DefaultTransformer) Registry

func (t *DefaultTransformer) Registry() *types.Registry

Registry returns the registry in DefaultTransformer.

func (*DefaultTransformer) Transform

func (t *DefaultTransformer) Transform(in jsonutil.JSONToken) (res jsonutil.JSONToken, err error)

Transform converts the json tree using the specified config.

type Option

type Option func(*Options)

Option is a setter function for Options.

func CloudFunctions

func CloudFunctions(enabledCloudFunctions bool) Option

CloudFunctions initializes the CloudFunctions transform option.

func FetchConfigs

func FetchConfigs(enableFetchConfig bool) Option

FetchConfigs initializes the FetchConfigs transform option.

func GCSClient

func GCSClient(c gcsutil.StorageClient) Option

GCSClient sets the GCSClient in the transform option.

func Parallel

func Parallel(enableParallel bool) Option

Parallel initializes the Parallel transform option.

type Options

type Options struct {
	// CloudFunctions enables support for cloud functions within the transform library.
	CloudFunctions bool

	// FetchConfigs enables support for fetch configurations wtihin the transform library.
	FetchConfigs bool

	// Parallel enables support for parallelization within the transform library.
	Parallel bool

	// GCSClient is a client for downloading from GCS. If unset, the default third party GCS client will be used.
	GCSClient gcsutil.StorageClient
}

Options for initializing Data Harmonization transform library

type TransformationConfig

type TransformationConfig struct {
	LogTrace     bool
	SkipBundling bool
}

TransformationConfig contains metadata used during transformation.

type Transformer

type Transformer interface {
	// Transform transforms given JSONToken (parsed JSON) into a target JSONToken using the
	// config.
	Transform(jsonutil.JSONToken) (jsonutil.JSONToken, error)
	// JSONtoJSON transforms given raw JSON into a target raw JSON using the config.
	JSONtoJSON(json.RawMessage) (json.RawMessage, error)

	// ParseJSON parses given raw JSON into a JSONToken.
	ParseJSON(json.RawMessage) (jsonutil.JSONToken, error)

	// LoadProjectors registers all given projectors in the config.
	LoadProjectors([]*mappb.ProjectorDefinition) error

	// Registry returns the registry used in Transformer.
	Registry() *types.Registry

	// HasPostProcessProjector returns true iff a post process projector is set.
	HasPostProcessProjector() bool
}

Transformer defines an interface to perform transformations.

func NewTransformer

func NewTransformer(ctx context.Context, config *dhpb.DataHarmonizationConfig, tconfig TransformationConfig, setters ...Option) (Transformer, error)

NewTransformer creates and initializes a transformer, and returns a new DefaultTransformer by default.

Jump to

Keyboard shortcuts

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