Skip to content
This repository was archived by the owner on May 13, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/api/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const formQueryOpts = (logsQuery: FormQueryOptsType) => {
const orderBy = `ORDER BY ${timePartitionColumn} desc`;
const timestampClause = timeRangeSQLCondition(timePartitionColumn, optimizedStartTime, optimizedEndTime);
const offsetPart = _.isNumber(pageOffset) ? `OFFSET ${pageOffset}` : '';
const query = `SELECT * FROM ${streamName} where ${timestampClause} ${orderBy} ${offsetPart} LIMIT ${limit} `;
const query = `SELECT * FROM \"${streamName}\" where ${timestampClause} ${orderBy} ${offsetPart} LIMIT ${limit} `;
return { query, startTime: optimizedStartTime, endTime: optimizedEndTime };
};

Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useQueryResult.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const useFetchCount = () => {
const [timeRange, setLogsStore] = useLogsStore((store) => store.timeRange);
const { isQuerySearchActive, custSearchQuery, activeMode } = custQuerySearchState;

const defaultQuery = `select count(*) as count from ${currentStream}`;
const defaultQuery = `select count(*) as count from \"${currentStream}\"`;
const query = (() => {
if (isQuerySearchActive) {
const finalQuery = custSearchQuery.replace(/SELECT[\s\S]*?FROM/i, 'SELECT COUNT(*) as count FROM');
Expand Down
21 changes: 15 additions & 6 deletions src/pages/Home/CreateStreamModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,20 @@ import { GetInputPropsReturnType } from 'node_modules/@mantine/form/lib/types';

const { toggleCreateStreamModal } = appStoreReducers;

const allowedSpecialCharacters = ['-', '_'];

const isValidStreamName = (val: string) => {
if (!/[A-Za-z]/.test(val)) {
return 'Name should contain at least one letter';
} else if (_.includes(val, ' ')) {
} else if (/\s/.test(val)) {
return 'Name should not contain whitespace';
} else if (!/^[a-zA-Z0-9]+$/.test(val)) {
return 'Name should not contain any special characters';
} else {
null;
} else if (!new RegExp(`^[a-zA-Z0-9${allowedSpecialCharacters.join('')}\]+$`).test(val)) {
return `Name should only contain letters, numbers, or these special characters: ${allowedSpecialCharacters.join(
' , ',
)}`;
}

return null;
};

const reservedFieldNames = ['p_metadata', 'p_tags', 'p_timestamp'];
Expand Down Expand Up @@ -348,6 +352,11 @@ const CreateStreamForm = (props: { toggleModal: () => void }) => {
getLogStreamListRefetch();
}, []);

const isStreamNameValid = useCallback(() => {
const { hasError } = form.validateField('name');
return !hasError;
}, [form]);

const onSubmit = useCallback(() => {
const { hasErrors } = form.validate();
const { schemaType, fields, partitionField, customPartitionFields, partitionLimit } = form.values;
Expand Down Expand Up @@ -415,7 +424,7 @@ const CreateStreamForm = (props: { toggleModal: () => void }) => {
<Stack style={{ flexDirection: 'row', justifyContent: 'flex-end' }}>
<Box>
{!createLogStreamIsLoading ? (
<Button w="6rem" onClick={onSubmit}>
<Button w="6rem" onClick={onSubmit} disabled={!isStreamNameValid()}>
Create
</Button>
) : (
Expand Down
4 changes: 2 additions & 2 deletions src/pages/Stream/components/EventTimeLineGraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ const generateCountQuery = (
whereClause: string,
) => {
const range = compactTypeIntervalMap[compactType];
return `SELECT DATE_BIN('${range}', p_timestamp, '${startTime.toISOString()}') AS date_bin_timestamp, COUNT(*) AS log_count FROM ${streamName} WHERE p_timestamp BETWEEN '${startTime.toISOString()}' AND '${endTime.toISOString()}' AND ${whereClause} GROUP BY date_bin_timestamp ORDER BY date_bin_timestamp`;
return `SELECT DATE_BIN('${range}', p_timestamp, '${startTime.toISOString()}') AS date_bin_timestamp, COUNT(*) AS log_count FROM \"${streamName}\" WHERE p_timestamp BETWEEN '${startTime.toISOString()}' AND '${endTime.toISOString()}' AND ${whereClause} GROUP BY date_bin_timestamp ORDER BY date_bin_timestamp`;
};

const NoDataView = (props: { isError: boolean }) => {
Expand Down Expand Up @@ -336,7 +336,7 @@ const EventTimeLineGraph = () => {
dotProps={{ strokeWidth: 1, r: 2.5 }}
/>
) : (
<NoDataView isError={fetchQueryMutation.isError}/>
<NoDataView isError={fetchQueryMutation.isError} />
)}
</Skeleton>
</Stack>
Expand Down
25 changes: 21 additions & 4 deletions src/pages/Stream/components/Querier/QueryCodeEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,21 @@ const genColumnConfig = (fields: Field[]) => {
}, columnConfig);
};

export const defaultCustSQLQuery = (streamName: string | null, startTime: Date, endTime: Date, timePartitionColumn: string) => {
export const defaultCustSQLQuery = (
streamName: string | null,
startTime: Date,
endTime: Date,
timePartitionColumn: string,
) => {
if (streamName && streamName.length > 0) {
const { query } = formQueryOpts({ streamName: streamName || '', limit: LOAD_LIMIT, startTime, endTime, timePartitionColumn, pageOffset: 0 });
const { query } = formQueryOpts({
streamName: streamName || '',
limit: LOAD_LIMIT,
startTime,
endTime,
timePartitionColumn,
pageOffset: 0,
});
return query;
} else {
return '';
Expand Down Expand Up @@ -67,7 +79,12 @@ const QueryCodeEditor: FC<{

useEffect(() => {
if (props.queryCodeEditorRef.current === '' || currentStream !== localStreamName) {
props.queryCodeEditorRef.current = defaultCustSQLQuery(currentStream, timeRange.startTime, timeRange.endTime, timePartitionColumn);
props.queryCodeEditorRef.current = defaultCustSQLQuery(
currentStream,
timeRange.startTime,
timeRange.endTime,
timePartitionColumn,
);
}
}, [currentStream, timeRange.startTime, timeRange.endTime, timePartitionColumn]);

Expand Down Expand Up @@ -109,7 +126,7 @@ const QueryCodeEditor: FC<{
useEffect(() => {
if (currentStream !== localStreamName) {
setlocalStreamName(currentStream);
const query = `SELECT * FROM ${currentStream} LIMIT ${LOAD_LIMIT}; `;
const query = `SELECT * FROM \"${currentStream}\" LIMIT ${LOAD_LIMIT}; `;
updateQuery(query);
}
setlocalLlmActive(isLlmActive);
Expand Down
10 changes: 7 additions & 3 deletions src/pages/Stream/providers/FilterProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ type FilterStoreReducers = {
parseQuery: (
query: QueryType,
currentStream: string,
timeRangeOpts?: { startTime: Date; endTime: Date, timePartitionColumn: string },
timeRangeOpts?: { startTime: Date; endTime: Date; timePartitionColumn: string },
) => { where: string; parsedQuery: string };
toggleSubmitBtn: (store: FilterStore, val: boolean) => ReducerOutput;
toggleSaveFiltersModal: (_store: FilterStore, val: boolean) => ReducerOutput;
Expand Down Expand Up @@ -240,13 +240,17 @@ const toggleSubmitBtn = (_store: FilterStore, val: boolean) => {
};

// todo - custom rule processor to prevent converting number strings into numbers for text fields
const parseQuery = (query: QueryType, currentStream: string, timeRangeOpts?: { startTime: Date; endTime: Date, timePartitionColumn: string }) => {
const parseQuery = (
query: QueryType,
currentStream: string,
timeRangeOpts?: { startTime: Date; endTime: Date; timePartitionColumn: 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 = timeRangeOpts
? timeRangeSQLCondition(timeRangeOpts.timePartitionColumn, timeRangeOpts.startTime, timeRangeOpts.endTime)
: '(1=1)';
const parsedQuery = `select * from ${currentStream} where ${where} AND ${timeRangeCondition} offset 0 limit ${LOAD_LIMIT}`;
const parsedQuery = `select * from \"${currentStream}\" where ${where} AND ${timeRangeCondition} offset 0 limit ${LOAD_LIMIT}`;
return { where, parsedQuery };
};

Expand Down
Loading