I have a java POJO for collecting metics like below :
public class Metric {
Long metricId;
Long resultKeyId;
@NonNull DatasetType datasetType;
@NonNull String datasetName;
@NonNull String analyzerName;
@NonNull String constraintAlias;
@NonNull LocalDateTime entityDate;
@NonNull long entityDurationSec;
@NonNull Double metricValue;
@NonNull String changedBy;
Long jobId = 0L;
Long codeArtifactId = 0L;
LocalDateTime createdAt;
LocalDateTime lastChanged;
}
I have a list of metrics from the above pojo like List<Metric> metrics
Now this list can have multiple items and i want to select only one record for the same resultKeyId,datasetType,datasetName,analyzerName,constraintAlias with the max createdAt
The SQL Representation of this would be something like :
select a.* from
dataval_metric a
join dataval_metric b
on a.result_key_id=b.result_key_id
and a.dataset_type=b.dataset_type
and a.dataset_name=b.dataset_name
and a.analyzer_name=b.analyzer_name
and a.constraint_alias=b.constraint_alias
where a.result_key_id = 434
and a.mysql_row_created_at >= b. mysql_row_created_at;
Looking for pointers to understand how this can be done in a performant way in Java