You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by GitBox <gi...@apache.org> on 2020/07/12 07:23:05 UTC

[GitHub] [iceberg] rdsr commented on a change in pull request #971: Add reader for position based delete file

rdsr commented on a change in pull request #971:
URL: https://github.com/apache/iceberg/pull/971#discussion_r453278818



##########
File path: core/src/main/java/org/apache/iceberg/PositionBasedDeleteRecord.java
##########
@@ -0,0 +1,93 @@
+/*
+ * 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;
+
+import org.apache.avro.Schema;
+import org.apache.avro.generic.IndexedRecord;
+import org.apache.avro.specific.SpecificData;
+import org.apache.iceberg.relocated.com.google.common.base.MoreObjects;
+import org.apache.iceberg.types.Types;
+
+import static org.apache.iceberg.types.Types.NestedField.required;
+
+class PositionBasedDeleteRecord implements IndexedRecord, SpecificData.SchemaConstructable {
+
+  private transient org.apache.avro.Schema avroSchema = null;
+  private String filePath = null;
+  private Long position = null;
+
+  static org.apache.iceberg.Schema schema() {

Review comment:
       Can't we make this a static constant?

##########
File path: core/src/main/java/org/apache/iceberg/PositionBasedDeleteRecord.java
##########
@@ -0,0 +1,93 @@
+/*
+ * 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;
+
+import org.apache.avro.Schema;
+import org.apache.avro.generic.IndexedRecord;
+import org.apache.avro.specific.SpecificData;
+import org.apache.iceberg.relocated.com.google.common.base.MoreObjects;
+import org.apache.iceberg.types.Types;
+
+import static org.apache.iceberg.types.Types.NestedField.required;
+
+class PositionBasedDeleteRecord implements IndexedRecord, SpecificData.SchemaConstructable {
+
+  private transient org.apache.avro.Schema avroSchema = null;
+  private String filePath = null;
+  private Long position = null;
+
+  static org.apache.iceberg.Schema schema() {
+    return new org.apache.iceberg.Schema(
+        required(1, "file_path", Types.StringType.get()),
+        required(2, "position", Types.LongType.get()));
+  }
+
+  /**
+   * Used by Avro reflection to instantiate this class when reading manifest files.
+   */
+  PositionBasedDeleteRecord(org.apache.avro.Schema avroSchema) {
+    this.avroSchema = avroSchema;
+  }
+
+  PositionBasedDeleteRecord(String path, Long pos) {
+    this.filePath = path;
+    this.position = pos;
+  }
+
+  @Override
+  public void put(int pos, Object v) {
+    switch (pos) {
+      case 0:
+        // always coerce to String for Serializable
+        this.filePath = v.toString();
+        return;
+      case 1:
+        this.position = (Long) v;
+        return;
+      default:
+        // ignore the object, it must be from a newer version of the format
+    }
+  }
+
+  @Override
+  public Object get(int pos) {
+    switch (pos) {
+      case 0:
+        return filePath;
+      case 1:
+        return position;
+      default:
+        throw new UnsupportedOperationException("Unknown field ordinal: " + pos);
+    }
+  }
+
+  @Override
+  public Schema getSchema() {
+    return avroSchema;
+  }
+
+  @Override
+  public String toString() {
+    return MoreObjects.toStringHelper(this)

Review comment:
       What is the recommendation here, do we use Guava or standard Java 8 idioms? I inclined to use Java8 to avoid more class-path conflicts. Intellij will generate a nice one using `java.util.StringJoiner`

##########
File path: spark/src/main/java/org/apache/iceberg/spark/source/PositionDeleteFileReader.java
##########
@@ -0,0 +1,79 @@
+/*
+ * 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 org.apache.iceberg.FileFormat;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.avro.Avro;
+import org.apache.iceberg.io.CloseableIterable;
+import org.apache.iceberg.io.InputFile;
+import org.apache.iceberg.orc.ORC;
+import org.apache.iceberg.parquet.Parquet;
+import org.apache.iceberg.spark.data.SparkAvroReader;
+import org.apache.iceberg.spark.data.SparkOrcReader;
+import org.apache.iceberg.spark.data.SparkParquetReaders;
+import org.apache.iceberg.types.Types;
+import org.apache.spark.sql.catalyst.InternalRow;
+
+import static org.apache.iceberg.types.Types.NestedField.required;
+
+class PositionDeleteFileReader {
+  private final InputFile inputFile;
+  private final FileFormat format;
+
+  private static final Schema deleteSchema = new Schema(
+      required(1, "file_path", Types.StringType.get()),
+      required(2, "position", Types.LongType.get())
+  );
+
+  PositionDeleteFileReader(InputFile inputFile, FileFormat format) {
+    this.inputFile = inputFile;
+    this.format = format;
+  }
+
+  public CloseableIterable<InternalRow> open(long start, long length) {
+    switch (format) {
+      case PARQUET:
+        return Parquet.read(inputFile)
+            .project(deleteSchema)

Review comment:
       I'm just learning about about Row level deletes here. 
   - Can you please elaborate why do we need to have this class under spark module
   -  Is my understanding correct that the delta computation will be performed at query planning time? If so that do we really need to support splits here?

##########
File path: spark/src/main/java/org/apache/iceberg/spark/source/PositionDeleteFileReader.java
##########
@@ -0,0 +1,79 @@
+/*
+ * 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 org.apache.iceberg.FileFormat;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.avro.Avro;
+import org.apache.iceberg.io.CloseableIterable;
+import org.apache.iceberg.io.InputFile;
+import org.apache.iceberg.orc.ORC;
+import org.apache.iceberg.parquet.Parquet;
+import org.apache.iceberg.spark.data.SparkAvroReader;
+import org.apache.iceberg.spark.data.SparkOrcReader;
+import org.apache.iceberg.spark.data.SparkParquetReaders;
+import org.apache.iceberg.types.Types;
+import org.apache.spark.sql.catalyst.InternalRow;
+
+import static org.apache.iceberg.types.Types.NestedField.required;
+
+class PositionDeleteFileReader {
+  private final InputFile inputFile;
+  private final FileFormat format;
+
+  private static final Schema deleteSchema = new Schema(

Review comment:
       Nit: we should refer to the constant defined in `PositionDeleteRecord`




----------------------------------------------------------------
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:
users@infra.apache.org



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