Skip to content

Commit

Permalink
[core] Fix ArrayIndexOutOfBoundsException when sequenceGroup repeat d…
Browse files Browse the repository at this point in the history
…efined with no field (apache#2010)
  • Loading branch information
pongandnoon authored Sep 19, 2023
1 parent f31cd18 commit e713d72
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,24 @@ public void testSequenceGroup() {
validate(func, 1, null, null, 6, null, null, 6);
}

@Test
public void testSequenceGroupDefinedNoField() {
Options options = new Options();
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("can not be found in table schema");
}

@Test
public void testSequenceGroupRepeatDefine() {
Options options = new Options();
Expand Down

0 comments on commit e713d72

Please sign in to comment.