Skip to content

Commit

Permalink
Fix EXISTS select conversion on connector level (#3493)
Browse files Browse the repository at this point in the history
  • Loading branch information
jnsrnhld authored Jul 15, 2024
1 parent a845aef commit edc3bf1
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.bakdata.conquery.sql.conversion.cqelement.concept;

import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;

import com.bakdata.conquery.sql.conversion.model.QueryStep;
Expand Down Expand Up @@ -39,8 +38,13 @@ private Selects collectSelects(CQTableContext tableContext) {
List<SqlSelect> forAggregationFilterStep =
tableContext.allSqlSelects().stream()
.flatMap(sqlSelects -> sqlSelects.getFinalSelects().stream())
.filter(Predicate.not(SqlSelect::isUniversal))
.map(sqlSelect -> sqlSelect.qualify(previous.getCteName()))
.map(sqlSelect -> {
// universal selects like an ExistsSelect have no predecessor in preceding CTE
if (sqlSelect.isUniversal()) {
return sqlSelect;
}
return sqlSelect.qualify(previous.getCteName());
})
.collect(Collectors.toList());

return Selects.builder()
Expand Down
5 changes: 5 additions & 0 deletions backend/src/test/resources/tests/sql/combined/combined.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
{
"id": "concept.connector",
"selects": [
"concept.connector.exists",
"concept.connector.event-date",
"concept.connector.event_duration_sum",
"concept.connector.first_value",
Expand Down Expand Up @@ -83,6 +84,10 @@
}
],
"selects": [
{
"type": "EXISTS",
"name": "exists"
},
{
"type": "EVENT_DATE_UNION",
"name": "event-date"
Expand Down
12 changes: 6 additions & 6 deletions backend/src/test/resources/tests/sql/combined/expected.csv
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
result,dates,concept exists,concept event-date,concept event_duration_sum,concept connector event-date,concept connector event_duration_sum,concept connector first_value,concept connector sum_distinct,concept tree_label first_test_column
1,"{2012-01-01/2012-01-01,2013-01-01/2013-12-31,2015-01-01/2015-01-01}",1,"{2012-01-01/2012-01-01,2013-01-01/2013-12-31,2015-01-01/2015-01-01}",367,"{2012-01-01/2012-01-01,2013-01-01/2013-12-31}",366,1.0,2.0,A1
2,"{2010-07-15/2010-07-15,2012-01-01/2012-01-02,2012-01-05/2012-01-10}",1,"{2010-07-15/2010-07-15,2012-01-01/2012-01-02,2012-01-05/2012-01-10}",9,"{2012-01-01/2012-01-02,2012-01-05/2012-01-10}",8,1.01,2.01,B2
3,"{2012-01-01/2012-01-03,2013-11-10/2013-11-10}",1,"{2012-01-01/2012-01-03,2013-11-10/2013-11-10}",4,{2012-01-01/2012-01-03},3,0.5,0.5,A1
4,"{2012-01-01/2012-01-04,2012-11-11/2012-11-11}",1,"{2012-01-01/2012-01-04,2012-11-11/2012-11-11}",5,{2012-01-01/2012-01-04},4,0.5,0.5,B2
5,{2012-01-01/2012-01-05},1,{2012-01-01/2012-01-05},5,{2012-01-01/2012-01-05},5,1.0,1.5,
result,dates,concept exists,concept event-date,concept event_duration_sum,concept connector exists,concept connector event-date,concept connector event_duration_sum,concept connector first_value,concept connector sum_distinct,concept tree_label first_test_column
1,"{2012-01-01/2012-01-01,2013-01-01/2013-12-31,2015-01-01/2015-01-01}",1,"{2012-01-01/2012-01-01,2013-01-01/2013-12-31,2015-01-01/2015-01-01}",367,1,"{2012-01-01/2012-01-01,2013-01-01/2013-12-31}",366,1.0,2.0,A1
2,"{2010-07-15/2010-07-15,2012-01-01/2012-01-02,2012-01-05/2012-01-10}",1,"{2010-07-15/2010-07-15,2012-01-01/2012-01-02,2012-01-05/2012-01-10}",9,1,"{2012-01-01/2012-01-02,2012-01-05/2012-01-10}",8,1.01,2.01,B2
3,"{2012-01-01/2012-01-03,2013-11-10/2013-11-10}",1,"{2012-01-01/2012-01-03,2013-11-10/2013-11-10}",4,1,{2012-01-01/2012-01-03},3,0.5,0.5,A1
4,"{2012-01-01/2012-01-04,2012-11-11/2012-11-11}",1,"{2012-01-01/2012-01-04,2012-11-11/2012-11-11}",5,1,{2012-01-01/2012-01-04},4,0.5,0.5,B2
5,{2012-01-01/2012-01-05},1,{2012-01-01/2012-01-05},5,1,{2012-01-01/2012-01-05},5,1.0,1.5,
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
pid,datum_start,datum_end
1,2014-06-30,2015-06-30
2,2014-06-30,2015-06-30
2,2014-06-30,2015-06-30
3,2014-06-30,2015-06-30
4,2014-06-30,2015-06-30
5,2014-06-30,2015-06-30
5,2014-06-30,2015-06-30
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"type": "QUERY_TEST",
"sqlSpec": {
"isEnabled": true
},
"label": "EXISTS select on connector",
"expectedCsv": "tests/sql/selects/exists/exists_on_connector/expected.csv",
"query": {
"type": "CONCEPT_QUERY",
"root": {
"ids": [
"concept"
],
"type": "CONCEPT",
"tables": [
{
"id": "concept.connector",
"selects": "concept.connector.exists"
}
]
}
},
"concepts": [
{
"name": "concept",
"type": "TREE",
"connectors": [
{
"label": "connector",
"table": "exists_table",
"selects": {
"type": "EXISTS",
"name": "exists"
}
}
]
}
],
"content": {
"tables": [
{
"csv": "tests/sql/selects/exists/exists_on_connector/content.csv",
"name": "exists_table",
"primaryColumn": {
"name": "pid",
"type": "STRING"
},
"columns": [
{
"name": "datum_start",
"type": "DATE"
},
{
"name": "datum_end",
"type": "DATE"
}
]
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
result,dates,concept exists
2,{},1
4,{},1
3,{},1
5,{},1
1,{},1

0 comments on commit edc3bf1

Please sign in to comment.