forCDateSet(CDateSet dateset, SharedAliases alias){
+ if (dateset.isEmpty()) {
+ // Need to explicitly provide an empty result
+ return List.of(emptyColumnDateRange().as(alias.getAlias()));
+ }
+
+ return dateset.asRanges().stream()
+ .map(this::forCDateRange)
+ .map(dateRange -> dateRange.as(alias.getAlias()))
+ .toList();
+ }
/**
* Creates a {@link ColumnDateRange} for a tables {@link ValidityDate}.
@@ -86,6 +104,26 @@ Collection extends OrderField>> orderByValidityDates(
ColumnDateRange forValidityDate(ValidityDate validityDate);
+ default Condition isNotEmptyValidityDate(ValidityDate validityDate) {
+ ColumnId singleColumn = validityDate.getColumn();
+ if (singleColumn != null) {
+ return field(name(singleColumn.getTable().getTable(), singleColumn.getColumn())).isNotNull();
+ }
+
+ ColumnId startColumn = validityDate.getStartColumn();
+ ColumnId endColumn = validityDate.getEndColumn();
+
+ Condition isNotEmptyStart = field(name(startColumn.getTable().getTable(), startColumn.getColumn())).isNotNull();
+ Condition isNotEmptyEnd = field(name(endColumn.getTable().getTable(), endColumn.getColumn())).isNotNull();
+
+ return isNotEmptyStart.or(isNotEmptyEnd);
+ }
+
+ /**
+ * Creates a {@link ColumnDateRange} of maximum range.
+ */
+ ColumnDateRange allRange();
+
/**
* Creates a {@link ColumnDateRange} for a tables {@link CQTable}s validity date. The validity dates bounds will be restricted by the given date
* restriction.
@@ -127,20 +165,30 @@ Collection extends OrderField>> orderByValidityDates(
*
* Example: {[-∞,2013-11-11),[2015-11-10,∞)}
*/
- Field daterangeStringAggregation(ColumnDateRange columnDateRange);
+ Field> dateRangeAggregation(ColumnDateRange columnDateRange);
/**
* Combines the start and end column of a validity date entry into one compound string expression.
*
* Example: [2013-11-10,2013-11-11)
*/
- Field daterangeStringExpression(ColumnDateRange columnDateRange);
+ Field> dateRangeToField(ColumnDateRange columnDateRange);
/**
* Calculates the date distance in the given {@link ChronoUnit} between an exclusive end date and an inclusive start date.
*/
Field dateDistance(ChronoUnit datePart, Field startDate, Field endDate);
+ /**
+ * Extract the lower inclusive bound of a daterange field. Not supported for dialects without range type support.
+ */
+ Field lower(Field> daterange);
+
+ /**
+ * Extract the upper exclusive bound of a daterange field. Not supported for dialects without range type support.
+ */
+ Field upper(Field> daterange);
+
Field addDays(Field dateColumn, Field amountOfDays);
Field random(Field column);
@@ -153,24 +201,30 @@ Collection extends OrderField>> orderByValidityDates(
Field yearQuarter(Field dateField);
default Field stringAggregation(Field stringField, Field delimiter, List> orderByFields) {
- return DSL.field(
+ return field(
"{0}({1}, {2} {3})",
String.class,
- DSL.keyword("string_agg"),
+ keyword("string_agg"),
stringField,
delimiter,
- DSL.orderBy(orderByFields)
+ orderBy(orderByFields)
);
}
- default Field concat(List> fields) {
- String concatenated = fields.stream()
- // if a field is null, the whole concatenation would be null - but we just want to skip this field in this case,
- // thus concat an empty string
- .map(field -> DSL.when(field.isNull(), DSL.val("")).otherwise(field))
- .map(Field::toString)
- .collect(Collectors.joining(SQL_UNIT_SEPARATOR));
- return DSL.field(concatenated, String.class);
+ ColumnDateRange allRangeIf(Condition condition);
+
+ /**
+ * Render an array for Conquery processing.
+ */
+ default Field> arrayOut(List> fields) {
+ String concatenated =
+ fields.stream()
+ // if a field is null, the whole concatenation would be null - but we just want to skip this field in this case,
+ // thus concat an empty string
+ .map(field -> field)
+ .map(Field::toString)
+ .collect(Collectors.joining(SQL_UNIT_SEPARATOR));
+ return field(concatenated, String.class);
}
default Field