|
| 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, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | +package org.apache.beam.io.iceberg; |
| 19 | + |
| 20 | +import com.google.auto.value.AutoValue; |
| 21 | +import java.io.Serializable; |
| 22 | +import org.apache.beam.sdk.schemas.Schema; |
| 23 | +import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.collect.ImmutableMap; |
| 24 | +import org.apache.iceberg.Table; |
| 25 | +import org.apache.iceberg.catalog.TableIdentifier; |
| 26 | +import org.apache.iceberg.expressions.Expression; |
| 27 | +import org.checkerframework.checker.nullness.qual.MonotonicNonNull; |
| 28 | +import org.checkerframework.checker.nullness.qual.Nullable; |
| 29 | +import org.checkerframework.dataflow.qual.Pure; |
| 30 | + |
| 31 | +@AutoValue |
| 32 | +public abstract class IcebergScanConfig implements Serializable { |
| 33 | + |
| 34 | + private transient @MonotonicNonNull Table cachedTable; |
| 35 | + |
| 36 | + public enum ScanType { |
| 37 | + TABLE, |
| 38 | + BATCH |
| 39 | + } |
| 40 | + |
| 41 | + @Pure |
| 42 | + public abstract ScanType getScanType(); |
| 43 | + |
| 44 | + @Pure |
| 45 | + public abstract IcebergCatalogConfig getCatalogConfig(); |
| 46 | + |
| 47 | + @Pure |
| 48 | + public abstract String getTableIdentifier(); |
| 49 | + |
| 50 | + @Pure |
| 51 | + public Table getTable() { |
| 52 | + if (cachedTable == null) { |
| 53 | + cachedTable = |
| 54 | + getCatalogConfig().catalog().loadTable(TableIdentifier.parse(getTableIdentifier())); |
| 55 | + } |
| 56 | + return cachedTable; |
| 57 | + } |
| 58 | + |
| 59 | + @Pure |
| 60 | + public abstract Schema getSchema(); |
| 61 | + |
| 62 | + @Pure |
| 63 | + public abstract @Nullable Expression getFilter(); |
| 64 | + |
| 65 | + @Pure |
| 66 | + public abstract @Nullable Boolean getCaseSensitive(); |
| 67 | + |
| 68 | + @Pure |
| 69 | + public abstract ImmutableMap<String, String> getOptions(); |
| 70 | + |
| 71 | + @Pure |
| 72 | + public abstract @Nullable Long getSnapshot(); |
| 73 | + |
| 74 | + @Pure |
| 75 | + public abstract @Nullable Long getTimestamp(); |
| 76 | + |
| 77 | + @Pure |
| 78 | + public abstract @Nullable Long getFromSnapshotInclusive(); |
| 79 | + |
| 80 | + @Pure |
| 81 | + public abstract @Nullable String getFromSnapshotRefInclusive(); |
| 82 | + |
| 83 | + @Pure |
| 84 | + public abstract @Nullable Long getFromSnapshotExclusive(); |
| 85 | + |
| 86 | + @Pure |
| 87 | + public abstract @Nullable String getFromSnapshotRefExclusive(); |
| 88 | + |
| 89 | + @Pure |
| 90 | + public abstract @Nullable Long getToSnapshot(); |
| 91 | + |
| 92 | + @Pure |
| 93 | + public abstract @Nullable String getToSnapshotRef(); |
| 94 | + |
| 95 | + @Pure |
| 96 | + public abstract @Nullable String getTag(); |
| 97 | + |
| 98 | + @Pure |
| 99 | + public abstract @Nullable String getBranch(); |
| 100 | + |
| 101 | + @Pure |
| 102 | + public static Builder builder() { |
| 103 | + return new AutoValue_IcebergScanConfig.Builder() |
| 104 | + .setScanType(ScanType.TABLE) |
| 105 | + .setFilter(null) |
| 106 | + .setCaseSensitive(null) |
| 107 | + .setOptions(ImmutableMap.of()) |
| 108 | + .setSnapshot(null) |
| 109 | + .setTimestamp(null) |
| 110 | + .setFromSnapshotInclusive(null) |
| 111 | + .setFromSnapshotRefInclusive(null) |
| 112 | + .setFromSnapshotExclusive(null) |
| 113 | + .setFromSnapshotRefExclusive(null) |
| 114 | + .setToSnapshot(null) |
| 115 | + .setToSnapshotRef(null) |
| 116 | + .setTag(null) |
| 117 | + .setBranch(null); |
| 118 | + } |
| 119 | + |
| 120 | + @AutoValue.Builder |
| 121 | + public abstract static class Builder { |
| 122 | + public abstract Builder setScanType(ScanType type); |
| 123 | + |
| 124 | + public abstract Builder setCatalogConfig(IcebergCatalogConfig catalog); |
| 125 | + |
| 126 | + public abstract Builder setTableIdentifier(String tableIdentifier); |
| 127 | + |
| 128 | + public Builder setTableIdentifier(TableIdentifier tableIdentifier) { |
| 129 | + return this.setTableIdentifier(tableIdentifier.toString()); |
| 130 | + } |
| 131 | + |
| 132 | + public Builder setTableIdentifier(String... names) { |
| 133 | + return setTableIdentifier(TableIdentifier.of(names)); |
| 134 | + } |
| 135 | + |
| 136 | + public abstract Builder setSchema(Schema schema); |
| 137 | + |
| 138 | + public abstract Builder setFilter(@Nullable Expression filter); |
| 139 | + |
| 140 | + public abstract Builder setCaseSensitive(@Nullable Boolean caseSensitive); |
| 141 | + |
| 142 | + public abstract Builder setOptions(ImmutableMap<String, String> options); |
| 143 | + |
| 144 | + public abstract Builder setSnapshot(@Nullable Long snapshot); |
| 145 | + |
| 146 | + public abstract Builder setTimestamp(@Nullable Long timestamp); |
| 147 | + |
| 148 | + public abstract Builder setFromSnapshotInclusive(@Nullable Long fromInclusive); |
| 149 | + |
| 150 | + public abstract Builder setFromSnapshotRefInclusive(@Nullable String ref); |
| 151 | + |
| 152 | + public abstract Builder setFromSnapshotExclusive(@Nullable Long fromExclusive); |
| 153 | + |
| 154 | + public abstract Builder setFromSnapshotRefExclusive(@Nullable String ref); |
| 155 | + |
| 156 | + public abstract Builder setToSnapshot(@Nullable Long snapshot); |
| 157 | + |
| 158 | + public abstract Builder setToSnapshotRef(@Nullable String ref); |
| 159 | + |
| 160 | + public abstract Builder setTag(@Nullable String tag); |
| 161 | + |
| 162 | + public abstract Builder setBranch(@Nullable String branch); |
| 163 | + |
| 164 | + public abstract IcebergScanConfig build(); |
| 165 | + } |
| 166 | +} |
0 commit comments