fix: fixing key-value after adding version (#3093)

This commit is contained in:
Gabe Lyons 2021-08-12 17:52:58 -07:00 committed by GitHub
parent 01bc0e8e4c
commit c13d83b5c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 70 additions and 6 deletions

View File

@ -1,4 +1,4 @@
import translateFieldPath from '../schema/utils/translateFieldPath';
import translateFieldPath from '../../schema/utils/translateFieldPath';
describe('translateFieldPath', () => {
it('translates qualified unions', () => {

View File

@ -1,4 +1,4 @@
import translateFieldPathSegment from '../schema/utils/translateFieldPathSegment';
import translateFieldPathSegment from '../../schema/utils/translateFieldPathSegment';
describe('translateFieldPathSegment', () => {
it('translates unions', () => {

View File

@ -0,0 +1,49 @@
import { SchemaFieldDataType } from '../../../../../../types.generated';
import { filterKeyFieldPath } from '../../schema/utils/utils';
describe('utils', () => {
describe('filterKeyFieldPath', () => {
it('allows keys when looking for keys', () => {
expect(
filterKeyFieldPath(true, {
fieldPath: '[version=2.0].[key=True].[type=long].field',
nullable: false,
type: SchemaFieldDataType.Number,
recursive: false,
}),
).toEqual(true);
});
it('blocks non-keys when looking for keys', () => {
expect(
filterKeyFieldPath(true, {
fieldPath: '[version=2.0].[type=long].field',
nullable: false,
type: SchemaFieldDataType.Number,
recursive: false,
}),
).toEqual(false);
});
it('allows non-keys when looking for non-keys', () => {
expect(
filterKeyFieldPath(false, {
fieldPath: '[version=2.0].[type=long].field',
nullable: false,
type: SchemaFieldDataType.Number,
recursive: false,
}),
).toEqual(true);
});
it('blocks keys when looking for non-keys', () => {
expect(
filterKeyFieldPath(false, {
fieldPath: '[version=2.0].[key=True].[type=long].field',
nullable: false,
type: SchemaFieldDataType.Number,
recursive: false,
}),
).toEqual(false);
});
});
});

View File

@ -64,7 +64,7 @@ export default function SchemaView({
});
const hasKeySchema = useMemo(
() => (schema?.fields?.findIndex((field) => field.fieldPath.startsWith(KEY_SCHEMA_PREFIX)) || -1) !== -1,
() => (schema?.fields?.findIndex((field) => field.fieldPath.indexOf(KEY_SCHEMA_PREFIX) > -1) || -1) !== -1,
[schema],
);

View File

@ -46,7 +46,7 @@ export function convertEditableSchemaMetadataForUpdate(
}
export function filterKeyFieldPath(showKeySchema: boolean, field: SchemaField) {
return field.fieldPath.startsWith(KEY_SCHEMA_PREFIX) ? showKeySchema : !showKeySchema;
return field.fieldPath.indexOf(KEY_SCHEMA_PREFIX) > -1 ? showKeySchema : !showKeySchema;
}
export function downgradeV2FieldPath(fieldPath?: string | null) {

View File

@ -206,7 +206,7 @@
},
"fields": [
{
"fieldPath": "field_foo_2",
"fieldPath": "[version=2.0].[type=boolean].field_foo_2",
"jsonPath": null,
"nullable": false,
"description": {
@ -224,7 +224,7 @@
"recursive": false
},
{
"fieldPath": "field_bar",
"fieldPath": "[version=2.0].[type=boolean].field_bar",
"jsonPath": null,
"nullable": false,
"description": {
@ -237,6 +237,21 @@
},
"nativeDataType": "boolean",
"recursive": false
},
{
"fieldPath": "[version=2.0].[key=True].[type=int].id",
"jsonPath": null,
"nullable": false,
"description": {
"string": "Id specifying which partition the message should go to"
},
"type": {
"type": {
"com.linkedin.pegasus2avro.schema.BooleanType": {}
}
},
"nativeDataType": "boolean",
"recursive": false
}
],
"primaryKeys": null,