diff --git a/backend/src/main/java/com/bakdata/conquery/sql/conversion/cqelement/concept/AggregationFilterCte.java b/backend/src/main/java/com/bakdata/conquery/sql/conversion/cqelement/concept/AggregationFilterCte.java index 0ada55f076..85179b7043 100644 --- a/backend/src/main/java/com/bakdata/conquery/sql/conversion/cqelement/concept/AggregationFilterCte.java +++ b/backend/src/main/java/com/bakdata/conquery/sql/conversion/cqelement/concept/AggregationFilterCte.java @@ -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; @@ -39,8 +38,13 @@ private Selects collectSelects(CQTableContext tableContext) { List 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() diff --git a/backend/src/test/resources/tests/sql/combined/combined.json b/backend/src/test/resources/tests/sql/combined/combined.json index 3e9b99ce63..e7a04869d9 100644 --- a/backend/src/test/resources/tests/sql/combined/combined.json +++ b/backend/src/test/resources/tests/sql/combined/combined.json @@ -16,6 +16,7 @@ { "id": "concept.connector", "selects": [ + "concept.connector.exists", "concept.connector.event-date", "concept.connector.event_duration_sum", "concept.connector.first_value", @@ -83,6 +84,10 @@ } ], "selects": [ + { + "type": "EXISTS", + "name": "exists" + }, { "type": "EVENT_DATE_UNION", "name": "event-date" diff --git a/backend/src/test/resources/tests/sql/combined/expected.csv b/backend/src/test/resources/tests/sql/combined/expected.csv index a87c0031ab..4902ce95be 100644 --- a/backend/src/test/resources/tests/sql/combined/expected.csv +++ b/backend/src/test/resources/tests/sql/combined/expected.csv @@ -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, diff --git a/backend/src/test/resources/tests/sql/selects/exists/exists_on_connector/content.csv b/backend/src/test/resources/tests/sql/selects/exists/exists_on_connector/content.csv new file mode 100644 index 0000000000..f3fe352607 --- /dev/null +++ b/backend/src/test/resources/tests/sql/selects/exists/exists_on_connector/content.csv @@ -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 diff --git a/backend/src/test/resources/tests/sql/selects/exists/exists_on_connector/exists.spec.json b/backend/src/test/resources/tests/sql/selects/exists/exists_on_connector/exists.spec.json new file mode 100644 index 0000000000..c3592c4365 --- /dev/null +++ b/backend/src/test/resources/tests/sql/selects/exists/exists_on_connector/exists.spec.json @@ -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" + } + ] + } + ] + } +} diff --git a/backend/src/test/resources/tests/sql/selects/exists/exists_on_connector/expected.csv b/backend/src/test/resources/tests/sql/selects/exists/exists_on_connector/expected.csv new file mode 100644 index 0000000000..2760828d6b --- /dev/null +++ b/backend/src/test/resources/tests/sql/selects/exists/exists_on_connector/expected.csv @@ -0,0 +1,6 @@ +result,dates,concept exists +2,{},1 +4,{},1 +3,{},1 +5,{},1 +1,{},1