Annotation library for Apache Spark test categorization and API stability markers
npx @tessl/cli install tessl/maven-org-apache-spark--spark-tags-2-12@3.5.0Apache Spark Tags provides Java and Scala annotations for API stability marking and test categorization within the Apache Spark ecosystem. This annotation library enables consistent test organization, clear API stability communication to users, and systematic tracking of feature evolution across Spark releases.
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-tags_2.12</artifactId>
<version>3.5.6</version>
</dependency>For Gradle:
implementation 'org.apache.spark:spark-tags_2.12:3.5.6'// API Stability Annotations
import org.apache.spark.annotation.Stable;
import org.apache.spark.annotation.Unstable;
import org.apache.spark.annotation.Experimental;
import org.apache.spark.annotation.Evolving;
import org.apache.spark.annotation.DeveloperApi;
import org.apache.spark.annotation.Private;
import org.apache.spark.annotation.AlphaComponent;
// Test Category Annotations
import org.apache.spark.tags.ExtendedSQLTest;
import org.apache.spark.tags.DockerTest;
import org.apache.spark.tags.SlowHiveTest;For Scala:
import org.apache.spark.annotation.Since// Mark a stable API
@Stable
public class MyStableAPI {
@Stable
public void stableMethod() {
// Implementation
}
}
// Mark experimental features
@Experimental
public class NewFeature {
@DeveloperApi
public void advancedConfiguration() {
// Developer-only API
}
}
// Categorize tests
@ExtendedSQLTest
public class MyExtendedSQLTest {
@DockerTest
public void testWithDocker() {
// Test requiring Docker
}
}Apache Spark Tags is organized into two main annotation packages:
org.apache.spark.annotation): Annotations for marking API stability and intended audience. This package contains "Spark annotations to mark an API experimental or intended only for advanced usages by developers" and is reflected in Scala and Java docs.org.apache.spark.tags): ScalaTest tag annotations for test categorization and filteringAnnotations for marking the stability and intended audience of APIs within the Apache Spark ecosystem.
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER,
ElementType.CONSTRUCTOR, ElementType.LOCAL_VARIABLE, ElementType.PACKAGE})
public @interface Stable {}
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER,
ElementType.CONSTRUCTOR, ElementType.LOCAL_VARIABLE, ElementType.PACKAGE})
public @interface Unstable {}
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER,
ElementType.CONSTRUCTOR, ElementType.LOCAL_VARIABLE, ElementType.PACKAGE})
public @interface Experimental {}
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER,
ElementType.CONSTRUCTOR, ElementType.LOCAL_VARIABLE, ElementType.PACKAGE})
public @interface Evolving {}
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER,
ElementType.CONSTRUCTOR, ElementType.LOCAL_VARIABLE, ElementType.PACKAGE})
public @interface DeveloperApi {}
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER,
ElementType.CONSTRUCTOR, ElementType.LOCAL_VARIABLE, ElementType.PACKAGE})
public @interface Private {}
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER,
ElementType.CONSTRUCTOR, ElementType.LOCAL_VARIABLE, ElementType.PACKAGE})
public @interface AlphaComponent {}Stability Levels (in order of stability):
Audience Annotations:
Usage Examples:
// Stable public API
@Stable
public class DataFrameReader {
@Stable
public Dataset<Row> json(String path) {
// Implementation
}
}
// Experimental feature
@Experimental
public class MLPipeline {
@Experimental
public Model fit(Dataset<?> dataset) {
// Implementation
}
}
// Developer-only API
@DeveloperApi
public class InternalCacheManager {
@Private
void clearInternalCache() {
// Internal implementation
}
}
// Alpha component
@AlphaComponent
public class GraphXExperimental {
@Unstable
public Graph<VD, ED> processGraph() {
// Implementation
}
}Scala annotation for tracking when features were introduced in Spark versions.
private[spark] class Since(version: String) extends StaticAnnotationUsage:
@Since("3.0.0")
def newSparkFeature(): Unit = {
// Implementation introduced in Spark 3.0.0
}
@Since("2.4.0")
class FeatureFromTwoFour {
@Since("2.4.5")
def methodAddedInPatch(): String = "result"
}The Since annotation is private to the Spark package (private[spark]) and is used internally to track API evolution. Unlike @since JavaDoc tags, this annotation doesn't require explicit JavaDoc and works for overridden methods that inherit documentation from parents. However, it doesn't appear in generated Java API documentation.
ScalaTest tag annotations for categorizing and filtering test execution in the Apache Spark test suite.
@TagAnnotation
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.TYPE})
public @interface ExtendedSQLTest {}
@TagAnnotation
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.TYPE})
public @interface ExtendedHiveTest {}
@TagAnnotation
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.TYPE})
public @interface ExtendedYarnTest {}
@TagAnnotation
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.TYPE})
public @interface ExtendedLevelDBTest {}
@TagAnnotation
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.TYPE})
public @interface SlowSQLTest {}
@TagAnnotation
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.TYPE})
public @interface SlowHiveTest {}
@TagAnnotation
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.TYPE})
public @interface DockerTest {}
@TagAnnotation
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.TYPE})
public @interface ChromeUITest {}All test category annotations are ScalaTest @TagAnnotation interfaces that can be applied to test methods or test classes. They enable selective test execution and organization.
Test Categories:
Usage Examples:
// Categorize a test class
@ExtendedSQLTest
public class ComplexSQLQueryTest {
@Test
public void testComplexJoins() {
// Test implementation
}
}
// Categorize individual test methods
public class MixedTestSuite {
@Test
@SlowSQLTest
public void testLargeDatasetQuery() {
// Slow SQL test
}
@Test
@DockerTest
public void testWithExternalDatabase() {
// Test requiring Docker
}
@Test
@ChromeUITest
public void testWebUI() {
// UI test requiring Chrome
}
}
// Multiple annotations
@ExtendedHiveTest
@SlowHiveTest
public class HeavyHiveProcessingTest {
// Extended and slow Hive tests
}Test Filtering:
These annotations enable running specific test categories:
# Run only extended SQL tests
mvn test -Dtest.include.tags=org.apache.spark.tags.ExtendedSQLTest
# Exclude slow tests
mvn test -Dtest.exclude.tags=org.apache.spark.tags.SlowSQLTest,org.apache.spark.tags.SlowHiveTest
# Run only Docker tests
mvn test -Dtest.include.tags=org.apache.spark.tags.DockerTestAll annotations are marker annotations (no parameters) that serve as metadata for the Java/Scala compiler and runtime reflection. The annotations use Java's built-in annotation types:
// Standard annotation imports used by all annotations
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
// ScalaTest import for test annotations
import org.scalatest.TagAnnotation;Retention Policies:
RetentionPolicy.RUNTIME: Annotations are available at runtime via reflectionTarget Elements:
Scala Annotation Features:
import scala.annotation.StaticAnnotation
import scala.annotation.meta._
// Meta-annotations for Scala annotation targets
@param @field @getter @setter @beanGetter @beanSetter
private[spark] class Since(version: String) extends StaticAnnotationThe Since annotation uses Scala's meta-annotation system to apply to multiple target types simultaneously (parameters, fields, getters, setters, and bean accessors).