Skip to content

Commit

Permalink
CAE-193: add "IGNORE" options to time series commands (for v4 branch) (
Browse files Browse the repository at this point in the history
  • Loading branch information
sjpotter authored Jul 10, 2024
1 parent a1bee1c commit 5576a0d
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 11 deletions.
16 changes: 13 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,26 @@ describe('ADD', () => {
);
});

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

it('with RETENTION, ENCODING, CHUNK_SIZE, ON_DUPLICATE, LABELS, IGNORE', () => {
assert.deepEqual(
transformArguments('key', '*', 1, {
RETENTION: 1,
ENCODING: TimeSeriesEncoding.UNCOMPRESSED,
CHUNK_SIZE: 1,
ON_DUPLICATE: TimeSeriesDuplicatePolicies.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
9 changes: 9 additions & 0 deletions packages/time-series/lib/commands/ADD.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,21 @@ import {
Labels,
pushLabelsArgument,
Timestamp,
pushIgnoreArgument,
} from '.';

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

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

export const FIRST_KEY_INDEX = 1;
Expand All @@ -40,6 +47,8 @@ export function transformArguments(key: string, timestamp: Timestamp, value: num

pushLabelsArgument(args, options?.LABELS);

pushIgnoreArgument(args, options?.IGNORE);

return args;
}

Expand Down
16 changes: 13 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,25 @@ describe('ALTER', () => {
);
});

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

it('with RETENTION, CHUNK_SIZE, DUPLICATE_POLICY, LABELS, IGNORE', () => {
assert.deepEqual(
transformArguments('key', {
RETENTION: 1,
CHUNK_SIZE: 1,
DUPLICATE_POLICY: TimeSeriesDuplicatePolicies.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: 5 additions & 1 deletion packages/time-series/lib/commands/ALTER.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { pushRetentionArgument, Labels, pushLabelsArgument, TimeSeriesDuplicatePolicies, pushChunkSizeArgument, pushDuplicatePolicy } from '.';
import { pushRetentionArgument, Labels, pushLabelsArgument, TimeSeriesDuplicatePolicies, pushChunkSizeArgument, pushDuplicatePolicy, pushIgnoreArgument } from '.';
import { TsIgnoreOptions } from './ADD';

export const FIRST_KEY_INDEX = 1;

Expand All @@ -7,6 +8,7 @@ interface AlterOptions {
CHUNK_SIZE?: number;
DUPLICATE_POLICY?: TimeSeriesDuplicatePolicies;
LABELS?: Labels;
IGNORE?: TsIgnoreOptions;
}

export function transformArguments(key: string, options?: AlterOptions): Array<string> {
Expand All @@ -20,6 +22,8 @@ export function transformArguments(key: string, options?: AlterOptions): Array<s

pushLabelsArgument(args, options?.LABELS);

pushIgnoreArgument(args, options?.IGNORE);

return args;
}

Expand Down
16 changes: 13 additions & 3 deletions packages/time-series/lib/commands/CREATE.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,27 @@ describe('CREATE', () => {
['TS.CREATE', 'key', 'LABELS', 'label', 'value']
);
});

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

it('with RETENTION, ENCODING, CHUNK_SIZE, DUPLICATE_POLICY, LABELS', () => {
it('with RETENTION, ENCODING, CHUNK_SIZE, DUPLICATE_POLICY, LABELS, IGNORE', () => {
assert.deepEqual(
transformArguments('key', {
RETENTION: 1,
ENCODING: TimeSeriesEncoding.UNCOMPRESSED,
CHUNK_SIZE: 1,
DUPLICATE_POLICY: TimeSeriesDuplicatePolicies.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 @@ -6,8 +6,10 @@ import {
TimeSeriesDuplicatePolicies,
Labels,
pushLabelsArgument,
pushDuplicatePolicy
pushDuplicatePolicy,
pushIgnoreArgument
} from '.';
import { TsIgnoreOptions } from './ADD';

export const FIRST_KEY_INDEX = 1;

Expand All @@ -17,6 +19,7 @@ interface CreateOptions {
CHUNK_SIZE?: number;
DUPLICATE_POLICY?: TimeSeriesDuplicatePolicies;
LABELS?: Labels;
IGNORE?: TsIgnoreOptions;
}

export function transformArguments(key: string, options?: CreateOptions): Array<string> {
Expand All @@ -32,6 +35,8 @@ export function transformArguments(key: string, options?: CreateOptions): Array<

pushLabelsArgument(args, options?.LABELS);

pushIgnoreArgument(args, options?.IGNORE);

return args;
}

Expand Down
6 changes: 6 additions & 0 deletions packages/time-series/lib/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ export function transformTimestampArgument(timestamp: Timestamp): string {
).toString();
}

export function pushIgnoreArgument(args: RedisCommandArguments, ignore?: ADD.TsIgnoreOptions) {
if (ignore !== undefined) {
args.push('IGNORE', ignore.MAX_TIME_DIFF.toString(), ignore.MAX_VAL_DIFF.toString());
}
}

export function pushRetentionArgument(args: RedisCommandArguments, retention?: number): RedisCommandArguments {
if (retention !== undefined) {
args.push(
Expand Down

0 comments on commit 5576a0d

Please sign in to comment.