|
| 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.iceberg.actions; |
| 21 | + |
| 22 | +import org.apache.iceberg.Table; |
| 23 | +import org.apache.iceberg.common.DynConstructors; |
| 24 | +import org.apache.spark.sql.SparkSession; |
| 25 | + |
| 26 | +/** |
| 27 | + * An API for interacting with actions in Spark. |
| 28 | + * |
| 29 | + * @deprecated since 0.12.0, used for supporting {@link RewriteDataFilesAction} in Spark 2.4 for backward compatibility. |
| 30 | + * This implementation is no longer maintained, the new implementation is available with Spark 3.x |
| 31 | + */ |
| 32 | +@Deprecated |
| 33 | +public class Actions { |
| 34 | + |
| 35 | + // Load the actual implementation of Actions via reflection to allow for differences |
| 36 | + // between the major Spark APIs while still defining the API in this class. |
| 37 | + private static final String IMPL_NAME = "SparkActions"; |
| 38 | + private static DynConstructors.Ctor<Actions> implConstructor; |
| 39 | + |
| 40 | + private static String implClass() { |
| 41 | + return Actions.class.getPackage().getName() + "." + IMPL_NAME; |
| 42 | + } |
| 43 | + |
| 44 | + private static DynConstructors.Ctor<Actions> actionConstructor() { |
| 45 | + if (implConstructor == null) { |
| 46 | + String className = implClass(); |
| 47 | + try { |
| 48 | + implConstructor = |
| 49 | + DynConstructors.builder().hiddenImpl(className, SparkSession.class, Table.class).buildChecked(); |
| 50 | + } catch (NoSuchMethodException e) { |
| 51 | + throw new IllegalArgumentException("Cannot find appropriate Actions implementation on the classpath.", e); |
| 52 | + } |
| 53 | + } |
| 54 | + return implConstructor; |
| 55 | + } |
| 56 | + |
| 57 | + private SparkSession spark; |
| 58 | + private Table table; |
| 59 | + |
| 60 | + protected Actions(SparkSession spark, Table table) { |
| 61 | + this.spark = spark; |
| 62 | + this.table = table; |
| 63 | + } |
| 64 | + |
| 65 | + /** |
| 66 | + * @deprecated since 0.12.0, used for supporting {@link RewriteDataFilesAction} |
| 67 | + * in Spark 2.4 for backward compatibility. |
| 68 | + * This implementation is no longer maintained, the new implementation is available with Spark 3.x |
| 69 | + */ |
| 70 | + @Deprecated |
| 71 | + public static Actions forTable(SparkSession spark, Table table) { |
| 72 | + return actionConstructor().newInstance(spark, table); |
| 73 | + } |
| 74 | + |
| 75 | + /** |
| 76 | + * @deprecated since 0.12.0, used for supporting {@link RewriteDataFilesAction} |
| 77 | + * in Spark 2.4 for backward compatibility. |
| 78 | + * This implementation is no longer maintained, the new implementation is available with Spark 3.x |
| 79 | + */ |
| 80 | + @Deprecated |
| 81 | + public static Actions forTable(Table table) { |
| 82 | + return forTable(SparkSession.active(), table); |
| 83 | + } |
| 84 | + |
| 85 | + /** |
| 86 | + * @deprecated since 0.12.0, used for supporting {@link RewriteDataFilesAction} |
| 87 | + * in Spark 2.4 for backward compatibility. |
| 88 | + * This implementation is no longer maintained, the new implementation is available with Spark 3.x |
| 89 | + */ |
| 90 | + @Deprecated |
| 91 | + public RewriteDataFilesAction rewriteDataFiles() { |
| 92 | + return new RewriteDataFilesAction(spark, table); |
| 93 | + } |
| 94 | + |
| 95 | + protected SparkSession spark() { |
| 96 | + return spark; |
| 97 | + } |
| 98 | + |
| 99 | + protected Table table() { |
| 100 | + return table; |
| 101 | + } |
| 102 | + |
| 103 | +} |
0 commit comments