You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by lz...@apache.org on 2022/11/21 11:34:04 UTC

[flink-table-store] branch master updated: [FLINK-30071] Throw exception at compile time when sequence field does not exist

This is an automated email from the ASF dual-hosted git repository.

lzljs3620320 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink-table-store.git


The following commit(s) were added to refs/heads/master by this push:
     new 4616e775 [FLINK-30071] Throw exception at compile time when sequence field does not exist
4616e775 is described below

commit 4616e775efd567001704fea0734e5e12e72cfffd
Author: Jane Chan <55...@users.noreply.github.com>
AuthorDate: Mon Nov 21 19:33:59 2022 +0800

    [FLINK-30071] Throw exception at compile time when sequence field does not exist
    
    This closes #386
---
 .../flink/table/store/file/schema/SchemaManager.java       |  6 ++++++
 .../flink/table/store/file/schema/SchemaManagerTest.java   | 14 ++++++++++++++
 2 files changed, 20 insertions(+)

diff --git a/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/schema/SchemaManager.java b/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/schema/SchemaManager.java
index 7ab38278..2d020f21 100644
--- a/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/schema/SchemaManager.java
+++ b/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/schema/SchemaManager.java
@@ -142,6 +142,12 @@ public class SchemaManager implements Serializable {
                 id = 0;
             }
 
+            String sequenceField = options.get(CoreOptions.SEQUENCE_FIELD.key());
+            Preconditions.checkArgument(
+                    sequenceField == null || rowType.getFieldNames().contains(sequenceField),
+                    "Nonexistent sequence field: '%s'",
+                    sequenceField);
+
             TableSchema newSchema =
                     new TableSchema(
                             id,
diff --git a/flink-table-store-core/src/test/java/org/apache/flink/table/store/file/schema/SchemaManagerTest.java b/flink-table-store-core/src/test/java/org/apache/flink/table/store/file/schema/SchemaManagerTest.java
index b6c8b910..1210375f 100644
--- a/flink-table-store-core/src/test/java/org/apache/flink/table/store/file/schema/SchemaManagerTest.java
+++ b/flink-table-store-core/src/test/java/org/apache/flink/table/store/file/schema/SchemaManagerTest.java
@@ -19,6 +19,7 @@
 package org.apache.flink.table.store.file.schema;
 
 import org.apache.flink.core.fs.Path;
+import org.apache.flink.table.store.CoreOptions;
 import org.apache.flink.table.store.file.utils.FailingAtomicRenameFileSystem;
 import org.apache.flink.table.types.logical.BigIntType;
 import org.apache.flink.table.types.logical.DoubleType;
@@ -106,6 +107,19 @@ public class SchemaManagerTest {
         assertThat(tableSchema.partitionKeys()).isEqualTo(partitionKeys);
         assertThat(tableSchema.primaryKeys()).isEqualTo(primaryKeys);
         assertThat(tableSchema.options()).isEqualTo(options);
+
+        assertThatThrownBy(
+                        () ->
+                                manager.commitNewVersion(
+                                        new UpdateSchema(
+                                                rowType,
+                                                partitionKeys,
+                                                primaryKeys,
+                                                Collections.singletonMap(
+                                                        CoreOptions.SEQUENCE_FIELD.key(), "f4"),
+                                                "")))
+                .isInstanceOf(IllegalArgumentException.class)
+                .hasMessageContaining("Nonexistent sequence field: 'f4'");
     }
 
     @Test