thingsboard-aplcache

Was fixed Materialized View

9/18/2018 9:33:37 AM

Details

diff --git a/application/src/main/data/upgrade/2.1.1/schema_update.cql b/application/src/main/data/upgrade/2.1.1/schema_update.cql
index c5d919b..888f43c 100644
--- a/application/src/main/data/upgrade/2.1.1/schema_update.cql
+++ b/application/src/main/data/upgrade/2.1.1/schema_update.cql
@@ -22,51 +22,71 @@ DROP MATERIALIZED VIEW IF EXISTS thingsboard.entity_views_by_tenant_and_customer
 DROP TABLE IF EXISTS thingsboard.entity_views;
 
 CREATE TABLE IF NOT EXISTS thingsboard.entity_views (
-id timeuuid,
-entity_id timeuuid,
-entity_type text,
-tenant_id timeuuid,
-customer_id timeuuid,
-name text,
-keys text,
-start_ts bigint,
-end_ts bigint,
-search_text text,
-additional_info text,
-PRIMARY KEY (id, tenant_id, customer_id)
+    id timeuuid,
+    entity_id timeuuid,
+    entity_type text,
+    tenant_id timeuuid,
+    customer_id timeuuid,
+    name text,
+    keys text,
+    start_ts bigint,
+    end_ts bigint,
+    search_text text,
+    additional_info text,
+    PRIMARY KEY (id, entity_id, tenant_id, customer_id)
 );
 
 CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_views_by_tenant_and_name AS
-SELECT *
-from thingsboard.entity_views
-WHERE entity_id IS NOT NULL AND tenant_id IS NOT NULL AND customer_id IS NOT NULL AND keys IS NOT NULL AND start_ts IS NOT NULL AND end_ts IS NOT NULL AND name IS NOT NULL AND id IS NOT NULL
-PRIMARY KEY (tenant_id, name, id, entity_id, customer_id)
-WITH CLUSTERING ORDER BY (name ASC, id DESC, entity_id DESC, customer_id DESC);
+    SELECT *
+    from thingsboard.entity_views
+    WHERE tenant_id IS NOT NULL
+        AND entity_id IS NOT NULL
+        AND customer_id IS NOT NULL
+        AND name IS NOT NULL
+        AND id IS NOT NULL
+    PRIMARY KEY (tenant_id, name, id, customer_id, entity_id)
+    WITH CLUSTERING ORDER BY (name ASC, id DESC, customer_id DESC);
 
 CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_view_by_tenant_and_search_text AS
-SELECT *
-from thingsboard.entity_views
-WHERE entity_id IS NOT NULL AND search_text IS NOT NULL AND tenant_id IS NOT NULL AND customer_id IS NOT NULL AND keys IS NOT NULL AND start_ts IS NOT NULL AND end_ts IS NOT NULL AND name IS NOT NULL AND id IS NOT NULL
-PRIMARY KEY (tenant_id, search_text, id, customer_id, name)
-WITH CLUSTERING ORDER BY (search_text ASC, customer_id ASC, id DESC, name DESC);
+    SELECT *
+    from thingsboard.entity_views
+    WHERE tenant_id IS NOT NULL
+      AND entity_id IS NOT NULL
+      AND customer_id IS NOT NULL
+      AND search_text IS NOT NULL
+      AND id IS NOT NULL
+    PRIMARY KEY (tenant_id, search_text, id, customer_id, entity_id)
+    WITH CLUSTERING ORDER BY (search_text ASC, id DESC, customer_id DESC);
 
-CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_view_by_tenant_and_entity_and_search_text AS
-SELECT *
-from thingsboard.entity_views
-WHERE entity_id IS NOT NULL AND search_text IS NOT NULL AND tenant_id IS NOT NULL AND customer_id IS NOT NULL AND keys IS NOT NULL AND start_ts IS NOT NULL AND end_ts IS NOT NULL AND name IS NOT NULL AND id IS NOT NULL
-PRIMARY KEY (tenant_id, entity_id, search_text, id, customer_id, name)
-WITH CLUSTERING ORDER BY (entity_id ASC, search_text ASC, id DESC, name DESC);
+CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_view_by_tenant_and_entity AS
+    SELECT *
+    from thingsboard.entity_views
+    WHERE tenant_id IS NOT NULL
+      AND customer_id IS NOT NULL
+      AND entity_id IS NOT NULL
+      AND search_text IS NOT NULL
+      AND id IS NOT NULL
+    PRIMARY KEY (tenant_id, entity_id, search_text, id, customer_id)
+    WITH CLUSTERING ORDER BY (entity_id ASC, search_text ASC, id DESC, customer_id DESC);
 
-CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_views_by_tenant_and_customer_and_search_text AS
-SELECT *
-from thingsboard.entity_views
-WHERE entity_id IS NOT NULL AND search_text IS NOT NULL AND tenant_id IS NOT NULL AND customer_id IS NOT NULL AND keys IS NOT NULL AND start_ts IS NOT NULL AND end_ts IS NOT NULL AND name IS NOT NULL AND id IS NOT NULL
-PRIMARY KEY (tenant_id, customer_id, search_text, id, entity_id)
-WITH CLUSTERING ORDER BY (customer_id ASC, search_text ASC, id DESC, entity_id DESC);
+CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_views_by_tenant_and_customer AS
+    SELECT *
+    from thingsboard.entity_views
+    WHERE tenant_id IS NOT NULL
+      AND customer_id IS NOT NULL
+      AND entity_id IS NOT NULL
+      AND search_text IS NOT NULL
+      AND id IS NOT NULL
+    PRIMARY KEY (tenant_id, customer_id, search_text, id, entity_id)
+    WITH CLUSTERING ORDER BY (customer_id DESC, search_text ASC, id DESC);
 
-CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_views_by_tenant_and_customer_and_entity_and_search_text AS
-SELECT *
-from thingsboard.entity_views
-WHERE entity_id IS NOT NULL AND search_text IS NOT NULL AND tenant_id IS NOT NULL AND customer_id IS NOT NULL AND keys IS NOT NULL AND start_ts IS NOT NULL AND end_ts IS NOT NULL AND name IS NOT NULL AND id IS NOT NULL
-PRIMARY KEY (tenant_id, customer_id, search_text,entity_id, id)
-WITH CLUSTERING ORDER BY (customer_id ASC, search_text ASC, entity_id DESC, id DESC);
+CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_views_by_tenant_and_customer_and_entity AS
+    SELECT *
+    from thingsboard.entity_views
+    WHERE tenant_id IS NOT NULL
+      AND customer_id IS NOT NULL
+      AND entity_id IS NOT NULL
+      AND search_text IS NOT NULL
+      AND id IS NOT NULL
+    PRIMARY KEY (tenant_id, customer_id, entity_id, search_text, id)
+    WITH CLUSTERING ORDER BY (customer_id DESC, entity_id ASC, search_text ASC, id DESC);
diff --git a/dao/src/main/java/org/thingsboard/server/dao/model/ModelConstants.java b/dao/src/main/java/org/thingsboard/server/dao/model/ModelConstants.java
index da180af..45d0ff9 100644
--- a/dao/src/main/java/org/thingsboard/server/dao/model/ModelConstants.java
+++ b/dao/src/main/java/org/thingsboard/server/dao/model/ModelConstants.java
@@ -150,15 +150,15 @@ public class ModelConstants {
     public static final String ENTITY_VIEW_TENANT_ID_PROPERTY = TENANT_ID_PROPERTY;
     public static final String ENTITY_VIEW_CUSTOMER_ID_PROPERTY = CUSTOMER_ID_PROPERTY;
     public static final String ENTITY_VIEW_NAME_PROPERTY = DEVICE_NAME_PROPERTY;
-    public static final String ENTITY_VIEW_BY_TENANT_AND_CUSTOMER_AND_ENTITY_AND_SEARCH_TEXT = "entity_views_by_tenant_and_customer_and_entity_and_search_text";
-    public static final String ENTITY_VIEW_BY_TENANT_AND_CUSTOMER_AND_SEARCH_TEXT = "entity_views_by_tenant_and_customer_and_search_text";
+    public static final String ENTITY_VIEW_BY_TENANT_AND_CUSTOMER_AND_ENTITY_AND_SEARCH_TEXT = "entity_views_by_tenant_and_customer_and_entity";
+    public static final String ENTITY_VIEW_BY_TENANT_AND_CUSTOMER_AND_SEARCH_TEXT = "entity_views_by_tenant_and_customer";
     public static final String ENTITY_VIEW_KEYS_PROPERTY = "keys";
     public static final String ENTITY_VIEW_START_TS_PROPERTY = "start_ts";
     public static final String ENTITY_VIEW_END_TS_PROPERTY = "end_ts";
     public static final String ENTITY_VIEW_ADDITIONAL_INFO_PROPERTY = ADDITIONAL_INFO_PROPERTY;
     public static final String ENTITY_VIEW_BY_TENANT_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME = "entity_view_by_tenant_and_search_text";
     public static final String ENTITY_VIEW_BY_TENANT_AND_NAME = "entity_views_by_tenant_and_name";
-    public static final String ENTITY_VIEW_BY_TENANT_AND_ENTITY_AND_SEARCH_TEXT = "entity_view_by_tenant_and_entity_and_search_text";
+    public static final String ENTITY_VIEW_BY_TENANT_AND_ENTITY_AND_SEARCH_TEXT = "entity_view_by_tenant_and_entity";
 
     /**
      * Cassandra audit log constants.
diff --git a/dao/src/main/resources/cassandra/schema.cql b/dao/src/main/resources/cassandra/schema.cql
index 674d30e..4645420 100644
--- a/dao/src/main/resources/cassandra/schema.cql
+++ b/dao/src/main/resources/cassandra/schema.cql
@@ -165,35 +165,55 @@ CREATE TABLE IF NOT EXISTS thingsboard.device (
 CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.device_by_tenant_and_name AS
     SELECT *
     from thingsboard.device
-    WHERE tenant_id IS NOT NULL AND customer_id IS NOT NULL AND type IS NOT NULL AND name IS NOT NULL AND id IS NOT NULL
+    WHERE tenant_id IS NOT NULL
+      AND customer_id IS NOT NULL
+      AND type IS NOT NULL
+      AND name IS NOT NULL
+      AND id IS NOT NULL
     PRIMARY KEY ( tenant_id, name, id, customer_id, type)
     WITH CLUSTERING ORDER BY ( name ASC, id DESC, customer_id DESC);
 
 CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.device_by_tenant_and_search_text AS
     SELECT *
     from thingsboard.device
-    WHERE tenant_id IS NOT NULL AND customer_id IS NOT NULL AND type IS NOT NULL AND search_text IS NOT NULL AND id IS NOT NULL
+    WHERE tenant_id IS NOT NULL
+      AND customer_id IS NOT NULL
+      AND type IS NOT NULL
+      AND search_text IS NOT NULL
+      AND id IS NOT NULL
     PRIMARY KEY ( tenant_id, search_text, id, customer_id, type)
     WITH CLUSTERING ORDER BY ( search_text ASC, id DESC, customer_id DESC);
 
 CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.device_by_tenant_by_type_and_search_text AS
     SELECT *
     from thingsboard.device
-    WHERE tenant_id IS NOT NULL AND customer_id IS NOT NULL AND type IS NOT NULL AND search_text IS NOT NULL AND id IS NOT NULL
+    WHERE tenant_id IS NOT NULL
+      AND customer_id IS NOT NULL
+      AND type IS NOT NULL
+      AND search_text IS NOT NULL
+      AND id IS NOT NULL
     PRIMARY KEY ( tenant_id, type, search_text, id, customer_id)
     WITH CLUSTERING ORDER BY ( type ASC, search_text ASC, id DESC, customer_id DESC);
 
 CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.device_by_customer_and_search_text AS
     SELECT *
     from thingsboard.device
-    WHERE tenant_id IS NOT NULL AND customer_id IS NOT NULL AND type IS NOT NULL AND search_text IS NOT NULL AND id IS NOT NULL
+    WHERE tenant_id IS NOT NULL
+      AND customer_id IS NOT NULL
+      AND type IS NOT NULL
+      AND search_text IS NOT NULL
+      AND id IS NOT NULL
     PRIMARY KEY ( customer_id, tenant_id, search_text, id, type )
     WITH CLUSTERING ORDER BY ( tenant_id DESC, search_text ASC, id DESC );
 
 CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.device_by_customer_by_type_and_search_text AS
     SELECT *
     from thingsboard.device
-    WHERE tenant_id IS NOT NULL AND customer_id IS NOT NULL AND type IS NOT NULL AND search_text IS NOT NULL AND id IS NOT NULL
+    WHERE tenant_id IS NOT NULL
+      AND customer_id IS NOT NULL
+      AND type IS NOT NULL
+      AND search_text IS NOT NULL
+      AND id IS NOT NULL
     PRIMARY KEY ( customer_id, tenant_id, type, search_text, id )
     WITH CLUSTERING ORDER BY ( tenant_id DESC, type ASC, search_text ASC, id DESC );
 
@@ -651,40 +671,60 @@ CREATE TABLE IF NOT EXISTS thingsboard.entity_views (
     end_ts bigint,
     search_text text,
     additional_info text,
-    PRIMARY KEY (id, tenant_id, customer_id)
+    PRIMARY KEY (id, entity_id, tenant_id, customer_id)
 );
 
 CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_views_by_tenant_and_name AS
     SELECT *
     from thingsboard.entity_views
-    WHERE entity_id IS NOT NULL AND tenant_id IS NOT NULL AND customer_id IS NOT NULL AND keys IS NOT NULL AND start_ts IS NOT NULL AND end_ts IS NOT NULL AND name IS NOT NULL AND id IS NOT NULL
-    PRIMARY KEY (tenant_id, name, id, entity_id, customer_id)
-    WITH CLUSTERING ORDER BY (name ASC, id DESC, entity_id DESC, customer_id DESC);
+    WHERE tenant_id IS NOT NULL
+      AND entity_id IS NOT NULL
+      AND customer_id IS NOT NULL
+      AND name IS NOT NULL
+      AND id IS NOT NULL
+    PRIMARY KEY (tenant_id, name, id, customer_id, entity_id)
+    WITH CLUSTERING ORDER BY (name ASC, id DESC, customer_id DESC);
 
 CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_view_by_tenant_and_search_text AS
     SELECT *
     from thingsboard.entity_views
-    WHERE entity_id IS NOT NULL AND search_text IS NOT NULL AND tenant_id IS NOT NULL AND customer_id IS NOT NULL AND keys IS NOT NULL AND start_ts IS NOT NULL AND end_ts IS NOT NULL AND name IS NOT NULL AND id IS NOT NULL
-    PRIMARY KEY (tenant_id, search_text, id, customer_id, name)
-    WITH CLUSTERING ORDER BY (search_text ASC, customer_id ASC, id DESC, name DESC);
-
-CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_view_by_tenant_and_entity_and_search_text AS
+    WHERE tenant_id IS NOT NULL
+      AND entity_id IS NOT NULL
+      AND customer_id IS NOT NULL
+      AND search_text IS NOT NULL
+      AND id IS NOT NULL
+    PRIMARY KEY (tenant_id, search_text, id, customer_id, entity_id)
+    WITH CLUSTERING ORDER BY (search_text ASC, id DESC, customer_id DESC);
+
+CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_view_by_tenant_and_entity AS
     SELECT *
     from thingsboard.entity_views
-    WHERE entity_id IS NOT NULL AND search_text IS NOT NULL AND tenant_id IS NOT NULL AND customer_id IS NOT NULL AND keys IS NOT NULL AND start_ts IS NOT NULL AND end_ts IS NOT NULL AND name IS NOT NULL AND id IS NOT NULL
-    PRIMARY KEY (tenant_id, entity_id, search_text, id, customer_id, name)
-    WITH CLUSTERING ORDER BY (entity_id ASC, search_text ASC, id DESC, name DESC);
-
-CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_views_by_tenant_and_customer_and_search_text AS
+    WHERE tenant_id IS NOT NULL
+      AND customer_id IS NOT NULL
+      AND entity_id IS NOT NULL
+      AND search_text IS NOT NULL
+      AND id IS NOT NULL
+    PRIMARY KEY (tenant_id, entity_id, search_text, id, customer_id)
+    WITH CLUSTERING ORDER BY (entity_id ASC, search_text ASC, id DESC, customer_id DESC);
+
+CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_views_by_tenant_and_customer AS
     SELECT *
     from thingsboard.entity_views
-    WHERE entity_id IS NOT NULL AND search_text IS NOT NULL AND tenant_id IS NOT NULL AND customer_id IS NOT NULL AND keys IS NOT NULL AND start_ts IS NOT NULL AND end_ts IS NOT NULL AND name IS NOT NULL AND id IS NOT NULL
+    WHERE tenant_id IS NOT NULL
+      AND customer_id IS NOT NULL
+      AND entity_id IS NOT NULL
+      AND search_text IS NOT NULL
+      AND id IS NOT NULL
     PRIMARY KEY (tenant_id, customer_id, search_text, id, entity_id)
-    WITH CLUSTERING ORDER BY (customer_id ASC, search_text ASC, id DESC, entity_id DESC);
+    WITH CLUSTERING ORDER BY (customer_id DESC, search_text ASC, id DESC);
 
-CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_views_by_tenant_and_customer_and_entity_and_search_text AS
+CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_views_by_tenant_and_customer_and_entity AS
     SELECT *
     from thingsboard.entity_views
-    WHERE entity_id IS NOT NULL AND search_text IS NOT NULL AND tenant_id IS NOT NULL AND customer_id IS NOT NULL AND keys IS NOT NULL AND start_ts IS NOT NULL AND end_ts IS NOT NULL AND name IS NOT NULL AND id IS NOT NULL
-    PRIMARY KEY (tenant_id, customer_id, search_text,entity_id, id)
-    WITH CLUSTERING ORDER BY (customer_id ASC, search_text ASC, entity_id DESC, id DESC);
+    WHERE tenant_id IS NOT NULL
+      AND customer_id IS NOT NULL
+      AND entity_id IS NOT NULL
+      AND search_text IS NOT NULL
+      AND id IS NOT NULL
+    PRIMARY KEY (tenant_id, customer_id, entity_id, search_text, id)
+    WITH CLUSTERING ORDER BY (customer_id DESC, entity_id ASC, search_text ASC, id DESC);