Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQL conversion of relative forms #3419

Merged
merged 60 commits into from
May 8, 2024

Conversation

jnsrnhld
Copy link
Collaborator

@jnsrnhld jnsrnhld commented May 3, 2024

No description provided.

jnsrnhld and others added 30 commits April 8, 2024 14:44
This reverts commit 55c33eb.
…s/README.md

Co-authored-by: Torben Meyer <torben.meyer@bakdata.com>
…s/README.md

Co-authored-by: Torben Meyer <torben.meyer@bakdata.com>
…ect/HanaSqlFunctionProvider.java

Co-authored-by: Torben Meyer <torben.meyer@bakdata.com>
…sion' into sql/feature/absolute-form-conversion
…s/README.md

Co-authored-by: awildturtok <1553491+awildturtok@users.noreply.github.com>
jnsrnhld and others added 4 commits April 25, 2024 07:47
…conversion

# Conflicts:
#	backend/src/main/java/com/bakdata/conquery/sql/conversion/dialect/HanaSqlFunctionProvider.java
#	backend/src/main/java/com/bakdata/conquery/sql/conversion/dialect/PostgreSqlFunctionProvider.java
#	backend/src/main/java/com/bakdata/conquery/sql/conversion/dialect/SqlDialect.java
#	backend/src/main/java/com/bakdata/conquery/sql/conversion/forms/FormCteStep.java
#	backend/src/main/java/com/bakdata/conquery/sql/conversion/forms/HanaStratificationFunctions.java
#	backend/src/main/java/com/bakdata/conquery/sql/conversion/forms/README.md
#	backend/src/main/java/com/bakdata/conquery/sql/conversion/forms/StratificationFunctions.java
#	backend/src/main/java/com/bakdata/conquery/sql/conversion/forms/StratificationTableFactory.java
#	backend/src/main/java/com/bakdata/conquery/sql/conversion/query/AbsoluteFormQueryConverter.java
// end date of validity dates is exclusive, but we need the inclusive one
case LATEST -> functionProvider.addDays(DSL.max(validityDate.getEnd()), DSL.val(-1));
case RANDOM -> {
// TODO seed required?
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ich glaube wir hatten darüber mal gesprochen, dass es einen Seed dafür bei euch gibt?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Genau, der ist als Konstante in ConqueryConstants.RANDOM_SEED festgelegt.

Es war nur wichtig, dass der Seed konstant war zur Reproduzierbarkeit von eventuellen Fehlern.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also das Problem ist, dass nach meinem Kenntnisstand für HANA keine Möglichkeit existiert einen Seed zu setzen. Für Postgres schon.

@jnsrnhld jnsrnhld requested a review from awildturtok May 3, 2024 16:43
Comment on lines 90 to 95
protected Field<Date> jumpToNextQuarterStart(Field<Date> date) {
Field<Timestamp> yearStart = dateTruncate(DSL.val("year"), date);
Field<Date> quarterEndInclusive = date.minus(1);
Field<Integer> quarter = functionProvider.extract(DatePart.QUARTER, quarterEndInclusive);
return addQuarters(yearStart, quarter, Offset.NONE);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kann es sein, dass die Funktion mit einem Datum wie z.B. 01.01.2024 das falsche Ergebnis rausgibt.

Statt 01.10.2023, kommt dann 01.10.2024 heraus.

case EARLIEST -> DSL.min(lower(validityDate));
// upper returns the exclusive end date, we want to inclusive one, so we add -1 day
case LATEST -> functionProvider.addDays(DSL.max(upper(validityDate)), DSL.val(-1));
case RANDOM -> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hier bitte auch einen konstanten Seed nutzen

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Man kann in SQL den seed nicht so setzen, wie wir das machen, das müsste dann als CTE in jeder Query passieren

}

@Override
protected Field<Date> jumpToNextQuarterStart(Field<Date> date) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quartal 4 landet im nächsten Jahr

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ist in dem Fall beabsichtigt.

Field<Date> yearStart = jumpToYearStart(dateRange.getEnd());
Field<Date> inclusiveEnd = functionProvider.addDays(dateRange.getEnd(), DSL.val(-1));
Field<Integer> quartersInMonths = getMonthsInQuarters(inclusiveEnd, Offset.NONE);
return jumpToNextQuarterStart(dateRange.getEnd());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minus 1?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch 👍 Danke dir.

}

@Override
public Field<Date> quarterEnd(ColumnDateRange dateRange) {
Field<Timestamp> yearStart = dateTruncate(DSL.val("year"), upper(dateRange));
Field<Date> quarterEndInclusive = upper(dateRange).minus(1);
return jumpToNextQuarterStart(upper(dateRange));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

links hattest du auch noch minus 1, kannst du bitte einen kommentar dran machen, wrum du das nicht brauchst?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ich brauche sie, hatte es allerdings an der falschen Stelle in der jumpToNextQuarterStart() Methode.

case EARLIEST -> DSL.min(lower(validityDate));
// upper returns the exclusive end date, we want to inclusive one, so we add -1 day
case LATEST -> functionProvider.addDays(DSL.max(upper(validityDate)), DSL.val(-1));
case RANDOM -> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Man kann in SQL den seed nicht so setzen, wie wir das machen, das müsste dann als CTE in jeder Query passieren

jnsrnhld and others added 6 commits May 7, 2024 14:08
…s/RelativeStratification.java

Co-authored-by: awildturtok <1553491+awildturtok@users.noreply.github.com>
…s/PostgresStratificationFunctions.java

Co-authored-by: MT <12283268+thoniTUB@users.noreply.github.com>
Base automatically changed from sql/feature/entity-date-query-conversion to develop May 7, 2024 14:33
jnsrnhld added 8 commits May 7, 2024 18:34
This reverts commit 37d441c6efce4e423b09e694af19b2eca45029ac.
…ersion

# Conflicts:
#	backend/src/main/java/com/bakdata/conquery/sql/conversion/dialect/SqlDialect.java
#	backend/src/main/java/com/bakdata/conquery/sql/conversion/forms/FormCteStep.java
#	backend/src/main/java/com/bakdata/conquery/sql/conversion/forms/HanaStratificationFunctions.java
#	backend/src/main/java/com/bakdata/conquery/sql/conversion/forms/PostgresStratificationFunctions.java
#	backend/src/main/java/com/bakdata/conquery/sql/conversion/forms/README.md
#	backend/src/main/java/com/bakdata/conquery/sql/conversion/forms/StratificationFunctions.java
#	backend/src/main/java/com/bakdata/conquery/sql/conversion/forms/StratificationTableFactory.java
#	backend/src/main/java/com/bakdata/conquery/sql/conversion/query/AbsoluteFormQueryConverter.java
#	backend/src/main/java/com/bakdata/conquery/sql/conversion/query/EntityDateQueryConverter.java
#	backend/src/main/java/com/bakdata/conquery/sql/conversion/query/FormConversionHelper.java
@jnsrnhld
Copy link
Collaborator Author

jnsrnhld commented May 7, 2024

@thoniTUB @awildturtok Vielen dank nochmal für die Hinweise zu den Edge-Cases, da gab es noch einige Fehler. Ich habe dahingehend auch nochmal die Testcases angepasst. Da ist jetzt auch der Edge-Case mit 31.12./01.01. mit dabei.

@jnsrnhld jnsrnhld requested a review from thoniTUB May 7, 2024 16:55
@jnsrnhld jnsrnhld merged commit f26749d into develop May 8, 2024
6 checks passed
@delete-merged-branch delete-merged-branch bot deleted the sql/feature/relative-form-conversion branch May 8, 2024 08:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants