-
Notifications
You must be signed in to change notification settings - Fork 55
/
gen_rum_sql--1.1--1.2.pl
183 lines (153 loc) · 4.59 KB
/
gen_rum_sql--1.1--1.2.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
use strict;
use warnings;
my $func_distance_template=<<EOT;
CREATE FUNCTION rum_TYPEIDENT_key_distance(TYPENAME, TYPENAME, smallint)
RETURNS float8
AS 'MODULE_PATHNAME'
LANGUAGE C IMMUTABLE STRICT;
EOT
my $opclass_distance_template=<<EOT;
ALTER OPERATOR FAMILY rum_TYPEIDENT_ops USING rum ADD
FUNCTION 8 (TYPENAME,TYPENAME) rum_TYPEIDENT_key_distance(TYPENAME, TYPENAME, smallint);
EOT
my @opinfo = map {
$_->{TYPEIDENT} = $_->{TYPENAME} if !exists $_->{TYPEIDENT};
$_
} (
{
TYPENAME => 'int2',
func_tmpl => \$func_distance_template,
opclass_tmpl=> \$opclass_distance_template,
},
{
TYPENAME => 'int4',
func_tmpl => \$func_distance_template,
opclass_tmpl=> \$opclass_distance_template,
},
{
TYPENAME => 'int8',
func_tmpl => \$func_distance_template,
opclass_tmpl=> \$opclass_distance_template,
},
{
TYPENAME => 'float4',
func_tmpl => \$func_distance_template,
opclass_tmpl=> \$opclass_distance_template,
},
{
TYPENAME => 'float8',
func_tmpl => \$func_distance_template,
opclass_tmpl=> \$opclass_distance_template,
},
{
TYPENAME => 'money',
func_tmpl => \$func_distance_template,
opclass_tmpl=> \$opclass_distance_template,
},
{
TYPENAME => 'oid',
func_tmpl => \$func_distance_template,
opclass_tmpl=> \$opclass_distance_template,
},
{
TYPENAME => 'timestamp',
func_tmpl => \$func_distance_template,
opclass_tmpl=> \$opclass_distance_template,
},
{
TYPENAME => 'timestamptz',
func_tmpl => \$func_distance_template,
opclass_tmpl=> \$opclass_distance_template,
},
);
##############Generate!!!
print <<EOT;
/*
* RUM version 1.2
*/
/*--------------------anyarray-----------------------*/
CREATE FUNCTION rum_anyarray_config(internal)
RETURNS void
AS 'MODULE_PATHNAME'
LANGUAGE C IMMUTABLE STRICT;
CREATE FUNCTION rum_anyarray_similar(anyarray,anyarray)
RETURNS bool
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT STABLE;
CREATE OPERATOR % (
PROCEDURE = rum_anyarray_similar,
LEFTARG = anyarray,
RIGHTARG = anyarray,
COMMUTATOR = '%',
RESTRICT = contsel,
JOIN = contjoinsel
);
CREATE FUNCTION rum_anyarray_distance(anyarray,anyarray)
RETURNS float8
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT STABLE;
CREATE OPERATOR <=> (
PROCEDURE = rum_anyarray_distance,
LEFTARG = anyarray,
RIGHTARG = anyarray,
COMMUTATOR = '<=>'
);
CREATE FUNCTION rum_extract_anyarray(anyarray,internal,internal,internal,internal)
RETURNS internal
AS 'MODULE_PATHNAME'
LANGUAGE C IMMUTABLE STRICT;
CREATE FUNCTION rum_extract_anyarray_query(anyarray,internal,smallint,internal,internal,internal,internal)
RETURNS internal
AS 'MODULE_PATHNAME'
LANGUAGE C IMMUTABLE STRICT;
CREATE FUNCTION rum_anyarray_consistent(internal, smallint, anyarray, integer, internal, internal, internal, internal)
RETURNS bool
AS 'MODULE_PATHNAME'
LANGUAGE C IMMUTABLE STRICT;
CREATE FUNCTION rum_anyarray_ordering(internal,smallint,anyarray,int,internal,internal,internal,internal,internal)
RETURNS float8
AS 'MODULE_PATHNAME'
LANGUAGE C IMMUTABLE STRICT;
CREATE OPERATOR CLASS rum_anyarray_ops
DEFAULT FOR TYPE anyarray USING rum
AS
OPERATOR 1 && (anyarray, anyarray),
OPERATOR 2 @> (anyarray, anyarray),
OPERATOR 3 <@ (anyarray, anyarray),
OPERATOR 4 = (anyarray, anyarray),
OPERATOR 5 % (anyarray, anyarray),
OPERATOR 20 <=> (anyarray, anyarray) FOR ORDER BY pg_catalog.float_ops,
--dispatch function 1 for concrete type
FUNCTION 2 rum_extract_anyarray(anyarray,internal,internal,internal,internal),
FUNCTION 3 rum_extract_anyarray_query(anyarray,internal,smallint,internal,internal,internal,internal),
FUNCTION 4 rum_anyarray_consistent(internal,smallint,anyarray,integer,internal,internal,internal,internal),
FUNCTION 6 rum_anyarray_config(internal),
FUNCTION 8 rum_anyarray_ordering(internal,smallint,anyarray,int,internal,internal,internal,internal,internal),
STORAGE anyelement;
CREATE OPERATOR CLASS rum_anyarray_addon_ops
FOR TYPE anyarray USING rum
AS
OPERATOR 1 && (anyarray, anyarray),
OPERATOR 2 @> (anyarray, anyarray),
OPERATOR 3 <@ (anyarray, anyarray),
OPERATOR 4 = (anyarray, anyarray),
--dispatch function 1 for concrete type
FUNCTION 2 ginarrayextract(anyarray,internal,internal),
FUNCTION 3 ginqueryarrayextract(anyarray,internal,smallint,internal,internal,internal,internal),
FUNCTION 4 ginarrayconsistent(internal,smallint,anyarray,integer,internal,internal,internal,internal),
STORAGE anyelement;
EOT
foreach my $t (@opinfo)
{
print "/*--------------------$t->{TYPENAME}-----------------------*/\n\n";
for my $v (qw(func_tmpl opclass_tmpl))
{
next if !exists $t->{$v};
my $x = ${$t->{$v}};
for my $k (grep {uc($_) eq $_} keys %$t)
{
$x=~s/$k/$t->{$k}/g;
}
print $x;
}
}