Skip to content

feat(QTDI-1672): Allow disable nullable check in tck framework level #1086

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

Open
wants to merge 3 commits 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 @@ -327,6 +327,8 @@
"Entry '" + entry.getOriginalFieldName() + "' expected to be a " + entry.getType() + ", got a "
+ type);
}
// final boolean disableNullableCheck = Boolean.parseBoolean(System.getProperty("talend.sdk.skip.nullable.check", "false"));
//!disableNullableCheck &&

Check warning on line 331 in component-runtime-impl/src/main/java/org/talend/sdk/component/runtime/record/RecordImpl.java

View check run for this annotation

sonar-eks / SonarQube Code Analysis

component-runtime-impl/src/main/java/org/talend/sdk/component/runtime/record/RecordImpl.java#L331

This block of commented-out lines of code should be removed.
if (value == null && !entry.isNullable()) {
throw new IllegalArgumentException("Entry '" + entry.getOriginalFieldName() + "' is not nullable");
}
Expand Down Expand Up @@ -357,7 +359,9 @@
.filter(it -> !it.isNullable() && !values.containsKey(it.getName()))
.map(Schema.Entry::getName)
.collect(joining(", "));
if (!missing.isEmpty()) {

if (!Boolean.parseBoolean(System.getProperty("talend.sdk.skip.nullable.check", "false"))
&& !missing.isEmpty()) {
throw new IllegalArgumentException("Missing entries: " + missing);
}

Expand Down Expand Up @@ -587,12 +591,16 @@
} else {
realEntry = entry;
}
if (value != null) {
values.put(realEntry.getName(), value);
} else if (!realEntry.isNullable()) {
throw new IllegalArgumentException(realEntry.getName() + " is not nullable but got a null value");
}
// if (Boolean.parseBoolean(System.getProperty("talend.sdk.skip.nullable.check", "false"))) {
// values.put(realEntry.getName(), value);

Check warning on line 595 in component-runtime-impl/src/main/java/org/talend/sdk/component/runtime/record/RecordImpl.java

View check run for this annotation

sonar-eks / SonarQube Code Analysis

component-runtime-impl/src/main/java/org/talend/sdk/component/runtime/record/RecordImpl.java#L595

This block of commented-out lines of code should be removed.
// } else {
if (value != null) {
values.put(realEntry.getName(), value);
} else if (!realEntry.isNullable()) {
throw new IllegalArgumentException(realEntry.getName() + " is not nullable but got a null value");
}
// }

Check warning on line 603 in component-runtime-impl/src/main/java/org/talend/sdk/component/runtime/record/RecordImpl.java

View check run for this annotation

sonar-eks / SonarQube Code Analysis

component-runtime-impl/src/main/java/org/talend/sdk/component/runtime/record/RecordImpl.java#L603

This block of commented-out lines of code should be removed.
if (this.entries != null) {
this.entries.addValue(realEntry);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,56 @@
.withString(new SchemaImpl.EntryImpl.BuilderImpl().withNullable(false).withName("test").build(), null));
}

@Test
void disableNullableCheck_no() {
RecordBuilderFactoryImpl recordBuilderFactory = new RecordBuilderFactoryImpl("test");
Schema.Builder schemaBuilder = recordBuilderFactory.newSchemaBuilder(Type.RECORD);
Schema schema = schemaBuilder.withEntry(
recordBuilderFactory.newEntryBuilder().withType(Type.STRING).withName("c1").withNullable(false).build())
.withEntry(recordBuilderFactory.newEntryBuilder()
.withName("c2")
.withType(Type.STRING)
.withNullable(true)
.build())
.build();
Record.Builder recordBuilder = recordBuilderFactory.newRecordBuilder(schema);
recordBuilder.withString("c1", "v1");
recordBuilder.build();

Schema.Builder schemaBuilder2 = recordBuilderFactory.newSchemaBuilder(Type.RECORD);
Schema schema2 = schemaBuilder2.withEntry(
recordBuilderFactory.newEntryBuilder().withType(Type.STRING).withName("c1").withNullable(false).build())
.withEntry(recordBuilderFactory.newEntryBuilder()
.withName("c2")
.withType(Type.STRING)
.withNullable(false)
.build())
.build();
Record.Builder recordBuilder2 = recordBuilderFactory.newRecordBuilder(schema2);
recordBuilder2.withString("c1", "v1");
assertThrows(IllegalArgumentException.class, () -> recordBuilder2.build());

Check notice on line 262 in component-runtime-impl/src/test/java/org/talend/sdk/component/runtime/record/RecordBuilderImplTest.java

View check run for this annotation

sonar-eks / SonarQube Code Analysis

component-runtime-impl/src/test/java/org/talend/sdk/component/runtime/record/RecordBuilderImplTest.java#L262

Replace this lambda with method reference 'recordBuilder2::build'.
}

@Test
void disableNullableCheck_yes() {
System.setProperty("talend.sdk.skip.nullable.check", "true");
RecordBuilderFactoryImpl recordBuilderFactory = new RecordBuilderFactoryImpl("test");
Schema.Builder schemaBuilder = recordBuilderFactory.newSchemaBuilder(Type.RECORD);
Schema schema = schemaBuilder.withEntry(
recordBuilderFactory.newEntryBuilder().withType(Type.STRING).withName("c1").withNullable(false).build())
.withEntry(recordBuilderFactory.newEntryBuilder()
.withName("c2")
.withType(Type.STRING)
.withNullable(false)
.build())
.build();
Record.Builder recordBuilder = recordBuilderFactory.newRecordBuilder(schema);
recordBuilder.withString("c1", "v1");
Record record = recordBuilder.build();

Check warning on line 280 in component-runtime-impl/src/test/java/org/talend/sdk/component/runtime/record/RecordBuilderImplTest.java

View check run for this annotation

sonar-eks / SonarQube Code Analysis

component-runtime-impl/src/test/java/org/talend/sdk/component/runtime/record/RecordBuilderImplTest.java#L280

Rename this variable to not match a restricted identifier.
assertNull(record.getString("c2"));
System.clearProperty("talend.sdk.skip.nullable.check");
}

@Test
void dateTime() {
final Schema schema = new SchemaImpl.BuilderImpl()
Expand Down
Loading