ypath

package
v0.0.24 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2024 License: Apache-2.0 Imports: 9 Imported by: 23

Documentation

Overview

Package ypath defined type for working with YPath.

YPath has two forms, simple and rich.

For more information about ypath see https://docs.yandex-team.ru/yt/description/common/ypath

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SplitTokens

func SplitTokens(path string) (tokens []string, err error)

Types

type CompressionCodec

type CompressionCodec string

CompressionCodec is compression codec used for storing data.

const (
	CompressionNode               CompressionCodec = "none"
	CompressionSnappy             CompressionCodec = "snappy"
	CompressionLZ4                CompressionCodec = "lz4"
	CompressionLZ4HighCompression CompressionCodec = "lz4_high_compression"
	CompressionQuickLZ            CompressionCodec = "quick_lz"
)

func CompressionBZIP2

func CompressionBZIP2(n int) CompressionCodec

CompressionBZIP2 returns bzip2 compression codec with quality n.

Supports quality between 1 and 9.

func CompressionBrotli

func CompressionBrotli(n int) CompressionCodec

CompressionBrotli returns brotli compression codec with quality n.

Supports quality between 1 and 11.

func CompressionLZMA

func CompressionLZMA(n int) CompressionCodec

CompressionLZMA returns lzma compression codec with quality n.

Supports quality between 0 and 9.

func CompressionZLIB

func CompressionZLIB(n int) CompressionCodec

CompressionZLIB returns zlib compression codec with quality n.

Supports quality between 1 and 9.

func CompressionZSTD

func CompressionZSTD(n int) CompressionCodec

CompressionZSTD returns zstd compression codec with quality n.

Supports quality between 1 and 21.

func (CompressionCodec) MarshalText

func (c CompressionCodec) MarshalText() (text []byte, err error)

MarshalText is implementation of encoding.TextMarshaler.

func (*CompressionCodec) UnmarshalText

func (c *CompressionCodec) UnmarshalText(text []byte) error

UnmarshalText is implementation of encoding.TextUnmarshaler.

type ErasureCodec

type ErasureCodec string

ErasureCodec is erasure codec used for storing data.

const (
	ErasureNone        ErasureCodec = "none"
	ErasureReedSolomon ErasureCodec = "reed_solomon_6_3"
	ErasureLRC         ErasureCodec = "lrc_12_2_2"
	ErasureISALRC      ErasureCodec = "isa_lrc_12_2_2"
)

func (ErasureCodec) MarshalText

func (c ErasureCodec) MarshalText() (text []byte, err error)

MarshalText is implementation of encoding.TextMarshaler.

func (*ErasureCodec) UnmarshalText

func (c *ErasureCodec) UnmarshalText(text []byte) error

UnmarshalText is implementation of encoding.TextUnmarshaler.

type Path

type Path string

Path is ypath in simple text form.

Create Path by casting from string.

path := ypath.Path("//home/prime")

Edit Path using helper methods.

myHome = ypath.Root.Child("home").Child("prime")
myHome = ypath.Root.JoinChild("home", "prime")

For complex manipulations, use Rich.

const Root Path = "/"

Root is path to cypress root.

func PathsUpToRoot

func PathsUpToRoot(path Path) ([]Path, error)

PathsUpToRoot returns list of paths referring to the nodes on the path to the root.

Starting node and root are included.

func Split

func Split(path Path) (parent Path, child string, err error)

Split splits path into parent and a child component.

//home/prime/table -> //home/prime /table
#a-b-c-d/@attr     -> #a-b-c-d     /@attr

If path refers to cypress root or object id, Split sets parent to path and child to an empty string.

Path attributes, column selectors and range selectors are stripped from provided path.

func (Path) Attr

func (p Path) Attr(name string) Path

Attr returns path referencing attribute of p.

func (Path) Attrs

func (p Path) Attrs() Path

Attrs returns path referencing all attributes of p.

func (Path) Child

func (p Path) Child(name string) Path

func (Path) Children

func (p Path) Children() Path

Children returns path referencing all children of p.

The only place such path is ever useful is RemoveNode command.

func (Path) JoinChild

func (p Path) JoinChild(names ...string) Path

JoinChild returns path referencing grandchild of p.

root := ypath.Root
myHome := root.JoinChild("home", "prime")

func (Path) ListAfter

func (p Path) ListAfter(n int) Path

ListAfter returns path used for inserting elements into the list.

func (Path) ListBefore

func (p Path) ListBefore(n int) Path

ListBefore returns path used for inserting elements into the list.

func (Path) ListBegin

func (p Path) ListBegin() Path

ListBegin returns path used for inserting elements into beginning of the list.

func (Path) ListEnd

func (p Path) ListEnd() Path

ListEnd returns path used for appending elements to the list.

func (Path) ListIndex

func (p Path) ListIndex(n int) Path

ListIndex returns path referencing n-th element of p, given that p references a list.

func (Path) ListLast

func (p Path) ListLast() Path

ListLast returns path referencing last element of p, given that p references a list.

func (Path) MarshalText

func (p Path) MarshalText() (text []byte, err error)

UnmarshalText is implementation of encoding.TextMarshaler interface.

func (Path) MarshalYSON

func (p Path) MarshalYSON(w *yson.Writer) error

MarshalYSON is implementation of yson.StreamMarshaler interface.

func (Path) Rich

func (p Path) Rich() *Rich

Rich creates Rich from p.

This function doesn't validate and doesn't normalize p.

func (Path) String

func (p Path) String() string

String casts Path back to string.

func (p Path) SuppressSymlink() Path

SuppressSymlink returns path referencing symlink node.

By default, name of symlink references it target.

Typical usage would be:

var linkName ypath.Path
linkTarget := linkName.SuppressSymlink().Attr("target_path")

func (*Path) UnmarshalText

func (p *Path) UnmarshalText(text []byte) error

UnmarshalText is implementation of encoding.TextUnmarshaler interface.

func (Path) YPath

func (p Path) YPath() Path

YPath is implementation of YPath interface.

type Range

type Range struct {
	Lower *ReadLimit `yson:"lower_limit,omitempty"`
	Upper *ReadLimit `yson:"upper_limit,omitempty"`
	Exact *ReadLimit `yson:"exact,omitempty"`
}

Range is subset of table rows defined by lower and upper bound.

func Exact

func Exact(r ReadLimit) Range

Exact is Range of all rows with key matching read limit.

func Full

func Full() Range

Full is Range corresponding to full table.

func Interval

func Interval(lower ReadLimit, upper ReadLimit) Range

Interval is Range of all rows between upper and lower limit.

func StartingFrom

func StartingFrom(lower ReadLimit) Range

StartingFrom is Range of all rows starting from lower read limit and up to table end.

func UpTo

func UpTo(lower ReadLimit) Range

UpTo is Range of all rows starting from the first row and up to upper read limit.

type ReadLimit

type ReadLimit struct {
	Key      []any  `yson:"key,omitempty"`
	RowIndex *int64 `yson:"row_index,omitempty"`
}

ReadLimit is either table key or row index.

func Key

func Key(values ...any) ReadLimit

RowIndex creates ReadLimit from table key.

func RowIndex

func RowIndex(index int64) ReadLimit

RowIndex creates ReadLimit from row index.

type Rich

type Rich struct {
	Path Path `yson:",value"`

	Append   *bool          `yson:"append,attr,omitempty"`
	SortedBy []string       `yson:"sorted_by,attr,omitempty"`
	Ranges   []Range        `yson:"ranges,attr,omitempty"`
	Columns  []string       `yson:"columns,attr,omitempty"`
	Schema   *schema.Schema `yson:"schema,attr,omitempty"`
	FileName string         `yson:"file_name,attr,omitempty"`
	Create   bool           `yson:"create,attr,omitempty"`

	Teleport bool `yson:"teleport,attr,omitempty"`
	Foreign  bool `yson:"foreign,attr,omitempty"`

	Compression CompressionCodec `yson:"compression_codec,attr,omitempty"`
	Erasure     ErasureCodec     `yson:"erasure_codec,attr,omitempty"`

	TransactionID any               `yson:"transaction_id,attr,omitempty"`
	RenameColumns map[string]string `yson:"rename_columns,attr,omitempty"`
}

Rich is YPath representation suitable for manipulation by code.

Note that unlike Path, all methods of Rich mutate receiver.

p := ypath.NewRich("//home/foo/bar").
    AddRange(ypath.Interval(ypath.RowIndex(0), ypath.RowIndex(1000))).
    SetColumns([]string{"time", "message"})

func NewRich

func NewRich(path string) *Rich

NewRich creates new Rich.

This function does not normalize Path and does no validation, use Parse if you need to parse attributes from Path.

func Parse

func Parse(path string) (p *Rich, err error)

Parse parses prefix and suffix of the path in simple form.

func (*Rich) AddRange

func (r *Rich) AddRange(rr Range) *Rich

AddRange adds element to ranges attribute of to p.

func (*Rich) Child

func (r *Rich) Child(name string) *Rich

Child append name to Path.

func (*Rich) Copy

func (r *Rich) Copy() *Rich

Copy returns deep copy of p.

func (Rich) MarshalYSON

func (r Rich) MarshalYSON(w *yson.Writer) error

MarshalYSON is implementation yson.StreamMarshaler interface.

func (*Rich) SetAppend

func (r *Rich) SetAppend() *Rich

SetAppend sets append attribute of p.

func (*Rich) SetColumns

func (r *Rich) SetColumns(columns []string) *Rich

SetColumns updates columns attribute of p.

func (*Rich) SetCompression

func (r *Rich) SetCompression(compression CompressionCodec) *Rich

SetCompression updates compression_codec attribute of p.

func (*Rich) SetCreate added in v0.0.21

func (r *Rich) SetCreate() *Rich

SetCreate sets create attribute of p.

func (*Rich) SetErasure

func (r *Rich) SetErasure(erasure ErasureCodec) *Rich

SetErasure updates erasure_codec attribute of p.

func (*Rich) SetSchema

func (r *Rich) SetSchema(schema schema.Schema) *Rich

SetSchema updates schema attribute of p.

func (*Rich) SetSortedBy

func (r *Rich) SetSortedBy(keysColumns []string) *Rich

SetSortedBy updates sorted_by attribute of p.

func (Rich) YPath

func (r Rich) YPath() Path

YPath is implementation of YPath interface.

type YPath

type YPath interface {
	// YPath returns path with all attributes stripped.
	//
	// If path is malformed, returns original path unmodified. Use Parse() if you need to check path for correctness.
	YPath() Path

	yson.StreamMarshaler
}

YPath is interface type that is able to hold both Path and Rich.

It is used by api methods that accept both kind of paths.

Jump to

Keyboard shortcuts

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