Class: Aliyun::Odps::UploadSession

Inherits:
Struct::Base show all
Defined in:
lib/aliyun/odps/tunnel/upload_session.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Struct::Base

#initialize, property, #update_attrs

Constructor Details

This class inherits a constructor from Aliyun::Odps::Struct::Base

Instance Attribute Details

#blocks:Array

Returns:

  • (:Array)


17
18
19
# File 'lib/aliyun/odps/tunnel/upload_session.rb', line 17

property :blocks, :Array, init_with: ->(value) do
  value.map { |v| UploadBlock.new(v) }
end

#client:Client

Returns:

  • (:Client)


8
# File 'lib/aliyun/odps/tunnel/upload_session.rb', line 8

property :client, :Client, required: true

#initiated:DateTime

Returns:

  • (:DateTime)


15
# File 'lib/aliyun/odps/tunnel/upload_session.rb', line 15

property :initiated, :DateTime

#owner:String

Returns:

  • (:String)


14
# File 'lib/aliyun/odps/tunnel/upload_session.rb', line 14

property :owner, :String

#partition_spec:String

Returns:

  • (:String)


12
# File 'lib/aliyun/odps/tunnel/upload_session.rb', line 12

property :partition_spec, :String

#project:Project

Returns:

  • (:Project)


7
# File 'lib/aliyun/odps/tunnel/upload_session.rb', line 7

property :project, :Project, required: true

#schema:Hash

Returns:

  • (:Hash)


16
# File 'lib/aliyun/odps/tunnel/upload_session.rb', line 16

property :schema, :Hash

#status:String

Returns:

  • (:String)


13
# File 'lib/aliyun/odps/tunnel/upload_session.rb', line 13

property :status, :String

#table_name:String

Returns:

  • (:String)


11
# File 'lib/aliyun/odps/tunnel/upload_session.rb', line 11

property :table_name, :String, required: true

#upload_id:String

Returns:

  • (:String)


10
# File 'lib/aliyun/odps/tunnel/upload_session.rb', line 10

property :upload_id, :String, required: true

Instance Method Details

#completetrue

Complete the upload session

Returns:

  • (true)

See Also:



76
77
78
79
80
81
82
83
84
85
# File 'lib/aliyun/odps/tunnel/upload_session.rb', line 76

def complete
  path = "/projects/#{project.name}/tables/#{table_name}"

  query = { uploadid: upload_id }
  query.merge!(partition: partition_spec) if partition_spec

  headers = { 'x-odps-tunnel-version' => TableTunnels::TUNNEL_VERSION }

  !!client.post(path, query: query, headers: headers)
end

#list_blocksArray<UploadBlock>

List uploaded blocks

Returns:



66
67
68
69
# File 'lib/aliyun/odps/tunnel/upload_session.rb', line 66

def list_blocks
  reload
  blocks
end

#reloadUploadSession

reload this upload session



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/aliyun/odps/tunnel/upload_session.rb', line 49

def reload
  path = "/projects/#{project.name}/tables/#{table_name}"

  query = { uploadid: upload_id }
  query.merge!(partition: partition_spec) if partition_spec

  resp = client.get(path, query: query)

  result = resp.parsed_response
  attrs = result.is_a?(String) ? JSON.parse(result) : result

  update_attrs(attrs)
end

#upload(block_id, record_values, encoding = 'raw') ⇒ true

Upload data with block id

Parameters:

  • block_id (String)

    specify block_id for this upload, range in 0~19999, new block with replace with old with same blockid

  • record_values (Array<Array>)

    specify the data, a array for your record, with order matched with your schema

  • encoding (String) (defaults to: 'raw')

    specify the data compression format, supported value: raw, deflate

Returns:

  • (true)

See Also:



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/aliyun/odps/tunnel/upload_session.rb', line 32

def upload(block_id, record_values, encoding = 'raw')
  path = "/projects/#{project.name}/tables/#{table_name}"

  query = { blockid: block_id, uploadid: upload_id }
  query[:partition] = partition_spec if partition_spec

  headers = build_upload_headers(encoding)
  body = generate_upload_body(record_values, encoding)

  !!client.put(path, query: query, headers: headers, body: body)
end