dwh 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.
- checksums.yaml +7 -0
- data/.rubocop.yml +36 -0
- data/CHANGELOG.md +5 -0
- data/LICENSE +21 -0
- data/README.md +130 -0
- data/Rakefile +42 -0
- data/docs/DWH/Adapters/Adapter.html +3053 -0
- data/docs/DWH/Adapters/Athena.html +1704 -0
- data/docs/DWH/Adapters/Boolean.html +121 -0
- data/docs/DWH/Adapters/Druid.html +1626 -0
- data/docs/DWH/Adapters/DuckDb.html +2012 -0
- data/docs/DWH/Adapters/MySql.html +1704 -0
- data/docs/DWH/Adapters/OpenAuthorizable/ClassMethods.html +265 -0
- data/docs/DWH/Adapters/OpenAuthorizable.html +1102 -0
- data/docs/DWH/Adapters/Postgres.html +2000 -0
- data/docs/DWH/Adapters/Snowflake.html +1662 -0
- data/docs/DWH/Adapters/SqlServer.html +2084 -0
- data/docs/DWH/Adapters/Trino.html +1835 -0
- data/docs/DWH/Adapters.html +129 -0
- data/docs/DWH/AuthenticationError.html +142 -0
- data/docs/DWH/Behaviors.html +767 -0
- data/docs/DWH/Capabilities.html +748 -0
- data/docs/DWH/Column.html +1115 -0
- data/docs/DWH/ConfigError.html +143 -0
- data/docs/DWH/ConnectionError.html +143 -0
- data/docs/DWH/DWHError.html +138 -0
- data/docs/DWH/ExecutionError.html +143 -0
- data/docs/DWH/Factory.html +1133 -0
- data/docs/DWH/Functions/Arrays.html +505 -0
- data/docs/DWH/Functions/Dates.html +1644 -0
- data/docs/DWH/Functions/ExtractDatePart.html +804 -0
- data/docs/DWH/Functions/Nulls.html +377 -0
- data/docs/DWH/Functions.html +846 -0
- data/docs/DWH/Logger.html +258 -0
- data/docs/DWH/OAuthError.html +138 -0
- data/docs/DWH/Settings.html +658 -0
- data/docs/DWH/StreamingStats.html +804 -0
- data/docs/DWH/Table.html +1260 -0
- data/docs/DWH/TableStats.html +583 -0
- data/docs/DWH/TokenExpiredError.html +142 -0
- data/docs/DWH/UnsupportedCapability.html +135 -0
- data/docs/DWH.html +220 -0
- data/docs/_index.html +471 -0
- data/docs/class_list.html +54 -0
- data/docs/css/common.css +1 -0
- data/docs/css/full_list.css +58 -0
- data/docs/css/style.css +503 -0
- data/docs/file.README.html +210 -0
- data/docs/file.adapters.html +514 -0
- data/docs/file.creating-adapters.html +497 -0
- data/docs/file.getting-started.html +288 -0
- data/docs/file.usage.html +446 -0
- data/docs/file_list.html +79 -0
- data/docs/frames.html +22 -0
- data/docs/guides/adapters.md +445 -0
- data/docs/guides/creating-adapters.md +430 -0
- data/docs/guides/getting-started.md +225 -0
- data/docs/guides/usage.md +378 -0
- data/docs/index.html +210 -0
- data/docs/js/app.js +344 -0
- data/docs/js/full_list.js +242 -0
- data/docs/js/jquery.js +4 -0
- data/docs/method_list.html +2038 -0
- data/docs/top-level-namespace.html +110 -0
- data/lib/dwh/adapters/athena.rb +359 -0
- data/lib/dwh/adapters/druid.rb +267 -0
- data/lib/dwh/adapters/duck_db.rb +235 -0
- data/lib/dwh/adapters/my_sql.rb +235 -0
- data/lib/dwh/adapters/open_authorizable.rb +215 -0
- data/lib/dwh/adapters/postgres.rb +250 -0
- data/lib/dwh/adapters/snowflake.rb +489 -0
- data/lib/dwh/adapters/sql_server.rb +257 -0
- data/lib/dwh/adapters/trino.rb +213 -0
- data/lib/dwh/adapters.rb +363 -0
- data/lib/dwh/behaviors.rb +67 -0
- data/lib/dwh/capabilities.rb +39 -0
- data/lib/dwh/column.rb +79 -0
- data/lib/dwh/errors.rb +29 -0
- data/lib/dwh/factory.rb +125 -0
- data/lib/dwh/functions/arrays.rb +42 -0
- data/lib/dwh/functions/dates.rb +162 -0
- data/lib/dwh/functions/extract_date_part.rb +70 -0
- data/lib/dwh/functions/nulls.rb +31 -0
- data/lib/dwh/functions.rb +86 -0
- data/lib/dwh/logger.rb +50 -0
- data/lib/dwh/settings/athena.yml +77 -0
- data/lib/dwh/settings/base.yml +81 -0
- data/lib/dwh/settings/databricks.yml +51 -0
- data/lib/dwh/settings/druid.yml +59 -0
- data/lib/dwh/settings/duckdb.yml +44 -0
- data/lib/dwh/settings/mysql.yml +67 -0
- data/lib/dwh/settings/postgres.yml +30 -0
- data/lib/dwh/settings/redshift.yml +52 -0
- data/lib/dwh/settings/snowflake.yml +45 -0
- data/lib/dwh/settings/sqlserver.yml +80 -0
- data/lib/dwh/settings/trino.yml +77 -0
- data/lib/dwh/settings.rb +79 -0
- data/lib/dwh/streaming_stats.rb +69 -0
- data/lib/dwh/table.rb +105 -0
- data/lib/dwh/table_stats.rb +51 -0
- data/lib/dwh/version.rb +5 -0
- data/lib/dwh.rb +54 -0
- data/sig/dwh.rbs +4 -0
- metadata +231 -0
@@ -0,0 +1,446 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta charset="UTF-8">
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6
|
+
<title>
|
7
|
+
File: Advanced Usage
|
8
|
+
|
9
|
+
— Documentation by YARD 0.9.37
|
10
|
+
|
11
|
+
</title>
|
12
|
+
|
13
|
+
<link rel="stylesheet" href="css/style.css" type="text/css" />
|
14
|
+
|
15
|
+
<link rel="stylesheet" href="css/common.css" type="text/css" />
|
16
|
+
|
17
|
+
<script type="text/javascript">
|
18
|
+
pathId = "usage";
|
19
|
+
relpath = '';
|
20
|
+
</script>
|
21
|
+
|
22
|
+
|
23
|
+
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
24
|
+
|
25
|
+
<script type="text/javascript" charset="utf-8" src="js/app.js"></script>
|
26
|
+
|
27
|
+
|
28
|
+
</head>
|
29
|
+
<body>
|
30
|
+
<div class="nav_wrap">
|
31
|
+
<iframe id="nav" src="file_list.html?1"></iframe>
|
32
|
+
<div id="resizer"></div>
|
33
|
+
</div>
|
34
|
+
|
35
|
+
<div id="main" tabindex="-1">
|
36
|
+
<div id="header">
|
37
|
+
<div id="menu">
|
38
|
+
|
39
|
+
<a href="_index.html">Index</a> »
|
40
|
+
<span class="title">File: Advanced Usage</span>
|
41
|
+
|
42
|
+
</div>
|
43
|
+
|
44
|
+
<div id="search">
|
45
|
+
|
46
|
+
<a class="full_list_link" id="class_list_link"
|
47
|
+
href="class_list.html">
|
48
|
+
|
49
|
+
<svg width="24" height="24">
|
50
|
+
<rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
|
51
|
+
<rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
|
52
|
+
<rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
|
53
|
+
</svg>
|
54
|
+
</a>
|
55
|
+
|
56
|
+
</div>
|
57
|
+
<div class="clear"></div>
|
58
|
+
</div>
|
59
|
+
|
60
|
+
<div id="content"><div id='filecontents'><h1 id="advanced-usage-guide">Advanced Usage Guide</h1>
|
61
|
+
|
62
|
+
<p>This guide covers advanced features and usage patterns for DWH, including function translation, streaming, connection pooling, and performance optimization.</p>
|
63
|
+
|
64
|
+
<h2 id="sql-function-translation">SQL Function Translation</h2>
|
65
|
+
|
66
|
+
<p>DWH provides automatic translation of common SQL functions to database-specific syntax. This allows you to write database-agnostic code while leveraging native optimizations.</p>
|
67
|
+
|
68
|
+
<h3 id="date-functions">Date Functions</h3>
|
69
|
+
|
70
|
+
<h4 id="date-truncation">Date Truncation</h4>
|
71
|
+
|
72
|
+
<p>```ruby
|
73
|
+
# Truncate dates to different periods
|
74
|
+
adapter.truncate_date(‘week’, ‘created_at’)
|
75
|
+
# PostgreSQL: DATE_TRUNC(‘week’, created_at)
|
76
|
+
# SQL Server: DATETRUNC(week, created_at)
|
77
|
+
# MySQL: DATE_FORMAT(created_at, ‘%Y-%m-%d’) - complex logic</p>
|
78
|
+
|
79
|
+
<p>adapter.truncate_date(‘month’, ‘order_date’)
|
80
|
+
adapter.truncate_date(‘year’, ‘signup_date’)
|
81
|
+
```</p>
|
82
|
+
|
83
|
+
<h4 id="date-literals">Date Literals</h4>
|
84
|
+
|
85
|
+
<p>```ruby
|
86
|
+
# Create database-specific date literals
|
87
|
+
adapter.date_literal(‘2025-01-01’)
|
88
|
+
# PostgreSQL: ‘2025-01-01’::DATE
|
89
|
+
# SQL Server: ‘2025-01-01’
|
90
|
+
# MySQL: ‘2025-01-01’</p>
|
91
|
+
|
92
|
+
<p>adapter.date_time_literal(‘2025-01-01 10:30:00’)
|
93
|
+
# PostgreSQL: ‘2025-01-01 10:30:00’::TIMESTAMP
|
94
|
+
# SQL Server: ‘2025-01-01 10:30:00’
|
95
|
+
```</p>
|
96
|
+
|
97
|
+
<h4 id="date-arithmetic">Date Arithmetic</h4>
|
98
|
+
|
99
|
+
<p>```ruby
|
100
|
+
# Add/subtract time periods
|
101
|
+
adapter.date_add(‘created_at’, 30, ‘day’)
|
102
|
+
# PostgreSQL: (created_at + ‘30 day’::interval)
|
103
|
+
# SQL Server: DATEADD(day, 30, created_at)
|
104
|
+
# MySQL: TIMESTAMPADD(day, 30, created_at)</p>
|
105
|
+
|
106
|
+
<p>adapter.date_diff(‘end_date’, ‘start_date’, ‘day’)
|
107
|
+
# Calculate difference between dates in specified units
|
108
|
+
```</p>
|
109
|
+
|
110
|
+
<h4 id="date-extraction">Date Extraction</h4>
|
111
|
+
|
112
|
+
<p>```ruby
|
113
|
+
# Extract date parts
|
114
|
+
adapter.extract_year(‘created_at’)
|
115
|
+
# PostgreSQL: extract(year from created_at)
|
116
|
+
# SQL Server: DATEPART(year, created_at)</p>
|
117
|
+
|
118
|
+
<p>adapter.extract_month(‘created_at’)
|
119
|
+
adapter.extract_day_of_week(‘created_at’)
|
120
|
+
adapter.extract_quarter(‘created_at’)
|
121
|
+
```</p>
|
122
|
+
|
123
|
+
<h3 id="string-functions">String Functions</h3>
|
124
|
+
|
125
|
+
<p>```ruby
|
126
|
+
# String manipulation
|
127
|
+
adapter.trim(‘column_name’) # Remove whitespace
|
128
|
+
adapter.upper_case(‘column_name’) # Convert to uppercase
|
129
|
+
adapter.lower_case(‘column_name’) # Convert to lowercase</p>
|
130
|
+
|
131
|
+
<h1 id="quoting-and-literals">Quoting and literals</h1>
|
132
|
+
<p>adapter.quote(‘column_name’) # Database-specific column quoting
|
133
|
+
adapter.string_literal(‘value’) # Database-specific string literals
|
134
|
+
```</p>
|
135
|
+
|
136
|
+
<h3 id="null-handling">Null Handling</h3>
|
137
|
+
|
138
|
+
<p>```ruby
|
139
|
+
# Null value handling
|
140
|
+
adapter.if_null(‘column1’, “‘default’”)
|
141
|
+
# PostgreSQL: COALESCE(column1, ‘default’)
|
142
|
+
# SQL Server: ISNULL(column1, ‘default’)</p>
|
143
|
+
|
144
|
+
<p>adapter.null_if(‘column1’, “‘empty’”)
|
145
|
+
# Returns NULL if column1 equals ‘empty’</p>
|
146
|
+
|
147
|
+
<p>adapter.null_if_zero(‘numeric_column’)
|
148
|
+
# Returns NULL if numeric_column equals 0
|
149
|
+
```</p>
|
150
|
+
|
151
|
+
<h3 id="array-functions">Array Functions</h3>
|
152
|
+
|
153
|
+
<p>Available for databases that support array operations (PostgreSQL, Druid):</p>
|
154
|
+
|
155
|
+
<p>```ruby
|
156
|
+
# Check if array contains any values from a list
|
157
|
+
adapter.array_in_list(‘tags’, “‘tech’, ‘science’”)
|
158
|
+
# PostgreSQL: tags && ARRAY[‘tech’, ‘science’]
|
159
|
+
# Druid: MV_OVERLAP(tags, ARRAY[‘tech’, ‘science’])</p>
|
160
|
+
|
161
|
+
<h1 id="check-if-array-excludes-all-values-from-a-list">Check if array excludes all values from a list</h1>
|
162
|
+
<p>adapter.array_exclude_list(‘categories’, “‘spam’, ‘test’”)</p>
|
163
|
+
|
164
|
+
<h1 id="unnestexplode-array-for-joins">Unnest/explode array for joins</h1>
|
165
|
+
<p>adapter.array_unnest_join(‘tags’, ‘tag_alias’)
|
166
|
+
# PostgreSQL: CROSS JOIN UNNEST(tags) AS tag_alias
|
167
|
+
# Druid: CROSS JOIN UNNEST(MV_TO_ARRAY(tags)) tag_alias
|
168
|
+
```</p>
|
169
|
+
|
170
|
+
<h3 id="type-casting">Type Casting</h3>
|
171
|
+
|
172
|
+
<p><code>ruby
|
173
|
+
# Database-specific type casting
|
174
|
+
adapter.cast('column_name', 'INTEGER')
|
175
|
+
# PostgreSQL: column_name::INTEGER
|
176
|
+
# SQL Server: CAST(column_name AS INTEGER)
|
177
|
+
# MySQL: CAST(column_name AS SIGNED)
|
178
|
+
</code></p>
|
179
|
+
|
180
|
+
<h2 id="streaming-and-large-result-sets">Streaming and Large Result Sets</h2>
|
181
|
+
|
182
|
+
<h3 id="basic-streaming">Basic Streaming</h3>
|
183
|
+
|
184
|
+
<p>```ruby
|
185
|
+
# Stream results directly to a file
|
186
|
+
File.open(‘large_export.csv’, ‘w’) do |file|
|
187
|
+
adapter.execute_stream(“SELECT * FROM large_table”, file)
|
188
|
+
end</p>
|
189
|
+
|
190
|
+
<h1 id="stream-with-custom-processing">Stream with custom processing</h1>
|
191
|
+
<p>adapter.stream(“SELECT * FROM large_table”) do |chunk|
|
192
|
+
# Process each chunk as it arrives
|
193
|
+
process_data_chunk(chunk)
|
194
|
+
end
|
195
|
+
```</p>
|
196
|
+
|
197
|
+
<h3 id="streaming-with-statistics">Streaming with Statistics</h3>
|
198
|
+
|
199
|
+
<p>```ruby
|
200
|
+
# Create streaming stats collector
|
201
|
+
stats = DWH::StreamingStats.new(10_000) # Keep 10k rows in memory for preview</p>
|
202
|
+
|
203
|
+
<h1 id="stream-with-stats-tracking">Stream with stats tracking</h1>
|
204
|
+
<p>File.open(‘export.csv’, ‘w’) do |file|
|
205
|
+
exec_thread = adapter.execute_stream(“SELECT * FROM large_table”, file, stats: stats)</p>
|
206
|
+
|
207
|
+
<p># Monitor progress in another thread
|
208
|
+
Thread.new do
|
209
|
+
loop do
|
210
|
+
puts “Processed: #statsstats.total_rows rows”
|
211
|
+
puts “Preview size: #statsstats.datastats.data.size rows”
|
212
|
+
puts “Max row size: #statsstats.max_row_size bytes”
|
213
|
+
sleep(5)
|
214
|
+
break unless exec_thread.alive?
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end</p>
|
218
|
+
|
219
|
+
<h1 id="access-collected-statistics">Access collected statistics</h1>
|
220
|
+
<p>puts “Final count: #statsstats.total_rows”
|
221
|
+
puts “Sample data: #statsstats.datastats.data.first(5)”
|
222
|
+
```</p>
|
223
|
+
|
224
|
+
<h3 id="memory-management">Memory Management</h3>
|
225
|
+
|
226
|
+
<p>```ruby
|
227
|
+
# Configure streaming stats memory usage
|
228
|
+
stats = DWH::StreamingStats.new(50_000) # Keep more data for larger previews</p>
|
229
|
+
|
230
|
+
<h1 id="reset-stats-for-reuse">Reset stats for reuse</h1>
|
231
|
+
<p>stats.reset</p>
|
232
|
+
|
233
|
+
<h1 id="manual-memory-management">Manual memory management</h1>
|
234
|
+
<p>stats.add_row([‘col1’, ‘col2’, ‘col3’])
|
235
|
+
current_data = stats.data # Thread-safe access
|
236
|
+
```</p>
|
237
|
+
|
238
|
+
<h2 id="connection-pooling">Connection Pooling</h2>
|
239
|
+
|
240
|
+
<h3 id="creating-connection-pools">Creating Connection Pools</h3>
|
241
|
+
|
242
|
+
<p>```ruby
|
243
|
+
# Create a named connection pool
|
244
|
+
pool = DWH.pool(‘analytics_pool’, :postgres, {
|
245
|
+
host: ‘localhost’,
|
246
|
+
database: ‘analytics’,
|
247
|
+
username: ‘analyst’,
|
248
|
+
password: ‘password’
|
249
|
+
}, size: 10, timeout: 5)</p>
|
250
|
+
|
251
|
+
<h1 id="multiple-pools-for-different-databases">Multiple pools for different databases</h1>
|
252
|
+
<p>etl_pool = DWH.pool(‘etl_pool’, :postgres, etl_config, size: 5)
|
253
|
+
reporting_pool = DWH.pool(‘reporting_pool’, :mysql, reporting_config, size: 15)
|
254
|
+
```</p>
|
255
|
+
|
256
|
+
<h3 id="using-connection-pools">Using Connection Pools</h3>
|
257
|
+
|
258
|
+
<p>```ruby
|
259
|
+
# Basic pool usage
|
260
|
+
pool.with do |connection|
|
261
|
+
results = connection.execute(“SELECT COUNT(*) FROM users”)
|
262
|
+
metadata = connection.metadata(‘orders’)
|
263
|
+
end</p>
|
264
|
+
|
265
|
+
<h1 id="nested-pool-operations">Nested pool operations</h1>
|
266
|
+
<p>pool.with do |conn1|
|
267
|
+
users = conn1.execute(“SELECT id FROM users LIMIT 100”)</p>
|
268
|
+
|
269
|
+
<p>pool.with do |conn2| # Gets different connection from pool
|
270
|
+
orders = conn2.execute(“SELECT * FROM orders WHERE user_id IN (?)”,
|
271
|
+
users.map(&:first))
|
272
|
+
end
|
273
|
+
end
|
274
|
+
```</p>
|
275
|
+
|
276
|
+
<h3 id="pool-management">Pool Management</h3>
|
277
|
+
|
278
|
+
<p>```ruby
|
279
|
+
# Check pool status
|
280
|
+
puts “Pool size: #poolpool.size”
|
281
|
+
puts “Available connections: #poolpool.available”
|
282
|
+
puts “Active connections: #poolpool.in_use”</p>
|
283
|
+
|
284
|
+
<h1 id="graceful-shutdown">Graceful shutdown</h1>
|
285
|
+
<p>DWH.shutdown(‘analytics_pool’)</p>
|
286
|
+
|
287
|
+
<h1 id="shutdown-all-pools">Shutdown all pools</h1>
|
288
|
+
<p>DWH.shutdown_all
|
289
|
+
```</p>
|
290
|
+
|
291
|
+
<h2 id="database-capabilities-detection">Database Capabilities Detection</h2>
|
292
|
+
|
293
|
+
<h3 id="checking-capabilities">Checking Capabilities</h3>
|
294
|
+
|
295
|
+
<p><code>ruby
|
296
|
+
# Check what features are supported
|
297
|
+
if adapter.supports_window_functions?
|
298
|
+
query = "SELECT name, ROW_NUMBER() OVER (ORDER BY created_at) FROM users"
|
299
|
+
results = adapter.execute(query)
|
300
|
+
end
|
301
|
+
</code></p>
|
302
|
+
|
303
|
+
<h3 id="available-capability-checks">Available Capability Checks</h3>
|
304
|
+
|
305
|
+
<ul>
|
306
|
+
<li><code>supports_table_join?</code> - Basic JOIN support</li>
|
307
|
+
<li><code>supports_full_join?</code> - FULL OUTER JOIN support</li>
|
308
|
+
<li><code>supports_cross_join?</code> - CROSS JOIN support</li>
|
309
|
+
<li><code>supports_sub_queries?</code> - Subquery support</li>
|
310
|
+
<li><code>supports_common_table_expressions?</code> - CTE support</li>
|
311
|
+
<li><code>supports_temp_tables?</code> - Temporary table support</li>
|
312
|
+
<li><code>supports_window_functions?</code> - Window function support</li>
|
313
|
+
<li><code>supports_array_functions?</code> - Array operation support</li>
|
314
|
+
</ul>
|
315
|
+
|
316
|
+
<h2 id="performance-optimization">Performance Optimization</h2>
|
317
|
+
|
318
|
+
<h3 id="query-timeouts">Query Timeouts</h3>
|
319
|
+
|
320
|
+
<p>```ruby
|
321
|
+
# Set query timeouts per adapter
|
322
|
+
postgres = DWH.create(:postgres, {
|
323
|
+
host: ‘localhost’,
|
324
|
+
database: ‘mydb’,
|
325
|
+
username: ‘user’,
|
326
|
+
query_timeout: 1800 # 30 minutes
|
327
|
+
})</p>
|
328
|
+
|
329
|
+
<h1 id="for-long-running-analytical-queries">For long-running analytical queries</h1>
|
330
|
+
<p>druid = DWH.create(:druid, {
|
331
|
+
host: ‘localhost’,
|
332
|
+
port: 8080,
|
333
|
+
protocol: ‘http’,
|
334
|
+
query_timeout: 3600 # 1 hour
|
335
|
+
})
|
336
|
+
```</p>
|
337
|
+
|
338
|
+
<h3 id="result-format-optimization">Result Format Optimization</h3>
|
339
|
+
|
340
|
+
<p><code>ruby
|
341
|
+
# Choose appropriate result format for your use case
|
342
|
+
arrays = adapter.execute(sql, format: :array) # Fastest, least memory
|
343
|
+
objects = adapter.execute(sql, format: :object) # Hash access, more memory
|
344
|
+
csv = adapter.execute(sql, format: :csv) # String format
|
345
|
+
native = adapter.execute(sql, format: :native) # Database's native format
|
346
|
+
</code></p>
|
347
|
+
|
348
|
+
<h3 id="streaming-for-large-results">Streaming for Large Results</h3>
|
349
|
+
|
350
|
+
<p>```ruby
|
351
|
+
# Use streaming for large result sets
|
352
|
+
def export_large_table(adapter, table_name, output_file)
|
353
|
+
query = “SELECT * FROM #table_name”</p>
|
354
|
+
|
355
|
+
<p>File.open(output_file, ‘w’) do |file|
|
356
|
+
adapter.execute_stream(query, file)
|
357
|
+
end
|
358
|
+
end</p>
|
359
|
+
|
360
|
+
<h1 id="chunk-processing-for-memory-efficiency">Chunk processing for memory efficiency</h1>
|
361
|
+
<p>def process_large_dataset(adapter, query)
|
362
|
+
adapter.stream(query) do |chunk|
|
363
|
+
# Process each chunk immediately
|
364
|
+
# Avoids loading entire result set into memory
|
365
|
+
chunk.each { |row| process_row(row) }
|
366
|
+
end
|
367
|
+
end
|
368
|
+
```</p>
|
369
|
+
|
370
|
+
<h2 id="error-handling-and-debugging">Error Handling and Debugging</h2>
|
371
|
+
|
372
|
+
<h3 id="comprehensive-error-handling">Comprehensive Error Handling</h3>
|
373
|
+
|
374
|
+
<p><code>ruby
|
375
|
+
begin
|
376
|
+
results = adapter.execute("SELECT * FROM table")
|
377
|
+
rescue DWH::ExecutionError => e
|
378
|
+
# Query execution failed
|
379
|
+
puts "Query failed: #{e.message}"
|
380
|
+
puts "SQL: #{e.sql}" if e.respond_to?(:sql)
|
381
|
+
rescue DWH::ConnectionError => e
|
382
|
+
# Connection issues
|
383
|
+
puts "Connection failed: #{e.message}"
|
384
|
+
# Implement retry logic
|
385
|
+
rescue DWH::ConfigError => e
|
386
|
+
# Configuration problems
|
387
|
+
puts "Configuration error: #{e.message}"
|
388
|
+
rescue DWH::UnsupportedCapability => e
|
389
|
+
# Attempted unsupported operation
|
390
|
+
puts "Feature not supported: #{e.message}"
|
391
|
+
end
|
392
|
+
</code></p>
|
393
|
+
|
394
|
+
<h2 id="custom-settings-and-overrides">Custom Settings and Overrides</h2>
|
395
|
+
|
396
|
+
<h3 id="runtime-settings-modification">Runtime Settings Modification</h3>
|
397
|
+
|
398
|
+
<p>```ruby
|
399
|
+
# Create adapter with custom settings
|
400
|
+
adapter = DWH.create(:postgres, {
|
401
|
+
host: ‘localhost’,
|
402
|
+
database: ‘mydb’,
|
403
|
+
username: ‘user’,
|
404
|
+
settings: {
|
405
|
+
quote: ‘<code>@exp</code>’, # Use backticks instead of double quotes
|
406
|
+
supports_window_functions: false, # Force disable window functions
|
407
|
+
temp_table_type: ‘cte’ # Prefer CTEs over subqueries
|
408
|
+
}
|
409
|
+
})</p>
|
410
|
+
|
411
|
+
<h1 id="modify-settings-at-runtime">Modify settings at runtime</h1>
|
412
|
+
<p>adapter.alter_settings({
|
413
|
+
supports_full_join: false, # Disable FULL JOINs
|
414
|
+
final_pass_measure_join_type: ‘inner’ # Use INNER JOINs
|
415
|
+
})</p>
|
416
|
+
|
417
|
+
<h1 id="reset-to-original-settings">Reset to original settings</h1>
|
418
|
+
<p>adapter.reset_settings
|
419
|
+
```</p>
|
420
|
+
|
421
|
+
<h3 id="custom-function-mappings">Custom Function Mappings</h3>
|
422
|
+
|
423
|
+
<p><code>ruby
|
424
|
+
# Override specific function translations
|
425
|
+
adapter = DWH.create(:postgres, {
|
426
|
+
host: 'localhost',
|
427
|
+
database: 'mydb',
|
428
|
+
username: 'user',
|
429
|
+
settings: {
|
430
|
+
truncate_date: "DATE_TRUNC('@unit', @exp)", # Custom date truncation
|
431
|
+
cast: "@exp::@type", # PostgreSQL-style casting
|
432
|
+
null_if: "CASE WHEN @exp = @target THEN NULL ELSE @exp END" # Custom NULLIF
|
433
|
+
}
|
434
|
+
})
|
435
|
+
</code></p>
|
436
|
+
</div></div>
|
437
|
+
|
438
|
+
<div id="footer">
|
439
|
+
Generated on Fri Aug 22 08:31:21 2025 by
|
440
|
+
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
441
|
+
0.9.37 (ruby-3.4.4).
|
442
|
+
</div>
|
443
|
+
|
444
|
+
</div>
|
445
|
+
</body>
|
446
|
+
</html>
|
data/docs/file_list.html
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html >
|
3
|
+
<head>
|
4
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
5
|
+
<meta charset="utf-8" />
|
6
|
+
|
7
|
+
<link rel="stylesheet" href="css/full_list.css" type="text/css" media="screen" />
|
8
|
+
|
9
|
+
<link rel="stylesheet" href="css/common.css" type="text/css" media="screen" />
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
14
|
+
|
15
|
+
<script type="text/javascript" charset="utf-8" src="js/full_list.js"></script>
|
16
|
+
|
17
|
+
|
18
|
+
<title>File List</title>
|
19
|
+
<base id="base_target" target="_parent" />
|
20
|
+
</head>
|
21
|
+
<body>
|
22
|
+
<div id="content">
|
23
|
+
<div class="fixed_header">
|
24
|
+
<h1 id="full_list_header">File List</h1>
|
25
|
+
<div id="full_list_nav">
|
26
|
+
|
27
|
+
<span><a target="_self" href="class_list.html">
|
28
|
+
Classes
|
29
|
+
</a></span>
|
30
|
+
|
31
|
+
<span><a target="_self" href="method_list.html">
|
32
|
+
Methods
|
33
|
+
</a></span>
|
34
|
+
|
35
|
+
<span><a target="_self" href="file_list.html">
|
36
|
+
Files
|
37
|
+
</a></span>
|
38
|
+
|
39
|
+
</div>
|
40
|
+
|
41
|
+
<div id="search">
|
42
|
+
<label for="search-class">Search:</label>
|
43
|
+
<input id="search-class" type="text" />
|
44
|
+
</div>
|
45
|
+
</div>
|
46
|
+
|
47
|
+
<ul id="full_list" class="file">
|
48
|
+
|
49
|
+
|
50
|
+
<li id="object_README" class="odd">
|
51
|
+
<div class="item"><span class="object_link"><a href="index.html" title="README">README</a></span></div>
|
52
|
+
</li>
|
53
|
+
|
54
|
+
|
55
|
+
<li id="object_adapters" class="even">
|
56
|
+
<div class="item"><span class="object_link"><a href="file.adapters.html" title="Adapter Configuration">Adapter Configuration</a></span></div>
|
57
|
+
</li>
|
58
|
+
|
59
|
+
|
60
|
+
<li id="object_creating-adapters" class="odd">
|
61
|
+
<div class="item"><span class="object_link"><a href="file.creating-adapters.html" title="Creating Custom Adapters">Creating Custom Adapters</a></span></div>
|
62
|
+
</li>
|
63
|
+
|
64
|
+
|
65
|
+
<li id="object_getting-started" class="even">
|
66
|
+
<div class="item"><span class="object_link"><a href="file.getting-started.html" title="Getting Started">Getting Started</a></span></div>
|
67
|
+
</li>
|
68
|
+
|
69
|
+
|
70
|
+
<li id="object_usage" class="odd">
|
71
|
+
<div class="item"><span class="object_link"><a href="file.usage.html" title="Advanced Usage">Advanced Usage</a></span></div>
|
72
|
+
</li>
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
</ul>
|
77
|
+
</div>
|
78
|
+
</body>
|
79
|
+
</html>
|
data/docs/frames.html
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta charset="utf-8">
|
5
|
+
<title>Documentation by YARD 0.9.37</title>
|
6
|
+
</head>
|
7
|
+
<script type="text/javascript">
|
8
|
+
var mainUrl = 'index.html';
|
9
|
+
try {
|
10
|
+
var match = decodeURIComponent(window.location.hash).match(/^#!(.+)/);
|
11
|
+
var name = match ? match[1] : mainUrl;
|
12
|
+
var url = new URL(name, location.href);
|
13
|
+
window.top.location.replace(url.origin === location.origin ? name : mainUrl);
|
14
|
+
} catch (e) {
|
15
|
+
window.top.location.replace(mainUrl);
|
16
|
+
}
|
17
|
+
</script>
|
18
|
+
<noscript>
|
19
|
+
<h1>Oops!</h1>
|
20
|
+
<h2>YARD requires JavaScript!</h2>
|
21
|
+
</noscript>
|
22
|
+
</html>
|