Skip to content

Commit

Permalink
added polling result type, updated version constant
Browse files Browse the repository at this point in the history
Signed-off-by: Shenoy Pratik <sgguruda@amazon.com>
  • Loading branch information
ps48 committed Mar 8, 2024
1 parent 5e14f57 commit 8ce818d
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 24 deletions.
2 changes: 2 additions & 0 deletions common/constants/data_sources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ export enum DATA_SOURCE_TYPES {
S3Glue = 's3glue',
}
export const ASYNC_POLLING_INTERVAL = 2000;

export const CATALOG_CACHE_VERSION = '1.0';
7 changes: 7 additions & 0 deletions common/types/data_connections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,10 @@ export interface AccelerationsCacheData {
lastUpdated: string; // Assuming date string in UTC format
status: CachedDataSourceStatus;
}

export interface PollingSuccessResult {
schema: Array<{ name: string; type: string }>;
datarows: Array<Array<string | number | boolean>>;
}

export type AsyncPollingResult = PollingSuccessResult | null;
4 changes: 2 additions & 2 deletions common/utils/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ export function addBackticksIfNeeded(input: string): string {

export function combineSchemaAndDatarows(
schema: Array<{ name: string; type: string }>,
datarows: string[][]
datarows: Array<Array<string | number | boolean>>
): object[] {
const combinedData: object[] = [];

datarows.forEach((row) => {
const rowData: { [key: string]: string } = {};
const rowData: { [key: string]: string | number | boolean } = {};
schema.forEach((field, index) => {
rowData[field.name] = row[index];
});
Expand Down
5 changes: 3 additions & 2 deletions public/framework/catalog_cache/cache_loader.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { CATALOG_CACHE_VERSION } from '../../../common/constants/data_sources';
import { CachedDataSourceStatus } from '../../../common/types/data_connections';
import {
mockShowDatabasesPollingResult,
Expand Down Expand Up @@ -169,7 +170,7 @@ describe('loadCacheTests', () => {

// Verify that saveAccelerationsCache is called with the correct parameters
expect(CatalogCacheManager.saveAccelerationsCache).toHaveBeenCalledWith({
version: '1.0',
version: CATALOG_CACHE_VERSION,
accelerations: [],
lastUpdated: expect.any(String),
status: CachedDataSourceStatus.Failed,
Expand All @@ -181,7 +182,7 @@ describe('loadCacheTests', () => {

// Verify that saveAccelerationsCache is called with the correct parameters
expect(CatalogCacheManager.saveAccelerationsCache).toHaveBeenCalledWith({
version: '1.0',
version: CATALOG_CACHE_VERSION,
accelerations: [
{
flintIndexName: 'flint_mys3_default_http_logs_skipping_index',
Expand Down
24 changes: 17 additions & 7 deletions public/framework/catalog_cache/cache_loader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@
*/

import { useEffect, useState } from 'react';
import { ASYNC_POLLING_INTERVAL } from '../../../common/constants/data_sources';
import { CachedDataSourceStatus, LoadCacheType } from '../../../common/types/data_connections';
import {
ASYNC_POLLING_INTERVAL,
CATALOG_CACHE_VERSION,
} from '../../../common/constants/data_sources';
import {
AsyncPollingResult,
CachedDataSourceStatus,
LoadCacheType,
} from '../../../common/types/data_connections';
import { DirectQueryLoadingStatus, DirectQueryRequest } from '../../../common/types/explorer';
import { getAsyncSessionId, setAsyncSessionId } from '../../../common/utils/query_session_utils';
import {
Expand All @@ -19,7 +26,10 @@ import { SQLService } from '../../services/requests/sql';
import { coreRefs } from '../core_refs';
import { CatalogCacheManager } from './cache_manager';

export const updateDatabasesToCache = (dataSourceName: string, pollingResult: any) => {
export const updateDatabasesToCache = (
dataSourceName: string,
pollingResult: AsyncPollingResult
) => {
const cachedDataSource = CatalogCacheManager.getOrCreateDataSource(dataSourceName);
const currentTime = new Date().toUTCString();

Expand Down Expand Up @@ -52,7 +62,7 @@ export const updateDatabasesToCache = (dataSourceName: string, pollingResult: an
export const updateTablesToCache = (
dataSourceName: string,
databaseName: string,
pollingResult: any
pollingResult: AsyncPollingResult
) => {
const cachedDatabase = CatalogCacheManager.getDatabase(dataSourceName, databaseName);
const currentTime = new Date().toUTCString();
Expand Down Expand Up @@ -81,12 +91,12 @@ export const updateTablesToCache = (
});
};

export const updateAccelerationsToCache = (pollingResult: any) => {
export const updateAccelerationsToCache = (pollingResult: AsyncPollingResult) => {
const currentTime = new Date().toUTCString();

if (!pollingResult) {
CatalogCacheManager.saveAccelerationsCache({
version: '1.0',
version: CATALOG_CACHE_VERSION,
accelerations: [],
lastUpdated: currentTime,
status: CachedDataSourceStatus.Failed,
Expand All @@ -107,7 +117,7 @@ export const updateAccelerationsToCache = (pollingResult: any) => {
}));

CatalogCacheManager.saveAccelerationsCache({
version: '1.0',
version: CATALOG_CACHE_VERSION,
accelerations: newAccelerations,
lastUpdated: currentTime,
status: CachedDataSourceStatus.Updated,
Expand Down
15 changes: 8 additions & 7 deletions public/framework/catalog_cache/cache_manager.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { CATALOG_CACHE_VERSION } from '../../../common/constants/data_sources';
import {
ASYNC_QUERY_ACCELERATIONS_CACHE,
ASYNC_QUERY_DATASOURCE_CACHE,
Expand Down Expand Up @@ -55,7 +56,7 @@ describe('CatalogCacheManager', () => {
describe('saveDataSourceCache', () => {
it('should save data source cache with correct key and data', () => {
const cacheData: DataSourceCacheData = {
version: '1.0',
version: CATALOG_CACHE_VERSION,
dataSources: [
{
name: 'testDataSource',
Expand All @@ -74,7 +75,7 @@ describe('CatalogCacheManager', () => {

it('should overwrite existing data source cache with new data', () => {
const initialCacheData: DataSourceCacheData = {
version: '1.0',
version: CATALOG_CACHE_VERSION,
dataSources: [
{
name: 'testDataSource',
Expand Down Expand Up @@ -108,7 +109,7 @@ describe('CatalogCacheManager', () => {
describe('getDataSourceCache', () => {
it('should retrieve data source cache from local storage', () => {
const cacheData: DataSourceCacheData = {
version: '1.0',
version: CATALOG_CACHE_VERSION,
dataSources: [
{
name: 'testDataSource',
Expand All @@ -123,7 +124,7 @@ describe('CatalogCacheManager', () => {
});

it('should return default cache object if cache is not found', () => {
const defaultCacheObject = { version: '1.0', dataSources: [] };
const defaultCacheObject = { version: CATALOG_CACHE_VERSION, dataSources: [] };
localStorage.removeItem(ASYNC_QUERY_DATASOURCE_CACHE);
expect(CatalogCacheManager.getDataSourceCache()).toEqual(defaultCacheObject);
});
Expand All @@ -132,7 +133,7 @@ describe('CatalogCacheManager', () => {
describe('saveAccelerationsCache', () => {
it('should save accelerations cache to local storage', () => {
const cacheData: AccelerationsCacheData = {
version: '1.0',
version: CATALOG_CACHE_VERSION,
accelerations: [],
lastUpdated: '2024-03-07T12:00:00Z',
status: CachedDataSourceStatus.Empty,
Expand All @@ -148,7 +149,7 @@ describe('CatalogCacheManager', () => {
describe('getAccelerationsCache', () => {
it('should retrieve accelerations cache from local storage', () => {
const cacheData: AccelerationsCacheData = {
version: '1.0',
version: CATALOG_CACHE_VERSION,
accelerations: [],
lastUpdated: '2024-03-07T12:00:00Z',
status: CachedDataSourceStatus.Empty,
Expand All @@ -159,7 +160,7 @@ describe('CatalogCacheManager', () => {

it('should return default cache object if cache is not found', () => {
const defaultCacheObject = {
version: '1.0',
version: CATALOG_CACHE_VERSION,
accelerations: [],
lastUpdated: '',
status: CachedDataSourceStatus.Empty,
Expand Down
5 changes: 3 additions & 2 deletions public/framework/catalog_cache/cache_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { CATALOG_CACHE_VERSION } from '../../../common/constants/data_sources';
import {
ASYNC_QUERY_ACCELERATIONS_CACHE,
ASYNC_QUERY_DATASOURCE_CACHE,
Expand Down Expand Up @@ -48,7 +49,7 @@ export class CatalogCacheManager {
if (catalogData) {
return JSON.parse(catalogData);
} else {
const defaultCacheObject = { version: '1.0', dataSources: [] };
const defaultCacheObject = { version: CATALOG_CACHE_VERSION, dataSources: [] };
this.saveDataSourceCache(defaultCacheObject);
return defaultCacheObject;
}
Expand All @@ -73,7 +74,7 @@ export class CatalogCacheManager {
return JSON.parse(accelerationCacheData);
} else {
const defaultCacheObject = {
version: '1.0',
version: CATALOG_CACHE_VERSION,
accelerations: [],
lastUpdated: '',
status: CachedDataSourceStatus.Empty,
Expand Down
8 changes: 4 additions & 4 deletions test/datasources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { DatasourceType } from '../common/types/data_connections';
import { AsyncPollingResult, DatasourceType } from '../common/types/data_connections';

export const showDataConnectionsData = {
schema: [
Expand Down Expand Up @@ -807,12 +807,12 @@ export const mockRoleData = {
},
};

export const mockShowDatabasesPollingResult = {
export const mockShowDatabasesPollingResult: AsyncPollingResult = {
schema: [{ name: 'namespace', type: 'string' }],
datarows: [['Database1'], ['Database2']],
};

export const mockShowTablesPollingResult = {
export const mockShowTablesPollingResult: AsyncPollingResult = {
schema: [
{ name: 'namespace', type: 'string' },
{ name: 'tableName', type: 'string' },
Expand All @@ -824,7 +824,7 @@ export const mockShowTablesPollingResult = {
],
};

export const mockShowIndexesPollingResult = {
export const mockShowIndexesPollingResult: AsyncPollingResult = {
schema: [
{ name: 'flint_index_name', type: 'string' },
{ name: 'kind', type: 'string' },
Expand Down

0 comments on commit 8ce818d

Please sign in to comment.