dwh 0.6.2 → 0.6.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6bfaf112cbfb915c0adc5d504514b6a634b666a97305e55ecbe89b71367fc784
4
- data.tar.gz: 4e997a453cbff2e904b174b6872944c1a22612e69774a79fde835ea680f5f307
3
+ metadata.gz: 191a0e0f57c43aaeeb61a50ba9b353c45fa15579f955e6d5b0fa433c623b138b
4
+ data.tar.gz: 0cee05d93db5bdfd0d574984fb086f0fadb868845e8a8cf089088604c3fd68d3
5
5
  SHA512:
6
- metadata.gz: 649345383a23acece4522e778866b3c9f8ab7c4d5de76101bbca63a701ef71367336e58e7636831e350e58afbee6b59cbd95009a46ddabbb287d46b86129ebf8
7
- data.tar.gz: 8be2519f016034f9796eeeec261ee9ba0ae56b2cbfe040260c02e817a5fe6ff74baba9b8de05d5aecf6543594ac4471dae9ee5202a169f2d95accec1f57186c6
6
+ metadata.gz: cc463c3498206c11bf0fd44c7ee2916ad673265749b0dd56e762db2963b67c51958ef11ab7dcd93a8174aac7facd0833532a01f3ae7dbe25101b9bc8cc9c11be
7
+ data.tar.gz: 7b16c0b020923077a47db38c44307d8ac25c4cc0d4fd2d398a272f9bb6a0e657793692aa5eb900b3145d37ce47591d6c11fd7886fad78897f03f4180b16d9e93
data/CHANGELOG.md CHANGED
@@ -1,5 +1,35 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.6.6] - 2026-11-18
4
+
5
+ ### Fixed
6
+
7
+ - **Snowflake**: `tables` and `metadata` honour the configured `schema`. Both consulted only an explicit qualifier, so with none they scanned every schema in the database: a listing repeated each table once per schema, and `metadata` returned every column once per schema, building a table with each column duplicated. An explicit qualifier still wins, and with no schema configured the lookups stay unscoped as before.
8
+ - **Snowflake**: `metadata` matches the table name without regard to case. It forced the name to upper, so a table created quoted in lower case came back with no columns at all rather than an error.
9
+ - **Snowflake**: the PAT rejection hints cover all three ways a token is refused, not just a missing network policy. A blocked address is told to add itself to the policy's `ALLOWED_IP_LIST` (and that setting it replaces the list); an invalid token is told it may be deleted or expired, **or** that `account_identifier` may name a different account than the one the token was created on — Snowflake reports both of those identically.
10
+
11
+ ## [0.6.5] - 2026-11-17
12
+
13
+ ### Fixed
14
+
15
+ - `quote_identifier` was left out of 0.6.4: it was added to the pull request after that one had already merged, so it never reached main. The app calls it for every inner-pass alias, so on 0.6.4 any query answered in more than one pass raises `undefined method 'quote_identifier'` on every warehouse. Shipping it is what makes strata#465 work.
16
+
17
+ ## [0.6.4] - 2026-11-11
18
+
19
+ ### Fixed
20
+
21
+ - Column names are reported in the case the warehouse stores them, instead of being downcased. Generated SQL quotes a physical column name, and a quoted name is matched exactly, so a Snowflake column stored as `I_CATEGORY` could not be queried as `"i_category"`. `Table#find_column` was already case insensitive, so lookups are unaffected.
22
+ - `quote_identifier` quotes an alias that will later be referenced unquoted, folding it to the case the warehouse folds unquoted names to (`identifier_case`, new in settings: `preserve` by default, `upper` for Snowflake). It is only for names a caller invents: a name the warehouse owns keeps its own case and goes through `quote` as before. Without this, an alias projected quoted in lower case could not be reached by an unquoted reference on Snowflake.
23
+ - `table?` matches a table name without regard to case. An unquoted name is case insensitive to every supported warehouse, but the case one reports is not the case the user wrote — Snowflake lists `ITEM` for a table queried as `item` — so an existing table was reported missing. The identical `table?` overrides in the Postgres and SQL Server adapters, which also dropped their qualifiers, are removed in favour of the base implementation.
24
+ - **Snowflake**: a PAT rejection for a missing network policy now explains the requirement, gives the shape of the two statements that satisfy it, and names key-pair auth as the alternative. Snowflake's own message is only "Network policy is required.", and it is the first thing a new trial account hits.
25
+ - **Databricks**: `host` accepts a workspace URL with or without the `https://` prefix and a trailing slash. A pasted browser URL previously reached Faraday as `https://https://...` and failed in `getaddrinfo` against a host called "https".
26
+
27
+ ## [0.6.3] - 2026-09-30
28
+
29
+ ### Fixed
30
+
31
+ - **BigQuery**: `close` no longer calls `close` on the Google client, which has none. Pool shutdown (for example when a datasource config changes) raised `undefined method close`.
32
+
3
33
  ## [0.6.2] - 2026-09-30
4
34
 
5
35
  ### Added
data/README.md CHANGED
@@ -153,4 +153,4 @@ This project is available as open source under the terms of the MIT License.
153
153
 
154
154
  ## Version
155
155
 
156
- Current version: 0.6.2
156
+ Current version: 0.6.3
@@ -70,6 +70,12 @@ module DWH
70
70
  raise ConfigError, "Failed to connect to BigQuery: #{e.message}"
71
71
  end
72
72
 
73
+ # (see Adapter#close) The Google client holds no persistent connection,
74
+ # so there is nothing to close; just drop the reference.
75
+ def close
76
+ @connection = nil
77
+ end
78
+
73
79
  # (see Adapter#test_connection)
74
80
  def test_connection(raise_exception: false)
75
81
  raise ConnectionError, "Dataset '#{config[:dataset]}' not found" unless connection.dataset(config[:dataset])
@@ -44,6 +44,11 @@ module DWH
44
44
 
45
45
  def initialize(config)
46
46
  super
47
+ # Workspace URLs get copied out of the browser, so host arrives as
48
+ # "https://dbc-xxx.cloud.databricks.com" as often as the bare hostname. Left alone it
49
+ # reaches Faraday as https://https://... and dies in getaddrinfo on "https", which
50
+ # tells the user nothing. Every URL here is built as https://#{host}.
51
+ @config[:host] = @config[:host].to_s.sub(%r{\A\w+://}, '').chomp('/')
47
52
  validate_oauth_config
48
53
  end
49
54
 
@@ -140,7 +145,7 @@ module DWH
140
145
 
141
146
  columns.each do |col|
142
147
  db_table << Column.new(
143
- name: col[0]&.downcase,
148
+ name: col[0],
144
149
  data_type: col[1]&.downcase,
145
150
  precision: col[2],
146
151
  scale: col[3],
@@ -86,11 +86,6 @@ module DWH
86
86
  result.values.flatten
87
87
  end
88
88
 
89
- # (see Adapter#table?)
90
- def table?(table_name)
91
- tables.include?(table_name)
92
- end
93
-
94
89
  # (see Adapter#stats)
95
90
  def stats(table, date_column: nil, **qualifiers)
96
91
  table_name = qualifiers[:schema] ? "#{qualifiers[:schema]}.#{table}" : table
@@ -209,6 +209,7 @@ module DWH
209
209
  # @return [Array<String>] list of table names
210
210
  def tables(**qualifiers)
211
211
  catalog, schema = qualifiers.values_at(:catalog, :schema)
212
+ schema ||= config[:schema]
212
213
 
213
214
  db = catalog || config[:database]
214
215
  sql = "SELECT table_name FROM #{db}.information_schema.tables"
@@ -225,21 +226,24 @@ module DWH
225
226
  # (see Adapter#tables)
226
227
  def metadata(table, **qualifiers)
227
228
  catalog, schema = qualifiers.values_at(:catalog, :schema)
228
- db_table = Table.new(table, schema: schema, catalog: catalog)
229
+ db_table = Table.new(table, schema: schema || config[:schema], catalog: catalog)
229
230
  db = db_table.catalog || config[:database]
230
231
  sql = <<~SQL
231
232
  SELECT column_name, data_type, numeric_precision, numeric_scale, character_maximum_length
232
233
  FROM #{db}.information_schema.columns
233
234
  SQL
234
235
 
235
- conditions = ["table_name = '#{db_table.physical_name.upcase}'"]
236
+ # Compared without case: an unquoted name is folded to upper, but a table
237
+ # created quoted keeps the case it was made with, and forcing upper here
238
+ # returned no columns at all rather than an error.
239
+ conditions = ["UPPER(table_name) = UPPER('#{db_table.physical_name}')"]
236
240
  conditions << "table_schema = '#{db_table.schema.upcase}'" if db_table.schema
237
241
 
238
242
  columns = execute("#{sql} WHERE #{conditions.join(' AND ')}")
239
243
 
240
244
  columns.each do |col|
241
245
  db_table << Column.new(
242
- name: col[0]&.downcase,
246
+ name: col[0],
243
247
  data_type: col[1]&.downcase,
244
248
  precision: col[2],
245
249
  scale: col[3],
@@ -388,7 +392,34 @@ module DWH
388
392
  response.body
389
393
  end
390
394
  message = error_info.is_a?(Hash) ? error_info['message'] : error_info
391
- raise ExecutionError, "Snowflake query failed: #{message}"
395
+ raise ExecutionError, "Snowflake query failed: #{message}#{pat_auth_hint(message)}"
396
+ end
397
+ end
398
+
399
+ # Snowflake's three PAT rejections all name something other than the cause: a
400
+ # missing policy, the caller's address, or the token. Each needs a different
401
+ # fix, and the last one is routinely a stale account_identifier rather than a
402
+ # bad token, so say which is which.
403
+ def pat_auth_hint(message)
404
+ return '' unless config[:auth_mode].to_s == 'pat'
405
+
406
+ case message.to_s
407
+ when /network policy is required/i
408
+ ' — Snowflake only accepts programmatic access tokens from users covered by a network ' \
409
+ 'policy. Create one allowing the IPs this client connects from and attach it to the ' \
410
+ 'user (CREATE NETWORK POLICY ... ALLOWED_IP_LIST=(...); ALTER USER ... SET NETWORK_POLICY=...), ' \
411
+ 'or switch this datasource to key-pair auth (auth_mode: kp).'
412
+ when /not allowed to access/i
413
+ ' — the address in this message is not in the network policy covering this user. Add it ' \
414
+ 'to the policy (ALTER NETWORK POLICY ... SET ALLOWED_IP_LIST=(...), which replaces the ' \
415
+ 'list, so repeat the addresses you still need), or switch to key-pair auth ' \
416
+ '(auth_mode: kp), which needs no policy.'
417
+ when /token is invalid/i
418
+ ' — the token may have been deleted or expired, or account_identifier ' \
419
+ "(#{config[:account_identifier]}) may name a different account than the one the token " \
420
+ 'was created on. Snowflake reports both the same way.'
421
+ else
422
+ ''
392
423
  end
393
424
  end
394
425
 
@@ -109,11 +109,6 @@ module DWH
109
109
  use(config[:database])
110
110
  end
111
111
 
112
- # (see Adapter#table?)
113
- def table?(table_name)
114
- tables.include?(table_name)
115
- end
116
-
117
112
  # (see Adapter#stats)
118
113
  def stats(table, date_column: nil, **qualifiers)
119
114
  change_current_database(qualifiers[:catalog])
data/lib/dwh/adapters.rb CHANGED
@@ -234,13 +234,16 @@ module DWH
234
234
 
235
235
  # Check if table exists in remote db.
236
236
  #
237
+ # Matched without case: an unquoted name is case insensitive to every
238
+ # supported warehouse, but Snowflake lists ITEM for a table written item.
239
+ #
237
240
  # @option qualifiers [String] :catalog optional catalog or equivalent name space.
238
241
  # will be ignored if the adapter doesn't support
239
242
  # @option qualifiers [String] :schema optional schema to scope to.
240
243
  # will be ignored if the adapter doesn't support
241
244
  # @return [Boolean]
242
245
  def table?(table, **qualifiers)
243
- tables(**qualifiers).include?(table)
246
+ tables(**qualifiers).any? { |t| t.casecmp?(table) }
244
247
  end
245
248
 
246
249
  # Get the schema structure of a given a given table_name.
data/lib/dwh/column.rb CHANGED
@@ -3,8 +3,10 @@ module DWH
3
3
  class Column
4
4
  attr_reader :schema_type, :data_type, :name, :precision, :scale, :max_char_length
5
5
 
6
+ # Name is kept as the warehouse reported it: a quoted identifier is matched
7
+ # exactly, so Snowflake's I_CATEGORY cannot be queried as "i_category".
6
8
  def initialize(name:, data_type:, precision: 0, scale: 0, schema_type: nil, max_char_length: nil)
7
- @name = name.downcase
9
+ @name = name
8
10
  @precision = precision.is_a?(String) ? precision.to_i : precision
9
11
  @scale = scale.is_a?(String) ? scale.to_i : scale
10
12
  @data_type = data_type&.downcase
data/lib/dwh/functions.rb CHANGED
@@ -54,6 +54,17 @@ module DWH
54
54
  gsk(:quote).sub(/@exp/i, exp)
55
55
  end
56
56
 
57
+ # Quotes an alias that will later be referenced UNQUOTED, folding it to the
58
+ # case this warehouse folds unquoted names to so both sides resolve alike.
59
+ # Only for names we invent; a name the warehouse owns must keep its own case.
60
+ def quote_identifier(exp)
61
+ case gsk(:identifier_case).to_s
62
+ when 'upper' then quote(exp.to_s.upcase)
63
+ when 'lower' then quote(exp.to_s.downcase)
64
+ else quote(exp)
65
+ end
66
+ end
67
+
57
68
  # Applies adapter specific string literal translation around the given
58
69
  # expression. The expression is usually a string value.
59
70
  #
@@ -1,6 +1,9 @@
1
1
 
2
2
  # quotes and string lit
3
3
  quote: "\"@exp\""
4
+ # Case this warehouse folds an UNQUOTED identifier to: preserve, upper or lower.
5
+ # Only consulted for names Strata invents, never for names the warehouse owns.
6
+ identifier_case: preserve
4
7
  string_literal: "'@exp'"
5
8
 
6
9
  # Date Literal Formats
@@ -1,4 +1,6 @@
1
1
 
2
+ identifier_case: upper
3
+
2
4
  # Date Literal Formats
3
5
  date_format: "%Y-%m-%d"
4
6
  date_time_format: "%Y-%m-%d %H:%M:%S"
data/lib/dwh/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DWH
4
- VERSION = '0.6.2'
4
+ VERSION = '0.6.6'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dwh
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 0.6.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ajo Abraham