Skip to content

Commit

Permalink
feat(#3054): Change delimiter for nested property structure (#3143)
Browse files Browse the repository at this point in the history
* feat(#3054): Change delimiter for nested property structure

* feat(#3054): Fix unit tests
  • Loading branch information
tenthe authored Aug 16, 2024
1 parent 76a84a3 commit c15b157
Show file tree
Hide file tree
Showing 12 changed files with 97 additions and 309 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void visit(DeleteRuleDescription rule) {

@Override
public void visit(MoveRuleDescription rule) {
var targetRuntimeKey = rule.getNewRuntimeKey() + "." + rule.getOldRuntimeKey();
var targetRuntimeKey = rule.getNewRuntimeKey() + Utils.DELIMITER + rule.getOldRuntimeKey();
var existing = new Cloner().property(findProperty(properties, targetRuntimeKey));
var existingHierarchy = findPropertyHierarchy(this.properties, targetRuntimeKey);
existingHierarchy.removeIf(property -> property.getRuntimeName().equals(existing.getRuntimeName()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@

public class Utils {

public static final String DELIMITER = "<-=>";

public static String getLastKey(String s) {
String[] list = s.split("\\.");
String[] list = s.split(DELIMITER);
if (list.length == 0) {
return s;
} else {
Expand All @@ -36,7 +38,7 @@ public static String getLastKey(String s) {
}

public static List<String> toKeyArray(String s) {
String[] split = s.split("\\.");
String[] split = s.split(DELIMITER);
if (split.length == 0) {
return List.of(s);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@

public class ToOriginalSchemaConverterTest {

private static final String NESTED_DELIMITER = "<-=>";

@Test
public void testSimpleUnitConversion() {
List<EventProperty> properties = makeSimpleProperties(true);
Expand All @@ -60,10 +62,11 @@ public void testNestedUnitConversion() {

var rules = new ArrayList<TransformationRuleDescription>();

rules.add(makeUnitTransformationRule("nested.stringProp"));
rules.add(makeUnitTransformationRule("nested" + NESTED_DELIMITER + "stringProp"));

var resultProperties = executeAndReturnResult(properties, rules);
var nestedResultProperty = ((EventPropertyNested) resultProperties.get(1)).getEventProperties().get(0);
var nestedResultProperty = ((EventPropertyNested) resultProperties.get(1)).getEventProperties()
.get(0);

Assertions.assertEquals(2, resultProperties.size());
Assertions.assertEquals("originalUnit", getUnit(nestedResultProperty));
Expand All @@ -73,18 +76,25 @@ public void testNestedUnitConversion() {
public void testSimpleMoveConversion() {
List<EventProperty> properties = makeNestedProperties();
var nestedProperty = ((EventPropertyNested) properties.get(1));
nestedProperty.getEventProperties().add(EpProperties.stringEp(Labels.empty(), "epToBeMoved", ""));
nestedProperty.getEventProperties()
.add(EpProperties.stringEp(Labels.empty(), "epToBeMoved", ""));

var rules = new ArrayList<TransformationRuleDescription>();

rules.add(makeMoveTransformationRule("epToBeMoved", "nested"));

var result = executeAndReturnResult(properties, rules);
Assertions.assertEquals(3, result.size());
Assertions.assertEquals("timestamp",
result.get(0).getRuntimeName());
Assertions.assertEquals(2,
((EventPropertyNested) result.get(1)).getEventProperties().size());
Assertions.assertEquals(
"timestamp",
result.get(0)
.getRuntimeName()
);
Assertions.assertEquals(
2,
((EventPropertyNested) result.get(1)).getEventProperties()
.size()
);
}

@Test
Expand All @@ -95,12 +105,17 @@ public void testDeleteRule() {
rules.add(makeDeleteTransformationRule("epToBeRestored"));
var result = executeAndReturnResult(properties, rules);
Assertions.assertEquals(4, result.size());
Assertions.assertEquals("epToBeRestored",
result.get(3).getRuntimeName());
Assertions.assertEquals(
"epToBeRestored",
result.get(3)
.getRuntimeName()
);
}

private List<EventProperty> executeAndReturnResult(List<EventProperty> properties,
List<TransformationRuleDescription> rules) {
private List<EventProperty> executeAndReturnResult(
List<EventProperty> properties,
List<TransformationRuleDescription> rules
) {
var result = new SchemaConverter().toOriginalSchema(new EventSchema(properties), rules);
return result.getEventProperties();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public void testNestedUnitConversion() {

var rules = new ArrayList<TransformationRuleDescription>();

rules.add(makeUnitTransformationRule("nested.stringProp"));
rules.add(makeUnitTransformationRule("nested<-=>stringProp"));

var resultProperties = executeAndReturnResult(properties, rules);
var nestedResultProperty = ((EventPropertyNested) resultProperties.get(1)).getEventProperties().get(0);
Expand Down
4 changes: 2 additions & 2 deletions ui/cypress/fixtures/connect/schemaRules/expected.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
count;staticPropertyName;temperature
122.0;id1;11.0
count;dot;staticPropertyName;temperature
122.0;special_char_in_column_name;id1;11.0
4 changes: 2 additions & 2 deletions ui/cypress/fixtures/connect/schemaRules/input.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
timestamp;count;density;temperature
1720018277000;122.0;62.0;11
timestamp;count;density;temperature;contains.dot
1720018277000;122.0;62.0;11;special_char_in_column_name
6 changes: 6 additions & 0 deletions ui/cypress/support/utils/connect/ConnectBtns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ export class ConnectBtns {
});
}

public static runtimeNameInput() {
return cy.dataCy('connect-edit-field-runtime-name', {
timeout: 10000,
});
}

// ========================================================================

// ===================== Format configurations ==========================
Expand Down
39 changes: 33 additions & 6 deletions ui/cypress/support/utils/connect/ConnectEventSchemaUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,26 @@ export class ConnectEventSchemaUtils {
cy.dataCy('sp-save-edit-property').click();
}

public static renameProperty(
fromRuntimeName: string,
toRuntimeName: string,
) {
ConnectEventSchemaUtils.clickEditProperty(fromRuntimeName);
ConnectEventSchemaUtils.setRuntimeName(toRuntimeName);
ConnectBtns.saveEditProperty().click();
}

public static setRuntimeName(newRuntimeName: string) {
ConnectBtns.runtimeNameInput().clear().type(newRuntimeName);
}

public static validateRuntimeName(expectedRuntimeName: string) {
ConnectBtns.runtimeNameInput().should(
'have.value',
expectedRuntimeName,
);
}

public static unitTransformation(
propertyName: string,
fromUnit: string,
Expand Down Expand Up @@ -244,13 +264,20 @@ export class ConnectEventSchemaUtils {
}

public static clickEditProperty(propertyName: string) {
cy.dataCy('edit-' + propertyName.toLowerCase(), {
cy.dataCy(`edit-${ConnectEventSchemaUtils.escape(propertyName)}`, {
timeout: 10000,
}).click();
cy.dataCy('connect-edit-field-runtime-name').should(
'have.value',
propertyName,
{ timeout: 10000 },
);
ConnectEventSchemaUtils.validateRuntimeName(propertyName);
}

//
/**
* Function to escape special characters in a string for use in Cypress
* selectors
*/
public static escape(selector: string): string {
return selector
.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, '\\$1')
.toLowerCase();
}
}
13 changes: 5 additions & 8 deletions ui/cypress/tests/connect/editAdapterValuesAndFields.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import { ConnectUtils } from '../../support/utils/connect/ConnectUtils';
import { ConnectBtns } from '../../support/utils/connect/ConnectBtns';
import { AdapterBuilder } from '../../support/builder/AdapterBuilder';
import { ConnectEventSchemaUtils } from '../../support/utils/connect/ConnectEventSchemaUtils';

describe('Test Edit Adapter', () => {
beforeEach('Setup Test', () => {
Expand All @@ -42,9 +43,7 @@ describe('Test Edit Adapter', () => {
cy.dataCy('connect-add-field-name-button').click();
cy.dataCy('edit-density').click();
// Change runtime name
cy.dataCy('connect-edit-field-runtime-name')
.clear()
.type('test-density');
ConnectBtns.runtimeNameInput().clear().type('test-density');
// Change field semantic type
cy.get('[id="domainproperty"]')
.clear()
Expand Down Expand Up @@ -75,10 +74,8 @@ describe('Test Edit Adapter', () => {
ConnectBtns.editAdapter().click();
cy.contains('Next').click();
cy.dataCy('edit-density').click();
cy.dataCy('connect-edit-field-runtime-name').should(
'have.value',
'test-density',
);
ConnectEventSchemaUtils.validateRuntimeName('test-density');

cy.get('[id="domainproperty"]').should(
'have.value',
'http://schema.org/Numbers',
Expand All @@ -91,7 +88,7 @@ describe('Test Edit Adapter', () => {
);

// Delete inserted values in edit field
cy.dataCy('connect-edit-field-runtime-name').clear();
ConnectBtns.runtimeNameInput().clear();
cy.get('[id="domainproperty"]').clear();
ConnectBtns.changeRuntimeType()
.click()
Expand Down
9 changes: 6 additions & 3 deletions ui/cypress/tests/connect/rules/schemaRules.smoke.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import { ConnectEventSchemaUtils } from '../../../support/utils/connect/ConnectE
describe('Connect schema rule transformations', () => {
beforeEach('Setup Test', () => {
cy.initStreamPipesTest();
FileManagementUtils.addFile('connect/schemaRules/input.csv');
});

it('Perform Test', () => {
it('Test several schema rules', () => {
FileManagementUtils.addFile('connect/schemaRules/input.csv');
const adapterConfiguration =
ConnectUtils.setUpPreprocessingRuleTest(true);

Expand All @@ -36,7 +36,10 @@ describe('Connect schema rule transformations', () => {
// Delete one property
ConnectEventSchemaUtils.deleteProperty('density');

// Set data type to float
// Rename property with special char
ConnectEventSchemaUtils.renameProperty('contains.dot', 'dot');

// Set data type to integer
ConnectEventSchemaUtils.changePropertyDataType(
'temperature',
'Integer',
Expand Down
Loading

0 comments on commit c15b157

Please sign in to comment.