types

package
v25.0.0-split-vector3 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2025 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Overview

Package types contains some very common utilities used by Dgraph. These utilities are of "miscellaneous" nature, e.g., error checking.

Index

Constants

View Source
const (
	// MinCellLevel is the smallest cell level (largest cell size) used by indexing
	MinCellLevel = 5 // Approx 250km x 380km
	// MaxCellLevel is the largest cell level (smallest cell size) used by indexing
	MaxCellLevel = 16 // Approx 120m x 180m
	// MaxCells is the maximum number of cells to use when indexing regions.
	MaxCells = 18
)
View Source
const (
	// DefaultID represents the default type.
	DefaultID = TypeID(pb.Posting_DEFAULT)
	// BinaryID represents the binary data type.
	BinaryID = TypeID(pb.Posting_BINARY)
	// IntID represents the integer type.
	IntID = TypeID(pb.Posting_INT)
	// FloatID represents the floating-point number type.
	FloatID = TypeID(pb.Posting_FLOAT)
	// BoolID represents the boolean type.
	BoolID = TypeID(pb.Posting_BOOL)
	// DateTimeID represents the datetime type.
	DateTimeID = TypeID(pb.Posting_DATETIME)
	// GeoID represents the geo-location data type.
	GeoID = TypeID(pb.Posting_GEO)
	// UidID represents the uid type.
	UidID = TypeID(pb.Posting_UID)
	// PasswordID represents the password type.
	PasswordID = TypeID(pb.Posting_PASSWORD)
	// StringID represents the string type.
	StringID = TypeID(pb.Posting_STRING)
	// TODO: Add constant for pb.Posting_OBJECT ??
	//       Not clear if it belongs here, but if it does,
	//       we should add it, if not, we should document here
	//       why it does not belong here.
	// VFloatID represents a vector of IEEE754 64-bit floats.
	VFloatID = TypeID(pb.Posting_VFLOAT)
	// UndefinedID represents the undefined type.
	UndefinedID = TypeID(100)
	// BigFloatID represents the arbitrary precision type.
	BigFloatID = TypeID(pb.Posting_BIGFLOAT)
)

Note: These ids are stored in the posting lists to indicate the type of the data. The order *cannot* be changed without breaking existing data. When adding a new type *always* add to the end of this list. Never delete anything from this list even if it becomes unused.

View Source
const (
	BigFloatPrecision = 200
)
View Source
const EarthRadiusMeters = 1000 * 6371

EarthRadiusMeters is the radius of the earth in meters (in a spherical earth model).

View Source
const NumShards = 30

Variables

This section is empty.

Functions

func BytesAsFloatArray

func BytesAsFloatArray(encoded []byte) []float32

BytesAsFloatArray(encoded) converts encoded into a []float32. If len(encoded) % 4 is not 0, it will ignore any trailing bytes, and simply convert 4 bytes at a time to generate the float64 entries. Current implementation assuming littleEndian encoding

func CompareBetween

func CompareBetween(dst, val1, val2 Val) bool

CompareBetween compares if the dst value lie between two values val1 and val2(both inclusive).

func CompareVals

func CompareVals(op string, arg1, arg2 Val) bool

CompareVals compares two values using the given comparison type. Should be used only in filtering arg1 by comparing with arg2. arg2 is reference Val to which arg1 is compared.

func Contains

func Contains(a *s2.Loop, b *s2.Loop) bool

Contains checks whether loop A contains loop B.

func EarthAngle

func EarthAngle(dist float64) s1.Angle

EarthAngle converts a to distance on earth in meters to an angle

func Encrypt

func Encrypt(plain string) (string, error)

Encrypt encrypts the given plain-text password.

func Equal

func Equal(a, b Val) (bool, error)

Equal returns true if a is equal to b.

func FloatArrayAsBytes

func FloatArrayAsBytes(v []float32) []byte

FloatArrayAsBytes(v) will create a byte array encoding v using LittleEndian format. This is sort of the inverse of BytesAsFloatArray, but note that we can always be successful converting to bytes, but the inverse is not feasible.

func FloatArrayAsString

func FloatArrayAsString(v []float32) string

func GoodTimeZone

func GoodTimeZone(offset int) bool

GoodTimeZone returns true if timezone (provided in offset format in seconds) is valid according to RFC3339.

func IndexGeoTokens

func IndexGeoTokens(g geom.T) ([]string, error)

IndexGeoTokens returns the tokens to be used in a geospatial index for the given geometry. If the geometry is not supported it returns an error.

func Intersects

func Intersects(l1 *s2.Loop, l2 *s2.Loop) bool

Intersects returns true if the two loops intersect.

func IsGeoFunc

func IsGeoFunc(str string) bool

IsGeoFunc returns if a function is of geo type.

func IsSortable

func IsSortable(tid TypeID) bool

IsSortable returns true, if tid is sortable. Otherwise it returns false.

func Less

func Less(a, b Val) (bool, error)

Less returns true if a is strictly less than b.

func Marshal

func Marshal(from Val, to *Val) error

func MatchGeo

func MatchGeo(value *pb.TaskValue, q *GeoQueryData) bool

MatchGeo matches values and GeoQueryData and ensures that the value actually matches the query criteria.

func ObjectValue

func ObjectValue(id TypeID, value interface{}) (*api.Value, error)

ObjectValue converts into api.Value.

func ParseTime

func ParseTime(val string) (time.Time, error)

ParseTime parses the time from string trying various datetime formats. By default, Go parses time in UTC unless specified in the data itself.

func ParseVFloat

func ParseVFloat(s string) ([]float32, error)

parseVFloat(s) will generate a slice of float64 values, as long as s is either an empty string, or if it is formatted according to the following ebnf:

floatArray ::= "[" [floatList] [whitespace] "]"
floatList := float32Val |
             float32Val floatSpaceList |
             float32Val floatCommaList
floatSpaceList := (whitespace float32Val)+
floatCommaList := ([whitespace] "," [whitespace] float32Val)+
float32Val := < a string rep of a float32 value >

func Sort

func Sort(v [][]Val, ul *[]uint64, desc []bool, lang string) error

Sort sorts the given array in-place.

func SortTopN

func SortTopN(v [][]Val, ul *[]uint64, desc []bool, lang string, n int) error

SortTopN finds and places the first n elements in 0-N

func SortWithFacet

func SortWithFacet(v [][]Val, ul *[]uint64, l []*pb.Facets, desc []bool, lang string) error

SortWithFacet sorts the given array in-place and considers the given facets to calculate the proper ordering.

func VerifyPassword

func VerifyPassword(plain, encrypted string) error

VerifyPassword checks that the plain-text password matches the encrypted password.

Types

type Area

type Area float64

Area denotes an area on Earth

func EarthArea

func EarthArea(a float64) Area

EarthArea converts an area on the unit sphere to an area on earth in sq. meters.

func (Area) String

func (a Area) String() string

String converts the area to human readable units

type GeoQueryData

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

GeoQueryData is pb.data used by the geo query filter to additionally filter the geometries.

func GetGeoTokens

func GetGeoTokens(srcFunc *pb.SrcFunction) ([]string, *GeoQueryData, error)

GetGeoTokens returns the corresponding index keys based on the type of function.

func (GeoQueryData) MatchesFilter

func (q GeoQueryData) MatchesFilter(g geom.T) bool

MatchesFilter applies the query filter to a geo value

type Length

type Length float64

Length denotes a length on Earth

func EarthDistance

func EarthDistance(angle s1.Angle) Length

EarthDistance converts an angle to distance on earth in meters.

func (Length) String

func (l Length) String() string

String converts the length to human readable units

type QueryType

type QueryType byte

QueryType indicates the type of geo query.

const (
	// QueryTypeWithin finds all points that are within the given geometry
	QueryTypeWithin QueryType = iota
	// QueryTypeContains finds all polygons that contain the given point
	QueryTypeContains
	// QueryTypeIntersects finds all objects that intersect the given geometry
	QueryTypeIntersects
	// QueryTypeNear finds all points that are within the given distance from the given point.
	QueryTypeNear
)

type ShardedMap

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

func NewShardedMap

func NewShardedMap() *ShardedMap

func (*ShardedMap) Get

func (s *ShardedMap) Get(key uint64) (Val, bool)

func (*ShardedMap) GetShardOrNil

func (s *ShardedMap) GetShardOrNil(key int) map[uint64]Val

func (*ShardedMap) IsEmpty

func (s *ShardedMap) IsEmpty() bool

func (*ShardedMap) Iterate

func (s *ShardedMap) Iterate(f func(uint64, Val) error) error

func (*ShardedMap) Len

func (s *ShardedMap) Len() int

func (*ShardedMap) Merge

func (s *ShardedMap) Merge(other *ShardedMap, ag func(a, b Val) Val)

func (*ShardedMap) Set

func (s *ShardedMap) Set(key uint64, value Val)

type TypeID

type TypeID pb.Posting_ValType

TypeID represents the type of the data.

func TypeForName

func TypeForName(name string) (TypeID, bool)

TypeForName returns the type corresponding to the given name. If name is not recognized, it returns nil.

func TypeForValue

func TypeForValue(v []byte) (TypeID, interface{})

TypeForValue tries to determine the most likely type based on a value. We only want to use this function when there's no schema type and no suggested storage type. Returns the guessed type or DefaultID if it couldn't be determined. If retval is non-nil, the parsed value is returned, useful in conjunction with ObjectValue().

func (TypeID) Enum

func (t TypeID) Enum() pb.Posting_ValType

Enum takes a TypeID value and returns the corresponding ValType enum value.

func (TypeID) IsNumber

func (t TypeID) IsNumber() bool

IsNumber returns whether the type is a number type.

func (TypeID) IsScalar

func (t TypeID) IsScalar() bool

IsScalar returns whether the type is a scalar type.

func (TypeID) Name

func (t TypeID) Name() string

Name returns the name of the type.

type Val

type Val struct {
	Tid   TypeID
	Value interface{}
}

Val is a value with type information.

func Convert

func Convert(from Val, toID TypeID) (Val, error)

Convert converts the value to given scalar type.

func ValueForType

func ValueForType(id TypeID) Val

ValueForType returns the zero value for a type id

func (Val) MarshalJSON

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

MarshalJSON makes Val satisfy the json.Marshaler interface.

func (Val) Safe

func (v Val) Safe() interface{}

Safe ensures that Val's Value is not nil. This is useful when doing type assertions and default values might be involved. This function won't change the original v.Value, may it be nil. See: "Default value vars" in `fillVars()` Returns a safe v.Value suitable for type assertions.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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