Compare commits

...

6 Commits

Author SHA1 Message Date
Tushar Vats
ceb93490f2 feat(logs): read log patterns from the sharded mappings tables
Mappings are sharded like the logs by log ID, so pattern() matches each
shard's logs against that shard's mappings. Templates and evolutions are
full copies on every node.

Assisted-by: Claude Opus 5.5
2026-12-04 21:05:03 +05:30
Tushar Vats
fe4b9ff3fc fix(querybuilder): skip the cost guard for pattern()
Its estimate had to build the pattern's log ID set and timed out at 5s.

Assisted-by: Claude Opus 5.5
2026-12-04 21:05:02 +05:30
Tushar Vats
03c39fb333 chore(logs-explorer): merge the log patterns api, filter and frontend branches
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 03:20:06 +05:30
Tushar Vats
46d55f079e feat(logs-explorer): add a patterns view and a show logs action per pattern
A Patterns tab next to List, Time series and Table shows the patterns of the
current query from the pattern request type: template, count, share and a
trend sparkline, with a note when counts come from a sample. Show logs adds
pattern('<template>') to the filter and opens the List view. The filter
editor treats pattern( as a function token.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 03:19:33 +05:30
Tushar Vats
8e6abc1ba2 feat(querier): add the pattern request type for ingest-time log patterns
A pattern request counts the logs of one logs builder query by the pattern
the template miner exporter mapped them to (log_pattern_map), with each
pattern's template, share and trend. IDs of patterns that widened since are
counted under their current ID through pattern_changes. Log IDs sort by log
time, so the time range and the trend steps are log ID ranges. Above about
500k matching logs, logs and map rows keep the same hash sample.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 03:17:19 +05:30
Tushar Vats
5321023284 feat(querybuilder): add the pattern() filter for ingest-time log patterns
pattern('<template>'[, ...]) keeps the logs the template miner exporter
mapped to the given templates' patterns, or to older patterns that have
since widened into them. A template's ID is the FNV-1a hash of its text.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 03:17:19 +05:30
66 changed files with 3364 additions and 962 deletions

View File

@@ -10445,6 +10445,80 @@ components:
- asc
- desc
type: string
Querybuildertypesv5Pattern:
properties:
count:
description: The number of logs of the pattern in the time range, scaled
up by sampleRate.
minimum: 0
type: integer
id:
description: 'The pattern''s ID: the decimal 64-bit FNV-1a hash of its template.'
type: string
pattern:
description: 'The pattern''s template: the log message with the values that
change replaced by <*>. Empty when the template is not known yet.'
type: string
percent:
description: The pattern's count as a percentage of total.
format: double
type: number
trend:
description: The number of logs of the pattern in each step of the time
range, oldest first. Steps without a log are left out.
items:
$ref: '#/components/schemas/Querybuildertypesv5PatternTrendPoint'
nullable: true
type: array
required:
- id
- pattern
- count
- percent
- trend
type: object
Querybuildertypesv5PatternTrendPoint:
properties:
count:
description: The number of logs of the pattern in the step, scaled up by
sampleRate.
minimum: 0
type: integer
timestamp:
description: The Unix time in milliseconds the step starts at.
format: int64
type: integer
required:
- timestamp
- count
type: object
Querybuildertypesv5PatternsData:
properties:
patterns:
description: The patterns, most logs first.
items:
$ref: '#/components/schemas/Querybuildertypesv5Pattern'
nullable: true
type: array
queryName:
description: The name of the query that produced this result.
type: string
sampleRate:
description: One in sampleRate of the matching logs was read and every count
is scaled up by it. 1 means every log was read and the counts are exact.
minimum: 0
type: integer
total:
description: The number of matching logs that have a pattern, over every
pattern.
minimum: 0
type: integer
required:
- queryName
- sampleRate
- total
- patterns
type: object
Querybuildertypesv5PreviewStatement:
properties:
db.statement.args:
@@ -11006,11 +11080,12 @@ components:
- $ref: '#/components/schemas/Querybuildertypesv5ScalarData'
- $ref: '#/components/schemas/Querybuildertypesv5RawData'
- $ref: '#/components/schemas/Querybuildertypesv5DistributionData'
- $ref: '#/components/schemas/Querybuildertypesv5PatternsData'
properties:
results:
description: 'One result per enabled query, typed by the request type: TimeSeriesData
for time_series and heatmap, ScalarData for scalar, RawData for raw and
DistributionData for distribution requests.'
for time_series and heatmap, ScalarData for scalar, RawData for raw, DistributionData
for distribution and PatternsData for pattern requests.'
items: {}
nullable: true
type: array
@@ -11201,8 +11276,8 @@ components:
Querybuildertypesv5QueryRangeResponse:
description: 'Response from the v5 query range endpoint. The data.results array
contains typed results depending on the requestType: TimeSeriesData for time_series
and heatmap, ScalarData for scalar, RawData for raw, or DistributionData for
distribution requests.'
and heatmap, ScalarData for scalar, RawData for raw, DistributionData for
distribution, or PatternsData for pattern requests.'
properties:
data:
allOf:
@@ -11299,6 +11374,7 @@ components:
- raw_stream
- trace
- heatmap
- pattern
- distribution
type: string
Querybuildertypesv5ScalarData:

View File

@@ -7270,6 +7270,7 @@ export enum Querybuildertypesv5RequestTypeDTO {
raw_stream = 'raw_stream',
trace = 'trace',
heatmap = 'heatmap',
pattern = 'pattern',
distribution = 'distribution',
}
/**
@@ -12190,6 +12191,76 @@ export interface Querybuildertypesv5FormatOptionsDTO {
formatTableResultForUI?: boolean;
}
export interface Querybuildertypesv5PatternTrendPointDTO {
/**
* @type integer
* @minimum 0
* @description The number of logs of the pattern in the step, scaled up by sampleRate.
*/
count: number;
/**
* @type integer
* @format int64
* @description The Unix time in milliseconds the step starts at.
*/
timestamp: number;
}
export interface Querybuildertypesv5PatternDTO {
/**
* @type integer
* @minimum 0
* @description The number of logs of the pattern in the time range, scaled up by sampleRate.
*/
count: number;
/**
* @type string
* @description The pattern's ID: the decimal 64-bit FNV-1a hash of its template.
*/
id: string;
/**
* @type string
* @description The pattern's template: the log message with the values that change replaced by <*>. Empty when the template is not known yet.
*/
pattern: string;
/**
* @type number
* @format double
* @description The pattern's count as a percentage of total.
*/
percent: number;
/**
* @type array,null
* @description The number of logs of the pattern in each step of the time range, oldest first. Steps without a log are left out.
*/
trend: Querybuildertypesv5PatternTrendPointDTO[] | null;
}
export interface Querybuildertypesv5PatternsDataDTO {
/**
* @type array,null
* @description The patterns, most logs first.
*/
patterns: Querybuildertypesv5PatternDTO[] | null;
/**
* @type string
* @description The name of the query that produced this result.
*/
queryName: string;
/**
* @type integer
* @minimum 0
* @description One in sampleRate of the matching logs was read and every count is scaled up by it. 1 means every log was read and the counts are exact.
*/
sampleRate: number;
/**
* @type integer
* @minimum 0
* @description The number of matching logs that have a pattern, over every pattern.
*/
total: number;
}
export interface TelemetrystoretypesIndexStepDTO {
/**
* @type string
@@ -12396,28 +12467,35 @@ export type Querybuildertypesv5QueryDataDTO =
| (Querybuildertypesv5TimeSeriesDataDTO & {
/**
* @type array,null
* @description One result per enabled query, typed by the request type: TimeSeriesData for time_series and heatmap, ScalarData for scalar, RawData for raw and DistributionData for distribution requests.
* @description One result per enabled query, typed by the request type: TimeSeriesData for time_series and heatmap, ScalarData for scalar, RawData for raw, DistributionData for distribution and PatternsData for pattern requests.
*/
results?: unknown[] | null;
})
| (Querybuildertypesv5ScalarDataDTO & {
/**
* @type array,null
* @description One result per enabled query, typed by the request type: TimeSeriesData for time_series and heatmap, ScalarData for scalar, RawData for raw and DistributionData for distribution requests.
* @description One result per enabled query, typed by the request type: TimeSeriesData for time_series and heatmap, ScalarData for scalar, RawData for raw, DistributionData for distribution and PatternsData for pattern requests.
*/
results?: unknown[] | null;
})
| (Querybuildertypesv5RawDataDTO & {
/**
* @type array,null
* @description One result per enabled query, typed by the request type: TimeSeriesData for time_series and heatmap, ScalarData for scalar, RawData for raw and DistributionData for distribution requests.
* @description One result per enabled query, typed by the request type: TimeSeriesData for time_series and heatmap, ScalarData for scalar, RawData for raw, DistributionData for distribution and PatternsData for pattern requests.
*/
results?: unknown[] | null;
})
| (Querybuildertypesv5DistributionDataDTO & {
/**
* @type array,null
* @description One result per enabled query, typed by the request type: TimeSeriesData for time_series and heatmap, ScalarData for scalar, RawData for raw and DistributionData for distribution requests.
* @description One result per enabled query, typed by the request type: TimeSeriesData for time_series and heatmap, ScalarData for scalar, RawData for raw, DistributionData for distribution and PatternsData for pattern requests.
*/
results?: unknown[] | null;
})
| (Querybuildertypesv5PatternsDataDTO & {
/**
* @type array,null
* @description One result per enabled query, typed by the request type: TimeSeriesData for time_series and heatmap, ScalarData for scalar, RawData for raw, DistributionData for distribution and PatternsData for pattern requests.
*/
results?: unknown[] | null;
});
@@ -12551,7 +12629,7 @@ export interface Querybuildertypesv5QueryRangeRequestDTO {
}
/**
* Response from the v5 query range endpoint. The data.results array contains typed results depending on the requestType: TimeSeriesData for time_series and heatmap, ScalarData for scalar, RawData for raw, or DistributionData for distribution requests.
* Response from the v5 query range endpoint. The data.results array contains typed results depending on the requestType: TimeSeriesData for time_series and heatmap, ScalarData for scalar, RawData for raw, DistributionData for distribution, or PatternsData for pattern requests.
*/
export interface Querybuildertypesv5QueryRangeResponseDTO {
/**

View File

@@ -124,7 +124,7 @@ function isDeprecatedField(fieldName: string): boolean {
);
}
function getFilter(queryData: IBuilderQuery): Filter {
export function getFilter(queryData: IBuilderQuery): Filter {
const { filter } = queryData;
if (filter?.expression) {
return {

View File

@@ -73,6 +73,14 @@ const formatSingleValue = (v: string | number | boolean): string => {
return String(v);
};
/**
* Quotes text as a filter expression string literal, escaping backslashes and
* single quotes so the text round-trips exactly. Unlike formatValueForExpression,
* it never treats the text as already quoted or as a variable.
*/
export const formatStringLiteralForExpression = (value: string): string =>
`'${value.replace(/\\/g, '\\\\').replace(/'/g, "\\'")}'`;
/**
* Format a value for the expression string
* @param value - The value to format

View File

@@ -50,6 +50,7 @@ export enum QueryParams {
tab = 'tab',
thresholds = 'thresholds',
selectedExplorerView = 'selectedExplorerView',
logsExplorerView = 'logsExplorerView',
variables = 'variables',
version = 'version',
source = 'source',

View File

@@ -12,6 +12,7 @@ export const REACT_QUERY_KEY = {
GET_PUBLIC_DASHBOARD_WIDGET_DATA: 'GET_PUBLIC_DASHBOARD_WIDGET_DATA',
GET_ALL_LICENCES: 'GET_ALL_LICENCES',
GET_QUERY_RANGE: 'GET_QUERY_RANGE',
GET_LOG_PATTERNS: 'GET_LOG_PATTERNS',
GET_ALL_DASHBOARDS: 'GET_ALL_DASHBOARDS',
GET_TRIGGERED_ALERTS: 'GET_TRIGGERED_ALERTS',
DASHBOARD_BY_ID: 'DASHBOARD_BY_ID',

View File

@@ -34,7 +34,10 @@ function LogExplorerQuerySection({
isRawQuery={panelTypes === PANEL_TYPES.LIST}
config={{ initialDataSource: DataSource.LOGS, queryVariant: 'static' }}
panelType={panelTypes}
showOnlyWhereClause={selectedView === ExplorerViews.LIST}
showOnlyWhereClause={
selectedView === ExplorerViews.LIST ||
selectedView === ExplorerViews.PATTERNS
}
/>
);
}

View File

@@ -0,0 +1,51 @@
.patternsView {
display: flex;
flex: 1;
flex-direction: column;
min-height: 0;
gap: var(--spacing-4);
padding: var(--spacing-4) 0;
}
.header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 var(--spacing-8);
}
.table {
display: flex;
flex: 1;
flex-direction: column;
min-height: 0;
}
.patternCell {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: var(--spacing-4);
}
.template {
/* stylelint-disable property-disallowed-list -- Typography's code variant has line height 1, too tight for templates that wrap */
font-family: var(--code-base-400-font-family);
font-size: var(--code-base-400-font-size);
line-height: var(--paragraph-base-400-line-height);
/* stylelint-enable property-disallowed-list */
color: var(--l1-foreground);
white-space: pre-wrap;
word-break: break-word;
}
.share {
display: flex;
flex-direction: column;
gap: var(--spacing-2);
}
.sparkline {
display: flex;
align-items: center;
}

View File

@@ -0,0 +1,102 @@
import { Dispatch, MutableRefObject, SetStateAction, useEffect } from 'react';
import { Typography } from '@signozhq/ui/typography';
import ErrorInPlace from 'components/ErrorInPlace/ErrorInPlace';
import TanStackTable from 'components/TanStackTableView';
import EmptyLogsSearch from 'container/EmptyLogsSearch/EmptyLogsSearch';
import { LogsLoading } from 'container/LogsLoading/LogsLoading';
import NoLogs from 'container/NoLogs/NoLogs';
import { ChangeViewFunctionType } from 'hooks/useHandleExplorerTabChange';
import { DataSource } from 'types/common/queryBuilder';
import { useLogsPatterns } from './useLogsPatterns';
import { usePatternColumns } from './usePatternColumns';
import { useShowPatternLogs } from './useShowPatternLogs';
import { getPatternRowKey } from './utils';
import styles from './LogsPatternsView.module.scss';
interface LogsPatternsViewProps {
queryKeyRef: MutableRefObject<unknown>;
handleChangeSelectedView: ChangeViewFunctionType;
setIsLoadingQueries: Dispatch<SetStateAction<boolean>>;
}
function LogsPatternsView({
queryKeyRef,
handleChangeSelectedView,
setIsLoadingQueries,
}: LogsPatternsViewProps): JSX.Element {
const {
rows,
sampleRate,
isFilterApplied,
isLoading,
isFetching,
error,
queryKey,
} = useLogsPatterns();
const showPatternLogs = useShowPatternLogs(handleChangeSelectedView);
const columns = usePatternColumns(showPatternLogs);
useEffect(() => {
queryKeyRef.current = queryKey;
}, [queryKey, queryKeyRef]);
useEffect(() => {
setIsLoadingQueries(isLoading || isFetching);
}, [isLoading, isFetching, setIsLoadingQueries]);
useEffect(() => (): void => setIsLoadingQueries(false), [setIsLoadingQueries]);
if (isLoading || (isFetching && rows.length === 0)) {
return <LogsLoading />;
}
if (error) {
return <ErrorInPlace error={error} data-testid="logs-patterns-error" />;
}
if (rows.length === 0) {
return (
<div className={styles.patternsView} data-testid="logs-patterns-empty">
{isFilterApplied ? (
<EmptyLogsSearch dataSource={DataSource.LOGS} panelType="LIST" />
) : (
<NoLogs dataSource={DataSource.LOGS} />
)}
</div>
);
}
return (
<div className={styles.patternsView} data-testid="logs-patterns-view">
{sampleRate > 1 && (
<div className={styles.header}>
<Typography
variant="paragraph"
size="small"
weight="regular"
color="secondary"
as="span"
textOverflow="wrap"
testId="logs-patterns-sample-note"
>
Counts are estimated from a 1-in-{sampleRate.toLocaleString('en-US')}{' '}
sample of the matching logs.
</Typography>
</div>
)}
<div className={styles.table}>
<TanStackTable
data={rows}
columns={columns}
getRowKey={getPatternRowKey}
disableVirtualScroll
testId="logs-patterns-table"
/>
</div>
</div>
);
}
export default LogsPatternsView;

View File

@@ -0,0 +1,49 @@
import { Color } from '@signozhq/design-tokens';
import Uplot from 'components/Uplot';
import { PatternRow } from './types';
import styles from './LogsPatternsView.module.scss';
const WIDTH = 120;
const HEIGHT = 24;
const OPTIONS: uPlot.Options = {
width: WIDTH,
height: HEIGHT,
legend: { show: false },
cursor: { show: false },
padding: [2, 0, 2, 0],
scales: {
x: { time: false },
y: { range: (_u, _min, max): uPlot.Range.MinMax => [0, Math.max(max, 1)] },
},
series: [
{},
{
stroke: Color.BG_ROBIN_500,
fill: 'rgba(78, 116, 248, 0.20)',
width: 1.2,
points: { show: false },
},
],
axes: [{ show: false }, { show: false }],
};
interface PatternSparklineProps {
trend: PatternRow['trend'];
testId: string;
}
function PatternSparkline({
trend,
testId,
}: PatternSparklineProps): JSX.Element {
return (
<div className={styles.sparkline} data-testid={testId}>
<Uplot data={trend} options={OPTIONS} />
</div>
);
}
export default PatternSparkline;

View File

@@ -0,0 +1,235 @@
import type {
Querybuildertypesv5PatternsDataDTO,
Querybuildertypesv5QueryRangeRequestDTO,
} from 'api/generated/services/sigNoz.schemas';
import { ENVIRONMENT } from 'constants/env';
import { initialQueriesMap } from 'constants/queryBuilder';
import { ChangeViewFunctionType } from 'hooks/useHandleExplorerTabChange';
import { server } from 'mocks-server/server';
import { ExplorerViews } from 'pages/LogsExplorer/utils';
import { rest } from 'msw';
import {
NO_DELAY_USER_EVENT,
render,
screen,
userEvent,
} from 'tests/test-utils';
import { Query } from 'types/api/queryBuilder/queryBuilderData';
import { QueryBuilderContextType } from 'types/common/queryBuilder';
import LogsPatternsView from '../LogsPatternsView';
const QUERY_RANGE_URL = `${ENVIRONMENT.baseURL}/api/v5/query_range`;
const FILTER = "service.name = 'api'";
const stagedQuery: Query = {
...initialQueriesMap.logs,
id: 'staged-1',
builder: {
...initialQueriesMap.logs.builder,
queryData: [
{
...initialQueriesMap.logs.builder.queryData[0],
filter: { expression: FILTER },
},
],
},
};
const patternsData = (
overrides: Partial<Querybuildertypesv5PatternsDataDTO> = {},
): Querybuildertypesv5PatternsDataDTO => ({
queryName: 'A',
sampleRate: 1,
total: 1500,
patterns: [
{
id: '11',
pattern: 'GET <*> 200',
count: 1234,
percent: 82.27,
trend: [],
},
{ id: '22', pattern: '', count: 266, percent: 17.73, trend: null },
],
...overrides,
});
function mockPatterns(
data: Querybuildertypesv5PatternsDataDTO,
requests: Querybuildertypesv5QueryRangeRequestDTO[] = [],
): void {
server.use(
rest.post(QUERY_RANGE_URL, async (req, res, ctx) => {
requests.push(await req.json());
return res(
ctx.status(200),
ctx.json({
status: 'success',
data: { type: 'pattern', data: { results: [data] } },
}),
);
}),
);
}
const updateQueriesData: QueryBuilderContextType['updateQueriesData'] = (
query,
type,
updateCallback,
) => ({
...query,
builder: { ...query.builder, [type]: query.builder[type].map(updateCallback) },
});
const handleChangeSelectedView =
jest.fn() as jest.MockedFunction<ChangeViewFunctionType>;
const renderView = (): void => {
render(
<LogsPatternsView
queryKeyRef={{ current: null }}
handleChangeSelectedView={handleChangeSelectedView}
setIsLoadingQueries={jest.fn()}
/>,
undefined,
{
queryBuilderOverrides: {
stagedQuery,
updateQueriesData,
} as Partial<QueryBuilderContextType>,
},
);
};
describe('LogsPatternsView', () => {
it('requests the patterns of the staged filter', async () => {
const requests: Querybuildertypesv5QueryRangeRequestDTO[] = [];
mockPatterns(patternsData(), requests);
renderView();
await screen.findByTestId('logs-patterns-table');
expect(requests).toHaveLength(1);
const [request] = requests;
expect(request.requestType).toBe('pattern');
expect(request.compositeQuery?.queries).toStrictEqual([
{
type: 'builder_query',
spec: {
name: 'A',
signal: 'logs',
limit: 100,
stepInterval: Math.ceil(
((request.end ?? 0) - (request.start ?? 0)) / 1000 / 60,
),
filter: { expression: FILTER },
},
},
]);
});
it('shows each pattern with its count and share', async () => {
mockPatterns(patternsData());
renderView();
await expect(
screen.findByTestId('pattern-template-11'),
).resolves.toHaveTextContent('GET <*> 200');
expect(screen.getByTestId('pattern-count-11')).toHaveTextContent('1,234');
expect(screen.getByTestId('pattern-share-11')).toHaveTextContent('82.3%');
expect(screen.getByTestId('pattern-trend-11')).toBeInTheDocument();
});
it('labels a pattern without a template as unknown', async () => {
mockPatterns(patternsData());
renderView();
await expect(
screen.findByTestId('pattern-template-22'),
).resolves.toHaveTextContent('Unknown pattern');
});
it('shows the logs of a pattern in the list view, filtered on its template', async () => {
const user = userEvent.setup(NO_DELAY_USER_EVENT);
mockPatterns(patternsData());
renderView();
await user.click(await screen.findByTestId('pattern-show-logs-11'));
expect(handleChangeSelectedView).toHaveBeenCalledTimes(1);
const [view, queryData] = handleChangeSelectedView.mock.calls[0];
expect(view).toBe(ExplorerViews.LIST);
expect(queryData?.query.builder.queryData[0].filter).toStrictEqual({
expression: "service.name = 'api' AND pattern('GET <*> 200')",
});
});
it('offers no logs for a pattern without a template', async () => {
mockPatterns(patternsData());
renderView();
await screen.findByTestId('pattern-template-22');
expect(screen.queryByTestId('pattern-show-logs-22')).not.toBeInTheDocument();
});
it('notes that counts are estimated when the logs were sampled', async () => {
mockPatterns(patternsData({ sampleRate: 1200 }));
renderView();
await expect(
screen.findByTestId('logs-patterns-sample-note'),
).resolves.toHaveTextContent(
'Counts are estimated from a 1-in-1,200 sample of the matching logs.',
);
});
it('has no sample note when every log was read', async () => {
mockPatterns(patternsData());
renderView();
await screen.findByTestId('logs-patterns-table');
expect(
screen.queryByTestId('logs-patterns-sample-note'),
).not.toBeInTheDocument();
});
it('shows the empty search state when no pattern matches the filter', async () => {
mockPatterns(patternsData({ patterns: [], total: 0 }));
renderView();
await expect(
screen.findByTestId('logs-patterns-empty'),
).resolves.toHaveTextContent('This query had no results.');
});
it('shows the error from the server', async () => {
server.use(
rest.post(QUERY_RANGE_URL, (_req, res, ctx) =>
res(
ctx.status(400),
ctx.json({
status: 'error',
error: {
code: 'invalid_input',
message: 'pattern requests take one logs builder query',
},
}),
),
),
);
renderView();
await expect(
screen.findByTestId('logs-patterns-error'),
).resolves.toHaveTextContent('pattern requests take one logs builder query');
});
});

View File

@@ -0,0 +1,72 @@
import {
addPatternToExpression,
formatPatternShare,
getPatternsTimeRange,
getTrendSeries,
} from '../utils';
const MS_TO_NS = 1_000_000;
describe('getPatternsTimeRange', () => {
it('picks the smallest step that keeps the trend within 60 steps', () => {
expect(getPatternsTimeRange(0, 3_600_000 * MS_TO_NS)).toStrictEqual({
startMs: 0,
endMs: 3_600_000,
stepSeconds: 60,
});
expect(getPatternsTimeRange(0, 3_601_000 * MS_TO_NS).stepSeconds).toBe(61);
});
});
describe('getTrendSeries', () => {
it('fills the steps the server left out with zero', () => {
const range = { startMs: 1000, endMs: 1000 + 4 * 60_000, stepSeconds: 60 };
expect(
getTrendSeries(
[
{ timestamp: 1000 + 60_000, count: 5 },
{ timestamp: 1000 + 3 * 60_000, count: 2 },
],
range,
),
).toStrictEqual([
[1000, 61_000, 121_000, 181_000],
[0, 5, 0, 2],
]);
});
it('returns a flat line for a pattern without a trend', () => {
const range = { startMs: 0, endMs: 120_000, stepSeconds: 60 };
expect(getTrendSeries(null, range)).toStrictEqual([
[0, 60_000],
[0, 0],
]);
});
});
describe('formatPatternShare', () => {
it('keeps a tiny share from reading as zero', () => {
expect(formatPatternShare(0.02)).toBe('<0.1%');
expect(formatPatternShare(12.345)).toBe('12.3%');
});
});
describe('addPatternToExpression', () => {
it('sets the pattern filter when there is no expression', () => {
expect(addPatternToExpression(' ', 'auth <*>')).toBe("pattern('auth <*>')");
});
it('escapes backslashes and single quotes in the template', () => {
expect(addPatternToExpression('', "it's C:\\tmp")).toBe(
"pattern('it\\'s C:\\\\tmp')",
);
});
it('keeps an OR expression grouped under the added AND', () => {
expect(addPatternToExpression("a = '1' OR b = '2'", 'x')).toBe(
"(a = '1' OR b = '2') AND pattern('x')",
);
});
});

View File

@@ -0,0 +1,13 @@
export interface PatternRow {
id: string;
pattern: string;
count: number;
percent: number;
trend: [number[], number[]];
}
export interface PatternsTimeRange {
startMs: number;
endMs: number;
stepSeconds: number;
}

View File

@@ -0,0 +1,93 @@
import { useMemo } from 'react';
import { useQuery } from 'react-query';
// eslint-disable-next-line no-restricted-imports
import { useSelector } from 'react-redux';
import { queryRangeV5 } from 'api/generated/services/querier';
import {
QueryRangeV5200,
RenderErrorResponseDTO,
} from 'api/generated/services/sigNoz.schemas';
import { ErrorType } from 'api/generatedAPIInstance';
import { getFilter } from 'api/v5/queryRange/prepareQueryRangePayloadV5';
import { REACT_QUERY_KEY } from 'constants/reactQueryKeys';
import { getListQuery } from 'container/LogsExplorerViews/explorerUtils';
import { useQueryBuilder } from 'hooks/queryBuilder/useQueryBuilder';
import { AppState } from 'store/reducers';
import APIError from 'types/api/error';
import { GlobalReducer } from 'types/reducer/globalTime';
import { toAPIError } from 'utils/errorUtils';
import { PatternRow } from './types';
import {
buildPatternsRequest,
getPatternsData,
getPatternsTimeRange,
toPatternRows,
} from './utils';
interface UseLogsPatterns {
rows: PatternRow[];
sampleRate: number;
isFilterApplied: boolean;
isLoading: boolean;
isFetching: boolean;
error: APIError | null;
queryKey: unknown[];
}
export function useLogsPatterns(): UseLogsPatterns {
const { stagedQuery } = useQueryBuilder();
const { minTime, maxTime } = useSelector<AppState, GlobalReducer>(
(state) => state.globalTime,
);
const listQuery = useMemo(() => getListQuery(stagedQuery), [stagedQuery]);
const filterExpression = listQuery ? getFilter(listQuery).expression : '';
const timeRange = useMemo(
() => getPatternsTimeRange(minTime, maxTime),
[minTime, maxTime],
);
const request = useMemo(
() =>
buildPatternsRequest(
listQuery?.queryName || 'A',
filterExpression,
timeRange,
),
[listQuery?.queryName, filterExpression, timeRange],
);
// The staged query id changes on every Run Query, so an unchanged filter refetches too.
const queryKey = useMemo(
() => [REACT_QUERY_KEY.GET_LOG_PATTERNS, request, stagedQuery?.id],
[request, stagedQuery?.id],
);
const { data, isLoading, isIdle, isFetching, error } = useQuery<
QueryRangeV5200,
ErrorType<RenderErrorResponseDTO>
>({
queryKey,
queryFn: ({ signal }) => queryRangeV5(request, signal),
enabled: !!listQuery,
});
const patternsData = useMemo(() => getPatternsData(data), [data]);
const rows = useMemo(
() => toPatternRows(patternsData, timeRange),
[patternsData, timeRange],
);
const apiError = useMemo(() => (error ? toAPIError(error) : null), [error]);
return {
rows,
sampleRate: patternsData?.sampleRate ?? 1,
isFilterApplied: filterExpression.trim() !== '',
isLoading: isLoading || isIdle,
isFetching,
error: apiError,
queryKey,
};
}

View File

@@ -0,0 +1,98 @@
import { useMemo } from 'react';
import { Button } from '@signozhq/ui/button';
import { Progress } from '@signozhq/ui/progress';
import { Typography } from '@signozhq/ui/typography';
import TanStackTable from 'components/TanStackTableView';
import type { TableColumnDef } from 'components/TanStackTableView/types';
import PatternSparkline from './PatternSparkline';
import { PatternRow } from './types';
import { formatPatternCount, formatPatternShare } from './utils';
import styles from './LogsPatternsView.module.scss';
export function usePatternColumns(
onShowLogs: (template: string) => void,
): TableColumnDef<PatternRow>[] {
return useMemo(
(): TableColumnDef<PatternRow>[] => [
{
id: 'count',
header: 'Count',
accessorKey: 'count',
width: { fixed: 120 },
cell: ({ row }): JSX.Element => (
<TanStackTable.Text data-testid={`pattern-count-${row.id}`}>
{formatPatternCount(row.count)}
</TanStackTable.Text>
),
},
{
id: 'share',
header: 'Share',
accessorKey: 'percent',
width: { fixed: 140 },
cell: ({ row }): JSX.Element => (
<div className={styles.share}>
<TanStackTable.Text data-testid={`pattern-share-${row.id}`}>
{formatPatternShare(row.percent)}
</TanStackTable.Text>
<Progress
percent={row.percent}
color="primary"
aria-label="Share of logs"
/>
</div>
),
},
{
id: 'trend',
header: 'Trend',
width: { fixed: 150 },
cell: ({ row }): JSX.Element => (
<PatternSparkline trend={row.trend} testId={`pattern-trend-${row.id}`} />
),
},
{
id: 'pattern',
header: 'Pattern',
accessorKey: 'pattern',
width: { min: 320 },
cell: ({ row }): JSX.Element =>
row.pattern ? (
<div className={styles.patternCell}>
<span
className={styles.template}
data-testid={`pattern-template-${row.id}`}
>
{row.pattern}
</span>
<Button
variant="link"
color="primary"
size="sm"
onClick={(): void => onShowLogs(row.pattern)}
testId={`pattern-show-logs-${row.id}`}
aria-label={`Show logs of pattern ${row.pattern}`}
>
Show logs
</Button>
</div>
) : (
<Typography
variant="paragraph"
size="base"
weight="regular"
color="tertiary"
as="span"
textOverflow="wrap"
data-testid={`pattern-template-${row.id}`}
>
Unknown pattern
</Typography>
),
},
],
[onShowLogs],
);
}

View File

@@ -0,0 +1,38 @@
import { useCallback } from 'react';
import { getFilter } from 'api/v5/queryRange/prepareQueryRangePayloadV5';
import { useQueryBuilder } from 'hooks/queryBuilder/useQueryBuilder';
import { ChangeViewFunctionType } from 'hooks/useHandleExplorerTabChange';
import { ExplorerViews } from 'pages/LogsExplorer/utils';
import { addPatternToExpression } from './utils';
export function useShowPatternLogs(
handleChangeSelectedView: ChangeViewFunctionType,
): (template: string) => void {
const { stagedQuery, updateQueriesData } = useQueryBuilder();
return useCallback(
(template: string): void => {
if (!stagedQuery || !template) {
return;
}
const query = updateQueriesData(stagedQuery, 'queryData', (item, index) =>
index === 0
? {
...item,
filter: {
expression: addPatternToExpression(
getFilter(item).expression,
template,
),
},
}
: item,
);
handleChangeSelectedView(ExplorerViews.LIST, { query });
},
[stagedQuery, updateQueriesData, handleChangeSelectedView],
);
}

View File

@@ -0,0 +1,128 @@
import {
Querybuildertypesv5PatternDTO,
Querybuildertypesv5PatternsDataDTO,
Querybuildertypesv5QueryBuilderQueryGithubComSigNozSignozPkgTypesQuerybuildertypesQuerybuildertypesv5LogAggregationDTOSignal as LogSignal,
Querybuildertypesv5QueryEnvelopeBuilderDTOType,
Querybuildertypesv5QueryRangeRequestDTO,
Querybuildertypesv5RequestTypeDTO,
QueryRangeV5200,
} from 'api/generated/services/sigNoz.schemas';
import { formatStringLiteralForExpression } from 'components/QueryBuilderV2/utils';
import { NANO_SECOND_MULTIPLIER } from 'store/globalTime';
import { PatternRow, PatternsTimeRange } from './types';
export const PATTERNS_LIMIT = 100;
// The backend caps a pattern's trend at 60 steps.
const MAX_TREND_STEPS = 60;
export function getPatternsTimeRange(
minTimeNs: number,
maxTimeNs: number,
): PatternsTimeRange {
const startMs = Math.floor(minTimeNs / NANO_SECOND_MULTIPLIER);
const endMs = Math.floor(maxTimeNs / NANO_SECOND_MULTIPLIER);
const stepSeconds = Math.max(
1,
Math.ceil((endMs - startMs) / 1000 / MAX_TREND_STEPS),
);
return { startMs, endMs, stepSeconds };
}
export function buildPatternsRequest(
queryName: string,
filterExpression: string,
{ startMs, endMs, stepSeconds }: PatternsTimeRange,
): Querybuildertypesv5QueryRangeRequestDTO {
return {
schemaVersion: 'v1',
start: startMs,
end: endMs,
requestType: Querybuildertypesv5RequestTypeDTO.pattern,
compositeQuery: {
queries: [
{
type: Querybuildertypesv5QueryEnvelopeBuilderDTOType.builder_query,
spec: {
name: queryName,
signal: LogSignal.logs,
limit: PATTERNS_LIMIT,
stepInterval: stepSeconds,
filter: { expression: filterExpression },
},
},
],
},
};
}
export function getPatternsData(
response: QueryRangeV5200 | undefined,
): Querybuildertypesv5PatternsDataDTO | null {
const result = response?.data?.data?.results?.[0];
if (!result || typeof result !== 'object' || !('sampleRate' in result)) {
return null;
}
return result as Querybuildertypesv5PatternsDataDTO;
}
// The backend leaves out steps without logs; fill them with zero on the request's step grid.
export function getTrendSeries(
trend: Querybuildertypesv5PatternDTO['trend'],
{ startMs, endMs, stepSeconds }: PatternsTimeRange,
): [number[], number[]] {
const stepMs = stepSeconds * 1000;
const steps = Math.max(1, Math.ceil((endMs - startMs) / stepMs));
const xs = Array.from({ length: steps }, (_, i) => startMs + i * stepMs);
const ys = new Array<number>(steps).fill(0);
(trend ?? []).forEach(({ timestamp, count }) => {
const index = Math.round((timestamp - startMs) / stepMs);
if (index >= 0 && index < steps) {
ys[index] += count;
}
});
return [xs, ys];
}
export function toPatternRows(
data: Querybuildertypesv5PatternsDataDTO | null,
timeRange: PatternsTimeRange,
): PatternRow[] {
return (data?.patterns ?? []).map((item) => ({
id: item.id,
pattern: item.pattern,
count: item.count,
percent: item.percent,
trend: getTrendSeries(item.trend, timeRange),
}));
}
export function getPatternRowKey(row: PatternRow): string {
return row.id;
}
export function formatPatternCount(count: number): string {
return count.toLocaleString('en-US');
}
export function formatPatternShare(percent: number): string {
if (percent > 0 && percent < 0.1) {
return '<0.1%';
}
return `${percent.toFixed(1)}%`;
}
// Parenthesised when it has an OR, which binds looser than the added AND.
export function addPatternToExpression(
expression: string,
template: string,
): string {
const patternFilter = `pattern(${formatStringLiteralForExpression(template)})`;
const base = expression.trim();
if (!base) {
return patternFilter;
}
const scoped = /\bor\b/i.test(base) ? `(${base})` : base;
return `${scoped} AND ${patternFilter}`;
}

View File

@@ -5,6 +5,7 @@ import {
SquareMousePointer,
Terminal,
Binoculars,
Layers,
} from '@signozhq/icons';
import { Button, Tooltip } from 'antd';
import cx from 'classnames';
@@ -29,7 +30,7 @@ export default function LeftToolbarActions({
showFilter,
handleFilterVisibilityChange,
}: LeftToolbarActionsProps): JSX.Element {
const { clickhouse, list, timeseries, table, trace } = items;
const { clickhouse, list, timeseries, table, trace, patterns } = items;
return (
<div className="left-toolbar">
@@ -134,6 +135,25 @@ export default function LeftToolbarActions({
</Button>
</Tooltip>
)}
{patterns?.show && (
<Tooltip title="Patterns">
<Button
disabled={patterns.disabled}
className={cx(
'patterns-view-tab',
'explorer-view-option',
selectedView === patterns.key ? activeTab : '',
)}
onClick={(): void => onChangeSelectedView(patterns.key)}
data-testid="explorer-view-patterns"
aria-pressed={selectedView === patterns.key}
>
<Layers size={14} />
Patterns
</Button>
</Tooltip>
)}
</div>
</div>
);

View File

@@ -5,8 +5,11 @@ import {
initialQueryBuilderFormValues,
PANEL_TYPES,
} from 'constants/queryBuilder';
import { ENVIRONMENT } from 'constants/env';
import { LOCALSTORAGE } from 'constants/localStorage';
import { noop } from 'lodash-es';
import { server } from 'mocks-server/server';
import { rest } from 'msw';
import { PreferenceContextProvider } from 'providers/preferences/context/PreferenceContextProvider';
import { QueryBuilderContext } from 'providers/QueryBuilder';
import { render, screen, userEvent, waitFor } from 'tests/test-utils';
@@ -146,6 +149,60 @@ describe('Logs Explorer Tests', () => {
);
});
it('renders the patterns view without asking for the log list', async () => {
const requestTypes: string[] = [];
server.use(
rest.post(
`${ENVIRONMENT.baseURL}/api/v5/query_range`,
async (req, res, ctx) => {
const body = await req.json();
requestTypes.push(body.requestType);
return res(
ctx.status(200),
ctx.json({
status: 'success',
data: {
type: 'pattern',
data: {
results: [
{
queryName: 'A',
sampleRate: 1,
total: 3,
patterns: [
{ id: '1', pattern: 'ok <*>', count: 3, percent: 100, trend: [] },
],
},
],
},
},
}),
);
},
),
);
render(
<PreferenceContextProvider>
<LogsExplorer />
</PreferenceContextProvider>,
undefined,
{
initialRoute: `/logs-explorer/?panelTypes=%22list%22&logsExplorerView=%22patterns%22&compositeQuery=${encodeURIComponent(
encodeURIComponent(JSON.stringify(initialQueriesMap.logs)),
)}`,
},
);
await expect(
screen.findByTestId('pattern-template-1'),
).resolves.toHaveTextContent('ok <*>');
expect(screen.getByTestId('explorer-view-patterns')).toHaveClass(
'active-tab',
);
expect(requestTypes).toStrictEqual(['pattern']);
});
// update this test properly
it.skip('Logs Explorer Page should render with data', async () => {
const { queryByText, queryByTestId } = render(

View File

@@ -0,0 +1,151 @@
import { QueryParams } from 'constants/query';
import { initialQueriesMap, PANEL_TYPES } from 'constants/queryBuilder';
import ROUTES from 'constants/routes';
import LeftToolbarActions from 'container/QueryBuilder/components/ToolbarActions/LeftToolbarActions';
import { noop } from 'lodash-es';
import {
NO_DELAY_USER_EVENT,
render,
screen,
userEvent,
waitFor,
} from 'tests/test-utils';
import { Query } from 'types/api/queryBuilder/queryBuilderData';
import { getUnstableCurrentSearchParams } from 'utils/getUnstableCurrentSearchParams';
import { QueryBuilderContextType } from 'types/common/queryBuilder';
import { useLogsExplorerView } from '../useLogsExplorerView';
import { ExplorerViews } from '../utils';
const view = (key: ExplorerViews): Record<string, unknown> => ({
name: key,
label: key,
show: true,
disabled: false,
key,
});
const ITEMS = {
list: view(ExplorerViews.LIST),
timeseries: view(ExplorerViews.TIMESERIES),
patterns: view(ExplorerViews.PATTERNS),
};
function ViewSwitcher(): JSX.Element {
const { selectedView, handleChangeSelectedView } = useLogsExplorerView();
return (
<LeftToolbarActions
items={ITEMS}
selectedView={selectedView}
onChangeSelectedView={handleChangeSelectedView}
showFilter
handleFilterVisibilityChange={noop}
/>
);
}
const route = (panelType: string, patterns = false): string => {
const params = new URLSearchParams({
[QueryParams.panelTypes]: JSON.stringify(panelType),
});
if (patterns) {
params.set(QueryParams.logsExplorerView, JSON.stringify('patterns'));
}
return `${ROUTES.LOGS_EXPLORER}?${params}`;
};
// The view param is a shallow nuqs write, which the router's location does not see.
const urlParam = (key: string): string | null =>
getUnstableCurrentSearchParams().get(key);
const redirectWithQueryBuilderData = jest.fn() as jest.MockedFunction<
QueryBuilderContextType['redirectWithQueryBuilderData']
>;
const renderAt = (initialRoute: string, panelType: PANEL_TYPES): void => {
render(<ViewSwitcher />, undefined, {
initialRoute,
queryBuilderOverrides: {
panelType,
currentQuery: initialQueriesMap.logs,
handleSetConfig: jest.fn(),
redirectWithQueryBuilderData,
updateAllQueriesOperators: (query: Query): Query => query,
updateQueriesData: (query: Query): Query => query,
} as Partial<QueryBuilderContextType>,
});
};
describe('useLogsExplorerView', () => {
it('opens on the patterns view from the URL', () => {
renderAt(route('list', true), PANEL_TYPES.LIST);
expect(screen.getByTestId('explorer-view-patterns')).toHaveAttribute(
'aria-pressed',
'true',
);
expect(screen.getByTestId('explorer-view-list')).toHaveAttribute(
'aria-pressed',
'false',
);
});
it('switches from list to patterns by setting only the view param', async () => {
const user = userEvent.setup(NO_DELAY_USER_EVENT);
renderAt(route('list'), PANEL_TYPES.LIST);
await user.click(screen.getByTestId('explorer-view-patterns'));
await waitFor(() =>
expect(urlParam(QueryParams.logsExplorerView)).toBe('"patterns"'),
);
expect(urlParam(QueryParams.panelTypes)).toBe('"list"');
expect(redirectWithQueryBuilderData).not.toHaveBeenCalled();
expect(screen.getByTestId('explorer-view-patterns')).toHaveAttribute(
'aria-pressed',
'true',
);
});
it('switches from patterns back to list by clearing the view param', async () => {
const user = userEvent.setup(NO_DELAY_USER_EVENT);
renderAt(route('list', true), PANEL_TYPES.LIST);
await user.click(screen.getByTestId('explorer-view-list'));
await waitFor(() =>
expect(urlParam(QueryParams.logsExplorerView)).toBeNull(),
);
expect(redirectWithQueryBuilderData).not.toHaveBeenCalled();
expect(screen.getByTestId('explorer-view-list')).toHaveAttribute(
'aria-pressed',
'true',
);
});
it('switches from time series to patterns in one redirect to the list panel type', async () => {
const user = userEvent.setup(NO_DELAY_USER_EVENT);
renderAt(route('graph'), PANEL_TYPES.TIME_SERIES);
await user.click(screen.getByTestId('explorer-view-patterns'));
expect(redirectWithQueryBuilderData).toHaveBeenCalledTimes(1);
expect(redirectWithQueryBuilderData.mock.calls[0][1]).toStrictEqual({
[QueryParams.logsExplorerView]: ExplorerViews.PATTERNS,
[QueryParams.panelTypes]: PANEL_TYPES.LIST,
});
});
it('switches from patterns to time series and clears the view param', async () => {
const user = userEvent.setup(NO_DELAY_USER_EVENT);
renderAt(route('list', true), PANEL_TYPES.LIST);
await user.click(screen.getByTestId('explorer-view-timeseries'));
expect(redirectWithQueryBuilderData).toHaveBeenCalledTimes(1);
expect(redirectWithQueryBuilderData.mock.calls[0][1]).toStrictEqual({
[QueryParams.logsExplorerView]: null,
[QueryParams.panelTypes]: PANEL_TYPES.TIME_SERIES,
});
});
});

View File

@@ -10,29 +10,19 @@ import { useSignalFieldApis } from 'components/QuickFilters/hooks/useSignalField
import { QuickFiltersSource } from 'components/QuickFilters/types';
import WarningPopover from 'components/WarningPopover/WarningPopover';
import { LOCALSTORAGE } from 'constants/localStorage';
import { PANEL_TYPES } from 'constants/queryBuilder';
import { usePageActions } from 'container/AIAssistant/pageActions/usePageActions';
import LogExplorerQuerySection from 'container/LogExplorerQuerySection';
import LogsExplorerViewsContainer from 'container/LogsExplorerViews';
import LogsPatternsView from 'container/LogsPatternsView/LogsPatternsView';
import LeftToolbarActions from 'container/QueryBuilder/components/ToolbarActions/LeftToolbarActions';
import RightToolbarActions from 'container/QueryBuilder/components/ToolbarActions/RightToolbarActions';
import Toolbar from 'container/Toolbar/Toolbar';
import { useGetPanelTypesQueryParam } from 'hooks/queryBuilder/useGetPanelTypesQueryParam';
import { useQueryBuilder } from 'hooks/queryBuilder/useQueryBuilder';
import {
ICurrentQueryData,
useHandleExplorerTabChange,
} from 'hooks/useHandleExplorerTabChange';
import { useIsAIAssistantEnabled } from 'hooks/useIsAIAssistantEnabled';
import { defaultTo, isEmpty, isNull } from 'lodash-es';
import { isEmpty, isNull } from 'lodash-es';
import ErrorBoundaryFallback from 'pages/ErrorBoundaryFallback/ErrorBoundaryFallback';
import { EventSourceProvider } from 'providers/EventSource';
import { Warning } from 'types/api';
import { DataSource } from 'types/common/queryBuilder';
import {
explorerViewToPanelType,
panelTypeToExplorerView,
} from 'utils/explorerUtils';
import {
logsAddFilterAction,
@@ -40,6 +30,7 @@ import {
logsRunQueryAction,
logsSaveViewAction,
} from './aiActions';
import { useLogsExplorerView } from './useLogsExplorerView';
import { ExplorerViews } from './utils';
import './LogsExplorer.styles.scss';
@@ -47,10 +38,7 @@ import './LogsExplorer.styles.scss';
function LogsExplorer(): JSX.Element {
const [showLiveLogs, setShowLiveLogs] = useState<boolean>(false);
// Get panel type from URL
const panelTypesFromUrl = useGetPanelTypesQueryParam(PANEL_TYPES.LIST);
const selectedView = panelTypeToExplorerView[panelTypesFromUrl];
const { selectedView, handleChangeSelectedView } = useLogsExplorerView();
useEffect(() => {
if (selectedView !== ExplorerViews.LIST) {
@@ -70,14 +58,11 @@ function LogsExplorer(): JSX.Element {
const {
handleRunQuery,
handleSetConfig,
currentQuery,
handleSetQueryData,
redirectWithQueryBuilderData,
} = useQueryBuilder();
const { handleExplorerTabChange } = useHandleExplorerTabChange();
const quickFilterFieldApis = useSignalFieldApis();
const isAIAssistantEnabled = useIsAIAssistantEnabled();
@@ -111,20 +96,6 @@ function LogsExplorer(): JSX.Element {
const [warning, setWarning] = useState<Warning | undefined>();
const handleChangeSelectedView = useCallback(
(view: ExplorerViews, querySearchParameters?: ICurrentQueryData): void => {
const nextPanelType = defaultTo(
explorerViewToPanelType[view],
PANEL_TYPES.LIST,
);
handleSetConfig(nextPanelType, DataSource.LOGS);
handleExplorerTabChange(nextPanelType, querySearchParameters);
},
[handleSetConfig, handleExplorerTabChange],
);
// ─── AI Assistant page actions (only when license feature is on) ───────────
const aiActions = useMemo(
() =>
@@ -208,6 +179,13 @@ function LogsExplorer(): JSX.Element {
show: false,
key: 'clickhouse',
},
patterns: {
name: 'patterns',
label: 'Patterns',
disabled: false,
show: true,
key: 'patterns',
},
}),
[],
);
@@ -272,6 +250,12 @@ function LogsExplorer(): JSX.Element {
<div className="logs-explorer-views">
{isCancelled ? (
<QueryCancelledPlaceholder subText='Click "Run Query" to load logs.' />
) : selectedView === ExplorerViews.PATTERNS && !showLiveLogs ? (
<LogsPatternsView
queryKeyRef={listQueryKeyRef}
handleChangeSelectedView={handleChangeSelectedView}
setIsLoadingQueries={setIsLoadingQueries}
/>
) : (
<LogsExplorerViewsContainer
listQueryKeyRef={listQueryKeyRef}

View File

@@ -0,0 +1,89 @@
import { useCallback, useMemo } from 'react';
import { QueryParams } from 'constants/query';
import { PANEL_TYPES } from 'constants/queryBuilder';
import { useGetPanelTypesQueryParam } from 'hooks/queryBuilder/useGetPanelTypesQueryParam';
import { useQueryBuilder } from 'hooks/queryBuilder/useQueryBuilder';
import {
ICurrentQueryData,
useHandleExplorerTabChange,
} from 'hooks/useHandleExplorerTabChange';
import { defaultTo } from 'lodash-es';
import { useQueryState } from 'nuqs';
import { DataSource } from 'types/common/queryBuilder';
import {
explorerViewToPanelType,
panelTypeToExplorerView,
} from 'utils/explorerUtils';
import { parseAsJsonNoValidate } from 'utils/nuqsParsers';
import { ExplorerViews } from './utils';
interface UseLogsExplorerView {
selectedView: ExplorerViews;
handleChangeSelectedView: (
view: ExplorerViews,
querySearchParameters?: ICurrentQueryData,
) => void;
}
// Patterns runs on the list panel type, so the view lives in its own param,
// JSON-encoded like `panelTypes` because the query builder redirect writes it.
export function useLogsExplorerView(): UseLogsExplorerView {
const panelTypesFromUrl = useGetPanelTypesQueryParam(PANEL_TYPES.LIST);
const [viewParam, setViewParam] = useQueryState(
QueryParams.logsExplorerView,
parseAsJsonNoValidate<string>().withOptions({ history: 'push' }),
);
const { handleSetConfig, panelType } = useQueryBuilder();
const { handleExplorerTabChange } = useHandleExplorerTabChange();
const selectedView = useMemo(
() =>
viewParam === ExplorerViews.PATTERNS
? ExplorerViews.PATTERNS
: panelTypeToExplorerView[panelTypesFromUrl],
[viewParam, panelTypesFromUrl],
);
const handleChangeSelectedView = useCallback(
(view: ExplorerViews, querySearchParameters?: ICurrentQueryData): void => {
const nextPanelType = defaultTo(
explorerViewToPanelType[view],
PANEL_TYPES.LIST,
);
handleSetConfig(nextPanelType, DataSource.LOGS);
const toPatterns = view === ExplorerViews.PATTERNS;
if (toPatterns === (selectedView === ExplorerViews.PATTERNS)) {
handleExplorerTabChange(nextPanelType, querySearchParameters);
return;
}
const nextViewParam = toPatterns ? ExplorerViews.PATTERNS : null;
// handleExplorerTabChange skips the redirect when the panel type is unchanged.
if (nextPanelType === panelType && !querySearchParameters) {
void setViewParam(nextViewParam);
return;
}
handleExplorerTabChange(
nextPanelType,
querySearchParameters,
undefined,
undefined,
{ [QueryParams.logsExplorerView]: nextViewParam },
);
},
[
handleSetConfig,
handleExplorerTabChange,
selectedView,
panelType,
setViewParam,
],
);
return { selectedView, handleChangeSelectedView };
}

View File

@@ -22,6 +22,7 @@ export enum ExplorerViews {
TRACE = 'trace',
TABLE = 'table',
CLICKHOUSE = 'clickhouse',
PATTERNS = 'patterns',
}
export const LogsQuickFiltersConfig: IQuickFiltersConfig[] = [

File diff suppressed because one or more lines are too long

View File

@@ -25,12 +25,13 @@ HAS=24
HASANY=25
HASALL=26
SEARCH=27
BOOL=28
NUMBER=29
QUOTED_TEXT=30
KEY=31
WS=32
FREETEXT=33
PATTERN_CALL=28
BOOL=29
NUMBER=30
QUOTED_TEXT=31
KEY=32
WS=33
FREETEXT=34
'('=1
')'=2
'['=3

File diff suppressed because one or more lines are too long

View File

@@ -25,12 +25,13 @@ HAS=24
HASANY=25
HASALL=26
SEARCH=27
BOOL=28
NUMBER=29
QUOTED_TEXT=30
KEY=31
WS=32
FREETEXT=33
PATTERN_CALL=28
BOOL=29
NUMBER=30
QUOTED_TEXT=31
KEY=32
WS=33
FREETEXT=34
'('=1
')'=2
'['=3

View File

@@ -39,12 +39,13 @@ export default class FilterQueryLexer extends Lexer {
public static readonly HASANY = 25;
public static readonly HASALL = 26;
public static readonly SEARCH = 27;
public static readonly BOOL = 28;
public static readonly NUMBER = 29;
public static readonly QUOTED_TEXT = 30;
public static readonly KEY = 31;
public static readonly WS = 32;
public static readonly FREETEXT = 33;
public static readonly PATTERN_CALL = 28;
public static readonly BOOL = 29;
public static readonly NUMBER = 30;
public static readonly QUOTED_TEXT = 31;
public static readonly KEY = 32;
public static readonly WS = 33;
public static readonly FREETEXT = 34;
public static readonly EOF = Token.EOF;
public static readonly channelNames: string[] = [ "DEFAULT_TOKEN_CHANNEL", "HIDDEN" ];
@@ -70,6 +71,7 @@ export default class FilterQueryLexer extends Lexer {
"HASTOKEN",
"HAS", "HASANY",
"HASALL", "SEARCH",
"PATTERN_CALL",
"BOOL", "NUMBER",
"QUOTED_TEXT",
"KEY", "WS",
@@ -80,8 +82,8 @@ export default class FilterQueryLexer extends Lexer {
"LPAREN", "RPAREN", "LBRACK", "RBRACK", "COMMA", "EQUALS", "NOT_EQUALS",
"NEQ", "LT", "LE", "GT", "GE", "LIKE", "ILIKE", "BETWEEN", "EXISTS", "REGEXP",
"CONTAINS", "IN", "NOT", "AND", "OR", "HASTOKEN", "HAS", "HASANY", "HASALL",
"SEARCH", "BOOL", "SIGN", "NUMBER", "QUOTED_TEXT", "SEGMENT", "EMPTY_BRACKS",
"OLD_JSON_BRACKS", "KEY", "WS", "DIGIT", "FREETEXT",
"SEARCH", "PATTERN_CALL", "BOOL", "SIGN", "NUMBER", "QUOTED_TEXT", "SEGMENT",
"EMPTY_BRACKS", "OLD_JSON_BRACKS", "KEY", "WS", "DIGIT", "FREETEXT",
];
@@ -102,122 +104,127 @@ export default class FilterQueryLexer extends Lexer {
public get modeNames(): string[] { return FilterQueryLexer.modeNames; }
public static readonly _serializedATN: number[] = [4,0,33,329,6,-1,2,0,
public static readonly _serializedATN: number[] = [4,0,34,346,6,-1,2,0,
7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,2,6,7,6,2,7,7,7,2,8,7,8,2,9,
7,9,2,10,7,10,2,11,7,11,2,12,7,12,2,13,7,13,2,14,7,14,2,15,7,15,2,16,7,
16,2,17,7,17,2,18,7,18,2,19,7,19,2,20,7,20,2,21,7,21,2,22,7,22,2,23,7,23,
2,24,7,24,2,25,7,25,2,26,7,26,2,27,7,27,2,28,7,28,2,29,7,29,2,30,7,30,2,
31,7,31,2,32,7,32,2,33,7,33,2,34,7,34,2,35,7,35,2,36,7,36,2,37,7,37,1,0,
1,0,1,1,1,1,1,2,1,2,1,3,1,3,1,4,1,4,1,5,1,5,1,5,3,5,91,8,5,1,6,1,6,1,6,
1,7,1,7,1,7,1,8,1,8,1,9,1,9,1,9,1,10,1,10,1,11,1,11,1,11,1,12,1,12,1,12,
1,12,1,12,1,13,1,13,1,13,1,13,1,13,1,13,1,14,1,14,1,14,1,14,1,14,1,14,1,
14,1,14,1,15,1,15,1,15,1,15,1,15,1,15,3,15,134,8,15,1,16,1,16,1,16,1,16,
1,16,1,16,1,16,1,17,1,17,1,17,1,17,1,17,1,17,1,17,1,17,3,17,151,8,17,1,
18,1,18,1,18,1,19,1,19,1,19,1,19,1,20,1,20,1,20,1,20,1,21,1,21,1,21,1,22,
1,22,1,22,1,22,1,22,1,22,1,22,1,22,1,22,1,23,1,23,1,23,1,23,1,24,1,24,1,
24,1,24,1,24,1,24,1,24,1,25,1,25,1,25,1,25,1,25,1,25,1,25,1,26,1,26,1,26,
1,26,1,26,1,26,1,26,1,27,1,27,1,27,1,27,1,27,1,27,1,27,1,27,1,27,3,27,210,
8,27,1,28,1,28,1,29,3,29,215,8,29,1,29,4,29,218,8,29,11,29,12,29,219,1,
29,1,29,5,29,224,8,29,10,29,12,29,227,9,29,3,29,229,8,29,1,29,1,29,3,29,
233,8,29,1,29,4,29,236,8,29,11,29,12,29,237,3,29,240,8,29,1,29,3,29,243,
8,29,1,29,1,29,4,29,247,8,29,11,29,12,29,248,1,29,1,29,3,29,253,8,29,1,
29,4,29,256,8,29,11,29,12,29,257,3,29,260,8,29,3,29,262,8,29,1,30,1,30,
1,30,1,30,5,30,268,8,30,10,30,12,30,271,9,30,1,30,1,30,1,30,1,30,1,30,5,
30,278,8,30,10,30,12,30,281,9,30,1,30,3,30,284,8,30,1,31,1,31,5,31,288,
8,31,10,31,12,31,291,9,31,1,32,1,32,1,32,1,33,1,33,1,33,1,33,1,34,1,34,
1,34,1,34,1,34,1,34,1,34,4,34,307,8,34,11,34,12,34,308,5,34,311,8,34,10,
34,12,34,314,9,34,1,35,4,35,317,8,35,11,35,12,35,318,1,35,1,35,1,36,1,36,
1,37,4,37,326,8,37,11,37,12,37,327,0,0,38,1,1,3,2,5,3,7,4,9,5,11,6,13,7,
15,8,17,9,19,10,21,11,23,12,25,13,27,14,29,15,31,16,33,17,35,18,37,19,39,
20,41,21,43,22,45,23,47,24,49,25,51,26,53,27,55,28,57,0,59,29,61,30,63,
0,65,0,67,0,69,31,71,32,73,0,75,33,1,0,29,2,0,76,76,108,108,2,0,73,73,105,
105,2,0,75,75,107,107,2,0,69,69,101,101,2,0,66,66,98,98,2,0,84,84,116,116,
2,0,87,87,119,119,2,0,78,78,110,110,2,0,88,88,120,120,2,0,83,83,115,115,
2,0,82,82,114,114,2,0,71,71,103,103,2,0,80,80,112,112,2,0,67,67,99,99,2,
0,79,79,111,111,2,0,65,65,97,97,2,0,68,68,100,100,2,0,72,72,104,104,2,0,
89,89,121,121,2,0,85,85,117,117,2,0,70,70,102,102,2,0,43,43,45,45,2,0,34,
34,92,92,2,0,39,39,92,92,4,0,35,36,64,90,95,95,97,123,7,0,35,36,45,45,47,
58,64,90,95,95,97,123,125,125,3,0,9,10,13,13,32,32,1,0,48,57,8,0,9,10,13,
13,32,34,39,41,44,44,60,62,91,91,93,93,353,0,1,1,0,0,0,0,3,1,0,0,0,0,5,
1,0,0,0,0,7,1,0,0,0,0,9,1,0,0,0,0,11,1,0,0,0,0,13,1,0,0,0,0,15,1,0,0,0,
0,17,1,0,0,0,0,19,1,0,0,0,0,21,1,0,0,0,0,23,1,0,0,0,0,25,1,0,0,0,0,27,1,
0,0,0,0,29,1,0,0,0,0,31,1,0,0,0,0,33,1,0,0,0,0,35,1,0,0,0,0,37,1,0,0,0,
0,39,1,0,0,0,0,41,1,0,0,0,0,43,1,0,0,0,0,45,1,0,0,0,0,47,1,0,0,0,0,49,1,
0,0,0,0,51,1,0,0,0,0,53,1,0,0,0,0,55,1,0,0,0,0,59,1,0,0,0,0,61,1,0,0,0,
0,69,1,0,0,0,0,71,1,0,0,0,0,75,1,0,0,0,1,77,1,0,0,0,3,79,1,0,0,0,5,81,1,
0,0,0,7,83,1,0,0,0,9,85,1,0,0,0,11,90,1,0,0,0,13,92,1,0,0,0,15,95,1,0,0,
0,17,98,1,0,0,0,19,100,1,0,0,0,21,103,1,0,0,0,23,105,1,0,0,0,25,108,1,0,
0,0,27,113,1,0,0,0,29,119,1,0,0,0,31,127,1,0,0,0,33,135,1,0,0,0,35,142,
1,0,0,0,37,152,1,0,0,0,39,155,1,0,0,0,41,159,1,0,0,0,43,163,1,0,0,0,45,
166,1,0,0,0,47,175,1,0,0,0,49,179,1,0,0,0,51,186,1,0,0,0,53,193,1,0,0,0,
55,209,1,0,0,0,57,211,1,0,0,0,59,261,1,0,0,0,61,283,1,0,0,0,63,285,1,0,
0,0,65,292,1,0,0,0,67,295,1,0,0,0,69,299,1,0,0,0,71,316,1,0,0,0,73,322,
1,0,0,0,75,325,1,0,0,0,77,78,5,40,0,0,78,2,1,0,0,0,79,80,5,41,0,0,80,4,
1,0,0,0,81,82,5,91,0,0,82,6,1,0,0,0,83,84,5,93,0,0,84,8,1,0,0,0,85,86,5,
44,0,0,86,10,1,0,0,0,87,91,5,61,0,0,88,89,5,61,0,0,89,91,5,61,0,0,90,87,
1,0,0,0,90,88,1,0,0,0,91,12,1,0,0,0,92,93,5,33,0,0,93,94,5,61,0,0,94,14,
1,0,0,0,95,96,5,60,0,0,96,97,5,62,0,0,97,16,1,0,0,0,98,99,5,60,0,0,99,18,
1,0,0,0,100,101,5,60,0,0,101,102,5,61,0,0,102,20,1,0,0,0,103,104,5,62,0,
0,104,22,1,0,0,0,105,106,5,62,0,0,106,107,5,61,0,0,107,24,1,0,0,0,108,109,
7,0,0,0,109,110,7,1,0,0,110,111,7,2,0,0,111,112,7,3,0,0,112,26,1,0,0,0,
113,114,7,1,0,0,114,115,7,0,0,0,115,116,7,1,0,0,116,117,7,2,0,0,117,118,
7,3,0,0,118,28,1,0,0,0,119,120,7,4,0,0,120,121,7,3,0,0,121,122,7,5,0,0,
122,123,7,6,0,0,123,124,7,3,0,0,124,125,7,3,0,0,125,126,7,7,0,0,126,30,
1,0,0,0,127,128,7,3,0,0,128,129,7,8,0,0,129,130,7,1,0,0,130,131,7,9,0,0,
131,133,7,5,0,0,132,134,7,9,0,0,133,132,1,0,0,0,133,134,1,0,0,0,134,32,
1,0,0,0,135,136,7,10,0,0,136,137,7,3,0,0,137,138,7,11,0,0,138,139,7,3,0,
0,139,140,7,8,0,0,140,141,7,12,0,0,141,34,1,0,0,0,142,143,7,13,0,0,143,
144,7,14,0,0,144,145,7,7,0,0,145,146,7,5,0,0,146,147,7,15,0,0,147,148,7,
1,0,0,148,150,7,7,0,0,149,151,7,9,0,0,150,149,1,0,0,0,150,151,1,0,0,0,151,
36,1,0,0,0,152,153,7,1,0,0,153,154,7,7,0,0,154,38,1,0,0,0,155,156,7,7,0,
0,156,157,7,14,0,0,157,158,7,5,0,0,158,40,1,0,0,0,159,160,7,15,0,0,160,
161,7,7,0,0,161,162,7,16,0,0,162,42,1,0,0,0,163,164,7,14,0,0,164,165,7,
10,0,0,165,44,1,0,0,0,166,167,7,17,0,0,167,168,7,15,0,0,168,169,7,9,0,0,
169,170,7,5,0,0,170,171,7,14,0,0,171,172,7,2,0,0,172,173,7,3,0,0,173,174,
7,7,0,0,174,46,1,0,0,0,175,176,7,17,0,0,176,177,7,15,0,0,177,178,7,9,0,
0,178,48,1,0,0,0,179,180,7,17,0,0,180,181,7,15,0,0,181,182,7,9,0,0,182,
183,7,15,0,0,183,184,7,7,0,0,184,185,7,18,0,0,185,50,1,0,0,0,186,187,7,
17,0,0,187,188,7,15,0,0,188,189,7,9,0,0,189,190,7,15,0,0,190,191,7,0,0,
0,191,192,7,0,0,0,192,52,1,0,0,0,193,194,7,9,0,0,194,195,7,3,0,0,195,196,
7,15,0,0,196,197,7,10,0,0,197,198,7,13,0,0,198,199,7,17,0,0,199,54,1,0,
0,0,200,201,7,5,0,0,201,202,7,10,0,0,202,203,7,19,0,0,203,210,7,3,0,0,204,
205,7,20,0,0,205,206,7,15,0,0,206,207,7,0,0,0,207,208,7,9,0,0,208,210,7,
3,0,0,209,200,1,0,0,0,209,204,1,0,0,0,210,56,1,0,0,0,211,212,7,21,0,0,212,
58,1,0,0,0,213,215,3,57,28,0,214,213,1,0,0,0,214,215,1,0,0,0,215,217,1,
0,0,0,216,218,3,73,36,0,217,216,1,0,0,0,218,219,1,0,0,0,219,217,1,0,0,0,
219,220,1,0,0,0,220,228,1,0,0,0,221,225,5,46,0,0,222,224,3,73,36,0,223,
222,1,0,0,0,224,227,1,0,0,0,225,223,1,0,0,0,225,226,1,0,0,0,226,229,1,0,
0,0,227,225,1,0,0,0,228,221,1,0,0,0,228,229,1,0,0,0,229,239,1,0,0,0,230,
232,7,3,0,0,231,233,3,57,28,0,232,231,1,0,0,0,232,233,1,0,0,0,233,235,1,
0,0,0,234,236,3,73,36,0,235,234,1,0,0,0,236,237,1,0,0,0,237,235,1,0,0,0,
237,238,1,0,0,0,238,240,1,0,0,0,239,230,1,0,0,0,239,240,1,0,0,0,240,262,
1,0,0,0,241,243,3,57,28,0,242,241,1,0,0,0,242,243,1,0,0,0,243,244,1,0,0,
0,244,246,5,46,0,0,245,247,3,73,36,0,246,245,1,0,0,0,247,248,1,0,0,0,248,
246,1,0,0,0,248,249,1,0,0,0,249,259,1,0,0,0,250,252,7,3,0,0,251,253,3,57,
28,0,252,251,1,0,0,0,252,253,1,0,0,0,253,255,1,0,0,0,254,256,3,73,36,0,
255,254,1,0,0,0,256,257,1,0,0,0,257,255,1,0,0,0,257,258,1,0,0,0,258,260,
1,0,0,0,259,250,1,0,0,0,259,260,1,0,0,0,260,262,1,0,0,0,261,214,1,0,0,0,
261,242,1,0,0,0,262,60,1,0,0,0,263,269,5,34,0,0,264,268,8,22,0,0,265,266,
5,92,0,0,266,268,9,0,0,0,267,264,1,0,0,0,267,265,1,0,0,0,268,271,1,0,0,
0,269,267,1,0,0,0,269,270,1,0,0,0,270,272,1,0,0,0,271,269,1,0,0,0,272,284,
5,34,0,0,273,279,5,39,0,0,274,278,8,23,0,0,275,276,5,92,0,0,276,278,9,0,
0,0,277,274,1,0,0,0,277,275,1,0,0,0,278,281,1,0,0,0,279,277,1,0,0,0,279,
280,1,0,0,0,280,282,1,0,0,0,281,279,1,0,0,0,282,284,5,39,0,0,283,263,1,
0,0,0,283,273,1,0,0,0,284,62,1,0,0,0,285,289,7,24,0,0,286,288,7,25,0,0,
287,286,1,0,0,0,288,291,1,0,0,0,289,287,1,0,0,0,289,290,1,0,0,0,290,64,
1,0,0,0,291,289,1,0,0,0,292,293,5,91,0,0,293,294,5,93,0,0,294,66,1,0,0,
0,295,296,5,91,0,0,296,297,5,42,0,0,297,298,5,93,0,0,298,68,1,0,0,0,299,
312,3,63,31,0,300,301,5,46,0,0,301,311,3,63,31,0,302,311,3,65,32,0,303,
311,3,67,33,0,304,306,5,46,0,0,305,307,3,73,36,0,306,305,1,0,0,0,307,308,
1,0,0,0,308,306,1,0,0,0,308,309,1,0,0,0,309,311,1,0,0,0,310,300,1,0,0,0,
310,302,1,0,0,0,310,303,1,0,0,0,310,304,1,0,0,0,311,314,1,0,0,0,312,310,
1,0,0,0,312,313,1,0,0,0,313,70,1,0,0,0,314,312,1,0,0,0,315,317,7,26,0,0,
316,315,1,0,0,0,317,318,1,0,0,0,318,316,1,0,0,0,318,319,1,0,0,0,319,320,
1,0,0,0,320,321,6,35,0,0,321,72,1,0,0,0,322,323,7,27,0,0,323,74,1,0,0,0,
324,326,8,28,0,0,325,324,1,0,0,0,326,327,1,0,0,0,327,325,1,0,0,0,327,328,
1,0,0,0,328,76,1,0,0,0,29,0,90,133,150,209,214,219,225,228,232,237,239,
242,248,252,257,259,261,267,269,277,279,283,289,308,310,312,318,327,1,6,
0,0];
31,7,31,2,32,7,32,2,33,7,33,2,34,7,34,2,35,7,35,2,36,7,36,2,37,7,37,2,38,
7,38,1,0,1,0,1,1,1,1,1,2,1,2,1,3,1,3,1,4,1,4,1,5,1,5,1,5,3,5,93,8,5,1,6,
1,6,1,6,1,7,1,7,1,7,1,8,1,8,1,9,1,9,1,9,1,10,1,10,1,11,1,11,1,11,1,12,1,
12,1,12,1,12,1,12,1,13,1,13,1,13,1,13,1,13,1,13,1,14,1,14,1,14,1,14,1,14,
1,14,1,14,1,14,1,15,1,15,1,15,1,15,1,15,1,15,3,15,136,8,15,1,16,1,16,1,
16,1,16,1,16,1,16,1,16,1,17,1,17,1,17,1,17,1,17,1,17,1,17,1,17,3,17,153,
8,17,1,18,1,18,1,18,1,19,1,19,1,19,1,19,1,20,1,20,1,20,1,20,1,21,1,21,1,
21,1,22,1,22,1,22,1,22,1,22,1,22,1,22,1,22,1,22,1,23,1,23,1,23,1,23,1,24,
1,24,1,24,1,24,1,24,1,24,1,24,1,25,1,25,1,25,1,25,1,25,1,25,1,25,1,26,1,
26,1,26,1,26,1,26,1,26,1,26,1,27,1,27,1,27,1,27,1,27,1,27,1,27,1,27,5,27,
211,8,27,10,27,12,27,214,9,27,1,27,1,27,1,28,1,28,1,28,1,28,1,28,1,28,1,
28,1,28,1,28,3,28,227,8,28,1,29,1,29,1,30,3,30,232,8,30,1,30,4,30,235,8,
30,11,30,12,30,236,1,30,1,30,5,30,241,8,30,10,30,12,30,244,9,30,3,30,246,
8,30,1,30,1,30,3,30,250,8,30,1,30,4,30,253,8,30,11,30,12,30,254,3,30,257,
8,30,1,30,3,30,260,8,30,1,30,1,30,4,30,264,8,30,11,30,12,30,265,1,30,1,
30,3,30,270,8,30,1,30,4,30,273,8,30,11,30,12,30,274,3,30,277,8,30,3,30,
279,8,30,1,31,1,31,1,31,1,31,5,31,285,8,31,10,31,12,31,288,9,31,1,31,1,
31,1,31,1,31,1,31,5,31,295,8,31,10,31,12,31,298,9,31,1,31,3,31,301,8,31,
1,32,1,32,5,32,305,8,32,10,32,12,32,308,9,32,1,33,1,33,1,33,1,34,1,34,1,
34,1,34,1,35,1,35,1,35,1,35,1,35,1,35,1,35,4,35,324,8,35,11,35,12,35,325,
5,35,328,8,35,10,35,12,35,331,9,35,1,36,4,36,334,8,36,11,36,12,36,335,1,
36,1,36,1,37,1,37,1,38,4,38,343,8,38,11,38,12,38,344,0,0,39,1,1,3,2,5,3,
7,4,9,5,11,6,13,7,15,8,17,9,19,10,21,11,23,12,25,13,27,14,29,15,31,16,33,
17,35,18,37,19,39,20,41,21,43,22,45,23,47,24,49,25,51,26,53,27,55,28,57,
29,59,0,61,30,63,31,65,0,67,0,69,0,71,32,73,33,75,0,77,34,1,0,30,2,0,76,
76,108,108,2,0,73,73,105,105,2,0,75,75,107,107,2,0,69,69,101,101,2,0,66,
66,98,98,2,0,84,84,116,116,2,0,87,87,119,119,2,0,78,78,110,110,2,0,88,88,
120,120,2,0,83,83,115,115,2,0,82,82,114,114,2,0,71,71,103,103,2,0,80,80,
112,112,2,0,67,67,99,99,2,0,79,79,111,111,2,0,65,65,97,97,2,0,68,68,100,
100,2,0,72,72,104,104,2,0,89,89,121,121,2,0,9,9,32,32,2,0,85,85,117,117,
2,0,70,70,102,102,2,0,43,43,45,45,2,0,34,34,92,92,2,0,39,39,92,92,4,0,35,
36,64,90,95,95,97,123,7,0,35,36,45,45,47,58,64,90,95,95,97,123,125,125,
3,0,9,10,13,13,32,32,1,0,48,57,8,0,9,10,13,13,32,34,39,41,44,44,60,62,91,
91,93,93,371,0,1,1,0,0,0,0,3,1,0,0,0,0,5,1,0,0,0,0,7,1,0,0,0,0,9,1,0,0,
0,0,11,1,0,0,0,0,13,1,0,0,0,0,15,1,0,0,0,0,17,1,0,0,0,0,19,1,0,0,0,0,21,
1,0,0,0,0,23,1,0,0,0,0,25,1,0,0,0,0,27,1,0,0,0,0,29,1,0,0,0,0,31,1,0,0,
0,0,33,1,0,0,0,0,35,1,0,0,0,0,37,1,0,0,0,0,39,1,0,0,0,0,41,1,0,0,0,0,43,
1,0,0,0,0,45,1,0,0,0,0,47,1,0,0,0,0,49,1,0,0,0,0,51,1,0,0,0,0,53,1,0,0,
0,0,55,1,0,0,0,0,57,1,0,0,0,0,61,1,0,0,0,0,63,1,0,0,0,0,71,1,0,0,0,0,73,
1,0,0,0,0,77,1,0,0,0,1,79,1,0,0,0,3,81,1,0,0,0,5,83,1,0,0,0,7,85,1,0,0,
0,9,87,1,0,0,0,11,92,1,0,0,0,13,94,1,0,0,0,15,97,1,0,0,0,17,100,1,0,0,0,
19,102,1,0,0,0,21,105,1,0,0,0,23,107,1,0,0,0,25,110,1,0,0,0,27,115,1,0,
0,0,29,121,1,0,0,0,31,129,1,0,0,0,33,137,1,0,0,0,35,144,1,0,0,0,37,154,
1,0,0,0,39,157,1,0,0,0,41,161,1,0,0,0,43,165,1,0,0,0,45,168,1,0,0,0,47,
177,1,0,0,0,49,181,1,0,0,0,51,188,1,0,0,0,53,195,1,0,0,0,55,202,1,0,0,0,
57,226,1,0,0,0,59,228,1,0,0,0,61,278,1,0,0,0,63,300,1,0,0,0,65,302,1,0,
0,0,67,309,1,0,0,0,69,312,1,0,0,0,71,316,1,0,0,0,73,333,1,0,0,0,75,339,
1,0,0,0,77,342,1,0,0,0,79,80,5,40,0,0,80,2,1,0,0,0,81,82,5,41,0,0,82,4,
1,0,0,0,83,84,5,91,0,0,84,6,1,0,0,0,85,86,5,93,0,0,86,8,1,0,0,0,87,88,5,
44,0,0,88,10,1,0,0,0,89,93,5,61,0,0,90,91,5,61,0,0,91,93,5,61,0,0,92,89,
1,0,0,0,92,90,1,0,0,0,93,12,1,0,0,0,94,95,5,33,0,0,95,96,5,61,0,0,96,14,
1,0,0,0,97,98,5,60,0,0,98,99,5,62,0,0,99,16,1,0,0,0,100,101,5,60,0,0,101,
18,1,0,0,0,102,103,5,60,0,0,103,104,5,61,0,0,104,20,1,0,0,0,105,106,5,62,
0,0,106,22,1,0,0,0,107,108,5,62,0,0,108,109,5,61,0,0,109,24,1,0,0,0,110,
111,7,0,0,0,111,112,7,1,0,0,112,113,7,2,0,0,113,114,7,3,0,0,114,26,1,0,
0,0,115,116,7,1,0,0,116,117,7,0,0,0,117,118,7,1,0,0,118,119,7,2,0,0,119,
120,7,3,0,0,120,28,1,0,0,0,121,122,7,4,0,0,122,123,7,3,0,0,123,124,7,5,
0,0,124,125,7,6,0,0,125,126,7,3,0,0,126,127,7,3,0,0,127,128,7,7,0,0,128,
30,1,0,0,0,129,130,7,3,0,0,130,131,7,8,0,0,131,132,7,1,0,0,132,133,7,9,
0,0,133,135,7,5,0,0,134,136,7,9,0,0,135,134,1,0,0,0,135,136,1,0,0,0,136,
32,1,0,0,0,137,138,7,10,0,0,138,139,7,3,0,0,139,140,7,11,0,0,140,141,7,
3,0,0,141,142,7,8,0,0,142,143,7,12,0,0,143,34,1,0,0,0,144,145,7,13,0,0,
145,146,7,14,0,0,146,147,7,7,0,0,147,148,7,5,0,0,148,149,7,15,0,0,149,150,
7,1,0,0,150,152,7,7,0,0,151,153,7,9,0,0,152,151,1,0,0,0,152,153,1,0,0,0,
153,36,1,0,0,0,154,155,7,1,0,0,155,156,7,7,0,0,156,38,1,0,0,0,157,158,7,
7,0,0,158,159,7,14,0,0,159,160,7,5,0,0,160,40,1,0,0,0,161,162,7,15,0,0,
162,163,7,7,0,0,163,164,7,16,0,0,164,42,1,0,0,0,165,166,7,14,0,0,166,167,
7,10,0,0,167,44,1,0,0,0,168,169,7,17,0,0,169,170,7,15,0,0,170,171,7,9,0,
0,171,172,7,5,0,0,172,173,7,14,0,0,173,174,7,2,0,0,174,175,7,3,0,0,175,
176,7,7,0,0,176,46,1,0,0,0,177,178,7,17,0,0,178,179,7,15,0,0,179,180,7,
9,0,0,180,48,1,0,0,0,181,182,7,17,0,0,182,183,7,15,0,0,183,184,7,9,0,0,
184,185,7,15,0,0,185,186,7,7,0,0,186,187,7,18,0,0,187,50,1,0,0,0,188,189,
7,17,0,0,189,190,7,15,0,0,190,191,7,9,0,0,191,192,7,15,0,0,192,193,7,0,
0,0,193,194,7,0,0,0,194,52,1,0,0,0,195,196,7,9,0,0,196,197,7,3,0,0,197,
198,7,15,0,0,198,199,7,10,0,0,199,200,7,13,0,0,200,201,7,17,0,0,201,54,
1,0,0,0,202,203,7,12,0,0,203,204,7,15,0,0,204,205,7,5,0,0,205,206,7,5,0,
0,206,207,7,3,0,0,207,208,7,10,0,0,208,212,7,7,0,0,209,211,7,19,0,0,210,
209,1,0,0,0,211,214,1,0,0,0,212,210,1,0,0,0,212,213,1,0,0,0,213,215,1,0,
0,0,214,212,1,0,0,0,215,216,5,40,0,0,216,56,1,0,0,0,217,218,7,5,0,0,218,
219,7,10,0,0,219,220,7,20,0,0,220,227,7,3,0,0,221,222,7,21,0,0,222,223,
7,15,0,0,223,224,7,0,0,0,224,225,7,9,0,0,225,227,7,3,0,0,226,217,1,0,0,
0,226,221,1,0,0,0,227,58,1,0,0,0,228,229,7,22,0,0,229,60,1,0,0,0,230,232,
3,59,29,0,231,230,1,0,0,0,231,232,1,0,0,0,232,234,1,0,0,0,233,235,3,75,
37,0,234,233,1,0,0,0,235,236,1,0,0,0,236,234,1,0,0,0,236,237,1,0,0,0,237,
245,1,0,0,0,238,242,5,46,0,0,239,241,3,75,37,0,240,239,1,0,0,0,241,244,
1,0,0,0,242,240,1,0,0,0,242,243,1,0,0,0,243,246,1,0,0,0,244,242,1,0,0,0,
245,238,1,0,0,0,245,246,1,0,0,0,246,256,1,0,0,0,247,249,7,3,0,0,248,250,
3,59,29,0,249,248,1,0,0,0,249,250,1,0,0,0,250,252,1,0,0,0,251,253,3,75,
37,0,252,251,1,0,0,0,253,254,1,0,0,0,254,252,1,0,0,0,254,255,1,0,0,0,255,
257,1,0,0,0,256,247,1,0,0,0,256,257,1,0,0,0,257,279,1,0,0,0,258,260,3,59,
29,0,259,258,1,0,0,0,259,260,1,0,0,0,260,261,1,0,0,0,261,263,5,46,0,0,262,
264,3,75,37,0,263,262,1,0,0,0,264,265,1,0,0,0,265,263,1,0,0,0,265,266,1,
0,0,0,266,276,1,0,0,0,267,269,7,3,0,0,268,270,3,59,29,0,269,268,1,0,0,0,
269,270,1,0,0,0,270,272,1,0,0,0,271,273,3,75,37,0,272,271,1,0,0,0,273,274,
1,0,0,0,274,272,1,0,0,0,274,275,1,0,0,0,275,277,1,0,0,0,276,267,1,0,0,0,
276,277,1,0,0,0,277,279,1,0,0,0,278,231,1,0,0,0,278,259,1,0,0,0,279,62,
1,0,0,0,280,286,5,34,0,0,281,285,8,23,0,0,282,283,5,92,0,0,283,285,9,0,
0,0,284,281,1,0,0,0,284,282,1,0,0,0,285,288,1,0,0,0,286,284,1,0,0,0,286,
287,1,0,0,0,287,289,1,0,0,0,288,286,1,0,0,0,289,301,5,34,0,0,290,296,5,
39,0,0,291,295,8,24,0,0,292,293,5,92,0,0,293,295,9,0,0,0,294,291,1,0,0,
0,294,292,1,0,0,0,295,298,1,0,0,0,296,294,1,0,0,0,296,297,1,0,0,0,297,299,
1,0,0,0,298,296,1,0,0,0,299,301,5,39,0,0,300,280,1,0,0,0,300,290,1,0,0,
0,301,64,1,0,0,0,302,306,7,25,0,0,303,305,7,26,0,0,304,303,1,0,0,0,305,
308,1,0,0,0,306,304,1,0,0,0,306,307,1,0,0,0,307,66,1,0,0,0,308,306,1,0,
0,0,309,310,5,91,0,0,310,311,5,93,0,0,311,68,1,0,0,0,312,313,5,91,0,0,313,
314,5,42,0,0,314,315,5,93,0,0,315,70,1,0,0,0,316,329,3,65,32,0,317,318,
5,46,0,0,318,328,3,65,32,0,319,328,3,67,33,0,320,328,3,69,34,0,321,323,
5,46,0,0,322,324,3,75,37,0,323,322,1,0,0,0,324,325,1,0,0,0,325,323,1,0,
0,0,325,326,1,0,0,0,326,328,1,0,0,0,327,317,1,0,0,0,327,319,1,0,0,0,327,
320,1,0,0,0,327,321,1,0,0,0,328,331,1,0,0,0,329,327,1,0,0,0,329,330,1,0,
0,0,330,72,1,0,0,0,331,329,1,0,0,0,332,334,7,27,0,0,333,332,1,0,0,0,334,
335,1,0,0,0,335,333,1,0,0,0,335,336,1,0,0,0,336,337,1,0,0,0,337,338,6,36,
0,0,338,74,1,0,0,0,339,340,7,28,0,0,340,76,1,0,0,0,341,343,8,29,0,0,342,
341,1,0,0,0,343,344,1,0,0,0,344,342,1,0,0,0,344,345,1,0,0,0,345,78,1,0,
0,0,30,0,92,135,152,212,226,231,236,242,245,249,254,256,259,265,269,274,
276,278,284,286,294,296,300,306,325,327,329,335,344,1,6,0,0];
private static __ATN: ATN;
public static get _ATN(): ATN {

View File

@@ -16,6 +16,7 @@ import { ValueListContext } from "./FilterQueryParser.js";
import { FullTextContext } from "./FilterQueryParser.js";
import { FunctionCallContext } from "./FilterQueryParser.js";
import { SearchCallContext } from "./FilterQueryParser.js";
import { PatternCallContext } from "./FilterQueryParser.js";
import { FunctionParamListContext } from "./FilterQueryParser.js";
import { FunctionParamContext } from "./FilterQueryParser.js";
import { ArrayContext } from "./FilterQueryParser.js";
@@ -158,6 +159,16 @@ export default class FilterQueryListener extends ParseTreeListener {
* @param ctx the parse tree
*/
exitSearchCall?: (ctx: SearchCallContext) => void;
/**
* Enter a parse tree produced by `FilterQueryParser.patternCall`.
* @param ctx the parse tree
*/
enterPatternCall?: (ctx: PatternCallContext) => void;
/**
* Exit a parse tree produced by `FilterQueryParser.patternCall`.
* @param ctx the parse tree
*/
exitPatternCall?: (ctx: PatternCallContext) => void;
/**
* Enter a parse tree produced by `FilterQueryParser.functionParamList`.
* @param ctx the parse tree

File diff suppressed because it is too large Load Diff

View File

@@ -16,6 +16,7 @@ import { ValueListContext } from "./FilterQueryParser.js";
import { FullTextContext } from "./FilterQueryParser.js";
import { FunctionCallContext } from "./FilterQueryParser.js";
import { SearchCallContext } from "./FilterQueryParser.js";
import { PatternCallContext } from "./FilterQueryParser.js";
import { FunctionParamListContext } from "./FilterQueryParser.js";
import { FunctionParamContext } from "./FilterQueryParser.js";
import { ArrayContext } from "./FilterQueryParser.js";
@@ -109,6 +110,12 @@ export default class FilterQueryVisitor<Result> extends ParseTreeVisitor<Result>
* @return the visitor result
*/
visitSearchCall?: (ctx: SearchCallContext) => Result;
/**
* Visit a parse tree produced by `FilterQueryParser.patternCall`.
* @param ctx the parse tree
* @return the visitor result
*/
visitPatternCall?: (ctx: PatternCallContext) => Result;
/**
* Visit a parse tree produced by `FilterQueryParser.functionParamList`.
* @param ctx the parse tree

View File

@@ -393,6 +393,15 @@ describe('extractQueryPairs', () => {
).toStrictEqual(['service.name']);
});
it('does not turn the templates of a pattern() call into pairs', () => {
expect(extractQueryPairs("pattern('a <*>', 'b')")).toStrictEqual([]);
expect(
extractQueryPairs("pattern(a) AND service.name = 'api'").map(
(pair) => pair.key,
),
).toStrictEqual(['service.name']);
});
it('should treat lowercase exists as non-value operator', () => {
const input = 'body exists service.name contains "test"';
const result = extractQueryPairs(input);
@@ -838,7 +847,7 @@ describe('getQueryContextAtCursor - partial operator', () => {
describe('getQueryContextAtCursor - function context', () => {
// Each function keyword gets its own lexer token, and every one has to be
// registered as a function token for the editor to offer the function list.
it.each(['has', 'hasAny', 'hasAll', 'hasToken', 'search'])(
it.each(['has', 'hasAny', 'hasAll', 'hasToken', 'search', 'pattern('])(
'resolves %s to function context',
(functionName) => {
const ctx = getQueryContextAtCursor(functionName, functionName.length);

View File

@@ -0,0 +1,15 @@
import { validateQuery } from '../queryValidationUtils';
describe('validateQuery', () => {
it.each([
"pattern('a <*>')",
"pattern ('a <*>', 'it\\'s <*>')",
"service.name = 'api' AND pattern('a <*>')",
])('accepts the pattern filter %s', (query) => {
expect(validateQuery(query)).toStrictEqual({
isValid: true,
message: 'Query is valid!',
errors: [],
});
});
});

View File

@@ -95,6 +95,7 @@ export const explorerViewToPanelType = {
[ExplorerViews.TIMESERIES]: PANEL_TYPES.TIME_SERIES,
[ExplorerViews.TRACE]: PANEL_TYPES.TRACE,
[ExplorerViews.TABLE]: PANEL_TYPES.TABLE,
[ExplorerViews.PATTERNS]: PANEL_TYPES.LIST,
} as Record<ExplorerViews, PANEL_TYPES>;
/**

View File

@@ -1314,6 +1314,26 @@ function indexPastArguments(tokens: IToken[], argumentStart: number): number {
return index;
}
// Like indexPastArguments, for an argument list whose opening parenthesis was
// already consumed.
function indexPastOpenArguments(
tokens: IToken[],
argumentStart: number,
): number {
let depth = 1;
for (let index = argumentStart; index < tokens.length; index++) {
if (tokens[index].type === FilterQueryLexer.LPAREN) {
depth += 1;
} else if (tokens[index].type === FilterQueryLexer.RPAREN) {
depth -= 1;
if (depth === 0) {
return index + 1;
}
}
}
return tokens.length;
}
/**
* Extracts all key-operator-value triplets from a query string
* This is useful for getting value suggestions based on the current key and operator
@@ -1367,6 +1387,12 @@ export function extractQueryPairs(query: string): IQueryPair[] {
continue;
}
// pattern( carries its opening parenthesis, and its templates are not values of a key.
if (token.type === FilterQueryLexer.PATTERN_CALL) {
iterator = indexPastOpenArguments(allTokens, iterator);
continue;
}
// If token is a KEY, start a new pair
if (
token.type === FilterQueryLexer.KEY &&

View File

@@ -78,6 +78,7 @@ export function isFunctionToken(tokenType: number): boolean {
FilterQueryLexer.HASALL,
FilterQueryLexer.HASTOKEN,
FilterQueryLexer.SEARCH,
FilterQueryLexer.PATTERN_CALL,
].includes(tokenType);
}

View File

@@ -38,6 +38,7 @@ primary
| comparison
| functionCall
| searchCall
| patternCall
| fullText
| key
| value
@@ -121,6 +122,16 @@ searchCall
;
// Function parameters can be keys, single scalar values, or arrays
/*
* Log pattern filter: pattern('User <*> logged in'[, '...']) keeps the logs
* whose pattern is one of the given templates. Handled in the visitor.
* PATTERN_CALL carries its opening parenthesis, so a bare `pattern` stays a key
* or a full-text word.
*/
patternCall
: PATTERN_CALL valueList RPAREN
;
functionParamList
: functionParam ( COMMA functionParam )*
;
@@ -195,6 +206,7 @@ HAS : [Hh][Aa][Ss] ;
HASANY : [Hh][Aa][Ss][Aa][Nn][Yy] ;
HASALL : [Hh][Aa][Ss][Aa][Ll][Ll] ;
SEARCH : [Ss][Ee][Aa][Rr][Cc][Hh] ;
PATTERN_CALL : [Pp][Aa][Tt][Tt][Ee][Rr][Nn] [ \t]* '(' ;
// Potential boolean constants
BOOL

View File

@@ -176,6 +176,8 @@ func (r *WhereClauseRewriter) VisitPrimary(ctx *parser.PrimaryContext) any {
ctx.FunctionCall().Accept(r)
} else if ctx.SearchCall() != nil {
ctx.SearchCall().Accept(r)
} else if ctx.PatternCall() != nil {
ctx.PatternCall().Accept(r)
} else if ctx.FullText() != nil {
ctx.FullText().Accept(r)
} else if ctx.Key() != nil {
@@ -374,6 +376,13 @@ func (r *WhereClauseRewriter) VisitSearchCall(ctx *parser.SearchCallContext) any
return nil
}
// VisitPatternCall visits pattern() calls. It has no keys to rewrite, so it
// is preserved verbatim.
func (r *WhereClauseRewriter) VisitPatternCall(ctx *parser.PatternCallContext) any {
r.rewritten.WriteString(ctx.GetText())
return nil
}
// VisitFunctionCall visits function calls.
func (r *WhereClauseRewriter) VisitFunctionCall(ctx *parser.FunctionCallContext) any {
// Write function name

File diff suppressed because one or more lines are too long

View File

@@ -25,12 +25,13 @@ HAS=24
HASANY=25
HASALL=26
SEARCH=27
BOOL=28
NUMBER=29
QUOTED_TEXT=30
KEY=31
WS=32
FREETEXT=33
PATTERN_CALL=28
BOOL=29
NUMBER=30
QUOTED_TEXT=31
KEY=32
WS=33
FREETEXT=34
'('=1
')'=2
'['=3

File diff suppressed because one or more lines are too long

View File

@@ -25,12 +25,13 @@ HAS=24
HASANY=25
HASALL=26
SEARCH=27
BOOL=28
NUMBER=29
QUOTED_TEXT=30
KEY=31
WS=32
FREETEXT=33
PATTERN_CALL=28
BOOL=29
NUMBER=30
QUOTED_TEXT=31
KEY=32
WS=33
FREETEXT=34
'('=1
')'=2
'['=3

View File

@@ -99,6 +99,12 @@ func (s *BaseFilterQueryListener) EnterSearchCall(ctx *SearchCallContext) {}
// ExitSearchCall is called when production searchCall is exited.
func (s *BaseFilterQueryListener) ExitSearchCall(ctx *SearchCallContext) {}
// EnterPatternCall is called when production patternCall is entered.
func (s *BaseFilterQueryListener) EnterPatternCall(ctx *PatternCallContext) {}
// ExitPatternCall is called when production patternCall is exited.
func (s *BaseFilterQueryListener) ExitPatternCall(ctx *PatternCallContext) {}
// EnterFunctionParamList is called when production functionParamList is entered.
func (s *BaseFilterQueryListener) EnterFunctionParamList(ctx *FunctionParamListContext) {}

View File

@@ -60,6 +60,10 @@ func (v *BaseFilterQueryVisitor) VisitSearchCall(ctx *SearchCallContext) interfa
return v.VisitChildren(ctx)
}
func (v *BaseFilterQueryVisitor) VisitPatternCall(ctx *PatternCallContext) interface{} {
return v.VisitChildren(ctx)
}
func (v *BaseFilterQueryVisitor) VisitFunctionParamList(ctx *FunctionParamListContext) interface{} {
return v.VisitChildren(ctx)
}

View File

@@ -50,174 +50,184 @@ func filterquerylexerLexerInit() {
"", "LPAREN", "RPAREN", "LBRACK", "RBRACK", "COMMA", "EQUALS", "NOT_EQUALS",
"NEQ", "LT", "LE", "GT", "GE", "LIKE", "ILIKE", "BETWEEN", "EXISTS",
"REGEXP", "CONTAINS", "IN", "NOT", "AND", "OR", "HASTOKEN", "HAS", "HASANY",
"HASALL", "SEARCH", "BOOL", "NUMBER", "QUOTED_TEXT", "KEY", "WS", "FREETEXT",
"HASALL", "SEARCH", "PATTERN_CALL", "BOOL", "NUMBER", "QUOTED_TEXT",
"KEY", "WS", "FREETEXT",
}
staticData.RuleNames = []string{
"LPAREN", "RPAREN", "LBRACK", "RBRACK", "COMMA", "EQUALS", "NOT_EQUALS",
"NEQ", "LT", "LE", "GT", "GE", "LIKE", "ILIKE", "BETWEEN", "EXISTS",
"REGEXP", "CONTAINS", "IN", "NOT", "AND", "OR", "HASTOKEN", "HAS", "HASANY",
"HASALL", "SEARCH", "BOOL", "SIGN", "NUMBER", "QUOTED_TEXT", "SEGMENT",
"EMPTY_BRACKS", "OLD_JSON_BRACKS", "KEY", "WS", "DIGIT", "FREETEXT",
"HASALL", "SEARCH", "PATTERN_CALL", "BOOL", "SIGN", "NUMBER", "QUOTED_TEXT",
"SEGMENT", "EMPTY_BRACKS", "OLD_JSON_BRACKS", "KEY", "WS", "DIGIT",
"FREETEXT",
}
staticData.PredictionContextCache = antlr.NewPredictionContextCache()
staticData.serializedATN = []int32{
4, 0, 33, 329, 6, -1, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2,
4, 0, 34, 346, 6, -1, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2,
4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, 2, 8, 7, 8, 2, 9, 7, 9, 2,
10, 7, 10, 2, 11, 7, 11, 2, 12, 7, 12, 2, 13, 7, 13, 2, 14, 7, 14, 2, 15,
7, 15, 2, 16, 7, 16, 2, 17, 7, 17, 2, 18, 7, 18, 2, 19, 7, 19, 2, 20, 7,
20, 2, 21, 7, 21, 2, 22, 7, 22, 2, 23, 7, 23, 2, 24, 7, 24, 2, 25, 7, 25,
2, 26, 7, 26, 2, 27, 7, 27, 2, 28, 7, 28, 2, 29, 7, 29, 2, 30, 7, 30, 2,
31, 7, 31, 2, 32, 7, 32, 2, 33, 7, 33, 2, 34, 7, 34, 2, 35, 7, 35, 2, 36,
7, 36, 2, 37, 7, 37, 1, 0, 1, 0, 1, 1, 1, 1, 1, 2, 1, 2, 1, 3, 1, 3, 1,
4, 1, 4, 1, 5, 1, 5, 1, 5, 3, 5, 91, 8, 5, 1, 6, 1, 6, 1, 6, 1, 7, 1, 7,
1, 7, 1, 8, 1, 8, 1, 9, 1, 9, 1, 9, 1, 10, 1, 10, 1, 11, 1, 11, 1, 11,
1, 12, 1, 12, 1, 12, 1, 12, 1, 12, 1, 13, 1, 13, 1, 13, 1, 13, 1, 13, 1,
13, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 15, 1, 15,
1, 15, 1, 15, 1, 15, 1, 15, 3, 15, 134, 8, 15, 1, 16, 1, 16, 1, 16, 1,
16, 1, 16, 1, 16, 1, 16, 1, 17, 1, 17, 1, 17, 1, 17, 1, 17, 1, 17, 1, 17,
1, 17, 3, 17, 151, 8, 17, 1, 18, 1, 18, 1, 18, 1, 19, 1, 19, 1, 19, 1,
19, 1, 20, 1, 20, 1, 20, 1, 20, 1, 21, 1, 21, 1, 21, 1, 22, 1, 22, 1, 22,
1, 22, 1, 22, 1, 22, 1, 22, 1, 22, 1, 22, 1, 23, 1, 23, 1, 23, 1, 23, 1,
24, 1, 24, 1, 24, 1, 24, 1, 24, 1, 24, 1, 24, 1, 25, 1, 25, 1, 25, 1, 25,
1, 25, 1, 25, 1, 25, 1, 26, 1, 26, 1, 26, 1, 26, 1, 26, 1, 26, 1, 26, 1,
27, 1, 27, 1, 27, 1, 27, 1, 27, 1, 27, 1, 27, 1, 27, 1, 27, 3, 27, 210,
8, 27, 1, 28, 1, 28, 1, 29, 3, 29, 215, 8, 29, 1, 29, 4, 29, 218, 8, 29,
11, 29, 12, 29, 219, 1, 29, 1, 29, 5, 29, 224, 8, 29, 10, 29, 12, 29, 227,
9, 29, 3, 29, 229, 8, 29, 1, 29, 1, 29, 3, 29, 233, 8, 29, 1, 29, 4, 29,
236, 8, 29, 11, 29, 12, 29, 237, 3, 29, 240, 8, 29, 1, 29, 3, 29, 243,
8, 29, 1, 29, 1, 29, 4, 29, 247, 8, 29, 11, 29, 12, 29, 248, 1, 29, 1,
29, 3, 29, 253, 8, 29, 1, 29, 4, 29, 256, 8, 29, 11, 29, 12, 29, 257, 3,
29, 260, 8, 29, 3, 29, 262, 8, 29, 1, 30, 1, 30, 1, 30, 1, 30, 5, 30, 268,
8, 30, 10, 30, 12, 30, 271, 9, 30, 1, 30, 1, 30, 1, 30, 1, 30, 1, 30, 5,
30, 278, 8, 30, 10, 30, 12, 30, 281, 9, 30, 1, 30, 3, 30, 284, 8, 30, 1,
31, 1, 31, 5, 31, 288, 8, 31, 10, 31, 12, 31, 291, 9, 31, 1, 32, 1, 32,
1, 32, 1, 33, 1, 33, 1, 33, 1, 33, 1, 34, 1, 34, 1, 34, 1, 34, 1, 34, 1,
34, 1, 34, 4, 34, 307, 8, 34, 11, 34, 12, 34, 308, 5, 34, 311, 8, 34, 10,
34, 12, 34, 314, 9, 34, 1, 35, 4, 35, 317, 8, 35, 11, 35, 12, 35, 318,
1, 35, 1, 35, 1, 36, 1, 36, 1, 37, 4, 37, 326, 8, 37, 11, 37, 12, 37, 327,
0, 0, 38, 1, 1, 3, 2, 5, 3, 7, 4, 9, 5, 11, 6, 13, 7, 15, 8, 17, 9, 19,
10, 21, 11, 23, 12, 25, 13, 27, 14, 29, 15, 31, 16, 33, 17, 35, 18, 37,
19, 39, 20, 41, 21, 43, 22, 45, 23, 47, 24, 49, 25, 51, 26, 53, 27, 55,
28, 57, 0, 59, 29, 61, 30, 63, 0, 65, 0, 67, 0, 69, 31, 71, 32, 73, 0,
75, 33, 1, 0, 29, 2, 0, 76, 76, 108, 108, 2, 0, 73, 73, 105, 105, 2, 0,
75, 75, 107, 107, 2, 0, 69, 69, 101, 101, 2, 0, 66, 66, 98, 98, 2, 0, 84,
84, 116, 116, 2, 0, 87, 87, 119, 119, 2, 0, 78, 78, 110, 110, 2, 0, 88,
88, 120, 120, 2, 0, 83, 83, 115, 115, 2, 0, 82, 82, 114, 114, 2, 0, 71,
71, 103, 103, 2, 0, 80, 80, 112, 112, 2, 0, 67, 67, 99, 99, 2, 0, 79, 79,
111, 111, 2, 0, 65, 65, 97, 97, 2, 0, 68, 68, 100, 100, 2, 0, 72, 72, 104,
104, 2, 0, 89, 89, 121, 121, 2, 0, 85, 85, 117, 117, 2, 0, 70, 70, 102,
102, 2, 0, 43, 43, 45, 45, 2, 0, 34, 34, 92, 92, 2, 0, 39, 39, 92, 92,
4, 0, 35, 36, 64, 90, 95, 95, 97, 123, 7, 0, 35, 36, 45, 45, 47, 58, 64,
90, 95, 95, 97, 123, 125, 125, 3, 0, 9, 10, 13, 13, 32, 32, 1, 0, 48, 57,
8, 0, 9, 10, 13, 13, 32, 34, 39, 41, 44, 44, 60, 62, 91, 91, 93, 93, 353,
0, 1, 1, 0, 0, 0, 0, 3, 1, 0, 0, 0, 0, 5, 1, 0, 0, 0, 0, 7, 1, 0, 0, 0,
0, 9, 1, 0, 0, 0, 0, 11, 1, 0, 0, 0, 0, 13, 1, 0, 0, 0, 0, 15, 1, 0, 0,
0, 0, 17, 1, 0, 0, 0, 0, 19, 1, 0, 0, 0, 0, 21, 1, 0, 0, 0, 0, 23, 1, 0,
0, 0, 0, 25, 1, 0, 0, 0, 0, 27, 1, 0, 0, 0, 0, 29, 1, 0, 0, 0, 0, 31, 1,
0, 0, 0, 0, 33, 1, 0, 0, 0, 0, 35, 1, 0, 0, 0, 0, 37, 1, 0, 0, 0, 0, 39,
1, 0, 0, 0, 0, 41, 1, 0, 0, 0, 0, 43, 1, 0, 0, 0, 0, 45, 1, 0, 0, 0, 0,
47, 1, 0, 0, 0, 0, 49, 1, 0, 0, 0, 0, 51, 1, 0, 0, 0, 0, 53, 1, 0, 0, 0,
0, 55, 1, 0, 0, 0, 0, 59, 1, 0, 0, 0, 0, 61, 1, 0, 0, 0, 0, 69, 1, 0, 0,
0, 0, 71, 1, 0, 0, 0, 0, 75, 1, 0, 0, 0, 1, 77, 1, 0, 0, 0, 3, 79, 1, 0,
0, 0, 5, 81, 1, 0, 0, 0, 7, 83, 1, 0, 0, 0, 9, 85, 1, 0, 0, 0, 11, 90,
1, 0, 0, 0, 13, 92, 1, 0, 0, 0, 15, 95, 1, 0, 0, 0, 17, 98, 1, 0, 0, 0,
19, 100, 1, 0, 0, 0, 21, 103, 1, 0, 0, 0, 23, 105, 1, 0, 0, 0, 25, 108,
1, 0, 0, 0, 27, 113, 1, 0, 0, 0, 29, 119, 1, 0, 0, 0, 31, 127, 1, 0, 0,
0, 33, 135, 1, 0, 0, 0, 35, 142, 1, 0, 0, 0, 37, 152, 1, 0, 0, 0, 39, 155,
1, 0, 0, 0, 41, 159, 1, 0, 0, 0, 43, 163, 1, 0, 0, 0, 45, 166, 1, 0, 0,
0, 47, 175, 1, 0, 0, 0, 49, 179, 1, 0, 0, 0, 51, 186, 1, 0, 0, 0, 53, 193,
1, 0, 0, 0, 55, 209, 1, 0, 0, 0, 57, 211, 1, 0, 0, 0, 59, 261, 1, 0, 0,
0, 61, 283, 1, 0, 0, 0, 63, 285, 1, 0, 0, 0, 65, 292, 1, 0, 0, 0, 67, 295,
1, 0, 0, 0, 69, 299, 1, 0, 0, 0, 71, 316, 1, 0, 0, 0, 73, 322, 1, 0, 0,
0, 75, 325, 1, 0, 0, 0, 77, 78, 5, 40, 0, 0, 78, 2, 1, 0, 0, 0, 79, 80,
5, 41, 0, 0, 80, 4, 1, 0, 0, 0, 81, 82, 5, 91, 0, 0, 82, 6, 1, 0, 0, 0,
83, 84, 5, 93, 0, 0, 84, 8, 1, 0, 0, 0, 85, 86, 5, 44, 0, 0, 86, 10, 1,
0, 0, 0, 87, 91, 5, 61, 0, 0, 88, 89, 5, 61, 0, 0, 89, 91, 5, 61, 0, 0,
90, 87, 1, 0, 0, 0, 90, 88, 1, 0, 0, 0, 91, 12, 1, 0, 0, 0, 92, 93, 5,
33, 0, 0, 93, 94, 5, 61, 0, 0, 94, 14, 1, 0, 0, 0, 95, 96, 5, 60, 0, 0,
96, 97, 5, 62, 0, 0, 97, 16, 1, 0, 0, 0, 98, 99, 5, 60, 0, 0, 99, 18, 1,
0, 0, 0, 100, 101, 5, 60, 0, 0, 101, 102, 5, 61, 0, 0, 102, 20, 1, 0, 0,
0, 103, 104, 5, 62, 0, 0, 104, 22, 1, 0, 0, 0, 105, 106, 5, 62, 0, 0, 106,
107, 5, 61, 0, 0, 107, 24, 1, 0, 0, 0, 108, 109, 7, 0, 0, 0, 109, 110,
7, 1, 0, 0, 110, 111, 7, 2, 0, 0, 111, 112, 7, 3, 0, 0, 112, 26, 1, 0,
0, 0, 113, 114, 7, 1, 0, 0, 114, 115, 7, 0, 0, 0, 115, 116, 7, 1, 0, 0,
116, 117, 7, 2, 0, 0, 117, 118, 7, 3, 0, 0, 118, 28, 1, 0, 0, 0, 119, 120,
7, 4, 0, 0, 120, 121, 7, 3, 0, 0, 121, 122, 7, 5, 0, 0, 122, 123, 7, 6,
0, 0, 123, 124, 7, 3, 0, 0, 124, 125, 7, 3, 0, 0, 125, 126, 7, 7, 0, 0,
126, 30, 1, 0, 0, 0, 127, 128, 7, 3, 0, 0, 128, 129, 7, 8, 0, 0, 129, 130,
7, 1, 0, 0, 130, 131, 7, 9, 0, 0, 131, 133, 7, 5, 0, 0, 132, 134, 7, 9,
0, 0, 133, 132, 1, 0, 0, 0, 133, 134, 1, 0, 0, 0, 134, 32, 1, 0, 0, 0,
135, 136, 7, 10, 0, 0, 136, 137, 7, 3, 0, 0, 137, 138, 7, 11, 0, 0, 138,
139, 7, 3, 0, 0, 139, 140, 7, 8, 0, 0, 140, 141, 7, 12, 0, 0, 141, 34,
1, 0, 0, 0, 142, 143, 7, 13, 0, 0, 143, 144, 7, 14, 0, 0, 144, 145, 7,
7, 0, 0, 145, 146, 7, 5, 0, 0, 146, 147, 7, 15, 0, 0, 147, 148, 7, 1, 0,
0, 148, 150, 7, 7, 0, 0, 149, 151, 7, 9, 0, 0, 150, 149, 1, 0, 0, 0, 150,
151, 1, 0, 0, 0, 151, 36, 1, 0, 0, 0, 152, 153, 7, 1, 0, 0, 153, 154, 7,
7, 0, 0, 154, 38, 1, 0, 0, 0, 155, 156, 7, 7, 0, 0, 156, 157, 7, 14, 0,
0, 157, 158, 7, 5, 0, 0, 158, 40, 1, 0, 0, 0, 159, 160, 7, 15, 0, 0, 160,
161, 7, 7, 0, 0, 161, 162, 7, 16, 0, 0, 162, 42, 1, 0, 0, 0, 163, 164,
7, 14, 0, 0, 164, 165, 7, 10, 0, 0, 165, 44, 1, 0, 0, 0, 166, 167, 7, 17,
0, 0, 167, 168, 7, 15, 0, 0, 168, 169, 7, 9, 0, 0, 169, 170, 7, 5, 0, 0,
170, 171, 7, 14, 0, 0, 171, 172, 7, 2, 0, 0, 172, 173, 7, 3, 0, 0, 173,
174, 7, 7, 0, 0, 174, 46, 1, 0, 0, 0, 175, 176, 7, 17, 0, 0, 176, 177,
7, 15, 0, 0, 177, 178, 7, 9, 0, 0, 178, 48, 1, 0, 0, 0, 179, 180, 7, 17,
0, 0, 180, 181, 7, 15, 0, 0, 181, 182, 7, 9, 0, 0, 182, 183, 7, 15, 0,
0, 183, 184, 7, 7, 0, 0, 184, 185, 7, 18, 0, 0, 185, 50, 1, 0, 0, 0, 186,
187, 7, 17, 0, 0, 187, 188, 7, 15, 0, 0, 188, 189, 7, 9, 0, 0, 189, 190,
7, 15, 0, 0, 190, 191, 7, 0, 0, 0, 191, 192, 7, 0, 0, 0, 192, 52, 1, 0,
0, 0, 193, 194, 7, 9, 0, 0, 194, 195, 7, 3, 0, 0, 195, 196, 7, 15, 0, 0,
196, 197, 7, 10, 0, 0, 197, 198, 7, 13, 0, 0, 198, 199, 7, 17, 0, 0, 199,
54, 1, 0, 0, 0, 200, 201, 7, 5, 0, 0, 201, 202, 7, 10, 0, 0, 202, 203,
7, 19, 0, 0, 203, 210, 7, 3, 0, 0, 204, 205, 7, 20, 0, 0, 205, 206, 7,
15, 0, 0, 206, 207, 7, 0, 0, 0, 207, 208, 7, 9, 0, 0, 208, 210, 7, 3, 0,
0, 209, 200, 1, 0, 0, 0, 209, 204, 1, 0, 0, 0, 210, 56, 1, 0, 0, 0, 211,
212, 7, 21, 0, 0, 212, 58, 1, 0, 0, 0, 213, 215, 3, 57, 28, 0, 214, 213,
1, 0, 0, 0, 214, 215, 1, 0, 0, 0, 215, 217, 1, 0, 0, 0, 216, 218, 3, 73,
36, 0, 217, 216, 1, 0, 0, 0, 218, 219, 1, 0, 0, 0, 219, 217, 1, 0, 0, 0,
219, 220, 1, 0, 0, 0, 220, 228, 1, 0, 0, 0, 221, 225, 5, 46, 0, 0, 222,
224, 3, 73, 36, 0, 223, 222, 1, 0, 0, 0, 224, 227, 1, 0, 0, 0, 225, 223,
1, 0, 0, 0, 225, 226, 1, 0, 0, 0, 226, 229, 1, 0, 0, 0, 227, 225, 1, 0,
0, 0, 228, 221, 1, 0, 0, 0, 228, 229, 1, 0, 0, 0, 229, 239, 1, 0, 0, 0,
230, 232, 7, 3, 0, 0, 231, 233, 3, 57, 28, 0, 232, 231, 1, 0, 0, 0, 232,
233, 1, 0, 0, 0, 233, 235, 1, 0, 0, 0, 234, 236, 3, 73, 36, 0, 235, 234,
1, 0, 0, 0, 236, 237, 1, 0, 0, 0, 237, 235, 1, 0, 0, 0, 237, 238, 1, 0,
0, 0, 238, 240, 1, 0, 0, 0, 239, 230, 1, 0, 0, 0, 239, 240, 1, 0, 0, 0,
240, 262, 1, 0, 0, 0, 241, 243, 3, 57, 28, 0, 242, 241, 1, 0, 0, 0, 242,
243, 1, 0, 0, 0, 243, 244, 1, 0, 0, 0, 244, 246, 5, 46, 0, 0, 245, 247,
3, 73, 36, 0, 246, 245, 1, 0, 0, 0, 247, 248, 1, 0, 0, 0, 248, 246, 1,
0, 0, 0, 248, 249, 1, 0, 0, 0, 249, 259, 1, 0, 0, 0, 250, 252, 7, 3, 0,
0, 251, 253, 3, 57, 28, 0, 252, 251, 1, 0, 0, 0, 252, 253, 1, 0, 0, 0,
253, 255, 1, 0, 0, 0, 254, 256, 3, 73, 36, 0, 255, 254, 1, 0, 0, 0, 256,
257, 1, 0, 0, 0, 257, 255, 1, 0, 0, 0, 257, 258, 1, 0, 0, 0, 258, 260,
1, 0, 0, 0, 259, 250, 1, 0, 0, 0, 259, 260, 1, 0, 0, 0, 260, 262, 1, 0,
0, 0, 261, 214, 1, 0, 0, 0, 261, 242, 1, 0, 0, 0, 262, 60, 1, 0, 0, 0,
263, 269, 5, 34, 0, 0, 264, 268, 8, 22, 0, 0, 265, 266, 5, 92, 0, 0, 266,
268, 9, 0, 0, 0, 267, 264, 1, 0, 0, 0, 267, 265, 1, 0, 0, 0, 268, 271,
1, 0, 0, 0, 269, 267, 1, 0, 0, 0, 269, 270, 1, 0, 0, 0, 270, 272, 1, 0,
0, 0, 271, 269, 1, 0, 0, 0, 272, 284, 5, 34, 0, 0, 273, 279, 5, 39, 0,
0, 274, 278, 8, 23, 0, 0, 275, 276, 5, 92, 0, 0, 276, 278, 9, 0, 0, 0,
277, 274, 1, 0, 0, 0, 277, 275, 1, 0, 0, 0, 278, 281, 1, 0, 0, 0, 279,
277, 1, 0, 0, 0, 279, 280, 1, 0, 0, 0, 280, 282, 1, 0, 0, 0, 281, 279,
1, 0, 0, 0, 282, 284, 5, 39, 0, 0, 283, 263, 1, 0, 0, 0, 283, 273, 1, 0,
0, 0, 284, 62, 1, 0, 0, 0, 285, 289, 7, 24, 0, 0, 286, 288, 7, 25, 0, 0,
287, 286, 1, 0, 0, 0, 288, 291, 1, 0, 0, 0, 289, 287, 1, 0, 0, 0, 289,
290, 1, 0, 0, 0, 290, 64, 1, 0, 0, 0, 291, 289, 1, 0, 0, 0, 292, 293, 5,
91, 0, 0, 293, 294, 5, 93, 0, 0, 294, 66, 1, 0, 0, 0, 295, 296, 5, 91,
0, 0, 296, 297, 5, 42, 0, 0, 297, 298, 5, 93, 0, 0, 298, 68, 1, 0, 0, 0,
299, 312, 3, 63, 31, 0, 300, 301, 5, 46, 0, 0, 301, 311, 3, 63, 31, 0,
302, 311, 3, 65, 32, 0, 303, 311, 3, 67, 33, 0, 304, 306, 5, 46, 0, 0,
305, 307, 3, 73, 36, 0, 306, 305, 1, 0, 0, 0, 307, 308, 1, 0, 0, 0, 308,
306, 1, 0, 0, 0, 308, 309, 1, 0, 0, 0, 309, 311, 1, 0, 0, 0, 310, 300,
1, 0, 0, 0, 310, 302, 1, 0, 0, 0, 310, 303, 1, 0, 0, 0, 310, 304, 1, 0,
0, 0, 311, 314, 1, 0, 0, 0, 312, 310, 1, 0, 0, 0, 312, 313, 1, 0, 0, 0,
313, 70, 1, 0, 0, 0, 314, 312, 1, 0, 0, 0, 315, 317, 7, 26, 0, 0, 316,
315, 1, 0, 0, 0, 317, 318, 1, 0, 0, 0, 318, 316, 1, 0, 0, 0, 318, 319,
1, 0, 0, 0, 319, 320, 1, 0, 0, 0, 320, 321, 6, 35, 0, 0, 321, 72, 1, 0,
0, 0, 322, 323, 7, 27, 0, 0, 323, 74, 1, 0, 0, 0, 324, 326, 8, 28, 0, 0,
325, 324, 1, 0, 0, 0, 326, 327, 1, 0, 0, 0, 327, 325, 1, 0, 0, 0, 327,
328, 1, 0, 0, 0, 328, 76, 1, 0, 0, 0, 29, 0, 90, 133, 150, 209, 214, 219,
225, 228, 232, 237, 239, 242, 248, 252, 257, 259, 261, 267, 269, 277, 279,
283, 289, 308, 310, 312, 318, 327, 1, 6, 0, 0,
7, 36, 2, 37, 7, 37, 2, 38, 7, 38, 1, 0, 1, 0, 1, 1, 1, 1, 1, 2, 1, 2,
1, 3, 1, 3, 1, 4, 1, 4, 1, 5, 1, 5, 1, 5, 3, 5, 93, 8, 5, 1, 6, 1, 6, 1,
6, 1, 7, 1, 7, 1, 7, 1, 8, 1, 8, 1, 9, 1, 9, 1, 9, 1, 10, 1, 10, 1, 11,
1, 11, 1, 11, 1, 12, 1, 12, 1, 12, 1, 12, 1, 12, 1, 13, 1, 13, 1, 13, 1,
13, 1, 13, 1, 13, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14,
1, 15, 1, 15, 1, 15, 1, 15, 1, 15, 1, 15, 3, 15, 136, 8, 15, 1, 16, 1,
16, 1, 16, 1, 16, 1, 16, 1, 16, 1, 16, 1, 17, 1, 17, 1, 17, 1, 17, 1, 17,
1, 17, 1, 17, 1, 17, 3, 17, 153, 8, 17, 1, 18, 1, 18, 1, 18, 1, 19, 1,
19, 1, 19, 1, 19, 1, 20, 1, 20, 1, 20, 1, 20, 1, 21, 1, 21, 1, 21, 1, 22,
1, 22, 1, 22, 1, 22, 1, 22, 1, 22, 1, 22, 1, 22, 1, 22, 1, 23, 1, 23, 1,
23, 1, 23, 1, 24, 1, 24, 1, 24, 1, 24, 1, 24, 1, 24, 1, 24, 1, 25, 1, 25,
1, 25, 1, 25, 1, 25, 1, 25, 1, 25, 1, 26, 1, 26, 1, 26, 1, 26, 1, 26, 1,
26, 1, 26, 1, 27, 1, 27, 1, 27, 1, 27, 1, 27, 1, 27, 1, 27, 1, 27, 5, 27,
211, 8, 27, 10, 27, 12, 27, 214, 9, 27, 1, 27, 1, 27, 1, 28, 1, 28, 1,
28, 1, 28, 1, 28, 1, 28, 1, 28, 1, 28, 1, 28, 3, 28, 227, 8, 28, 1, 29,
1, 29, 1, 30, 3, 30, 232, 8, 30, 1, 30, 4, 30, 235, 8, 30, 11, 30, 12,
30, 236, 1, 30, 1, 30, 5, 30, 241, 8, 30, 10, 30, 12, 30, 244, 9, 30, 3,
30, 246, 8, 30, 1, 30, 1, 30, 3, 30, 250, 8, 30, 1, 30, 4, 30, 253, 8,
30, 11, 30, 12, 30, 254, 3, 30, 257, 8, 30, 1, 30, 3, 30, 260, 8, 30, 1,
30, 1, 30, 4, 30, 264, 8, 30, 11, 30, 12, 30, 265, 1, 30, 1, 30, 3, 30,
270, 8, 30, 1, 30, 4, 30, 273, 8, 30, 11, 30, 12, 30, 274, 3, 30, 277,
8, 30, 3, 30, 279, 8, 30, 1, 31, 1, 31, 1, 31, 1, 31, 5, 31, 285, 8, 31,
10, 31, 12, 31, 288, 9, 31, 1, 31, 1, 31, 1, 31, 1, 31, 1, 31, 5, 31, 295,
8, 31, 10, 31, 12, 31, 298, 9, 31, 1, 31, 3, 31, 301, 8, 31, 1, 32, 1,
32, 5, 32, 305, 8, 32, 10, 32, 12, 32, 308, 9, 32, 1, 33, 1, 33, 1, 33,
1, 34, 1, 34, 1, 34, 1, 34, 1, 35, 1, 35, 1, 35, 1, 35, 1, 35, 1, 35, 1,
35, 4, 35, 324, 8, 35, 11, 35, 12, 35, 325, 5, 35, 328, 8, 35, 10, 35,
12, 35, 331, 9, 35, 1, 36, 4, 36, 334, 8, 36, 11, 36, 12, 36, 335, 1, 36,
1, 36, 1, 37, 1, 37, 1, 38, 4, 38, 343, 8, 38, 11, 38, 12, 38, 344, 0,
0, 39, 1, 1, 3, 2, 5, 3, 7, 4, 9, 5, 11, 6, 13, 7, 15, 8, 17, 9, 19, 10,
21, 11, 23, 12, 25, 13, 27, 14, 29, 15, 31, 16, 33, 17, 35, 18, 37, 19,
39, 20, 41, 21, 43, 22, 45, 23, 47, 24, 49, 25, 51, 26, 53, 27, 55, 28,
57, 29, 59, 0, 61, 30, 63, 31, 65, 0, 67, 0, 69, 0, 71, 32, 73, 33, 75,
0, 77, 34, 1, 0, 30, 2, 0, 76, 76, 108, 108, 2, 0, 73, 73, 105, 105, 2,
0, 75, 75, 107, 107, 2, 0, 69, 69, 101, 101, 2, 0, 66, 66, 98, 98, 2, 0,
84, 84, 116, 116, 2, 0, 87, 87, 119, 119, 2, 0, 78, 78, 110, 110, 2, 0,
88, 88, 120, 120, 2, 0, 83, 83, 115, 115, 2, 0, 82, 82, 114, 114, 2, 0,
71, 71, 103, 103, 2, 0, 80, 80, 112, 112, 2, 0, 67, 67, 99, 99, 2, 0, 79,
79, 111, 111, 2, 0, 65, 65, 97, 97, 2, 0, 68, 68, 100, 100, 2, 0, 72, 72,
104, 104, 2, 0, 89, 89, 121, 121, 2, 0, 9, 9, 32, 32, 2, 0, 85, 85, 117,
117, 2, 0, 70, 70, 102, 102, 2, 0, 43, 43, 45, 45, 2, 0, 34, 34, 92, 92,
2, 0, 39, 39, 92, 92, 4, 0, 35, 36, 64, 90, 95, 95, 97, 123, 7, 0, 35,
36, 45, 45, 47, 58, 64, 90, 95, 95, 97, 123, 125, 125, 3, 0, 9, 10, 13,
13, 32, 32, 1, 0, 48, 57, 8, 0, 9, 10, 13, 13, 32, 34, 39, 41, 44, 44,
60, 62, 91, 91, 93, 93, 371, 0, 1, 1, 0, 0, 0, 0, 3, 1, 0, 0, 0, 0, 5,
1, 0, 0, 0, 0, 7, 1, 0, 0, 0, 0, 9, 1, 0, 0, 0, 0, 11, 1, 0, 0, 0, 0, 13,
1, 0, 0, 0, 0, 15, 1, 0, 0, 0, 0, 17, 1, 0, 0, 0, 0, 19, 1, 0, 0, 0, 0,
21, 1, 0, 0, 0, 0, 23, 1, 0, 0, 0, 0, 25, 1, 0, 0, 0, 0, 27, 1, 0, 0, 0,
0, 29, 1, 0, 0, 0, 0, 31, 1, 0, 0, 0, 0, 33, 1, 0, 0, 0, 0, 35, 1, 0, 0,
0, 0, 37, 1, 0, 0, 0, 0, 39, 1, 0, 0, 0, 0, 41, 1, 0, 0, 0, 0, 43, 1, 0,
0, 0, 0, 45, 1, 0, 0, 0, 0, 47, 1, 0, 0, 0, 0, 49, 1, 0, 0, 0, 0, 51, 1,
0, 0, 0, 0, 53, 1, 0, 0, 0, 0, 55, 1, 0, 0, 0, 0, 57, 1, 0, 0, 0, 0, 61,
1, 0, 0, 0, 0, 63, 1, 0, 0, 0, 0, 71, 1, 0, 0, 0, 0, 73, 1, 0, 0, 0, 0,
77, 1, 0, 0, 0, 1, 79, 1, 0, 0, 0, 3, 81, 1, 0, 0, 0, 5, 83, 1, 0, 0, 0,
7, 85, 1, 0, 0, 0, 9, 87, 1, 0, 0, 0, 11, 92, 1, 0, 0, 0, 13, 94, 1, 0,
0, 0, 15, 97, 1, 0, 0, 0, 17, 100, 1, 0, 0, 0, 19, 102, 1, 0, 0, 0, 21,
105, 1, 0, 0, 0, 23, 107, 1, 0, 0, 0, 25, 110, 1, 0, 0, 0, 27, 115, 1,
0, 0, 0, 29, 121, 1, 0, 0, 0, 31, 129, 1, 0, 0, 0, 33, 137, 1, 0, 0, 0,
35, 144, 1, 0, 0, 0, 37, 154, 1, 0, 0, 0, 39, 157, 1, 0, 0, 0, 41, 161,
1, 0, 0, 0, 43, 165, 1, 0, 0, 0, 45, 168, 1, 0, 0, 0, 47, 177, 1, 0, 0,
0, 49, 181, 1, 0, 0, 0, 51, 188, 1, 0, 0, 0, 53, 195, 1, 0, 0, 0, 55, 202,
1, 0, 0, 0, 57, 226, 1, 0, 0, 0, 59, 228, 1, 0, 0, 0, 61, 278, 1, 0, 0,
0, 63, 300, 1, 0, 0, 0, 65, 302, 1, 0, 0, 0, 67, 309, 1, 0, 0, 0, 69, 312,
1, 0, 0, 0, 71, 316, 1, 0, 0, 0, 73, 333, 1, 0, 0, 0, 75, 339, 1, 0, 0,
0, 77, 342, 1, 0, 0, 0, 79, 80, 5, 40, 0, 0, 80, 2, 1, 0, 0, 0, 81, 82,
5, 41, 0, 0, 82, 4, 1, 0, 0, 0, 83, 84, 5, 91, 0, 0, 84, 6, 1, 0, 0, 0,
85, 86, 5, 93, 0, 0, 86, 8, 1, 0, 0, 0, 87, 88, 5, 44, 0, 0, 88, 10, 1,
0, 0, 0, 89, 93, 5, 61, 0, 0, 90, 91, 5, 61, 0, 0, 91, 93, 5, 61, 0, 0,
92, 89, 1, 0, 0, 0, 92, 90, 1, 0, 0, 0, 93, 12, 1, 0, 0, 0, 94, 95, 5,
33, 0, 0, 95, 96, 5, 61, 0, 0, 96, 14, 1, 0, 0, 0, 97, 98, 5, 60, 0, 0,
98, 99, 5, 62, 0, 0, 99, 16, 1, 0, 0, 0, 100, 101, 5, 60, 0, 0, 101, 18,
1, 0, 0, 0, 102, 103, 5, 60, 0, 0, 103, 104, 5, 61, 0, 0, 104, 20, 1, 0,
0, 0, 105, 106, 5, 62, 0, 0, 106, 22, 1, 0, 0, 0, 107, 108, 5, 62, 0, 0,
108, 109, 5, 61, 0, 0, 109, 24, 1, 0, 0, 0, 110, 111, 7, 0, 0, 0, 111,
112, 7, 1, 0, 0, 112, 113, 7, 2, 0, 0, 113, 114, 7, 3, 0, 0, 114, 26, 1,
0, 0, 0, 115, 116, 7, 1, 0, 0, 116, 117, 7, 0, 0, 0, 117, 118, 7, 1, 0,
0, 118, 119, 7, 2, 0, 0, 119, 120, 7, 3, 0, 0, 120, 28, 1, 0, 0, 0, 121,
122, 7, 4, 0, 0, 122, 123, 7, 3, 0, 0, 123, 124, 7, 5, 0, 0, 124, 125,
7, 6, 0, 0, 125, 126, 7, 3, 0, 0, 126, 127, 7, 3, 0, 0, 127, 128, 7, 7,
0, 0, 128, 30, 1, 0, 0, 0, 129, 130, 7, 3, 0, 0, 130, 131, 7, 8, 0, 0,
131, 132, 7, 1, 0, 0, 132, 133, 7, 9, 0, 0, 133, 135, 7, 5, 0, 0, 134,
136, 7, 9, 0, 0, 135, 134, 1, 0, 0, 0, 135, 136, 1, 0, 0, 0, 136, 32, 1,
0, 0, 0, 137, 138, 7, 10, 0, 0, 138, 139, 7, 3, 0, 0, 139, 140, 7, 11,
0, 0, 140, 141, 7, 3, 0, 0, 141, 142, 7, 8, 0, 0, 142, 143, 7, 12, 0, 0,
143, 34, 1, 0, 0, 0, 144, 145, 7, 13, 0, 0, 145, 146, 7, 14, 0, 0, 146,
147, 7, 7, 0, 0, 147, 148, 7, 5, 0, 0, 148, 149, 7, 15, 0, 0, 149, 150,
7, 1, 0, 0, 150, 152, 7, 7, 0, 0, 151, 153, 7, 9, 0, 0, 152, 151, 1, 0,
0, 0, 152, 153, 1, 0, 0, 0, 153, 36, 1, 0, 0, 0, 154, 155, 7, 1, 0, 0,
155, 156, 7, 7, 0, 0, 156, 38, 1, 0, 0, 0, 157, 158, 7, 7, 0, 0, 158, 159,
7, 14, 0, 0, 159, 160, 7, 5, 0, 0, 160, 40, 1, 0, 0, 0, 161, 162, 7, 15,
0, 0, 162, 163, 7, 7, 0, 0, 163, 164, 7, 16, 0, 0, 164, 42, 1, 0, 0, 0,
165, 166, 7, 14, 0, 0, 166, 167, 7, 10, 0, 0, 167, 44, 1, 0, 0, 0, 168,
169, 7, 17, 0, 0, 169, 170, 7, 15, 0, 0, 170, 171, 7, 9, 0, 0, 171, 172,
7, 5, 0, 0, 172, 173, 7, 14, 0, 0, 173, 174, 7, 2, 0, 0, 174, 175, 7, 3,
0, 0, 175, 176, 7, 7, 0, 0, 176, 46, 1, 0, 0, 0, 177, 178, 7, 17, 0, 0,
178, 179, 7, 15, 0, 0, 179, 180, 7, 9, 0, 0, 180, 48, 1, 0, 0, 0, 181,
182, 7, 17, 0, 0, 182, 183, 7, 15, 0, 0, 183, 184, 7, 9, 0, 0, 184, 185,
7, 15, 0, 0, 185, 186, 7, 7, 0, 0, 186, 187, 7, 18, 0, 0, 187, 50, 1, 0,
0, 0, 188, 189, 7, 17, 0, 0, 189, 190, 7, 15, 0, 0, 190, 191, 7, 9, 0,
0, 191, 192, 7, 15, 0, 0, 192, 193, 7, 0, 0, 0, 193, 194, 7, 0, 0, 0, 194,
52, 1, 0, 0, 0, 195, 196, 7, 9, 0, 0, 196, 197, 7, 3, 0, 0, 197, 198, 7,
15, 0, 0, 198, 199, 7, 10, 0, 0, 199, 200, 7, 13, 0, 0, 200, 201, 7, 17,
0, 0, 201, 54, 1, 0, 0, 0, 202, 203, 7, 12, 0, 0, 203, 204, 7, 15, 0, 0,
204, 205, 7, 5, 0, 0, 205, 206, 7, 5, 0, 0, 206, 207, 7, 3, 0, 0, 207,
208, 7, 10, 0, 0, 208, 212, 7, 7, 0, 0, 209, 211, 7, 19, 0, 0, 210, 209,
1, 0, 0, 0, 211, 214, 1, 0, 0, 0, 212, 210, 1, 0, 0, 0, 212, 213, 1, 0,
0, 0, 213, 215, 1, 0, 0, 0, 214, 212, 1, 0, 0, 0, 215, 216, 5, 40, 0, 0,
216, 56, 1, 0, 0, 0, 217, 218, 7, 5, 0, 0, 218, 219, 7, 10, 0, 0, 219,
220, 7, 20, 0, 0, 220, 227, 7, 3, 0, 0, 221, 222, 7, 21, 0, 0, 222, 223,
7, 15, 0, 0, 223, 224, 7, 0, 0, 0, 224, 225, 7, 9, 0, 0, 225, 227, 7, 3,
0, 0, 226, 217, 1, 0, 0, 0, 226, 221, 1, 0, 0, 0, 227, 58, 1, 0, 0, 0,
228, 229, 7, 22, 0, 0, 229, 60, 1, 0, 0, 0, 230, 232, 3, 59, 29, 0, 231,
230, 1, 0, 0, 0, 231, 232, 1, 0, 0, 0, 232, 234, 1, 0, 0, 0, 233, 235,
3, 75, 37, 0, 234, 233, 1, 0, 0, 0, 235, 236, 1, 0, 0, 0, 236, 234, 1,
0, 0, 0, 236, 237, 1, 0, 0, 0, 237, 245, 1, 0, 0, 0, 238, 242, 5, 46, 0,
0, 239, 241, 3, 75, 37, 0, 240, 239, 1, 0, 0, 0, 241, 244, 1, 0, 0, 0,
242, 240, 1, 0, 0, 0, 242, 243, 1, 0, 0, 0, 243, 246, 1, 0, 0, 0, 244,
242, 1, 0, 0, 0, 245, 238, 1, 0, 0, 0, 245, 246, 1, 0, 0, 0, 246, 256,
1, 0, 0, 0, 247, 249, 7, 3, 0, 0, 248, 250, 3, 59, 29, 0, 249, 248, 1,
0, 0, 0, 249, 250, 1, 0, 0, 0, 250, 252, 1, 0, 0, 0, 251, 253, 3, 75, 37,
0, 252, 251, 1, 0, 0, 0, 253, 254, 1, 0, 0, 0, 254, 252, 1, 0, 0, 0, 254,
255, 1, 0, 0, 0, 255, 257, 1, 0, 0, 0, 256, 247, 1, 0, 0, 0, 256, 257,
1, 0, 0, 0, 257, 279, 1, 0, 0, 0, 258, 260, 3, 59, 29, 0, 259, 258, 1,
0, 0, 0, 259, 260, 1, 0, 0, 0, 260, 261, 1, 0, 0, 0, 261, 263, 5, 46, 0,
0, 262, 264, 3, 75, 37, 0, 263, 262, 1, 0, 0, 0, 264, 265, 1, 0, 0, 0,
265, 263, 1, 0, 0, 0, 265, 266, 1, 0, 0, 0, 266, 276, 1, 0, 0, 0, 267,
269, 7, 3, 0, 0, 268, 270, 3, 59, 29, 0, 269, 268, 1, 0, 0, 0, 269, 270,
1, 0, 0, 0, 270, 272, 1, 0, 0, 0, 271, 273, 3, 75, 37, 0, 272, 271, 1,
0, 0, 0, 273, 274, 1, 0, 0, 0, 274, 272, 1, 0, 0, 0, 274, 275, 1, 0, 0,
0, 275, 277, 1, 0, 0, 0, 276, 267, 1, 0, 0, 0, 276, 277, 1, 0, 0, 0, 277,
279, 1, 0, 0, 0, 278, 231, 1, 0, 0, 0, 278, 259, 1, 0, 0, 0, 279, 62, 1,
0, 0, 0, 280, 286, 5, 34, 0, 0, 281, 285, 8, 23, 0, 0, 282, 283, 5, 92,
0, 0, 283, 285, 9, 0, 0, 0, 284, 281, 1, 0, 0, 0, 284, 282, 1, 0, 0, 0,
285, 288, 1, 0, 0, 0, 286, 284, 1, 0, 0, 0, 286, 287, 1, 0, 0, 0, 287,
289, 1, 0, 0, 0, 288, 286, 1, 0, 0, 0, 289, 301, 5, 34, 0, 0, 290, 296,
5, 39, 0, 0, 291, 295, 8, 24, 0, 0, 292, 293, 5, 92, 0, 0, 293, 295, 9,
0, 0, 0, 294, 291, 1, 0, 0, 0, 294, 292, 1, 0, 0, 0, 295, 298, 1, 0, 0,
0, 296, 294, 1, 0, 0, 0, 296, 297, 1, 0, 0, 0, 297, 299, 1, 0, 0, 0, 298,
296, 1, 0, 0, 0, 299, 301, 5, 39, 0, 0, 300, 280, 1, 0, 0, 0, 300, 290,
1, 0, 0, 0, 301, 64, 1, 0, 0, 0, 302, 306, 7, 25, 0, 0, 303, 305, 7, 26,
0, 0, 304, 303, 1, 0, 0, 0, 305, 308, 1, 0, 0, 0, 306, 304, 1, 0, 0, 0,
306, 307, 1, 0, 0, 0, 307, 66, 1, 0, 0, 0, 308, 306, 1, 0, 0, 0, 309, 310,
5, 91, 0, 0, 310, 311, 5, 93, 0, 0, 311, 68, 1, 0, 0, 0, 312, 313, 5, 91,
0, 0, 313, 314, 5, 42, 0, 0, 314, 315, 5, 93, 0, 0, 315, 70, 1, 0, 0, 0,
316, 329, 3, 65, 32, 0, 317, 318, 5, 46, 0, 0, 318, 328, 3, 65, 32, 0,
319, 328, 3, 67, 33, 0, 320, 328, 3, 69, 34, 0, 321, 323, 5, 46, 0, 0,
322, 324, 3, 75, 37, 0, 323, 322, 1, 0, 0, 0, 324, 325, 1, 0, 0, 0, 325,
323, 1, 0, 0, 0, 325, 326, 1, 0, 0, 0, 326, 328, 1, 0, 0, 0, 327, 317,
1, 0, 0, 0, 327, 319, 1, 0, 0, 0, 327, 320, 1, 0, 0, 0, 327, 321, 1, 0,
0, 0, 328, 331, 1, 0, 0, 0, 329, 327, 1, 0, 0, 0, 329, 330, 1, 0, 0, 0,
330, 72, 1, 0, 0, 0, 331, 329, 1, 0, 0, 0, 332, 334, 7, 27, 0, 0, 333,
332, 1, 0, 0, 0, 334, 335, 1, 0, 0, 0, 335, 333, 1, 0, 0, 0, 335, 336,
1, 0, 0, 0, 336, 337, 1, 0, 0, 0, 337, 338, 6, 36, 0, 0, 338, 74, 1, 0,
0, 0, 339, 340, 7, 28, 0, 0, 340, 76, 1, 0, 0, 0, 341, 343, 8, 29, 0, 0,
342, 341, 1, 0, 0, 0, 343, 344, 1, 0, 0, 0, 344, 342, 1, 0, 0, 0, 344,
345, 1, 0, 0, 0, 345, 78, 1, 0, 0, 0, 30, 0, 92, 135, 152, 212, 226, 231,
236, 242, 245, 249, 254, 256, 259, 265, 269, 274, 276, 278, 284, 286, 294,
296, 300, 306, 325, 327, 329, 335, 344, 1, 6, 0, 0,
}
deserializer := antlr.NewATNDeserializer(nil)
staticData.atn = deserializer.Deserialize(staticData.serializedATN)
@@ -258,37 +268,38 @@ func NewFilterQueryLexer(input antlr.CharStream) *FilterQueryLexer {
// FilterQueryLexer tokens.
const (
FilterQueryLexerLPAREN = 1
FilterQueryLexerRPAREN = 2
FilterQueryLexerLBRACK = 3
FilterQueryLexerRBRACK = 4
FilterQueryLexerCOMMA = 5
FilterQueryLexerEQUALS = 6
FilterQueryLexerNOT_EQUALS = 7
FilterQueryLexerNEQ = 8
FilterQueryLexerLT = 9
FilterQueryLexerLE = 10
FilterQueryLexerGT = 11
FilterQueryLexerGE = 12
FilterQueryLexerLIKE = 13
FilterQueryLexerILIKE = 14
FilterQueryLexerBETWEEN = 15
FilterQueryLexerEXISTS = 16
FilterQueryLexerREGEXP = 17
FilterQueryLexerCONTAINS = 18
FilterQueryLexerIN = 19
FilterQueryLexerNOT = 20
FilterQueryLexerAND = 21
FilterQueryLexerOR = 22
FilterQueryLexerHASTOKEN = 23
FilterQueryLexerHAS = 24
FilterQueryLexerHASANY = 25
FilterQueryLexerHASALL = 26
FilterQueryLexerSEARCH = 27
FilterQueryLexerBOOL = 28
FilterQueryLexerNUMBER = 29
FilterQueryLexerQUOTED_TEXT = 30
FilterQueryLexerKEY = 31
FilterQueryLexerWS = 32
FilterQueryLexerFREETEXT = 33
FilterQueryLexerLPAREN = 1
FilterQueryLexerRPAREN = 2
FilterQueryLexerLBRACK = 3
FilterQueryLexerRBRACK = 4
FilterQueryLexerCOMMA = 5
FilterQueryLexerEQUALS = 6
FilterQueryLexerNOT_EQUALS = 7
FilterQueryLexerNEQ = 8
FilterQueryLexerLT = 9
FilterQueryLexerLE = 10
FilterQueryLexerGT = 11
FilterQueryLexerGE = 12
FilterQueryLexerLIKE = 13
FilterQueryLexerILIKE = 14
FilterQueryLexerBETWEEN = 15
FilterQueryLexerEXISTS = 16
FilterQueryLexerREGEXP = 17
FilterQueryLexerCONTAINS = 18
FilterQueryLexerIN = 19
FilterQueryLexerNOT = 20
FilterQueryLexerAND = 21
FilterQueryLexerOR = 22
FilterQueryLexerHASTOKEN = 23
FilterQueryLexerHAS = 24
FilterQueryLexerHASANY = 25
FilterQueryLexerHASALL = 26
FilterQueryLexerSEARCH = 27
FilterQueryLexerPATTERN_CALL = 28
FilterQueryLexerBOOL = 29
FilterQueryLexerNUMBER = 30
FilterQueryLexerQUOTED_TEXT = 31
FilterQueryLexerKEY = 32
FilterQueryLexerWS = 33
FilterQueryLexerFREETEXT = 34
)

View File

@@ -47,6 +47,9 @@ type FilterQueryListener interface {
// EnterSearchCall is called when entering the searchCall production.
EnterSearchCall(c *SearchCallContext)
// EnterPatternCall is called when entering the patternCall production.
EnterPatternCall(c *PatternCallContext)
// EnterFunctionParamList is called when entering the functionParamList production.
EnterFunctionParamList(c *FunctionParamListContext)
@@ -101,6 +104,9 @@ type FilterQueryListener interface {
// ExitSearchCall is called when exiting the searchCall production.
ExitSearchCall(c *SearchCallContext)
// ExitPatternCall is called when exiting the patternCall production.
ExitPatternCall(c *PatternCallContext)
// ExitFunctionParamList is called when exiting the functionParamList production.
ExitFunctionParamList(c *FunctionParamListContext)

File diff suppressed because it is too large Load Diff

View File

@@ -47,6 +47,9 @@ type FilterQueryVisitor interface {
// Visit a parse tree produced by FilterQueryParser#searchCall.
VisitSearchCall(ctx *SearchCallContext) interface{}
// Visit a parse tree produced by FilterQueryParser#patternCall.
VisitPatternCall(ctx *PatternCallContext) interface{}
// Visit a parse tree produced by FilterQueryParser#functionParamList.
VisitFunctionParamList(ctx *FunctionParamListContext) interface{}

View File

@@ -446,6 +446,8 @@ func emptyResultFor(kind qbtypes.RequestType, queryName string) *qbtypes.Result
value = &qbtypes.TimeSeriesData{QueryName: queryName}
case kind == qbtypes.RequestTypeScalar:
value = &qbtypes.ScalarData{QueryName: queryName}
case kind == qbtypes.RequestTypePattern:
value = &qbtypes.PatternsData{QueryName: queryName, SampleRate: 1, Patterns: []*qbtypes.Pattern{}}
default:
value = &qbtypes.RawData{QueryName: queryName}
}

View File

@@ -98,6 +98,8 @@ func consume(rows driver.Rows, kind qbtypes.RequestType, queryWindow *qbtypes.Ti
payload, err = readAsHeatmap(rows, queryWindow, step, queryName)
case qbtypes.RequestTypeRaw, qbtypes.RequestTypeTrace, qbtypes.RequestTypeRawStream:
payload, err = readAsRaw(rows, queryName)
case qbtypes.RequestTypePattern:
payload, err = readAsPatterns(rows, queryName)
// TODO: add support for other request types
}
@@ -442,6 +444,70 @@ func isNumericKind(t reflect.Type) bool {
}
}
// readAsPatterns reads a patterns statement: one row per pattern, its columns
// named by the qbtypes.PatternsColumn constants. Counts scale up by the
// sample rate.
func readAsPatterns(rows driver.Rows, queryName string) (*qbtypes.PatternsData, error) {
colNames := rows.Columns()
colTypes := rows.ColumnTypes()
scan := make([]any, len(colTypes))
for i := range scan {
scan[i] = reflect.New(colTypes[i].ScanType()).Interface()
}
data := &qbtypes.PatternsData{QueryName: queryName, SampleRate: 1, Patterns: []*qbtypes.Pattern{}}
for rows.Next() {
if err := rows.Scan(scan...); err != nil {
return nil, err
}
pattern := &qbtypes.Pattern{Trend: []*qbtypes.PatternTrendPoint{}}
var sampledCount uint64
var trendTs, trendCounts []int64
for i, name := range colNames {
value := derefValue(scan[i])
switch name {
case qbtypes.PatternsColumnPattern:
pattern.Pattern, _ = value.(string)
case qbtypes.PatternsColumnID:
pattern.ID, _ = value.(string)
case qbtypes.PatternsColumnSampledCount:
sampledCount, _ = value.(uint64)
case qbtypes.PatternsColumnSampleRate:
if rate, ok := value.(uint64); ok && rate > 0 {
data.SampleRate = rate
}
case qbtypes.PatternsColumnTotal:
data.Total, _ = value.(uint64)
case qbtypes.PatternsColumnTrendTs:
trendTs, _ = value.([]int64)
case qbtypes.PatternsColumnTrendCounts:
trendCounts, _ = value.([]int64)
}
}
pattern.Count = sampledCount * data.SampleRate
for i := 0; i < len(trendTs) && i < len(trendCounts); i++ {
pattern.Trend = append(pattern.Trend, &qbtypes.PatternTrendPoint{
Timestamp: trendTs[i] / 1_000_000,
Count: uint64(trendCounts[i]) * data.SampleRate,
})
}
data.Patterns = append(data.Patterns, pattern)
}
if err := rows.Err(); err != nil {
return nil, err
}
data.Total *= data.SampleRate
for _, pattern := range data.Patterns {
if data.Total > 0 {
pattern.Percent = 100 * float64(pattern.Count) / float64(data.Total)
}
}
return data, nil
}
func readAsScalar(rows driver.Rows, queryName string) (*qbtypes.ScalarData, error) {
colNames := rows.Columns()
colTypes := rows.ColumnTypes()

View File

@@ -691,6 +691,8 @@ func (q *querier) run(
return slices.ContainsFunc(val.Aggregations, func(aggregation *qbtypes.DistributionAggregation) bool {
return len(aggregation.Distributions) != 0
})
case *qbtypes.PatternsData:
return len(val.Patterns) != 0
}
return false
}
@@ -739,6 +741,8 @@ func (q *querier) run(
v.QueryName = name
case *qbtypes.DistributionData:
v.QueryName = name
case *qbtypes.PatternsData:
v.QueryName = name
}
queryResults[i] = result
return nil

View File

@@ -32,7 +32,7 @@ var friendly = map[string]string{
"BETWEEN": "BETWEEN", "IN": "IN", "EXISTS": "EXISTS",
"REGEXP": "REGEXP", "CONTAINS": "CONTAINS",
"HAS": "has()", "HASANY": "hasAny()", "HASALL": "hasAll()",
"HASTOKEN": "hasToken()", "SEARCH": "search()",
"HASTOKEN": "hasToken()", "SEARCH": "search()", "PATTERN_CALL": "pattern()",
// literals / identifiers
"NUMBER": "number",

View File

@@ -194,6 +194,9 @@ func (d *LogicalContradictionDetector) VisitPrimary(ctx *grammar.PrimaryContext)
} else if ctx.SearchCall() != nil {
// search() spans all fields; it can never be a logical contradiction
return nil
} else if ctx.PatternCall() != nil {
// pattern() reads no key, so it can't contradict a comparison
return nil
} else if ctx.FullText() != nil {
// Handle full text search if needed
return nil

View File

@@ -204,6 +204,8 @@ func (v *filterExpressionVisitor) Visit(tree antlr.ParseTree) any {
return v.VisitFullText(t)
case *grammar.SearchCallContext:
return v.VisitSearchCall(t)
case *grammar.PatternCallContext:
return v.VisitPatternCall(t)
case *grammar.FunctionCallContext:
return v.VisitFunctionCall(t)
case *grammar.FunctionParamListContext:
@@ -320,6 +322,8 @@ func (v *filterExpressionVisitor) VisitPrimary(ctx *grammar.PrimaryContext) any
return v.Visit(ctx.FunctionCall())
} else if ctx.SearchCall() != nil {
return v.Visit(ctx.SearchCall())
} else if ctx.PatternCall() != nil {
return v.Visit(ctx.PatternCall())
} else if ctx.FullText() != nil {
return v.Visit(ctx.FullText())
}
@@ -841,6 +845,43 @@ func (v *filterExpressionVisitor) VisitSearchCall(ctx *grammar.SearchCallContext
return v.builder.Or(conds...)
}
// PatternFilterer is a storage that can keep the logs of given log patterns.
type PatternFilterer interface {
PatternCondition(ctx context.Context, q qbtypes.QueryInfo, patterns []string, sb *sqlbuilder.SelectBuilder) (string, error)
}
// VisitPatternCall handles pattern('<pattern text>'[, ...]): the logs whose
// pattern is one of the given pattern texts.
func (v *filterExpressionVisitor) VisitPatternCall(ctx *grammar.PatternCallContext) any {
if v.storage.Traits().Split == qbtypes.FingerprintOfSplit {
// the main query evaluates it
return SkipConditionLiteral
}
filterer, ok := v.storage.(PatternFilterer)
if !ok {
v.errors = append(v.errors, "function `pattern` is supported only for logs")
return ErrorConditionLiteral
}
var patterns []string
if valueList := ctx.ValueList(); valueList != nil {
for _, param := range valueList.AllValue() {
pattern, ok := searchParamText(param)
if !ok {
v.errors = append(v.errors, "function `pattern` expects pattern texts, e.g. pattern('User <*> logged in')")
return ErrorConditionLiteral
}
patterns = append(patterns, pattern)
}
}
condition, err := filterer.PatternCondition(v.context, v.query, patterns, v.builder)
if err != nil {
v.recordError(err)
return ErrorConditionLiteral
}
return condition
}
// searchParamText returns an argument's raw token text (quoted or bare) rather than its
// visited value, so a bare word stays literal and search(1000000) isn't "1e+06".
func searchParamText(val grammar.IValueContext) (string, bool) {

View File

@@ -0,0 +1,168 @@
package logsstatementbuilder
import (
"context"
"fmt"
"strings"
"time"
"github.com/SigNoz/signoz/pkg/errors"
"github.com/SigNoz/signoz/pkg/querybuilder"
"github.com/SigNoz/signoz/pkg/telemetryschema/logstelemetryschema"
qbtypes "github.com/SigNoz/signoz/pkg/types/querybuildertypes/querybuildertypesv5"
"github.com/SigNoz/signoz/pkg/types/telemetrytypes"
"github.com/SigNoz/signoz/pkg/valuer"
"github.com/huandu/go-sqlbuilder"
)
const (
// patternsSampleTarget is about how many logs a patterns query counts: it
// reads one in ceil(matching logs / patternsSampleTarget) of them.
patternsSampleTarget = 500000
patternsDefaultLimit = 50
patternsMaxSteps = 60
patternsRateCTE = "__pattern_rate"
patternsLogsCTE = "__pattern_logs"
patternsChangesCTE = "__pattern_changes"
)
// buildPatternsQuery counts the logs of the query by the pattern the template
// miner mapped them to. Mappings are sharded like the logs, so each shard
// matches its own logs against its own mappings. Patterns that widened since
// are counted under their current ID. Above patternsSampleTarget matching
// logs, both sides keep the same hash sample of IDs.
func (b *logQueryStatementBuilder) buildPatternsQuery(
ctx context.Context,
orgID valuer.UUID,
sb *sqlbuilder.SelectBuilder,
query qbtypes.QueryBuilderQuery[qbtypes.LogAggregation],
start, end uint64,
keys map[string][]*telemetrytypes.TelemetryFieldKey,
variables map[string]qbtypes.VariableItem,
) (*qbtypes.Statement, error) {
var (
cteFragments []string
cteArgs [][]any
)
limit := query.Limit
if limit <= 0 {
limit = patternsDefaultLimit
}
if limit > qbtypes.PatternsMaxLimit {
return nil, errors.NewInvalidInputf(errors.CodeInvalidInput, "pattern requests return at most %d patterns, got limit %d", qbtypes.PatternsMaxLimit, limit)
}
frag, args, skipResourceFilter, err := b.maybeAttachResourceFilter(ctx, orgID, sqlbuilder.NewSelectBuilder(), query, start, end, variables)
if err != nil {
return nil, err
}
if frag != "" {
cteFragments = append(cteFragments, frag)
cteArgs = append(cteArgs, args)
}
filteredLogs := func(table, selectExpr string) (*sqlbuilder.SelectBuilder, querybuilder.PreparedWhereClause, error) {
logsSB := sqlbuilder.NewSelectBuilder()
logsSB.Select(selectExpr).From(fmt.Sprintf("%s.%s", logstelemetryschema.DBName, table))
if frag != "" {
logsSB.Where("resource_fingerprint GLOBAL IN (SELECT fingerprint FROM __resource_filter)")
}
where, err := b.addFilterCondition(ctx, orgID, logsSB, start, end, query, keys, variables, skipResourceFilter)
return logsSB, where, err
}
rateSB, preparedWhereClause, err := filteredLogs(logstelemetryschema.LogsV2TableName, fmt.Sprintf("greatest(toUInt64(1), toUInt64(ceil(count() / %d))) AS rate", patternsSampleTarget))
if err != nil {
return nil, err
}
rateSQL, rateArgs := rateSB.BuildWithFlavor(sqlbuilder.ClickHouse)
cteFragments = append(cteFragments, fmt.Sprintf("%s AS (%s)", patternsRateCTE, rateSQL))
cteArgs = append(cteArgs, rateArgs)
rate := fmt.Sprintf("(SELECT rate FROM %s)", patternsRateCTE)
hasFilter := query.Filter != nil && strings.TrimSpace(query.Filter.Expression) != ""
if hasFilter {
// read on each shard against that shard's mappings
logsSB, _, err := filteredLogs(logstelemetryschema.LogsV2LocalTableName, logstelemetryschema.LogsV2IDColumn)
if err != nil {
return nil, err
}
logsSB.Where(fmt.Sprintf("xxHash64(%s) %% %s = 0", logstelemetryschema.LogsV2IDColumn, rate))
logsSQL, logsArgs := logsSB.BuildWithFlavor(sqlbuilder.ClickHouse)
cteFragments = append(cteFragments, fmt.Sprintf("%s AS (%s)", patternsLogsCTE, logsSQL))
cteArgs = append(cteArgs, logsArgs)
}
cteFragments = append(cteFragments, fmt.Sprintf(
"%s AS (SELECT from_id, argMax(to_id, window_id) AS to_id FROM %s.%s GROUP BY from_id)",
patternsChangesCTE, logstelemetryschema.DBName, logstelemetryschema.LogPatternEvolutionsTableName))
cteArgs = append(cteArgs, nil)
startTime, endTime := time.Unix(0, int64(start)), time.Unix(0, int64(end))
bucketStart := uint64(startTime.Unix()) / logstelemetryschema.PatternBucketSeconds * logstelemetryschema.PatternBucketSeconds
bucketEnd := uint64(endTime.Unix())
stepNs := uint64(query.StepInterval.Seconds()) * querybuilder.NsToSeconds
if stepNs == 0 {
stepNs = querybuilder.RecommendedStepInterval(start, end) * querybuilder.NsToSeconds
}
if steps := (end - start) / stepNs; steps > patternsMaxSteps {
stepNs = (end - start + patternsMaxSteps - 1) / patternsMaxSteps
}
stepExpr := fmt.Sprintf("toInt64(%[1]d + intDiv(m.timestamp - %[1]d, %[2]d) * %[2]d)", start, stepNs)
sb.Select(
fmt.Sprintf("toString(ifNull(nullIf(c.to_id, 0), m.pattern_id)) AS %s", qbtypes.PatternsColumnID),
fmt.Sprintf("count() AS %s", qbtypes.PatternsColumnSampledCount),
fmt.Sprintf("%s AS %s", rate, qbtypes.PatternsColumnSampleRate),
fmt.Sprintf("sum(count()) OVER () AS %s", qbtypes.PatternsColumnTotal),
fmt.Sprintf("tupleElement(sumMap([%s], [toInt64(1)]) AS __trend, 1) AS %s", stepExpr, qbtypes.PatternsColumnTrendTs),
fmt.Sprintf("tupleElement(__trend, 2) AS %s", qbtypes.PatternsColumnTrendCounts),
)
sb.From(fmt.Sprintf("%s.%s AS m", logstelemetryschema.DBName, logstelemetryschema.DistributedLogPatternMappingsTableName))
sb.JoinWithOption(sqlbuilder.LeftJoin, fmt.Sprintf("%s AS c", patternsChangesCTE), "c.from_id = m.pattern_id")
sb.Where(
sb.Between("m.ts_bucket_start", bucketStart, bucketEnd),
sb.GE("m.timestamp", start),
sb.LT("m.timestamp", end),
fmt.Sprintf("xxHash64(m.log_id) %% %s = 0", rate),
)
if frag != "" {
sb.Where("m.resource_fingerprint GLOBAL IN (SELECT fingerprint FROM __resource_filter)")
}
if hasFilter {
sb.Where(fmt.Sprintf("m.log_id IN (SELECT %s FROM %s)", logstelemetryschema.LogsV2IDColumn, patternsLogsCTE))
}
sb.GroupBy(qbtypes.PatternsColumnID)
sb.OrderBy(fmt.Sprintf("%s DESC", qbtypes.PatternsColumnSampledCount), fmt.Sprintf("%s ASC", qbtypes.PatternsColumnID))
sb.Limit(limit)
if query.Offset > 0 {
sb.Offset(query.Offset)
}
countsSQL, countsArgs := sb.BuildWithFlavor(sqlbuilder.ClickHouse)
// templates are written by processing time, so late logs need the next bucket
templatesSB := sqlbuilder.NewSelectBuilder()
templatesSB.Select("toString(pattern_id) AS id", "any(template) AS template").
From(fmt.Sprintf("%s.%s", logstelemetryschema.DBName, logstelemetryschema.LogPatternTemplatesTableName)).
Where(templatesSB.Between("ts_bucket_start", bucketStart, bucketEnd+logstelemetryschema.PatternBucketSeconds)).
GroupBy("pattern_id")
templatesSQL, templatesArgs := templatesSB.BuildWithFlavor(sqlbuilder.ClickHouse)
mainSQL := fmt.Sprintf(
"SELECT p.%[1]s AS %[1]s, ifNull(t.template, '') AS %[2]s, p.%[3]s AS %[3]s, p.%[4]s AS %[4]s, p.%[5]s AS %[5]s, p.%[6]s AS %[6]s, p.%[7]s AS %[7]s"+
" FROM (%[8]s) AS p LEFT JOIN (%[9]s) AS t ON t.id = p.%[1]s ORDER BY p.%[3]s DESC, p.%[1]s ASC",
qbtypes.PatternsColumnID, qbtypes.PatternsColumnPattern, qbtypes.PatternsColumnSampledCount,
qbtypes.PatternsColumnSampleRate, qbtypes.PatternsColumnTotal, qbtypes.PatternsColumnTrendTs,
qbtypes.PatternsColumnTrendCounts, countsSQL, templatesSQL)
return &qbtypes.Statement{
Query: querybuilder.CombineCTEs(cteFragments) + mainSQL,
Args: querybuilder.PrependArgs(cteArgs, append(countsArgs, templatesArgs...)),
Warnings: preparedWhereClause.Warnings,
WarningsDocURL: preparedWhereClause.WarningsDocURL,
CostGuard: b.costGuardFor(ctx, orgID, preparedWhereClause.RequiresCostGuard),
}, nil
}

View File

@@ -0,0 +1,96 @@
package logsstatementbuilder
import (
"context"
"testing"
"time"
"github.com/SigNoz/signoz/pkg/flagger/flaggertest"
"github.com/SigNoz/signoz/pkg/instrumentation/instrumentationtest"
"github.com/SigNoz/signoz/pkg/querybuilder"
"github.com/SigNoz/signoz/pkg/statementbuilder"
"github.com/SigNoz/signoz/pkg/telemetryschema/logstelemetryschema"
qbtypes "github.com/SigNoz/signoz/pkg/types/querybuildertypes/querybuildertypesv5"
"github.com/SigNoz/signoz/pkg/types/telemetrytypes"
"github.com/SigNoz/signoz/pkg/types/telemetrytypes/telemetrytypestest"
"github.com/SigNoz/signoz/pkg/valuer"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestStatementBuilderPatterns(t *testing.T) {
testCases := []struct {
name string
query qbtypes.QueryBuilderQuery[qbtypes.LogAggregation]
contains []string
notContains []string
wantErr string
}{
{
name: "NoFilter_ReadsMappingsOnly",
query: qbtypes.QueryBuilderQuery[qbtypes.LogAggregation]{Signal: telemetrytypes.SignalLogs, Limit: 20},
contains: []string{
"__pattern_changes AS (SELECT from_id, argMax(to_id, window_id) AS to_id FROM signoz_logs.log_pattern_evolutions GROUP BY from_id)",
"FROM signoz_logs.distributed_log_pattern_mappings AS m LEFT JOIN __pattern_changes AS c ON c.from_id = m.pattern_id",
"m.timestamp >= ? AND m.timestamp < ?",
"intDiv(m.timestamp - 1747947419000000000,",
"xxHash64(m.log_id) % (SELECT rate FROM __pattern_rate) = 0",
"toString(ifNull(nullIf(c.to_id, 0), m.pattern_id)) AS __pattern_id",
"FROM signoz_logs.log_pattern_templates WHERE ts_bucket_start BETWEEN ? AND ? GROUP BY pattern_id",
},
notContains: []string{"__pattern_logs", "__resource_filter"},
},
{
name: "Filter_KeepsMatchingLogsOnSameShardAndSample",
query: qbtypes.QueryBuilderQuery[qbtypes.LogAggregation]{
Signal: telemetrytypes.SignalLogs,
Filter: &qbtypes.Filter{Expression: "service.name = 'cartservice'"},
},
contains: []string{
"__pattern_logs AS (SELECT id FROM signoz_logs.logs_v2 WHERE resource_fingerprint GLOBAL IN (SELECT fingerprint FROM __resource_filter)",
"xxHash64(id) % (SELECT rate FROM __pattern_rate) = 0",
"m.resource_fingerprint GLOBAL IN (SELECT fingerprint FROM __resource_filter)",
"m.log_id IN (SELECT id FROM __pattern_logs)",
},
notContains: []string{"GLOBAL IN (SELECT id FROM __pattern_logs)"},
},
{
name: "LimitAboveMax_Rejected",
query: qbtypes.QueryBuilderQuery[qbtypes.LogAggregation]{Signal: telemetrytypes.SignalLogs, Limit: qbtypes.PatternsMaxLimit + 1},
wantErr: "pattern requests return at most",
},
}
fl := flaggertest.New(t)
metadataStore := telemetrytypestest.NewMockMetadataStore()
metadataStore.KeysMap = logstelemetryschema.BuildCompleteFieldKeyMap(time.Date(2024, 1, 15, 10, 0, 0, 0, time.UTC))
storage := logstelemetryschema.NewStorage()
builder := NewLogQueryStatementBuilder(
instrumentationtest.New().ToProviderSettings(),
metadataStore,
storage,
querybuilder.NewAggExprRewriter(instrumentationtest.New().ToProviderSettings(), nil, storage, fl, telemetrytypes.SignalLogs),
logstelemetryschema.DefaultFullTextColumn,
fl,
nil,
statementbuilder.Config{SkipResourceFingerprint: statementbuilder.SkipResourceFingerprint{Enabled: false, Threshold: 100000}},
)
for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {
stmt, err := builder.Build(context.Background(), valuer.UUID{}, 1747947419000, 1747983448000, qbtypes.RequestTypePattern, testCase.query, nil)
if testCase.wantErr != "" {
require.Error(t, err)
assert.Contains(t, err.Error(), testCase.wantErr)
return
}
require.NoError(t, err)
for _, fragment := range testCase.contains {
assert.Contains(t, stmt.Query, fragment)
}
for _, fragment := range testCase.notContains {
assert.NotContains(t, stmt.Query, fragment)
}
})
}
}

View File

@@ -146,6 +146,8 @@ func (b *logQueryStatementBuilder) Build(
stmt, err = b.buildHeatmapTimeSeriesQuery(ctx, orgID, q, query, start, end, keys, variables)
case qbtypes.RequestTypeScalar:
stmt, err = b.buildScalarQuery(ctx, orgID, q, query, start, end, keys, false, variables)
case qbtypes.RequestTypePattern:
stmt, err = b.buildPatternsQuery(ctx, orgID, q, query, start, end, keys, variables)
default:
return nil, errors.NewInvalidInputf(errors.CodeInvalidInput, "unsupported request type: %s", requestType)
}

View File

@@ -112,7 +112,7 @@ func TestFilterExprLogs(t *testing.T) {
category: "Single word",
query: "<script>alert('xss')</script>",
shouldPass: false,
expectedErrorContains: "expecting one of {(, ), AND, FREETEXT, NOT, boolean, has(), hasAll(), hasAny(), hasToken(), number, quoted text, search()} but got '<'",
expectedErrorContains: "expecting one of {(, ), AND, FREETEXT, NOT, boolean, has(), hasAll(), hasAny(), hasToken(), number, pattern(), quoted text, search()} but got '<'",
},
// Single word searches with spaces
@@ -178,7 +178,7 @@ func TestFilterExprLogs(t *testing.T) {
category: "Special characters",
query: "[tracing]",
shouldPass: false,
expectedErrorContains: "expecting one of {(, ), AND, FREETEXT, NOT, boolean, has(), hasAll(), hasAny(), hasToken(), number, quoted text, search()} but got '['",
expectedErrorContains: "expecting one of {(, ), AND, FREETEXT, NOT, boolean, has(), hasAll(), hasAny(), hasToken(), number, pattern(), quoted text, search()} but got '['",
},
{
category: "Special characters",
@@ -208,7 +208,7 @@ func TestFilterExprLogs(t *testing.T) {
category: "Special characters",
query: "ERROR: cannot execute update() in a read-only context",
shouldPass: false,
expectedErrorContains: "expecting one of {(, AND, FREETEXT, NOT, boolean, has(), hasAll(), hasAny(), hasToken(), number, quoted text, search()} but got ')'",
expectedErrorContains: "expecting one of {(, AND, FREETEXT, NOT, boolean, has(), hasAll(), hasAny(), hasToken(), number, pattern(), quoted text, search()} but got ')'",
},
{
category: "Special characters",
@@ -630,7 +630,7 @@ func TestFilterExprLogs(t *testing.T) {
shouldPass: false,
expectedQuery: "",
expectedArgs: nil,
expectedErrorContains: "expecting one of {(, ), FREETEXT, NOT, boolean, has(), hasAll(), hasAny(), hasToken(), number, quoted text, search()} but got 'and'",
expectedErrorContains: "expecting one of {(, ), FREETEXT, NOT, boolean, has(), hasAll(), hasAny(), hasToken(), number, pattern(), quoted text, search()} but got 'and'",
},
{
category: "Keyword conflict",
@@ -638,7 +638,7 @@ func TestFilterExprLogs(t *testing.T) {
shouldPass: false,
expectedQuery: "",
expectedArgs: nil,
expectedErrorContains: "expecting one of {(, ), AND, FREETEXT, NOT, boolean, has(), hasAll(), hasAny(), hasToken(), number, quoted text, search()} but got 'or'",
expectedErrorContains: "expecting one of {(, ), AND, FREETEXT, NOT, boolean, has(), hasAll(), hasAny(), hasToken(), number, pattern(), quoted text, search()} but got 'or'",
},
{
category: "Keyword conflict",
@@ -646,7 +646,7 @@ func TestFilterExprLogs(t *testing.T) {
shouldPass: false,
expectedQuery: "",
expectedArgs: nil,
expectedErrorContains: "expecting one of {(, ), FREETEXT, boolean, has(), hasAll(), hasAny(), hasToken(), number, quoted text, search()} but got EOF",
expectedErrorContains: "expecting one of {(, ), FREETEXT, boolean, has(), hasAll(), hasAny(), hasToken(), number, pattern(), quoted text, search()} but got EOF",
},
{
category: "Keyword conflict",
@@ -654,7 +654,7 @@ func TestFilterExprLogs(t *testing.T) {
shouldPass: false,
expectedQuery: "",
expectedArgs: nil,
expectedErrorContains: "expecting one of {(, ), AND, FREETEXT, NOT, boolean, has(), hasAll(), hasAny(), hasToken(), number, quoted text, search()} but got 'like'",
expectedErrorContains: "expecting one of {(, ), AND, FREETEXT, NOT, boolean, has(), hasAll(), hasAny(), hasToken(), number, pattern(), quoted text, search()} but got 'like'",
},
{
category: "Keyword conflict",
@@ -662,7 +662,7 @@ func TestFilterExprLogs(t *testing.T) {
shouldPass: false,
expectedQuery: "",
expectedArgs: nil,
expectedErrorContains: "expecting one of {(, ), AND, FREETEXT, NOT, boolean, has(), hasAll(), hasAny(), hasToken(), number, quoted text, search()} but got 'between'",
expectedErrorContains: "expecting one of {(, ), AND, FREETEXT, NOT, boolean, has(), hasAll(), hasAny(), hasToken(), number, pattern(), quoted text, search()} but got 'between'",
},
{
category: "Keyword conflict",
@@ -670,7 +670,7 @@ func TestFilterExprLogs(t *testing.T) {
shouldPass: false,
expectedQuery: "",
expectedArgs: nil,
expectedErrorContains: "expecting one of {(, ), AND, FREETEXT, NOT, boolean, has(), hasAll(), hasAny(), hasToken(), number, quoted text, search()} but got 'in'",
expectedErrorContains: "expecting one of {(, ), AND, FREETEXT, NOT, boolean, has(), hasAll(), hasAny(), hasToken(), number, pattern(), quoted text, search()} but got 'in'",
},
{
category: "Keyword conflict",
@@ -678,7 +678,7 @@ func TestFilterExprLogs(t *testing.T) {
shouldPass: false,
expectedQuery: "",
expectedArgs: nil,
expectedErrorContains: "expecting one of {(, ), AND, FREETEXT, NOT, boolean, has(), hasAll(), hasAny(), hasToken(), number, quoted text, search()} but got 'exists'",
expectedErrorContains: "expecting one of {(, ), AND, FREETEXT, NOT, boolean, has(), hasAll(), hasAny(), hasToken(), number, pattern(), quoted text, search()} but got 'exists'",
},
{
category: "Keyword conflict",
@@ -686,7 +686,7 @@ func TestFilterExprLogs(t *testing.T) {
shouldPass: false,
expectedQuery: "",
expectedArgs: nil,
expectedErrorContains: "expecting one of {(, ), AND, FREETEXT, NOT, boolean, has(), hasAll(), hasAny(), hasToken(), number, quoted text, search()} but got 'regexp'",
expectedErrorContains: "expecting one of {(, ), AND, FREETEXT, NOT, boolean, has(), hasAll(), hasAny(), hasToken(), number, pattern(), quoted text, search()} but got 'regexp'",
},
{
category: "Keyword conflict",
@@ -694,7 +694,7 @@ func TestFilterExprLogs(t *testing.T) {
shouldPass: false,
expectedQuery: "",
expectedArgs: nil,
expectedErrorContains: "expecting one of {(, ), AND, FREETEXT, NOT, boolean, has(), hasAll(), hasAny(), hasToken(), number, quoted text, search()} but got 'contains'",
expectedErrorContains: "expecting one of {(, ), AND, FREETEXT, NOT, boolean, has(), hasAll(), hasAny(), hasToken(), number, pattern(), quoted text, search()} but got 'contains'",
},
{
category: "Keyword conflict",
@@ -2062,9 +2062,9 @@ func TestFilterExprLogs(t *testing.T) {
expectedErrorContains: "",
},
{category: "Only keywords", query: "AND", shouldPass: false, expectedErrorContains: "expecting one of {(, ), FREETEXT, NOT, boolean, has(), hasAll(), hasAny(), hasToken(), number, quoted text, search()} but got 'AND'"},
{category: "Only keywords", query: "OR", shouldPass: false, expectedErrorContains: "expecting one of {(, ), AND, FREETEXT, NOT, boolean, has(), hasAll(), hasAny(), hasToken(), number, quoted text, search()} but got 'OR'"},
{category: "Only keywords", query: "NOT", shouldPass: false, expectedErrorContains: "expecting one of {(, ), FREETEXT, boolean, has(), hasAll(), hasAny(), hasToken(), number, quoted text, search()} but got EOF"},
{category: "Only keywords", query: "AND", shouldPass: false, expectedErrorContains: "expecting one of {(, ), FREETEXT, NOT, boolean, has(), hasAll(), hasAny(), hasToken(), number, pattern(), quoted text, search()} but got 'AND'"},
{category: "Only keywords", query: "OR", shouldPass: false, expectedErrorContains: "expecting one of {(, ), AND, FREETEXT, NOT, boolean, has(), hasAll(), hasAny(), hasToken(), number, pattern(), quoted text, search()} but got 'OR'"},
{category: "Only keywords", query: "NOT", shouldPass: false, expectedErrorContains: "expecting one of {(, ), FREETEXT, boolean, has(), hasAll(), hasAny(), hasToken(), number, pattern(), quoted text, search()} but got EOF"},
{category: "Only functions", query: "has", shouldPass: false, expectedErrorContains: "expecting one of {(, )} but got EOF"},
{category: "Only functions", query: "hasAny", shouldPass: false, expectedErrorContains: "expecting one of {(, )} but got EOF"},
@@ -2206,7 +2206,7 @@ func TestFilterExprLogs(t *testing.T) {
shouldPass: false,
expectedQuery: "",
expectedArgs: nil,
expectedErrorContains: "line 1:0 expecting one of {(, ), FREETEXT, NOT, boolean, has(), hasAll(), hasAny(), hasToken(), number, quoted text, search()} but got 'and'",
expectedErrorContains: "line 1:0 expecting one of {(, ), FREETEXT, NOT, boolean, has(), hasAll(), hasAny(), hasToken(), number, pattern(), quoted text, search()} but got 'and'",
},
{
category: "Operator keywords as keys",
@@ -2214,7 +2214,7 @@ func TestFilterExprLogs(t *testing.T) {
shouldPass: false,
expectedQuery: "",
expectedArgs: nil,
expectedErrorContains: "line 1:0 expecting one of {(, ), AND, FREETEXT, NOT, boolean, has(), hasAll(), hasAny(), hasToken(), number, quoted text, search()} but got 'or'",
expectedErrorContains: "line 1:0 expecting one of {(, ), AND, FREETEXT, NOT, boolean, has(), hasAll(), hasAny(), hasToken(), number, pattern(), quoted text, search()} but got 'or'",
},
{
category: "Operator keywords as keys",
@@ -2222,7 +2222,7 @@ func TestFilterExprLogs(t *testing.T) {
shouldPass: false,
expectedQuery: "",
expectedArgs: nil,
expectedErrorContains: "line 1:3 expecting one of {(, ), FREETEXT, boolean, has(), hasAll(), hasAny(), hasToken(), number, quoted text, search()} but got '='",
expectedErrorContains: "line 1:3 expecting one of {(, ), FREETEXT, boolean, has(), hasAll(), hasAny(), hasToken(), number, pattern(), quoted text, search()} but got '='",
},
{
category: "Operator keywords as keys",
@@ -2230,7 +2230,7 @@ func TestFilterExprLogs(t *testing.T) {
shouldPass: false,
expectedQuery: "",
expectedArgs: nil,
expectedErrorContains: "line 1:0 expecting one of {(, ), AND, FREETEXT, NOT, boolean, has(), hasAll(), hasAny(), hasToken(), number, quoted text, search()} but got 'between'",
expectedErrorContains: "line 1:0 expecting one of {(, ), AND, FREETEXT, NOT, boolean, has(), hasAll(), hasAny(), hasToken(), number, pattern(), quoted text, search()} but got 'between'",
},
{
category: "Operator keywords as keys",
@@ -2238,7 +2238,7 @@ func TestFilterExprLogs(t *testing.T) {
shouldPass: false,
expectedQuery: "",
expectedArgs: nil,
expectedErrorContains: "line 1:0 expecting one of {(, ), AND, FREETEXT, NOT, boolean, has(), hasAll(), hasAny(), hasToken(), number, quoted text, search()} but got 'in'",
expectedErrorContains: "line 1:0 expecting one of {(, ), AND, FREETEXT, NOT, boolean, has(), hasAll(), hasAny(), hasToken(), number, pattern(), quoted text, search()} but got 'in'",
},
// Using function keywords as keys

View File

@@ -0,0 +1,55 @@
package logstelemetryschema
import (
"context"
"fmt"
"hash/fnv"
"strconv"
"strings"
"time"
"github.com/SigNoz/signoz/pkg/errors"
qbtypes "github.com/SigNoz/signoz/pkg/types/querybuildertypes/querybuildertypesv5"
"github.com/huandu/go-sqlbuilder"
)
// PatternID is the template miner's ID of a pattern: the 64-bit FNV-1a hash
// of its template.
func PatternID(template string) uint64 {
h := fnv.New64a()
_, _ = h.Write([]byte(template))
return h.Sum64()
}
// PatternCondition keeps the logs mapped to the given templates' patterns, or
// to any older pattern that has since widened into one of them.
func (s *storage) PatternCondition(_ context.Context, q qbtypes.QueryInfo, patterns []string, sb *sqlbuilder.SelectBuilder) (string, error) {
if len(patterns) == 0 {
return "", errors.NewInvalidInputf(errors.CodeInvalidInput, "function `pattern` expects at least one pattern, e.g. pattern('User <*> logged in')")
}
ids := make([]string, len(patterns))
for i, pattern := range patterns {
ids[i] = strconv.FormatUint(PatternID(pattern), 10)
}
changes := fmt.Sprintf("(SELECT from_id, argMax(to_id, window_id) AS to_id FROM %s.%s GROUP BY from_id)", DBName, LogPatternEvolutionsTableName)
current := fmt.Sprintf(
"SELECT ifNull(nullIf(c.to_id, 0), p.id) FROM (SELECT arrayJoin([%s]) AS id) AS p LEFT JOIN %s AS c ON c.from_id = p.id",
strings.Join(ids, ", "), changes)
conditions := []string{
fmt.Sprintf("(pattern_id IN (%s) OR pattern_id IN (SELECT from_id FROM %s WHERE to_id IN (%s)))", current, changes, current),
}
if q.StartNs != 0 {
start := time.Unix(0, int64(q.StartNs))
conditions = append(conditions,
sb.GE("ts_bucket_start", uint64(start.Unix())/PatternBucketSeconds*PatternBucketSeconds),
sb.GE("timestamp", q.StartNs))
}
if q.EndNs != 0 {
end := time.Unix(0, int64(q.EndNs))
conditions = append(conditions, sb.LE("ts_bucket_start", uint64(end.Unix())), sb.LE("timestamp", q.EndNs))
}
return fmt.Sprintf("%s IN (SELECT log_id FROM %s.%s WHERE %s)",
LogsV2IDColumn, DBName, LogPatternMappingsTableName, strings.Join(conditions, " AND ")), nil
}

View File

@@ -0,0 +1,70 @@
package logstelemetryschema
import (
"context"
"testing"
qbtypes "github.com/SigNoz/signoz/pkg/types/querybuildertypes/querybuildertypesv5"
"github.com/huandu/go-sqlbuilder"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestPatternID(t *testing.T) {
testCases := []struct {
name string
template string
want uint64
}{
{name: "Wildcard", template: "auth <*>", want: 5564266107741400479},
{name: "Empty", template: "", want: 14695981039346656037},
}
for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {
assert.Equal(t, testCase.want, PatternID(testCase.template))
})
}
}
func TestPatternCondition(t *testing.T) {
testCases := []struct {
name string
patterns []string
query qbtypes.QueryInfo
contains []string
wantErr bool
}{
{
name: "OnePattern_MapsLogIDsOfPatternAndOlderIDs",
patterns: []string{"auth <*>"},
query: qbtypes.QueryInfo{StartNs: 1796243100000000000, EndNs: 1796243700000000000},
contains: []string{
"id IN (SELECT log_id FROM signoz_logs.log_pattern_mappings WHERE (pattern_id IN (",
"arrayJoin([5564266107741400479])",
"OR pattern_id IN (SELECT from_id FROM (SELECT from_id, argMax(to_id, window_id) AS to_id FROM signoz_logs.log_pattern_evolutions GROUP BY from_id) WHERE to_id IN (",
"ts_bucket_start >= ?", "timestamp >= ?", "ts_bucket_start <= ?", "timestamp <= ?",
},
},
{
name: "TwoPatterns_OneIDList",
patterns: []string{"auth <*>", ""},
contains: []string{"arrayJoin([5564266107741400479, 14695981039346656037])"},
},
{name: "NoPattern_Rejected", wantErr: true},
}
for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {
sb := sqlbuilder.NewSelectBuilder()
condition, err := (&storage{}).PatternCondition(context.Background(), testCase.query, testCase.patterns, sb)
if testCase.wantErr {
assert.Error(t, err)
return
}
require.NoError(t, err)
sql, _ := sb.Select("1").Where(condition).BuildWithFlavor(sqlbuilder.ClickHouse)
for _, fragment := range testCase.contains {
assert.Contains(t, sql, fragment)
}
})
}
}

View File

@@ -0,0 +1,13 @@
package logstelemetryschema
// The tables the template miner exporter writes. A log's pattern is in
// LogPatternMappingsTableName, sharded like the logs by the log's ID, so a
// shard's logs find their mappings on the same shard. Templates and
// evolutions are full copies on every node.
const (
LogPatternMappingsTableName = "log_pattern_mappings"
DistributedLogPatternMappingsTableName = "distributed_log_pattern_mappings"
LogPatternTemplatesTableName = "log_pattern_templates"
LogPatternEvolutionsTableName = "log_pattern_evolutions"
PatternBucketSeconds = 1800
)

View File

@@ -19,7 +19,7 @@ func (r *RequestType) UnmarshalJSON(data []byte) error {
}
v := RequestType{valuer.NewString(s)}
switch v {
case RequestTypeScalar, RequestTypeTimeSeries, RequestTypeRaw, RequestTypeRawStream, RequestTypeTrace, RequestTypeDistribution, RequestTypeHeatmap:
case RequestTypeScalar, RequestTypeTimeSeries, RequestTypeRaw, RequestTypeRawStream, RequestTypeTrace, RequestTypeDistribution, RequestTypeHeatmap, RequestTypePattern:
*r = v
return nil
default:
@@ -46,6 +46,9 @@ var (
// TimeSeriesData carrying one count per histogram bucket at each timestamp,
// with the shared bucket upper bounds on the aggregation's meta.
RequestTypeHeatmap = RequestType{valuer.NewString("heatmap")}
// PatternsData: the log patterns of one logs query, example: the patterns
// view of the logs explorer.
RequestTypePattern = RequestType{valuer.NewString("pattern")}
)
// IsAggregation returns true for request types that produce aggregated results
@@ -74,6 +77,7 @@ func (RequestType) Enum() []any {
RequestTypeRawStream,
RequestTypeTrace,
RequestTypeHeatmap,
RequestTypePattern,
RequestTypeDistribution,
}
}

View File

@@ -42,7 +42,7 @@ type QueryWarnDataAdditional struct {
}
type QueryData struct {
Results []any `json:"results" description:"One result per enabled query, typed by the request type: TimeSeriesData for time_series and heatmap, ScalarData for scalar, RawData for raw and DistributionData for distribution requests."`
Results []any `json:"results" description:"One result per enabled query, typed by the request type: TimeSeriesData for time_series and heatmap, ScalarData for scalar, RawData for raw, DistributionData for distribution and PatternsData for pattern requests."`
}
var _ jsonschema.OneOfExposer = QueryData{}
@@ -54,6 +54,7 @@ func (QueryData) JSONSchemaOneOf() []any {
ScalarData{},
RawData{},
DistributionData{},
PatternsData{},
}
}
@@ -129,7 +130,7 @@ var _ jsonschema.Preparer = &QueryRangeResponse{}
// PrepareJSONSchema adds description to the QueryRangeResponse schema.
func (q *QueryRangeResponse) PrepareJSONSchema(schema *jsonschema.Schema) error {
schema.WithDescription("Response from the v5 query range endpoint. The data.results array contains typed results depending on the requestType: TimeSeriesData for time_series and heatmap, ScalarData for scalar, RawData for raw, or DistributionData for distribution requests.")
schema.WithDescription("Response from the v5 query range endpoint. The data.results array contains typed results depending on the requestType: TimeSeriesData for time_series and heatmap, ScalarData for scalar, RawData for raw, DistributionData for distribution, or PatternsData for pattern requests.")
return nil
}
@@ -649,3 +650,35 @@ func (r RawData) MarshalJSON() ([]byte, error) {
type Alias RawData
return json.Marshal((*Alias)(&r))
}
// The columns of a patterns statement, which the querier reads by name.
const (
PatternsColumnPattern = "__pattern"
PatternsColumnID = "__pattern_id"
PatternsColumnSampledCount = "__sampled_count"
PatternsColumnSampleRate = "__sample_rate"
PatternsColumnTotal = "__total"
PatternsColumnTrendTs = "__trend_ts"
PatternsColumnTrendCounts = "__trend_counts"
)
// PatternsData is the log patterns of one logs query.
type PatternsData struct {
QueryName string `json:"queryName" required:"true" description:"The name of the query that produced this result."`
SampleRate uint64 `json:"sampleRate" required:"true" description:"One in sampleRate of the matching logs was read and every count is scaled up by it. 1 means every log was read and the counts are exact."`
Total uint64 `json:"total" required:"true" description:"The number of matching logs that have a pattern, over every pattern."`
Patterns []*Pattern `json:"patterns" required:"true" description:"The patterns, most logs first."`
}
type Pattern struct {
ID string `json:"id" required:"true" description:"The pattern's ID: the decimal 64-bit FNV-1a hash of its template."`
Pattern string `json:"pattern" required:"true" description:"The pattern's template: the log message with the values that change replaced by <*>. Empty when the template is not known yet."`
Count uint64 `json:"count" required:"true" description:"The number of logs of the pattern in the time range, scaled up by sampleRate."`
Percent float64 `json:"percent" required:"true" description:"The pattern's count as a percentage of total."`
Trend []*PatternTrendPoint `json:"trend" required:"true" description:"The number of logs of the pattern in each step of the time range, oldest first. Steps without a log are left out."`
}
type PatternTrendPoint struct {
Timestamp int64 `json:"timestamp" required:"true" description:"The Unix time in milliseconds the step starts at."`
Count uint64 `json:"count" required:"true" description:"The number of logs of the pattern in the step, scaled up by sampleRate."`
}

View File

@@ -607,6 +607,10 @@ func (r *QueryRangeRequest) Validate(opts ...ValidationOption) error {
return err
}
if err := r.validatePatterns(); err != nil {
return err
}
// raw/trace request types don't support metric queries;
// metrics are always aggregated and there is no raw form.
if r.RequestType == RequestTypeRaw || r.RequestType == RequestTypeRawStream || r.RequestType == RequestTypeTrace {
@@ -651,6 +655,10 @@ func (r *QueryRangeRequest) ValidateRequestScope() ([]ValidationOption, error) {
return nil, err
}
if err := r.validatePatterns(); err != nil {
return nil, err
}
if r.RequestType == RequestTypeRaw || r.RequestType == RequestTypeRawStream || r.RequestType == RequestTypeTrace {
for _, envelope := range r.CompositeQuery.Queries {
if envelope.GetSignal() == telemetrytypes.SignalMetrics {
@@ -882,6 +890,45 @@ func validateQueryEnvelope(envelope QueryEnvelope, opts ...ValidationOption) err
}
}
// PatternsMaxLimit is the most patterns a pattern request returns.
const PatternsMaxLimit = 1000
// validatePatterns checks a pattern request: one enabled logs builder query,
// which the request counts by pattern itself, so it takes no aggregation,
// having, or function.
func (r *QueryRangeRequest) validatePatterns() error {
if r.RequestType != RequestTypePattern {
return nil
}
if len(r.CompositeQuery.Queries) != 1 {
return errors.NewInvalidInputf(errors.CodeInvalidInput,
"pattern requests take exactly one logs builder query, got %d queries", len(r.CompositeQuery.Queries))
}
envelope := r.CompositeQuery.Queries[0]
spec, ok := envelope.Spec.(QueryBuilderQuery[LogAggregation])
if !ok || envelope.Type != QueryTypeBuilder || spec.Signal != telemetrytypes.SignalLogs {
return errors.NewInvalidInputf(errors.CodeInvalidInput,
"pattern requests support only a logs builder query, got %q", envelope.Type.StringValue())
}
switch {
case spec.Disabled:
return errors.NewInvalidInputf(errors.CodeInvalidInput, "the query of a pattern request can't be disabled")
case len(spec.Aggregations) > 0:
return errors.NewInvalidInputf(errors.CodeInvalidInput,
"pattern requests count the logs of each pattern themselves, so the query takes no aggregations")
case spec.Having != nil && spec.Having.Expression != "":
return errors.NewInvalidInputf(errors.CodeInvalidInput, "pattern requests don't support having")
case len(spec.Functions) > 0:
return errors.NewInvalidInputf(errors.CodeInvalidInput, "pattern requests don't support functions")
case len(spec.GroupBy) > 0:
return errors.NewInvalidInputf(errors.CodeInvalidInput, "pattern requests don't support group by")
case spec.Limit > PatternsMaxLimit:
return errors.NewInvalidInputf(errors.CodeInvalidInput,
"pattern requests return at most %d patterns, got limit %d", PatternsMaxLimit, spec.Limit)
}
return nil
}
func (r *QueryRangeRequest) validateBucketCounting() error {
if !r.RequestType.CountsIntoBuckets() {
for _, envelope := range r.CompositeQuery.Queries {
@@ -1142,6 +1189,8 @@ func GetValidationOptions(requestType RequestType) []ValidationOption {
return []ValidationOption{WithSkipSelectFieldValidation(), WithReduceToValidation()}
case RequestTypeRaw, RequestTypeRawStream, RequestTypeTrace:
return []ValidationOption{WithSkipAggregationValidation(), WithSkipHavingValidation(), WithSkipAggregationOrderBy(), WithSkipGroupByValidation()}
case RequestTypePattern:
return []ValidationOption{WithSkipAggregationValidation(), WithSkipHavingValidation(), WithSkipAggregationOrderBy(), WithSkipSelectFieldValidation()}
default:
return []ValidationOption{}
}

View File

@@ -1461,7 +1461,7 @@ func TestRequestType_IsAggregation(t *testing.T) {
}
func TestQueryRangeRequest_ValidateRequestType(t *testing.T) {
validRequestTypes := []string{"valid request types are `scalar`, `time_series`, `raw`, `raw_stream`, `trace`, `heatmap`, `distribution`"}
validRequestTypes := []string{"valid request types are `scalar`, `time_series`, `raw`, `raw_stream`, `trace`, `heatmap`, `pattern`, `distribution`"}
testCases := []struct {
name string
@@ -1771,3 +1771,38 @@ func TestValidateBucketCountingFormulaInputs(t *testing.T) {
})
}
}
func TestValidatePatterns(t *testing.T) {
logsQuery := func(mutate func(*QueryBuilderQuery[LogAggregation])) QueryEnvelope {
spec := QueryBuilderQuery[LogAggregation]{Name: "A", Signal: telemetrytypes.SignalLogs}
mutate(&spec)
return QueryEnvelope{Type: QueryTypeBuilder, Spec: spec}
}
testCases := []struct {
name string
queries []QueryEnvelope
expectedErr string
}{
{name: "OneLogsQuery_Valid", queries: []QueryEnvelope{logsQuery(func(*QueryBuilderQuery[LogAggregation]) {})}},
{name: "TwoQueries_Rejected", queries: []QueryEnvelope{logsQuery(func(*QueryBuilderQuery[LogAggregation]) {}), logsQuery(func(q *QueryBuilderQuery[LogAggregation]) { q.Name = "B" })}, expectedErr: "exactly one logs builder query"},
{name: "Aggregation_Rejected", queries: []QueryEnvelope{logsQuery(func(q *QueryBuilderQuery[LogAggregation]) { q.Aggregations = []LogAggregation{{Expression: "count()"}} })}, expectedErr: "takes no aggregations"},
{name: "GroupBy_Rejected", queries: []QueryEnvelope{logsQuery(func(q *QueryBuilderQuery[LogAggregation]) {
q.GroupBy = []GroupByKey{{TelemetryFieldKey: telemetrytypes.TelemetryFieldKey{Name: "service.name"}}}
})}, expectedErr: "don't support group by"},
{name: "LimitAboveMax_Rejected", queries: []QueryEnvelope{logsQuery(func(q *QueryBuilderQuery[LogAggregation]) { q.Limit = PatternsMaxLimit + 1 })}, expectedErr: "at most 1000 patterns"},
}
for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {
req := &QueryRangeRequest{RequestType: RequestTypePattern, CompositeQuery: CompositeQuery{Queries: testCase.queries}}
err := req.validatePatterns()
if testCase.expectedErr == "" {
assert.NoError(t, err)
return
}
require.Error(t, err)
assert.Contains(t, err.Error(), testCase.expectedErr)
})
}
}

View File

@@ -111,6 +111,8 @@ func (v *variableReplacementVisitor) Visit(tree antlr.ParseTree) any {
return v.VisitFullText(t)
case *grammar.SearchCallContext:
return v.VisitSearchCall(t)
case *grammar.PatternCallContext:
return v.VisitPatternCall(t)
case *grammar.FunctionCallContext:
return v.VisitFunctionCall(t)
case *grammar.FunctionParamListContext:
@@ -207,6 +209,8 @@ func (v *variableReplacementVisitor) VisitPrimary(ctx *grammar.PrimaryContext) a
return v.Visit(ctx.FunctionCall())
} else if ctx.SearchCall() != nil {
return v.Visit(ctx.SearchCall())
} else if ctx.PatternCall() != nil {
return v.Visit(ctx.PatternCall())
} else if ctx.FullText() != nil {
return v.Visit(ctx.FullText())
}
@@ -423,6 +427,18 @@ func (v *variableReplacementVisitor) VisitSearchCall(ctx *grammar.SearchCallCont
return "search" + result
}
func (v *variableReplacementVisitor) VisitPatternCall(ctx *grammar.PatternCallContext) any {
if ctx.ValueList() == nil {
return "pattern()"
}
// VisitValueList already parenthesizes the args and propagates the __all__ marker.
result := v.Visit(ctx.ValueList()).(string)
if result == specialSkipMarker {
return specialSkipMarker
}
return "pattern" + result
}
func (v *variableReplacementVisitor) VisitFunctionParamList(ctx *grammar.FunctionParamListContext) any {
params := ctx.AllFunctionParam()
parts := make([]string, 0, len(params))