Skip to content
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

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

Open
wants to merge 3 commits into
base: v5
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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: { }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is "IGNORE no values" supported? (RedisTimeSeries/RedisTimeSeries#1543)
If it is - add support for IGNORE: true for this case

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see what I wrote below

}),
['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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is "IGNORE no values" supported? (RedisTimeSeries/RedisTimeSeries#1543)
If it is - both MAX_TIME_DIFF and MAX_VAL_DIFF should be optional..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't seem like it, from code

int parseIgnoreArgs(RedisModuleCtx *ctx,
                    RedisModuleString **argv,
                    int argc,
                    long long int *ignoreMaxTimeDiff,
                    double *ignoreMaxValDiff) {
    int idx = RMUtil_ArgIndex("IGNORE", argv, argc);
    if (idx > 0) {
        long long maxTimeDiff;
        double maxValDiff;

        if (idx + 2 >= argc ||
            RMUtil_ParseArgs(argv, argc, idx + 1, "ld", &maxTimeDiff, &maxValDiff) !=
                REDISMODULE_OK) {
            RTS_ReplyGeneralError(ctx, "TSDB: Couldn't parse IGNORE");
            return TSDB_ERROR;
        }

        if (maxTimeDiff < 0 || maxValDiff < 0) {
            RTS_ReplyGeneralError(ctx, "TSDB: IGNORE arguments cannot be negative");
            return TSDB_ERROR;
        }

        *ignoreMaxTimeDiff = maxTimeDiff;
        *ignoreMaxValDiff = maxValDiff;
    }

    return TSDB_OK;
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So if not, why MAX_TIME_DIFF and MAX_VAL_DIFF are optional? also, rename them to maxTimeDiff and maxValDiff to match the command interface.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made the optional to not requiring a user to set them to 0, if left off, treated as 0. can require them and simplify the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we want to require the user to specify them as 0, I'm good with that as well

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the server does not have defaults we shouldn't as well..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, pushed and done.

}

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