Class: DeltaSharing::Client
- Inherits:
-
Object
- Object
- DeltaSharing::Client
- Defined in:
- lib/delta_sharing/client.rb
Instance Attribute Summary collapse
-
#profile ⇒ Object
readonly
Returns the value of attribute profile.
Instance Method Summary collapse
-
#get_share(share_name) ⇒ Object
Get share info.
-
#get_table_metadata(share_name, schema_name, table_name) ⇒ Object
Get table metadata.
-
#get_table_version(share_name, schema_name, table_name) ⇒ Object
Query table version (HEAD request).
-
#initialize(profile_file = nil, endpoint: nil, bearer_token: nil) ⇒ Client
constructor
Initialize with profile file path OR direct credentials.
-
#list_schemas(share_name) ⇒ Object
List all schemas in a share.
-
#list_shares ⇒ Object
List all shares.
-
#list_tables(share_name, schema_name = nil) ⇒ Object
List all tables in a share and schema.
-
#read_table_changes(share_name, schema_name, table_name, options = {}) ⇒ Object
Read table changes using POST request.
-
#read_table_data(share_name, schema_name, table_name, options = {}) ⇒ Object
Read table data using POST request.
Constructor Details
#initialize(profile_file = nil, endpoint: nil, bearer_token: nil) ⇒ Client
Initialize with profile file path OR direct credentials
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/delta_sharing/client.rb', line 8 def initialize(profile_file = nil, endpoint: nil, bearer_token: nil) if profile_file && (endpoint || bearer_token) raise ArgumentError, 'Must provide either profile_file path OR both endpoint and bearer_token not both' end if profile_file.nil? && (endpoint && bearer_token.nil? || endpoint.nil? && bearer_token) raise ArgumentError, 'Must provide both endpoint and bearer_token' end if profile_file @profile = load_profile_from_file(profile_file) elsif endpoint && bearer_token @profile = { 'endpoint' => endpoint, 'bearerToken' => bearer_token } end end |
Instance Attribute Details
#profile ⇒ Object (readonly)
Returns the value of attribute profile.
5 6 7 |
# File 'lib/delta_sharing/client.rb', line 5 def profile @profile end |
Instance Method Details
#get_share(share_name) ⇒ Object
Get share info
42 43 44 45 46 |
# File 'lib/delta_sharing/client.rb', line 42 def get_share(share_name) path = "/shares/#{share_name}" response = make_request(path) JSON.parse(response.body) end |
#get_table_metadata(share_name, schema_name, table_name) ⇒ Object
Get table metadata
87 88 89 90 91 |
# File 'lib/delta_sharing/client.rb', line 87 def (share_name, schema_name, table_name) path = "/shares/#{share_name}/schemas/#{schema_name}/tables/#{table_name}/metadata" response = make_request(path) (response.body) end |
#get_table_version(share_name, schema_name, table_name) ⇒ Object
Query table version (HEAD request)
80 81 82 83 84 |
# File 'lib/delta_sharing/client.rb', line 80 def get_table_version(share_name, schema_name, table_name) path = "/shares/#{share_name}/schemas/#{schema_name}/tables/#{table_name}/version" response = make_request(path, method: 'GET') response.headers['delta-table-version'] end |
#list_schemas(share_name) ⇒ Object
List all schemas in a share
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/delta_sharing/client.rb', line 49 def list_schemas(share_name) path = "/shares/#{share_name}/schemas" response = make_request(path) schemas, next_page_token = parse_schemas_response(response.body) while next_page_token response = make_request(path, params: { nextPageToken: next_page_token }) schemas, next_page_token = parse_schemas_response(response.body) end schemas end |
#list_shares ⇒ Object
List all shares
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/delta_sharing/client.rb', line 30 def list_shares path = '/shares' response = make_request(path) shares, next_page_token = parse_shares_response(response.body) while next_page_token response = make_request(path, params: { nextPageToken: next_page_token }) shares, next_page_token = parse_shares_response(response.body) end shares end |
#list_tables(share_name, schema_name = nil) ⇒ Object
List all tables in a share and schema
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/delta_sharing/client.rb', line 61 def list_tables(share_name, schema_name = nil) path = if schema_name # List tables in a specific schema "/shares/#{share_name}/schemas/#{schema_name}/tables" else # List all tables in the share (across all schemas) "/shares/#{share_name}/all-tables" end response = make_request(path) tables, next_page_token = parse_tables_response(response.body) while next_page_token response = make_request(path, params: { nextPageToken: next_page_token }) tables, next_page_token = parse_tables_response(response.body) end tables end |
#read_table_changes(share_name, schema_name, table_name, options = {}) ⇒ Object
Read table changes using POST request
102 103 104 105 106 107 |
# File 'lib/delta_sharing/client.rb', line 102 def read_table_changes(share_name, schema_name, table_name, = {}) path = "/shares/#{share_name}/schemas/#{schema_name}/tables/#{table_name}/changes" params = build_changes_params() response = make_request(path, params: params) parse_newline_delimited_json(response.body) end |
#read_table_data(share_name, schema_name, table_name, options = {}) ⇒ Object
Read table data using POST request
94 95 96 97 98 99 |
# File 'lib/delta_sharing/client.rb', line 94 def read_table_data(share_name, schema_name, table_name, = {}) path = "/shares/#{share_name}/schemas/#{schema_name}/tables/#{table_name}/query" body = build_query_body() response = make_request(path, method: 'POST', body: body) parse_newline_delimited_json(response.body) end |