Documentation ¶
Index ¶
- Constants
- Variables
- type Cluster
- type Config
- type InsFilterFunc
- type Instance
- func (instance *Instance) EndTime() time.Time
- func (instance *Instance) GetCachedInfo() (string, error)
- func (instance *Instance) GetResult() ([]TaskResult, error)
- func (instance *Instance) GetTaskDetail(taskName string) ([]byte, error)
- func (instance *Instance) GetTaskProgress(taskName string) ([]TaskProgressStage, error)
- func (instance *Instance) GetTaskQuotaJson(taskName string) (string, error)
- func (instance *Instance) GetTaskSummary(taskName string) (*TaskSummary, error)
- func (instance *Instance) GetTasks() ([]TaskInInstance, error)
- func (instance *Instance) Id() string
- func (instance *Instance) IsAsync() bool
- func (instance *Instance) IsLoaded() bool
- func (instance *Instance) IsSync() bool
- func (instance *Instance) Load() error
- func (instance *Instance) Owner() string
- func (instance *Instance) ProjectName() string
- func (instance *Instance) StartTime() time.Time
- func (instance *Instance) Status() InstanceStatus
- func (instance *Instance) TaskNameCommitted() string
- func (instance *Instance) TaskResults() []TaskResult
- func (instance *Instance) Terminate() error
- func (instance *Instance) WaitForSuccess() error
- type InstanceOrErr
- type InstanceStatus
- type Instances
- func (instances Instances) CreateTask(projectName string, task Task) (*Instance, error)
- func (instances Instances) CreateTaskWithPriority(projectName string, task Task, jobPriority int) (*Instance, error)
- func (instances Instances) List(f func(*Instance, error), filters ...InsFilterFunc)
- func (instances Instances) ListInstancesQueued(filters ...InsFilterFunc) ([]string, error)
- type LogView
- type MergeTask
- type Odps
- func (odps *Odps) Account() account2.Account
- func (odps *Odps) DefaultProject() Project
- func (odps *Odps) DefaultProjectName() string
- func (odps *Odps) ExecSQl(sql string) (*Instance, error)
- func (odps *Odps) ExecSQlWithHints(sql string, hints map[string]string) (*Instance, error)
- func (odps *Odps) Instance(instanceId string) Instance
- func (odps *Odps) Instances() Instances
- func (odps *Odps) LogView() LogView
- func (odps *Odps) Project(name string) Project
- func (odps *Odps) Projects() Projects
- func (odps *Odps) RestClient() restclient.RestClient
- func (odps *Odps) SetDefaultProjectName(projectName string)
- func (odps *Odps) SetHttpTimeout(t time.Duration)
- func (odps *Odps) SetTcpConnectTimeout(t time.Duration)
- func (odps *Odps) SetUserAgent(userAgent string)
- func (odps *Odps) Table(name string) Table
- func (odps *Odps) Tables() Tables
- type OptionalQuota
- type PFilterFunc
- type Partition
- func (p *Partition) CreatedTime() time.Time
- func (p *Partition) FileNumEx() int
- func (p *Partition) IsArchivedEx() bool
- func (p *Partition) LastDDLTime() time.Time
- func (p *Partition) LastModifiedTime() time.Time
- func (p *Partition) LifeCycleEx() int
- func (p *Partition) Load() error
- func (p *Partition) LoadExtended() error
- func (p *Partition) Name() string
- func (p *Partition) PhysicalSizeEx() int
- func (p *Partition) RecordNum() int
- func (p *Partition) ReservedEx() string
- func (p *Partition) Size() int
- type Project
- func (p *Project) Comment() string
- func (p *Project) CreationTime() time.Time
- func (p *Project) Existed() bool
- func (p *Project) GetAllProperties() (common.Properties, error)
- func (p *Project) GetClusters() ([]Cluster, error)
- func (p *Project) GetDefaultCluster() (string, error)
- func (p *Project) GetExtendedProperties() (common.Properties, error)
- func (p *Project) GetTunnelEndpoint(quotaNames ...string) (string, error)
- func (p *Project) IsLoaded() bool
- func (p *Project) LastModifiedTime() time.Time
- func (p *Project) Load() error
- func (p *Project) Name() string
- func (p *Project) OdpsIns() *Odps
- func (p *Project) Owner() string
- func (p *Project) ProjectGroupName() string
- func (p *Project) PropertiesHasBeSet() common.Properties
- func (p *Project) RestClient() restclient.RestClient
- func (p *Project) SecurityManager() security.Manager
- func (p *Project) Status() ProjectStatus
- func (p *Project) Type() string
- func (p *Project) Update(properties map[string]string) error
- type ProjectStatus
- type Projects
- func (p *Projects) CreateExternalProject(projectName string) error
- func (p *Projects) DeleteExternalProject(projectName string) error
- func (p *Projects) Exists(projectName string) (bool, error)
- func (p *Projects) Get(projectName string) Project
- func (p *Projects) GetDefaultProject() Project
- func (p *Projects) List(filters ...PFilterFunc) ([]Project, error)
- func (p *Projects) UpdateProject(projectName string) error
- type SQLCostTask
- type SQLPlanTask
- type SQLRTTask
- type SQLTask
- type TFilterFunc
- type Table
- func (t *Table) AddPartition(ifNotExists bool, partitionKey string) error
- func (t *Table) Comment() string
- func (t *Table) CreateShards(shardCount int) error
- func (t *Table) CreatedTime() time.Time
- func (t *Table) CryptoAlgo() string
- func (t *Table) DeletePartition(ifExists bool, partitionKey string) error
- func (t *Table) ExecSql(taskName, sql string) (*Instance, error)
- func (t *Table) ExecSqlWithHints(taskName, sql string, hints map[string]string) (*Instance, error)
- func (t *Table) GetPartitions(partitionKey string) ([]Partition, error)
- func (t *Table) GetSchema() (*tableschema.TableSchema, error)
- func (t *Table) HubLifeCycle() int
- func (t *Table) IsLoaded() bool
- func (t *Table) LastDDLTime() time.Time
- func (t *Table) LastModifiedTime() time.Time
- func (t *Table) LifeCycle() int
- func (t *Table) Load() error
- func (t *Table) LoadExtendedInfo() error
- func (t *Table) MaxExtendedLabel() string
- func (t *Table) MaxLabel() string
- func (t *Table) Name() string
- func (t *Table) Owner() string
- func (t *Table) PartitionColumns() []tableschema.Column
- func (t *Table) ProjectName() string
- func (t *Table) RecordNum() int
- func (t *Table) ResourceUrl() string
- func (t *Table) Schema() tableschema.TableSchema
- func (t *Table) SchemaJson() string
- func (t *Table) ShardInfoJson() string
- func (t *Table) Size() int
- func (t *Table) TableExtendedLabels() []string
- func (t *Table) TableID() string
- func (t *Table) TableLabel() string
- func (t *Table) Type() TableType
- func (t *Table) ViewText() string
- type TableOrErr
- type TableType
- type Tables
- func (ts *Tables) BatchLoadTables(tableNames []string) ([]Table, error)
- func (ts *Tables) Create(schema tableschema.TableSchema, createIfNotExists bool, ...) error
- func (ts *Tables) CreateExternal(schema tableschema.TableSchema, createIfNotExists bool, ...) error
- func (ts *Tables) CreateWithDataHub(schema tableschema.TableSchema, createIfNotExists bool, ...) error
- func (ts *Tables) Delete(tableName string, ifExists bool) error
- func (ts *Tables) List(f func(*Table, error), filters ...TFilterFunc)
- type Task
- type TaskConfig
- type TaskInInstance
- type TaskName
- type TaskProgressStage
- type TaskResult
- type TaskStatus
- type TaskSummary
Examples ¶
- Instance.GetCachedInfo
- Instance.GetTaskProgress
- Instance.GetTaskSummary
- Instance.Terminate
- Instances.CreateTask
- Instances.List
- Instances.ListInstancesQueued
- Partition.Load
- Partition.LoadExtended
- Project
- Project.GetTunnelEndpoint
- Projects.Exists
- Projects.List
- Table.AddPartition
- Table.ExecSql
- Table.GetPartitions
- Table.Load
- Tables.BatchLoadTables
- Tables.Create
- Tables.Delete
- Tables.List
Constants ¶
const ( TaskWaiting TaskRunning TaskSuccess TaskFailed TaskSuspended TaskCancelled TaskStatusUnknown )
const ( ProjectStatusAvailable ProjectStatusReadOnly ProjectStatusDeleting ProjectStatusFrozen ProjectStatusUnKnown )
const ( // ProjectTypeManaged ordinary project ProjectTypeManaged = "managed" // ProjectExternalExternal external project,like hive ProjectExternalExternal = "external" )
const DefaultJobPriority = 9
const (
HostDefault = "https://logview.alibaba-inc.com"
)
Variables ¶
var InstanceFilter = struct { // Only get instances with a given status Status func(InstanceStatus) InsFilterFunc // Only get instances that create by the current account OnlyOwner func() InsFilterFunc // Instance 运行所在 quota 组过滤条件 QuotaIndex func(string) InsFilterFunc // Get instances running between start and end times TimeRange func(time.Time, time.Time) InsFilterFunc }{ Status: func(status InstanceStatus) InsFilterFunc { return func(values url.Values) { if status != 0 { values.Set("status", status.String()) } } }, OnlyOwner: func() InsFilterFunc { return func(values url.Values) { values.Set("onlyowner", "yes") } }, QuotaIndex: func(s string) InsFilterFunc { return func(values url.Values) { values.Set("quotaindex", s) } }, TimeRange: func(s time.Time, e time.Time) InsFilterFunc { return func(values url.Values) { startTime := strconv.FormatInt(s.Unix(), 10) endTime := strconv.FormatInt(e.Unix(), 10) dateRange := fmt.Sprintf("%s:%s", startTime, endTime) values.Set("daterange", dateRange) } }, }
var ProjectFilter = struct { // Filter out projects with a name prefix NamePrefix func(string) PFilterFunc // Filter out projects with project owner name, this filter cannot be used with `User` together Owner func(string) PFilterFunc // Filter out projects with a project member name User func(string) PFilterFunc // Filter out projects with the project group name Group func(string) PFilterFunc }{ NamePrefix: withProjectNamePrefix, Owner: withProjectOwner, User: withUserInProject, Group: withProjectGroup, }
var TableFilter = struct { // Weather get extended information or not Extended func() TFilterFunc // Filter out tables with name prefix NamePrefix func(string) TFilterFunc // Filter out tables with owner name Owner func(string) TFilterFunc // Filter out tables with table type Type func(TableType) TFilterFunc }{ Extended: func() TFilterFunc { return func(values url.Values) { values.Set("extended", "") } }, NamePrefix: func(name string) TFilterFunc { return func(values url.Values) { values.Set("name", name) } }, Owner: func(owner string) TFilterFunc { return func(values url.Values) { values.Set("owner", owner) } }, Type: func(tableType TableType) TFilterFunc { return func(values url.Values) { values.Set("type", tableType.String()) } }, }
Functions ¶
This section is empty.
Types ¶
type Cluster ¶
type Cluster struct { Name string `xml:"Name"` QuotaId string `xml:"QuotaId"` Quotas []OptionalQuota `xml:"Quotas"` }
type Config ¶
type Config struct { AccessId string AccessKey string StsToken string Endpoint string ProjectName string TcpConnectionTimeout time.Duration HttpTimeout time.Duration TunnelEndpoint string TunnelQuotaName string Hints map[string]string Others map[string]string }
Config is the basic config for odps. The NewConfig function should be used, which sets default values.
func NewConfigFromIni ¶
func (*Config) GenAccount ¶
func (*Config) GenRestClient ¶
func (c *Config) GenRestClient() restclient.RestClient
type InsFilterFunc ¶
type Instance ¶
type Instance struct {
// contains filtered or unexported fields
}
func NewInstance ¶
func (*Instance) GetCachedInfo ¶
GetCachedInfo 获取instance cached信息,返回的是json字符串,需要自己进行解析
Example ¶
instances := odps.NewInstances(odpsIns) sqlTask := odps.NewSqlTask("hello1", "select * from user;", "", nil) instance, err := instances.CreateTask(defaultProjectName, &sqlTask) if err != nil { log.Fatalf("%+v", err) } println(instance.Id()) i, err := instance.GetCachedInfo() if err != nil { log.Fatalf("%+v", err) } println(fmt.Sprintf("%+v", i))
Output:
func (*Instance) GetResult ¶
func (instance *Instance) GetResult() ([]TaskResult, error)
func (*Instance) GetTaskDetail ¶
func (*Instance) GetTaskProgress ¶
func (instance *Instance) GetTaskProgress(taskName string) ([]TaskProgressStage, error)
Example ¶
instances := odps.NewInstances(odpsIns) sqlTask := odps.NewSqlTask("hello", "select count(*) from sale_detail;", "", nil) instance, err := instances.CreateTask(defaultProjectName, &sqlTask) if err != nil { log.Fatalf("%+v", err) } println(instance.Id()) for i := 0; i < 5; i++ { progress, err := instance.GetTaskProgress("hello") if err != nil { log.Fatalf("%+v", err) } for _, stage := range progress { println(fmt.Sprintf("%+v", stage)) } time.Sleep(time.Second * 1) } body, err := instance.GetTaskDetail("hello") if err != nil { log.Fatalf("%+v", err) } println(string(body))
Output:
func (*Instance) GetTaskQuotaJson ¶
func (*Instance) GetTaskSummary ¶
func (instance *Instance) GetTaskSummary(taskName string) (*TaskSummary, error)
Example ¶
instances := odps.NewInstances(odpsIns) sqlTask := odps.NewSqlTask("hello1", "select count(*) from sale_detail;", "", nil) instance, err := instances.CreateTask(defaultProjectName, &sqlTask) if err != nil { log.Fatalf("%+v", err) } println(instance.Id()) _ = instance.WaitForSuccess() taskSummary, err := instance.GetTaskSummary("hello1") if err != nil { log.Fatalf("%+v", err) } println(fmt.Sprintf("%s\n%s\n", taskSummary.JsonSummary, taskSummary.Summary))
Output:
func (*Instance) GetTasks ¶
func (instance *Instance) GetTasks() ([]TaskInInstance, error)
GetTasks 绝大部分时候返回一个Task(名字与提交的task名字相同),返回多个task的情况我还没有遇到过
func (*Instance) ProjectName ¶
func (*Instance) Status ¶
func (instance *Instance) Status() InstanceStatus
func (*Instance) TaskNameCommitted ¶
func (*Instance) TaskResults ¶
func (instance *Instance) TaskResults() []TaskResult
func (*Instance) Terminate ¶
Example ¶
instances := odps.NewInstances(odpsIns) sqlTask := odps.NewSqlTask("hello", "select count(*) from user;", "", nil) instance, err := instances.CreateTask(defaultProjectName, &sqlTask) if err != nil { log.Fatalf("%+v", err) } println(instance.Id()) err = instance.Terminate() if err != nil { log.Fatalf("%+v", err) } err = instance.Load() if err != nil { log.Fatalf("%+v", err) } println(fmt.Sprintf("%s, %s, %s", instance.StartTime(), instance.EndTime(), instance.Status()))
Output:
func (*Instance) WaitForSuccess ¶
type InstanceOrErr ¶
InstanceOrErr is used for the return value of Instances.List
type InstanceStatus ¶
type InstanceStatus int
const ( InstanceRunning InstanceStatus InstanceSuspended InstanceTerminated InstanceStatusUnknown )
func InstancesStatusFromStr ¶
func InstancesStatusFromStr(s string) InstanceStatus
func (*InstanceStatus) MarshalXML ¶
func (status *InstanceStatus) MarshalXML(d *xml.Encoder, start xml.StartElement) error
func (InstanceStatus) String ¶
func (status InstanceStatus) String() string
func (*InstanceStatus) UnmarshalXML ¶
func (status *InstanceStatus) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
type Instances ¶
type Instances struct {
// contains filtered or unexported fields
}
Instances is used to get or create instance(s)
func NewInstances ¶
NewInstances create Instances object, if the projectName is not set, the default project name of odpsIns will be used
func (Instances) CreateTask ¶
Example ¶
instances := odpsIns.Instances() sqlTask := odps.NewSqlTask("hello", "select count(*) from sale_detail;", "", nil) instance, err := instances.CreateTask(defaultProjectName, &sqlTask) if err != nil { log.Fatalf("%+v", err) } println(instance.Id()) err = instance.Load() if err != nil { log.Fatalf("%+v", err) } println(fmt.Sprintf("%s, %s, %s", instance.StartTime(), instance.EndTime(), instance.Status())) timeFormat := "2006-01-02 15:04:05" Loop: for { tasks, err := instance.GetTasks() task := tasks[0] if err != nil { log.Fatalf("%+v", err) } println( fmt.Sprintf( "%s, %s, %s, %s", task.StartTime.Format(timeFormat), task.EndTime.Format(timeFormat), task.Status, task.Name, )) switch task.Status { case odps.TaskCancelled, odps.TaskFailed, odps.TaskSuccess: break Loop } time.Sleep(time.Second * 2) } err = instance.Load() if err != nil { log.Fatalf("%+v", err) } body, err := instance.GetTaskDetail("hello") if err != nil { log.Fatalf("%+v", err) } println(string(body)) println( fmt.Sprintf( "%s, %s, %s", instance.StartTime().Format(timeFormat), instance.EndTime().Format(timeFormat), instance.Status(), ))
Output:
func (Instances) CreateTaskWithPriority ¶
func (Instances) List ¶
func (instances Instances) List(f func(*Instance, error), filters ...InsFilterFunc)
List Get all instances, the filters can be given with InstanceFilter.Status, InstanceFilter.OnlyOwner, InstanceFilter.QuotaIndex, InstanceFilter.TimeRange
Example ¶
ins := odpsIns.Instances() timeFormat := "2006-01-02 15:04:05" startTime, _ := time.Parse(timeFormat, "2021-11-15 02:15:30") endTime, _ := time.Parse(timeFormat, "2021-11-18 06:22:02") var f = func(i *odps.Instance, err error) { if err != nil { log.Fatalf("%+v", err) } println( fmt.Sprintf( "%s, %s, %s, %s, %s", i.Id(), i.Owner(), i.StartTime().Format(timeFormat), i.EndTime().Format(timeFormat), i.Status(), )) } ins.List(f, odps.InstanceFilter.TimeRange(startTime, endTime))
Output:
func (Instances) ListInstancesQueued ¶
func (instances Instances) ListInstancesQueued(filters ...InsFilterFunc) ([]string, error)
ListInstancesQueued Get all instance Queued information, the information is in json string,you need parse it yourself。 The filters can be given with InstanceFilter.Status, InstanceFilter.OnlyOwner, InstanceFilter.QuotaIndex, InstanceFilter.TimeRange
Example ¶
ins := odpsIns.Instances() instances, err := ins.ListInstancesQueued() if err != nil { log.Fatalf("%+v", err) } for _, i := range instances { println(fmt.Sprintf("%+v", i)) }
Output:
type LogView ¶
type LogView struct {
// contains filtered or unexported fields
}
func NewLogView ¶
func (*LogView) GenerateLogView ¶
func (*LogView) LogViewHost ¶
func (*LogView) SetLogViewHost ¶
type MergeTask ¶
type Odps ¶
type Odps struct {
// contains filtered or unexported fields
}
func (*Odps) DefaultProject ¶
func (*Odps) DefaultProjectName ¶
func (*Odps) ExecSQlWithHints ¶
func (*Odps) RestClient ¶
func (odps *Odps) RestClient() restclient.RestClient
func (*Odps) SetDefaultProjectName ¶
func (*Odps) SetHttpTimeout ¶
func (*Odps) SetTcpConnectTimeout ¶
func (*Odps) SetUserAgent ¶
type OptionalQuota ¶
type OptionalQuota struct { XMLName xml.Name `xml:"OptionalQuota"` QuotaId string `xml:"QuotaID"` Properties common.Properties `xml:"Properties"` }
type PFilterFunc ¶
type Partition ¶
type Partition struct {
// contains filtered or unexported fields
}
Partition ODPS分区表中一个特定的分区
func NewPartition ¶
func (*Partition) CreatedTime ¶
func (*Partition) IsArchivedEx ¶
func (*Partition) LastModifiedTime ¶
func (*Partition) LifeCycleEx ¶
func (*Partition) Load ¶
Example ¶
kv := make(map[string]string, 2) kv["sale_date"] = "201910" kv["region"] = "shanghai" partition := odps.NewPartition(odpsIns, "project_1", "sale_detail", kv) err := partition.Load() if err != nil { log.Fatalf("%+v", err) } println(fmt.Sprintf("Name: %s", partition.Name())) println(fmt.Sprintf("Record number: %d", partition.RecordNum())) println(fmt.Sprintf("Create Time: %s", partition.CreatedTime()))
Output:
func (*Partition) LoadExtended ¶
Example ¶
kv := make(map[string]string, 2) kv["sale_date"] = "201910" kv["region"] = "shanghai" partition := odps.NewPartition(odpsIns, "project_1", "sale_detail", kv) err := partition.LoadExtended() if err != nil { log.Fatalf("%+v", err) } println(fmt.Sprintf("Name: %s", partition.Name())) println(fmt.Sprintf("File number: %d", partition.FileNumEx())) println(fmt.Sprintf("PhysicalSizefd: %d", partition.PhysicalSizeEx())) println(fmt.Sprintf("Reserved: %s", partition.ReservedEx()))
Output:
func (*Partition) PhysicalSizeEx ¶
func (*Partition) ReservedEx ¶
ReservedEx 返回扩展信息的保留字段 json 字符串
type Project ¶
type Project struct {
// contains filtered or unexported fields
}
Example ¶
projects := odpsIns.Projects() project := projects.Get(defaultProjectName) if err := project.Load(); err != nil { panic(err) } println(project.Status()) println(project.Owner()) creationTime := project.CreationTime() println(creationTime.Format(time.RFC1123)) lastModifiedTime := project.LastModifiedTime() println(lastModifiedTime.Format(time.RFC1123)) defaultCluster, _ := project.GetDefaultCluster() println(defaultCluster) println("************all properties") allProperties, _ := project.GetAllProperties() for _, p := range allProperties { println(p.Name, p.Value) } println("************extended properties") extendedProperties, _ := project.GetExtendedProperties() for _, p := range extendedProperties { println(p.Name, p.Value) } isExisted := project.Existed() println(isExisted)
Output:
func NewProject ¶
func (*Project) CreationTime ¶
func (*Project) GetAllProperties ¶
func (p *Project) GetAllProperties() (common.Properties, error)
GetAllProperties get all the configurable properties of the project, including the properties inherit from group. **note**, this method may return error when something wrong during loading data from the api serer
func (*Project) GetClusters ¶
GetClusters Get information of clusters owned by this project. This is an internal method for group-api. **note**, this method may return error when something wrong during loading data from the api serer
func (*Project) GetDefaultCluster ¶
GetDefaultCluster Get default cluster. This is an internal method for group-api. Returns efault cluster when called by group owner, otherwise ,null. **note**, this method may return error when something wrong during loading data from the api serer
func (*Project) GetExtendedProperties ¶
func (p *Project) GetExtendedProperties() (common.Properties, error)
GetExtendedProperties get the extended properties of the project **note**, this method may return error when something wrong during loading data from the api serer
func (*Project) GetTunnelEndpoint ¶
Example ¶
project := odpsIns.DefaultProject() tunnelEndpoint, err := project.GetTunnelEndpoint() if err != nil { log.Fatalf("%+v", err) } else { println(tunnelEndpoint) }
Output:
func (*Project) LastModifiedTime ¶
func (*Project) ProjectGroupName ¶
func (*Project) PropertiesHasBeSet ¶
func (p *Project) PropertiesHasBeSet() common.Properties
PropertiesHasBeSet Properties get the properties those have be set for the project
func (*Project) RestClient ¶
func (p *Project) RestClient() restclient.RestClient
func (*Project) SecurityManager ¶
func (*Project) Status ¶
func (p *Project) Status() ProjectStatus
type ProjectStatus ¶
type ProjectStatus int
func (*ProjectStatus) FromStr ¶
func (status *ProjectStatus) FromStr(s string)
func (ProjectStatus) MarshalXML ¶
func (status ProjectStatus) MarshalXML(d *xml.Encoder, start xml.StartElement) error
func (ProjectStatus) String ¶
func (status ProjectStatus) String() string
func (*ProjectStatus) UnmarshalXML ¶
func (status *ProjectStatus) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
type Projects ¶
type Projects struct {
// contains filtered or unexported fields
}
func NewProjects ¶
func (*Projects) CreateExternalProject ¶
CreateExternalProject unimplemented!
func (*Projects) DeleteExternalProject ¶
DeleteExternalProject unimplemented!
func (*Projects) Exists ¶
Example ¶
projects := odpsIns.Projects() projectName := "project_1" existed, err := projects.Exists(projectName) if err != nil { log.Fatalf("%+v", err) } println(fmt.Sprintf("%s existed: %t", projectName, existed))
Output:
func (*Projects) GetDefaultProject ¶
func (*Projects) List ¶
func (p *Projects) List(filters ...PFilterFunc) ([]Project, error)
List get all the projects thant current account can access in the specific endpoint filters can be specified with ProjectFilter.NamePrefix, ProjectFilter.Owner, ProjectFilter.User, ProjectFilter.Group
Example ¶
projectsIns := odpsIns.Projects() projects, err := projectsIns.List(odps.ProjectFilter.NamePrefix("p")) if err != nil { log.Fatalf("%+v", err) } for _, project := range projects { println(fmt.Sprintf("%+v", project)) }
Output:
func (*Projects) UpdateProject ¶
type SQLCostTask ¶
func NewSQLCostTask ¶
func (*SQLCostTask) TaskType ¶
func (t *SQLCostTask) TaskType() string
type SQLPlanTask ¶
func (*SQLPlanTask) TaskType ¶
func (t *SQLPlanTask) TaskType() string
type SQLTask ¶
type SQLTask struct { XMLName xml.Name `xml:"SQL"` TaskName `xml:"Name"` Comment string TaskConfig Query string }
func NewAnonymousSQLTask ¶
func NewSqlTask ¶
func (*SQLTask) GetSelectResultAsCsv ¶
GetSelectResultAsCsv 最多返回1W条数据
type TFilterFunc ¶
type Table ¶
type Table struct {
// contains filtered or unexported fields
}
Table represent the table in odps projects
func (*Table) AddPartition ¶
AddPartition Example: AddPartition(true, "region='10026, name='abc'")
Example ¶
table := odpsIns.Table("sale_detail") err := table.AddPartition(true, "sale_date='202111',region='hangzhou'") if err != nil { log.Fatalf("%+v", err) }
Output:
func (*Table) CreateShards ¶
func (*Table) CreatedTime ¶
func (*Table) CryptoAlgo ¶
func (*Table) DeletePartition ¶
DeletePartition Example: DeletePartition(true, "region='10026, name='abc'")
func (*Table) ExecSql ¶
Example ¶
//table := odps.NewTable(odpsIns, "project_1", "sale_detail") table := odpsIns.Table("has_struct") //instance, err := table.ExecSql("SelectSale_detail", "select * from sale_detail;") instance, err := table.ExecSql("Select_has_struct", "select * from has_struct;") if err != nil { log.Fatalf("%+v", err) } err = instance.WaitForSuccess() if err != nil { log.Fatalf("%+v", err) } results, err := instance.GetResult() if err != nil { log.Fatalf("%+v", err) } else if len(results) == 0 { log.Fatalf("should get at least one result") } println(fmt.Sprintf("%+v", results[0].Result))
Output:
func (*Table) ExecSqlWithHints ¶
func (*Table) GetPartitions ¶
GetPartitions get partitions with partitionKey like "region='10026, name='abc'"
Example ¶
table := odpsIns.Table("sale_detail") partitions, err := table.GetPartitions("") if err != nil { log.Fatalf("%+v", err) } for _, p := range partitions { println(fmt.Sprintf("Name: %s", p.Name())) println(fmt.Sprintf("Create time: %s", p.CreatedTime())) println(fmt.Sprintf("Last DDL time: %s", p.LastDDLTime())) println(fmt.Sprintf("Last Modified time: %s", p.LastModifiedTime())) println("") }
Output:
func (*Table) GetSchema ¶
func (t *Table) GetSchema() (*tableschema.TableSchema, error)
func (*Table) HubLifeCycle ¶
func (*Table) LastDDLTime ¶
func (*Table) LastModifiedTime ¶
func (*Table) Load ¶
Example ¶
table := odpsIns.Table("has_struct") err := table.Load() if err != nil { log.Fatalf("%+v", err) } schema := table.Schema() println(fmt.Sprintf("%+v", schema.Columns))
Output:
func (*Table) LoadExtendedInfo ¶
func (*Table) MaxExtendedLabel ¶
func (*Table) MaxLabel ¶
MaxLabel 获取最高的label级别 Label的定义分两部分: 1. 业务分类:C,S,B 2. 数据等级:1,2,3,4
二者是正交关系,即C1,C2,C3,C4,S1,S2,S3,S4,B1,B2,B3,B4。
MaxLabel的语意: 1. MaxLabel=max(TableLabel, ColumnLabel), max(...)函数的语意由Label中的数据等级决定:4>3>2>1 2. MaxLabel显示: 当最高等级Label只出现一次时,MaxLabel=业务分类+数据等级,例如:B4, C3,S2 当最高等级LabeL出现多次,但业务分类也唯一,MaxLabel=业务分类+数据等级,例如:B4, C3,S2 当最高等级Label出现多次,且业务不唯一,MaxLabel=L+数据等级,例如:L4, L3
func (*Table) PartitionColumns ¶
func (t *Table) PartitionColumns() []tableschema.Column
func (*Table) ProjectName ¶
func (*Table) ResourceUrl ¶
func (*Table) Schema ¶
func (t *Table) Schema() tableschema.TableSchema
func (*Table) SchemaJson ¶
func (*Table) ShardInfoJson ¶
func (*Table) TableExtendedLabels ¶
func (*Table) TableLabel ¶
type TableOrErr ¶
TableOrErr is used for the return value of Tables.List
type TableType ¶
type TableType int
const ( ManagedTable TableType VirtualView ExternalTable TableTypeUnknown )
func TableTypeFromStr ¶
func (TableType) MarshalXML ¶
func (*TableType) UnmarshalXML ¶
type Tables ¶
type Tables struct {
// contains filtered or unexported fields
}
Tables used for get all the tables in an odps project
func (*Tables) BatchLoadTables ¶
BatchLoadTables can get at most 100 tables, and the information of table is according to the permission
Example ¶
tablesIns := odps.NewTables(odpsIns) tableNames := []string{ "jet_mr_input", "jet_smode_test", "odps_smoke_table", "user", } tables, err := tablesIns.BatchLoadTables(tableNames) if err != nil { log.Fatalf("%+v", err) } for _, table := range tables { println(fmt.Sprintf("%s, %s, %s", table.Name(), table.TableID(), table.Type())) } schema, err := tables[len(tables)-1].GetSchema() if err != nil { log.Fatalf("%+v", err) } for _, c := range schema.Columns { println(fmt.Sprintf("%s, %s, %t, %s", c.Name, c.Type, c.IsNullable, c.Comment)) }
Output:
func (*Tables) Create ¶
func (ts *Tables) Create( schema tableschema.TableSchema, createIfNotExists bool, hints, alias map[string]string) error
Create table with schema, the schema can be build with tableschema.SchemaBuilder parameter hints can affect the `Set` sql execution, like odps.mapred.map.split.size you can get introduce about alias from the reference of alias command
Example ¶
c1 := tableschema.Column{ Name: "name", Type: datatype.StringType, Comment: "name of user", } c2 := tableschema.Column{ Name: "age", Type: datatype.IntType, Comment: "how old is the user", } p1 := tableschema.Column{ Name: "region", Type: datatype.StringType, Comment: "居住区域", } p2 := tableschema.Column{ Name: "code", Type: datatype.IntType, } hints := make(map[string]string) hints["odps.sql.preparse.odps"] = "lot" hints["odps.sql.planner.mode"] = "lot" hints["odps.sql.planner.parser.odps"] = "true" hints["odps.sql.ddl.odps"] = "true" hints["odps.compiler.output.format"] = "lot,pot" builder := tableschema.NewSchemaBuilder() builder.Name("user_temp"). Comment("这就是一条注释"). Columns(c1, c2). PartitionColumns(p1, p2). Lifecycle(2) schema := builder.Build() sql, _ := schema.ToSQLString(defaultProjectName, false) println(sql) tables := odps.NewTables(odpsIns) err := tables.Create(schema, true, hints, nil) if err != nil { log.Fatalf("%+v", err) }
Output:
func (*Tables) CreateExternal ¶
func (ts *Tables) CreateExternal( schema tableschema.TableSchema, createIfNotExists bool, serdeProperties map[string]string, jars []string, hints, alias map[string]string) error
CreateExternal create external table, the schema can be build with tableschema.SchemaBuilder
func (*Tables) CreateWithDataHub ¶
func (ts *Tables) CreateWithDataHub( schema tableschema.TableSchema, createIfNotExists bool, shardNum, hubLifecycle int, ) error
func (*Tables) Delete ¶
Delete delete table
Example ¶
tables := odps.NewTables(odpsIns, odpsIns.DefaultProjectName()) err := tables.Delete("user_temp", false) if err != nil { log.Fatalf("%+v", err) }
Output:
func (*Tables) List ¶
func (ts *Tables) List(f func(*Table, error), filters ...TFilterFunc)
List get all the tables, filters can be specified with TableFilter.NamePrefix, TableFilter.Extended, TableFilter.Owner
Example ¶
ts := odps.NewTables(odpsIns) var f = func(t *odps.Table, err error) { if err != nil { log.Fatalf("%+v", err) } println(fmt.Sprintf("%s, %s, %s", t.Name(), t.Owner(), t.Type())) } ts.List(f, odps.TableFilter.Extended())
Output:
type TaskConfig ¶
TaskConfig 作为embedding filed使用时,使用者自动实现Task接口的AddProperty方法
func (*TaskConfig) AddProperty ¶
func (t *TaskConfig) AddProperty(key, value string)
type TaskInInstance ¶
type TaskInInstance struct { Type string `xml:"Type,attr"` Name string StartTime common.GMTTime EndTime common.GMTTime `xml:"EndTime"` Status TaskStatus }
TaskInInstance 通过Instance创建的Task
type TaskProgressStage ¶
type TaskResult ¶
type TaskResult struct { Type string `xml:"Type,attr"` Name string Status TaskStatus Result struct { TransForm string `xml:"Transform,attr"` Format string `xml:"Format,attr"` // 这个字段没有用到 Content string `xml:",cdata"` } `xml:"Result"` }
func (*TaskResult) Content ¶ added in v0.0.5
func (tr *TaskResult) Content() string
type TaskStatus ¶
type TaskStatus int
func TaskStatusFromStr ¶
func TaskStatusFromStr(s string) TaskStatus
func (*TaskStatus) MarshalXML ¶
func (status *TaskStatus) MarshalXML(d *xml.Encoder, start xml.StartElement) error
func (TaskStatus) String ¶
func (status TaskStatus) String() string
func (*TaskStatus) UnmarshalXML ¶
func (status *TaskStatus) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error