mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-08-28 10:56:02 +00:00
Add orderby for listing KpiResult Times Series (#8942)
* Add orderby for listing KpiResult Times Series * Add order by param for kpi results Co-authored-by: Sachin Chaurasiya <sachinchaurasiyachotey87@gmail.com>
This commit is contained in:
parent
68e6ed5421
commit
67cd61cf79
@ -2953,6 +2953,11 @@ public interface CollectionDAO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface EntityExtensionTimeSeriesDAO {
|
interface EntityExtensionTimeSeriesDAO {
|
||||||
|
enum OrderBy {
|
||||||
|
ASC,
|
||||||
|
DESC
|
||||||
|
};
|
||||||
|
|
||||||
@ConnectionAwareSqlUpdate(
|
@ConnectionAwareSqlUpdate(
|
||||||
value =
|
value =
|
||||||
"INSERT INTO entity_extension_time_series(entityFQN, extension, jsonSchema, json) "
|
"INSERT INTO entity_extension_time_series(entityFQN, extension, jsonSchema, json) "
|
||||||
@ -3036,6 +3041,16 @@ public interface CollectionDAO {
|
|||||||
@Bind("extension") String extension,
|
@Bind("extension") String extension,
|
||||||
@Bind("startTs") Long startTs,
|
@Bind("startTs") Long startTs,
|
||||||
@Bind("endTs") long endTs);
|
@Bind("endTs") long endTs);
|
||||||
|
|
||||||
|
@SqlQuery(
|
||||||
|
"SELECT json FROM entity_extension_time_series where entityFQN = :entityFQN and extension = :extension "
|
||||||
|
+ " AND timestamp >= :startTs and timestamp <= :endTs ORDER BY timestamp <orderBy>")
|
||||||
|
List<String> listBetweenTimestampsByOrder(
|
||||||
|
@Bind("entityFQN") String entityFQN,
|
||||||
|
@Bind("extension") String extension,
|
||||||
|
@Bind("startTs") Long startTs,
|
||||||
|
@Bind("endTs") long endTs,
|
||||||
|
@Define("orderBy") OrderBy orderBy);
|
||||||
}
|
}
|
||||||
|
|
||||||
class EntitiesCountRowMapper implements RowMapper<EntitiesCount> {
|
class EntitiesCountRowMapper implements RowMapper<EntitiesCount> {
|
||||||
|
@ -185,13 +185,15 @@ public class KpiRepository extends EntityRepository<Kpi> {
|
|||||||
daoCollection.entityExtensionTimeSeriesDao().getLatestExtension(fqn, KPI_RESULT_EXTENSION), KpiResult.class);
|
daoCollection.entityExtensionTimeSeriesDao().getLatestExtension(fqn, KPI_RESULT_EXTENSION), KpiResult.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResultList<KpiResult> getKpiResults(String fqn, Long startTs, Long endTs) throws IOException {
|
public ResultList<KpiResult> getKpiResults(
|
||||||
|
String fqn, Long startTs, Long endTs, CollectionDAO.EntityExtensionTimeSeriesDAO.OrderBy orderBy)
|
||||||
|
throws IOException {
|
||||||
List<KpiResult> kpiResults;
|
List<KpiResult> kpiResults;
|
||||||
kpiResults =
|
kpiResults =
|
||||||
JsonUtils.readObjects(
|
JsonUtils.readObjects(
|
||||||
daoCollection
|
daoCollection
|
||||||
.entityExtensionTimeSeriesDao()
|
.entityExtensionTimeSeriesDao()
|
||||||
.listBetweenTimestamps(fqn, KPI_RESULT_EXTENSION, startTs, endTs),
|
.listBetweenTimestampsByOrder(fqn, KPI_RESULT_EXTENSION, startTs, endTs, orderBy),
|
||||||
KpiResult.class);
|
KpiResult.class);
|
||||||
return new ResultList<>(kpiResults, String.valueOf(startTs), String.valueOf(endTs), kpiResults.size());
|
return new ResultList<>(kpiResults, String.valueOf(startTs), String.valueOf(endTs), kpiResults.size());
|
||||||
}
|
}
|
||||||
|
@ -423,9 +423,14 @@ public class KpiResource extends EntityResource<Kpi, KpiRepository> {
|
|||||||
@Parameter(description = "Filter kpi results before the given end timestamp", schema = @Schema(type = "number"))
|
@Parameter(description = "Filter kpi results before the given end timestamp", schema = @Schema(type = "number"))
|
||||||
@NonNull
|
@NonNull
|
||||||
@QueryParam("endTs")
|
@QueryParam("endTs")
|
||||||
Long endTs)
|
Long endTs,
|
||||||
|
@Parameter(description = "Order the result ", schema = @Schema(type = "string"))
|
||||||
|
@Valid
|
||||||
|
@QueryParam("orderBy")
|
||||||
|
@DefaultValue("DESC")
|
||||||
|
CollectionDAO.EntityExtensionTimeSeriesDAO.OrderBy orderBy)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
return dao.getKpiResults(fqn, startTs, endTs);
|
return dao.getKpiResults(fqn, startTs, endTs, orderBy);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
|
@ -77,10 +77,14 @@ export const getKPIByName = async (kpiName: string, params?: ListParams) => {
|
|||||||
return response.data;
|
return response.data;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getListKpiResult = async (fqn: string, params: KpiResultParam) => {
|
export const getListKpiResult = async (
|
||||||
|
fqn: string,
|
||||||
|
params: KpiResultParam,
|
||||||
|
orderBy = 'ASC'
|
||||||
|
) => {
|
||||||
const response = await APIClient.get<PagingResponse<KpiResult[]>>(
|
const response = await APIClient.get<PagingResponse<KpiResult[]>>(
|
||||||
`/kpi/${fqn}/kpiResult`,
|
`/kpi/${fqn}/kpiResult`,
|
||||||
{ params }
|
{ params: { ...params, orderBy } }
|
||||||
);
|
);
|
||||||
|
|
||||||
return response.data;
|
return response.data;
|
||||||
|
@ -53,9 +53,9 @@ import {
|
|||||||
KpiTargetType,
|
KpiTargetType,
|
||||||
} from '../../generated/api/dataInsight/kpi/createKpiRequest';
|
} from '../../generated/api/dataInsight/kpi/createKpiRequest';
|
||||||
import {
|
import {
|
||||||
|
ChartDataType,
|
||||||
ChartParameterValues,
|
ChartParameterValues,
|
||||||
DataInsightChart,
|
DataInsightChart,
|
||||||
DataType,
|
|
||||||
} from '../../generated/dataInsight/dataInsightChart';
|
} from '../../generated/dataInsight/dataInsightChart';
|
||||||
import { DataInsightChartType } from '../../generated/dataInsight/dataInsightChartResult';
|
import { DataInsightChartType } from '../../generated/dataInsight/dataInsightChartResult';
|
||||||
import { Kpi } from '../../generated/dataInsight/kpi/kpi';
|
import { Kpi } from '../../generated/dataInsight/kpi/kpi';
|
||||||
@ -103,8 +103,8 @@ const AddKPIPage = () => {
|
|||||||
() =>
|
() =>
|
||||||
(selectedChart?.metrics ?? []).filter((metric) =>
|
(selectedChart?.metrics ?? []).filter((metric) =>
|
||||||
// only return supported data type
|
// only return supported data type
|
||||||
[DataType.Number, DataType.Percentage].includes(
|
[ChartDataType.Number, ChartDataType.Percentage].includes(
|
||||||
metric.dataType as DataType
|
metric.chartDataType as ChartDataType
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
[selectedChart]
|
[selectedChart]
|
||||||
@ -166,7 +166,8 @@ const AddKPIPage = () => {
|
|||||||
const handleSubmit: FormProps['onFinish'] = async (values) => {
|
const handleSubmit: FormProps['onFinish'] = async (values) => {
|
||||||
const startDate = getTimeStampByDateTime(kpiDates.startDate);
|
const startDate = getTimeStampByDateTime(kpiDates.startDate);
|
||||||
const endDate = getTimeStampByDateTime(kpiDates.endDate);
|
const endDate = getTimeStampByDateTime(kpiDates.endDate);
|
||||||
const metricType = selectedMetric?.dataType as unknown as KpiTargetType;
|
const metricType =
|
||||||
|
selectedMetric?.chartDataType as unknown as KpiTargetType;
|
||||||
|
|
||||||
const targetValue = getKpiTargetValueByMetricType(metricType, metricValue);
|
const targetValue = getKpiTargetValueByMetricType(metricType, metricValue);
|
||||||
|
|
||||||
@ -300,7 +301,7 @@ const AddKPIPage = () => {
|
|||||||
onChange={handleMetricSelect}>
|
onChange={handleMetricSelect}>
|
||||||
{metricTypes.map((metric) => (
|
{metricTypes.map((metric) => (
|
||||||
<Option key={metric.name}>
|
<Option key={metric.name}>
|
||||||
{`${metric.name} (${metric.dataType})`}
|
{`${metric.name} (${metric.chartDataType})`}
|
||||||
</Option>
|
</Option>
|
||||||
))}
|
))}
|
||||||
</Select>
|
</Select>
|
||||||
@ -323,7 +324,8 @@ const AddKPIPage = () => {
|
|||||||
},
|
},
|
||||||
]}>
|
]}>
|
||||||
<>
|
<>
|
||||||
{selectedMetric.dataType === DataType.Percentage && (
|
{selectedMetric.chartDataType ===
|
||||||
|
ChartDataType.Percentage && (
|
||||||
<Row gutter={20}>
|
<Row gutter={20}>
|
||||||
<Col span={20}>
|
<Col span={20}>
|
||||||
<Slider
|
<Slider
|
||||||
@ -356,7 +358,7 @@ const AddKPIPage = () => {
|
|||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
)}
|
)}
|
||||||
{selectedMetric.dataType === DataType.Number && (
|
{selectedMetric.chartDataType === ChartDataType.Number && (
|
||||||
<InputNumber
|
<InputNumber
|
||||||
className="w-full"
|
className="w-full"
|
||||||
min={0}
|
min={0}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user