gql

package
v0.0.0-...-9d3c4bc Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2019 License: Apache-2.0 Imports: 66 Imported by: 0

Documentation

Overview

Code generated by generate_randomized_freepool.py. DO NOT EDIT.

Index

Constants

View Source
const (
	DefaultCacheRoot      = "s3://grail-query/cache4"
	DefaultLocalCacheRoot = "/tmp/grail-query/cache4"
)

Default values for cacheRoot when using EC2 bigslice system and otherwise.

View Source
const OptionalCompression = `(\.gz|\.bz2|\.zst)?$`

OptionalCompression is a regexp that matches compressed-file suffixes.

Variables

View Source
var (
	// Shorthand for trivial types.
	AIAnyType    = AIType{Any: true}
	AIBoolType   = AIType{Type: BoolType}
	AIIntType    = AIType{Type: IntType}
	AIFloatType  = AIType{Type: FloatType}
	AIStringType = AIType{Type: StringType}
	AIStructType = AIType{Type: StructType}
	AITableType  = AIType{Type: TableType}
)
View Source
var (

	// MinNMinRowsPerShard is the minimum number of rows per sortshard.
	MinNMinRowsPerShard = 1 << 18
	// MinNMaxRowsPerShard is the maximum number of rows per sortshard.
	MinNMaxRowsPerShard = 1 << 20
	// MinNParallelism is the maximum number of goroutines to create during
	// sorting.
	MinNParallelism = runtime.NumCPU() * 2
)
View Source
var (
	// Null is a singleton instance of NA.
	Null = NewNull(PosNull)
	// True is a true Bool constant
	True = NewBool(true)
	// False is a false Bool constant
	False = NewBool(false)
)
View Source
var BAMTableMaxShards = 512

BAMTableMaxShards sets the maximum physical shards created for a BAM scanner. Exposed only for testing.

TODO(marius): it might make more sense to compute a dynamic max shard by having a minimum shard size.

View Source
var (

	// BackgroundContext is used in stringers, etc, when the user doesn't
	// explicitly pass a context. Copied from Opts.BackgroundContext in Init.
	BackgroundContext context.Context
)
View Source
var (
	// MaxTSVRowsInMemory defines the maximum number of TSV rows to read and cache
	// in memory.  If a TSV file contains more rows than this limit, the file
	// contents are read incrementally in each scanner.
	//
	// This flag is exposed only for unittesting.
	MaxTSVRowsInMemory = 65536
)
View Source
var VerifyFileHash = false

If verifyFileHash = true, some table implementation will verify that the fileHash (see below) hasn't changed since it was first computed. The check is slow especially on S3, so it's disabled by default.

Functions

func ActivateCache

func ActivateCache(ctx context.Context, name, uniquePath string)

activateCache arranges so that future calls to lookupCache(name) will return uniquePath. This function is implemented by creating a symlink-like file that stores the uniquePath as the contents.

func BTSVShardPath

func BTSVShardPath(dir string, shard, nshards int) string

BTSVShardPath computes the path of a btsv shard file.

REQUIRES: dir must end with ".btsv". 0 <= shard < nshards.

func CheckCancellation

func CheckCancellation(ctx context.Context)

CheckCancellation checks if ctx has been cancelled and panics if so.

func Compare

func Compare(ast ASTNode, v0, v1 Value) int

Compare compares the two values lexicographically. It returns -1,0,1 if v0<v1, v0==v1, v0>v1, respectively. It crashes if the two values are not of the same type. "ast" is for displaying error messages.

func Debugf

func Debugf(ast ASTNode, format string, args ...interface{})

Debugf is similar to log.Debug.Printf(...). Arg "ast" is the source-code location of the error. If "ast" is unknown, pass &ASTUnknown{}.

func DefaultTableLen

func DefaultTableLen(ctx context.Context, t Table) int

DefaultTableLen computes the number of rows in the table accurately by scanning it.

func DescribeValue

func DescribeValue(v Value) string

DescribeValue a shorthand for calling v.Print() with PrintArgs.Mode of PrintDescription.

func Errorf

func Errorf(ast ASTNode, format string, args ...interface{})

Logf is similar to log.Error.Printf(...). Arg "ast" is the source-code location of the error. If "ast" is unknown, pass &ASTUnknown{}.

func FileHash

func FileHash(ctx context.Context, path string, ast ASTNode) hash.Hash

FileHash computes a hash from a pathname and the file's modtime. The resulting value can be used as the hash for a file-based Table.

func FormatSeq

func FormatSeq(s sam.Seq) string

FormatSeq reports a human-readable string for the give DNA sequence.

func GenerateStableCachePath

func GenerateStableCachePath(name string) string

GenerateStableCachePath generates a stable path using "name" as a template. name should be of form "prefix.extension". The generated pathname is currently of the form cacheRoot/name but this may change in future implementations.

func Init

func Init(opts Opts)

Init initializes the GQL runtime. It must be called once before using evaluating gql expressions.

func InitStruct

func InitStruct(s Struct)

InitStruct initializes the itable pointer of the given struct. It must be called once when a new Struct object is created.

func IsFileImmutable

func IsFileImmutable(path string) bool

IsFileImmutable checks if the pathname matches gql.Opts.ImmutableFilesRE.

func Logf

func Logf(ast ASTNode, format string, args ...interface{})

Logf is similar to log.Printf(...). Arg "ast" is the source-code location of the error. If "ast" is unknown, pass &ASTUnknown{}.

func LookupCache

func LookupCache(ctx context.Context, name string) (string, bool)

LookupCache looks up "name" in the persistent cache. If found, it returns the abspathname of the data and true.

If the cache entry is not found, it generates a new unique file path. The caller should produce cache contents in the given file, then call activateCache once done to activate the cache entry.

Example:

path, found := lookupCache("foo.btsv")
if !found {
  w := NewBTSVShardWriter(path, 0, 1, TableAttrs{})
  .. fill w ...
  w.Close()
  activateCache("foo.btsv", path)
}
r := NewBTSVTable(path, ...)
... use r ...

func MarshalTableInline

func MarshalTableInline(ctx MarshalContext, enc *marshal.Encoder, t Table)

MarshalTableInline marshals the given table contents directly. It shall be used only for small tables.

func MarshalTableOutline

func MarshalTableOutline(ctx MarshalContext, enc *marshal.Encoder, t Table)

MarshalTableOutline marshals the given table by first writing its contents in btsv format in the cachedir, then marshaling the pathname of the generated btsv file.

func MarshalTablePath

func MarshalTablePath(enc *marshal.Encoder, path string, fh FileHandler, hash hash.Hash)

MarshalTablePath encodes a table as a tuple of <pathname, filehandler, hash>. It does not encode the table contents, so this function is suitable only for files that can be accessed from any machine (e.g., S3) and are immutable.

func NewBTSVTable

func NewBTSVTable(path string, ast ASTNode, hash hash.Hash) *btsvTable

NewBTSVTable creates a Table implementation for a btsv table stored in directory "path". path must end with *.btsv. hash is an optional hash of the inputs that derives the btsv table.

func NewactualArgFreePool

func NewactualArgFreePool(new func() []ActualArg, maxSize int) *actualArgFreePool

NewactualArgFreePool creates a new free object pool. new should create a new object. It is called when the pool is empty on Get(). maxSize bounds the approx max number of objects that can be stored in the pool. Beyond this limit, Put() call will drop the objects.

func NewstructFieldFreePool

func NewstructFieldFreePool(new func() []StructField, maxSize int) *structFieldFreePool

NewstructFieldFreePool creates a new free object pool. new should create a new object. It is called when the pool is empty on Get(). maxSize bounds the approx max number of objects that can be stored in the pool. Beyond this limit, Put() call will drop the objects.

func Panicf

func Panicf(ast ASTNode, format string, args ...interface{})

Logf is similar to log.Panicf.(...). Arg "ast" is the source-code location of the error. If "ast" is unknown, pass &ASTUnknown{}.

func PrintValueList

func PrintValueList(vals []Value) string

PrintValueList prints a list of values in form "[val0, val1, ...]". Arg depth is used as PrintArgs.Depth.

func Recover

func Recover(cb func()) (err error)

Recover runs the given function, catching any panic thrown by the function and turning it into an error. If the function finishes without panicking, CatchPanic returns nil.

func RegisterFileHandler

func RegisterFileHandler(fh FileHandler, pathRE ...string)

RegisterFileHandler registers a file handler. This function is typically invoked in an init() function. Arg pathRE is the list of regexps that defines the pathame patterrs. If any of the patterns matches a path, the file handler is invoked to read and write the file.

func RegisterGlobalConst

func RegisterGlobalConst(name string, val Value)

RegisterGlobalConst adds name->value binding in the global constant table. It panics if the name already exists. This function may be called after gql.Init(), but before evaluating any user expression.

func RegisterTableUnmarshaler

func RegisterTableUnmarshaler(magic UnmarshalMagic, cb UnmarshalTableCallback)

RegisterTableUnmarshaler registers a magic number for table marshaler and unmarshaler. "cb" will be called to unmarshal a table with the given magic. The MarshalGOB method of the table type should use the same magic.

This function must be called in an init() function.

func ScaleShardRange

func ScaleShardRange(start, limit, nshards, nitems int) (int, int)

func TestClearCache

func TestClearCache()

TestClearCache deletes all the files in cacheRoot. For unittests only.

func TestMarshalValue

func TestMarshalValue(t *testing.T, val Value) (ctxData, valData []byte)

func TestPrintValueLong

func TestPrintValueLong(v Value) string

func TestSetOverwriteFiles

func TestSetOverwriteFiles(v bool) bool

TestSetOverwriteFiles temporarily overrides overwriteFiles. Return the old value. For unittests only.

func Unsafeint32sToBytes

func Unsafeint32sToBytes(recs []int32) (b []uint8)

func Unsafeuint8sToBytes

func Unsafeuint8sToBytes(recs []uint8) []uint8

func WriteColumnarTSV

func WriteColumnarTSV(ctx context.Context, table Table, format string, gzipFiles, overwrite bool)

WriteColumnarTSV writes the given table in 'columnar' format, that is, each column is written to a separate file. Prefix represents a path prefix (eg. an S3 prefix or a directory), and format is a template in go's text/template language that is used to generate the name of each of the columnar files. The template is executed executed with the following fields available:

Name   string  // Column header but with white space replaced by _
Number int     // 1..<num-cols>

The first row of all of the files will contain the column header. If gzip is true then the output files will be gzip compressed and a .gz extension appended to all of the filenames. If overwrite is false and the file "path" exists, this function returns quickly without overwriting the file.

func WriteTSV

func WriteTSV(ctx context.Context, path string, table Table, headerLine, gzip bool)

WriteTSV writes the table contents to a TSV file. If headerLine=true, it emits the column names in the first line. If gzip is true, the file is compressed using gzip.

Types

type AIArg

type AIArg struct {
	Name         symbol.ID  // =symbol.Invalid iff the arg is positional.
	Type         AIType     // Set when the value is eagerly evaluated
	Env          aiBindings // Env and Expr form a closure
	Expr         ASTNode    // Syntactic node. Nil iff the arg is optional and is omitted by the caller.
	Symbol       symbol.ID  // Set iff FormalArg.Symbol=true.
	DefaultValue Value      // Copied from FormalArg.DefaultValue
}

AIArg is the result of parsing & typechecking FormalFuncArg.

type AIType

type AIType struct {
	// ValueType is the type of the node.
	Type ValueType

	// Literal is non-nil if the type refers to a compile-time constant.
	Literal *Value

	// Any is set when the type is unknown. An any type matches anything.
	Any bool

	// Formal args to the function.
	FormalArgs []FormalArg
	// TypeCB is called via ASTNode.Analyze to run a
	// function-implementation-specific typecheck.
	//
	// Note: the types of non-lazy args in []FormalArgs are checked by
	// ASTFunctionCall.Analeze, so TypeCB implementations don't need to check
	// them.
	TypeCB TypeCallback
}

AIType is similar to ValueType, but it contains more detailed information, such as function signatures. It is used only during pre-execution program analysis, while ASTNode.Analyze is running. It is never persisted.

func (AIType) FuncReturnType

func (t AIType) FuncReturnType(ast ASTNode) AIType

FuncReturnType is the type of return values of the function. If t.Any, it returns AIAnyType.

REQUIRES: t.Is(FuncType).

func (AIType) Is

func (t AIType) Is(typ ValueType) bool

Is checks if t is of the given type. It always returns true if t.Any==true. It also treats string-like types as the same, and date-like types as the same.

func (AIType) IsType

func (t AIType) IsType(other AIType) bool

IsType checks if "other" can be interpreted as "t".

type ASTBlock

type ASTBlock struct {
	Pos        scanner.Position
	Statements []ASTStatement
}

ASTBlock represents an expression of form "{ assignments; expr }"

func (*ASTBlock) String

func (n *ASTBlock) String() string

type ASTColumnRef

type ASTColumnRef struct {
	// Pos is the location of this node in the source file.
	Pos scanner.Position
	// Col is the column name
	Col symbol.ID

	// Deprecated is true if this syntax node was created by a "$column"
	// expression, as opposed to "&column".
	Deprecated bool
}

ASTColumnRef represents a "_.column" expression. It is produced as a result of rewriting &column.

func (*ASTColumnRef) String

func (n *ASTColumnRef) String() string

String implements the ASTNode interface.

type ASTCondOp

type ASTCondOp struct {
	// Pos is the position of the start of the expression.
	Pos scanner.Position
	// Cond is the conditional.
	Cond ASTNode
	// Then is the positive clause.
	Then ASTNode
	// Else is the negative clause.
	Else ASTNode
}

ASTCondOp is an ASTNode implementation for "cond(if,then,else)".

func (*ASTCondOp) String

func (n *ASTCondOp) String() string

String returns a human-readable description.

type ASTFuncall

type ASTFuncall struct {
	Pos      scanner.Position
	Function ASTNode       // function body.
	Raw      []ASTParamVal // set by yacc.
	Args     []AIArg       // set in analyze
	Analyzed bool          // true after analyze() runs.
}

ASTFuncall is an ASTNode for function call 'func(arg0,arg1,...)'

func NewASTBuiltinFuncall

func NewASTBuiltinFuncall(pos scanner.Position, f Value, args ...ASTNode) *ASTFuncall

NewASTBuiltinFuncall creates a new ASTFuncall object. Is is used for infix or prefix operators.

func NewASTFuncall

func NewASTFuncall(fun ASTNode, args []ASTParamVal) *ASTFuncall

NewASTFuncall creates a new ASTFuncall.

func NewASTPipe

func NewASTPipe(left ASTNode, right ASTNode) *ASTFuncall

NewASTPipe creates a syntax node for construct "left | fun(args)". It is translated into "fun(left, args)".

func (*ASTFuncall) String

func (n *ASTFuncall) String() string

String implements the ASTNode interface.

type ASTImplicitColumnRef

type ASTImplicitColumnRef struct {
	// Pos is the location of this node in the source file.
	Pos scanner.Position
	// Col is the column name.
	Col symbol.ID
}

ASTImplicitColumnRef represents a "&column" expression. It can appear only in function-call arguments. "&column" is rewritten into "|_|{_.column}" by replaceImplicitColumnRef.

func (*ASTImplicitColumnRef) String

func (n *ASTImplicitColumnRef) String() string

String implements the ASTNode interface.

type ASTLambda

type ASTLambda struct {
	Pos  scanner.Position
	Args []FormalArg
	// Body is the function body.
	Body ASTNode
}

ASTLambda is an ASTNode for a user-defined function, "func(params...) {statements...}".

func NewASTLambda

func NewASTLambda(pos scanner.Position, params []string, body ASTNode) *ASTLambda

NewASTLambda creates a new ASTLambda node.

func (*ASTLambda) String

func (n *ASTLambda) String() string

String implements the ASTNode interface.

type ASTLiteral

type ASTLiteral struct {
	// Pos is the source-code location of this node.
	Pos scanner.Position
	// Literal stores the const value.
	Literal Value
	// Org stores the original expression, if this node was created as a result of
	// constant-propagation optimization. Otherwise Org is nil.
	Org ASTNode
}

ASTLiteral is an ASTNode for a literal value, such as 123, `foobar`.

func (*ASTLiteral) String

func (n *ASTLiteral) String() string

String implements the ASTNode interface.

type ASTLogicalOp

type ASTLogicalOp struct {
	// AndAnd is true for "&&", false for "||"
	AndAnd   bool
	LHS, RHS ASTNode
}

ASTLogicalOp is an ASTNode implementation for "||" and "&&" operators.

func (*ASTLogicalOp) String

func (n *ASTLogicalOp) String() string

String returns a human-readable description.

type ASTNode

type ASTNode interface {

	// String produces a human-readable description of the expression node.  The
	// resulting string is only for logging; it may not be a valid GQL expression.
	String() string
	// contains filtered or unexported methods
}

ASTNode represents an abstract syntax tree node. One ASTnode is created for a syntactic element found in the source script. Implementations of ASTNode must be threadsafe and GOB-encodable.

type ASTParamVal

type ASTParamVal struct {
	Pos scanner.Position
	// Name is set to symbol.Intern("foo") if the actual arg is 'foo:=expr'. It is
	// symbol.Invalid for a positional arg.
	Name symbol.ID
	// Expr is the actual arg expression.
	Expr ASTNode
	// PipeSource is true if if this arg is a LHS of a pipe operator.  E.g., take
	// expression `read("foo.tsv") | map($col==0)`. It is syntactically translated
	// into `map(read("foo.tsv"), $col==0)`. Its first arg, `read("foo.tsv")` is
	// marked as PipeSource. A pipesource argument is exempted from '&' expansion.
	PipeSource bool
}

ASTParamVal represents a function-call parameter that appears in the source code.

func NewASTParamVal

func NewASTParamVal(pos scanner.Position, name string, expr ASTNode) ASTParamVal

NewASTParamVal creates a new ASTParamVal.

type ASTStatement

type ASTStatement struct {
	// Pos is the location of this node in the source file.
	Pos scanner.Position

	// LHS is set when the statement is of form "var := expr".
	LHS symbol.ID

	// Expr is the right-hand side of "var := expr". It is also set when the
	// statement is a naked expression.
	Expr ASTNode
}

ASTStatement represents an assignment 'var:=expr' or an expression.

func NewASTStatement

func NewASTStatement(pos scanner.Position, name string, expr ASTNode) ASTStatement

NewASTStatement creates a new ASTStatement.

func (ASTStatement) String

func (s ASTStatement) String() string

type ASTStatementOrLoad

type ASTStatementOrLoad struct {
	ASTStatement
	// Load is set when the statement is of form "load `path`". The value is the
	// pathname. Other fields are unset.
	LoadPath string
}

ASTStatementOrLoad is a toplevel gql construct.

func (ASTStatementOrLoad) String

func (s ASTStatementOrLoad) String() string

String returns a human-readable string.

type ASTStructFieldRef

type ASTStructFieldRef struct {
	Parent ASTNode   // Refers to the struct object.
	Field  symbol.ID // Field in the struct.
}

ASTStructFieldRef represents an expression "struct.field".

func NewASTStructFieldRef

func NewASTStructFieldRef(parent ASTNode, name string) *ASTStructFieldRef

NewASTStructFieldRef creates a new ASTStructFieldRef.

func (*ASTStructFieldRef) String

func (n *ASTStructFieldRef) String() string

String implements the ASTNode interface.

type ASTStructFieldRegex

type ASTStructFieldRegex struct {
	Pos scanner.Position
	// contains filtered or unexported fields
}

ASTStructFieldRegex is for evaluating expressions of form "struct./regex/". It evaluates into a value containing []StructField.

func NewASTStructFieldRegex

func NewASTStructFieldRegex(pos scanner.Position, parent ASTNode, re string) *ASTStructFieldRegex

NewASTStructFieldRegex creates a new ASTStructFieldRegex.

func (*ASTStructFieldRegex) MarshalBinary

func (n *ASTStructFieldRegex) MarshalBinary() ([]byte, error)

MarshalBinary implements the GOB interface.

func (*ASTStructFieldRegex) String

func (n *ASTStructFieldRegex) String() string

String implements the ASTNode interface.

func (*ASTStructFieldRegex) UnmarshalBinary

func (n *ASTStructFieldRegex) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the GOB interface.

type ASTStructLiteral

type ASTStructLiteral struct {
	Pos    scanner.Position
	Fields []ASTStructLiteralField
}

ASTStructLiteral is an ASTNode that represents a struct literal '{f0:=val0,f1:=val1,...}.

func NewASTStructLiteral

func NewASTStructLiteral(pos scanner.Position, fields []ASTStructLiteralField) *ASTStructLiteral

NewASTStructLiteral creates a new ASTStructLiteral.

func (*ASTStructLiteral) String

func (n *ASTStructLiteral) String() string

String implements the ASTNode interface.

type ASTStructLiteralField

type ASTStructLiteralField struct {
	Pos  scanner.Position
	Name symbol.ID // column name. may be symbol.Invalid.
	Expr ASTNode
}

ASTStructLiteralField represents a column within a struct literal expression '{f0:=val0,f1:=val1,...}.

func NewASTStructLiteralField

func NewASTStructLiteralField(pos scanner.Position, name string, expr ASTNode) ASTStructLiteralField

NewASTStructLiteralField creates a new ASTStructLiteralField. name is the the column (field) name, and expr is an expression that refers to the struct.

type ASTUnknown

type ASTUnknown struct{}

ASTUnknown implements ASTNode. It is a placeholder whose only purpose to report a source code location.

func (*ASTUnknown) String

func (n *ASTUnknown) String() string

type ASTVarRef

type ASTVarRef struct {
	Pos scanner.Position
	Var symbol.ID // variable name
}

ASTVarRef represents a symbol reference.

func (*ASTVarRef) String

func (n *ASTVarRef) String() string

String implements the ASTNode interface.

type ActualArg

type ActualArg struct {
	Name   symbol.ID // Formal arg name. Copied from FormalArg.Name
	Value  Value     // Set for eagerly evaluated arg.
	Expr   ASTNode   // Points to the source code element. Set unless the arg is optional and is not provided by the caller.
	Symbol symbol.ID // Set only for symbol arg.
}

ActualArg represents an function-call argument.

1. If FormalArg.Symbol==true, only the Symbol field will be set.

2. Else Value and Expr are set. Value is the actual fully-evaluated arg value. Expr is useful primarily to show a informative error message.

func (*ActualArg) Bool

func (arg *ActualArg) Bool() bool

Bool retrieves the bool value from arg.Value. A shorthand for arg.Value.Bool(arg.Expr).

func (*ActualArg) Char

func (arg *ActualArg) Char() rune

Char retrieves the char value from arg.Value. A shorthand for arg.Value.Char(arg.Expr).

func (*ActualArg) DateTime

func (arg *ActualArg) DateTime() time.Time

DateTime retrieves the char value from arg.Value. A shorthand for arg.Value.DateTime(arg.Expr).

func (*ActualArg) Duration

func (arg *ActualArg) Duration() time.Duration

Duration retrieves the duration value from arg.Value. A shorthand for arg.Value.Duration(arg.Expr).

func (*ActualArg) Float

func (arg *ActualArg) Float() float64

Float retrieves the float64 value from arg.Value. A shorthand for arg.Value.Float(arg.Expr).

func (*ActualArg) Func

func (arg *ActualArg) Func() *Func

Func retrieves the function closure from arg.Value. A shorthand for arg.Value.Func(arg.Expr).

func (*ActualArg) Int

func (arg *ActualArg) Int() int64

Int retrieves the int64 value from arg.Value. A shorthand for arg.Value.Int(arg.Expr).

func (*ActualArg) Str

func (arg *ActualArg) Str() string

Str retrieves the string value from arg.Value. A shorthand for arg.Value.Str(arg.Expr).

func (*ActualArg) Struct

func (arg *ActualArg) Struct() Struct

Struct retrieves the struct value from arg.Value. A shorthand for arg.Value.Struct(arg.Expr).

func (*ActualArg) Table

func (arg *ActualArg) Table() Table

Table retrieves the table64 value from arg.Value. A shorthand for arg.Value.Table(arg.Expr).

type BTSVShardWriter

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

BTSVShardWriter creates a BTSV shard. Use NewBTSVShardWriter to create this object..

func NewBTSVShardWriter

func NewBTSVShardWriter(ctx context.Context, dir string, shard, nshards int, attrs TableAttrs) *BTSVShardWriter

NewBTSVShardWriter creates a BTSVShardWriter object. The attrs is used only as table description in the index.

REQUIRES: path ends with ".btsv"

Example:

w := NewBTSVShardWriter("/tmp/foo.btsv", 0, 1, attrs)
t := some Table
s := t.Scanner(...)
for s.Scan() {
  w.Append(s.Value())
}
w.Close()

func (*BTSVShardWriter) Append

func (b *BTSVShardWriter) Append(val Value)

Append adds a value to the btsv table.

func (*BTSVShardWriter) Close

func (b *BTSVShardWriter) Close(ctx context.Context)

Close must be called exactly once at the end of writes. It finalizes the file contents.

type ClosureFormalArg

type ClosureFormalArg struct {
	// Name is the default name of the arg
	Name symbol.ID
	// Override specifies the name of the argument to the (outer) function that
	// overrides the Name. For example, the builtin map() function has an optional
	// argument "row" that overrides the name of the arguments to filter and map
	// callbacks. For these callbacks, Name=symbol.Intern("_"),
	// Override=symbol.Intern("row").
	Override symbol.ID
}

ClosureFormalArg is the list of formal args for a closure. It is part of FormalArg

type CountMode

type CountMode int

CountMode controls the behavior of Table.Len().

const (
	// Exact causes Table.Len() implementations to return the exact count.
	Exact CountMode = iota
	// Approx causes Table.Len() implementations to quickly return an approximate
	// count.
	Approx
)

type FileHandler

type FileHandler interface {
	// Name returns the file-type name, e.g., "tsv" for TSV handler, "bam" for BAM
	// handler.
	Name() string
	// Open opens the file and returns a Table that reads its contents.  Arg "ast"
	// can be passed to functions such as Logf, Panicf to report the source-code
	// location on error.
	Open(ctx context.Context, path string, ast ASTNode, hash hash.Hash) Table
	// Write writes the contents of the table to the given file. "nshard" the
	// number of file shards to create. It is meaningful only for btsv files.
	// "overwrite" is true iff. the caller wishes to overwrite the file if it
	// exits already.
	//
	// Arg "ast" can be passed to functions such as Logf, Panicf to report the
	// source-code location on error.
	Write(ctx context.Context, path string, ast ASTNode, table Table, nShard int, overwrite bool)
}

FileHandler defines methods for reading a file into a Table and writing a table into a file.

func GetFileHandlerByName

func GetFileHandlerByName(name string) FileHandler

GetFileHandlerByName finds the FileHandler object with the given name.

func GetFileHandlerByPath

func GetFileHandlerByPath(path string) FileHandler

GetFileHandlerByName finds the FileHandler for the given file. It works only by examining the path name. It does not read file contents. If multiple handlers match the path name, the one with the longest match will be used.

func TSVFileHandler

func TSVFileHandler() FileHandler

type FormalArg

type FormalArg struct {
	// Name must be set for a named argument. For positional args, this field is
	// only informational.
	Name symbol.ID
	// Positional is true if the caller need not name the arg in form
	// "arg:=value".
	Positional bool
	// Required is true if the arg must be provided by the caller.
	Required bool
	// Variadic causes this arg to consume all the remaining, unnamed actual args
	Variadic bool

	// Closure is true if the argument is treated as a lambda body with the args
	// specified in ClosureArgs. A Closure argument is translated into a
	// user-defined function during the analysis phase.
	Closure     bool
	ClosureArgs []ClosureFormalArg

	// Joinclosure is a special kind of closure that's used to specify the join
	// condition and map arg for the join function. The formal args to these
	// callbacks need to be extraced from the 1st arg to join ({t0:table0, ...,
	// tN:tableN}).
	JoinClosure bool

	// If Symbol=true, the actual arg must be a naked symbol that specifies a
	// variable name. It is used, e.g., as the "row:=foobar" arg in map() and
	// filter().
	Symbol bool
	// DefaultSymbol is set as the value of the symbol arg if it is not provided
	// by the caller.
	//
	// INVARIANT: If DefaultSymbol!=symbol.Invalid then Symbol==true.
	DefaultSymbol symbol.ID

	// DefaultValue is set as the arg value if it is not provided by the caller.
	// It is meaningful only for non-lazy, non-symbol args.
	DefaultValue Value

	// The list of types allowed as the arg. Meaningful only if !Symbol. This
	// field is optional. The parser will check for type conformance if len(Types)
	// len(Types)>0. This field may be nil, in which case it is up to the
	// typecheck callback to validate arg types.
	Types []ValueType
}

FormalArg is a description of an argument to a function.

func (FormalArg) String

func (f FormalArg) String() string

type Func

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

Func represents a function closure. It is stored in Value.

func NewUserDefinedFunc

func NewUserDefinedFunc(ast ASTNode, orgEnv *bindings, formalArgs []FormalArg, body ASTNode) *Func

NewUserDefinedFunc creates a new user-defined function. "ast" is used only to show debug messages on error.

func (*Func) Builtin

func (f *Func) Builtin() bool

Builtin returns true if the function is built into GQL.

func (*Func) Eval

func (f *Func) Eval(ctx context.Context, args ...Value) Value

Eval evaluates the closure

func (*Func) Hash

func (f *Func) Hash() hash.Hash

Hash computes the hash of the function, including its closure environment.

func (*Func) Marshal

func (f *Func) Marshal(ctx MarshalContext, enc *marshal.Encoder)

Marshal marshals given function.

func (*Func) String

func (f *Func) String() string

String generates a human-readable description.

type FuncCallback

type FuncCallback func(ctx context.Context, ast ASTNode, args []ActualArg) Value

FuncCallback is the function body. ast is syntax the tree node of the call, used only to report the source-code location on error. args is the arguments to the function.

type MarshalContext

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

Types MarshalContext and UnmarshalContext store state needed while marshaling or unmarshaling a table. They keep track of call frames referenced by closures, so that reference cycles involving closure -> frame -> a closure stored in the frame -> frame ... can be terminated.

Map keys are the set of frames referenced transitively by closures. Keys are callFrame.hash().

type NullStatus

type NullStatus int

NullStatus is the return value of Value.Null()

const (
	// PosNull is the standard status of a null value. PosNull sorts after
	// any non-null value.
	PosNull NullStatus = 1
	// NotNull is a placeholder for a non-null value.
	NotNull NullStatus = 0
	// NegNull value is created after negating a null value (expression "-NA" will
	// create such a value).  NegNull sorts before any non-null avlue.
	NegNull NullStatus = -1
)

type NullTableScanner

type NullTableScanner struct{}

NullScanner implements TableScanner for NA. Its Scan() always returns false.

func (*NullTableScanner) Scan

func (n *NullTableScanner) Scan() bool

func (*NullTableScanner) Value

func (n *NullTableScanner) Value() Value

type Opts

type Opts struct {
	// BackgroundContext is the default context used in stringers and other
	// non-critical codepaths.
	// If unset, context.Background() is used.
	BackgroundContext context.Context
	// CacheDir is directory that stores materialized tables for caching.  If
	// unset, gql.DefaultCacheRoot is used when bsSession != nil. Else
	// gql.DefaultLocalCacheRoot is used.
	CacheDir string
	// OverwriteFiles controls whether write() function overwrites existing files.
	OverwriteFiles bool
	// BigsliceSession is an initialized bigslice session. If unset, a local
	// bigslice executor will be created.
	BigsliceSession *exec.Session
	// ImmutableFilesRE x lists regexps of paths of files that can be assumed to
	// be immutable.  Immutable files can be hashed quickly using just their
	// pathnames, so they improve performance of gql.
	//
	// If nil, "^s3://grail-clinical.*" and "^s3://grail-results.*" are used.
	ImmutableFilesRE []*regexp.Regexp
}

Opts is passed to gql.Init

type PrefetchingTableScanner

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

PrefetchingTableScanner is a TableScanner that wraps another TableScanner and prefetches rows.

func (*PrefetchingTableScanner) Scan

func (s *PrefetchingTableScanner) Scan() bool

Scan implements the TableScanner interface.

func (*PrefetchingTableScanner) Value

func (s *PrefetchingTableScanner) Value() Value

Value implements the TableScanner interface.

type PrintArgs

type PrintArgs struct {
	// Out is the output destination
	Out termutil.Printer

	// Mode defines how the value is printed
	Mode PrintMode
	// TmpVars collects names of subtables in case they are not printed in-line.
	// The user can later print the subtable contents by typing these names.  If
	// TmpVars is nil, a nested table will be printed as "[omitted]".
	TmpVars *TmpVars

	// MaxInlinedTableLen is the threshold for printing a nested table inline.
	// When a table's compact representation exceeds this length (bytes), it is
	// printed as "tmpNN" or "[omitted]" depending on whether TmpVars!=nil.
	//
	// If MaxInlinedTableLen <= 0, it is set to 78.
	MaxInlinedTableLen int
}

PrintArgs define parameters to Value.Print method.

type PrintMode

type PrintMode int

PrintMode specifies how a value is printed in the Value.Print method.

const (
	// PrintValues prints the values. Tables are pretty printed.
	PrintValues PrintMode = iota
	// PrintCompact is similar to PrintValues, but it prints tables in more
	// compact form.  Suitable for use in unittests.
	PrintCompact
	// PrintDescription prints the description of the value, not the actual value.  THe
	// descrtiption includes such as the value type and columns (for a table).
	PrintDescription
)

type Session

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

Session represents a GQL session. It contains global variable bindings.

func NewSession

func NewSession() *Session

NewSession creates a new empty session.

func TestNewSession

func TestNewSession() *Session

func (*Session) Bindings

func (s *Session) Bindings() *bindings

Bindings returrs the bindings for the global symbols.

func (*Session) Eval

func (s *Session) Eval(ctx context.Context, expr ASTNode) Value

Eval evaluates an expression.

func (*Session) EvalFile

func (s *Session) EvalFile(ctx context.Context, path string) Value

EvalFile reads a script and evaluates it. Returns the value computed by the last expression.

func (*Session) EvalStatements

func (s *Session) EvalStatements(ctx context.Context, statements []ASTStatementOrLoad) Value

EvalStatements evaluates the statement and returns the value of the expression within. If st is of form "var := expr", binds var to the result of the expression so that subsequent Eval calls can refer to the variable.

func (*Session) Parse

func (s *Session) Parse(filename string, text []byte) ([]ASTStatementOrLoad, error)

Parse parses the given text. filename is embedded in an error messages. It returns io.EOF if the text is incomplete. If the text is unparsable for other reasons, it returns non-nil errors other than io.EOF.

func (*Session) SetGlobal

func (s *Session) SetGlobal(name string, value Value)

SetGlobal sets the global variable value.

REQUIRES: the variable must not exist already, otherwise the process crashes.

func (*Session) SetGlobals

func (s *Session) SetGlobals(vars map[string]Value)

SetGlobals sets a set of global variables.

REQUIRES: each variable must not exist already, otherwise the process crashes.

type Struct

type Struct interface {
	// Len returns the number of fields (columns) in the struct.
	Len() int
	// Field returns the name and the value of the i'th field.
	//
	// REQUIRES: 0 <= i < Len()
	Field(i int) StructField
	// Value returns the value for the specified column. It returns false if the
	// column is not found.
	Value(colName symbol.ID) (Value, bool)
}

Struct is a collection of name->value mappings. Its analogous to a row in a relational database.

To reduce heap allocation, every struct implementation embeds the the itable pointer in its first word. Take the following code snippet as an example:

v := &structN{values: ...}
initStruct(v)
var s Struct = v

The memory layout will look like below:

s (Struct) +------+ | iptr | --------------------------------------->+-------+ +------+ +-----------+ / |random | | data | ----------> | structImpl|-----------/ |itable | +------+ +-----------+ |stuff |

											 |  values   |							 +-------+
                      +-----------+
                       v (structN)

The first word of *v will point to the itable of type structN. Function initStruct() plumbs these the fields. The Value object stores only the data pointer to the struct. Struct can be reconstructed from Value by first reading the data pointer, then reading the first word of the data for itable.

For more details about Go interface implementation, see https://research.swtch.com/interfaces.

func NewSimpleStruct

func NewSimpleStruct(values ...StructField) Struct

NewSimpleStruct creates a new struct from the given list of fields. "t" must be of type StructKind, and its field descriptions must match the values'.

func ReadDir

func ReadDir(ctx context.Context, rootDir string) Struct

ReadDir creates a Struct consisting of files in a directory. The field name is a sanitized pathname, value is either a Table (if the file is a .tsv, .btsv, etc), or a string (if the file cannot be parsed as a table).

type StructField

type StructField struct {
	Name  symbol.ID
	Value Value
}

StructField represents a field (column) in a struct (row).

type StructImpl

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

type TSVColumn

type TSVColumn struct {
	// Name is the column name
	Name string
	// Type is the type of the cells in the column.
	Type ValueType
	// Description is an optional description of the column.
	Description string `json:",omitempty"`
}

TSVColumn defines a column in a TSV-like file.

type TSVFormat

type TSVFormat struct {
	// HeaderLines is the number of comment lines at the beginning of the file.
	// The value is typically 0 or 1.
	HeaderLines int
	// List of columns in each row.
	Columns []TSVColumn
}

TSVFormat defines the format of a TSV file. JSON encodable.

type TSVTable

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

TSVTable implements Table for a TSV file.

func (*TSVTable) Attrs

func (t *TSVTable) Attrs(ctx context.Context) TableAttrs

Attrs implements the Table interface

func (*TSVTable) Hash

func (t *TSVTable) Hash() hash.Hash

Hash implements the Table interface.

func (*TSVTable) Len

func (t *TSVTable) Len(ctx context.Context, mode CountMode) int

Len implements the Table interface

func (*TSVTable) Marshal

func (t *TSVTable) Marshal(ctx MarshalContext, enc *marshal.Encoder)

Marshal implements the Table interface.

func (*TSVTable) Prefetch

func (t *TSVTable) Prefetch(ctx context.Context)

Prefetch implements the Table interface.

func (*TSVTable) Scanner

func (t *TSVTable) Scanner(ctx context.Context, start, limit, total int) TableScanner

Scanner implements the Table interface.

type Table

type Table interface {
	// Attrs obtains the table metadata. Any of the attr fields may be empty.
	Attrs(ctx context.Context) TableAttrs
	// Scanner creates a table scanner. The parameters are used to scan the part
	// [start,limit) of the table, where range [0,total) represents the whole
	// table.
	//
	// For example, Scanner(0,2,3) reads the 2/3rds of the table, and
	// Scanner(2,3,3) reads the remaining 1/3rd of the table. Note that the
	// scanner implementation need not guarantee that the shard size is uniform
	// (but they strive to). Also, it need not always range-shard the table -- it
	// can hash-shard the table, it that's more convenient.
	//
	// REQUIRES: 0 <= start <= limit <= total.
	Scanner(ctx context.Context, start, limit, total int) TableScanner

	// Len returns the number of rows in the table. When mode==Approx, this method
	// should return the approx number of rows quickly. The Approx mode is used to
	// guide sharding and parallelizing policies. When mode==Exact, this method
	// must compute the exact # of rows in the table.
	Len(ctx context.Context, mode CountMode) int

	// Hash computes a hash value for this table.
	Hash() hash.Hash
	// Marshal produces a string that can be fed to parser to reconstruct this table.
	Marshal(ctx MarshalContext, enc *marshal.Encoder)
	// Prefetch is called to fetch the contents in the background, if possible.
	// This method shall never block.
	Prefetch(ctx context.Context)
}

Table is a collection of Structs. It can be stored in a Value. It is analogous to a table in a relational database. Thread safe.

func NewBAMTable

func NewBAMTable(path string, ast ASTNode, hash hash.Hash) Table

NewBAMTable returns a new BAM table backed by the BAM or PAM file at the provided path.

TODO(marius): support selecting out fields from reading so that these can be pushed down to the underlying iterators.

func NewFlatTable

func NewFlatTable(ast ASTNode, tables []Table, subshard bool) Table

NewFlatTable creates a flatten() table.

func NewMinNTable

func NewMinNTable(ctx context.Context, ast ASTNode, attrs TableAttrs, srcTable Table, sortKey *Func, minn int64, shards int) Table

NewMinNTable creates a table that yields the smallest minn rows in srcTable. If minn<0, it is treated as ∞. The row order is determined by applying sortKey to each row, then comparing the results lexicographically.

func NewNullTable

func NewNullTable() Table

func NewSimpleTable

func NewSimpleTable(recs []Value, h hash.Hash, attrs TableAttrs) Table

NewSimpleTable creates a trivial table that stores all the rows in memory.

func NewTSVTable

func NewTSVTable(path string, ast ASTNode, h hash.Hash, fh FileHandler, format *TSVFormat) Table

NewTSVTable creates a Table for reading the given TSV file. "h" is the hash of the input sources that generate this table. "fh" is typically a tsvFileHandler and is used to parse the file and serialize the table. "format" is an optional format spec for the file. If format=nil, this function guesses the column types from the file contents.

func NewTableFromFile

func NewTableFromFile(ctx context.Context, path string, ast ASTNode, fh FileHandler) Table

NewTableFromFile creates a Table object that reads from the given file. If the file type is not specified, this function attempts to derive it from the path name. The hash of the table is computed from the pathname and the file's attributes.

type TableAttrs

type TableAttrs struct {
	// Name is a short description of the the table, "tsv", "mapfilter", etc.
	Name string
	// Path is the file from which the contents were read. It is "" for a computed
	// table.
	Path string
	// List of columns in the table.
	Columns []TSVColumn
	// Description can be any string.
	Description string
}

TableAttrs represents a metadata about a table. It is used only for debugging and display purposes, so all the fields are optional.

type TableScanner

type TableScanner interface {
	// Scan fetches the next value. It returns false on EOF.
	Scan() bool
	// Value returns the current value.
	//
	// REQUIRES: the last Scan() call returned true.
	Value() Value
}

TableScanner is an interface for reading a table. Thread compatible.

func NewPrefetchingTableScanner

func NewPrefetchingTableScanner(ctx context.Context, s TableScanner, depth int) TableScanner

NewPrefetchingTableScanner creates a TableScanner that wraps another scanner and prefetches up to "depth" rows.

type TmpVars

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

TmpVars is used by Value.Print to give names to nested tables when values are printed on screen. TmpVars is a singleton object. Thread compatible.

func (*TmpVars) Flush

func (a *TmpVars) Flush(s *Session)

Flush adds the registered tmp variables as the global variables in the given session. The caller must ensure that "s" is not concurrently used by other threads.

func (*TmpVars) Register

func (a *TmpVars) Register(val Value) string

Register assigns a name of form "tmpNNN" to the given value. If New is invoked for the same value multiple times, it returns the same name.

type TypeCallback

type TypeCallback func(ast ASTNode, args []AIArg) AIType

TypeCallback is called when a script is parsed. ast is the syntax tree node of the call. It should check if the args[] conforms to the the function's input spec. It returns (function return type, free variables read by lazy args passed to the function>

type UnmarshalContext

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

UnmarshalContext stores state needed while unmarshaling a table. The map stores the set of frames referenced transitively by closures. Keys are callFrame.hash().

type UnmarshalMagic

type UnmarshalMagic [2]byte

UnmarshalMagic identifies a magic number prefixed before a serialized Table or Struct. It is used to look up the unmarshal callback.

type UnmarshalTableCallback

type UnmarshalTableCallback func(ctx UnmarshalContext, hash hash.Hash, dec *marshal.Decoder) Table

UnmarshalTableCallback reconstruct a table object from a binary stream produced by Table.MarshalGOB

type Value

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

Value is a unified representation of a value in gql. It can represent scalar values such as int64 and float64, as well as a Table or Struct. A value is immutable once constructed.

func MustStructValue

func MustStructValue(v Struct, colName symbol.ID) Value

MustStructValue returns the value for the specified column. It panics if the column is not found.

func NewBool

func NewBool(v bool) Value

NewBool creates a new boolean value.

func NewChar

func NewChar(ch rune) Value

NewChar creates a new character value.

func NewDate

func NewDate(t time.Time) Value

NewDate creates a value of DateType.

func NewDateTime

func NewDateTime(t time.Time) Value

NewDateTime creates a value of DateTimeType.

func NewDuration

func NewDuration(t time.Duration) Value

NewDuration creates a value of DurationType.

func NewEnum

func NewEnum(v string) Value

NewEnum creates a new Enum value.

func NewFileName

func NewFileName(v string) Value

NewFileName creates a new FileName value.

func NewFloat

func NewFloat(v float64) Value

NewFloat creates a new float value.

func NewFunc

func NewFunc(f *Func) Value

NewFunc creates a new function value.

func NewInt

func NewInt(v int64) Value

NewInt creates a new integer.

func NewMapFilterTable

func NewMapFilterTable(
	ctx context.Context,
	ast ASTNode,
	srcTable Table,
	filterExpr *Func,
	mapExprs []*Func,
	nshards int) Value

NewMapFilterTable creates a Table that implements map() or filter(). It reads from srcTable. It removes rows for which filterExpr(row)=false. If filterExpr=nil, then it is assumed to be just "true". Then it emits expr(row) for each expr∈mapExprs. If len(mapExprs)=0, then it emits each matched row as is.

if nshards>0, the table runs on multiple machines using bigslice.

func NewNull

func NewNull(v NullStatus) Value

NewNull creates a new null value.

REQUIRES: v != NotNull.

func NewString

func NewString(s string) Value

NewString creates a new String value.

func NewStruct

func NewStruct(v Struct) Value

NewStruct creates a Value from a Struct.

func NewStructFragment

func NewStructFragment(frag []StructField) Value

NewStructFragment creates a new Value of type StructFragmentType.

func NewTable

func NewTable(v Table) Value

NewTable creates a Value object from a table.

func ParseDateTime

func ParseDateTime(v string) Value

ParseDateTime creates a Date or DateTime from a string. It only accepts ISO8601-format strings.

func ParseDuration

func ParseDuration(v string) Value

ParseDuration constructs a Value object from a human-readable duration string. The duration format is defined in time.ParseDuration.

func RegisterBuiltinFunc

func RegisterBuiltinFunc(name, desc string,
	funcCB FuncCallback,
	typeCB TypeCallback,
	formalArgs ...FormalArg) Value

RegisterBuiltinFunc registers a builtin function. It should be called inside init(). Note when specifying the list of FormatlArgs certain restrictions are imposed by the parser. In particular, all positional arguments must be listed before named ones.

func TestUnmarshalValue

func TestUnmarshalValue(t *testing.T, ctxData, valData []byte) Value

func (Value) Bool

func (v Value) Bool(ast ASTNode) bool

Bool extracts a boolean value. "ast" is used only to report source code location on error.

REQUIRES: v.Type()==BoolType

func (Value) Char

func (v Value) Char(ast ASTNode) rune

Char extracts the character value. "ast" is used only to report source code location on error.

REQUIRES: v.Type()==CharType.

func (Value) DateTime

func (v Value) DateTime(ast ASTNode) time.Time

DateTime extracts the time/date value."ast" is used only to report source code location on error.

REQUIRES: v.Type() is one of {DateTimeType, DateType}

func (Value) Duration

func (v Value) Duration(ast ASTNode) time.Duration

Int extracts an integer value. "ast" is used only to report source code location on error.

REQUIRES: v.Type()==DurationType

func (Value) Float

func (v Value) Float(ast ASTNode) float64

Float extracts a float64 value. "ast" is used only to report source code location on error.

REQUIRES: v.Type()==FloatType

func (Value) Func

func (v Value) Func(ast ASTNode) *Func

Func extracts the function value

REQUIRES: v.Type()==FuncType.

func (Value) Hash

func (v Value) Hash() hash.Hash

Hash computes a hash of the value.

func (Value) Hash32

func (v Value) Hash32() uint32

Hash32 implements the bigslice.Hasher interface.

func (Value) Int

func (v Value) Int(ast ASTNode) int64

Int extracts an integer value. "ast" is used only to report source code location on error.

REQUIRES: v.Type()==IntType

func (Value) Marshal

func (v Value) Marshal(ctx MarshalContext, enc *marshal.Encoder)

Marshal encodes the value into the given buffer.

func (Value) MarshalBinary

func (v Value) MarshalBinary() ([]byte, error)

MarshalBinary implements the GOB interface. This function should be called only for static literals embedded in an ASTNode.

Call Marshal() for dynamically constructed Values, especially Table objects, that may contain *Funcs.

func (Value) Null

func (v Value) Null() NullStatus

Null checks whether the value is null. If v is not null, it returns NotNull. Else, it returns either PosNull or NegNull.

func (Value) Prefetch

func (v Value) Prefetch(ctx context.Context)

Prefetch is called to fetch the contents in the background, if possible. This method never blocks.

func (Value) Print

func (v Value) Print(ctx context.Context, args PrintArgs)

Print prints the value according to args.

func (Value) Str

func (v Value) Str(ast ASTNode) string

Str extracts the string value. "ast" is used only to report source code location on error.

REQUIRES: v.Type() is one of {StringType,FileNameType,EnumType}.

func (Value) String

func (v Value) String() string

String produces a human-readable string of the value. It is a shorthand for v.Print() with mode PrintCompact

func (Value) Struct

func (v Value) Struct(ast ASTNode) Struct

Struct extracts a struct from the value. "ast" is used only to report source code location on error.

REQUIRES: v.Type() == StructType,NullType

TODO(saito) do we need to special-case null type here?

func (Value) StructFragment

func (v Value) StructFragment() []StructField

StructFragment extracts a []StructField created by "expr./columnregex/" construct.

func (Value) Table

func (v Value) Table(ast ASTNode) Table

Table extracts a table from the value. "ast" is used only to report source code location on error.

REQUIRES: v.Type() == TableType,NullType

TODO(saito) do we need to special-case null type here?

func (Value) Type

func (v Value) Type() ValueType

Type returns the type of the value.

func (*Value) Unmarshal

func (v *Value) Unmarshal(ctx UnmarshalContext, dec *marshal.Decoder)

Unmarshal decodes the buffer encoded using Marshal.

func (*Value) UnmarshalBinary

func (v *Value) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the GOB interface. This function should be called only for static literals embedded in an ASTNode.

Call Marshal() for dynamically constructed Values, especially Table objects, that may contain *Funcs.

func (Value) Valid

func (v Value) Valid() bool

Valid returns true if it stores a value. Note that null is a valid value. Only a default-constructed Value returns false.

type ValueType

type ValueType byte

ValueType defines the type of a Value object.

const (
	// InvalidType is a sentinel. It is not a valid value.
	InvalidType ValueType = iota
	// NullType represents a missing value
	NullType
	// BoolType represents a true or a false
	BoolType
	// IntType represents an int64 value
	IntType
	// FloatType represents an float64 value
	FloatType
	// StringType represents a UTF-8-encoded string
	StringType
	// FileNameType represents a UTF-8-encoded filename. FileNameType is a legacy
	// type. It is effectively the same as StringType.
	FileNameType
	// FileNameType represents an enum value. EnumType is a legacy type. It is
	// effectively the same as StringType.
	EnumType
	// CharType represents a UTF-8 character.
	CharType
	// DateType represents time.Time, but at a date granurality.
	DateType
	// DateTimeType represents time.Time.
	DateTimeType
	// DurationType represents time.Duration.
	DurationType
	UnusedType // Available for future use.
	// StructType stores a Struct
	StructType
	// StructFragmentType stores []StructField. It is a result of expanding a
	// regex struct pattern.
	StructFragmentType
	// TableType stores a Table
	TableType
	// FuncType stores a Func
	FuncType
)

Caution: these values must be stable. They are saved on disk.

func (ValueType) LikeDate

func (v ValueType) LikeDate() bool

LikeDate checks if the value's representation is a time.Time.

func (ValueType) LikeString

func (v ValueType) LikeString() bool

LikeString checks if the value's representation is a string.

func (ValueType) MarshalJSON

func (v ValueType) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (ValueType) String

func (i ValueType) String() string

func (*ValueType) UnmarshalJSON

func (v *ValueType) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler.

Jump to

Keyboard shortcuts

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