Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit301aa78

Browse files
committed
add tests for generate_range_bounds()
1 parenteafc6df commit301aa78

File tree

6 files changed

+69
-25
lines changed

6 files changed

+69
-25
lines changed

‎Makefile

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,7 @@ DATA = pg_pathman--1.0--1.1.sql \
2424

2525
PGFILEDESC = "pg_pathman - partitioning tool"
2626

27-
REGRESS = pathman_basic\
28-
pathman_only\
29-
pathman_cte\
30-
pathman_bgw\
31-
pathman_inserts\
32-
pathman_updates\
33-
pathman_domains\
34-
pathman_interval\
35-
pathman_callbacks\
36-
pathman_foreign_keys\
37-
pathman_permissions\
38-
pathman_rowmarks\
39-
pathman_runtime_nodes\
40-
pathman_utility_stmt\
41-
pathman_column_type\
42-
pathman_calamity
27+
REGRESS = pathman_calamity
4328

4429
EXTRA_REGRESS_OPTS=--temp-config=$(top_srcdir)/$(subdir)/conf.add
4530

‎expected/pathman_calamity.out

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,43 @@ SELECT drop_range_partition_expand_next(NULL) IS NULL;
396396
t
397397
(1 row)
398398

399+
/* check function generate_range_bounds() */
400+
SELECT generate_range_bounds(NULL, 100, 10) IS NULL;
401+
?column?
402+
----------
403+
t
404+
(1 row)
405+
406+
SELECT generate_range_bounds(0, NULL::INT4, 10) IS NULL;
407+
?column?
408+
----------
409+
t
410+
(1 row)
411+
412+
SELECT generate_range_bounds(0, 100, NULL) IS NULL;
413+
?column?
414+
----------
415+
t
416+
(1 row)
417+
418+
SELECT generate_range_bounds('a'::TEXT, 'test'::TEXT, 10);/* not ok */
419+
ERROR: cannot find operator +(text, text)
420+
SELECT generate_range_bounds('a'::TEXT, '1 mon'::INTERVAL, 10);/* not ok */
421+
ERROR: cannot find operator +(text, interval)
422+
SELECT generate_range_bounds(0::NUMERIC, 1::NUMERIC, 10);/* OK */
423+
generate_range_bounds
424+
--------------------------
425+
{0,1,2,3,4,5,6,7,8,9,10}
426+
(1 row)
427+
428+
SELECT generate_range_bounds('1-jan-2017'::DATE,
429+
'1 day'::INTERVAL,
430+
4);/* OK */
431+
generate_range_bounds
432+
----------------------------------------------------------
433+
{01-01-2017,01-02-2017,01-03-2017,01-04-2017,01-05-2017}
434+
(1 row)
435+
399436
/* check invoke_on_partition_created_callback() */
400437
CREATE FUNCTION calamity.dummy_cb(arg jsonb) RETURNS void AS $$
401438
begin

‎range.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,11 +1168,11 @@ CREATE OR REPLACE FUNCTION @extschema@.generate_range_bounds(
11681168
p_intervalINTERVAL,
11691169
p_countINTEGER)
11701170
RETURNS ANYARRAYAS'pg_pathman','generate_range_bounds_pl'
1171-
LANGUAGE C;
1171+
LANGUAGE C STRICT;
11721172

11731173
CREATEOR REPLACE FUNCTION @extschema@.generate_range_bounds(
11741174
p_startANYELEMENT,
11751175
p_intervalANYELEMENT,
11761176
p_countINTEGER)
11771177
RETURNS ANYARRAYAS'pg_pathman','generate_range_bounds_pl'
1178-
LANGUAGE C;
1178+
LANGUAGE C STRICT;

‎sql/pathman_calamity.sql

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ SELECT set_interval('calamity.part_test', 'abc'::text);/* not ok */
8989
SELECT drop_partitions('calamity.part_test', true);
9090
DELETEFROMcalamity.part_test;
9191

92-
9392
/* check function build_hash_condition()*/
9493
SELECT build_hash_condition('int4','val',10,1);
9594
SELECT build_hash_condition('text','val',10,1);
@@ -154,6 +153,17 @@ SELECT stop_concurrent_part_task(1::regclass);
154153
SELECT drop_range_partition_expand_next('pg_class');
155154
SELECT drop_range_partition_expand_next(NULL) ISNULL;
156155

156+
/* check function generate_range_bounds()*/
157+
SELECT generate_range_bounds(NULL,100,10) ISNULL;
158+
SELECT generate_range_bounds(0,NULL::INT4,10) ISNULL;
159+
SELECT generate_range_bounds(0,100,NULL) ISNULL;
160+
SELECT generate_range_bounds('a'::TEXT,'test'::TEXT,10);/* not ok*/
161+
SELECT generate_range_bounds('a'::TEXT,'1 mon'::INTERVAL,10);/* not ok*/
162+
SELECT generate_range_bounds(0::NUMERIC,1::NUMERIC,10);/* OK*/
163+
SELECT generate_range_bounds('1-jan-2017'::DATE,
164+
'1 day'::INTERVAL,
165+
4);/* OK*/
166+
157167

158168
/* check invoke_on_partition_created_callback()*/
159169
CREATEFUNCTIONcalamity.dummy_cb(arg jsonb) RETURNS voidAS $$

‎src/pl_range_funcs.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,17 @@ create_range_partitions_internal(PG_FUNCTION_ARGS)
246246
Datum
247247
check_range_available_pl(PG_FUNCTION_ARGS)
248248
{
249-
Oidparent_relid=PG_GETARG_OID(0);
249+
Oidparent_relid;
250250
Boundstart,
251251
end;
252252
Oidvalue_type=get_fn_expr_argtype(fcinfo->flinfo,1);
253253

254+
if (PG_ARGISNULL(0))
255+
ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
256+
errmsg("'parent_relid' should not be NULL")));
257+
258+
parent_relid=PG_GETARG_OID(0);
259+
254260
start=PG_ARGISNULL(1) ?
255261
MakeBoundInf(MINUS_INFINITY) :
256262
MakeBound(PG_GETARG_DATUM(1));
@@ -293,8 +299,13 @@ generate_range_bounds_pl(PG_FUNCTION_ARGS)
293299
charelemalign;
294300
Datum*datums;
295301

302+
Assert(!PG_ARGISNULL(0));
303+
Assert(!PG_ARGISNULL(1));
304+
Assert(!PG_ARGISNULL(2));
305+
296306
if (count<1)
297-
elog(ERROR,"'p_count' must be greater than zero");
307+
ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
308+
errmsg("'p_count' must be greater than zero")));
298309

299310
/* We must provide count+1 bounds */
300311
count+=1;

‎src/utils.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,10 @@ get_binary_operator(char *oprname, Oid arg1, Oid arg2)
257257
arg1,arg2, true,-1);
258258

259259
if (!op)
260-
elog(ERROR,"Cannot find operator \"%s\"(%u, %u)",oprname,arg1,arg2);
260+
elog(ERROR,"cannot find operator %s(%s, %s)",
261+
oprname,
262+
format_type_be(arg1),
263+
format_type_be(arg2));
261264

262265
returnop;
263266
}
@@ -319,9 +322,7 @@ extract_op_func_and_ret_type(char *opname,
319322

320323
/* Get "move bound operator" descriptor */
321324
op=get_binary_operator(opname,type1,type2);
322-
if (!op)
323-
elog(ERROR,"missing %s operator for types %s and %s",
324-
opname,format_type_be(type1),format_type_be(type2));
325+
Assert(op);
325326

326327
*op_func=oprfuncid(op);
327328
*op_ret_type= ((Form_pg_operator)GETSTRUCT(op))->oprresult;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp