databricks_sql 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "time"
4
+
5
+ module DatabricksSql
6
+ module TypeCoercer
7
+ module_function
8
+
9
+ def coerce_rows(rows, column_schema)
10
+ return rows if column_schema.nil? || column_schema.empty?
11
+
12
+ rows.map { |row| coerce_row(row, column_schema) }
13
+ end
14
+
15
+ def coerce_row(row, column_schema)
16
+ row.each_with_object({}) do |(key, value), coerced|
17
+ target_type = column_schema[key.to_s] || column_schema[key.to_sym]
18
+ coerced[key] = coerce_value(value, target_type)
19
+ end
20
+ end
21
+
22
+ def coerce_value(value, target_type)
23
+ return value if value.nil? || target_type.nil?
24
+
25
+ type = target_type.to_s.downcase
26
+
27
+ case type
28
+ when "string"
29
+ value.to_s
30
+ when "integer", "int"
31
+ Integer(value)
32
+ when "float", "double", "decimal"
33
+ Float(value)
34
+ when "boolean", "bool"
35
+ coerce_boolean(value)
36
+ when "time", "datetime", "timestamp"
37
+ Time.parse(value.to_s)
38
+ else
39
+ value
40
+ end
41
+ rescue ArgumentError, TypeError
42
+ value
43
+ end
44
+
45
+ def coerce_boolean(value)
46
+ return value if [true, false].include?(value)
47
+
48
+ case value.to_s.strip.downcase
49
+ when "true", "1", "yes", "y"
50
+ true
51
+ when "false", "0", "no", "n"
52
+ false
53
+ else
54
+ value
55
+ end
56
+ end
57
+ private_class_method :coerce_boolean
58
+ end
59
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DatabricksSql
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "databricks_sql/version"
4
+ require_relative "databricks_sql/errors"
5
+ require_relative "databricks_sql/configuration"
6
+ require_relative "databricks_sql/result"
7
+ require_relative "databricks_sql/type_coercer"
8
+ require_relative "databricks_sql/external_link_handler"
9
+ require_relative "databricks_sql/client"
10
+
11
+ module DatabricksSql
12
+ class << self
13
+ def configuration
14
+ @configuration ||= Configuration.new
15
+ end
16
+
17
+ def configure
18
+ yield(configuration)
19
+ end
20
+
21
+ def reset_configuration!
22
+ @configuration = Configuration.new
23
+ end
24
+
25
+ def client(**overrides)
26
+ Client.new(**overrides)
27
+ end
28
+ end
29
+ end
30
+
31
+ Databricks = DatabricksSql unless Object.const_defined?(:Databricks)
@@ -0,0 +1,182 @@
1
+ module DatabricksSql
2
+ VERSION: String
3
+
4
+ class << self
5
+ def configuration: () -> Configuration
6
+ def configure: () { (Configuration) -> untyped } -> Configuration
7
+ def reset_configuration!: () -> Configuration
8
+ def client: (**untyped overrides) -> Client
9
+ end
10
+
11
+ class Configuration
12
+ attr_accessor host: String?
13
+ attr_accessor token: String?
14
+ attr_accessor warehouse_id: String?
15
+ attr_accessor timeout: Numeric?
16
+ attr_accessor open_timeout: Numeric?
17
+ attr_accessor statement_path: String?
18
+ attr_accessor external_link_require_https: bool?
19
+ attr_accessor external_link_allowed_hosts: Array[String]?
20
+ def initialize: () -> void
21
+ end
22
+
23
+ class Error < ::StandardError
24
+ end
25
+
26
+ class ConfigurationError < Error
27
+ end
28
+
29
+ class ConnectionError < Error
30
+ end
31
+
32
+ class ParseError < Error
33
+ end
34
+
35
+ class TimeoutError < Error
36
+ attr_reader timeout_seconds: Numeric
37
+ def initialize: (String message, Numeric timeout_seconds) -> void
38
+ end
39
+
40
+ class HTTPError < Error
41
+ attr_reader status_code: Integer
42
+ attr_reader response_body: String?
43
+ def initialize: (String message, status_code: Integer, ?response_body: String?) -> void
44
+ end
45
+
46
+ class AuthenticationError < HTTPError
47
+ end
48
+
49
+ class AuthorizationError < HTTPError
50
+ end
51
+
52
+ class NotFoundError < HTTPError
53
+ end
54
+
55
+ class RateLimitError < HTTPError
56
+ attr_reader retry_after_seconds: Integer?
57
+ def initialize: (String message, status_code: Integer, ?response_body: String?, ?retry_after_seconds: Integer?) -> void
58
+ end
59
+
60
+ class ServerError < HTTPError
61
+ end
62
+
63
+ class ExecutionError < Error
64
+ attr_reader statement_id: String?
65
+ attr_reader status: String?
66
+ def initialize: (String message, statement_id: String?, status: String?) -> void
67
+ end
68
+
69
+ class Result
70
+ attr_reader statement_id: String?
71
+ attr_reader status: String
72
+ attr_reader disposition: String
73
+ attr_reader format: String
74
+ attr_reader columns: Array[String]
75
+ attr_reader rows: Array[untyped]
76
+ attr_reader manifest: Hash[untyped, untyped]?
77
+ attr_reader raw_response: Hash[untyped, untyped]
78
+ attr_reader next_chunk_internal_link: String?
79
+
80
+ def initialize: (
81
+ statement_id: String?,
82
+ status: String,
83
+ disposition: String,
84
+ format: String,
85
+ columns: Array[String],
86
+ rows: Array[untyped],
87
+ manifest: Hash[untyped, untyped]?,
88
+ raw_response: Hash[untyped, untyped],
89
+ ?next_chunk_internal_link: String?
90
+ ) -> void
91
+
92
+ def success?: () -> bool
93
+ end
94
+
95
+ class Client
96
+ def initialize: (
97
+ ?host: String?,
98
+ ?token: String?,
99
+ ?warehouse_id: String?,
100
+ ?timeout: Numeric,
101
+ ?open_timeout: Numeric,
102
+ ?statement_path: String
103
+ ) -> void
104
+
105
+ def execute_statement: (
106
+ statement: String,
107
+ ?parameters: untyped,
108
+ ?format: String,
109
+ ?disposition: String,
110
+ ?catalog: String?,
111
+ ?schema: String?,
112
+ ?column_schema: Hash[untyped, untyped]?,
113
+ ?wait_timeout: String,
114
+ ?on_wait_timeout: String,
115
+ ?poll_interval: Numeric,
116
+ ?max_wait: Numeric,
117
+ ?request_timeout: Numeric?,
118
+ ?cancel_on_timeout: bool,
119
+ ?auto_fetch_chunks: bool,
120
+ ?byte_limit: Integer?,
121
+ ?row_limit: Integer?,
122
+ ?query_tags: Array[Hash[untyped, untyped]]?
123
+ ) -> Result
124
+
125
+ def execute_statement_async: (
126
+ statement: String,
127
+ ?parameters: untyped,
128
+ ?format: String,
129
+ ?disposition: String,
130
+ ?catalog: String?,
131
+ ?schema: String?,
132
+ ?wait_timeout: String,
133
+ ?on_wait_timeout: String,
134
+ ?request_timeout: Numeric?,
135
+ ?byte_limit: Integer?,
136
+ ?row_limit: Integer?,
137
+ ?query_tags: Array[Hash[untyped, untyped]]?
138
+ ) -> Hash[untyped, untyped]
139
+
140
+ def get_statement: (statement_id: String, ?request_timeout: Numeric?) -> Hash[untyped, untyped]
141
+ def get_statement_chunk: (
142
+ statement_id: String,
143
+ chunk_index: Integer,
144
+ ?row_offset: Integer?,
145
+ ?request_timeout: Numeric?
146
+ ) -> Hash[untyped, untyped]
147
+ def get_statement_chunk_by_link: (
148
+ next_chunk_internal_link: String,
149
+ ?request_timeout: Numeric?
150
+ ) -> Hash[untyped, untyped]
151
+ def fetch_next_chunk: (
152
+ statement_id: String,
153
+ next_chunk_internal_link: String,
154
+ columns: Array[String],
155
+ ?disposition: String,
156
+ ?column_schema: Hash[untyped, untyped]?,
157
+ ?request_timeout: Numeric?
158
+ ) -> Result
159
+ def cancel_statement: (statement_id: String, ?request_timeout: Numeric?) -> Hash[untyped, untyped]?
160
+
161
+ def wait_for_statement: (
162
+ statement_id: String,
163
+ ?format: String,
164
+ ?disposition: String,
165
+ ?column_schema: Hash[untyped, untyped]?,
166
+ ?poll_interval: Numeric,
167
+ ?max_wait: Numeric,
168
+ ?request_timeout: Numeric?,
169
+ ?cancel_on_timeout: bool,
170
+ ?auto_fetch_chunks: bool
171
+ ) -> Result
172
+ end
173
+ end
174
+
175
+ module Databricks
176
+ class << self
177
+ def configuration: () -> DatabricksSql::Configuration
178
+ def configure: () { (DatabricksSql::Configuration) -> untyped } -> DatabricksSql::Configuration
179
+ def reset_configuration!: () -> DatabricksSql::Configuration
180
+ def client: (**untyped overrides) -> DatabricksSql::Client
181
+ end
182
+ end