cantabular

package
v2.104.0 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2022 License: MIT Imports: 22 Imported by: 27

Documentation

Index

Constants

View Source
const (
	Service       = "cantabular"
	ServiceAPIExt = "cantabularAPIExt"
)

Cantabular service names

View Source
const QueryAreasByArea = `` /* 392-byte string literal not displayed */

QueryDimensionsByName is the graphQL query to obtain dimensions by name (subset of variables, without categories)

View Source
const QueryDimensionOptions = `` /* 258-byte string literal not displayed */

QueryDimensionOptions is the graphQL query to obtain static dataset dimension options (variables with categories)

View Source
const QueryDimensions = `` /* 286-byte string literal not displayed */

QueryDimensions is the graphQL query to obtain dimensions (variables without categories)

View Source
const QueryDimensionsByName = `` /* 329-byte string literal not displayed */

QueryDimensionsByName is the graphQL query to obtain dimensions by name (subset of variables, without categories)

View Source
const QueryDimensionsSearch = `` /* 303-byte string literal not displayed */
View Source
const QueryGeographyDimensions = `` /* 331-byte string literal not displayed */

QueryGeographyDimensions is the graphQL query to obtain geography dimensions (subset of variables, without categories)

View Source
const QueryStaticDataset = `` /* 268-byte string literal not displayed */

QueryStaticDataset is the graphQL query to obtain static dataset counts (variables with categories and counts)

Variables

This section is empty.

Functions

func GraphQLJSONToCSV added in v2.4.0

func GraphQLJSONToCSV(ctx context.Context, r io.Reader, w io.Writer) (int32, error)

GraphQLJSONToCSV converts a JSON response in r to CSV on w, returning the row count if an error happens, the process is aborted and the error is returned.

Types

type Category

type Category struct {
	Code  string `json:"code"`
	Label string `json:"label"`
}

Category represents the 'category' field from the GraphQL query dataset response

type Client

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

Client is the client for interacting with the Cantabular API

func NewClient

func NewClient(cfg Config, ua httpClient, g GraphQLClient) *Client

NewClient returns a new Client

func (*Client) Checker

func (c *Client) Checker(ctx context.Context, state *healthcheck.CheckState) error

Checker contacts the /v9/datasets endpoint and updates the healthcheck state accordingly.

func (*Client) CheckerAPIExt added in v2.4.0

func (c *Client) CheckerAPIExt(ctx context.Context, state *healthcheck.CheckState) error

CheckerAPIExt contacts the /graphql endpoint with an empty query and updates the healthcheck state accordingly.

func (*Client) GetAreas added in v2.96.11

func (c *Client) GetAreas(ctx context.Context, req QueryData) (*GetAreasResponse, error)

func (*Client) GetCodebook

func (c *Client) GetCodebook(ctx context.Context, req GetCodebookRequest) (*GetCodebookResponse, error)

GetCodebook gets a Codebook from cantabular.

func (*Client) GetDimensionOptions added in v2.7.1

GetDimensionOptions performs a graphQL query to obtain the requested dimension options. It returns a Table with a list of Cantabular dimensions, where 'Variable' is the dimension and 'Categories' are the options The whole response is loaded to memory.

func (*Client) GetDimensions added in v2.7.1

func (c *Client) GetDimensions(ctx context.Context, dataset string) (*GetDimensionsResponse, error)

GetDimensions performs a graphQL query to obtain all the dimensions for the provided cantabular dataset. The whole response is loaded to memory.

func (*Client) GetDimensionsByName added in v2.7.1

func (c *Client) GetDimensionsByName(ctx context.Context, req GetDimensionsByNameRequest) (*GetDimensionsResponse, error)

GetDimensionsByName performs a graphQL query to obtain only the dimensions that match the provided dimension names for the provided cantabular dataset. The whole response is loaded to memory.

func (*Client) GetGeographyDimensions added in v2.8.1

func (c *Client) GetGeographyDimensions(ctx context.Context, dataset string) (*GetGeographyDimensionsResponse, error)

GetGeographyDimensions performs a graphQL query to obtain the geography dimensions for the provided cantabular dataset. The whole response is loaded to memory.

func (*Client) ListDatasets added in v2.9.0

func (c *Client) ListDatasets(ctx context.Context) ([]string, error)

func (*Client) ParseTable added in v2.1.13

func (c *Client) ParseTable(table Table) (*bufio.Reader, error)

ParseTable takes a table from a GraphQL response and parses it into a header and rows of counts (observations) ready to be read line-by-line.

func (*Client) SearchDimensions added in v2.9.3

func (c *Client) SearchDimensions(ctx context.Context, req SearchDimensionsRequest) (*GetDimensionsResponse, error)

SearchDimensionsRequest performs a graphQL query to obtain the dimensions that match the provided text in the provided cantabular dataset. The whole response is loaded to memory.

func (*Client) StaticDatasetQuery

func (c *Client) StaticDatasetQuery(ctx context.Context, req StaticDatasetQueryRequest) (*StaticDatasetQuery, error)

StaticDatasetQuery performs a query for a static dataset against the Cantabular Extended API using the /graphql endpoint and returns a StaticDatasetQuery, loading the whole response to memory. Use this method only if large query responses are NOT expected

func (*Client) StaticDatasetQueryStreamCSV added in v2.4.0

func (c *Client) StaticDatasetQueryStreamCSV(ctx context.Context, req StaticDatasetQueryRequest, consume Consumer) (int32, error)

StaticDatasetQueryStreamCSV performs a StaticDatasetQuery call and then starts 2 go-routines to transform the response body into a CSV stream and consume the transformed output with the provided Consumer concurrently. The number of CSV rows, including the header, is returned along with any error during the process. Use this method if large query responses are expected.

func (*Client) StatusCode added in v2.9.5

func (c *Client) StatusCode(err error) int

StatusCode provides a callback function whereby users can check a returned error for an embedded HTTP status code

type Codebook

type Codebook []Variable

Codebook represents a 'codebook' object returned from Cantabular Server

type Config

type Config struct {
	Host           string
	ExtApiHost     string
	GraphQLTimeout time.Duration
}

Config holds the config used to initialise the Cantabular Client

type Consumer added in v2.4.0

type Consumer = stream.Consumer

Consumer is a stream func to read from a reader

type Dataset

type Dataset struct {
	Name             string    `json:"name"`
	Digest           string    `json:"digest"`
	Description      string    `json:"description"`
	Size             int       `json:"size"`
	RulebaseVariable string    `json:"ruleBaseVariable"`
	DateTime         time.Time `json:"datetime"`
}

Dataset represents a 'dataset' object returned from Cantabular Server

type Dimension

type Dimension struct {
	Count      int          `json:"count"`
	Categories []Category   `json:"categories"`
	Variable   VariableBase `json:"variable"`
}

Dimension represents the 'dimension' field from a GraphQL query dataset response

type Dimensions added in v2.4.0

type Dimensions []Dimension

Dimensions describes the structure of a table

func (Dimensions) NewIterator added in v2.4.0

func (dims Dimensions) NewIterator(ctx context.Context) *Iterator

NewIterator creates an iterator over a table on these Dimensions

type DimensionsTable added in v2.7.1

type DimensionsTable struct {
	Dimensions []Dimension `json:"dimensions"`
	Error      string      `json:"error,omitempty" `
}

DimensionsTable represents the 'table' field from the GraphQL dataset response, which contains only dimensions and error fields

type ErrorResponse

type ErrorResponse struct {
	Message string `json:"message"`
}

ErrorResponse models the error response from cantabular

type Filter added in v2.9.6

type Filter struct {
	Codes    []string `json:"codes"`
	Variable string   `json:"variable"`
}

Filter holds the fields for the Cantabular GraphQL 'Filter' object used for specifying categories returned in tables

type GetAreasRequest added in v2.96.11

type GetAreasRequest struct {
	Dataset  string `schema:"dataset" validate:"required"`
	AreaType string `schema:"area-type"`
}

type GetAreasResponse added in v2.96.11

type GetAreasResponse struct {
	Dataset gql.DatasetRuleBase `json:"dataset"`
}

GetAreasResponse holds the response body for POST [cantabular-ext]/graphql with a query to obtain static dataset variables and categories, without values.

type GetCodebookRequest

type GetCodebookRequest struct {
	DatasetName string
	Variables   []string
	Categories  bool
}

GetCodebookRequest holds the query parameters for GET [cantabular-srv]/codebook/{dataset}?cats=xxx&v=xxx

type GetCodebookResponse

type GetCodebookResponse struct {
	Codebook Codebook `json:"codebook"`
	Dataset  Dataset  `json:"dataset"`
}

GetCodebookResponse holds the response body for GET [cantabular-srv]/codebook/{dataset}?cats=xxx&v=xxx

type GetDimensionOptionsRequest added in v2.8.1

type GetDimensionOptionsRequest struct {
	Dataset        string
	DimensionNames []string
	Filters        []Filter
}

GetDimensionOptionsRequest holds the request variables required from the caller for making a request to obtain dimension options (categories) for the provided cantabular Dataset and dimension names (Cantabular variables)

POST [cantabular-ext]/graphql with the encoded query

type GetDimensionOptionsResponse added in v2.7.1

type GetDimensionOptionsResponse struct {
	Dataset StaticDatasetDimensionOptions `json:"dataset"`
}

GetDimensionOptionsResponse holds the response body for POST [cantabular-ext]/graphql with a query to obtain static dataset variables and categories, without values.

type GetDimensionsByNameRequest added in v2.8.1

type GetDimensionsByNameRequest struct {
	Dataset        string
	DimensionNames []string
}

GetDimensionsByNameRequest holds the request variables required from the caller for making a request to obtain dimensions (Cantabular variables) by name POST [cantabular-ext]/graphql

type GetDimensionsResponse added in v2.7.1

type GetDimensionsResponse struct {
	Dataset gql.DatasetVariables `json:"dataset"`
}

GetDimensionsResponse holds the response body for POST [cantabular-ext]/graphql with a query to obtain variables

type GetGeographyDimensionsResponse added in v2.8.1

type GetGeographyDimensionsResponse struct {
	Dataset gql.DatasetRuleBase `json:"dataset"`
}

GetGeographyDimensionsResponse holds the response body for POST [cantabular-ext]/graphql with a query to obtain geography variables

type GraphQLClient

type GraphQLClient interface {
	Query(ctx context.Context, query interface{}, vars map[string]interface{}) error
}

GraphQLClient is the Client used by the GraphQL package to make queries

type Iterator added in v2.4.0

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

Iterator facilitates reading the coordinates of each cell in row-major order

func (*Iterator) CategoryAtColumn added in v2.4.0

func (it *Iterator) CategoryAtColumn(i int) (Category, error)

CategoryAtColumn returns the i-th coordinate of the current cell

func (*Iterator) End added in v2.4.0

func (it *Iterator) End() bool

End returns true if there are no more cells in the table

func (*Iterator) Next added in v2.4.0

func (it *Iterator) Next() error

Next advances to the next table cell. It should not be called if End() would return true. If the Iterator contet is done, an error will be returned.

type ListDatasetsItem added in v2.9.0

type ListDatasetsItem struct {
	Name graphql.String
}

type ListDatasetsQuery added in v2.9.0

type ListDatasetsQuery struct {
	Datasets []ListDatasetsItem
}

type MapFrom

type MapFrom struct {
	SourceNames []string `json:"sourceNames,omitempty"`
	Code        []string `json:"codes,omitempty"`
}

MapFrom represents the 'mapFrom' object from variable when category information is included

type QueryData added in v2.8.1

type QueryData struct {
	Dataset   string
	Text      string
	Variables []string
	Filters   []Filter
}

QueryData holds all the possible required variables to encode any of the graphql queries defined in this file.

func (*QueryData) Encode added in v2.8.1

func (data *QueryData) Encode(query string) (bytes.Buffer, error)

Encode the provided graphQL query with the data in QueryData returns a byte buffer with the encoded query, along with any encoding error that might happen

type SearchDimensionsRequest added in v2.9.3

type SearchDimensionsRequest struct {
	Dataset string
	Text    string
}

SearchDimensionsRequest holds the request variables required from the caller for making a request to search dimensions (Cantabular variables) by text POST [cantabular-ext]/graphql

type StaticDataset

type StaticDataset struct {
	Table Table `json:"table" graphql:"table(variables: $variables)"`
}

StaticDataset represents the 'dataset' field from a GraphQL static dataset query response

type StaticDatasetDimensionOptions added in v2.7.1

type StaticDatasetDimensionOptions struct {
	Table DimensionsTable `json:"table"`
}

StaticDatasetDimensionOptions represents the 'dataset' field from a GraphQL static dataset query response, containing a DimensionsTable, without values

type StaticDatasetQuery

type StaticDatasetQuery struct {
	Dataset StaticDataset `json:"dataset" graphql:"dataset(name: $name)"`
}

StaticDatasetQuery holds the query for a static dataset landing page from POST [cantabular-ext]/graphql. It is used both as the internal query request to GraphQL as well as the response to the caller, as GraphQL query responses are essentially unmarshalled into the requests.

type StaticDatasetQueryRequest

type StaticDatasetQueryRequest struct {
	Dataset   string   `json:"dataset"`
	Variables []string `json:"variables"`
}

StaticDatasetQueryRequest holds the request variables required from the caller for making a request for a static dataset landing page from POST [cantabular-ext]/graphql

type Table

type Table struct {
	Dimensions []Dimension `json:"dimensions"`
	Values     []int       `json:"values"`
	Error      string      `json:"error,omitempty" `
}

Table represents the 'table' field from the GraphQL dataset query response

type Variable

type Variable struct {
	VariableBase
	Len     int       `json:"len"`
	Codes   []string  `json:"codes,omitempty"`
	Labels  []string  `json:"labels,omitempty"`
	MapFrom []MapFrom `json:"mapFrom,omitempty"`
}

Variable represents a 'variable' object returned from Cantabular

type VariableBase

type VariableBase struct {
	Name  string `json:"name"`
	Label string `json:"label"`
}

VariableBase represents the minimum amount of fields returned by Cantabular for a 'variable' object. Is kept separate from the full Variable struct because GraphQL/Cantabular has difficulty unmarshaling into a struct with unexpected objects (in this case MapFrom), even if they're set to not be included

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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