Skip to content

Commit

Permalink
Removed QueryEngine Logic
Browse files Browse the repository at this point in the history
  • Loading branch information
praveen5959 committed Jan 10, 2025
1 parent 006298b commit 28a4351
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 34 deletions.
1 change: 0 additions & 1 deletion src/api/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ type CorrelationLogs = {
startTime: Date;
endTime: Date;
limit: number;
queryEngine?: QueryEngine;
correlationCondition?: string;
selectedFields?: string[];
};
Expand Down
2 changes: 0 additions & 2 deletions src/hooks/useCorrelationQueryLogs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const { setStreamData } = correlationStoreReducers;
export const useCorrelationQueryLogs = () => {
const [error, setError] = useMountedState<string | null>(null);
const [{ selectedFields, correlationCondition, fields }, setCorrelationStore] = useCorrelationStore((store) => store);
const [queryEngine] = useAppStore((store) => store.instanceConfig?.queryEngine);
const [streamInfo] = useStreamStore((store) => store.info);
const [currentStream] = useAppStore((store) => store.currentStream);
const timePartitionColumn = _.get(streamInfo, 'time_partition', 'p_timestamp');
Expand All @@ -32,7 +31,6 @@ export const useCorrelationQueryLogs = () => {
const streamNames = Object.keys(fields);

const defaultQueryOpts = {
queryEngine,
startTime: timeRange.startTime,
endTime: timeRange.endTime,
limit: CORRELATION_LOAD_LIMIT,
Expand Down
2 changes: 0 additions & 2 deletions src/hooks/useFetchStreamData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export const useFetchStreamData = () => {
const [{ selectedFields, correlationCondition, fields, streamData }, setCorrelationStore] = useCorrelationStore(
(store) => store,
);
const [queryEngine] = useAppStore((store) => store.instanceConfig?.queryEngine);
const [streamInfo] = useStreamStore((store) => store.info);
const [currentStream] = useAppStore((store) => store.currentStream);
const timePartitionColumn = _.get(streamInfo, 'time_partition', 'p_timestamp');
Expand All @@ -45,7 +44,6 @@ export const useFetchStreamData = () => {
}, [timeRange.startTime, timeRange.endTime]);

const defaultQueryOpts = {
queryEngine,
startTime: timeRange.startTime,
endTime: timeRange.endTime,
limit: STREAM_DATA_LOAD_LIMIT,
Expand Down
7 changes: 2 additions & 5 deletions src/pages/Correlation/components/CorrelationFilters/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ const ModalTitle = ({ title }: { title: string }) => {

const QuerierModal = (props: { onClear: () => void; onFiltersApply: () => void }) => {
const [currentStream] = useAppStore((store) => store.currentStream);
const [queryEngine] = useAppStore((store) => store.instanceConfig?.queryEngine);
const [{ showQueryBuilder }, setLogsStore] = useLogsStore((store) => store.custQuerySearchState);
const [streamInfo] = useStreamStore((store) => store.info);
const [timeRange] = useAppStore((store) => store.timeRange);
Expand All @@ -60,13 +59,12 @@ const QuerierModal = (props: { onClear: () => void; onFiltersApply: () => void }

useEffect(() => {
queryCodeEditorRef.current = defaultCustSQLQuery(
queryEngine,
currentStream,
timeRange.startTime,
timeRange.endTime,
timePartitionColumn,
);
}, [queryEngine, currentStream, timeRange.endTime, timeRange.startTime, timePartitionColumn]);
}, [currentStream, timeRange.endTime, timeRange.startTime, timePartitionColumn]);

return (
<Modal
Expand All @@ -91,7 +89,6 @@ const CorrelationFilters = () => {
const [{ startTime, endTime }, setAppStore] = useAppStore((store) => store.timeRange);
const { isQuerySearchActive, viewMode, showQueryBuilder, activeMode, savedFilterId } = custQuerySearchState;
const [currentStream] = useAppStore((store) => store.currentStream);
const [queryEngine] = useAppStore((store) => store.instanceConfig?.queryEngine);
const [activeSavedFilters] = useAppStore((store) => store.activeSavedFilters);
const openBuilderModal = useCallback(() => {
setLogsStore((store) => toggleQueryBuilder(store));
Expand Down Expand Up @@ -125,7 +122,7 @@ const CorrelationFilters = () => {
if (!currentStream) return;

const { isUncontrolled } = opts || {};
const { parsedQuery } = parseQuery(queryEngine, query, currentStream, {
const { parsedQuery } = parseQuery(query, currentStream, {
startTime,
endTime,
timePartitionColumn,
Expand Down
3 changes: 1 addition & 2 deletions src/pages/Correlation/components/MultiEventTimeLineGraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,6 @@ const parseGraphData = (
const MultiEventTimeLineGraph = () => {
const { fetchQueryMutation } = useQueryResult();
const [fields] = useCorrelationStore((store) => store.fields);
const [queryEngine] = useAppStore((store) => store.instanceConfig?.queryEngine);
const [appliedQuery] = useFilterStore((store) => store.appliedQuery);
const [timeRange] = useAppStore((store) => store.timeRange);
const [multipleStreamData, setMultipleStreamData] = useState<any>([]);
Expand All @@ -323,7 +322,7 @@ const MultiEventTimeLineGraph = () => {
endTime: modifiedEndTime,
access: [],
};
const whereClause = parseQuery(queryEngine, appliedQuery, streamKey).where;
const whereClause = parseQuery(appliedQuery, streamKey).where;
const query = generateCountQuery(streamKey, modifiedStartTime, modifiedEndTime, compactType, whereClause);
const graphQuery = removeOffsetFromQuery(query);

Expand Down
10 changes: 2 additions & 8 deletions src/pages/Correlation/providers/CorrelationProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Log, LogsResponseWithHeaders } from '@/@types/parseable/api/query';
import { LogStreamSchemaData } from '@/@types/parseable/api/stream';
import _ from 'lodash';
import { QueryType } from '@/pages/Stream/providers/FilterProvider';
import { QueryEngineType } from '@/@types/parseable/api/about';
import { FilterQueryBuilder } from '@/utils/queryBuilder';
import { formatQuery } from 'react-querybuilder';

Expand Down Expand Up @@ -77,11 +76,7 @@ type CorrelationStoreReducers = {
setCorrelationCondition: (store: CorrelationStore, correlationCondition: string) => ReducerOutput;
setPageAndPageData: (store: CorrelationStore, pageNo: number, perPage?: number) => ReducerOutput;
setIsCorrelatedFlag: (store: CorrelationStore, flag: boolean) => ReducerOutput;
parseQuery: (
queryEngine: 'Parseable' | 'Trino' | undefined,
query: QueryType,
currentStream: string,
) => { where: string; parsedQuery: string };
parseQuery: (query: QueryType, currentStream: string) => { where: string; parsedQuery: string };
};

const initialState: CorrelationStore = {
Expand Down Expand Up @@ -115,13 +110,12 @@ const initialState: CorrelationStore = {

// Utilites

const parseQuery = (queryEngine: QueryEngineType, query: QueryType, currentStream: string) => {
const parseQuery = (query: QueryType, currentStream: string) => {
// todo - custom rule processor to prevent converting number strings into numbers for text fields
const where = formatQuery(query, { format: 'sql', parseNumbers: true, quoteFieldNamesWith: ['"', '"'] });
const timeRangeCondition = '(1=1)';

const filterQueryBuilder = new FilterQueryBuilder({
queryEngine,
streamName: currentStream,
whereClause: where,
timeRangeCondition,
Expand Down
16 changes: 2 additions & 14 deletions src/utils/queryBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ type FilterQueryBuilderType = {
type CorrelationQueryBuilderType = {
streamNames: string[];
limit: number;
queryEngine?: QueryEngine;
correlationCondition?: string;
selectedFields?: string[];
startTime: Date;
Expand Down Expand Up @@ -101,7 +100,6 @@ export class FilterQueryBuilder {
}

export class CorrelationQueryBuilder {
queryEngine?: QueryEngine;
streamNames: string[];
limit: number;
correlationCondition?: string;
Expand All @@ -112,13 +110,11 @@ export class CorrelationQueryBuilder {
constructor({
streamNames,
limit,
queryEngine,
correlationCondition,
selectedFields,
startTime,
endTime,
}: CorrelationQueryBuilderType) {
this.queryEngine = queryEngine;
this.streamNames = streamNames;
this.startTime = startTime;
this.endTime = endTime;
Expand Down Expand Up @@ -154,18 +150,10 @@ export class CorrelationQueryBuilder {
};
}
getResourcePath(): string {
switch (this.queryEngine) {
case 'Trino':
return TRINO_RESOURCE_PATH;
default:
return PARSEABLE_RESOURCE_PATH;
}
return PARSEABLE_RESOURCE_PATH;
}

getQuery() {
switch (this.queryEngine) {
default:
return this.getParseableQuery();
}
return this.getParseableQuery();
}
}

0 comments on commit 28a4351

Please sign in to comment.