Documentation
¶
Overview ¶
Package types contains some very common utilities used by Dgraph. These utilities are of "miscellaneous" nature, e.g., error checking.
Index ¶
- Constants
- func BytesAsFloatArray(encoded []byte) []float32
- func CompareBetween(dst, val1, val2 Val) bool
- func CompareVals(op string, arg1, arg2 Val) bool
- func Contains(a *s2.Loop, b *s2.Loop) bool
- func EarthAngle(dist float64) s1.Angle
- func Encrypt(plain string) (string, error)
- func Equal(a, b Val) (bool, error)
- func FloatArrayAsBytes(v []float32) []byte
- func FloatArrayAsString(v []float32) string
- func GoodTimeZone(offset int) bool
- func IndexGeoTokens(g geom.T) ([]string, error)
- func Intersects(l1 *s2.Loop, l2 *s2.Loop) bool
- func IsGeoFunc(str string) bool
- func IsSortable(tid TypeID) bool
- func Less(a, b Val) (bool, error)
- func Marshal(from Val, to *Val) error
- func MatchGeo(value *pb.TaskValue, q *GeoQueryData) bool
- func ObjectValue(id TypeID, value interface{}) (*api.Value, error)
- func ParseTime(val string) (time.Time, error)
- func ParseVFloat(s string) ([]float32, error)
- func Sort(v [][]Val, ul *[]uint64, desc []bool, lang string) error
- func SortTopN(v [][]Val, ul *[]uint64, desc []bool, lang string, n int) error
- func SortWithFacet(v [][]Val, ul *[]uint64, l []*pb.Facets, desc []bool, lang string) error
- func VerifyPassword(plain, encrypted string) error
- type Area
- type GeoQueryData
- type Length
- type QueryType
- type ShardedMap
- func (s *ShardedMap) Get(key uint64) (Val, bool)
- func (s *ShardedMap) GetShardOrNil(key int) map[uint64]Val
- func (s *ShardedMap) IsEmpty() bool
- func (s *ShardedMap) Iterate(f func(uint64, Val) error) error
- func (s *ShardedMap) Len() int
- func (s *ShardedMap) Merge(other *ShardedMap, ag func(a, b Val) Val)
- func (s *ShardedMap) Set(key uint64, value Val)
- type TypeID
- type Val
Constants ¶
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 )
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.
const (
BigFloatPrecision = 200
)
const EarthRadiusMeters = 1000 * 6371
EarthRadiusMeters is the radius of the earth in meters (in a spherical earth model).
const NumShards = 30
Variables ¶
This section is empty.
Functions ¶
func BytesAsFloatArray ¶
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 ¶
CompareBetween compares if the dst value lie between two values val1 and val2(both inclusive).
func CompareVals ¶
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 EarthAngle ¶
EarthAngle converts a to distance on earth in meters to an angle
func FloatArrayAsBytes ¶
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 GoodTimeZone ¶
GoodTimeZone returns true if timezone (provided in offset format in seconds) is valid according to RFC3339.
func IndexGeoTokens ¶
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 ¶
Intersects returns true if the two loops intersect.
func IsSortable ¶
IsSortable returns true, if tid is sortable. Otherwise it returns false.
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 ¶
ObjectValue converts into api.Value.
func ParseTime ¶
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 ¶
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 SortWithFacet ¶
SortWithFacet sorts the given array in-place and considers the given facets to calculate the proper ordering.
func VerifyPassword ¶
VerifyPassword checks that the plain-text password matches the encrypted password.
Types ¶
type Area ¶
type Area float64
Area denotes an area on Earth
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 ¶
EarthDistance converts an angle to distance on earth in meters.
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) GetShardOrNil ¶
func (s *ShardedMap) GetShardOrNil(key int) map[uint64]Val
func (*ShardedMap) IsEmpty ¶
func (s *ShardedMap) IsEmpty() bool
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 ¶
TypeForName returns the type corresponding to the given name. If name is not recognized, it returns nil.
func TypeForValue ¶
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.
type Val ¶
type Val struct {
Tid TypeID
Value interface{}
}
Val is a value with type information.
func ValueForType ¶
ValueForType returns the zero value for a type id
func (Val) MarshalJSON ¶
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.