joiner

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2022 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidKey = errors.New("InvalidKey")
View Source
var ErrInvalidRange = errors.New("InvalidRange")
View Source
var ErrNewKeyFailure = errors.New("NewKeyFailure")

Functions

func SelectColumnsByRange

func SelectColumnsByRange(rng target.Range, sources [][]string) ([]string, error)

func SelectColumnsByTarget

func SelectColumnsByTarget(tgt *target.Target, sources [][]string) ([]string, error)

Types

type Cache

type Cache interface {
	Get(src, col int) (Index, bool)
	GetBySrc(src int) ([]Index, bool)
	Delimiter() string
}

type CacheBuilder

type CacheBuilder interface {
	Build(ctx context.Context) (Cache, error)
}

func NewCacheBuilder

func NewCacheBuilder(dataList []io.ReadSeeker, locationList []Location, delimiter string, limit, indexCacheSize int) CacheBuilder

type Index

type Index interface {
	KeyFunc() KeyFunc
	Get(key string) ([]Item, bool)
	Read(item Item) (ScannedItem, error)
	Scan(ctx context.Context) <-chan ScannedItem
	AllItems(ctx context.Context) <-chan Item
}

Index is an in-memory word-to-lines index. This is read-only, underlying data source (file) must be also read-only.

type IndexLoader added in v0.2.2

type IndexLoader interface {
	Load(ctx context.Context, key ...KeyFunc) ([]Index, error)
}

func NewIndexLoader added in v0.2.2

func NewIndexLoader(data async.ReadSeeker, indexCacheSize int) IndexLoader

type Item

type Item interface {
	Key() string
	Offset() int64
	Size() int
}

func NewItem

func NewItem(
	key string,
	offset int64,
	size int,
) Item

type Joiner

type Joiner interface {
	Join(ctx context.Context, key *joinkey.JoinKey) <-chan SelectItemList
}

func New

func New(relJoiner RelationJoiner) Joiner

type KeyFunc

type KeyFunc func(string) (string, error)

KeyFunc extracts a key from a line.

type Location

type Location interface {
	Source() int
	Column() int
}

func RelationListToLocationList

func RelationListToLocationList(relationList []*joinkey.Relation) []Location

type RelationJoiner

type RelationJoiner interface {
	// FullJoin links records with cross join.
	FullJoin(ctx context.Context, rel *joinkey.Relation) <-chan SelectItemList
	// Join links given rows and the other records.
	// Fallback to FullJoin if rowC is nil.
	Join(ctx context.Context, rel *joinkey.Relation, rowC <-chan SelectItemList) <-chan SelectItemList
}

func NewRelationJoiner

func NewRelationJoiner(cache Cache) RelationJoiner

type ScannedItem

type ScannedItem interface {
	Line() string
	Item() Item
}

func NewScannedItem

func NewScannedItem(
	line string,
	item Item,
) ScannedItem

type SelectItem

type SelectItem interface {
	Source() int
	Item() Item
}

func NewSelectItem

func NewSelectItem(
	source int,
	item Item,
) SelectItem

type SelectItemList

type SelectItemList map[int]SelectItem

func (SelectItemList) Clone

func (s SelectItemList) Clone() SelectItemList

func (SelectItemList) Keys

func (s SelectItemList) Keys() []int

func (SelectItemList) Set

func (s SelectItemList) Set(item SelectItem)

func (SelectItemList) Sorted

func (s SelectItemList) Sorted() []SelectItem

type Selector

type Selector interface {
	// Select forms selected items into a line depending on the target.
	// items specify the data sources, target is columns to be selected.
	Select(tgt *target.Target, items []SelectItem) (string, error)
}

func NewSelector

func NewSelector(cache Cache) Selector

Jump to

Keyboard shortcuts

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