-
Notifications
You must be signed in to change notification settings - Fork 52
feat(QTDI-1305): improve error in record #1041
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
base: master
Are you sure you want to change the base?
Changes from all commits
c924108
ae4cad7
9205765
cfa68e8
cf0a3c6
7d049d1
441faae
0d8f532
de71297
d5ab539
86ad7ee
884420f
a9450e3
727c512
e2dbb27
21cccfc
d2cf309
02a5ebd
92df0c0
fb6a891
7314bfb
01389f5
7884086
e9ea736
8633ea1
9e8120a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -232,6 +232,16 @@ interface Entry { | |
*/ | ||
boolean isMetadata(); | ||
|
||
/** | ||
* @return Is this entry can be in error. | ||
*/ | ||
boolean isErrorCapable(); | ||
|
||
/** | ||
* @return true if the value of this entry is valid; false for invalid value. | ||
*/ | ||
boolean isValid(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can also add a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is not using schema, but using Entry. |
||
|
||
/** | ||
* @param <T> the default value type. | ||
* | ||
|
@@ -296,6 +306,14 @@ default Entry.Builder toBuilder() { | |
throw new UnsupportedOperationException("#toBuilder is not implemented"); | ||
} | ||
|
||
default String getErrorMessage() { | ||
return getProp(SchemaProperty.ENTRY_ERROR_MESSAGE); | ||
} | ||
|
||
default String getErrorFallbackValue() { | ||
return getProp(SchemaProperty.ENTRY_ERROR_FALLBACK_VALUE); | ||
} | ||
|
||
/** | ||
* Plain builder matching {@link Entry} structure. | ||
*/ | ||
|
@@ -317,6 +335,8 @@ default Builder withLogicalType(String logicalType) { | |
|
||
Builder withNullable(boolean nullable); | ||
|
||
Builder withErrorCapable(boolean errorCapable); | ||
|
||
Builder withMetadata(boolean metadata); | ||
|
||
<T> Builder withDefaultValue(T value); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,14 @@ public interface SchemaProperty { | |
|
||
String ALLOW_SPECIAL_NAME = "field.special.name"; | ||
|
||
String ENTRY_IS_ON_ERROR = "entry.on.error"; | ||
|
||
String ENTRY_ERROR_MESSAGE = "entry.error.message"; | ||
|
||
String ENTRY_ERROR_FALLBACK_VALUE = "entry.error.fallback.value"; | ||
|
||
String ERROR_EXCEPTION = "entry.error.exception"; | ||
Comment on lines
+40
to
+46
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see my previous comment. Maybe smtg like |
||
|
||
enum LogicalType { | ||
|
||
DATE("date"), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -209,6 +209,53 @@ void mixedRecordTest() { | |
Assertions.assertNotNull(arrayType); | ||
} | ||
|
||
@Test | ||
void testWithError() { | ||
final String val = System.getProperty(Record.RECORD_ERROR_SUPPORT); | ||
System.setProperty(Record.RECORD_ERROR_SUPPORT, "true"); | ||
final String val2 = System.getProperty(Record.RECORD_ERROR_SUPPORT); | ||
Comment on lines
+214
to
+216
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can use the before and after annotations to handle this... |
||
|
||
org.talend.sdk.component.api.record.Schema.Builder schemaBuilder = factory.newSchemaBuilder(Schema.Type.RECORD); | ||
Schema.Entry nameEntry = factory | ||
.newEntryBuilder() | ||
.withName("name") | ||
.withNullable(false) | ||
.withType(Schema.Type.STRING) | ||
.build(); | ||
Schema.Entry nmEntry = factory | ||
.newEntryBuilder() | ||
.withName("normal") | ||
.withNullable(true) | ||
.withType(Schema.Type.STRING) | ||
.build(); | ||
Schema.Entry ageEntry = factory | ||
.newEntryBuilder() | ||
.withName("age") | ||
.withNullable(false) | ||
.withType(Schema.Type.INT) | ||
.build(); | ||
Schema customerSchema = schemaBuilder.withEntry(nameEntry).withEntry(nmEntry).withEntry(ageEntry).build(); | ||
// record 1 | ||
Record.Builder recordBuilder = factory.newRecordBuilder(customerSchema); | ||
Record record1 = recordBuilder.with(nameEntry, null) | ||
.with(nmEntry, "normal") | ||
.with(ageEntry, "is not an int") | ||
.build(); | ||
assertFalse(record1.isValid()); | ||
|
||
final Schema.Entry entry = | ||
record1.getSchema().getEntries().stream().filter(e -> "name".equals(e.getName())).findAny().get(); | ||
assertNotNull(entry); | ||
Assertions.assertFalse(entry.isValid()); | ||
|
||
final Schema.Entry entry2 = | ||
record1.getSchema().getEntries().stream().filter(e -> "age".equals(e.getName())).findAny().get(); | ||
assertNotNull(entry2); | ||
Assertions.assertFalse(entry2.isValid()); | ||
|
||
System.setProperty(Record.RECORD_ERROR_SUPPORT, "false"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can use the before and after annotations to handle this... |
||
} | ||
|
||
@Test | ||
void recordWithNewSchema() { | ||
final Schema schema0 = new AvroSchemaBuilder()// | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See sonar comment, more easy to read that double negation.