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

added fix for jobs and cache Support for workbench ,MDS support #1739

Merged
merged 10 commits into from
May 1, 2024
11 changes: 10 additions & 1 deletion common/types/data_connections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
interface AsyncApiDataResponse {
status: string;
schema?: Array<{ name: string; type: string }>;
datarows?: any;

Check warning on line 75 in common/types/data_connections.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
total?: number;
size?: number;
error?: string;
Expand Down Expand Up @@ -121,6 +121,7 @@
lastUpdated: string; // date string in UTC format
status: CachedDataSourceStatus;
databases: CachedDatabase[];
dataSourceMDSId?: string;
}

export interface DataSourceCacheData {
Expand All @@ -143,6 +144,7 @@
accelerations: CachedAcceleration[];
lastUpdated: string; // date string in UTC format
status: CachedDataSourceStatus;
dataSourceMDSId?: string;
}

export interface AccelerationsCacheData {
Expand Down Expand Up @@ -240,6 +242,13 @@

export interface LoadCachehookOutput {
loadStatus: DirectQueryLoadingStatus;
startLoading: (dataSourceName: string, databaseName?: string, tableName?: string) => void;
startLoading: (params: StartLoadingParams) => void;
stopLoading: () => void;
}

export interface StartLoadingParams {
dataSourceName: string;
dataSourceMDSId?: string;
databaseName?: string;
tableName?: string;
}
3 changes: 3 additions & 0 deletions common/utils/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ export function get<T = unknown>(obj: Record<string, any>, path: string, default
}

export function addBackticksIfNeeded(input: string): string {
if (input === undefined) {
return '';
}
sumukhswamy marked this conversation as resolved.
Show resolved Hide resolved
// Check if the string already has backticks
if (input.startsWith('`') && input.endsWith('`')) {
return input; // Return the string as it is
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,25 @@
EuiText,
} from '@elastic/eui';
import React, { useEffect, useState } from 'react';
import { OpenSearchDashboardsResponse } from '../../../../../../../../src/core/server/http/router';
import { CachedAcceleration } from '../../../../../../common/types/data_connections';
import { coreRefs } from '../../../../../framework/core_refs';
import { AccelerationActionOverlay } from './acceleration_action_overlay';
import { useAccelerationOperation } from './acceleration_operation';
import { AccelerationDetailsTab } from './flyout_modules/acceleration_details_tab';
import { AccelerationSchemaTab } from './flyout_modules/accelerations_schema_tab';
import {
onDiscoverIconClick,
AccelerationActionType,
getAccelerationName,
onDiscoverIconClick,
} from './utils/acceleration_utils';
import { coreRefs } from '../../../../../framework/core_refs';
import { OpenSearchDashboardsResponse } from '../../../../../../../../src/core/server/http/router';
import { CachedAcceleration } from '../../../../../../common/types/data_connections';
import { useAccelerationOperation } from './acceleration_operation';
import { AccelerationActionOverlay } from './acceleration_action_overlay';

export interface AccelerationDetailsFlyoutProps {
acceleration: CachedAcceleration;
dataSourceName: string;
resetFlyout: () => void;
handleRefresh?: () => void;
dataSourceMDSId?: string;
}

const getMappings = (index: string): Promise<OpenSearchDashboardsResponse> | undefined => {
Expand Down Expand Up @@ -61,7 +62,7 @@
const { dataSourceName, acceleration, resetFlyout, handleRefresh } = props;
const { flintIndexName } = acceleration;
const [selectedTab, setSelectedTab] = useState('details');
const tabsMap: { [key: string]: any } = {

Check warning on line 65 in public/components/datasources/components/manage/accelerations/acceleration_details_flyout.tsx

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
details: AccelerationDetailsTab,
schema: AccelerationSchemaTab,
};
Expand Down Expand Up @@ -141,7 +142,7 @@
if (flintIndexName !== undefined && flintIndexName.trim().length > 0) {
getAccDetail(flintIndexName);
}
}, [flintIndexName]);

Check warning on line 145 in public/components/datasources/components/manage/accelerations/acceleration_details_flyout.tsx

View workflow job for this annotation

GitHub Actions / Lint

React Hook useEffect has a missing dependency: 'getAccDetail'. Either include it or remove the dependency array

const DiscoverIcon = () => {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,33 @@
EuiText,
} from '@elastic/eui';
import React, { useCallback, useEffect, useState } from 'react';
import {
onDiscoverIconClick,
AccelerationStatus,
ACC_LOADING_MSG,
ACC_PANEL_TITLE,
ACC_PANEL_DESC,
getAccelerationName,
AccelerationActionType,
CreateAccelerationFlyoutButton,
} from './utils/acceleration_utils';
import { getRenderAccelerationDetailsFlyout } from '../../../../../plugin';
import { CatalogCacheManager } from '../../../../../framework/catalog_cache/cache_manager';
import {
CachedAcceleration,
CachedDataSourceStatus,
} from '../../../../../../common/types/data_connections';
import { DirectQueryLoadingStatus } from '../../../../../../common/types/explorer';
import { AccelerationActionOverlay } from './acceleration_action_overlay';
import { CatalogCacheManager } from '../../../../../framework/catalog_cache/cache_manager';
import {
getRenderAccelerationDetailsFlyout,
getRenderCreateAccelerationFlyout,
} from '../../../../../plugin';
import { isCatalogCacheFetching } from '../associated_objects/utils/associated_objects_tab_utils';
import { getRenderCreateAccelerationFlyout } from '../../../../../plugin';
import { AccelerationActionOverlay } from './acceleration_action_overlay';
import { useAccelerationOperation } from './acceleration_operation';
import {
ACC_LOADING_MSG,
ACC_PANEL_DESC,
ACC_PANEL_TITLE,
AccelerationActionType,
AccelerationStatus,
CreateAccelerationFlyoutButton,
getAccelerationName,
onDiscoverIconClick,
} from './utils/acceleration_utils';

interface AccelerationTableProps {
dataSourceName: string;
cacheLoadingHooks: any;

Check warning on line 47 in public/components/datasources/components/manage/accelerations/acceleration_table.tsx

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
}

interface ModalState {
Expand Down Expand Up @@ -73,7 +75,7 @@
if (operationSuccess) {
handleRefresh();
}
}, [operationSuccess]);

Check warning on line 78 in public/components/datasources/components/manage/accelerations/acceleration_table.tsx

View workflow job for this annotation

GitHub Actions / Lint

React Hook useEffect has a missing dependency: 'handleRefresh'. Either include it or remove the dependency array

const handleActionClick = (
actionType: ModalState['actionType'],
Expand Down Expand Up @@ -108,12 +110,12 @@
!isCatalogCacheFetching(accelerationsLoadStatus)
) {
setIsRefreshing(true);
startLoadingAccelerations(dataSourceName);
startLoadingAccelerations({ dataSourceName });
} else {
setAccelerations(cachedDataSource.accelerations);
setUpdatedTime(cachedDataSource.lastUpdated);
}
}, []);

Check warning on line 118 in public/components/datasources/components/manage/accelerations/acceleration_table.tsx

View workflow job for this annotation

GitHub Actions / Lint

React Hook useEffect has missing dependencies: 'accelerationsLoadStatus', 'dataSourceName', and 'startLoadingAccelerations'. Either include them or remove the dependency array

useEffect(() => {
if (accelerationsLoadStatus === DirectQueryLoadingStatus.SUCCESS) {
Expand All @@ -127,14 +129,14 @@
if (accelerationsLoadStatus === DirectQueryLoadingStatus.FAILED) {
setIsRefreshing(false);
}
}, [accelerationsLoadStatus]);

Check warning on line 132 in public/components/datasources/components/manage/accelerations/acceleration_table.tsx

View workflow job for this annotation

GitHub Actions / Lint

React Hook useEffect has a missing dependency: 'dataSourceName'. Either include it or remove the dependency array

const handleRefresh = useCallback(() => {
if (!isCatalogCacheFetching(accelerationsLoadStatus)) {
setIsRefreshing(true);
startLoadingAccelerations(dataSourceName);
}
}, [accelerationsLoadStatus]);

Check warning on line 139 in public/components/datasources/components/manage/accelerations/acceleration_table.tsx

View workflow job for this annotation

GitHub Actions / Lint

React Hook useCallback has missing dependencies: 'dataSourceName' and 'startLoadingAccelerations'. Either include them or remove the dependency array

const RefreshButton = () => {
return (
Expand Down Expand Up @@ -315,7 +317,7 @@
name: 'Actions',
actions: tableActions,
},
] as Array<EuiTableFieldDataColumnType<any>>;

Check warning on line 320 in public/components/datasources/components/manage/accelerations/acceleration_table.tsx

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type

const pagination = {
initialPageSize: 10,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
resetFlyout: () => void;
databaseName?: string;
tableName?: string;
dataSourceMDSId?: string;
refreshHandler?: () => void;
}

Expand All @@ -53,6 +54,7 @@
resetFlyout,
databaseName,
tableName,
dataSourceMDSId,
refreshHandler,
}: CreateAccelerationProps) => {
const { setToast } = useToast();
Expand Down Expand Up @@ -141,12 +143,22 @@
if (dataTable !== '') {
setTableFieldsLoading(true);
try {
const cachedTable = CatalogCacheManager.getTable(dataSource, database, dataTable);
const cachedTable = CatalogCacheManager.getTable(
dataSource,
database,
dataTable,
dataSourceMDSId
);
if (cachedTable.columns) {
loadColumnsToAccelerationForm(cachedTable);
setTableFieldsLoading(false);
} else {
startLoading(dataSource, database, dataTable);
startLoading({
dataSourceName: dataSource,
dataSourceMDSId,
databaseName: database,
tableName: dataTable,
});
}
} catch (error) {
setToast('Your cache is outdated, refresh databases and tables', 'warning');
Expand All @@ -163,7 +175,7 @@
accelerationFormData.dataTable
);
}
}, [databaseName, tableName]);

Check warning on line 178 in public/components/datasources/components/manage/accelerations/create_accelerations_flyout/create/create_acceleration.tsx

View workflow job for this annotation

GitHub Actions / Lint

React Hook useEffect has missing dependencies: 'accelerationFormData.dataSource', 'accelerationFormData.dataTable', 'accelerationFormData.database', and 'initiateColumnLoad'. Either include them or remove the dependency array

useEffect(() => {
const status = loadStatus.toLowerCase();
Expand All @@ -173,7 +185,8 @@
cachedTable = CatalogCacheManager.getTable(
accelerationFormData.dataSource,
accelerationFormData.database,
accelerationFormData.dataTable
accelerationFormData.dataTable,
dataSourceMDSId
);
} catch (error) {
setToast('Your cache is outdated, refresh databases and tables', 'warning');
Expand Down Expand Up @@ -218,6 +231,7 @@
selectedDatasource={selectedDatasource}
dataSourcesPreselected={dataSourcesPreselected}
tableFieldsLoading={tableFieldsLoading}
dataSourceMDSId={dataSourceMDSId}
/>
<EuiSpacer size="xxl" />
<IndexTypeSelector
Expand All @@ -235,6 +249,7 @@
accelerationFormData={accelerationFormData}
setAccelerationFormData={setAccelerationFormData}
tableFieldsLoading={tableFieldsLoading}
dataSourceMDSId={dataSourceMDSId}
/>
<EuiSpacer size="xxl" />
<IndexAdvancedSettings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const SelectorLoadDatabases = ({

const onClickRefreshDatabases = () => {
setIsLoading(true);
startDatabasesLoading(dataSourceName);
startDatabasesLoading({ dataSourceName });
};

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ export const SelectorLoadObjects = ({
tableStatus: true,
accelerationsStatus: true,
});
startLoadingTables(dataSourceName, databaseName);
startLoadingAccelerations(dataSourceName);
startLoadingTables({ dataSourceName, databaseName });
startLoadingAccelerations({ dataSourceName });
};

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ import React, { useEffect, useState } from 'react';
import { CoreStart } from '../../../../../../../../../../src/core/public';
import { DATACONNECTIONS_BASE } from '../../../../../../../../common/constants/shared';
import {
CachedDatabase,
CachedDataSourceStatus,
CachedDatabase,
CreateAccelerationForm,
} from '../../../../../../../../common/types/data_connections';
import { CatalogCacheManager } from '../../../../../../../framework/catalog_cache/cache_manager';
import { useToast } from '../../../../../../common/toast';
import { hasError, validateDatabase, validateDataTable } from '../create/utils';
import { hasError, validateDataTable, validateDatabase } from '../create/utils';
import { SelectorLoadDatabases } from './selector_helpers/load_databases';
import { SelectorLoadObjects } from './selector_helpers/load_objects';

Expand All @@ -37,6 +37,7 @@ interface AccelerationDataSourceSelectorProps {
selectedDatasource: string;
dataSourcesPreselected: boolean;
tableFieldsLoading: boolean;
dataSourceMDSId?: string;
}

export const AccelerationDataSourceSelector = ({
Expand All @@ -46,6 +47,7 @@ export const AccelerationDataSourceSelector = ({
selectedDatasource,
dataSourcesPreselected,
tableFieldsLoading,
dataSourceMDSId,
}: AccelerationDataSourceSelectorProps) => {
const { setToast } = useToast();
const [databases, setDatabases] = useState<Array<EuiComboBoxOptionOption<string>>>([]);
Expand All @@ -72,7 +74,7 @@ export const AccelerationDataSourceSelector = ({
const loadDataSource = () => {
setLoadingComboBoxes({ ...loadingComboBoxes, dataSource: true });
http
.get(DATACONNECTIONS_BASE)
.get(DATACONNECTIONS_BASE + `/dataSourceMDSId=${dataSourceMDSId}`)
.then((res) => {
const isValidDataSource = res.some(
(connection: any) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ interface QueryVisualEditorProps {
accelerationFormData: CreateAccelerationForm;
setAccelerationFormData: React.Dispatch<React.SetStateAction<CreateAccelerationForm>>;
tableFieldsLoading: boolean;
dataSourceMDSId?: string;
}

export const QueryVisualEditor = ({
accelerationFormData,
setAccelerationFormData,
tableFieldsLoading,
dataSourceMDSId,
}: QueryVisualEditorProps) => {
return tableFieldsLoading ? (
<>
Expand All @@ -38,6 +40,7 @@ export const QueryVisualEditor = ({
<SkippingIndexBuilder
accelerationFormData={accelerationFormData}
setAccelerationFormData={setAccelerationFormData}
dataSourceMDSId={dataSourceMDSId}
/>
)}
{accelerationFormData.accelerationIndexType === 'covering' && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ interface GenerateFieldsProps {
setAccelerationFormData: React.Dispatch<React.SetStateAction<CreateAccelerationForm>>;
isSkippingtableLoading: boolean;
setIsSkippingtableLoading: React.Dispatch<boolean>;
dataSourceMDSId?: string;
}

export const GenerateFields = ({
accelerationFormData,
setAccelerationFormData,
isSkippingtableLoading,
setIsSkippingtableLoading,
dataSourceMDSId,
}: GenerateFieldsProps) => {
const [isGenerateRun, setIsGenerateRun] = useState(false);
const { loadStatus, startLoading, stopLoading: _stopLoading, pollingResult } = useDirectQuery();
Expand Down Expand Up @@ -84,7 +86,7 @@ export const GenerateFields = ({
)}`,
datasource: accelerationFormData.dataSource,
};
startLoading(requestPayload);
startLoading(requestPayload, dataSourceMDSId);
setIsSkippingtableLoading(true);
setIsGenerateRun(true);
setReplaceDefinitionModal(<></>);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ import { GenerateFields } from './generate_fields';
interface SkippingIndexBuilderProps {
accelerationFormData: CreateAccelerationForm;
setAccelerationFormData: React.Dispatch<React.SetStateAction<CreateAccelerationForm>>;
dataSourceMDSId?: string;
}

export const SkippingIndexBuilder = ({
accelerationFormData,
setAccelerationFormData,
dataSourceMDSId,
}: SkippingIndexBuilderProps) => {
const [pageIndex, setPageIndex] = useState(0);
const [pageSize, setPageSize] = useState(20);
Expand Down Expand Up @@ -200,6 +202,7 @@ export const SkippingIndexBuilder = ({
setIsSkippingtableLoading={setIsSkippingtableLoading}
accelerationFormData={accelerationFormData}
setAccelerationFormData={setAccelerationFormData}
dataSourceMDSId={dataSourceMDSId}
/>
</EuiFlexItem>
</EuiFlexGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
* SPDX-License-Identifier: Apache-2.0
*/

import React from 'react';
import { EuiButton, EuiHealth } from '@elastic/eui';
import React from 'react';
import { DATA_SOURCE_TYPES } from '../../../../../../../common/constants/data_sources';
import { CachedAcceleration } from '../../../../../../../common/types/data_connections';
import {
redirectToExplorerOSIdx,
redirectToExplorerWithDataSrc,
} from '../../associated_objects/utils/associated_objects_tab_utils';
import { DATA_SOURCE_TYPES } from '../../../../../../../common/constants/data_sources';

export const ACC_PANEL_TITLE = 'Accelerations';
export const ACC_PANEL_DESC =
Expand Down Expand Up @@ -93,6 +93,7 @@ export const CreateAccelerationFlyoutButton = ({
dataSourceName: string;
renderCreateAccelerationFlyout: (
dataSource: string,
dataSourceMDSId?: string,
databaseName?: string,
tableName?: string,
handleRefresh?: () => void
Expand All @@ -103,7 +104,13 @@ export const CreateAccelerationFlyoutButton = ({
<>
<EuiButton
onClick={() =>
renderCreateAccelerationFlyout(dataSourceName, undefined, undefined, handleRefresh)
renderCreateAccelerationFlyout(
dataSourceName,
undefined,
undefined,
undefined,
handleRefresh
)
}
fill
>
Expand Down
Loading
Loading