cube

package module
v0.0.0-...-f57c993 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

README

cubejs-go

Go Reference Test

Table of Contents

Introduction

Cube is an open-source analytics platform for data engineers and application developers to make data accessible and consistent across every application. The project includes a full-featured JS client, along with a web-based playground environment. The purpose of this client implementation in Golang is to provide an easy way to integrate from Go applications. At Ternary, we dogfood this client to power our users' cost-saving recommendations, anomaly detection, and billing insights.

Support

We've intended to build the subset of functionality that we need at Ternary into the Cube client presented. We recognize that not all of the functionality available to the Javascript client has been ported, but we plan to expand feature support as find it necessary. Contributions are always welcome; see Contributing.

Documentation

Overview

Package cube implements a simple client for Cube.

Index

Constants

View Source
const (
	Order_Asc  Order = "asc"
	Order_Desc Order = "desc"

	// Boolean logical operators currently unsupported: https://cube.dev/docs/query-format#filters-operators
	Operator_Equals               Operator = "equals"
	Operator_NotEquals            Operator = "notEquals"
	Operator_Contains             Operator = "contains"
	Operator_NotContains          Operator = "notContains"
	Operator_GreaterThan          Operator = "gt"
	Operator_GreaterThanOrEqualTo Operator = "gte"
	Operator_LessThan             Operator = "lt"
	Operator_LessThanOrEqualTo    Operator = "lte"
	Operator_Set                  Operator = "set"
	Operator_NotSet               Operator = "notSet"
	Operator_InDateRange          Operator = "inDateRange"
	Operator_NotInDateRange       Operator = "notInDateRange"
	Operator_BeforeDate           Operator = "beforeDate"
	Operator_AfterDate            Operator = "afterDate"

	Granularity_Second  Granularity = "second"
	Granularity_Minute  Granularity = "minute"
	Granularity_Hour    Granularity = "hour"
	Granularity_Day     Granularity = "day"
	Granularity_Week    Granularity = "week"
	Granularity_Month   Granularity = "month"
	Granularity_Quarter Granularity = "quarter"
	Granularity_Year    Granularity = "year"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AccessTokenGenerator

type AccessTokenGenerator interface {
	Get(ctx context.Context) (string, error)
}

AccessTokenGenerator defines the interface for specifying access tokens which should be included in authenticated requests to the Cube server.

type AccessTokenGeneratorFunc

type AccessTokenGeneratorFunc func(ctx context.Context) (string, error)

AccessTokenGeneratorFunc defines a simple concrete type which can satisfy the AccessTokenGenerator interface. This type is only one of many options, and users may define their own implementations of the interface.

func (AccessTokenGeneratorFunc) Get

Get generates an AccessToken or a non-nil error if it cannot.

type Client

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

Client is a client for interacting with Cube. Clients can be reused instead of created as needed. The methods of Client are safe for concurrent use by multiple goroutines.

func NewClient

func NewClient(cubeURL url.URL, tokenGenerator AccessTokenGenerator) *Client

NewClient creates a new Cube client. The optional tokenGenerator can be used to include an API token with the Cube requests.

func (*Client) Load

func (c *Client) Load(ctx context.Context, query Query, results interface{}) (ResponseMetadata, error)

Load fetches JSON-encoded data from the Cube API and stores the result in the value pointed to by `results`. If `results` is nil or not a pointer, Load returns an error. Load uses the decodings that json.Unmarshal uses, allocating maps, slices, and pointers as necessary.

type DateRange

type DateRange struct {
	RelativeRange *string
	AbsoluteRange []string
}

DateRange represents the (string|[]string) date range type in the Cube query format. https://cube.dev/docs/query-format https://cube.dev/docs/@cubejs-client-core#date-range

This is a union type and only one field should be set.

func RelativeDateRange

func RelativeDateRange(dateRange string) DateRange

RelativeDateRange returns a DateRange with the RelativeRange field set to the input string Example arguments: "last 7 days", "this month", "1 hour ago"

func (DateRange) MarshalJSON

func (d DateRange) MarshalJSON() ([]byte, error)

MarshalJSON marshals the input DateRange object; only one of the fields (i.e. RelativeRange, AbsoluteRange) will be marshalled as a top-level JSON value, depending on which is set.

type Filter

type Filter struct {
	Member   string   `json:"member"`
	Operator Operator `json:"operator"`
	Values   []string `json:"values"`
}

https://cube.dev/docs/@cubejs-client-core#order

type OrderTuple

type OrderTuple struct {
	Key   string
	Order Order
}

func (OrderTuple) MarshalJSON

func (t OrderTuple) MarshalJSON() ([]byte, error)

func (*OrderTuple) UnmarshalJSON

func (t *OrderTuple) UnmarshalJSON(byts []byte) error

type Query

type Query struct {
	Measures       []string        `json:"measures,omitempty"`
	TimeDimensions []TimeDimension `json:"timeDimensions,omitempty"`
	Order          []OrderTuple    `json:"order,omitempty"`
	Limit          int             `json:"limit,omitempty"`
	Filters        []Filter        `json:"filters,omitempty"`
	Dimensions     []string        `json:"dimensions,omitempty"`
	Ungrouped      bool            `json:"ungrouped"`
}

Query represents a query that can be issued to a Cube server via the client.

type ResponseMetadata

type ResponseMetadata struct {
	Query      interface{} `json:"query"`
	Annotation interface{} `json:"annotation"`
}

ResponseMetadata returns metadata that appears in the response from the Cube API that is not the requested data.

type TimeDimension

type TimeDimension struct {
	Dimension   string      `json:"dimension"`
	DateRange   DateRange   `json:"dateRange"`
	Granularity Granularity `json:"granularity,omitempty"`
}

https://cube.dev/docs/query-format#time-dimensions-format

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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