Class: Aliyun::Odps::TablePartitions

Inherits:
ServiceObject show all
Defined in:
lib/aliyun/odps/model/table_partitions.rb

Instance Attribute Summary

Attributes inherited from ServiceObject

#master

Instance Method Summary collapse

Methods inherited from ServiceObject

build, #client, #initialize, #project, service_pool

Constructor Details

This class inherits a constructor from Aliyun::Odps::ServiceObject

Instance Method Details

#create(partition) ⇒ Hash

Create Partition

Parameters:

  • partition (Hash<name, value>)

    specify the partition you want to create

Returns:

  • (Hash)

    the partition you create

Raises:

  • InstanceTaskNotSuccessError if instance task failed



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/aliyun/odps/model/table_partitions.rb', line 34

def create(partition)
  sql = generate_create_sql(partition)

  task = InstanceTask.new(
    name: 'SQLCreatePartitionTask',
    type: 'SQL',
    query: sql
  )

  instance = project.instances.create([task])

  instance.wait_for_success

  partition
end

#delete(partition) ⇒ true

Delete Partition

Returns:

  • (true)

Raises:

  • InstanceTaskNotSuccessError if instance task failed



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/aliyun/odps/model/table_partitions.rb', line 57

def delete(partition)
  sql = generate_drop_sql(partition)

  task = InstanceTask.new(
    name: 'SQLDropPartitionTask',
    type: 'SQL',
    query: sql
  )

  instance = project.instances.create([task])

  instance.wait_for_success

  true
end

#list(options = {}) ⇒ List

List partitions for table

Parameters:

  • options (Hash) (defaults to: {})

    options

Options Hash (options):

  • :marker (String)

    specify marker for paginate

  • :maxitems (String) — default: 1000

    specify maxitems in this request

Returns:

See Also:



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/aliyun/odps/model/table_partitions.rb', line 13

def list(options = {})
  Utils.stringify_keys!(options)
  path = "/projects/#{project.name}/tables/#{master.name}"
  query = {
    partitions: true,
    expectmarker: true
  }.merge(Utils.hash_slice(options, 'marker', 'maxitems'))

  result = client.get(path, query: query).parsed_response
  Aliyun::Odps::List.build(result, %w(Partitions Partition)) do |hash|
    build_table_partition(hash)
  end
end