pg_query 6.0.0 → 6.2.1
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 +4 -4
- data/CHANGELOG.md +50 -1
- data/README.md +1 -1
- data/Rakefile +5 -4
- data/ext/pg_query/ext_symbols_freebsd_with_ruby_abi_version.sym +2 -0
- data/ext/pg_query/ext_symbols_openbsd.sym +1 -0
- data/ext/pg_query/ext_symbols_openbsd_with_ruby_abi_version.sym +2 -0
- data/ext/pg_query/ext_symbols_with_ruby_abi_version.sym +2 -0
- data/ext/pg_query/extconf.rb +21 -7
- data/ext/pg_query/include/pg_query.h +32 -2
- data/ext/pg_query/include/postgres/access/amapi.h +5 -1
- data/ext/pg_query/include/postgres/access/genam.h +9 -0
- data/ext/pg_query/include/postgres/access/slru.h +4 -7
- data/ext/pg_query/include/postgres/access/tableam.h +13 -5
- data/ext/pg_query/include/postgres/access/transam.h +43 -0
- data/ext/pg_query/include/postgres/access/xlog.h +1 -0
- data/ext/pg_query/include/postgres/access/xlogdefs.h +2 -1
- data/ext/pg_query/include/postgres/c.h +1 -1
- data/ext/pg_query/include/postgres/catalog/objectaddress.h +4 -0
- data/ext/pg_query/include/postgres/commands/defrem.h +1 -1
- data/ext/pg_query/include/postgres/commands/event_trigger.h +6 -0
- data/ext/pg_query/include/postgres/commands/trigger.h +18 -0
- data/ext/pg_query/include/postgres/common/hashfn_unstable.h +6 -52
- data/ext/pg_query/include/postgres/datatype/timestamp.h +1 -1
- data/ext/pg_query/include/postgres/executor/execdesc.h +1 -1
- data/ext/pg_query/include/postgres/executor/executor.h +4 -0
- data/ext/pg_query/include/postgres/libpq/libpq-be.h +6 -3
- data/ext/pg_query/include/postgres/mb/pg_wchar.h +3 -0
- data/ext/pg_query/include/postgres/miscadmin.h +12 -3
- data/ext/pg_query/include/postgres/nodes/execnodes.h +9 -8
- data/ext/pg_query/include/postgres/nodes/pathnodes.h +3 -1
- data/ext/pg_query/include/postgres/nodes/pg_list.h +1 -1
- data/ext/pg_query/include/postgres/nodes/primnodes.h +9 -5
- data/ext/pg_query/include/postgres/parser/parse_coerce.h +3 -0
- data/ext/pg_query/include/postgres/pg_config.h +32 -23
- data/ext/pg_query/include/postgres/pg_config_manual.h +2 -0
- data/ext/pg_query/include/postgres/port/atomics/generic-gcc.h +10 -2
- data/ext/pg_query/include/postgres/port/pg_iovec.h +11 -5
- data/ext/pg_query/include/postgres/port/win32_port.h +0 -2
- data/ext/pg_query/include/postgres/port.h +32 -1
- data/ext/pg_query/include/postgres/replication/reorderbuffer.h +38 -27
- data/ext/pg_query/include/postgres/replication/slot.h +7 -1
- data/ext/pg_query/include/postgres/storage/lockdefs.h +2 -0
- data/ext/pg_query/include/postgres/storage/proc.h +13 -16
- data/ext/pg_query/include/postgres/storage/smgr.h +5 -2
- data/ext/pg_query/include/postgres/utils/catcache.h +1 -0
- data/ext/pg_query/include/postgres/utils/elog.h +1 -0
- data/ext/pg_query/include/postgres/utils/guc.h +1 -1
- data/ext/pg_query/include/postgres/utils/guc_hooks.h +0 -2
- data/ext/pg_query/include/postgres/utils/pg_locale.h +5 -0
- data/ext/pg_query/include/postgres/utils/pgstat_internal.h +19 -0
- data/ext/pg_query/include/postgres/utils/portal.h +1 -1
- data/ext/pg_query/include/postgres/utils/syscache.h +5 -0
- data/ext/pg_query/include/postgres_deparse.h +34 -0
- data/ext/pg_query/include/protobuf/pg_query.pb-c.h +673 -516
- data/ext/pg_query/pg_query.pb-c.c +488 -0
- data/ext/pg_query/pg_query_deparse.c +148 -15
- data/ext/pg_query/pg_query_internal.h +9 -8
- data/ext/pg_query/pg_query_is_utility_stmt.c +70 -0
- data/ext/pg_query/pg_query_normalize.c +3 -0
- data/ext/pg_query/pg_query_raw_tree_walker_supports.c +117 -0
- data/ext/pg_query/pg_query_ruby.c +150 -0
- data/ext/pg_query/pg_query_summary.c +941 -0
- data/ext/pg_query/pg_query_summary.h +109 -0
- data/ext/pg_query/pg_query_summary_statement_type.c +797 -0
- data/ext/pg_query/pg_query_summary_truncate.c +530 -0
- data/ext/pg_query/postgres_deparse.c +4531 -3879
- data/ext/pg_query/src_backend_catalog_namespace.c +29 -0
- data/ext/pg_query/src_backend_nodes_bitmapset.c +84 -1
- data/ext/pg_query/src_backend_nodes_list.c +60 -1
- data/ext/pg_query/src_backend_parser_gram.c +740 -733
- data/ext/pg_query/src_backend_utils_activity_pgstat_database.c +2 -2
- data/ext/pg_query/src_backend_utils_error_elog.c +11 -0
- data/ext/pg_query/src_backend_utils_mb_mbutils.c +43 -4
- data/ext/pg_query/src_backend_utils_mmgr_alignedalloc.c +22 -7
- data/ext/pg_query/src_backend_utils_mmgr_aset.c +3 -3
- data/ext/pg_query/src_backend_utils_mmgr_bump.c +1 -1
- data/ext/pg_query/src_common_stringinfo.c +20 -0
- data/ext/pg_query/src_common_wchar.c +93 -7
- data/ext/pg_query/src_port_snprintf.c +14 -17
- data/lib/pg_query/deparse.rb +29 -8
- data/lib/pg_query/fingerprint.rb +3 -5
- data/lib/pg_query/param_refs.rb +1 -1
- data/lib/pg_query/parse.rb +24 -7
- data/lib/pg_query/parse_error.rb +1 -0
- data/lib/pg_query/pg_query_pb.rb +8 -24
- data/lib/pg_query/scan.rb +1 -0
- data/lib/pg_query/split.rb +20 -0
- data/lib/pg_query/treewalker.rb +11 -13
- data/lib/pg_query/truncate.rb +17 -19
- data/lib/pg_query/version.rb +1 -1
- data/lib/pg_query.rb +1 -0
- metadata +23 -81
- data/ext/pg_query/postgres_deparse.h +0 -9
- /data/ext/pg_query/{pg_query_ruby.sym → ext_symbols.sym} +0 -0
- /data/ext/pg_query/{pg_query_ruby_freebsd.sym → ext_symbols_freebsd.sym} +0 -0
data/lib/pg_query/scan.rb
CHANGED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
module PgQuery
|
|
2
|
+
class SplitError < ArgumentError
|
|
3
|
+
attr_reader :location
|
|
4
|
+
|
|
5
|
+
def initialize(message, source_file, source_line, location)
|
|
6
|
+
super("#{message} (#{source_file}:#{source_line})")
|
|
7
|
+
@location = location
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def self.split_with_parser(query)
|
|
12
|
+
result, stderr = _raw_split_with_parser(query)
|
|
13
|
+
|
|
14
|
+
raise SplitError.new(stderr, 'stderr', '', '') unless stderr.empty?
|
|
15
|
+
|
|
16
|
+
result.map do |location, len|
|
|
17
|
+
query[location..location + len]
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
data/lib/pg_query/treewalker.rb
CHANGED
|
@@ -11,13 +11,18 @@ module PgQuery
|
|
|
11
11
|
# multiple parser runs, assuming the same pg_query release and no modifications to the parse tree.
|
|
12
12
|
def walk!(&block)
|
|
13
13
|
if block.arity == 1
|
|
14
|
-
treewalker!(@tree)
|
|
15
|
-
yield(node)
|
|
16
|
-
end
|
|
14
|
+
treewalker!(@tree, &block)
|
|
17
15
|
else
|
|
18
|
-
treewalker_with_location!(@tree
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
treewalker_with_location!(@tree, &block)
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# Traverses the tree to find the node at the given location and yields
|
|
21
|
+
# its parent node, the parent field, and the node itself.
|
|
22
|
+
def find_tree_location(tree, searched_location)
|
|
23
|
+
treewalker_with_location! tree do |parent_node, parent_field, node, location|
|
|
24
|
+
next unless location == searched_location
|
|
25
|
+
yield(parent_node, parent_field, node)
|
|
21
26
|
end
|
|
22
27
|
end
|
|
23
28
|
|
|
@@ -77,12 +82,5 @@ module PgQuery
|
|
|
77
82
|
break if nodes.empty?
|
|
78
83
|
end
|
|
79
84
|
end
|
|
80
|
-
|
|
81
|
-
def find_tree_location(tree, searched_location)
|
|
82
|
-
treewalker_with_location! tree do |parent_node, parent_field, node, location|
|
|
83
|
-
next unless location == searched_location
|
|
84
|
-
yield(parent_node, parent_field, node)
|
|
85
|
-
end
|
|
86
|
-
end
|
|
87
85
|
end
|
|
88
86
|
end
|
data/lib/pg_query/truncate.rb
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
|
|
2
1
|
module PgQuery
|
|
3
2
|
class ParserResult
|
|
4
|
-
PossibleTruncation = Struct.new(:location, :node_type, :
|
|
3
|
+
PossibleTruncation = Struct.new(:location, :node_type, :len, :is_array)
|
|
5
4
|
|
|
6
5
|
# Truncates the query string to be below the specified length, first trying to
|
|
7
6
|
# omit less important parts of the query, and only then cutting off the end.
|
|
@@ -14,11 +13,11 @@ module PgQuery
|
|
|
14
13
|
truncations = find_possible_truncations
|
|
15
14
|
|
|
16
15
|
# Truncate the deepest possible truncation that is the longest first
|
|
17
|
-
truncations.sort_by! { |t| [-t.location.size, -t.
|
|
16
|
+
truncations.sort_by! { |t| [-t.location.size, -t.len] }
|
|
18
17
|
|
|
19
18
|
tree = dup_tree
|
|
20
19
|
truncations.each do |truncation|
|
|
21
|
-
next if truncation.
|
|
20
|
+
next if truncation.len < 3
|
|
22
21
|
|
|
23
22
|
find_tree_location(tree, truncation.location) do |node, _k|
|
|
24
23
|
dummy_column_ref = PgQuery::Node.new(column_ref: PgQuery::ColumnRef.new(fields: [PgQuery::Node.new(string: PgQuery::String.new(sval: '…'))]))
|
|
@@ -64,30 +63,29 @@ module PgQuery
|
|
|
64
63
|
case k
|
|
65
64
|
when :target_list
|
|
66
65
|
next unless node.is_a?(PgQuery::SelectStmt) || node.is_a?(PgQuery::UpdateStmt) || node.is_a?(PgQuery::OnConflictClause)
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
truncations << PossibleTruncation.new(location, :target_list,
|
|
66
|
+
len = if node.is_a?(PgQuery::SelectStmt)
|
|
67
|
+
select_target_list_len(v)
|
|
68
|
+
else # UpdateStmt / OnConflictClause
|
|
69
|
+
update_target_list_len(v)
|
|
70
|
+
end
|
|
71
|
+
truncations << PossibleTruncation.new(location, :target_list, len, true)
|
|
73
72
|
when :where_clause
|
|
74
73
|
next unless node.is_a?(PgQuery::SelectStmt) || node.is_a?(PgQuery::UpdateStmt) || node.is_a?(PgQuery::DeleteStmt) ||
|
|
75
74
|
node.is_a?(PgQuery::CopyStmt) || node.is_a?(PgQuery::IndexStmt) || node.is_a?(PgQuery::RuleStmt) ||
|
|
76
75
|
node.is_a?(PgQuery::InferClause) || node.is_a?(PgQuery::OnConflictClause)
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
truncations << PossibleTruncation.new(location, :where_clause, length, false)
|
|
76
|
+
len = PgQuery.deparse_expr(v).size
|
|
77
|
+
truncations << PossibleTruncation.new(location, :where_clause, len, false)
|
|
80
78
|
when :values_lists
|
|
81
|
-
|
|
82
|
-
truncations << PossibleTruncation.new(location, :values_lists,
|
|
79
|
+
len = select_values_lists_len(v)
|
|
80
|
+
truncations << PossibleTruncation.new(location, :values_lists, len, false)
|
|
83
81
|
when :ctequery
|
|
84
82
|
next unless node.is_a?(PgQuery::CommonTableExpr)
|
|
85
|
-
|
|
86
|
-
truncations << PossibleTruncation.new(location, :ctequery,
|
|
83
|
+
len = PgQuery.deparse_stmt(v[v.node.to_s]).size
|
|
84
|
+
truncations << PossibleTruncation.new(location, :ctequery, len, false)
|
|
87
85
|
when :cols
|
|
88
86
|
next unless node.is_a?(PgQuery::InsertStmt)
|
|
89
|
-
|
|
90
|
-
truncations << PossibleTruncation.new(location, :cols,
|
|
87
|
+
len = cols_len(v)
|
|
88
|
+
truncations << PossibleTruncation.new(location, :cols, len, true)
|
|
91
89
|
end
|
|
92
90
|
end
|
|
93
91
|
|
data/lib/pg_query/version.rb
CHANGED
data/lib/pg_query.rb
CHANGED
metadata
CHANGED
|
@@ -1,85 +1,15 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: pg_query
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 6.
|
|
4
|
+
version: 6.2.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Lukas Fittl
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2026-01-21 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
|
-
- !ruby/object:Gem::Dependency
|
|
14
|
-
name: rake-compiler
|
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
|
16
|
-
requirements:
|
|
17
|
-
- - "~>"
|
|
18
|
-
- !ruby/object:Gem::Version
|
|
19
|
-
version: '0'
|
|
20
|
-
type: :development
|
|
21
|
-
prerelease: false
|
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
-
requirements:
|
|
24
|
-
- - "~>"
|
|
25
|
-
- !ruby/object:Gem::Version
|
|
26
|
-
version: '0'
|
|
27
|
-
- !ruby/object:Gem::Dependency
|
|
28
|
-
name: rspec
|
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
|
30
|
-
requirements:
|
|
31
|
-
- - "~>"
|
|
32
|
-
- !ruby/object:Gem::Version
|
|
33
|
-
version: '3.0'
|
|
34
|
-
type: :development
|
|
35
|
-
prerelease: false
|
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
-
requirements:
|
|
38
|
-
- - "~>"
|
|
39
|
-
- !ruby/object:Gem::Version
|
|
40
|
-
version: '3.0'
|
|
41
|
-
- !ruby/object:Gem::Dependency
|
|
42
|
-
name: rubocop
|
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
|
44
|
-
requirements:
|
|
45
|
-
- - '='
|
|
46
|
-
- !ruby/object:Gem::Version
|
|
47
|
-
version: 0.49.1
|
|
48
|
-
type: :development
|
|
49
|
-
prerelease: false
|
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
-
requirements:
|
|
52
|
-
- - '='
|
|
53
|
-
- !ruby/object:Gem::Version
|
|
54
|
-
version: 0.49.1
|
|
55
|
-
- !ruby/object:Gem::Dependency
|
|
56
|
-
name: rubocop-rspec
|
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
|
58
|
-
requirements:
|
|
59
|
-
- - '='
|
|
60
|
-
- !ruby/object:Gem::Version
|
|
61
|
-
version: 1.15.1
|
|
62
|
-
type: :development
|
|
63
|
-
prerelease: false
|
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
-
requirements:
|
|
66
|
-
- - '='
|
|
67
|
-
- !ruby/object:Gem::Version
|
|
68
|
-
version: 1.15.1
|
|
69
|
-
- !ruby/object:Gem::Dependency
|
|
70
|
-
name: simplecov
|
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
|
72
|
-
requirements:
|
|
73
|
-
- - "~>"
|
|
74
|
-
- !ruby/object:Gem::Version
|
|
75
|
-
version: '0'
|
|
76
|
-
type: :development
|
|
77
|
-
prerelease: false
|
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
-
requirements:
|
|
80
|
-
- - "~>"
|
|
81
|
-
- !ruby/object:Gem::Version
|
|
82
|
-
version: '0'
|
|
83
13
|
- !ruby/object:Gem::Dependency
|
|
84
14
|
name: google-protobuf
|
|
85
15
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -107,6 +37,12 @@ files:
|
|
|
107
37
|
- LICENSE
|
|
108
38
|
- README.md
|
|
109
39
|
- Rakefile
|
|
40
|
+
- ext/pg_query/ext_symbols.sym
|
|
41
|
+
- ext/pg_query/ext_symbols_freebsd.sym
|
|
42
|
+
- ext/pg_query/ext_symbols_freebsd_with_ruby_abi_version.sym
|
|
43
|
+
- ext/pg_query/ext_symbols_openbsd.sym
|
|
44
|
+
- ext/pg_query/ext_symbols_openbsd_with_ruby_abi_version.sym
|
|
45
|
+
- ext/pg_query/ext_symbols_with_ruby_abi_version.sym
|
|
110
46
|
- ext/pg_query/extconf.rb
|
|
111
47
|
- ext/pg_query/include/pg_query.h
|
|
112
48
|
- ext/pg_query/include/pg_query_enum_defs.c
|
|
@@ -537,6 +473,7 @@ files:
|
|
|
537
473
|
- ext/pg_query/include/postgres/utils/wait_event_types.h
|
|
538
474
|
- ext/pg_query/include/postgres/utils/xml.h
|
|
539
475
|
- ext/pg_query/include/postgres/varatt.h
|
|
476
|
+
- ext/pg_query/include/postgres_deparse.h
|
|
540
477
|
- ext/pg_query/include/protobuf-c.h
|
|
541
478
|
- ext/pg_query/include/protobuf-c/protobuf-c.h
|
|
542
479
|
- ext/pg_query/include/protobuf/pg_query.pb-c.h
|
|
@@ -549,6 +486,7 @@ files:
|
|
|
549
486
|
- ext/pg_query/pg_query_fingerprint.c
|
|
550
487
|
- ext/pg_query/pg_query_fingerprint.h
|
|
551
488
|
- ext/pg_query/pg_query_internal.h
|
|
489
|
+
- ext/pg_query/pg_query_is_utility_stmt.c
|
|
552
490
|
- ext/pg_query/pg_query_json_plpgsql.c
|
|
553
491
|
- ext/pg_query/pg_query_json_plpgsql.h
|
|
554
492
|
- ext/pg_query/pg_query_normalize.c
|
|
@@ -557,15 +495,17 @@ files:
|
|
|
557
495
|
- ext/pg_query/pg_query_outfuncs_protobuf.c
|
|
558
496
|
- ext/pg_query/pg_query_parse.c
|
|
559
497
|
- ext/pg_query/pg_query_parse_plpgsql.c
|
|
498
|
+
- ext/pg_query/pg_query_raw_tree_walker_supports.c
|
|
560
499
|
- ext/pg_query/pg_query_readfuncs.h
|
|
561
500
|
- ext/pg_query/pg_query_readfuncs_protobuf.c
|
|
562
501
|
- ext/pg_query/pg_query_ruby.c
|
|
563
|
-
- ext/pg_query/pg_query_ruby.sym
|
|
564
|
-
- ext/pg_query/pg_query_ruby_freebsd.sym
|
|
565
502
|
- ext/pg_query/pg_query_scan.c
|
|
566
503
|
- ext/pg_query/pg_query_split.c
|
|
504
|
+
- ext/pg_query/pg_query_summary.c
|
|
505
|
+
- ext/pg_query/pg_query_summary.h
|
|
506
|
+
- ext/pg_query/pg_query_summary_statement_type.c
|
|
507
|
+
- ext/pg_query/pg_query_summary_truncate.c
|
|
567
508
|
- ext/pg_query/postgres_deparse.c
|
|
568
|
-
- ext/pg_query/postgres_deparse.h
|
|
569
509
|
- ext/pg_query/protobuf-c.c
|
|
570
510
|
- ext/pg_query/src_backend_catalog_namespace.c
|
|
571
511
|
- ext/pg_query/src_backend_catalog_pg_proc.c
|
|
@@ -635,14 +575,16 @@ files:
|
|
|
635
575
|
- lib/pg_query/parse_error.rb
|
|
636
576
|
- lib/pg_query/pg_query_pb.rb
|
|
637
577
|
- lib/pg_query/scan.rb
|
|
578
|
+
- lib/pg_query/split.rb
|
|
638
579
|
- lib/pg_query/treewalker.rb
|
|
639
580
|
- lib/pg_query/truncate.rb
|
|
640
581
|
- lib/pg_query/version.rb
|
|
641
582
|
homepage: https://github.com/pganalyze/pg_query
|
|
642
583
|
licenses:
|
|
643
584
|
- BSD-3-Clause
|
|
644
|
-
metadata:
|
|
645
|
-
|
|
585
|
+
metadata:
|
|
586
|
+
rubygems_mfa_required: 'true'
|
|
587
|
+
post_install_message:
|
|
646
588
|
rdoc_options:
|
|
647
589
|
- "--main"
|
|
648
590
|
- README.md
|
|
@@ -654,15 +596,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
654
596
|
requirements:
|
|
655
597
|
- - ">="
|
|
656
598
|
- !ruby/object:Gem::Version
|
|
657
|
-
version: '0'
|
|
599
|
+
version: '3.0'
|
|
658
600
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
659
601
|
requirements:
|
|
660
602
|
- - ">="
|
|
661
603
|
- !ruby/object:Gem::Version
|
|
662
604
|
version: '0'
|
|
663
605
|
requirements: []
|
|
664
|
-
rubygems_version: 3.
|
|
665
|
-
signing_key:
|
|
606
|
+
rubygems_version: 3.5.22
|
|
607
|
+
signing_key:
|
|
666
608
|
specification_version: 4
|
|
667
609
|
summary: PostgreSQL query parsing and normalization library
|
|
668
610
|
test_files: []
|
|
File without changes
|
|
File without changes
|