Skip to content

CAE-193: add "IGNORE" options to time series commands (for v5 branch) #2753

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions packages/time-series/lib/commands/ADD.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,44 @@ describe('TS.ADD', () => {
);
});

it('with RETENTION, ENCODING, CHUNK_SIZE, ON_DUPLICATE, LABELS', () => {
it('with IGNORE no values', () => {
assert.deepEqual(
ADD.transformArguments('key', '*', 1, {
IGNORE: { }
}),
['TS.ADD', 'key', '*', '1', 'IGNORE', '0', '0']
)
});

it('with IGNORE with MAX_TIME_DIFF', () => {
assert.deepEqual(
ADD.transformArguments('key', '*', 1, {
IGNORE: { MAX_TIME_DIFF: 1}
}),
['TS.ADD', 'key', '*', '1', 'IGNORE', '1', '0']
)
});

it('with IGNORE with MAX_VAL_DIFF', () => {
assert.deepEqual(
ADD.transformArguments('key', '*', 1, {
IGNORE: { MAX_VAL_DIFF: 1}
}),
['TS.ADD', 'key', '*', '1', 'IGNORE', '0', '1']
)
});

it('with RETENTION, ENCODING, CHUNK_SIZE, ON_DUPLICATE, LABELS, IGNORE', () => {
assert.deepEqual(
ADD.transformArguments('key', '*', 1, {
RETENTION: 1,
ENCODING: TIME_SERIES_ENCODING.UNCOMPRESSED,
CHUNK_SIZE: 1,
ON_DUPLICATE: TIME_SERIES_DUPLICATE_POLICIES.BLOCK,
LABELS: { label: 'value' }
LABELS: { label: 'value' },
IGNORE: { MAX_TIME_DIFF: 1, MAX_VAL_DIFF: 1}
}),
['TS.ADD', 'key', '*', '1', 'RETENTION', '1', 'ENCODING', 'UNCOMPRESSED', 'CHUNK_SIZE', '1', 'ON_DUPLICATE', 'BLOCK', 'LABELS', 'label', 'value']
['TS.ADD', 'key', '*', '1', 'RETENTION', '1', 'ENCODING', 'UNCOMPRESSED', 'CHUNK_SIZE', '1', 'ON_DUPLICATE', 'BLOCK', 'LABELS', 'label', 'value', 'IGNORE', '1', '1']
);
});
});
Expand Down
6 changes: 6 additions & 0 deletions packages/time-series/lib/commands/ADD.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,18 @@ import {
Timestamp
} from '.';

export interface TsIgnoreOptions {
MAX_TIME_DIFF: number;
MAX_VAL_DIFF: number;
}

export interface TsAddOptions {
RETENTION?: number;
ENCODING?: TimeSeriesEncoding;
CHUNK_SIZE?: number;
ON_DUPLICATE?: TimeSeriesDuplicatePolicies;
LABELS?: Labels;
IGNORE?: TsIgnoreOptions;
}

export default {
Expand Down
34 changes: 31 additions & 3 deletions packages/time-series/lib/commands/ALTER.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,43 @@ describe('TS.ALTER', () => {
);
});

it('with RETENTION, CHUNK_SIZE, DUPLICATE_POLICY, LABELS', () => {
it('with IGNORE no values', () => {
assert.deepEqual(
ALTER.transformArguments('key', {
IGNORE: { }
}),
['TS.ALTER', 'key', 'IGNORE', '0', '0']
)
});

it('with IGNORE with MAX_TIME_DIFF', () => {
assert.deepEqual(
ALTER.transformArguments('key', {
IGNORE: { MAX_TIME_DIFF: 1}
}),
['TS.ALTER', 'key', 'IGNORE', '1', '0']
)
});

it('with IGNORE with MAX_VAL_DIFF', () => {
assert.deepEqual(
ALTER.transformArguments('key', {
IGNORE: { MAX_VAL_DIFF: 1}
}),
['TS.ALTER', 'key', 'IGNORE', '0', '1']
)
});

it('with RETENTION, CHUNK_SIZE, DUPLICATE_POLICY, LABELS, IGNORE', () => {
assert.deepEqual(
ALTER.transformArguments('key', {
RETENTION: 1,
CHUNK_SIZE: 1,
DUPLICATE_POLICY: TIME_SERIES_DUPLICATE_POLICIES.BLOCK,
LABELS: { label: 'value' }
LABELS: { label: 'value' },
IGNORE: { MAX_TIME_DIFF: 1, MAX_VAL_DIFF: 1}
}),
['TS.ALTER', 'key', 'RETENTION', '1', 'CHUNK_SIZE', '1', 'DUPLICATE_POLICY', 'BLOCK', 'LABELS', 'label', 'value']
['TS.ALTER', 'key', 'RETENTION', '1', 'CHUNK_SIZE', '1', 'DUPLICATE_POLICY', 'BLOCK', 'LABELS', 'label', 'value', 'IGNORE', '1', '1']
);
});
});
Expand Down
6 changes: 4 additions & 2 deletions packages/time-series/lib/commands/ALTER.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { RedisArgument, SimpleStringReply, Command } from '@redis/client/dist/lib/RESP/types';
import { TsCreateOptions } from './CREATE';
import { pushRetentionArgument, pushChunkSizeArgument, pushDuplicatePolicy, pushLabelsArgument } from '.';
import { pushRetentionArgument, pushChunkSizeArgument, pushDuplicatePolicy, pushLabelsArgument, pushIgnoreArgument } from '.';

export type TsAlterOptions = Pick<TsCreateOptions, 'RETENTION' | 'CHUNK_SIZE' | 'DUPLICATE_POLICY' | 'LABELS'>;
export type TsAlterOptions = Pick<TsCreateOptions, 'RETENTION' | 'CHUNK_SIZE' | 'DUPLICATE_POLICY' | 'LABELS' | 'IGNORE'>;

export default {
FIRST_KEY_INDEX: 1,
Expand All @@ -18,6 +18,8 @@ export default {

pushLabelsArgument(args, options?.LABELS);

pushIgnoreArgument(args, options?.IGNORE);

return args;
},
transformReply: undefined as unknown as () => SimpleStringReply<'OK'>
Expand Down
34 changes: 31 additions & 3 deletions packages/time-series/lib/commands/CREATE.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,44 @@ describe('TS.CREATE', () => {
);
});

it('with RETENTION, ENCODING, CHUNK_SIZE, DUPLICATE_POLICY, LABELS', () => {
it('with IGNORE no values', () => {
assert.deepEqual(
CREATE.transformArguments('key', {
IGNORE: { }
}),
['TS.CREATE', 'key', 'IGNORE', '0', '0']
)
});

it('with IGNORE with MAX_TIME_DIFF', () => {
assert.deepEqual(
CREATE.transformArguments('key', {
IGNORE: { MAX_TIME_DIFF: 1}
}),
['TS.CREATE', 'IGNORE', '1', '0']
)
});

it('with IGNORE with MAX_VAL_DIFF', () => {
assert.deepEqual(
CREATE.transformArguments('key', {
IGNORE: { MAX_VAL_DIFF: 1}
}),
['TS.CREATE', 'IGNORE', '0', '1']
)
});

it('with RETENTION, ENCODING, CHUNK_SIZE, DUPLICATE_POLICY, LABELS, IGNORE', () => {
assert.deepEqual(
CREATE.transformArguments('key', {
RETENTION: 1,
ENCODING: TIME_SERIES_ENCODING.UNCOMPRESSED,
CHUNK_SIZE: 1,
DUPLICATE_POLICY: TIME_SERIES_DUPLICATE_POLICIES.BLOCK,
LABELS: { label: 'value' }
LABELS: { label: 'value' },
IGNORE: { MAX_TIME_DIFF: 1, MAX_VAL_DIFF: 1}
}),
['TS.CREATE', 'key', 'RETENTION', '1', 'ENCODING', 'UNCOMPRESSED', 'CHUNK_SIZE', '1', 'DUPLICATE_POLICY', 'BLOCK', 'LABELS', 'label', 'value']
['TS.CREATE', 'key', 'RETENTION', '1', 'ENCODING', 'UNCOMPRESSED', 'CHUNK_SIZE', '1', 'DUPLICATE_POLICY', 'BLOCK', 'LABELS', 'label', 'value', 'IGNORE', '1', '1']
);
});
});
Expand Down
7 changes: 6 additions & 1 deletion packages/time-series/lib/commands/CREATE.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@ import {
TimeSeriesDuplicatePolicies,
pushDuplicatePolicy,
Labels,
pushLabelsArgument
pushLabelsArgument,
pushIgnoreArgument
} from '.';
import { TsIgnoreOptions } from './ADD';

export interface TsCreateOptions {
RETENTION?: number;
ENCODING?: TimeSeriesEncoding;
CHUNK_SIZE?: number;
DUPLICATE_POLICY?: TimeSeriesDuplicatePolicies;
LABELS?: Labels;
IGNORE?: TsIgnoreOptions;
}

export default {
Expand All @@ -34,6 +37,8 @@ export default {

pushLabelsArgument(args, options?.LABELS);

pushIgnoreArgument(args, options?.IGNORE);

return args;
},
transformReply: undefined as unknown as () => SimpleStringReply<'OK'>
Expand Down
12 changes: 11 additions & 1 deletion packages/time-series/lib/commands/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { BlobStringReply, CommandArguments, DoubleReply, NumberReply, RedisArgument, RedisCommands, TuplesReply, UnwrapReply } from '@redis/client/dist/lib/RESP/types';
import ADD from './ADD';
import ADD, { TsIgnoreOptions } from './ADD';
import ALTER from './ALTER';
import CREATE from './CREATE';
import CREATERULE from './CREATERULE';
Expand Down Expand Up @@ -67,6 +67,16 @@ export default {
revRange: REVRANGE
} as const satisfies RedisCommands;

export function pushIgnoreArgument(args: Array<RedisArgument>, ignore?: TsIgnoreOptions) {
if (ignore !== undefined) {
args.push(
'IGNORE',
ignore.MAX_TIME_DIFF ? ignore.MAX_TIME_DIFF.toString() : '0',
ignore.MAX_VAL_DIFF ? ignore.MAX_VAL_DIFF.toString() : '0'
)
}
}

export function pushRetentionArgument(args: Array<RedisArgument>, retention?: number) {
if (retention !== undefined) {
args.push('RETENTION', retention.toString());
Expand Down