Documentation
¶
Overview ¶
Treasure Data API client. The following API functions are covered at the moment.
Account API:
ShowAccount AccountCoreUtilization
Status API:
ServerStatus
Database/Table API:
ListDatabases DeleteDatabase CreateDatabase ListTables CreateTable DeleteTable SwapTable UpdateSchema UpdateExpire Tail
Job/Query API:
ListJobs ShowJob KillJob SubmitQuery SubmitExportJob SubmitPartialDeleteJob JobStatus JobResult ListResults CreateResult DeleteResult
Import API:
Import
Index ¶
- Constants
- Variables
- type APIError
- type AddAPIKeyResult
- type AuthenticateResult
- type Blob
- type BufferingBlob
- type BulkImportElement
- type BulkImportResult
- type ConverterFunc
- type DeleteScheduleResult
- type EndpointRouter
- type FixedEndpointRouter
- type InMemoryBlob
- type ListAPIKeysResult
- type ListBulkImportElements
- type ListBulkImportParts
- type ListDataBasesResult
- type ListDataBasesResultElement
- type ListJobsOptions
- type ListJobsResult
- type ListJobsResultElement
- type ListJobsResultElements
- type ListResultsResult
- type ListResultsResultElement
- type ListScheduleResult
- type ListTablesResult
- type ListTablesResultElement
- type ListUsersResult
- type ListUsersResultElement
- type Optional
- type PerformBulkImportResult
- type Query
- type RunScheduleResult
- type RunScheduleResultList
- type ScheduleElement
- type ScheduleHistoryElement
- type ScheduleHistoryElementList
- type ScheduleHistoryList
- type ScheduleResult
- type ServerStatusResult
- type Settings
- type ShowAccountResult
- type ShowJobResult
- type ShowJobResultDebugElement
- type TDClient
- func (client *TDClient) AddAPIKey(email string) (*AddAPIKeyResult, error)
- func (client *TDClient) AddUser(name, org, email, password string) error
- func (client *TDClient) Authenticate(email, password string) (*AuthenticateResult, error)
- func (client *TDClient) CommitBulkImport(name string, options map[string]string) (*BulkImportResult, error)
- func (client *TDClient) CreateBulkImport(name string, db string, table string, options map[string]string) (*BulkImportResult, error)
- func (client *TDClient) CreateDatabase(db string, options map[string]string) error
- func (client *TDClient) CreateLogTable(db string, table string) error
- func (client *TDClient) CreateResult(name, url_ string) error
- func (client *TDClient) CreateSchedule(scheduleName string, options map[string]string) (*ScheduleResult, error)
- func (client *TDClient) DeleteBulkImport(name string, options map[string]string) error
- func (client *TDClient) DeleteBulkImportPart(name string, part_name string, options map[string]string) error
- func (client *TDClient) DeleteDatabase(db string) error
- func (client *TDClient) DeleteResult(name string) error
- func (client *TDClient) DeleteSchedule(scheduleName string) (*DeleteScheduleResult, error)
- func (client *TDClient) DeleteTable(db string, table string) (string, error)
- func (client *TDClient) FreezeBulkImport(name string, options map[string]string) (*BulkImportResult, error)
- func (client *TDClient) Import(db string, table string, format string, blob Blob, uniqueId string) (float64, error)
- func (client *TDClient) JobResult(jobId string, format string, reader func(io.Reader) error) error
- func (client *TDClient) JobResultEach(jobId string, reader func(interface{}) error) error
- func (client *TDClient) JobStatus(jobId string) (string, error)
- func (client *TDClient) KillJob(jobId string) error
- func (client *TDClient) ListAPIKeys(email string) (*ListAPIKeysResult, error)
- func (client *TDClient) ListBulkImportParts(name string, options map[string]string) (*ListBulkImportParts, error)
- func (client *TDClient) ListBulkImports(options map[string]string) (*ListBulkImportElements, error)
- func (client *TDClient) ListDatabases() (*ListDataBasesResult, error)
- func (client *TDClient) ListJobs() (*ListJobsResult, error)
- func (client *TDClient) ListJobsWithOptions(options *ListJobsOptions) (*ListJobsResult, error)
- func (client *TDClient) ListResults() (*ListResultsResult, error)
- func (client *TDClient) ListSchedules() (*ListScheduleResult, error)
- func (client *TDClient) ListTables(db string) (*ListTablesResult, error)
- func (client *TDClient) ListUsers() (*ListUsersResult, error)
- func (client *TDClient) PerformBulkImport(name string, options map[string]string) (*PerformBulkImportResult, error)
- func (client *TDClient) RemoveAPIKey(email, apikey string) error
- func (client *TDClient) RemoveUser(email string) error
- func (client *TDClient) RunSchedule(scheduleName string, runTime string, options map[string]string) (*RunScheduleResultList, error)
- func (client *TDClient) ScheduleHistory(scheduleName string, options map[string]string) (*ScheduleHistoryList, error)
- func (client *TDClient) ServerStatus() (*ServerStatusResult, error)
- func (client *TDClient) ShowAccount() (*ShowAccountResult, error)
- func (client *TDClient) ShowBulkImport(name string) (*BulkImportElement, error)
- func (client *TDClient) ShowDatabase(dbname string) (*ListDataBasesResultElement, error)
- func (client *TDClient) ShowJob(jobId string) (*ShowJobResult, error)
- func (client *TDClient) ShowTable(db, table string) (*ListTablesResultElement, error)
- func (client *TDClient) SubmitExportJob(db string, table string, storageType string, options map[string]string) (string, error)
- func (client *TDClient) SubmitPartialDeleteJob(db string, table string, to time.Time, from time.Time, ...) (string, error)
- func (client *TDClient) SubmitQuery(db string, q Query) (string, error)
- func (client *TDClient) SwapTable(db string, table1 string, table2 string) error
- func (client *TDClient) Tail(db string, table string, count int, to time.Time, from time.Time, ...) error
- func (client *TDClient) UnfreezeBulkImport(name string, options map[string]string) (*BulkImportResult, error)
- func (client *TDClient) UpdateExpire(db string, table string, expireDays int) error
- func (client *TDClient) UpdateSchedule(scheduleName string, options map[string]string) (*ScheduleResult, error)
- func (client *TDClient) UpdateSchema(db string, table string, schema []interface{}) error
- func (client *TDClient) UpdateTable(db string, table string, params map[string]string) error
- func (client *TDClient) UploadBulkImportPart(name string, part_name string, blob Blob) (*BulkImportResult, error)
- type TimeoutConn
- func (conn *TimeoutConn) Close() error
- func (conn *TimeoutConn) LocalAddr() net.Addr
- func (conn *TimeoutConn) Read(b []byte) (int, error)
- func (conn *TimeoutConn) RemoteAddr() net.Addr
- func (conn *TimeoutConn) SetDeadline(t time.Time) error
- func (conn *TimeoutConn) SetReadDeadline(t time.Time) error
- func (conn *TimeoutConn) SetWriteDeadline(t time.Time) error
- func (conn *TimeoutConn) Write(b []byte) (int, error)
- type V3EndpointRouter
Constants ¶
const ( GenericError = iota AuthError ForbiddenError AlreadyExistsError NotFoundError )
const ( DEFAULT_ENDPOINT = "api.treasure-data.com" DEFAULT_IMPORT_ENDPOINT = "api-import.treasure-data.com" NEW_DEFAULT_ENDPOINT = "api.treasuredata.com" NEW_DEFAULT_IMPORT_ENDPOINT = "api-import.treasuredata.com" )
const ( // Represents the date/time format for time.Time.Format(), // which is used in several API function parameters and results. TDAPIDateTime = "2006-01-02 15:04:05 MST" TDAPIDateTimeNumericZone = "2006-01-02 15:04:05 -0700" )
const (
CLIENT_VERSION = "0.3.0"
)
Variables ¶
var DefaultRouter = V3EndpointRouter{ DefaultEndpoint: NEW_DEFAULT_ENDPOINT, ImportEndpoint: NEW_DEFAULT_IMPORT_ENDPOINT, }
DefaultRouter is a V3EndpointRouter with the hard-coded endpoints.
Functions ¶
This section is empty.
Types ¶
type AddAPIKeyResult ¶
type AddAPIKeyResult struct {
APIKey string
}
AddAPIKeyResult represents the result of AddAPIKey API
type AuthenticateResult ¶
AuthenticateResult is result of authenticate API
type Blob ¶
type Blob interface {
Reader() (io.ReadCloser, error)
Size() (int64, error)
MD5Sum() ([]byte, error)
}
Blob denotes a concept, which is opaque data that can be read bytewise through an io.Reader, has a certain size and provides a calculated MD5 sum.
func NewBufferingBlob ¶
func NewBufferingBlobSize ¶
type BufferingBlob ¶
type BufferingBlob struct {
// contains filtered or unexported fields
}
BufferingBlob wraps the other blob so Reader() would return the buffered reader. This is helpful if the blob is backed by a *os.File.
func (*BufferingBlob) MD5Sum ¶
func (blob *BufferingBlob) MD5Sum() ([]byte, error)
func (*BufferingBlob) Reader ¶
func (blob *BufferingBlob) Reader() (io.ReadCloser, error)
func (*BufferingBlob) Size ¶
func (blob *BufferingBlob) Size() (int64, error)
type BulkImportElement ¶
type BulkImportResult ¶
type ConverterFunc ¶
Used in internal schema, marking the field so that it will be unmarshaled by the specified function.
func EmbeddedJSON ¶
func EmbeddedJSON(expectedTypeProto interface{}) ConverterFunc
EmbeddedJSON is a factory used internally that makes a ConverterFunc function that returns the specified type.
type DeleteScheduleResult ¶
type EndpointRouter ¶
EndpointRouter is expected to return the host name most suitable for the passed request URI
type FixedEndpointRouter ¶
type FixedEndpointRouter struct {
Endpoint string
}
A FixedEndpointRouter instance represents an EndpointRouter that always routes the request to the same endpoint.
func (*FixedEndpointRouter) Route ¶
func (r *FixedEndpointRouter) Route(_ string) string
type InMemoryBlob ¶
type InMemoryBlob []byte
InMemoryBlob is a Blob which stores the entire data as a byte array.
func (InMemoryBlob) MD5Sum ¶
func (b InMemoryBlob) MD5Sum() ([]byte, error)
func (InMemoryBlob) Reader ¶
func (b InMemoryBlob) Reader() (io.ReadCloser, error)
func (InMemoryBlob) Size ¶
func (b InMemoryBlob) Size() (int64, error)
type ListAPIKeysResult ¶
type ListAPIKeysResult struct {
APIKeys []string
}
ListAPIKeysResult represents the result of ListAPIKeys API
type ListBulkImportElements ¶
type ListBulkImportElements []BulkImportElement
type ListBulkImportParts ¶
type ListDataBasesResult ¶
type ListDataBasesResult []ListDataBasesResultElement
ListDataBasesResult is a collection of ListDataBasesResultElement
type ListDataBasesResultElement ¶
type ListDataBasesResultElement struct {
Id string
UserId int
Description string
Name string
Organization string
Count int
CreatedAt time.Time
UpdatedAt time.Time
Permission string
DeleteProtected bool
}
ListDataBasesResultElement represents an item of the result of ListDatabases API call
type ListJobsOptions ¶
type ListJobsOptions struct {
// contains filtered or unexported fields
}
func (*ListJobsOptions) WithFrom ¶
func (options *ListJobsOptions) WithFrom(from int) *ListJobsOptions
func (*ListJobsOptions) WithStatus ¶
func (options *ListJobsOptions) WithStatus(status string) *ListJobsOptions
func (*ListJobsOptions) WithTo ¶
func (options *ListJobsOptions) WithTo(to int) *ListJobsOptions
type ListJobsResult ¶
type ListJobsResult struct {
ListJobsResultElements ListJobsResultElements
Count int
From int
To int
}
type ListJobsResultElement ¶
type ListJobsResultElements ¶
type ListJobsResultElements []ListJobsResultElement
type ListResultsResult ¶
type ListResultsResult []ListResultsResultElement
type ListScheduleResult ¶
type ListScheduleResult []ScheduleElement
type ListTablesResult ¶
type ListTablesResult []ListTablesResultElement
ListTablesResult is a collection of ListTablesResultElement
type ListTablesResultElement ¶
type ListTablesResultElement struct {
Id int
UserId int
Description string
Name string
Type string
Count int
CreatedAt time.Time
UpdatedAt time.Time
LastImport time.Time
LastLogTimestamp time.Time
EstimatedStorageSize int
Schema []interface{}
ExpireDays int
PrimaryKey string
PrimaryKeyType string
IncludeV bool
}
ListTablesResultElement represents an item of the result of ListTables API call
type ListUsersResult ¶
type ListUsersResult []ListUsersResultElement
ListUsersResult is a collection of ListUsersResultElement
type ListUsersResultElement ¶
type ListUsersResultElement struct {
ID int
FirstName string
LastName string
Email string
Phone string
GravatarURL string
Administrator bool
CreatedAt time.Time
UpdatedAt time.Time
Name string
AccountOwner bool
Organization string
Roles []string
}
ListUsersResultElement represents an item of the result of ListUsers API
type Optional ¶
type Optional struct {
V interface{}
Default interface{}
}
Used in internal schema, marking the field as optional as well as providing the default.
type PerformBulkImportResult ¶
type RunScheduleResult ¶
type RunScheduleResultList ¶
type RunScheduleResultList []RunScheduleResult
type ScheduleElement ¶
type ScheduleHistoryElement ¶
type ScheduleHistoryElement struct {
ID string
Query string
Type string
URL string
Database string
Status string
StartAt time.Time
EndAt time.Time
ScheduledAt time.Time
CreatedAt time.Time
UpdatedAt time.Time
UserName string
CPUTime float64
Duration float64
ResultSize int
NumRecords int
Result string
Priority int
RetryLimit int
HiveResultSchema []interface{}
Organization string
}
type ScheduleHistoryElementList ¶
type ScheduleHistoryElementList []ScheduleHistoryElement
type ScheduleHistoryList ¶
type ScheduleHistoryList struct {
History ScheduleHistoryElementList
Count int
From int
To int
}
type ScheduleResult ¶
type ServerStatusResult ¶
type ServerStatusResult struct {
Status string
}
type Settings ¶
type Settings struct {
ApiKey string // Treasure Data Account API key
UserAgent string // (Optional) Name that will appear as the User-Agent HTTP header
Router EndpointRouter // (Optional) Endpoint router
ConnectionTimeout time.Duration // (Optional) Connection timeout
ReadTimeout time.Duration // (Optional) Read timeout.
SendTimeout time.Duration // (Optional) Send timeout.
RootCAs *x509.CertPool // (Optional) Specify the CA certificates.
Port int // (Optional) Port number.
Proxy interface{} // (Optional) HTTP proxy to use.
Transport http.RoundTripper // (Optional) Overrides the transport used to establish the connection.
Headers map[string]string // (Optional) Additional headers that will be sent to the endpoint.
}
Settings stores the parameters for initializaing TDClient.
Note that ReadTimeout / SendTimeout includes the time taken for receiving / sending the actual data in addition to the idle time, so it is advised to set the value long enough depending on the circumstances. (network latency etc.)
Specifying 0 to Port means the value will be automatically determined according to the settings.
Proxy can take three kinds of values: *url.URL (parsed URL), func(*http.Request)(*url.URL, error), string (URL) or nil (the direct connection to the endpoint is possible).
Transport allows you to take more control over the communication.
`Ssl` option was removed from client options. td-client-go no longer support `Ssl` option since Treasure Data permits only HTTPS access after September 1, 2020.
type ShowAccountResult ¶
type ShowAccountResult struct {
Id int
Plan int
StorageSize int
GuaranteedCores int
MaximumCores int
CreatedAt time.Time
}
ShowAccountResult stores the result of `ShowAccountResult` API call
type ShowJobResult ¶
type ShowJobResult struct {
Id string
Type string
Database string
UserName string
Status string
Query string
Debug ShowJobResultDebugElement
Url string
Duration int
CreatedAt time.Time
UpdatedAt time.Time
StartAt time.Time
EndAt time.Time
CpuTime float64
ResultSize int
NumRecords int
ResultUrl string
Priority int
RetryLimit int
HiveResultSchema []interface{}
}
ShowJobResult stores the result of `ShowJobResult` API call.
type TDClient ¶
type TDClient struct {
// contains filtered or unexported fields
}
TDClient represents a context used to talk to the Treasure Data API.
func NewTDClient ¶
Creates a new TDClient instance according to the settings.
func (*TDClient) AddAPIKey ¶
func (client *TDClient) AddAPIKey(email string) (*AddAPIKeyResult, error)
func (*TDClient) Authenticate ¶
func (client *TDClient) Authenticate(email, password string) (*AuthenticateResult, error)
func (*TDClient) CommitBulkImport ¶
func (*TDClient) CreateBulkImport ¶
func (*TDClient) CreateDatabase ¶
func (*TDClient) CreateLogTable ¶
func (*TDClient) CreateResult ¶
func (*TDClient) CreateSchedule ¶
func (*TDClient) DeleteBulkImport ¶
func (*TDClient) DeleteBulkImportPart ¶
func (*TDClient) DeleteDatabase ¶
func (*TDClient) DeleteResult ¶
func (*TDClient) DeleteSchedule ¶
func (client *TDClient) DeleteSchedule(scheduleName string) (*DeleteScheduleResult, error)
func (*TDClient) DeleteTable ¶
func (*TDClient) FreezeBulkImport ¶
func (*TDClient) Import ¶
func (client *TDClient) Import(db string, table string, format string, blob Blob, uniqueId string) (float64, error)
`Import` API call.
func (*TDClient) JobResultEach ¶
func (*TDClient) ListAPIKeys ¶
func (client *TDClient) ListAPIKeys(email string) (*ListAPIKeysResult, error)
func (*TDClient) ListBulkImportParts ¶
func (*TDClient) ListBulkImports ¶
func (client *TDClient) ListBulkImports(options map[string]string) (*ListBulkImportElements, error)
func (*TDClient) ListDatabases ¶
func (client *TDClient) ListDatabases() (*ListDataBasesResult, error)
func (*TDClient) ListJobs ¶
func (client *TDClient) ListJobs() (*ListJobsResult, error)
func (*TDClient) ListJobsWithOptions ¶
func (client *TDClient) ListJobsWithOptions(options *ListJobsOptions) (*ListJobsResult, error)
func (*TDClient) ListResults ¶
func (client *TDClient) ListResults() (*ListResultsResult, error)
func (*TDClient) ListSchedules ¶
func (client *TDClient) ListSchedules() (*ListScheduleResult, error)
func (*TDClient) ListTables ¶
func (client *TDClient) ListTables(db string) (*ListTablesResult, error)
func (*TDClient) ListUsers ¶
func (client *TDClient) ListUsers() (*ListUsersResult, error)
func (*TDClient) PerformBulkImport ¶
func (*TDClient) RemoveAPIKey ¶
func (*TDClient) RemoveUser ¶
func (*TDClient) RunSchedule ¶
func (*TDClient) ScheduleHistory ¶
func (*TDClient) ServerStatus ¶
func (client *TDClient) ServerStatus() (*ServerStatusResult, error)
func (*TDClient) ShowAccount ¶
func (client *TDClient) ShowAccount() (*ShowAccountResult, error)
ShowAccount returns the information about the current account
func (*TDClient) ShowBulkImport ¶
func (client *TDClient) ShowBulkImport(name string) (*BulkImportElement, error)
func (*TDClient) ShowDatabase ¶
func (client *TDClient) ShowDatabase(dbname string) (*ListDataBasesResultElement, error)
func (*TDClient) ShowTable ¶
func (client *TDClient) ShowTable(db, table string) (*ListTablesResultElement, error)
func (*TDClient) SubmitExportJob ¶
func (*TDClient) SubmitPartialDeleteJob ¶
func (*TDClient) SubmitQuery ¶
func (*TDClient) UnfreezeBulkImport ¶
func (*TDClient) UpdateExpire ¶
func (*TDClient) UpdateSchedule ¶
func (*TDClient) UpdateSchema ¶
func (*TDClient) UpdateTable ¶
func (*TDClient) UploadBulkImportPart ¶
type TimeoutConn ¶
type TimeoutConn struct {
Conn net.Conn
ReadTimeout time.Duration
WriteTimeout time.Duration
// contains filtered or unexported fields
}
TimeoutConn wraps a regular net.Conn so read / write operations on it will time out in the specified amount of time.
func (*TimeoutConn) Close ¶
func (conn *TimeoutConn) Close() error
func (*TimeoutConn) LocalAddr ¶
func (conn *TimeoutConn) LocalAddr() net.Addr
func (*TimeoutConn) RemoteAddr ¶
func (conn *TimeoutConn) RemoteAddr() net.Addr
func (*TimeoutConn) SetDeadline ¶
func (conn *TimeoutConn) SetDeadline(t time.Time) error
func (*TimeoutConn) SetReadDeadline ¶
func (conn *TimeoutConn) SetReadDeadline(t time.Time) error
func (*TimeoutConn) SetWriteDeadline ¶
func (conn *TimeoutConn) SetWriteDeadline(t time.Time) error
type V3EndpointRouter ¶
V3EndpointRouter routes the import request to the dedicated endpoint and other requests to the default.
func (*V3EndpointRouter) Route ¶
func (r *V3EndpointRouter) Route(requestUri string) string