Cache Implementation Updates#1371
Conversation
|
Note about these updates: 1: I adjusted the hash calculation to strip out names/descriptions of inclusion rules so that simple renames of those fields won't generate an entirely new design hash and result. It does mean that the values that show up in the UI will be based on the last-generated design. In addition, this resolves a SQL Injection vulnerability. 2: we now key our cache results on a design hash, and not a result identifier. 3: I would like to add additional tests to verify some of the design hash logic. I will make those updates soon. 4: I removed the functionality of 'get next result ID' because the implementation would not work: if two threads call 5: Because of 4, I removed tests that tested the 'nextReslut' value, but I left the test 6: We always 'generate with inclusion statistics', even tho generating a cohort characterization or treatment pathways doesn't use that information. The beauty of it is that if someone does want to look at the inclusion summary, they can go into the cohort, generate (from the cache) and see the output. 7: I specifically avoided making any changes to the WebAPI tables. The approach proposed here does make some columns redundant (such as the result_id = design_hash) but I wanted to limit the scope to changes. If requested, we can make additional migrations to adjust the WebAPI tables. |
| InclusionRule r = inclusionRules.get(i); | ||
| String[] values = new String[]{((Integer) i).toString(), r.name, MoreObjects.firstNonNull(r.description, "")}; | ||
|
|
||
| String inclusionRuleSql = SqlRender.renderSql(insertSql, names, values); |
There was a problem hiding this comment.
Unless I'm mistaken, this code that renders the Inclusion Rule names directly into a SQL string is a source of sql injection. The update to do it via insertInclusionRules will use prepared statements.
| } | ||
|
|
||
| String expressionSql = expressionQueryBuilder.buildExpressionQuery(request.getExpression(), options); | ||
| expressionSql = SqlRender.renderSql( |
There was a problem hiding this comment.
The below block is the way to override the result table names so that they write into a cache. This was the least invasive way I could think of to implement this functionality.
Introduced cohort cache tables. Added new test cases. Updated results schema DDL. Updated pom.xml for workaround in vs.code Fixes #1353.
4ec9b88 to
d240d9b
Compare
anthonysena
left a comment
There was a problem hiding this comment.
@chrisknoll - these changes are working well from my testing. Had a few questions/comments about the code itself so let me know if you'd like to discuss in more detail. Thanks!
|
@chrisknoll - let me know if you want to test the SQL Server migration before we merge this into master. |
|
@anthonysena : I found an issue on sql migration where you can't modify a column that is used in a constraint. For consistency, I did this on PG and oracle migrations as well, but I can't test them. You already probably have a PG migration complete on your local env, so I can either revert the changes in the PR related to PG or you can do a 'soft rollback' on the tables to add the result_id back to the table (so that the migration can drop it again). Your call, I'll make any change you require. |
|
@chrisknoll - thanks for reviewing & testing those out. I re-tested the PG migration on my side and it worked well. I think we are set now. Thanks! |
|
@chrisknoll hi, your PR overrides PR made by @pavgra and currently estimation generation does not work. |
|
@ssuvorov-fls sorry for this regression. To confirm, it is due to the changes in this function signature: https://github.com/OHDSI/WebAPI/pull/1371/files#diff-378ca22851bb7e5375071dc6718e5f9fR14 since the target* params were removed? |
|
@anthonysena I can't say exactly, I've just found that cohort_id field name is not passed to sql script and estimation analysis execution can not be created now |
|
@ssuvorov-fls: can you find out where the issue is? This was tested on CC and pathway generation (where a local cohort table is defined) as well as regular cohort generation (where there is no local cohort temp table). In those cases, it generates the cohort into the cache, and the result is red from the cache into the local cohort. How is estimation working differently from that? In addition, the test cases related to cohort generation passes, so if there is a failure we have a gap in our test cases. |
|
@chrisknoll it fails for estimation generation. There is a field '@cohort_id_field_name' in sql scripts from circe and currently it is not replaced with value. You can see how it is replaced in #1318 |
|
@ssuvorov-fls , It is still unclear as to why you are getting the failure. We don't need to specify a cohort_id_field_name because the generation util writes to the cache, and we don't need to paramaterize that. The This is where it's set in GenerationUtils.buildGenerationSql: Is it possible you don't have the correct results schema tables? Could you provide the exact error you are getting? |
|
@ssuvorov-fls I'd suggest working with @olga-ganina to open a new issue for 2.8 once you've collected more details around this problem. It is unclear to me how Arachne EE is using WebAPI to perform the estimation generation. |
Introduced cohort cache tables.
Added/Removed test cases.
Updated results schema DDL.
Updated pom.xml for workaround in vs.code
Fixes #1353.