hililiwei commented on code in PR #6222:
URL: https://github.com/apache/iceberg/pull/6222#discussion_r1039570783


##########
flink/v1.16/flink/src/test/java/org/apache/iceberg/flink/source/TestFlinkMetaDataTable.java:
##########
@@ -0,0 +1,713 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iceberg.flink.source;
+
+import java.io.IOException;
+import java.time.Instant;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import org.apache.avro.generic.GenericData;
+import org.apache.commons.collections.ListUtils;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.CoreOptions;
+import org.apache.flink.table.api.TableEnvironment;
+import org.apache.flink.types.Row;
+import org.apache.iceberg.DeleteFile;
+import org.apache.iceberg.FileContent;
+import org.apache.iceberg.FileFormat;
+import org.apache.iceberg.Files;
+import org.apache.iceberg.ManifestFile;
+import org.apache.iceberg.MetadataTableType;
+import org.apache.iceberg.MetadataTableUtils;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.Snapshot;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.avro.Avro;
+import org.apache.iceberg.catalog.Namespace;
+import org.apache.iceberg.catalog.TableIdentifier;
+import org.apache.iceberg.data.FileHelpers;
+import org.apache.iceberg.data.GenericRecord;
+import org.apache.iceberg.data.Record;
+import org.apache.iceberg.expressions.Expressions;
+import org.apache.iceberg.flink.FlinkCatalogTestBase;
+import org.apache.iceberg.flink.FlinkConfigOptions;
+import org.apache.iceberg.flink.TestHelpers;
+import org.apache.iceberg.io.CloseableIterable;
+import org.apache.iceberg.io.InputFile;
+import org.apache.iceberg.relocated.com.google.common.collect.Lists;
+import org.apache.iceberg.relocated.com.google.common.collect.Maps;
+import org.apache.iceberg.util.SnapshotUtil;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+public class TestFlinkMetaDataTable extends FlinkCatalogTestBase {
+
+  private static final String TABLE_NAME = "test_table";
+  private final FileFormat format = FileFormat.AVRO;
+  private static TemporaryFolder temp = new TemporaryFolder();
+
+  public TestFlinkMetaDataTable(String catalogName, Namespace baseNamespace) {
+    super(catalogName, baseNamespace);
+  }
+
+  @Override
+  protected TableEnvironment getTableEnv() {
+    Configuration configuration = 
super.getTableEnv().getConfig().getConfiguration();
+    configuration.set(CoreOptions.DEFAULT_PARALLELISM, 1);
+    configuration.set(FlinkConfigOptions.TABLE_EXEC_ICEBERG_USE_FLIP27_SOURCE, 
true);
+    return super.getTableEnv();
+  }
+
+  @Before
+  public void before() {
+    super.before();
+    sql("CREATE DATABASE %s", flinkDatabase);
+    sql("USE CATALOG %s", catalogName);
+    sql("USE %s", DATABASE);
+  }
+
+  @Override
+  @After
+  public void clean() {
+    sql("DROP TABLE IF EXISTS %s.%s", flinkDatabase, TABLE_NAME);
+    sql("DROP DATABASE IF EXISTS %s", flinkDatabase);
+    super.clean();
+  }
+
+  @Test
+  public void testSnapshots() {
+    sql(
+        "CREATE TABLE %s (id INT, data VARCHAR,d DOUBLE) WITH 
('format-version'='2', 'write.format.default'='%s')",
+        TABLE_NAME, format.name());
+    sql(
+        "INSERT INTO %s VALUES (1,'iceberg',10),(2,'b',20),(3,CAST(NULL AS 
VARCHAR),30)",
+        TABLE_NAME);
+    String sql = String.format("SELECT * FROM %s$snapshots ", TABLE_NAME);
+    List<Row> result = sql(sql);
+
+    Table table = 
validationCatalog.loadTable(TableIdentifier.of(icebergNamespace, TABLE_NAME));
+    Iterator<Snapshot> snapshots = table.snapshots().iterator();
+    for (Row row : result) {
+      Snapshot next = snapshots.next();
+      Assert.assertEquals(
+          "Should have expected timestamp",
+          ((Instant) row.getField(0)).toEpochMilli(),
+          next.timestampMillis());
+      Assert.assertEquals("Should have expected snapshot id", row.getField(1), 
next.snapshotId());
+      Assert.assertEquals("Should have expected parent id", row.getField(2), 
next.parentId());
+      Assert.assertEquals("Should have expected operation", row.getField(3), 
next.operation());
+      Assert.assertEquals(
+          "Should have expected manifest list location",
+          row.getField(4),
+          next.manifestListLocation());
+      Assert.assertEquals("Should have expected summary", row.getField(5), 
next.summary());
+    }
+  }
+
+  @Test
+  public void testHistory() {
+    sql(
+        "CREATE TABLE %s (id INT, data VARCHAR,d DOUBLE) WITH 
('format-version'='2', 'write.format.default'='%s')",
+        TABLE_NAME, format.name());
+    sql(
+        "INSERT INTO %s VALUES (1,'iceberg',10),(2,'b',20),(3,CAST(NULL AS 
VARCHAR),30)",
+        TABLE_NAME);
+    String sql = String.format("SELECT * FROM %s$history ", TABLE_NAME);
+    List<Row> result = sql(sql);
+
+    Table table = 
validationCatalog.loadTable(TableIdentifier.of(icebergNamespace, TABLE_NAME));
+    Iterator<Snapshot> snapshots = table.snapshots().iterator();
+    for (Row row : result) {
+      Snapshot next = snapshots.next();
+      Assert.assertEquals(
+          "Should have expected made_current_at",
+          ((Instant) row.getField(0)).toEpochMilli(),
+          next.timestampMillis());
+      Assert.assertEquals("Should have expected snapshot id", row.getField(1), 
next.snapshotId());
+      Assert.assertEquals("Should have expected parent id", row.getField(2), 
next.parentId());
+      Assert.assertEquals(

Review Comment:
   Multiple snapshots have been added.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org
For additional commands, e-mail: issues-h...@iceberg.apache.org

Reply via email to