Help us shape the future of Go! Take the 2026 Go Developer Survey

pilosa

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2017 License: BSD-3-Clause Imports: 14 Imported by: 0

README

Go Client for Pilosa

GoDoc

Go client for Pilosa high performance distributed bitmap index.

Change Log

  • v0.4.0 (2017-06-09):

    • Supports Pilosa Server v0.4.0.
    • Updated the accepted values for index, frame names and labels to match with the Pilosa server.
    • Union query now accepts zero or more variadic arguments. Intersect and Difference queries now accept one or more variadic arguments.
    • Added inverse TopN and inverse Range calls.
    • Inverse enabled status of frames is not checked on the client side.
  • v0.3.1 (2017-05-01):

    • Initial version
    • Supports Pilosa Server v0.3.1

Requirements

  • Go 1.7 and higher

Install

Download the library in your GOPATH using:

go get github.com/pilosa/go-pilosa

After that, you can import that in your code using:

import pilosa "pilosa/go-pilosa"

Usage

Quick overview

Assuming Pilosa server is running at localhost:10101 (the default):

var err error

// Create the default client
client := pilosa.DefaultClient()

// Create an Index object
myindex, err := pilosa.NewIndex("myindex", nil)

// Make sure the index exists on the server
err = client.EnsureIndex(myindex)

// Create a Frame object
myframe, err := myindex.Frame("myframe", nil)

// Make sure the frame exists on the server
err = client.EnsureFrame(myframe)

// Send a SetBit query. PilosaException is thrown if execution of the query fails.
err = client.Query(myframe.SetBit(5, 42), nil)

// Send a Bitmap query. PilosaException is thrown if execution of the query fails.
response, err = client.Query(myframe.Bitmap(5), nil)

// Get the result
result := response.Result()
// Act on the result
if result != nil {
    bits := result.Bitmap.Bits
    fmt.Println("Got bits: %v", bits)
}

// You can batch queries to improve throughput
response, err = client.Query(
    myindex.BatchQuery(
        myframe.Bitmap(5),
        myframe.Bitmap(10),
    ), nil
)

for _, result := range reponse.Results() {
    // Act on the result
}

Data Model and Queries
Indexes and Frames

Index and frames are the main data models of Pilosa. You can check the Pilosa documentation for more detail about the data model.

NewIndex function is used to create an index object. Note that this does not create an index on the server; the index object simply defines the schema.

repository, err := NewIndex("repository", nil)

Indexes support changing the column label and time quantum. In order to apply these custom options, pass an IndexOptions struct as the second argument to NewIndex:

options := &pilosa.IndexOptions{
    ColumnLabel: "repo_id",
    TimeQuantum: TimeQuantumYearMonth,
}

repository, err := pilosa.NewIndex("repository", options);

Frames are created with a call to Frame function of an index:

stargazer, err := repository.Frame("stargazer", nil)

Similar to index objects, you can pass custom options to frames:

stargazerOptions, err := &pilosa.FrameOptions{
    RowLabel: "stargazer_id",
    TimeQuantum: TimeQuantumYearMonthDay,
}

stargazer, err := repository.Frame("stargazer", stargazerOptions);
Queries

Once you have indexes and frame structs created, you can create queries for them. Some of the queries work on the columns; corresponding methods are attached to the index. Other queries work on rows with related methods attached to frames.

For instance, Bitmap queries work on rows; use a frame object to create those queries:

bitmapQuery := stargazer.Bitmap(1, 100)  // corresponds to PQL: Bitmap(frame='stargazer', stargazer_id=1)

Union queries work on columns; use the index object to create them:

query := repository.Union(bitmapQuery1, bitmapQuery2)

In order to increase througput, you may want to batch queries sent to the Pilosa server. The index.BatchQuery function is used for that purpose:

query := repository.BatchQuery(
    stargazer.Bitmap(1, 100),
    repository.Union(stargazer.Bitmap(100, 200), stargazer.Bitmap(5, 100))
)

The recommended way of creating query structs is, using dedicated methods attached to index and frame objects. But sometimes it would be desirable to send raw queries to Pilosa. You can use index.RawQuery method for that. Note that query string is not validated before sending to the server:

query := repository.RawQuery("Bitmap(frame='stargazer', stargazer_id=5)")

Please check Pilosa documentation for PQL details. Here is a list of methods corresponding to PQL calls:

Index:

  • Union(bitmaps *PQLBitmapQuery...) *PQLBitmapQuery
  • Intersect(bitmaps *PQLBitmapQuery...) *PQLBitmapQuery
  • Difference(bitmaps *PQLBitmapQuery...) *PQLBitmapQuery
  • Count(bitmap *PQLBitmapQuery) *PQLBaseQuery
  • SetColumnAttrs(columnID uint64, attrs map[string]interface{}) *PQLBaseQuery

Frame:

  • Bitmap(rowID uint64) *PQLBitmapQuery
  • InverseBitmap(columnID uint64) *PQLBitmapQuery
  • SetBit(rowID uint64, columnID uint64) *PQLBaseQuery
  • SetBitTimestamp(rowID uint64, columnID uint64, timestamp time.Time) *PQLBaseQuery
  • ClearBit(rowID uint64, columnID uint64) *PQLBaseQuery
  • TopN(n uint64) *PQLBitmapQuery
  • BitmapTopN(n uint64, bitmap *PQLBitmapQuery) *PQLBitmapQuery
  • FilterFieldTopN(n uint64, bitmap *PQLBitmapQuery, field string, values ...interface{}) *PQLBitmapQuery
  • InverseTopN(n uint64) *PQLBitmapQuery
  • InverseBitmapTopN(n uint64, bitmap *PQLBitmapQuery) *PQLBitmapQuery
  • InverseFilterFieldTopN(n uint64, bitmap *PQLBitmapQuery, field string, values ...interface{}) *PQLBitmapQuery
  • Range(rowID uint64, start time.Time, end time.Time) *PQLBitmapQuery
  • InverseRange(columnID uint64, start time.Time, end time.Time) *PQLBitmapQuery
  • SetBitmapAttrs(rowID uint64, attrs map[string]interface{}) *PQLBaseQuery
Pilosa URI

A Pilosa URI has the ${SCHEME}://${HOST}:${PORT} format:

  • Scheme: Protocol of the URI. Default: http.
  • Host: Hostname or ipv4/ipv6 IP address. Default: localhost.
  • Port: Port number. Default: 10101.

All parts of the URI are optional, but at least one of them must be specified. The following are equivalent:

  • http://localhost:10101
  • http://localhost
  • http://:10101
  • localhost:10101
  • localhost
  • :10101

A Pilosa URI is represented by the pilosa.URI struct. Below are a few ways to create URI objects:

// create the default URI: http://localhost:10101
uri1 := pilosa.DefaultURI()

// create a URI from string address
uri2, err := pilosa.NewURIFromAddress("index1.pilosa.com:20202");

// create a URI with the given host and port
uri3, err := pilosa.NewURIFromHostPort("index1.pilosa.com", 20202);
Pilosa Client

In order to interact with a Pilosa server, an instance of pilosa.Client should be created. The client is thread-safe and uses a pool of connections to the server, so we recommend creating a single instance of the client and sharing it when necessary.

If the Pilosa server is running at the default address (http://localhost:10101) you can create the client with default options using:

client := pilosa.DefaultClient()

To use a custom server address, use the NewClientWithURI function:

uri, err := pilosa.NewURIFromAddress("http://index1.pilosa.com:15000")
if err != nil {
    // Act on the error
}
client := pilosa.NewClientWithURI(uri)

If you are running a cluster of Pilosa servers, you can create a Cluster struct that keeps addresses of those servers:

uri1, err := pilosa.NewURIFromAddress(":10101")
uri2, err := pilosa.NewURIFromAddress(":10110")
uri3, err := pilosa.NewURIFromAddress(":10111")
cluster := pilosa.NewClusterWithHost(uri1, uri2, uri3)

// Create a client with the cluster
client := pilosa.NewClientWithCluster(cluster, nil)

It is possible to customize the behaviour of the underlying HTTP client by passing a ClientOptions struct to the NewClientWithCluster function:

options = &pilosa.ClientOptions{
    ConnectTimeout: 1000,  // if can't connect in  a second, close the connection
    setSocketTimeout: 10000,  // if no response received in 10 seconds, close the connection
    PoolSizePerRoute: 3,  // number of connections in the pool per host
    TotalPoolSize: 10,  // number of total connections in the pool  
}

client := pilosa.NewClientWithCluster(cluster, options)

Once you create a client, you can create indexes, frames and then start sending queries.

Here is how you would create a index and frame:

// materialize repository index instance initialized before
err := client.CreateIndex(repository)

// materialize stargazer frame instance initialized before
err :=client.CreateFrame(stargazer)

If the index or frame exists on the server, non-nil errors will be returned. You can use EnsureIndex and EnsureFrame functions to ignore existing indexes and frames.

You can send queries to a Pilosa server using the Query function of the Client struct:

response, err := client.Query(frame.Bitmap(5), nil);

The second argument of Query function is of type QueryOptions:

options = &pilosa.QueryOptions{
    Columns: true,  // return column data in the response
}

response := client.Query(frame.Bitmap(5), options)
Server Response

When a query is sent to a Pilosa server, the server either fulfills the query or sends an error message. In the case of an error, a pilosa.Error struct is returned, otherwise a QueryResponse struct is returned.

A QueryResponse struct may contain zero or more results of QueryResult type. You can access all results using the Results function of QueryResponse (which returns a list of QueryResult objects), or you can use the Result method (which returns either the first result or nil if there are no results):

response, err := client.Query(frame.Bitmap(5). nil)
if err != nil {
    // Act on the error
}

// check that there's a result and act on it
result := response.Result()
if result != nil {
    // Act on the result
}

// iterate over all results
for result := range response.Results() {
    // Act on the result
}

Similarly, a QueryResponse struct may include a number of columns (column objects) if Columns query option was set to true:

var column *pilosa.ColumnItem

// check that there's a column and act on it
column = response.Column()
if (column != null) {
    // Act on the column
}

// iterate over all columns
for column = range response.Columns() {
    // Act on the column
}

QueryResult objects contain:

  • Bitmap field to retrieve a bitmap result,
  • CountItems fied to retrieve column count per row ID entries returned from TopN queries,
  • Count field to retrieve the number of rows per the given row ID returned from Count queries.
bitmap := response.Bitmap
bits := bitmap.Bits
attributes := bitmap.Attributes

countItems := response.CountItems

count := response.Count

Contribution

Please check our Contributor's Guidelines.

  1. Sign the Developer Agreement so we can include your contibution in our codebase.
  2. Fork this repo and add it as upstream: git remote add upstream git@github.com:pilosa/go-pilosa.git.
  3. Make sure all tests pass (use make test-all) and be sure that the tests cover all statements in your code (we aim for 100% test coverage).
  4. Commit your code to a feature branch and send a pull request to the master branch of our repo.

The sections below assume your platform has make. Otherwise you can view the corresponding steps of the Makefile.

Running tests

You can run unit tests with:

make test

And both unit and integration tests with:

make test-all

Check the test coverage:

make cover
Generating protobuf classes

Protobuf classes are already checked in to source control, so this step is only needed when the upstream public.proto changes.

Before running the following step, make sure you have the Protobuf compiler and Go protobuf support is installed:

make generate

License

Copyright 2017 Pilosa Corp.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.

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

Constants

This section is empty.

Variables

View Source
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

func ValidFrameName(name string) bool

ValidFrameName returns true if the given frame name is valid, otherwise false.

func ValidIndexName

func ValidIndexName(name string) bool

ValidIndexName returns true if the given index name is valid, otherwise false.

func ValidLabel

func ValidLabel(label string) bool

ValidLabel returns true if the given label is valid, otherwise false.

Types

type BitmapResult

type BitmapResult struct {
	Attributes map[string]interface{}
	Bits       []uint64
}

BitmapResult represents a result from Bitmap, Union, Intersect, Difference and Range PQL calls.

type CacheType

type CacheType string
const (
	CacheTypeDefault CacheType = ""
	CacheTypeLRU     CacheType = "lru"
	CacheTypeRanked  CacheType = "ranked"
)

CacheType constants

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

func NewClientWithURI(uri *URI) *Client

NewClientWithURI creates a client with the given server address.

func (*Client) CreateFrame

func (c *Client) CreateFrame(frame *Frame) error

CreateFrame creates a frame on the server using the given Frame struct.

func (*Client) CreateIndex

func (c *Client) CreateIndex(index *Index) error

CreateIndex creates an index on the server using the given Index struct.

func (*Client) DeleteFrame

func (c *Client) DeleteFrame(frame *Frame) error

DeleteFrame deletes a frame on the server.

func (*Client) DeleteIndex

func (c *Client) DeleteIndex(index *Index) error

DeleteIndex deletes an index on the server.

func (*Client) EnsureFrame

func (c *Client) EnsureFrame(frame *Frame) error

EnsureFrame creates a frame on the server if it doesn't exists.

func (*Client) EnsureIndex

func (c *Client) EnsureIndex(index *Index) error

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.

func (*Client) Schema

func (c *Client) Schema() (*Schema, error)

Schema returns the indexes and frames on the server.

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 DefaultCluster

func DefaultCluster() *Cluster

DefaultCluster returns the default Cluster.

func NewClusterWithHost

func NewClusterWithHost(hosts ...*URI) *Cluster

NewClusterWithHost returns a cluster with the given URIs.

func (*Cluster) AddHost

func (c *Cluster) AddHost(address *URI)

AddHost adds a host to the cluster.

func (*Cluster) Host

func (c *Cluster) Host() *URI

Host returns the next host in the cluster.

func (*Cluster) Hosts

func (c *Cluster) Hosts() []URI

Hosts returns all hosts in the cluster.

func (*Cluster) RemoveHost

func (c *Cluster) RemoveHost(address *URI)

RemoveHost removes the host with the given URI from the cluster.

type ColumnItem

type ColumnItem struct {
	ID         uint64
	Attributes map[string]interface{}
}

ColumnItem represents data about a column. Column data is only returned if QueryOptions.Columns was set to true.

type CountResultItem

type CountResultItem struct {
	ID    uint64
	Count uint64
}

CountResultItem represents a result from TopN call.

type Error

type Error struct {
	Message string
}

Error contains a Pilosa specific error.

func NewError

func NewError(message string) *Error

NewError creates a Pilosa error.

func (Error) Error

func (e Error) Error() string

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) InverseBitmapTopN added in v0.4.0

func (f *Frame) InverseBitmapTopN(n uint64, bitmap *PQLBitmapQuery) *PQLBitmapQuery

InverseBitmapTopN creates a TopN query with the given item count and bitmap. This variant supports customizing the bitmap query and sets inverse=true.

func (*Frame) InverseFilterFieldTopN added in v0.4.0

func (f *Frame) InverseFilterFieldTopN(n uint64, bitmap *PQLBitmapQuery, field string, values ...interface{}) *PQLBitmapQuery

InverseFilterFieldTopN 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. This variant sets inverse=true.

func (*Frame) InverseRange added in v0.4.0

func (f *Frame) InverseRange(columnID uint64, start time.Time, end time.Time) *PQLBitmapQuery

InverseRange 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) InverseTopN added in v0.4.0

func (f *Frame) InverseTopN(n uint64) *PQLBitmapQuery

InverseTopN 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. This variant sets inverse=true

func (*Frame) Range

func (f *Frame) Range(rowID uint64, start time.Time, end time.Time) *PQLBitmapQuery

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

func (f *Frame) SetBitTimestamp(rowID uint64, columnID uint64, timestamp time.Time) *PQLBaseQuery

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(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(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) Name

func (d *Index) Name() string

Name returns the name of this index.

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(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 IndexInfo

type IndexInfo struct {
	Name   string       `json:"name"`
	Frames []*FrameInfo `json:"frames"`
}

IndexInfo represents schema information for an index

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 PQLQuery

type PQLQuery interface {
	Index() *Index

	Error() error
	// contains filtered or unexported methods
}

PQLQuery is an interface for PQL queries.

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 DefaultURI

func DefaultURI() *URI

DefaultURI creates and returns the default URI.

func NewURIFromAddress

func NewURIFromAddress(address string) (*URI, error)

NewURIFromAddress parses the passed address and returns a URI.

func NewURIFromHostPort

func NewURIFromHostPort(host string, port uint16) (*URI, error)

NewURIFromHostPort returns a URI with specified host and port.

func (URI) Equals

func (u URI) Equals(other *URI) bool

Equals returns true if the checked URI is equivalent to this URI.

func (*URI) Host

func (u *URI) Host() string

Host returns the host of this URI.

func (*URI) Normalize

func (u *URI) Normalize() string

Normalize returns the address in a form usable by a HTTP client.

func (*URI) Port

func (u *URI) Port() uint16

Port returns the port of this URI.

func (*URI) Scheme

func (u *URI) Scheme() string

Scheme returns the scheme of this URI.

Directories

Path Synopsis
Package internal is a generated protocol buffer package.
Package internal is a generated protocol buffer package.

Jump to

Keyboard shortcuts

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