Skip to content

Commit

Permalink
[core] report error when sequenceGroup is defined with no field
Browse files Browse the repository at this point in the history
  • Loading branch information
pongandnoon committed Sep 15, 2023
1 parent 175d028 commit 6b18da1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,17 @@ private Factory(Options options, RowType rowType) {
SequenceGenerator sequenceGen =
new SequenceGenerator(sequenceFieldName, rowType);
Arrays.stream(v.split(","))
.map(fieldNames::indexOf)
.map(
fieldName -> {
int field = fieldNames.indexOf(fieldName);
if (field == -1) {
throw new IllegalArgumentException(
String.format(
"Field %s can not be found in table schema",
fieldName));
}
return field;
})
.forEach(
field -> {
if (fieldSequences.containsKey(field)) {
Expand All @@ -214,10 +224,7 @@ private Factory(Options options, RowType rowType) {
"Field %s is defined repeatedly by multiple groups: %s",
fieldNames.get(field), k));
}

if (field >= 0) {
fieldSequences.put(field, sequenceGen);
}
fieldSequences.put(field, sequenceGen);
});

// add self
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,46 +91,37 @@ public void testSequenceGroup() {
}

@Test
public void testSequenceGroupRepeatDefine() {
public void testSequenceGroupDefinedNoField() {
Options options = new Options();
options.set("fields.f3.sequence-group", "f1,f2");
options.set("fields.f4.sequence-group", "f1,f2");
options.set("fields.f3.sequence-group", "f1,f2,f7");
options.set("fields.f6.sequence-group", "f4,f5");
RowType rowType =
RowType.of(
DataTypes.INT(),
DataTypes.INT(),
DataTypes.INT(),
DataTypes.INT(),
DataTypes.INT(),
DataTypes.INT(),
DataTypes.INT());
assertThatThrownBy(() -> PartialUpdateMergeFunction.factory(options, rowType))
.hasMessageContaining("is defined repeatedly by multiple groups");
.hasMessageContaining("can not be found in table schema");
}

@Test
public void testSequenceGroupRepeatDefineNoField() {
public void testSequenceGroupRepeatDefine() {
Options options = new Options();
options.set("fields.f3.sequence-group", "f1,f2,f6");
options.set("fields.f5.sequence-group", "f4,f6");
options.set("fields.f3.sequence-group", "f1,f2");
options.set("fields.f4.sequence-group", "f1,f2");
RowType rowType =
RowType.of(
DataTypes.INT(),
DataTypes.INT(),
DataTypes.INT(),
DataTypes.INT(),
DataTypes.INT(),
DataTypes.INT());
MergeFunction<KeyValue> func =
PartialUpdateMergeFunction.factory(options, rowType).create();
func.reset();
add(func, 1, 1, 1, 1, 1, 1);
add(func, 1, 2, 2, 2, 2, null);
validate(func, 1, 2, 2, 2, 1, 1);
add(func, 1, 3, 3, 1, 3, 3);
validate(func, 1, 2, 2, 2, 3, 3);

// delete
add(func, RowKind.DELETE, 1, 1, 1, 3, 1, null);
validate(func, 1, null, null, 3, 3, 3);
assertThatThrownBy(() -> PartialUpdateMergeFunction.factory(options, rowType))
.hasMessageContaining("is defined repeatedly by multiple groups");
}

@Test
Expand Down

0 comments on commit 6b18da1

Please sign in to comment.