Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/dev check #276

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@
<exclude>src/ports/postgres/modules/elastic_net/elastic_net_optimizer_fista.py_in</exclude>
<exclude>src/ports/postgres/modules/elastic_net/elastic_net_optimizer_igd.py_in</exclude>
<exclude>src/ports/postgres/modules/elastic_net/elastic_net_utils.py_in</exclude>
<exclude>src/ports/postgres/modules/elastic_net/test/elastic_net_install_check.sql_in</exclude>
<exclude>src/ports/postgres/modules/elastic_net/test/elastic_net.sql_in</exclude>
<exclude>src/ports/postgres/modules/glm/__init__.py_in</exclude>
<exclude>src/ports/postgres/modules/glm/glm.py_in</exclude>
<exclude>src/ports/postgres/modules/glm/glm.sql_in</exclude>
Expand Down
17 changes: 11 additions & 6 deletions src/madpack/madpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -770,10 +770,11 @@ def parse_arguments():
uninstall : run sql scripts to uninstall from DB
reinstall : performs uninstall and install
version : compare and print MADlib version (binaries vs database objects)
install-check : test all installed modules
install-check : sanity run of all installed modules
dev-check : test all installed modules
"""
choice_list = ['install', 'update', 'upgrade', 'uninstall',
'reinstall', 'version', 'install-check']
'reinstall', 'version', 'install-check', 'dev-check']

parser.add_argument('command', metavar='COMMAND', nargs=1,
choices=choice_list, help=help_msg)
Expand Down Expand Up @@ -812,7 +813,8 @@ def parse_arguments():
# Get the arguments
return parser.parse_args()

def run_install_check(args, testcase):
def run_install_check(args, testcase, madpack_cmd):
is_install_check = True if madpack_cmd == 'install-check' else False
schema = args['schema']
db_madlib_ver = args['db_madlib_ver']
# 1) Compare OS and DB versions. Continue if OS = DB.
Expand Down Expand Up @@ -898,7 +900,10 @@ def run_install_check(args, testcase):
% (test_user, test_schema, schema)

# Loop through all test SQL files for this module
sql_files = maddir_mod_sql + '/' + module + '/test/*.sql_in'
if is_install_check:
sql_files = maddir_mod_sql + '/' + module + '/test/*.ic.sql_in'
else:
sql_files = maddir_mod_sql + '/' + module + '/test/*[!ic].sql_in'
for sqlfile in sorted(glob.glob(sql_files), reverse=True):
algoname = os.path.basename(sqlfile).split('.')[0]
# run only algo specified
Expand Down Expand Up @@ -1240,8 +1245,8 @@ def main(argv):
_print_vers(new_madlib_ver, db_madlib_ver, con_args, schema)

# COMMAND: install-check
if args.command[0] == 'install-check':
run_install_check(locals(), args.testcase)
if args.command[0] in ('install-check', 'dev-check'):
run_install_check(locals(), args.testcase, args.command[0])
else:
try:
is_schema_in_db = _internal_run_query("SELECT schema_name FROM information_schema.schemata WHERE schema_name='%s';" % schema, True)
Expand Down
148 changes: 148 additions & 0 deletions src/ports/postgres/modules/assoc_rules/test/assoc_rules.ic.sql_in
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
/* ----------------------------------------------------------------------- *//**
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*//* ----------------------------------------------------------------------- */

---------------------------------------------------------------------------
-- Rules:
-- ------
-- 1) Any DB objects should be created w/o schema prefix,
-- since this file is executed in a separate schema context.
-- 2) There should be no DROP statements in this script, since
-- all objects created in the default schema will be cleaned-up outside.
---------------------------------------------------------------------------

---------------------------------------------------------------------------
-- Setup:
---------------------------------------------------------------------------
CREATE OR REPLACE FUNCTION assoc_array_eq
(
arr1 TEXT[],
arr2 TEXT[]
)
RETURNS BOOL AS $$
SELECT COUNT(*) = array_upper($1, 1) AND array_upper($1, 1) = array_upper($2, 1)
FROM (SELECT unnest($1) id) t1, (SELECT unnest($2) id) t2
WHERE t1.id = t2.id;

$$ LANGUAGE sql IMMUTABLE;


CREATE OR REPLACE FUNCTION install_test() RETURNS VOID AS $$
declare
result1 TEXT;
result2 TEXT;
result3 TEXT;
result_maxiter TEXT;
res MADLIB_SCHEMA.assoc_rules_results;
output_schema TEXT;
output_table TEXT;
total_rules INT;
total_time INTERVAL;
begin
DROP TABLE IF EXISTS test_data1;
CREATE TABLE test_data1 (
trans_id INT
, product INT
);

DROP TABLE IF EXISTS test_data2;
CREATE TABLE test_data2 (
trans_id INT
, product VARCHAR
);


INSERT INTO test_data1 VALUES (1,1);
INSERT INTO test_data1 VALUES (1,2);
INSERT INTO test_data1 VALUES (3,3);
INSERT INTO test_data1 VALUES (8,4);
INSERT INTO test_data1 VALUES (10,1);
INSERT INTO test_data1 VALUES (10,2);
INSERT INTO test_data1 VALUES (10,3);
INSERT INTO test_data1 VALUES (19,2);

INSERT INTO test_data2 VALUES (1, 'beer');
INSERT INTO test_data2 VALUES (1, 'diapers');
INSERT INTO test_data2 VALUES (1, 'chips');
INSERT INTO test_data2 VALUES (2, 'beer');
INSERT INTO test_data2 VALUES (2, 'diapers');
INSERT INTO test_data2 VALUES (3, 'beer');
INSERT INTO test_data2 VALUES (3, 'diapers');
INSERT INTO test_data2 VALUES (4, 'beer');
INSERT INTO test_data2 VALUES (4, 'chips');
INSERT INTO test_data2 VALUES (5, 'beer');
INSERT INTO test_data2 VALUES (6, 'beer');
INSERT INTO test_data2 VALUES (6, 'diapers');
INSERT INTO test_data2 VALUES (6, 'chips');
INSERT INTO test_data2 VALUES (7, 'beer');
INSERT INTO test_data2 VALUES (7, 'diapers');

DROP TABLE IF EXISTS test1_exp_result;
CREATE TABLE test1_exp_result (
ruleid integer,
pre text[],
post text[],
support double precision,
confidence double precision,
lift double precision,
conviction double precision
) ;

DROP TABLE IF EXISTS test2_exp_result;
CREATE TABLE test2_exp_result (
ruleid integer,
pre text[],
post text[],
support double precision,
confidence double precision,
lift double precision,
conviction double precision
) ;


INSERT INTO test1_exp_result VALUES (7, '{3}', '{1}', 0.20000000000000001, 0.5, 1.2499999999999998, 1.2);
INSERT INTO test1_exp_result VALUES (4, '{2}', '{1}', 0.40000000000000002, 0.66666666666666674, 1.6666666666666667, 1.8000000000000003);
INSERT INTO test1_exp_result VALUES (1, '{1}', '{2,3}', 0.20000000000000001, 0.5, 2.4999999999999996, 1.6000000000000001);
INSERT INTO test1_exp_result VALUES (9, '{2,3}', '{1}', 0.20000000000000001, 1, 2.4999999999999996, 0);
INSERT INTO test1_exp_result VALUES (6, '{1,2}', '{3}', 0.20000000000000001, 0.5, 1.2499999999999998, 1.2);
INSERT INTO test1_exp_result VALUES (8, '{3}', '{2}', 0.20000000000000001, 0.5, 0.83333333333333337, 0.80000000000000004);
INSERT INTO test1_exp_result VALUES (5, '{1}', '{2}', 0.40000000000000002, 1, 1.6666666666666667, 0);
INSERT INTO test1_exp_result VALUES (2, '{3}', '{2,1}', 0.20000000000000001, 0.5, 1.2499999999999998, 1.2);
INSERT INTO test1_exp_result VALUES (10, '{3,1}', '{2}', 0.20000000000000001, 1, 1.6666666666666667, 0);
INSERT INTO test1_exp_result VALUES (3, '{1}', '{3}', 0.20000000000000001, 0.5, 1.2499999999999998, 1.2);

INSERT INTO test2_exp_result VALUES (7, '{chips,diapers}', '{beer}', 0.2857142857142857, 1, 1, 0);
INSERT INTO test2_exp_result VALUES (2, '{chips}', '{diapers}', 0.2857142857142857, 0.66666666666666663, 0.93333333333333324, 0.85714285714285698);
INSERT INTO test2_exp_result VALUES (1, '{chips}', '{diapers,beer}', 0.2857142857142857, 0.66666666666666663, 0.93333333333333324, 0.85714285714285698);
INSERT INTO test2_exp_result VALUES (6, '{diapers}', '{beer}', 0.7142857142857143, 1, 1, 0);
INSERT INTO test2_exp_result VALUES (4, '{beer}', '{diapers}', 0.7142857142857143, 0.7142857142857143, 1, 1);
INSERT INTO test2_exp_result VALUES (3, '{chips,beer}', '{diapers}', 0.2857142857142857, 0.66666666666666663, 0.93333333333333324, 0.85714285714285698);
INSERT INTO test2_exp_result VALUES (5, '{chips}', '{beer}', 0.42857142857142855, 1, 1, 0);

res = MADLIB_SCHEMA.assoc_rules (.1, .5, 'trans_id', 'product', 'test_data1','madlib_installcheck_assoc_rules', false);

RETURN;

end $$ language plpgsql;

---------------------------------------------------------------------------
-- Test
---------------------------------------------------------------------------
SELECT install_test();
105 changes: 105 additions & 0 deletions src/ports/postgres/modules/bayes/test/bayes.ic.sql_in
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/* ----------------------------------------------------------------------- *//**
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*//* ----------------------------------------------------------------------- */

---------------------------------------------------------------------------
-- Rules:
-- ------
-- 1) Any DB objects should be created w/o schema prefix,
-- since this file is executed in a separate schema context.
-- 2) There should be no DROP statements in this script, since
-- all objects created in the default schema will be cleaned-up outside.
---------------------------------------------------------------------------

---------------------------------------------------------------------------
-- Setup:
---------------------------------------------------------------------------
CREATE OR REPLACE FUNCTION fill_feature(pre_class INT, p FLOAT, total INT)
RETURNS FLOAT AS $$
declare
result FLOAT;
thres INT;
begin
thres = total*p;

IF pre_class <= thres THEN
result = 1;
ELSE
result = 0;
END IF;
RETURN result;
end
$$ language plpgsql;

-- ----------------
-- install_test_1()
-- ----------------
CREATE FUNCTION install_test_1() RETURNS VOID AS $$
declare
num1 INT := 10;
num2 INT := 10;

result1 INT;
count1 INT;
tempvar INT[];

begin
-- prepare training data: equal priors
--DROP TABLE IF EXISTS data CASCADE;
CREATE TABLE data_1( class INT, attrib FLOAT[] );
INSERT INTO data_1 SELECT 1, ARRAY[fill_feature(id,0.3,num1),fill_feature(id,0.8,num1)] FROM generate_series(1,num1) as id;
INSERT INTO data_1 SELECT 2, ARRAY[fill_feature(id,0.5,num2),fill_feature(id,0.5,num2)] FROM generate_series(1,num2) as id;

-- prepare testing data
--DROP TABLE IF EXISTS data_test CASCADE;
CREATE TABLE data_test_1( id INT, attrib INT[], prob FLOAT[] );
INSERT INTO data_test_1 VALUES (1,'{0,0}','{0.4,0.6}');
INSERT INTO data_test_1 VALUES (2,'{0,1}','{0.66666,0.33333}');
INSERT INTO data_test_1 VALUES (3,'{1,0}','{0.25,0.75}');
INSERT INTO data_test_1 VALUES (4,'{1,1}','{0.5,0.5}');

-- prepare true results for testing data
--DROP TABLE IF EXISTS data_results;
CREATE TABLE data_results_1 AS
SELECT
id,
unnest('{1,2}'::INT[]) as class,
unnest(prob) as prob
FROM data_test_1;

-- Process training
--DROP TABLE IF EXISTS probs CASCADE;
--DROP TABLE IF EXISTS priors CASCADE;
PERFORM MADLIB_SCHEMA.create_nb_prepared_data_tables('data_1','class','attrib',2,'probs','priors');
-- Classify
--DROP VIEW IF EXISTS results;
PERFORM MADLIB_SCHEMA.create_nb_classify_view('probs','priors','data_test_1','id','attrib',2,'results_1');
-- Compute posteriors
--DROP VIEW IF EXISTS probs_view;
PERFORM MADLIB_SCHEMA.create_nb_probs_view('probs','priors','data_test_1','id','attrib',2,'probs_view_1');


end
$$ language plpgsql;

---------------------------------------------------------------------------
-- Test:
---------------------------------------------------------------------------
SELECT install_test_1();
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/* ----------------------------------------------------------------------- *//**
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*//* ----------------------------------------------------------------------- */

---------------------------------------------------------------------------
-- Rules:
-- ------
-- 1) Any DB objects should be created w/o schema prefix,
-- since this file is executed in a separate schema context.
-- 2) There should be no DROP statements in this script, since
-- all objects created in the default schema will be cleaned-up outside.
---------------------------------------------------------------------------

---------------------------------------------------------------------------
-- Setup:
---------------------------------------------------------------------------
CREATE FUNCTION install_test() RETURNS VOID AS $$
declare
result float;
x FLOAT[];

begin
CREATE TABLE A(
row INT,
val FLOAT[]
);

INSERT INTO A VALUES(1, ARRAY[1.0175001, 0.45604107, 0.32282152, 0.25168270, 0.20694042, 0.17602822, 0.15331823, 0.13589278, 0.12208089, 0.11085359]);
INSERT INTO A VALUES(2, ARRAY[0.4560411, 0.48234387, 0.21190993, 0.17177051, 0.14528005, 0.12627935, 0.11189286, 0.10057578, 0.09141562, 0.08383503]);
INSERT INTO A VALUES(3, ARRAY[0.3228215, 0.21190993, 0.36372483, 0.13511499, 0.11570299, 0.10149569, 0.09057135, 0.08187212, 0.07476054, 0.06882649]);
INSERT INTO A VALUES(4, ARRAY[0.2516827, 0.17177051, 0.13511499, 0.31270305, 0.09720943, 0.08572070, 0.07680054, 0.06964365, 0.06375766, 0.05882206]);
INSERT INTO A VALUES(5, ARRAY[0.2069404, 0.14528005, 0.11570299, 0.09720943, 0.28424848, 0.07454783, 0.06696472, 0.06084900, 0.05579869, 0.05154975]);
INSERT INTO A VALUES(6, ARRAY[0.1760282, 0.12627935, 0.10149569, 0.08572070, 0.07454783, 0.26612646, 0.05951006, 0.05415360, 0.04971703, 0.04597544]);
INSERT INTO A VALUES(7, ARRAY[0.1533182, 0.11189286, 0.09057135, 0.07680054, 0.06696472, 0.05951006, 0.25363014, 0.04885589, 0.04489247, 0.04154376]);
INSERT INTO A VALUES(8, ARRAY[0.1358928, 0.10057578, 0.08187212, 0.06964365, 0.06084900, 0.05415360, 0.04885589, 0.24454426, 0.04095839, 0.03792426]);
INSERT INTO A VALUES(9, ARRAY[0.1220809, 0.09141562, 0.07476054, 0.06375766, 0.05579869, 0.04971703, 0.04489247, 0.04095839, 0.23768165, 0.03490583]);
INSERT INTO A VALUES(10,ARRAY[0.1108536, 0.08383503, 0.06882649, 0.05882206, 0.05154975, 0.04597544, 0.04154376, 0.03792426, 0.03490583, 0.23234632]);

SELECT INTO x MADLIB_SCHEMA.conjugate_gradient('A', 'val', 'row', ARRAY(SELECT random() FROM generate_series(1,10)), .000001,2);
result = x[1]*x[1];
RETURN;
end
$$ language plpgsql;

---------------------------------------------------------------------------
-- Test
---------------------------------------------------------------------------
SELECT install_test();