Documentation
¶
Overview ¶
Package pilosa enables querying a Pilosa server.
This client uses Pilosa's http+protobuf API.
Usage:
import (
"fmt"
pilosa "github.com/pilosa/go-pilosa"
)
// Create a Client instance
client := pilosa.DefaultClient()
// Create an Index instance
index, err := NewIndex("repository", nil)
if err != nil {
panic(err)
}
stargazer, err := index.Frame("stargazer", nil)
if err != nil {
panic(err)
}
response, err := client.Query(stargazer.Bitmap(5), nil)
if err != nil {
panic(err)
}
// Act on the result
fmt.Println(response.Result())
See also https://www.pilosa.com/docs/api-reference/ and https://www.pilosa.com/docs/query-language/.
Index ¶
- Variables
- func ValidFrameName(name string) bool
- func ValidIndexName(name string) bool
- func ValidLabel(label string) bool
- type BitmapResult
- type CacheType
- type Client
- func (c *Client) CreateFrame(frame *Frame) error
- func (c *Client) CreateIndex(index *Index) error
- func (c *Client) DeleteFrame(frame *Frame) error
- func (c *Client) DeleteIndex(index *Index) error
- func (c *Client) EnsureFrame(frame *Frame) error
- func (c *Client) EnsureIndex(index *Index) error
- func (c *Client) Query(query PQLQuery, options *QueryOptions) (*QueryResponse, error)
- func (c *Client) Schema() (*Schema, error)
- type ClientOptions
- type Cluster
- type ColumnItem
- type CountResultItem
- type Error
- type Frame
- func (f *Frame) Bitmap(rowID uint64) *PQLBitmapQuery
- func (f *Frame) BitmapTopN(n uint64, bitmap *PQLBitmapQuery) *PQLBitmapQuery
- func (f *Frame) ClearBit(rowID uint64, columnID uint64) *PQLBaseQuery
- func (f *Frame) FilterFieldTopN(n uint64, bitmap *PQLBitmapQuery, field string, values ...interface{}) *PQLBitmapQuery
- func (f *Frame) InverseBitmap(columnID uint64) *PQLBaseQuery
- func (f *Frame) Range(rowID uint64, start time.Time, end time.Time) *PQLBitmapQuery
- func (f *Frame) SetBit(rowID uint64, columnID uint64) *PQLBaseQuery
- func (f *Frame) SetBitTimestamp(rowID uint64, columnID uint64, timestamp time.Time) *PQLBaseQuery
- func (f *Frame) SetRowAttrs(rowID uint64, attrs map[string]interface{}) *PQLBaseQuery
- func (f *Frame) TopN(n uint64) *PQLBitmapQuery
- type FrameInfo
- type FrameOptions
- type Index
- func (d *Index) BatchQuery(queries ...PQLQuery) *PQLBatchQuery
- func (d *Index) Count(bitmap *PQLBitmapQuery) *PQLBaseQuery
- func (d *Index) Difference(bitmap1 *PQLBitmapQuery, bitmap2 *PQLBitmapQuery, bitmaps ...*PQLBitmapQuery) *PQLBitmapQuery
- func (d *Index) Frame(name string, options *FrameOptions) (*Frame, error)
- func (d *Index) Intersect(bitmap1 *PQLBitmapQuery, bitmap2 *PQLBitmapQuery, bitmaps ...*PQLBitmapQuery) *PQLBitmapQuery
- func (d *Index) Name() string
- func (d *Index) RawQuery(query string) *PQLBaseQuery
- func (d *Index) SetColumnAttrs(columnID uint64, attrs map[string]interface{}) *PQLBaseQuery
- func (d *Index) Union(bitmap1 *PQLBitmapQuery, bitmap2 *PQLBitmapQuery, bitmaps ...*PQLBitmapQuery) *PQLBitmapQuery
- type IndexInfo
- type IndexOptions
- type PQLBaseQuery
- type PQLBatchQuery
- type PQLBitmapQuery
- type PQLQuery
- type QueryOptions
- type QueryResponse
- type QueryResult
- type Schema
- type TimeQuantum
- type URI
Constants ¶
This section is empty.
Variables ¶
var ( ErrorEmptyCluster = NewError("No usable addresses in the cluster") ErrorIndexExists = NewError("Index exists") ErrorFrameExists = NewError("Frame exists") ErrorInvalidIndexName = NewError("Invalid index name") ErrorInvalidFrameName = NewError("Invalid frame name") ErrorInvalidLabel = NewError("Invalid label") ErrorInverseBitmapsNotEnabled = NewError("Inverse bitmaps support was not enabled for this frame") )
Predefined Pilosa errors.
Functions ¶
func ValidFrameName ¶
ValidFrameName returns true if the given frame name is valid, otherwise false.
func ValidIndexName ¶
ValidIndexName returns true if the given index name is valid, otherwise false.
func ValidLabel ¶
ValidLabel returns true if the given label is valid, otherwise false.
Types ¶
type BitmapResult ¶
BitmapResult represents a result from Bitmap, Union, Intersect, Difference and Range PQL calls.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the HTTP client for Pilosa server.
func DefaultClient ¶
func DefaultClient() *Client
DefaultClient creates a client with the default address and options.
func NewClientWithCluster ¶
func NewClientWithCluster(cluster *Cluster, options *ClientOptions) *Client
NewClientWithCluster creates a client with the given cluster and options. Pass nil for default options.
func NewClientWithURI ¶
NewClientWithURI creates a client with the given server address.
func (*Client) CreateFrame ¶
CreateFrame creates a frame on the server using the given Frame struct.
func (*Client) CreateIndex ¶
CreateIndex creates an index on the server using the given Index struct.
func (*Client) DeleteFrame ¶
DeleteFrame deletes a frame on the server.
func (*Client) DeleteIndex ¶
DeleteIndex deletes an index on the server.
func (*Client) EnsureFrame ¶
EnsureFrame creates a frame on the server if it doesn't exists.
func (*Client) EnsureIndex ¶
EnsureIndex creates an index on the server if it does not exist.
func (*Client) Query ¶
func (c *Client) Query(query PQLQuery, options *QueryOptions) (*QueryResponse, error)
Query runs the given query against the server with the given options. Pass nil for default options.
type ClientOptions ¶
type ClientOptions struct {
SocketTimeout time.Duration
ConnectTimeout time.Duration
PoolSizePerRoute int
TotalPoolSize int
}
ClientOptions control the properties of client connection to the server
type Cluster ¶
type Cluster struct {
// contains filtered or unexported fields
}
Cluster contains hosts in a Pilosa cluster.
func NewClusterWithHost ¶
NewClusterWithHost returns a cluster with the given URIs.
func (*Cluster) RemoveHost ¶
RemoveHost removes the host with the given URI from the cluster.
type ColumnItem ¶
ColumnItem represents data about a column. Column data is only returned if QueryOptions.Columns was set to true.
type CountResultItem ¶
CountResultItem represents a result from TopN call.
type Frame ¶
type Frame struct {
// contains filtered or unexported fields
}
Frame structs are used to segment and define different functional characteristics within your entire index. You can think of a Frame as a table-like data partition within your Index. Row-level attributes are namespaced at the Frame level.
func (*Frame) Bitmap ¶
func (f *Frame) Bitmap(rowID uint64) *PQLBitmapQuery
Bitmap creates a bitmap query using the row label. Bitmap retrieves the indices of all the set bits in a row or column based on whether the row label or column label is given in the query. It also retrieves any attributes set on that row or column.
func (*Frame) BitmapTopN ¶
func (f *Frame) BitmapTopN(n uint64, bitmap *PQLBitmapQuery) *PQLBitmapQuery
BitmapTopN creates a TopN query with the given item count and bitmap. This variant supports customizing the bitmap query.
func (*Frame) ClearBit ¶
func (f *Frame) ClearBit(rowID uint64, columnID uint64) *PQLBaseQuery
ClearBit creates a ClearBit query. ClearBit, assigns a value of 0 to a bit in the binary matrix, thus disassociating the given row in the given frame from the given column.
func (*Frame) FilterFieldTopN ¶
func (f *Frame) FilterFieldTopN(n uint64, bitmap *PQLBitmapQuery, field string, values ...interface{}) *PQLBitmapQuery
FilterFieldTopN creates a TopN query with the given item count, bitmap, field and the filter for that field The field and filters arguments work together to only return Bitmaps which have the attribute specified by field with one of the values specified in filters.
func (*Frame) InverseBitmap ¶
func (f *Frame) InverseBitmap(columnID uint64) *PQLBaseQuery
InverseBitmap creates a bitmap query using the column label. Bitmap retrieves the indices of all the set bits in a row or column based on whether the row label or column label is given in the query. It also retrieves any attributes set on that row or column.
func (*Frame) Range ¶
Range creates a Range query. Similar to Bitmap, but only returns bits which were set with timestamps between the given start and end timestamps.
func (*Frame) SetBit ¶
func (f *Frame) SetBit(rowID uint64, columnID uint64) *PQLBaseQuery
SetBit creates a SetBit query. SetBit, assigns a value of 1 to a bit in the binary matrix, thus associating the given row in the given frame with the given column.
func (*Frame) SetBitTimestamp ¶
SetBitTimestamp creates a SetBit query with timestamp. SetBit, assigns a value of 1 to a bit in the binary matrix, thus associating the given row in the given frame with the given column.
func (*Frame) SetRowAttrs ¶
func (f *Frame) SetRowAttrs(rowID uint64, attrs map[string]interface{}) *PQLBaseQuery
SetRowAttrs creates a SetRowAttrs query. SetRowAttrs associates arbitrary key/value pairs with a row in a frame. Following types are accepted: integer, float, string and boolean types.
func (*Frame) TopN ¶
func (f *Frame) TopN(n uint64) *PQLBitmapQuery
TopN creates a TopN query with the given item count. Returns the id and count of the top n bitmaps (by count of bits) in the frame.
type FrameInfo ¶
type FrameInfo struct {
Name string `json:"name"`
}
FrameInfo represents schema information for a frame.
type FrameOptions ¶
type FrameOptions struct {
RowLabel string
// If a Frame has a time quantum, then Views are generated for each of the defined time segments.
TimeQuantum TimeQuantum
// Enables inverted frames
InverseEnabled bool
CacheType CacheType
CacheSize uint
}
FrameOptions contains options to customize Frame objects and frame queries.
func (FrameOptions) String ¶
func (options FrameOptions) String() string
type Index ¶
type Index struct {
// contains filtered or unexported fields
}
Index is a Pilosa index. The purpose of the Index is to represent a data namespace. You cannot perform cross-index queries. Column-level attributes are global to the Index.
func NewIndex ¶
func NewIndex(name string, options *IndexOptions) (*Index, error)
NewIndex creates an index with a name and options. Pass nil for default options.
func (*Index) BatchQuery ¶
func (d *Index) BatchQuery(queries ...PQLQuery) *PQLBatchQuery
BatchQuery creates a batch query with the given queries.
func (*Index) Count ¶
func (d *Index) Count(bitmap *PQLBitmapQuery) *PQLBaseQuery
Count creates a Count query. Returns the number of set bits in the BITMAP_CALL passed in.
func (*Index) Difference ¶
func (d *Index) Difference(bitmap1 *PQLBitmapQuery, bitmap2 *PQLBitmapQuery, bitmaps ...*PQLBitmapQuery) *PQLBitmapQuery
Difference creates an Intersect query. Difference returns all of the bits from the first BITMAP_CALL argument passed to it, without the bits from each subsequent BITMAP_CALL.
func (*Index) Frame ¶
func (d *Index) Frame(name string, options *FrameOptions) (*Frame, error)
Frame creates a frame struct with the specified name and defaults.
func (*Index) Intersect ¶
func (d *Index) Intersect(bitmap1 *PQLBitmapQuery, bitmap2 *PQLBitmapQuery, bitmaps ...*PQLBitmapQuery) *PQLBitmapQuery
Intersect creates an Intersect query. Intersect performs a logical AND on the results of each BITMAP_CALL query passed to it.
func (*Index) RawQuery ¶
func (d *Index) RawQuery(query string) *PQLBaseQuery
RawQuery creates a query with the given string. Note that the query is not validated before sending to the server.
func (*Index) SetColumnAttrs ¶
func (d *Index) SetColumnAttrs(columnID uint64, attrs map[string]interface{}) *PQLBaseQuery
SetColumnAttrs creates a SetColumnAttrs query. SetColumnAttrs associates arbitrary key/value pairs with a column in an index. Following types are accepted: integer, float, string and boolean types.
func (*Index) Union ¶
func (d *Index) Union(bitmap1 *PQLBitmapQuery, bitmap2 *PQLBitmapQuery, bitmaps ...*PQLBitmapQuery) *PQLBitmapQuery
Union creates a Union query. Union performs a logical OR on the results of each BITMAP_CALL query passed to it.
type IndexOptions ¶
type IndexOptions struct {
ColumnLabel string
TimeQuantum TimeQuantum
}
IndexOptions contains options to customize Index structs and column queries.
func (IndexOptions) String ¶
func (options IndexOptions) String() string
type PQLBaseQuery ¶
type PQLBaseQuery struct {
// contains filtered or unexported fields
}
PQLBaseQuery is the base implementation for PQLQuery.
func NewPQLBaseQuery ¶
func NewPQLBaseQuery(pql string, index *Index, err error) *PQLBaseQuery
NewPQLBaseQuery creates a new PQLQuery with the given PQL and index.
func (PQLBaseQuery) Error ¶
func (q PQLBaseQuery) Error() error
Error returns the error or nil for this query.
func (*PQLBaseQuery) Index ¶
func (q *PQLBaseQuery) Index() *Index
Index returns the index for this query
type PQLBatchQuery ¶
type PQLBatchQuery struct {
// contains filtered or unexported fields
}
PQLBatchQuery contains a batch of PQL queries. Use Index.BatchQuery function to create an instance.
Usage:
index, err := NewIndex("repository", nil)
stargazer, err := index.Frame("stargazer", nil)
query := repo.BatchQuery(
stargazer.Bitmap(5),
stargazer.Bitmap(15),
repo.Union(stargazer.Bitmap(20), stargazer.Bitmap(25)))
func (*PQLBatchQuery) Add ¶
func (q *PQLBatchQuery) Add(query PQLQuery)
Add adds a query to the batch.
func (*PQLBatchQuery) Error ¶
func (q *PQLBatchQuery) Error() error
func (*PQLBatchQuery) Index ¶
func (q *PQLBatchQuery) Index() *Index
Index returns the index for this query.
type PQLBitmapQuery ¶
type PQLBitmapQuery struct {
// contains filtered or unexported fields
}
PQLBitmapQuery is the return type for bitmap queries.
func NewPQLBitmapQuery ¶
func NewPQLBitmapQuery(pql string, index *Index, err error) *PQLBitmapQuery
NewPQLBitmapQuery creates a new PqlBitmapQuery.
func (PQLBitmapQuery) Error ¶
func (q PQLBitmapQuery) Error() error
Error returns the error or nil for this query.
func (*PQLBitmapQuery) Index ¶
func (q *PQLBitmapQuery) Index() *Index
Index returns the index for this query/
type QueryOptions ¶
type QueryOptions struct {
// Columns enables returning columns in the query response.
Columns bool
}
QueryOptions contains options to customize the Query function.
type QueryResponse ¶
type QueryResponse struct {
ErrorMessage string
Success bool
// contains filtered or unexported fields
}
QueryResponse represents the response from a Pilosa query.
func (*QueryResponse) Column ¶
func (qr *QueryResponse) Column() *ColumnItem
Column returns the first column or nil.
func (*QueryResponse) Columns ¶
func (qr *QueryResponse) Columns() []*ColumnItem
Columns returns all columns in the response.
func (*QueryResponse) Result ¶
func (qr *QueryResponse) Result() *QueryResult
Result returns the first result or nil.
func (*QueryResponse) Results ¶
func (qr *QueryResponse) Results() []*QueryResult
Results returns all results in the response.
type QueryResult ¶
type QueryResult struct {
Bitmap *BitmapResult
CountItems []*CountResultItem
Count uint64
}
QueryResult represent one of the results in the response.
type Schema ¶
type Schema struct {
Indexes []*IndexInfo `json:"indexes"`
}
Schema contains the index and frame metadata.
type TimeQuantum ¶
type TimeQuantum string
TimeQuantum type represents valid time quantum values for frames having support for that.
const ( TimeQuantumNone TimeQuantum = "" TimeQuantumYear TimeQuantum = "Y" TimeQuantumMonth TimeQuantum = "M" TimeQuantumDay TimeQuantum = "D" TimeQuantumHour TimeQuantum = "H" TimeQuantumYearMonth TimeQuantum = "YM" TimeQuantumMonthDay TimeQuantum = "MD" TimeQuantumDayHour TimeQuantum = "DH" TimeQuantumYearMonthDay TimeQuantum = "YMD" TimeQuantumMonthDayHour TimeQuantum = "MDH" TimeQuantumYearMonthDayHour TimeQuantum = "YMDH" )
TimeQuantum constants
type URI ¶
type URI struct {
// contains filtered or unexported fields
}
URI represents a Pilosa URI. A Pilosa URI consists of three parts: 1) Scheme: Protocol of the URI. Default: http. 2) Host: Hostname or IP URI. Default: localhost. 3) Port: Port of the URI. Default: 10101.
All parts of the URI are optional. The following are equivalent:
http://localhost:10101 http://localhost http://:10101 localhost:10101 localhost :10101
func NewURIFromAddress ¶
NewURIFromAddress parses the passed address and returns a URI.
func NewURIFromHostPort ¶
NewURIFromHostPort returns a URI with specified host and port.