Skip to content

Commit e404e30

Browse files
andygroveclaude
andcommitted
Replace @IcebergApi with @CometPublicApi({"Iceberg"}) annotation
Adopts a pattern inspired by Hadoop's @InterfaceAudience.LimitedPrivate where the annotation lists known external consumers. This makes it easy to add future consumers without creating new annotation types. Also addresses review feedback: removes redundant assertions in API tests and clarifies doc references. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent a4ca885 commit e404e30

23 files changed

Lines changed: 181 additions & 137 deletions

common/src/main/java/org/apache/arrow/c/AbstractCometSchemaImporter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import org.apache.arrow.vector.FieldVector;
2424
import org.apache.arrow.vector.types.pojo.Field;
2525

26-
import org.apache.comet.IcebergApi;
26+
import org.apache.comet.CometPublicApi;
2727

2828
/** This is a simple wrapper around SchemaImporter to make it accessible from Java Arrow. */
2929
public abstract class AbstractCometSchemaImporter {
@@ -69,7 +69,7 @@ public FieldVector importVector(ArrowArray array, ArrowSchema schema) {
6969
return vector;
7070
}
7171

72-
@IcebergApi
72+
@CometPublicApi({"Iceberg"})
7373
public void close() {
7474
provider.close();
7575
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.apache.comet;
21+
22+
import java.lang.annotation.Documented;
23+
import java.lang.annotation.ElementType;
24+
import java.lang.annotation.Retention;
25+
import java.lang.annotation.RetentionPolicy;
26+
import java.lang.annotation.Target;
27+
28+
/**
29+
* Indicates that the annotated element is part of the public API used by external projects.
30+
*
31+
* <p>The {@link #value()} lists the known consumers of this API element. Changes to annotated
32+
* elements may break those consumers, so contributors should exercise caution and consider backward
33+
* compatibility when modifying them.
34+
*
35+
* <p>Inspired by Hadoop's {@code @InterfaceAudience.LimitedPrivate}.
36+
*
37+
* <p>Example usage:
38+
*
39+
* <pre>
40+
* &#64;CometPublicApi({"Iceberg"})
41+
* public class FileReader { ... }
42+
* </pre>
43+
*/
44+
@Documented
45+
@Retention(RetentionPolicy.RUNTIME)
46+
@Target({ElementType.TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.FIELD})
47+
public @interface CometPublicApi {
48+
/** Lists the external projects known to use this API element. */
49+
String[] value();
50+
}

common/src/main/java/org/apache/comet/CometSchemaImporter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
import org.apache.arrow.memory.BufferAllocator;
2424

2525
/** This is a simple wrapper around SchemaImporter to make it accessible from Java Arrow. */
26-
@IcebergApi
26+
@CometPublicApi({"Iceberg"})
2727
public class CometSchemaImporter extends AbstractCometSchemaImporter {
28-
@IcebergApi
28+
@CometPublicApi({"Iceberg"})
2929
public CometSchemaImporter(BufferAllocator allocator) {
3030
super(allocator);
3131
}

common/src/main/java/org/apache/comet/IcebergApi.java

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,13 @@
1919

2020
package org.apache.comet;
2121

22-
import java.lang.annotation.Documented;
23-
import java.lang.annotation.ElementType;
24-
import java.lang.annotation.Retention;
25-
import java.lang.annotation.RetentionPolicy;
26-
import java.lang.annotation.Target;
27-
2822
/**
29-
* Indicates that the annotated element is part of the public API used by Apache Iceberg.
30-
*
31-
* <p>This annotation marks classes, methods, constructors, and fields that form the contract
32-
* between Comet and Iceberg. Changes to these APIs may break Iceberg's Comet integration, so
33-
* contributors should exercise caution and consider backward compatibility when modifying annotated
34-
* elements.
23+
* Convenience constant for use with {@link CometPublicApi}.
3524
*
36-
* <p>The Iceberg integration uses Comet's native Parquet reader for accelerated vectorized reads.
37-
* See the contributor guide documentation for details on how Iceberg uses these APIs.
38-
*
39-
* @see <a href="https://iceberg.apache.org/">Apache Iceberg</a>
25+
* <p>Usage: {@code @CometPublicApi({IcebergApi.ICEBERG})}
4026
*/
41-
@Documented
42-
@Retention(RetentionPolicy.RUNTIME)
43-
@Target({ElementType.TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.FIELD})
44-
public @interface IcebergApi {}
27+
public final class IcebergApi {
28+
public static final String ICEBERG = "Iceberg";
29+
30+
private IcebergApi() {}
31+
}

common/src/main/java/org/apache/comet/parquet/AbstractColumnReader.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@
2828
import org.apache.spark.sql.types.TimestampNTZType$;
2929

3030
import org.apache.comet.CometConf;
31-
import org.apache.comet.IcebergApi;
31+
import org.apache.comet.CometPublicApi;
3232
import org.apache.comet.vector.CometVector;
3333

3434
/** Base class for Comet Parquet column reader implementations. */
35-
@IcebergApi
35+
@CometPublicApi({"Iceberg"})
3636
public abstract class AbstractColumnReader implements AutoCloseable {
3737
protected static final Logger LOG = LoggerFactory.getLogger(AbstractColumnReader.class);
3838

@@ -63,7 +63,8 @@ public abstract class AbstractColumnReader implements AutoCloseable {
6363
protected int batchSize;
6464

6565
/** A pointer to the native implementation of ColumnReader. */
66-
@IcebergApi protected long nativeHandle;
66+
@CometPublicApi({"Iceberg"})
67+
protected long nativeHandle;
6768

6869
AbstractColumnReader(
6970
DataType type,
@@ -98,7 +99,7 @@ String getPath() {
9899
/**
99100
* Set the batch size of this reader to be 'batchSize'. Also initializes the native column reader.
100101
*/
101-
@IcebergApi
102+
@CometPublicApi({"Iceberg"})
102103
public void setBatchSize(int batchSize) {
103104
assert nativeHandle == 0
104105
: "Native column reader shouldn't be initialized before " + "'setBatchSize' is called";
@@ -116,7 +117,7 @@ public void setBatchSize(int batchSize) {
116117
/** Returns the {@link CometVector} read by this reader. */
117118
public abstract CometVector currentBatch();
118119

119-
@IcebergApi
120+
@CometPublicApi({"Iceberg"})
120121
@Override
121122
public void close() {
122123
if (nativeHandle != 0) {

common/src/main/java/org/apache/comet/parquet/BatchReader.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@
6464
import org.apache.spark.util.AccumulatorV2;
6565

6666
import org.apache.comet.CometConf;
67+
import org.apache.comet.CometPublicApi;
6768
import org.apache.comet.CometSchemaImporter;
68-
import org.apache.comet.IcebergApi;
6969
import org.apache.comet.shims.ShimBatchReader;
7070
import org.apache.comet.shims.ShimFileFormat;
7171
import org.apache.comet.vector.CometVector;
@@ -88,7 +88,7 @@
8888
* }
8989
* </pre>
9090
*/
91-
@IcebergApi
91+
@CometPublicApi({"Iceberg"})
9292
public class BatchReader extends RecordReader<Void, ColumnarBatch> implements Closeable {
9393
private static final Logger LOG = LoggerFactory.getLogger(FileReader.class);
9494
protected static final BufferAllocator ALLOCATOR = new RootAllocator();
@@ -191,7 +191,7 @@ public BatchReader(
191191
* @deprecated since 0.10.0, will be removed in 0.11.0.
192192
* @see <a href="https://github.com/apache/datafusion-comet/issues/2079">Comet Issue #2079</a>
193193
*/
194-
@IcebergApi
194+
@CometPublicApi({"Iceberg"})
195195
public BatchReader(AbstractColumnReader[] columnReaders) {
196196
// Todo: set useDecimal128 and useLazyMaterialization
197197
int numColumns = columnReaders.length;
@@ -390,7 +390,7 @@ public void init() throws URISyntaxException, IOException {
390390
* @deprecated since 0.10.0, will be removed in 0.11.0.
391391
* @see <a href="https://github.com/apache/datafusion-comet/issues/2079">Comet Issue #2079</a>
392392
*/
393-
@IcebergApi
393+
@CometPublicApi({"Iceberg"})
394394
public void setSparkSchema(StructType schema) {
395395
this.sparkSchema = schema;
396396
}
@@ -399,7 +399,7 @@ public void setSparkSchema(StructType schema) {
399399
* @deprecated since 0.10.0, will be removed in 0.11.0.
400400
* @see <a href="https://github.com/apache/datafusion-comet/issues/2079">Comet Issue #2079</a>
401401
*/
402-
@IcebergApi
402+
@CometPublicApi({"Iceberg"})
403403
public AbstractColumnReader[] getColumnReaders() {
404404
return columnReaders;
405405
}
@@ -503,7 +503,7 @@ public boolean nextBatch() throws IOException {
503503
return nextBatch(batchSize);
504504
}
505505

506-
@IcebergApi
506+
@CometPublicApi({"Iceberg"})
507507
public boolean nextBatch(int batchSize) {
508508
long totalDecodeTime = 0, totalLoadTime = 0;
509509
for (int i = 0; i < columnReaders.length; i++) {
@@ -530,7 +530,7 @@ public boolean nextBatch(int batchSize) {
530530
return true;
531531
}
532532

533-
@IcebergApi
533+
@CometPublicApi({"Iceberg"})
534534
@Override
535535
public void close() throws IOException {
536536
if (columnReaders != null) {

common/src/main/java/org/apache/comet/parquet/ColumnReader.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@
4343
import org.apache.spark.sql.types.DataType;
4444

4545
import org.apache.comet.CometConf;
46+
import org.apache.comet.CometPublicApi;
4647
import org.apache.comet.CometSchemaImporter;
47-
import org.apache.comet.IcebergApi;
4848
import org.apache.comet.vector.CometDecodedVector;
4949
import org.apache.comet.vector.CometDictionary;
5050
import org.apache.comet.vector.CometDictionaryVector;
5151
import org.apache.comet.vector.CometPlainVector;
5252
import org.apache.comet.vector.CometVector;
5353

54-
@IcebergApi
54+
@CometPublicApi({"Iceberg"})
5555
public class ColumnReader extends AbstractColumnReader {
5656
protected static final Logger LOG = LoggerFactory.getLogger(ColumnReader.class);
5757
protected final BufferAllocator ALLOCATOR = new RootAllocator();
@@ -116,7 +116,7 @@ public class ColumnReader extends AbstractColumnReader {
116116
* @deprecated since 0.10.0, will be removed in 0.11.0.
117117
* @see <a href="https://github.com/apache/datafusion-comet/issues/2079">Comet Issue #2079</a>
118118
*/
119-
@IcebergApi
119+
@CometPublicApi({"Iceberg"})
120120
public void setPageReader(PageReader pageReader) throws IOException {
121121
this.pageReader = pageReader;
122122

@@ -132,7 +132,7 @@ public void setPageReader(PageReader pageReader) throws IOException {
132132
}
133133

134134
/** This method is called from Apache Iceberg. */
135-
@IcebergApi
135+
@CometPublicApi({"Iceberg"})
136136
public void setRowGroupReader(RowGroupReader rowGroupReader, ParquetColumnSpec columnSpec)
137137
throws IOException {
138138
ColumnDescriptor descriptor = Utils.buildColumnDescriptor(columnSpec);

common/src/main/java/org/apache/comet/parquet/ConstantColumnReader.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@
2727
import org.apache.spark.sql.types.*;
2828
import org.apache.spark.unsafe.types.UTF8String;
2929

30-
import org.apache.comet.IcebergApi;
30+
import org.apache.comet.CometPublicApi;
3131

3232
/**
3333
* A column reader that always return constant vectors. Used for reading partition columns, for
3434
* instance.
3535
*/
36-
@IcebergApi
36+
@CometPublicApi({"Iceberg"})
3737
public class ConstantColumnReader extends MetadataColumnReader {
3838
/** Whether all the values in this constant column are nulls */
3939
private boolean isNull;
@@ -59,15 +59,15 @@ public class ConstantColumnReader extends MetadataColumnReader {
5959
* @deprecated since 0.10.0, will be removed in 0.11.0.
6060
* @see <a href="https://github.com/apache/datafusion-comet/issues/2079">Comet Issue #2079</a>
6161
*/
62-
@IcebergApi
62+
@CometPublicApi({"Iceberg"})
6363
public ConstantColumnReader(
6464
DataType type, ColumnDescriptor descriptor, Object value, boolean useDecimal128) {
6565
super(type, descriptor, useDecimal128, true);
6666
this.value = value;
6767
}
6868

6969
// Used by Iceberg
70-
@IcebergApi
70+
@CometPublicApi({"Iceberg"})
7171
public ConstantColumnReader(
7272
DataType type, ParquetColumnSpec spec, Object value, boolean useDecimal128) {
7373
super(type, spec, useDecimal128, true);

common/src/main/java/org/apache/comet/parquet/FileReader.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
import org.apache.parquet.schema.PrimitiveType;
9191
import org.apache.spark.sql.execution.metric.SQLMetric;
9292

93-
import org.apache.comet.IcebergApi;
93+
import org.apache.comet.CometPublicApi;
9494

9595
import static org.apache.parquet.hadoop.ParquetFileWriter.EFMAGIC;
9696
import static org.apache.parquet.hadoop.ParquetFileWriter.MAGIC;
@@ -103,7 +103,7 @@
103103
* A Parquet file reader. Mostly followed {@code ParquetFileReader} in {@code parquet-mr}, but with
104104
* customizations & optimizations for Comet.
105105
*/
106-
@IcebergApi
106+
@CometPublicApi({"Iceberg"})
107107
public class FileReader implements Closeable {
108108
private static final Logger LOG = LoggerFactory.getLogger(FileReader.class);
109109

@@ -138,7 +138,7 @@ public class FileReader implements Closeable {
138138
}
139139

140140
/** This constructor is called from Apache Iceberg. */
141-
@IcebergApi
141+
@CometPublicApi({"Iceberg"})
142142
public FileReader(
143143
WrappedInputFile file,
144144
ReadOptions cometOptions,
@@ -262,7 +262,7 @@ public void setRequestedSchema(List<ColumnDescriptor> projection) {
262262
}
263263

264264
/** This method is called from Apache Iceberg. */
265-
@IcebergApi
265+
@CometPublicApi({"Iceberg"})
266266
public void setRequestedSchemaFromSpecs(List<ParquetColumnSpec> specList) {
267267
paths.clear();
268268
for (ParquetColumnSpec colSpec : specList) {
@@ -341,7 +341,7 @@ public long getFilteredRecordCount() {
341341
}
342342

343343
/** Skips the next row group. Returns false if there's no row group to skip. Otherwise, true. */
344-
@IcebergApi
344+
@CometPublicApi({"Iceberg"})
345345
public boolean skipNextRowGroup() {
346346
return advanceToNextBlock();
347347
}
@@ -350,7 +350,7 @@ public boolean skipNextRowGroup() {
350350
* Returns the next row group to read (after applying row group filtering), or null if there's no
351351
* more row group.
352352
*/
353-
@IcebergApi
353+
@CometPublicApi({"Iceberg"})
354354
public RowGroupReader readNextRowGroup() throws IOException {
355355
if (currentBlock == blocks.size()) {
356356
return null;
@@ -871,7 +871,7 @@ public void closeStream() throws IOException {
871871
}
872872
}
873873

874-
@IcebergApi
874+
@CometPublicApi({"Iceberg"})
875875
@Override
876876
public void close() throws IOException {
877877
try {

0 commit comments

Comments
 (0)