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

support for date/time comparisons #1160

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
c365f3d
support for arithmetic operations
jgaleotti Jan 14, 2025
f8a904f
work in progress. Support for Date/Time
jgaleotti Jan 15, 2025
6ed289c
corrected expected types
jgaleotti Jan 15, 2025
57042f1
small change to order of evaluation
jgaleotti Jan 15, 2025
a0bc481
Merge remote-tracking branch 'origin/master' into sql_heuristics_for_…
jgaleotti Jan 20, 2025
7380b3e
Merge remote-tracking branch 'origin/master' into sql_heuristics_for_…
jgaleotti Jan 21, 2025
f7ef11f
Merge remote-tracking branch 'refs/remotes/origin/master' into sql_he…
jgaleotti Jan 23, 2025
f436be3
implementing comparison among Date/Time column types
jgaleotti Jan 23, 2025
f9ab8a8
Merge remote-tracking branch 'origin/master' into sql_heuristics_for_…
jgaleotti Jan 24, 2025
9481fc3
Merge remote-tracking branch 'refs/remotes/origin/master' into sql_he…
jgaleotti Jan 26, 2025
fb17023
parsing of dateTime Literals in SQL
jgaleotti Jan 26, 2025
c6e975d
refactors to improve code quality
jgaleotti Jan 26, 2025
0143a71
test fixes
jgaleotti Jan 27, 2025
3ea08dd
computing heuristic score for hex values, ranges, etc.
jgaleotti Jan 27, 2025
5894609
support for NULL values in operations / added Javadocs
jgaleotti Jan 29, 2025
a5f8e4b
minor refactors and changes to javadocs
jgaleotti Jan 29, 2025
18d81c2
Merge remote-tracking branch 'origin/master' into sql_heuristics_for_…
jgaleotti Jan 30, 2025
47663d9
support for left/right joins
jgaleotti Jan 31, 2025
8f3441d
Merge remote-tracking branch 'origin/master' into sql_heuristics_for_…
jgaleotti Feb 1, 2025
45d51a6
fixing javadocs errors and warnings
jgaleotti Feb 1, 2025
a361b14
Merge remote-tracking branch 'origin/master' into sql_heuristics_for_…
jgaleotti Feb 3, 2025
37c5278
refactor of test cases
jgaleotti Feb 4, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ public static Truthness getEqualityTruthness(double a, double b) {
);
}


/**
* Returns a truthness value for comparing how close a length was to 0.
* @param len a positive value for a length
* @return
*/
Expand All @@ -96,6 +96,25 @@ public static Truthness buildAndAggregationTruthness(Truthness... truthnesses) {
return new Truthness(averageOfTrue, falseOrAverageFalse);
}

public static Truthness buildOrAggregationTruthness(Truthness... truthnesses) {
jgaleotti marked this conversation as resolved.
Show resolved Hide resolved
double trueOrAverageTrue = trueOrAverageTrue(truthnesses);
double averageOfFalse = averageOfFalse(truthnesses);
return new Truthness(trueOrAverageTrue, averageOfFalse);
}

public static Truthness buildXorAggregationTruthness(Truthness left, Truthness right) {
jgaleotti marked this conversation as resolved.
Show resolved Hide resolved
Truthness leftAndNotRight = buildAndAggregationTruthness(left,right.invert());
Truthness notLeftAndRight = buildAndAggregationTruthness(left.invert(),right);
Truthness orAggregation = buildOrAggregationTruthness(leftAndNotRight, notLeftAndRight);
return orAggregation;
}

/**
* Returns an average of the <code>ofTrue</code> values for the truthnesses.
*
* @param truthnesses
* @return
*/
private static double averageOfTrue(Truthness... truthnesses) {
checkValidTruthnesses(truthnesses);
double[] getOfTrueValues = Arrays.stream(truthnesses).mapToDouble(Truthness::getOfTrue)
Expand All @@ -109,6 +128,13 @@ private static void checkValidTruthnesses(Truthness[] truthnesses) {
}
}

/**
* Computes an average of the given values.
* If no values are given, an <code>IllegalArgumentException</code> is thrown.
*
* @param values a non empty list of double values.
* @return
*/
private static double average(double... values) {
if (values == null || values.length == 0) {
throw new IllegalArgumentException("null or empty values");
Expand All @@ -120,13 +146,26 @@ private static double average(double... values) {
return total / values.length;
}

/**
* Returns the average of the <code>ofFalse</code> values for the truthnesses.
*
* @param truthnesses
* @return
*/
private static double averageOfFalse(Truthness... truthnesses) {
checkValidTruthnesses(truthnesses);
double[] getOfFalseValues = Arrays.stream(truthnesses).mapToDouble(Truthness::getOfFalse)
.toArray();
return average(getOfFalseValues);
}

/**
* Returns 1.0d if any of the truthnesses is false, otherwise returns the average of the <code>ofFalse</code> values
* for the truthnesses.
*
* @param truthnesses
* @return
*/
private static double falseOrAverageFalse(Truthness... truthnesses) {
checkValidTruthnesses(truthnesses);
if (Arrays.stream(truthnesses).anyMatch(t -> t.isFalse())) {
Expand All @@ -136,11 +175,34 @@ private static double falseOrAverageFalse(Truthness... truthnesses) {
}
}

/**
* Returns 1.0d if any of the truthnesses is true, otherwise returns the average of the <code>ofTrue</code> values
* for the truthnesses.
*
* @param truthnesses
* @return
*/
private static double trueOrAverageTrue(Truthness... truthnesses) {
checkValidTruthnesses(truthnesses);
if (Arrays.stream(truthnesses).anyMatch(t -> t.isTrue())) {
return 1.0d;
} else {
return averageOfTrue(truthnesses);
}
}

/**
* Returns
* @param base
* @param ofTrueToScale
* @return
*/
public static Truthness buildScaledTruthness(double base, double ofTrueToScale) {
final double scaledOfTrue = DistanceHelper.scaleHeuristicWithBase(ofTrueToScale, base);
final double ofFalse = 1.0d;
return new Truthness(scaledOfTrue, ofFalse);
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public static Instant getAsInstant(String content) {
List<Function<String, Instant>> parsers = Arrays.asList(
s -> ZonedDateTime.parse(s).toInstant(),
Instant::parse,
s -> OffsetDateTime.parse(s, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ssXXX")).toInstant(),
s -> OffsetDateTime.parse(s, DateTimeFormatter.ofPattern("uuuu-MM-dd'T'HH:mm:ss.SSSX")).toInstant(),
s -> {
/*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package org.evomaster.client.java.sql.internal;

import java.sql.Time;
import java.time.*;

public class ConversionHelper {

public static Instant convertToInstant(Object object) {
if (object ==null) {
return null;
} else if (object instanceof Time) {
String timeAsString = object.toString();
return ColumnTypeParser.getAsInstant(timeAsString);
} else if (object instanceof java.sql.Date) {
String dateAsString = object.toString();
return ColumnTypeParser.getAsInstant(dateAsString);
} else if (object instanceof java.util.Date) {
return ((java.util.Date) object).toInstant();
} else if (object instanceof OffsetDateTime) {
return ((OffsetDateTime) object).toInstant();
} else if (object instanceof OffsetTime) {
OffsetTime offsetTime = (OffsetTime) object;
LocalDate localDate = LocalDate.of(1970, 1, 1);
LocalDateTime localDateTime = LocalDateTime.of(localDate, offsetTime.toLocalTime());
OffsetDateTime offsetDateTime = localDateTime.atOffset(offsetTime.getOffset());
return offsetDateTime.toInstant();
} else if (object instanceof Long) {
Long year = (Long) object;
String yearAsDate = year + "-01-01";
return ColumnTypeParser.getAsInstant(yearAsDate);
} else if (object instanceof String) {
String objectAsString = (String) object;
return ColumnTypeParser.getAsInstant(objectAsString);
} else {
throw new IllegalArgumentException("Argument must be date, local date time or string but got " + object.getClass().getName());
}
}
}
Loading
Loading