rdblue commented on a change in pull request #228: Use Iceberg tables as sinks 
in Spark Structured Streaming
URL: https://github.com/apache/incubator-iceberg/pull/228#discussion_r296314978
 
 

 ##########
 File path: 
spark/src/main/java/org/apache/iceberg/spark/source/StreamingWriter.java
 ##########
 @@ -0,0 +1,113 @@
+/*
+ * 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.spark.source;
+
+import java.util.Map;
+import org.apache.iceberg.AppendFiles;
+import org.apache.iceberg.DataFile;
+import org.apache.iceberg.FileFormat;
+import org.apache.iceberg.OverwriteFiles;
+import org.apache.iceberg.Snapshot;
+import org.apache.iceberg.SnapshotUpdate;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.expressions.Expressions;
+import org.apache.spark.sql.sources.v2.writer.WriterCommitMessage;
+import org.apache.spark.sql.sources.v2.writer.streaming.StreamWriter;
+import org.apache.spark.sql.streaming.OutputMode;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class StreamingWriter extends Writer implements StreamWriter {
+
+  private static final Logger LOG = 
LoggerFactory.getLogger(StreamingWriter.class);
+  private static final String QUERY_ID_PROPERTY = 
"spark.sql.streaming.queryId";
+  private static final String EPOCH_ID_PROPERTY = 
"spark.sql.streaming.epochId";
+
+  private final String queryId;
+  private final OutputMode mode;
+
+  StreamingWriter(Table table, FileFormat format, String queryId, OutputMode 
mode) {
+    super(table, format);
+    this.queryId = queryId;
+    this.mode = mode;
+  }
+
+  @Override
+  public void commit(long epochId, WriterCommitMessage[] messages) {
+    LOG.info("Committing epoch {} for query {} in {} mode", epochId, queryId, 
mode);
+
+    Long lastCommittedEpochId = getLastCommittedEpochId();
 
 Review comment:
   When performing this check, it seems safer to always ensure the latest 
metadata is loaded by calling `table.refresh()` instead of assuming that 
metadata is up-to-date.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to