pg_query 2.1.3 → 2.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a47580d95bf78de051c96a5a4b260c9cf829ff74461dcea5fc99637467b86435
4
- data.tar.gz: 8249f9d2c493f74cdafc99f69f8bb55e4f9504975f73cff2dfb504f5ae8987a8
3
+ metadata.gz: fe9be3677078ec8a4990a53c9e0aa74c21f2a66672fe3a0990b23c00a6da34af
4
+ data.tar.gz: 31e3bbcdfac0cd27a1553ac0f0d33f7cbd7e36ce8c5080f29a314da67adcc76a
5
5
  SHA512:
6
- metadata.gz: 76a1633e48ac2c784510ef12a68ca7f6e4c43f134aa7bf7d82725138f95cd89564787e9bc862e50545ce99ca442f936d86bae6882156d7c52cd7b4acd1414699
7
- data.tar.gz: 541bfbe7bc660ebbe34e79a54b2cfa1dee1bb59a8d9892113b8ea2ffe5fbda6734375c189ab5b62a98c280e6cf456327d89360fd0467d2b279b93bb504f67c19
6
+ metadata.gz: 7a8e0ef4b389446f952988903aa6b5772c6caabaea80d97e4f40affdf0830227285e60af0848a2786fcdab98232e96a5a75d3b5f73b24378b9ef67e9d24d9bf8
7
+ data.tar.gz: ffd90f7bdf9a155cb7a014eaf9c8bfbf06d0905e70bc5dadc739015c4d11695ead10ae1960e1bcee44e3d81d3c8a5b7d47b6705a32ef93daa8d909b328ee9602
data/CHANGELOG.md CHANGED
@@ -4,6 +4,14 @@
4
4
 
5
5
  * ...
6
6
 
7
+ ## 2.1.4 2022-09-19
8
+
9
+ * Truncate: Simplify VALUES(...) lists
10
+ * Truncate: Correctly handle UPDATE and ON CONFLICT target lists
11
+ * Support complex queries with deeply nested ASTs ([#238](https://github.com/pganalyze/pg_query/pull/238))
12
+ * Find table references inside type casts
13
+ * Find function calls referenced in expression indexes ([#249](https://github.com/pganalyze/pg_query/pull/249))
14
+ * Drop `Init_pg_query` from exported symbol map ([#256](https://github.com/pganalyze/pg_query/pull/256))
7
15
 
8
16
  ## 2.1.3 2022-01-28
9
17
 
@@ -11,7 +11,13 @@ $CFLAGS << " -fvisibility=hidden -O3 -Wall -fno-strict-aliasing -fwrapv -fstack-
11
11
 
12
12
  $INCFLAGS = "-I#{File.join(__dir__, 'include')} " + $INCFLAGS
13
13
 
14
- SYMFILE = File.join(__dir__, 'pg_query_ruby.sym')
14
+ SYMFILE =
15
+ if RUBY_PLATFORM =~ /freebsd/
16
+ File.join(__dir__, 'pg_query_ruby_freebsd.sym')
17
+ else
18
+ File.join(__dir__, 'pg_query_ruby.sym')
19
+ end
20
+
15
21
  if RUBY_PLATFORM =~ /darwin/
16
22
  $DLDFLAGS << " -Wl,-exported_symbols_list #{SYMFILE}" unless defined?(::Rubinius)
17
23
  else
@@ -1,2 +1 @@
1
1
  _Init_pg_query
2
- Init_pg_query
@@ -0,0 +1,2 @@
1
+ _Init_pg_query
2
+ Init_pg_query
@@ -50,6 +50,8 @@ module PgQuery
50
50
  condition_items << statement.update_stmt.where_clause if statement.update_stmt.where_clause
51
51
  when :delete_stmt
52
52
  condition_items << statement.delete_stmt.where_clause if statement.delete_stmt.where_clause
53
+ when :index_stmt
54
+ condition_items << statement.index_stmt.where_clause if statement.index_stmt.where_clause
53
55
  end
54
56
  end
55
57
 
@@ -3,7 +3,13 @@ module PgQuery
3
3
  result, stderr = parse_protobuf(query)
4
4
 
5
5
  begin
6
- result = PgQuery::ParseResult.decode(result)
6
+ result = if PgQuery::ParseResult.method(:decode).arity == 1
7
+ PgQuery::ParseResult.decode(result)
8
+ elsif PgQuery::ParseResult.method(:decode).arity == -1
9
+ PgQuery::ParseResult.decode(result, recursion_limit: 1_000)
10
+ else
11
+ raise ArgumentError, 'Unsupported protobuf Ruby API'
12
+ end
7
13
  rescue Google::Protobuf::ParseError => e
8
14
  raise PgQuery::ParseError.new(format('Failed to parse tree: %s', e.message), __FILE__, __LINE__, -1)
9
15
  end
@@ -180,6 +186,11 @@ module PgQuery
180
186
  statements << statement.view_stmt.query
181
187
  when :index_stmt
182
188
  from_clause_items << { item: PgQuery::Node.new(range_var: statement.index_stmt.relation), type: :ddl }
189
+ statement.index_stmt.index_params.each do |p|
190
+ next if p.index_elem.expr.nil?
191
+ subselect_items << p.index_elem.expr
192
+ end
193
+ subselect_items << statement.index_stmt.where_clause if statement.index_stmt.where_clause
183
194
  when :create_trig_stmt
184
195
  from_clause_items << { item: PgQuery::Node.new(range_var: statement.create_trig_stmt.relation), type: :ddl }
185
196
  when :rule_stmt
@@ -274,6 +285,8 @@ module PgQuery
274
285
  subselect_items.concat(next_item.case_expr.args.map { |arg| arg.case_when.expr })
275
286
  subselect_items.concat(next_item.case_expr.args.map { |arg| arg.case_when.result })
276
287
  subselect_items << next_item.case_expr.defresult
288
+ when :type_cast
289
+ subselect_items << next_item.type_cast.arg
277
290
  end
278
291
  end
279
292
 
@@ -32,6 +32,12 @@ module PgQuery
32
32
  )
33
33
  when :where_clause
34
34
  node.where_clause = dummy_column_ref
35
+ when :values_lists
36
+ node.values_lists.replace(
37
+ [
38
+ PgQuery::Node.new(list: PgQuery::List.new(items: [dummy_column_ref]))
39
+ ]
40
+ )
35
41
  when :ctequery
36
42
  node.ctequery = PgQuery::Node.new(select_stmt: PgQuery::SelectStmt.new(where_clause: dummy_column_ref, op: :SETOP_NONE))
37
43
  when :cols
@@ -58,7 +64,11 @@ module PgQuery
58
64
  case k
59
65
  when :target_list
60
66
  next unless node.is_a?(PgQuery::SelectStmt) || node.is_a?(PgQuery::UpdateStmt) || node.is_a?(PgQuery::OnConflictClause)
61
- length = PgQuery.deparse_stmt(PgQuery::SelectStmt.new(k => v.to_a, op: :SETOP_NONE)).size - 7 # 'SELECT '.size
67
+ length = if node.is_a?(PgQuery::SelectStmt)
68
+ select_target_list_len(v)
69
+ else # UpdateStmt / OnConflictClause
70
+ update_target_list_len(v)
71
+ end
62
72
  truncations << PossibleTruncation.new(location, :target_list, length, true)
63
73
  when :where_clause
64
74
  next unless node.is_a?(PgQuery::SelectStmt) || node.is_a?(PgQuery::UpdateStmt) || node.is_a?(PgQuery::DeleteStmt) ||
@@ -67,23 +77,59 @@ module PgQuery
67
77
 
68
78
  length = PgQuery.deparse_expr(v).size
69
79
  truncations << PossibleTruncation.new(location, :where_clause, length, false)
80
+ when :values_lists
81
+ length = select_values_lists_len(v)
82
+ truncations << PossibleTruncation.new(location, :values_lists, length, false)
70
83
  when :ctequery
71
84
  next unless node.is_a?(PgQuery::CommonTableExpr)
72
85
  length = PgQuery.deparse_stmt(v[v.node.to_s]).size
73
86
  truncations << PossibleTruncation.new(location, :ctequery, length, false)
74
87
  when :cols
75
88
  next unless node.is_a?(PgQuery::InsertStmt)
76
- length = PgQuery.deparse_stmt(
77
- PgQuery::InsertStmt.new(
78
- relation: PgQuery::RangeVar.new(relname: 'x', inh: true),
79
- cols: v.to_a
80
- )
81
- ).size - 31 # "INSERT INTO x () DEFAULT VALUES".size
89
+ length = cols_len(v)
82
90
  truncations << PossibleTruncation.new(location, :cols, length, true)
83
91
  end
84
92
  end
85
93
 
86
94
  truncations
87
95
  end
96
+
97
+ def select_target_list_len(target_list)
98
+ deparsed_len = PgQuery.deparse_stmt(
99
+ PgQuery::SelectStmt.new(
100
+ target_list: target_list.to_a, op: :SETOP_NONE
101
+ )
102
+ ).size
103
+ deparsed_len - 7 # 'SELECT '.size
104
+ end
105
+
106
+ def select_values_lists_len(values_lists)
107
+ deparsed_len = PgQuery.deparse_stmt(
108
+ PgQuery::SelectStmt.new(
109
+ values_lists: values_lists.to_a, op: :SETOP_NONE
110
+ )
111
+ ).size
112
+ deparsed_len - 7 # 'SELECT '.size
113
+ end
114
+
115
+ def update_target_list_len(target_list)
116
+ deparsed_len = PgQuery.deparse_stmt(
117
+ PgQuery::UpdateStmt.new(
118
+ target_list: target_list.to_a,
119
+ relation: PgQuery::RangeVar.new(relname: 'x', inh: true)
120
+ )
121
+ ).size
122
+ deparsed_len - 13 # 'UPDATE x SET '.size
123
+ end
124
+
125
+ def cols_len(cols)
126
+ deparsed_len = PgQuery.deparse_stmt(
127
+ PgQuery::InsertStmt.new(
128
+ relation: PgQuery::RangeVar.new(relname: 'x', inh: true),
129
+ cols: cols.to_a
130
+ )
131
+ ).size
132
+ deparsed_len - 31 # "INSERT INTO x () DEFAULT VALUES".size
133
+ end
88
134
  end
89
135
  end
@@ -1,3 +1,3 @@
1
1
  module PgQuery
2
- VERSION = '2.1.3'.freeze
2
+ VERSION = '2.1.4'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pg_query
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.3
4
+ version: 2.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lukas Fittl
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-29 00:00:00.000000000 Z
11
+ date: 2022-09-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler
@@ -484,6 +484,7 @@ files:
484
484
  - ext/pg_query/pg_query_readfuncs_protobuf.c
485
485
  - ext/pg_query/pg_query_ruby.c
486
486
  - ext/pg_query/pg_query_ruby.sym
487
+ - ext/pg_query/pg_query_ruby_freebsd.sym
487
488
  - ext/pg_query/pg_query_scan.c
488
489
  - ext/pg_query/pg_query_split.c
489
490
  - ext/pg_query/protobuf-c.c