Skip to content

Commit

Permalink
fix: fixing key-value after adding version (#3093)
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe-lyons authored Aug 13, 2021
1 parent 01bc0e8 commit c13d83b
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import translateFieldPath from '../schema/utils/translateFieldPath';
import translateFieldPath from '../../schema/utils/translateFieldPath';

describe('translateFieldPath', () => {
it('translates qualified unions', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import translateFieldPathSegment from '../schema/utils/translateFieldPathSegment';
import translateFieldPathSegment from '../../schema/utils/translateFieldPathSegment';

describe('translateFieldPathSegment', () => {
it('translates unions', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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],
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
19 changes: 17 additions & 2 deletions metadata-ingestion/examples/mce_files/bootstrap_mce.json
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@
},
"fields": [
{
"fieldPath": "field_foo_2",
"fieldPath": "[version=2.0].[type=boolean].field_foo_2",
"jsonPath": null,
"nullable": false,
"description": {
Expand All @@ -224,7 +224,7 @@
"recursive": false
},
{
"fieldPath": "field_bar",
"fieldPath": "[version=2.0].[type=boolean].field_bar",
"jsonPath": null,
"nullable": false,
"description": {
Expand All @@ -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,
Expand Down

0 comments on commit c13d83b

Please sign in to comment.