Skip to content

Commit 46e70ab

Browse files
committed
structurize (normage) exclusion rule
1 parent 1bada6b commit 46e70ab

File tree

2 files changed

+54
-18
lines changed

2 files changed

+54
-18
lines changed

arc-core/src/main/java/fr/insee/arc/core/service/engine/normage/NormageEngine.java

Lines changed: 51 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ public void execute() throws Exception {
151151

152152
} else {
153153

154+
154155
// split structure blocks
155156
String[] ss=jointure.split(XMLComplexeHandlerCharger.JOINXML_STRUCTURE_BLOCK);
156157

@@ -218,6 +219,14 @@ public void execute() throws Exception {
218219

219220
}
220221

222+
223+
224+
private String normalizeTag (String tag)
225+
{
226+
return " "+"i_"+tag.toUpperCase()+" ";
227+
228+
}
229+
221230
@SuppressWarnings("unused")
222231
private String optimisation96(String jointure, int subjoinNumber) {
223232
StaticLoggerDispatcher.info("optimisation96()", LOGGER);
@@ -272,10 +281,6 @@ private String optimisation96(String jointure, int subjoinNumber) {
272281

273282
}
274283

275-
// r=r+"INSERT INTO "+this.tableNormageOKTemp+" SELECT "+fieldsToBeInserted+"
276-
// FROM {table_destination}; \n ";
277-
278-
// bug mémoire : analyze sur les tables générées;
279284
StringBuilder analyze = new StringBuilder();
280285

281286
Pattern p = Pattern.compile("create temporary table ([^ ]+) as ");
@@ -1627,6 +1632,40 @@ private String appliquerRegleReduction(HashMap<String, ArrayList<String>> regle,
16271632
return jointure;
16281633
}
16291634

1635+
1636+
private Integer excludeFileonTimeOut(HashMap<String, ArrayList<String>> regle)
1637+
{
1638+
for (int j = 0; j < regle.get("id_regle").size(); j++) {
1639+
String type = regle.get("id_classe").get(j);
1640+
if (type.equals("exclusion")) {
1641+
return Integer.parseInt(regle.get("rubrique").get(j));
1642+
}
1643+
}
1644+
return null;
1645+
}
1646+
1647+
1648+
private String applyQueryPlanParametersOnJointure(String query, Integer statementTimeOut)
1649+
{
1650+
return applyQueryPlanParametersOnJointure(new PreparedStatementBuilder(query), statementTimeOut).getQuery().toString();
1651+
}
1652+
1653+
1654+
private PreparedStatementBuilder applyQueryPlanParametersOnJointure(PreparedStatementBuilder query, Integer statementTimeOut)
1655+
{
1656+
PreparedStatementBuilder r=new PreparedStatementBuilder();
1657+
1658+
r.append("set enable_nestloop=off;\n");
1659+
r.append((statementTimeOut==null)?"":"set statement_timeout="+statementTimeOut.toString()+";\n");
1660+
r.append("commit;");
1661+
r.append(query);
1662+
r.append("set enable_nestloop=on;\n");
1663+
r.append("reset statement_timeout;");
1664+
1665+
r.setQuery(new StringBuilder(r.getQuery().toString().replace(" insert into ", "commit; insert into ")));
1666+
return r;
1667+
}
1668+
16301669
/**
16311670
* execute query with partition if needed
16321671
* @param regle
@@ -1658,9 +1697,7 @@ private void executerJointure(HashMap<String, ArrayList<String>> regle, String n
16581697

16591698
// No partition found; normal execution
16601699
UtilitaireDao.get("arc").executeImmediate(connection,
1661-
"set enable_nestloop=off;\n"
1662-
+ replaceQueryParameters(jointure, norme, validite, periodicite, jointure, validiteText, id_source)
1663-
+ "set enable_nestloop=on;\n"
1700+
applyQueryPlanParametersOnJointure(replaceQueryParameters(jointure, norme, validite, periodicite, jointure, validiteText, id_source),null)
16641701
);
16651702

16661703
}
@@ -1694,6 +1731,8 @@ private void executerJointureWithPartition(HashMap<String, ArrayList<String>> re
16941731
String partitionTableName="";
16951732
String partitionIdentifier=" m_"+element+" ";
16961733

1734+
Integer statementTimeOut=excludeFileonTimeOut(regle);
1735+
16971736
if (blocCreate.contains(partitionIdentifier))
16981737
{
16991738
// get the tablename
@@ -1725,19 +1764,19 @@ private void executerJointureWithPartition(HashMap<String, ArrayList<String>> re
17251764
// partition if and only if enough records
17261765
if (total>=minSize)
17271766
{
1767+
17281768
String partitionTableNameWithAllRecords="all_"+partitionTableName;
17291769

17301770
// rename the table to split
17311771
StringBuilder bloc3=new StringBuilder("alter table "+partitionTableName+" rename to "+partitionTableNameWithAllRecords+";");
17321772
UtilitaireDao.get("arc").executeImmediate(connection,bloc3);
17331773

17341774
PreparedStatementBuilder bloc4=new PreparedStatementBuilder();
1735-
bloc4.append("\n set enable_nestloop=off;\n");
17361775
bloc4.append("\n drop table if exists "+partitionTableName+";");
17371776
bloc4.append("\n create temporary table "+partitionTableName+" as select * from "+partitionTableNameWithAllRecords+" where "+partitionIdentifier+">=?::int and "+partitionIdentifier+"<?::int;");
17381777
bloc4.append(blocInsert);
1739-
bloc4.append("\n set enable_nestloop=on;\n");
1740-
1778+
1779+
bloc4=applyQueryPlanParametersOnJointure(bloc4, statementTimeOut);
17411780

17421781
// iterate through chunks
17431782
int iterate=1;
@@ -1753,14 +1792,9 @@ private void executerJointureWithPartition(HashMap<String, ArrayList<String>> re
17531792

17541793
}
17551794
else
1795+
// no partitions needed
17561796
{
1757-
StringBuilder bloc3=new StringBuilder();
1758-
1759-
bloc3.append("\n set enable_nestloop=off;\n");
1760-
bloc3.append(blocInsert);
1761-
bloc3.append("\n set enable_nestloop=on;\n");
1762-
1763-
UtilitaireDao.get("arc").executeImmediate(connection,bloc3);
1797+
UtilitaireDao.get("arc").executeImmediate(connection,applyQueryPlanParametersOnJointure(blocInsert,statementTimeOut));
17641798
}
17651799
}
17661800

arc-core/src/main/resources/BdD/script_global_phase_normage.sql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ CREATE TABLE IF NOT EXISTS arc.ext_type_normage
2525
);
2626
INSERT INTO arc.ext_type_normage values ('relation','1'),('cartesian','2'),('suppression','3'),('unicité','4') ON CONFLICT DO NOTHING;
2727
INSERT INTO arc.ext_type_normage values ('reduction','5') ON CONFLICT DO NOTHING;
28-
INSERT INTO arc.ext_type_normage values ('partition','5') ON CONFLICT DO NOTHING;
28+
INSERT INTO arc.ext_type_normage values ('partition','6') ON CONFLICT DO NOTHING;
29+
INSERT INTO arc.ext_type_normage values ('exclusion','7') ON CONFLICT DO NOTHING;
30+
2931

3032
do $$ begin CREATE TRIGGER tg_insert_normage BEFORE INSERT ON arc.ihm_normage_regle FOR EACH ROW EXECUTE PROCEDURE arc.insert_controle(); exception when others then end; $$;
3133

0 commit comments

Comments
 (0)