From e713d72be2945648336bb03b580793834fcd29a0 Mon Sep 17 00:00:00 2001 From: pongandnoon <2360580200@qq.com> Date: Tue, 19 Sep 2023 10:17:28 +0800 Subject: [PATCH] [core] Fix ArrayIndexOutOfBoundsException when sequenceGroup repeat defined with no field (#2010) --- .../compact/PartialUpdateMergeFunction.java | 12 +++++++++++- .../PartialUpdateMergeFunctionTest.java | 18 ++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/paimon-core/src/main/java/org/apache/paimon/mergetree/compact/PartialUpdateMergeFunction.java b/paimon-core/src/main/java/org/apache/paimon/mergetree/compact/PartialUpdateMergeFunction.java index bf21e5d40313..1bc9d36f9283 100644 --- a/paimon-core/src/main/java/org/apache/paimon/mergetree/compact/PartialUpdateMergeFunction.java +++ b/paimon-core/src/main/java/org/apache/paimon/mergetree/compact/PartialUpdateMergeFunction.java @@ -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)) { diff --git a/paimon-core/src/test/java/org/apache/paimon/mergetree/compact/PartialUpdateMergeFunctionTest.java b/paimon-core/src/test/java/org/apache/paimon/mergetree/compact/PartialUpdateMergeFunctionTest.java index 113aaac106b1..bfac6f629cfb 100644 --- a/paimon-core/src/test/java/org/apache/paimon/mergetree/compact/PartialUpdateMergeFunctionTest.java +++ b/paimon-core/src/test/java/org/apache/paimon/mergetree/compact/PartialUpdateMergeFunctionTest.java @@ -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();