From b031aef4715563b883f375d49e736176832670c1 Mon Sep 17 00:00:00 2001 From: Ashish Kumar Date: Mon, 19 Jul 2021 18:55:28 +0530 Subject: [PATCH 1/6] [vroom][tools] Added vroomdata for pgtap tests --- tools/testers/vroomdata.sql | 169 ++++++++++++++++++++++++++++++++++++ 1 file changed, 169 insertions(+) create mode 100644 tools/testers/vroomdata.sql diff --git a/tools/testers/vroomdata.sql b/tools/testers/vroomdata.sql new file mode 100644 index 0000000000..9c7d374e16 --- /dev/null +++ b/tools/testers/vroomdata.sql @@ -0,0 +1,169 @@ +DROP TABLE IF EXISTS public.vroom_time_windows; +DROP TABLE IF EXISTS public.vroom_jobs; +DROP TABLE IF EXISTS public.vroom_shipments; +DROP TABLE IF EXISTS public.vroom_breaks; +DROP TABLE IF EXISTS public.vroom_vehicles; +DROP TABLE IF EXISTS public.vroom_matrix; + +-- VROOM TWS TABLE CREATE start +CREATE TABLE public.vroom_time_windows ( + id BIGINT, + tw_open INTEGER, + tw_close INTEGER +); +-- VROOM TWS TABLE CREATE end + +-- VROOM TWS TABLE ADD DATA start +INSERT INTO public.vroom_time_windows ( + id, tw_open, tw_close) + VALUES +(1, 3625, 4375), +(2, 1250, 2000), +(3, 2725, 3475), +(4, 3525, 4275), +(5, 1025, 1775), +(6, 1625, 3650), +(7, 24925, 26700), +(8, 375, 1675), +(9, 4250, 5625), +(10, 15525, 17550), +(11, 20625, 21750), +(12, 6375, 8100), +(13, 8925, 10250), +(14, 13350, 15125), +(15, 18175, 19550), +(16, 250, 300), +(17, 250, 275), +(18, 0, 0), +(19, 250, 250); +-- VROOM TWS TABLE ADD DATA end + + +-- VROOM JOBS TABLE CREATE start +CREATE TABLE public.vroom_jobs ( + id BIGINT, + location_index BIGINT, + service INTEGER, + delivery BIGINT[], + pickup BIGINT[], + skills INTEGER[], + priority INTEGER, + time_windows_sql TEXT +); +-- VROOM JOBS TABLE CREATE end + +-- VROOM JOBS TABLE ADD DATA start +INSERT INTO public.vroom_jobs ( + id, location_index, service, delivery, pickup, skills, priority, time_windows_sql) + VALUES +(1, 1, 250, ARRAY[20], ARRAY[20], ARRAY[0], 0, $$SELECT * FROM vroom_time_windows WHERE id = 1$$), +(2, 2, 250, ARRAY[30], ARRAY[30], ARRAY[0], 0, $$SELECT * FROM vroom_time_windows WHERE id = 2$$), +(3, 3, 250, ARRAY[10], ARRAY[10], ARRAY[0], 0, $$SELECT * FROM vroom_time_windows WHERE id = 3$$), +(4, 3, 250, ARRAY[40], ARRAY[40], ARRAY[0], 0, $$SELECT * FROM vroom_time_windows WHERE id = 4$$), +(5, 4, 250, ARRAY[20], ARRAY[20], ARRAY[0], 0, $$SELECT * FROM vroom_time_windows WHERE id = 5$$); +-- VROOM JOBS TABLE ADD DATA end + + +-- VROOM SHIPMENTS TABLE CREATE start +CREATE TABLE public.vroom_shipments ( + p_id BIGINT, + p_location_index BIGINT, + p_service INTEGER, + p_time_windows_sql TEXT, + d_id BIGINT, + d_location_index BIGINT, + d_service INTEGER, + d_time_windows_sql TEXT, + amount BIGINT[], + skills INTEGER[], + priority INTEGER +); +-- VROOM SHIPMENTS TABLE CREATE end + +-- VROOM SHIPMENTS TABLE ADD DATA start +INSERT INTO public.vroom_shipments ( + p_id, p_location_index, p_service, p_time_windows_sql, + d_id, d_location_index, d_service, d_time_windows_sql, + amount, skills, priority) + VALUES +(6, 3, 2250, $$SELECT * FROM vroom_time_windows WHERE id = 6$$, + 7, 5, 2250, $$SELECT * FROM vroom_time_windows WHERE id = 7$$, + ARRAY[10], ARRAY[0], 0), +(8, 5, 2250, $$SELECT * FROM vroom_time_windows WHERE id = 8$$, + 9, 6, 2250, $$SELECT * FROM vroom_time_windows WHERE id = 9$$, + ARRAY[10], ARRAY[0], 0), +(10, 1, 2250, $$SELECT * FROM vroom_time_windows WHERE id = 10$$, + 11, 2, 2250, $$SELECT * FROM vroom_time_windows WHERE id = 11$$, + ARRAY[20], ARRAY[0], 0), +(12, 1, 2250, $$SELECT * FROM vroom_time_windows WHERE id = 12$$, + 13, 4, 2250, $$SELECT * FROM vroom_time_windows WHERE id = 13$$, + ARRAY[20], ARRAY[0], 0), +(14, 2, 2250, $$SELECT * FROM vroom_time_windows WHERE id = 14$$, + 15, 2, 2250, $$SELECT * FROM vroom_time_windows WHERE id = 15$$, + ARRAY[10], ARRAY[0], 0); +-- VROOM SHIPMENTS TABLE ADD DATA end + + +-- VROOM BREAKS TABLE CREATE start +CREATE TABLE public.vroom_breaks ( + id BIGINT, + time_windows_sql TEXT, + service INTEGER +); +-- VROOM BREAKS TABLE CREATE end + +-- VROOM BREAKS TABLE ADD DATA start +INSERT INTO public.vroom_breaks ( + id, time_windows_sql, service) + VALUES +(16, $$SELECT * FROM vroom_time_windows WHERE id = 16$$, 0), +(17, $$SELECT * FROM vroom_time_windows WHERE id = 17$$, 10), +(18, $$SELECT * FROM vroom_time_windows WHERE id = 18$$, 0), +(19, $$SELECT * FROM vroom_time_windows WHERE id = 19$$, 0); +-- VROOM BREAKS TABLE ADD DATA end + + +-- VROOM VEHICLES TABLE CREATE start +CREATE TABLE public.vroom_vehicles ( + id BIGINT, + start_index BIGINT, + end_index BIGINT, + capacity BIGINT[], + skills INTEGER[], + tw_open INTEGER, + tw_close INTEGER, + breaks_sql TEXT, + speed_factor FLOAT +); +-- VROOM VEHICLES TABLE CREATE end + +-- VROOM VEHICLES TABLE ADD DATA start +INSERT INTO public.vroom_vehicles ( + id, start_index, end_index, capacity, skills, + tw_open, tw_close, breaks_sql, speed_factor) + VALUES +(1, 1, 1, ARRAY[200], ARRAY[0], 0, 30900, $$SELECT * FROM vroom_breaks WHERE id = 16$$, 1.0), +(2, 1, 3, ARRAY[200], ARRAY[0], 100, 30900, $$SELECT * FROM vroom_breaks WHERE id = 17$$, 1.0), +(3, 1, 1, ARRAY[200], ARRAY[0], 0, 30900, $$SELECT * FROM vroom_breaks WHERE id = 18$$, 1.0), +(4, 3, 3, ARRAY[200], ARRAY[0], 0, 30900, $$SELECT * FROM vroom_breaks WHERE id = 19$$, 1.0); +-- VROOM VEHICLES TABLE ADD DATA end + +-- VROOM MATRIX TABLE CREATE start +CREATE TABLE public.vroom_matrix ( + start_vid BIGINT, + end_vid BIGINT, + agg_cost INTEGER +); +-- VROOM MATRIX TABLE CREATE end + +-- VROOM MATRIX TABLE ADD DATA start +INSERT INTO public.vroom_matrix ( + start_vid, end_vid, agg_cost) + VALUES +(1, 1, 0), (1, 2, 50), (1, 3, 90), (1, 4, 75), (1, 5, 106), (1, 6, 127), +(2, 1, 50), (2, 2, 0), (2, 3, 125), (2, 4, 90), (2, 5, 145), (2, 6, 127), +(3, 1, 90), (3, 2, 125), (3, 3, 0), (3, 4, 50), (3, 5, 25), (3, 6, 90), +(4, 1, 75), (4, 2, 90), (4, 3, 50), (4, 4, 0), (4, 5, 75), (4, 6, 55), +(5, 1, 106), (5, 2, 145), (5, 3, 25), (5, 4, 75), (5, 5, 0), (5, 6, 111), +(6, 1, 127), (6, 2, 127), (6, 3, 90), (6, 4, 55), (6, 5, 111), (6, 6, 0); +-- VROOM MATRIX TABLE ADD DATA end From 75a502445bc73a8e24b13affc28238c81e2951a6 Mon Sep 17 00:00:00 2001 From: Ashish Kumar Date: Thu, 22 Jul 2021 09:04:20 +0530 Subject: [PATCH 2/6] [vroom][pgtap] Added types check --- pgtap/vroom/types_check.sql | 88 +++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 pgtap/vroom/types_check.sql diff --git a/pgtap/vroom/types_check.sql b/pgtap/vroom/types_check.sql new file mode 100644 index 0000000000..9e426cea1f --- /dev/null +++ b/pgtap/vroom/types_check.sql @@ -0,0 +1,88 @@ +BEGIN; + +SELECT plan(15); + +CREATE OR REPLACE FUNCTION types_check() +RETURNS SETOF TEXT AS +$BODY$ +BEGIN + + RETURN QUERY + SELECT has_function('vrp_vroom'); + RETURN QUERY + SELECT has_function('vrp_vroom', ARRAY['text', 'text', 'text', 'text']); + RETURN QUERY + SELECT function_returns('vrp_vroom', ARRAY['text', 'text', 'text', 'text'], 'setof record'); + + -- parameter names + RETURN QUERY + SELECT bag_has( + $$SELECT proargnames from pg_proc where proname = 'vrp_vroom'$$, + $$SELECT '{"","","","","seq","vehicle_seq","vehicle_id","step_seq","step_type",' + '"task_id","arrival","travel_time","service_time","waiting_time","load"}'::TEXT[]$$ + ); + + -- parameter types + RETURN QUERY + SELECT set_eq( + $$SELECT proallargtypes from pg_proc where proname = 'vrp_vroom'$$, + $$VALUES + ('{25,25,25,25,20,20,20,20,23,20,23,23,23,23,1016}'::OID[]) + $$ + ); + + RETURN QUERY + SELECT has_function('vrp_vroomjobs'); + RETURN QUERY + SELECT has_function('vrp_vroomjobs', ARRAY['text', 'text', 'text']); + RETURN QUERY + SELECT function_returns('vrp_vroomjobs', ARRAY['text', 'text', 'text'], 'setof record'); + + -- parameter names + RETURN QUERY + SELECT bag_has( + $$SELECT proargnames from pg_proc where proname = 'vrp_vroomjobs'$$, + $$SELECT '{"","","","seq","vehicle_seq","vehicle_id","step_seq","step_type",' + '"task_id","arrival","travel_time","service_time","waiting_time","load"}'::TEXT[]$$ + ); + + -- parameter types + RETURN QUERY + SELECT set_eq( + $$SELECT proallargtypes from pg_proc where proname = 'vrp_vroomjobs'$$, + $$VALUES + ('{25,25,25,20,20,20,20,23,20,23,23,23,23,1016}'::OID[]) + $$ + ); + + RETURN QUERY + SELECT has_function('vrp_vroomshipments'); + RETURN QUERY + SELECT has_function('vrp_vroomshipments', ARRAY['text', 'text', 'text']); + RETURN QUERY + SELECT function_returns('vrp_vroomshipments', ARRAY['text', 'text', 'text'], 'setof record'); + + -- parameter names + RETURN QUERY + SELECT bag_has( + $$SELECT proargnames from pg_proc where proname = 'vrp_vroomshipments'$$, + $$SELECT '{"","","","seq","vehicle_seq","vehicle_id","step_seq","step_type",' + '"task_id","arrival","travel_time","service_time","waiting_time","load"}'::TEXT[]$$ + ); + + -- parameter types + RETURN QUERY + SELECT set_eq( + $$SELECT proallargtypes from pg_proc where proname = 'vrp_vroomshipments'$$, + $$VALUES + ('{25,25,25,20,20,20,20,23,20,23,23,23,23,1016}'::OID[]) + $$ + ); +END; +$BODY$ +LANGUAGE plpgsql; + +SELECT types_check(); + +SELECT * FROM finish(); +ROLLBACK; From 85973c390df7b9225f1cb07c14a913a44ce8d146 Mon Sep 17 00:00:00 2001 From: Ashish Kumar Date: Fri, 23 Jul 2021 18:45:37 +0530 Subject: [PATCH 3/6] [vroom][pgtap] Create no crash test --- pgtap/vroom/no_crash_test.sql | 76 +++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 pgtap/vroom/no_crash_test.sql diff --git a/pgtap/vroom/no_crash_test.sql b/pgtap/vroom/no_crash_test.sql new file mode 100644 index 0000000000..eea784e812 --- /dev/null +++ b/pgtap/vroom/no_crash_test.sql @@ -0,0 +1,76 @@ +BEGIN; + +select plan(30); + +PREPARE jobs AS +SELECT * FROM vroom_jobs; + +PREPARE shipments AS +SELECT * FROM vroom_shipments; + +PREPARE vehicles AS +SELECT * FROM vroom_vehicles; + +PREPARE matrix AS +SELECT * FROM vroom_matrix; + +CREATE OR REPLACE FUNCTION no_crash() +RETURNS SETOF TEXT AS +$BODY$ +DECLARE +params TEXT[]; +subs TEXT[]; +BEGIN + + RETURN QUERY + SELECT isnt_empty('jobs', 'Should be not empty to tests be meaningful'); + RETURN QUERY + SELECT isnt_empty('shipments', 'Should be not empty to tests be meaningful'); + RETURN QUERY + SELECT isnt_empty('vehicles', 'Should be not empty to tests be meaningful'); + RETURN QUERY + SELECT isnt_empty('matrix', 'Should be not empty to tests be meaningful'); + + params = ARRAY[ + '$$jobs$$', + '$$shipments$$', + '$$vehicles$$', + '$$matrix$$' + ]::TEXT[]; + subs = ARRAY[ + 'NULL', + 'NULL', + 'NULL', + 'NULL' + ]::TEXT[]; + + RETURN query SELECT * FROM no_crash_test('vrp_vroom', params, subs); + + params = ARRAY[ + '$$jobs$$', + '$$vehicles$$', + '$$matrix$$' + ]::TEXT[]; + subs = ARRAY[ + 'NULL', + 'NULL', + 'NULL' + ]::TEXT[]; + + RETURN query SELECT * FROM no_crash_test('vrp_vroomJobs', params, subs); + + params = ARRAY[ + '$$shipments$$', + '$$vehicles$$', + '$$matrix$$' + ]::TEXT[]; + RETURN query SELECT * FROM no_crash_test('vrp_vroomShipments', params, subs); + +END +$BODY$ +LANGUAGE plpgsql VOLATILE; + + +SELECT * FROM no_crash(); + +ROLLBACK; From 47b19d3979e2c2652c3756e4583de5f5f99c5ccd Mon Sep 17 00:00:00 2001 From: Ashish Kumar Date: Fri, 23 Jul 2021 18:47:52 +0530 Subject: [PATCH 4/6] [vroom][pgtap] Added inner query test for vrp_vroom --- pgtap/vroom/inner_query.sql | 216 ++++++++++++++++++++++++++++++++++++ 1 file changed, 216 insertions(+) create mode 100644 pgtap/vroom/inner_query.sql diff --git a/pgtap/vroom/inner_query.sql b/pgtap/vroom/inner_query.sql new file mode 100644 index 0000000000..471f26ed73 --- /dev/null +++ b/pgtap/vroom/inner_query.sql @@ -0,0 +1,216 @@ +BEGIN; + +SELECT plan(166); + +/* +SELECT * FROM vrp_vroom( + $$SELECT id, location_index, service, delivery, pickup, skills, priority, time_windows_sql FROM vroom_jobs$$, + $$SELECT p_id, p_location_index, p_service, p_time_windows_sql, d_id, d_location_index, d_service, d_time_windows_sql, amount, skills, priority FROM vroom_shipments$$, + $$SELECT id, start_index, end_index, capacity, skills, tw_open, tw_close, breaks_sql FROM vroom_vehicles$$, + $$SELECT start_vid, end_vid, agg_cost FROM vroom_matrix$$ +) +*/ + +CREATE OR REPLACE FUNCTION test_value(fn TEXT, inner_query_table TEXT, start_sql TEXT, rest_sql TEXT, params TEXT[], parameter TEXT, accept TEXT[], reject TEXT[]) +RETURNS SETOF TEXT AS +$BODY$ +DECLARE + end_sql TEXT; + query TEXT; + p TEXT; + type_name TEXT; +BEGIN + start_sql = 'SELECT * FROM ' || fn || '(' || start_sql || '$$ SELECT '; + FOREACH p IN ARRAY params + LOOP + IF p = parameter THEN CONTINUE; + END IF; + start_sql = start_sql || p || ', '; + END LOOP; + end_sql = ' FROM ' || inner_query_table || '$$' || rest_sql; + + FOREACH type_name IN ARRAY accept + LOOP + query := start_sql || parameter || '::' || type_name || end_sql; + RETURN query SELECT lives_ok(query); + END LOOP; + + FOREACH type_name IN ARRAY reject + LOOP + query := start_sql || parameter || '::' || type_name || end_sql; + RETURN query SELECT throws_ok(query); + END LOOP; +END; +$BODY$ LANGUAGE plpgsql; + + +CREATE OR REPLACE FUNCTION test_anyInteger(fn TEXT, inner_query_table TEXT, start_sql TEXT, rest_sql TEXT, params TEXT[], parameter TEXT) +RETURNS SETOF TEXT AS +$BODY$ +DECLARE + accept TEXT[] := ARRAY['SMALLINT', 'INTEGER', 'BIGINT']; + reject TEXT[] := ARRAY['REAL', 'FLOAT8', 'NUMERIC']; +BEGIN + RETURN query SELECT test_value(fn, inner_query_table, start_sql, rest_sql, params, parameter, accept, reject); +END; +$BODY$ LANGUAGE plpgsql; + + +CREATE OR REPLACE FUNCTION test_Integer(fn TEXT, inner_query_table TEXT, start_sql TEXT, rest_sql TEXT, params TEXT[], parameter TEXT) +RETURNS SETOF TEXT AS +$BODY$ +DECLARE + accept TEXT[] := ARRAY['SMALLINT', 'INTEGER']; + reject TEXT[] := ARRAY['BIGINT', 'REAL', 'FLOAT8', 'NUMERIC']; +BEGIN + RETURN query SELECT test_value(fn, inner_query_table, start_sql, rest_sql, params, parameter, accept, reject); +END; +$BODY$ LANGUAGE plpgsql; + + +CREATE OR REPLACE FUNCTION test_anyArrayInteger(fn TEXT, inner_query_table TEXT, start_sql TEXT, rest_sql TEXT, params TEXT[], parameter TEXT) +RETURNS SETOF TEXT AS +$BODY$ +DECLARE + accept TEXT[] := ARRAY['SMALLINT[]', 'INTEGER[]', 'BIGINT[]']; + reject TEXT[] := ARRAY['REAL[]', 'FLOAT8[]', 'NUMERIC[]']; +BEGIN + RETURN query SELECT test_value(fn, inner_query_table, start_sql, rest_sql, params, parameter, accept, reject); +END; +$BODY$ LANGUAGE plpgsql; + + +CREATE OR REPLACE FUNCTION test_arrayInteger(fn TEXT, inner_query_table TEXT, start_sql TEXT, rest_sql TEXT, params TEXT[], parameter TEXT) +RETURNS SETOF TEXT AS +$BODY$ +DECLARE + accept TEXT[] := ARRAY['SMALLINT[]', 'INTEGER[]']; + reject TEXT[] := ARRAY['BIGINT[]', 'REAL[]', 'FLOAT8[]', 'NUMERIC[]']; +BEGIN + RETURN query SELECT test_value(fn, inner_query_table, start_sql, rest_sql, params, parameter, accept, reject); +END; +$BODY$ LANGUAGE plpgsql; + + +CREATE OR REPLACE FUNCTION test_anyNumerical(fn TEXT, inner_query_table TEXT, start_sql TEXT, rest_sql TEXT, params TEXT[], parameter TEXT) +RETURNS SETOF TEXT AS +$BODY$ +DECLARE + accept TEXT[] := ARRAY['SMALLINT', 'INTEGER', 'BIGINT', 'REAL', 'FLOAT8', 'NUMERIC']; + reject TEXT[] := ARRAY[]::TEXT[]; +BEGIN + RETURN query SELECT test_value(fn, inner_query_table, start_sql, rest_sql, params, parameter, accept, reject); +END; +$BODY$ LANGUAGE plpgsql; + + +CREATE OR REPLACE FUNCTION test_Text(fn TEXT, inner_query_table TEXT, start_sql TEXT, rest_sql TEXT, params TEXT[], parameter TEXT) +RETURNS SETOF TEXT AS +$BODY$ +DECLARE + accept TEXT[] := ARRAY['TEXT']; + reject TEXT[] := ARRAY[]::TEXT[]; +BEGIN + RETURN query SELECT test_value(fn, inner_query_table, start_sql, rest_sql, params, parameter, accept, reject); +END; +$BODY$ LANGUAGE plpgsql; + + +CREATE OR REPLACE FUNCTION inner_query_jobs() +RETURNS SETOF TEXT AS +$BODY$ +DECLARE + fn TEXT := 'vrp_vroom'; + inner_query_table TEXT := 'vroom_jobs'; + start_sql TEXT := ''; + rest_sql TEXT := ', $$SELECT * FROM vroom_shipments$$, $$SELECT * FROM vroom_vehicles$$, $$SELECT * FROM vroom_matrix$$)'; + params TEXT[] := ARRAY['id', 'location_index', 'service', 'delivery', 'pickup', 'skills', 'priority', 'time_windows_sql']; +BEGIN + RETURN QUERY SELECT test_anyInteger(fn, inner_query_table, start_sql, rest_sql, params, 'id'); + RETURN QUERY SELECT test_anyInteger(fn, inner_query_table, start_sql, rest_sql, params, 'location_index'); + RETURN QUERY SELECT test_Integer(fn, inner_query_table, start_sql, rest_sql, params, 'service'); + RETURN QUERY SELECT test_anyArrayInteger(fn, inner_query_table, start_sql, rest_sql, params, 'delivery'); + RETURN QUERY SELECT test_anyArrayInteger(fn, inner_query_table, start_sql, rest_sql, params, 'pickup'); + RETURN QUERY SELECT test_arrayInteger(fn, inner_query_table, start_sql, rest_sql, params, 'skills'); + RETURN QUERY SELECT test_Integer(fn, inner_query_table, start_sql, rest_sql, params, 'priority'); + RETURN QUERY SELECT test_Text(fn, inner_query_table, start_sql, rest_sql, params, 'time_windows_sql'); +END; +$BODY$ +LANGUAGE plpgsql; + + +CREATE OR REPLACE FUNCTION inner_query_shipments() +RETURNS SETOF TEXT AS +$BODY$ +DECLARE + fn TEXT := 'vrp_vroom'; + inner_query_table TEXT := 'vroom_shipments'; + start_sql TEXT := '$$SELECT * FROM vroom_jobs$$, '; + rest_sql TEXT := ', $$SELECT * FROM vroom_vehicles$$, $$SELECT * FROM vroom_matrix$$)'; + params TEXT[] := ARRAY['p_id', 'p_location_index', 'p_service', 'p_time_windows_sql', 'd_id', 'd_location_index', 'd_service', 'd_time_windows_sql', 'amount', 'skills', 'priority']; +BEGIN + RETURN QUERY SELECT test_anyInteger(fn, inner_query_table, start_sql, rest_sql, params, 'p_id'); + RETURN QUERY SELECT test_anyInteger(fn, inner_query_table, start_sql, rest_sql, params, 'd_id'); + RETURN QUERY SELECT test_anyInteger(fn, inner_query_table, start_sql, rest_sql, params, 'p_location_index'); + RETURN QUERY SELECT test_anyInteger(fn, inner_query_table, start_sql, rest_sql, params, 'd_location_index'); + RETURN QUERY SELECT test_Integer(fn, inner_query_table, start_sql, rest_sql, params, 'p_service'); + RETURN QUERY SELECT test_Integer(fn, inner_query_table, start_sql, rest_sql, params, 'd_service'); + RETURN QUERY SELECT test_Text(fn, inner_query_table, start_sql, rest_sql, params, 'p_time_windows_sql'); + RETURN QUERY SELECT test_Text(fn, inner_query_table, start_sql, rest_sql, params, 'd_time_windows_sql'); + RETURN QUERY SELECT test_anyArrayInteger(fn, inner_query_table, start_sql, rest_sql, params, 'amount'); + RETURN QUERY SELECT test_arrayInteger(fn, inner_query_table, start_sql, rest_sql, params, 'skills'); + RETURN QUERY SELECT test_Integer(fn, inner_query_table, start_sql, rest_sql, params, 'priority'); +END; +$BODY$ +LANGUAGE plpgsql; + + +CREATE OR REPLACE FUNCTION inner_query_vehicles() +RETURNS SETOF TEXT AS +$BODY$ +DECLARE + fn TEXT := 'vrp_vroom'; + inner_query_table TEXT := 'vroom_vehicles'; + start_sql TEXT := '$$SELECT * FROM vroom_jobs$$, $$SELECT * FROM vroom_shipments$$, '; + rest_sql TEXT := ', $$SELECT * FROM vroom_matrix$$)'; + params TEXT[] := ARRAY['id', 'start_index', 'end_index', 'capacity', 'skills', 'tw_open', 'tw_close', 'breaks_sql', 'speed_factor']; +BEGIN + RETURN QUERY SELECT test_anyInteger(fn, inner_query_table, start_sql, rest_sql, params, 'id'); + RETURN QUERY SELECT test_anyInteger(fn, inner_query_table, start_sql, rest_sql, params, 'start_index'); + RETURN QUERY SELECT test_anyInteger(fn, inner_query_table, start_sql, rest_sql, params, 'end_index'); + RETURN QUERY SELECT test_anyArrayInteger(fn, inner_query_table, start_sql, rest_sql, params, 'capacity'); + RETURN QUERY SELECT test_arrayInteger(fn, inner_query_table, start_sql, rest_sql, params, 'skills'); + RETURN QUERY SELECT test_Integer(fn, inner_query_table, start_sql, rest_sql, params, 'tw_open'); + RETURN QUERY SELECT test_Integer(fn, inner_query_table, start_sql, rest_sql, params, 'tw_close'); + RETURN QUERY SELECT test_Text(fn, inner_query_table, start_sql, rest_sql, params, 'breaks_sql'); + RETURN QUERY SELECT test_anyNumerical(fn, inner_query_table, start_sql, rest_sql, params, 'speed_factor'); +END; +$BODY$ +LANGUAGE plpgsql; + + +CREATE OR REPLACE FUNCTION inner_query_matrix() +RETURNS SETOF TEXT AS +$BODY$ +DECLARE + fn TEXT := 'vrp_vroom'; + inner_query_table TEXT := 'vroom_matrix'; + start_sql TEXT := '$$SELECT * FROM vroom_jobs$$, $$SELECT * FROM vroom_shipments$$, $$SELECT * FROM vroom_vehicles$$, '; + rest_sql TEXT := ')'; + params TEXT[] := ARRAY['start_vid', 'end_vid', 'agg_cost']; +BEGIN + RETURN QUERY SELECT test_anyInteger(fn, inner_query_table, start_sql, rest_sql, params, 'start_vid'); + RETURN QUERY SELECT test_anyInteger(fn, inner_query_table, start_sql, rest_sql, params, 'end_vid'); + RETURN QUERY SELECT test_Integer(fn, inner_query_table, start_sql, rest_sql, params, 'agg_cost'); +END; +$BODY$ +LANGUAGE plpgsql; + + +SELECT inner_query_jobs(); +SELECT inner_query_shipments(); +SELECT inner_query_vehicles(); +SELECT inner_query_matrix(); + +SELECT finish(); +ROLLBACK; From 976181a9e1cdc60a7edf38c8c51202a42c73b30d Mon Sep 17 00:00:00 2001 From: Ashish Kumar Date: Fri, 23 Jul 2021 18:55:09 +0530 Subject: [PATCH 5/6] [src] Fixed spi_getText for NULL values --- src/common/get_check_data.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/common/get_check_data.c b/src/common/get_check_data.c index 67c8cc9085..da6694b8b3 100644 --- a/src/common/get_check_data.c +++ b/src/common/get_check_data.c @@ -750,7 +750,11 @@ spi_getCoordinate(HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info, Coor */ char* spi_getText(HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info) { - return DatumGetCString(SPI_getvalue(*tuple, *tupdesc, info.colNumber)); + char *val = DatumGetCString(SPI_getvalue(*tuple, *tupdesc, info.colNumber)); + if (!val) { + elog(ERROR, "Unexpected Null value in column %s", info.name); + } + return val; } /** From 819ba8b3f4cc3a241fd3cbee771fb5f17e21ed59 Mon Sep 17 00:00:00 2001 From: Ashish Kumar Date: Fri, 23 Jul 2021 18:55:40 +0530 Subject: [PATCH 6/6] [tools] Added vroomdata.sql to setup_db --- tools/testers/setup_db.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/testers/setup_db.sql b/tools/testers/setup_db.sql index 6d8116f09e..d5be2f4196 100644 --- a/tools/testers/setup_db.sql +++ b/tools/testers/setup_db.sql @@ -23,5 +23,6 @@ BEGIN; \i vrppdtw_data.sql \i solomon_100_rc101.data.sql \i no_crash_test.sql + \i vroomdata.sql END;