Skip to content

Commit

Permalink
Merge pull request #2205 from Kajal-NEC/issue2204
Browse files Browse the repository at this point in the history
Creates index as per data model
  • Loading branch information
fgalan authored Dec 13, 2022
2 parents bd09001 + 6210236 commit 330102e
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 14 deletions.
7 changes: 4 additions & 3 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[cygnus-common] Upgrade postgresql from 42.4.1 to 42.4.3
[cygnus-common] OracleSQL backend (#2195)
[cygnus-ngsi] OracleSQL ngsi sink added (for OracleS 11g and 12c) (#2195)
[cygnus-common] MongoDB indexes are created depending on DM (#2204)
[cygnus-common] Upgrade postgresql from 42.4.1 to 42.4.3
[cygnus-common] OracleSQL backend (#2195)
[cygnus-ngsi] OracleSQL ngsi sink added (for OracleS 11g and 12c) (#2195)
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,26 @@ public void createCollection(String dbName, String collectionName, long dataExpi
BasicDBObject keys;
IndexOptions options;
try {
keys = new BasicDBObject()
.append("_id.entityId", 1)
.append("_id.entityType", 1)
.append("_id.attrName", 1)
.append("_id.resolution", 1)
.append("_id.origin", 1);
keys = new BasicDBObject();
switch(dataModel) {
case DMBYSERVICEPATH:
keys.append("_id.entityId", 1)
.append("_id.entityType", 1)
.append("_id.attrName", 1)
.append("_id.resolution", 1)
.append("_id.origin", 1);
break;
case DMBYENTITY:
keys.append("_id.attrName", 1)
.append("_id.resolution", 1)
.append("_id.origin", 1);
break;
case DMBYATTRIBUTE:
keys.append("_id.resolution", 1)
.append("_id.origin", 1);
break;
default:
}
options = new IndexOptions().name("cyg_agg_opt");
db.getCollection(collectionName).createIndex(keys, options);
} catch (Exception e) {
Expand Down Expand Up @@ -162,14 +176,33 @@ public void createCollection(String dbName, String collectionName, long collecti
} // try catch

// check STH indexes documentation at https://github.com/telefonicaid/fiware-sth-comet/blob/master/doc/manuals/db_indexes.md
//Index creation based on data model
BasicDBObject keys;
IndexOptions options;
try {
keys = new BasicDBObject()
.append("entityId", 1)
.append("entityType", 1)
.append("attrName", 1)
.append("recvTime", 1);
keys = new BasicDBObject();
switch(dataModel) {
case DMBYSERVICEPATH:
keys.append("recvTime", 1)
.append("entityId", 1)
.append("entityType", 1)
.append("attrName", 1)
.append("attrType",1)
.append("attrValue",1);
break;
case DMBYENTITY:
keys.append("recvTime", 1)
.append("attrName", 1)
.append("attrType",1)
.append("attrValue",1);
break;
case DMBYATTRIBUTE:
keys.append("recvTime", 1)
.append("attrType",1)
.append("attrValue",1);
break;
default:
}
options = new IndexOptions().name("cyg_raw_opt");
db.getCollection(collectionName).createIndex(keys, options);
} catch (Exception e) {
Expand Down

0 comments on commit 330102e

Please sign in to comment.