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

Web console: fix SQL in segment card #13895

Merged
merged 1 commit into from
Mar 7, 2023
Merged
Changes from all commits
Commits
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
12 changes: 6 additions & 6 deletions web-console/src/views/home-view/segments-card/segments-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { deepGet, pluralIfNeeded, queryDruidSql } from '../../../utils';
import { HomeViewCard } from '../home-view-card/home-view-card';

export interface SegmentCounts {
available: number;
total: number;
unavailable: number;
}

Expand All @@ -41,8 +41,8 @@ export const SegmentsCard = React.memo(function SegmentsCard(props: SegmentsCard
if (capabilities.hasSql()) {
const segments = await queryDruidSql({
query: `SELECT
COUNT(*) as "available",
COUNT(*) FILTER (WHERE is_available = 0) as "unavailable"
COUNT(*) as "total",
COUNT(*) FILTER (WHERE is_active = 1 AND is_available = 0) as "unavailable"
FROM sys.segments`,
});
return segments.length === 1 ? segments[0] : null;
Expand All @@ -60,7 +60,7 @@ FROM sys.segments`,
);

return {
available: availableSegmentNum + unavailableSegmentNum,
total: availableSegmentNum + unavailableSegmentNum,
unavailable: unavailableSegmentNum,
};
} else {
Expand All @@ -70,7 +70,7 @@ FROM sys.segments`,
initQuery: props.capabilities,
});

const segmentCount = segmentCountState.data || { available: 0, unavailable: 0 };
const segmentCount = segmentCountState.data || { total: 0, unavailable: 0 };
return (
<HomeViewCard
className="segments-card"
Expand All @@ -80,7 +80,7 @@ FROM sys.segments`,
loading={segmentCountState.loading}
error={segmentCountState.error}
>
<p>{pluralIfNeeded(segmentCount.available, 'segment')}</p>
<p>{pluralIfNeeded(segmentCount.total, 'segment')}</p>
{Boolean(segmentCount.unavailable) && (
<p>{pluralIfNeeded(segmentCount.unavailable, 'unavailable segment')}</p>
)}
Expand Down