From de5a7025107189a05b44660f9855ac376d100ccb Mon Sep 17 00:00:00 2001 From: Raul Ochoa Date: Mon, 18 Apr 2016 17:41:39 +0200 Subject: [PATCH] Adds table for storing camshaft analysis nodes --- scripts-available/CDB_AnalysisCatalog.sql | 24 +++++++++++++++++++++ scripts-enabled/260-CDB_AnalysisCatalog.sql | 1 + test/extension/run_at_cartodb_schema.sql | 1 + test/extension/test.sh | 7 ++++++ 4 files changed, 33 insertions(+) create mode 100644 scripts-available/CDB_AnalysisCatalog.sql create mode 120000 scripts-enabled/260-CDB_AnalysisCatalog.sql diff --git a/scripts-available/CDB_AnalysisCatalog.sql b/scripts-available/CDB_AnalysisCatalog.sql new file mode 100644 index 0000000..6831e30 --- /dev/null +++ b/scripts-available/CDB_AnalysisCatalog.sql @@ -0,0 +1,24 @@ +-- Table to register analysis nodes from https://github.com/cartodb/camshaft +CREATE TABLE IF NOT EXISTS +cartodb.cdb_analysis_catalog ( + -- md5 hex hash + node_id char(40) CONSTRAINT cdb_analysis_catalog_pkey PRIMARY KEY, + -- being json allows to do queries like analysis_def->>'type' = 'buffer' + analysis_def json NOT NULL, + -- can reference other nodes in this very same table, allowing recursive queries + input_nodes char(40) ARRAY NOT NULL DEFAULT '{}', + status TEXT NOT NULL DEFAULT 'pending', + CONSTRAINT valid_status CHECK ( + status IN ( 'pending', 'waiting', 'running', 'canceled', 'failed', 'ready' ) + ), + created_at timestamp with time zone NOT NULL DEFAULT now(), + -- should be updated when some operation was performed in the node + -- and anything associated to it might have changed + updated_at timestamp with time zone DEFAULT NULL, + -- should register last time the node was used + used_at timestamp with time zone NOT NULL DEFAULT now(), + -- should register the number of times the node was used + hits NUMERIC DEFAULT 0, + -- should register what was the last node using current node + last_used_from char(40) +); diff --git a/scripts-enabled/260-CDB_AnalysisCatalog.sql b/scripts-enabled/260-CDB_AnalysisCatalog.sql new file mode 120000 index 0000000..3b75542 --- /dev/null +++ b/scripts-enabled/260-CDB_AnalysisCatalog.sql @@ -0,0 +1 @@ +../scripts-available/CDB_AnalysisCatalog.sql \ No newline at end of file diff --git a/test/extension/run_at_cartodb_schema.sql b/test/extension/run_at_cartodb_schema.sql index 0c09e5f..1637d43 100644 --- a/test/extension/run_at_cartodb_schema.sql +++ b/test/extension/run_at_cartodb_schema.sql @@ -3,4 +3,5 @@ SET SCHEMA 'cartodb'; \i scripts-available/CDB_TableMetadata.sql \i scripts-available/CDB_ColumnNames.sql \i scripts-available/CDB_ColumnType.sql +\i scripts-available/CDB_AnalysisCatalog.sql SET SCHEMA 'public'; \ No newline at end of file diff --git a/test/extension/test.sh b/test/extension/test.sh index 34f697d..410ac12 100755 --- a/test/extension/test.sh +++ b/test/extension/test.sh @@ -563,6 +563,13 @@ test_extension|public|"local-table-with-dashes"' DATABASE=fdw_target tear_down_database } +function test_cdb_catalog_basic_node() { + DEF="'{\"type\":\"buffer\",\"source\":\"b2db66bc7ac02e135fd20bbfef0fdd81b2d15fad\",\"radio\":10000}'" + sql postgres "INSERT INTO cartodb.cdb_analysis_catalog (node_id, analysis_def) VALUES ('1bbc4c41ea7c9d3a7dc1509727f698b7', ${DEF}::json)" + sql postgres "SELECT status from cartodb.cdb_analysis_catalog where node_id = '1bbc4c41ea7c9d3a7dc1509727f698b7'" should 'pending' + sql postgres "DELETE FROM cartodb.cdb_analysis_catalog" +} + #################################################### TESTS END HERE #################################################### run_tests $@