Skip to content

Commit 6bd1d00

Browse files
committed
generate rum--1.0--1.1.sql
1 parent 6ed9d49 commit 6bd1d00

File tree

4 files changed

+212
-645
lines changed

4 files changed

+212
-645
lines changed

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ REGRESS = rum rum_hash ruminv timestamp orderby orderby_hash altorder \
1919
macaddr inet cidr text varchar char bytea bit varbit \
2020
numeric
2121

22-
EXTRA_CLEAN += rum--1.1.sql
22+
EXTRA_CLEAN += rum--1.1.sql rum--1.0--1.1.sql
2323

2424
LDFLAGS_SL += $(filter -lm, $(LIBS))
2525

@@ -43,6 +43,8 @@ all: rum--1.1.sql
4343
rum--1.1.sql: rum--1.0.sql rum--1.0--1.1.sql
4444
cat rum--1.0.sql rum--1.0--1.1.sql > rum--1.1.sql
4545

46+
rum--1.0--1.1.sql: Makefile gen_rum_sql.pl
47+
perl gen_rum_sql.pl > rum--1.0--1.1.sql
4648

4749
install: installincludes
4850

gen_rum_sql.pl

Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
use strict;
2+
use warnings;
3+
4+
my $func_base_template=<<EOT;
5+
CREATE FUNCTION rum_extract_value_TYPEIDENT(TYPENAME, internal)
6+
RETURNS internal
7+
AS 'MODULE_PATHNAME'
8+
LANGUAGE C STRICT IMMUTABLE;
9+
10+
CREATE FUNCTION rum_compare_prefix_TYPEIDENT(TYPENAME, TYPENAME, int2, internal)
11+
RETURNS int4
12+
AS 'MODULE_PATHNAME'
13+
LANGUAGE C STRICT IMMUTABLE;
14+
15+
CREATE FUNCTION rum_extract_query_TYPEIDENT(TYPENAME, internal, int2, internal, internal)
16+
RETURNS internal
17+
AS 'MODULE_PATHNAME'
18+
LANGUAGE C STRICT IMMUTABLE;
19+
20+
EOT
21+
22+
my $opclass_base_template=<<EOT;
23+
24+
CREATE OPERATOR CLASS TYPEIDENT_ops
25+
DEFAULT FOR TYPE TYPENAME USING rum
26+
AS
27+
OPERATOR 1 < (TYPECMPTYPE, TYPECMPTYPE),
28+
OPERATOR 2 <=(TYPECMPTYPE, TYPECMPTYPE),
29+
OPERATOR 3 = (TYPECMPTYPE, TYPECMPTYPE),
30+
OPERATOR 4 >=(TYPECMPTYPE, TYPECMPTYPE),
31+
OPERATOR 5 > (TYPECMPTYPE, TYPECMPTYPE),
32+
FUNCTION 1 TYPECMPFUNC(TYPECMPTYPE,TYPECMPTYPE),
33+
FUNCTION 2 rum_extract_value_TYPESUBIDENT(TYPESUBNAME, internal),
34+
FUNCTION 3 rum_extract_query_TYPESUBIDENT(TYPESUBNAME, internal, int2, internal, internal),
35+
FUNCTION 4 rum_btree_consistent(internal,smallint,internal,int,internal,internal,internal,internal),
36+
FUNCTION 5 rum_compare_prefix_TYPESUBIDENT(TYPESUBNAME,TYPESUBNAME,int2, internal),
37+
STORAGE TYPENAME;
38+
39+
EOT
40+
41+
my @opinfo = map {
42+
$_->{TYPEIDENT} = $_->{TYPENAME} if ! exists $_->{TYPEIDENT};
43+
$_->{TYPECMPTYPE} = $_->{TYPENAME} if !exists $_->{TYPECMPTYPE};
44+
$_->{TYPESUBNAME} = $_->{TYPENAME} if !exists $_->{TYPESUBNAME};
45+
$_->{TYPESUBIDENT}= $_->{TYPEIDENT} if ! exists $_->{TYPESUBIDENT};
46+
$_
47+
} (
48+
{
49+
TYPENAME => 'int2',
50+
TYPECMPFUNC => 'btint2cmp',
51+
func_tmpl => \$func_base_template,
52+
opclass_tmpl=> \$opclass_base_template,
53+
},
54+
{
55+
TYPENAME => 'int4',
56+
TYPECMPFUNC => 'btint4cmp',
57+
func_tmpl => \$func_base_template,
58+
opclass_tmpl=> \$opclass_base_template,
59+
},
60+
{
61+
TYPENAME => 'int8',
62+
TYPECMPFUNC => 'btint8cmp',
63+
func_tmpl => \$func_base_template,
64+
opclass_tmpl=> \$opclass_base_template,
65+
},
66+
{
67+
TYPENAME => 'float4',
68+
TYPECMPFUNC => 'btfloat4cmp',
69+
func_tmpl => \$func_base_template,
70+
opclass_tmpl=> \$opclass_base_template,
71+
},
72+
{
73+
TYPENAME => 'float8',
74+
TYPECMPFUNC => 'btfloat8cmp',
75+
func_tmpl => \$func_base_template,
76+
opclass_tmpl=> \$opclass_base_template,
77+
},
78+
{
79+
TYPENAME => 'money',
80+
TYPECMPFUNC => 'cash_cmp',
81+
func_tmpl => \$func_base_template,
82+
opclass_tmpl=> \$opclass_base_template,
83+
},
84+
{
85+
TYPENAME => 'oid',
86+
TYPECMPFUNC => 'btoidcmp',
87+
func_tmpl => \$func_base_template,
88+
opclass_tmpl=> \$opclass_base_template,
89+
},
90+
{
91+
TYPENAME => 'time',
92+
TYPECMPFUNC => 'time_cmp',
93+
func_tmpl => \$func_base_template,
94+
opclass_tmpl=> \$opclass_base_template,
95+
},
96+
{
97+
TYPENAME => 'timetz',
98+
TYPECMPFUNC => 'timetz_cmp',
99+
func_tmpl => \$func_base_template,
100+
opclass_tmpl=> \$opclass_base_template,
101+
},
102+
{
103+
TYPENAME => 'date',
104+
TYPECMPFUNC => 'date_cmp',
105+
func_tmpl => \$func_base_template,
106+
opclass_tmpl=> \$opclass_base_template,
107+
},
108+
{
109+
TYPENAME => 'interval',
110+
TYPECMPFUNC => 'interval_cmp',
111+
func_tmpl => \$func_base_template,
112+
opclass_tmpl=> \$opclass_base_template,
113+
},
114+
{
115+
TYPENAME => 'macaddr',
116+
TYPECMPFUNC => 'macaddr_cmp',
117+
func_tmpl => \$func_base_template,
118+
opclass_tmpl=> \$opclass_base_template,
119+
},
120+
{
121+
TYPENAME => 'inet',
122+
TYPECMPFUNC => 'network_cmp',
123+
func_tmpl => \$func_base_template,
124+
opclass_tmpl=> \$opclass_base_template,
125+
},
126+
{
127+
TYPENAME => 'cidr',
128+
TYPECMPFUNC => 'network_cmp',
129+
TYPECMPTYPE => 'inet',
130+
func_tmpl => \$func_base_template,
131+
opclass_tmpl=> \$opclass_base_template,
132+
},
133+
{
134+
TYPENAME => 'text',
135+
TYPECMPFUNC => 'bttextcmp',
136+
func_tmpl => \$func_base_template,
137+
opclass_tmpl=> \$opclass_base_template,
138+
},
139+
{
140+
TYPENAME => 'varchar',
141+
TYPECMPFUNC => 'bttextcmp',
142+
TYPECMPTYPE => 'text',
143+
TYPESUBIDENT=> 'text',
144+
TYPESUBNAME => 'text',
145+
opclass_tmpl=> \$opclass_base_template,
146+
},
147+
{
148+
TYPENAME => '"char"',
149+
TYPEIDENT => 'char',
150+
TYPECMPFUNC => 'btcharcmp',
151+
func_tmpl => \$func_base_template,
152+
opclass_tmpl=> \$opclass_base_template,
153+
},
154+
{
155+
TYPENAME => 'bytea',
156+
TYPECMPFUNC => 'byteacmp',
157+
func_tmpl => \$func_base_template,
158+
opclass_tmpl=> \$opclass_base_template,
159+
},
160+
{
161+
TYPENAME => 'bit',
162+
TYPECMPFUNC => 'bitcmp',
163+
func_tmpl => \$func_base_template,
164+
opclass_tmpl=> \$opclass_base_template,
165+
},
166+
{
167+
TYPENAME => 'varbit',
168+
TYPECMPFUNC => 'varbitcmp',
169+
func_tmpl => \$func_base_template,
170+
opclass_tmpl=> \$opclass_base_template,
171+
},
172+
{
173+
TYPENAME => 'numeric',
174+
TYPECMPFUNC => 'rum_numeric_cmp',
175+
func_tmpl => \$func_base_template,
176+
opclass_tmpl=> \$opclass_base_template,
177+
preamble => <<EOT
178+
CREATE FUNCTION rum_numeric_cmp(numeric, numeric)
179+
RETURNS int4
180+
AS 'MODULE_PATHNAME'
181+
LANGUAGE C STRICT IMMUTABLE;
182+
183+
EOT
184+
},
185+
);
186+
187+
foreach my $t (@opinfo)
188+
{
189+
print "/*--------------------$t->{TYPENAME}-----------------------*/\n\n";
190+
191+
print $t->{preamble} if exists $t->{preamble};
192+
193+
for my $v (qw(func_tmpl opclass_tmpl))
194+
{
195+
next if !exists $t->{$v};
196+
197+
my $x = ${$t->{$v}};
198+
199+
for my $k (grep {uc($_) eq $_} keys %$t)
200+
{
201+
$x=~s/$k/$t->{$k}/g;
202+
}
203+
204+
print $x;
205+
}
206+
}

0 commit comments

Comments
 (0)