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

feat(QTDI-114) Ability to deactivate sanitization #952

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -471,8 +471,9 @@
*
* @return avro compatible name.
*/
static String sanitizeConnectionName(final String name) {

Check failure on line 474 in component-api/src/main/java/org/talend/sdk/component/api/record/Schema.java

View check run for this annotation

sonar-eks / Component Runtime Sonarqube Results

component-api/src/main/java/org/talend/sdk/component/api/record/Schema.java#L474

Refactor this method to reduce its Cognitive Complexity from 35 to the 15 allowed.
if (name == null || name.isEmpty()) {
if (name == null || name.isEmpty()
|| "false".equals(System.getProperty("talend.component.sanitize"))) {
return name;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,23 @@ void testSanitize() {
}
}

@Test
void testDeactivateSanitize() {
System.setProperty("talend.component.sanitize", "false");
Assertions.assertNull(Schema.sanitizeConnectionName(null));
Assertions.assertEquals("", Schema.sanitizeConnectionName(""));
Assertions.assertEquals("$", Schema.sanitizeConnectionName("$"));
Assertions.assertEquals("1", Schema.sanitizeConnectionName("1"));
Assertions.assertEquals("é", Schema.sanitizeConnectionName("é"));
Assertions.assertEquals("éH", Schema.sanitizeConnectionName("éH"));
Assertions.assertEquals("é1", Schema.sanitizeConnectionName("é1"));
Assertions.assertEquals("HélloWorld", Schema.sanitizeConnectionName("HélloWorld"));
Assertions.assertEquals("$oid", Schema.sanitizeConnectionName("$oid"));
Assertions.assertEquals(" Hello World ", Schema.sanitizeConnectionName(" Hello World "));
Assertions.assertEquals("123HelloWorld", Schema.sanitizeConnectionName("123HelloWorld"));
System.clearProperty("talend.component.sanitize");
}

@Test
void testTypes() {
final Record rec = new Record() {
Expand Down Expand Up @@ -205,6 +222,12 @@ void logicalType() {
assertEquals("date", logicalDate.key());
assertEquals(Type.DATETIME, logicalDate.storageType());
assertThrows(IllegalArgumentException.class, () -> SchemaProperty.LogicalType.valueOf("TINYINT"));

SchemaProperty.LogicalType logicalTime = SchemaProperty.LogicalType.valueOf("TIMESTAMP");
assertNotNull(logicalTime);
assertEquals(SchemaProperty.LogicalType.TIMESTAMP, logicalTime);
assertEquals("timestamp", logicalTime.key());
assertEquals(Type.DATETIME, logicalTime.storageType());
}

@RequiredArgsConstructor
Expand Down