-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Expand file tree
/
Copy pathTable.java
More file actions
388 lines (340 loc) · 10.8 KB
/
Copy pathTable.java
File metadata and controls
388 lines (340 loc) · 10.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
/*
* 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 java.util.List;
import java.util.Map;
import java.util.UUID;
import org.apache.iceberg.encryption.EncryptionManager;
import org.apache.iceberg.io.FileIO;
import org.apache.iceberg.io.LocationProvider;
import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList;
/** Represents a table. */
public interface Table {
/**
* Return the full name for this table.
*
* @return this table's name
*/
default String name() {
return toString();
}
/** Refresh the current table metadata. */
void refresh();
/**
* Create a new {@link TableScan scan} for this table.
*
* <p>Once a table scan is created, it can be refined to project columns and filter data.
*
* @return a table scan for this table
*/
TableScan newScan();
/**
* Create a new {@link BatchScan batch scan} for this table.
*
* <p>Once a batch scan is created, it can be refined to project columns and filter data.
*
* @return a batch scan for this table
*/
default BatchScan newBatchScan() {
return new BatchScanAdapter(newScan());
}
/**
* Create a new {@link IncrementalAppendScan scan} for this table.
*
* <p>Once a scan is created, it can be refined to project columns and filter data.
*
* @return an incremental scan for appends only snapshots
*/
default IncrementalAppendScan newIncrementalAppendScan() {
throw new UnsupportedOperationException("Incremental append scan is not supported");
}
/**
* Create a new {@link IncrementalChangelogScan} for this table.
*
* <p>Once a scan is created, it can be refined to project columns and filter data.
*
* @return an incremental changelog scan
*/
default IncrementalChangelogScan newIncrementalChangelogScan() {
throw new UnsupportedOperationException("Incremental changelog scan is not supported");
}
/**
* Create a new {@link PartitionStatisticsScan} for this table.
*
* <p>Once a partition statistics scan is created, it can be refined to project columns and filter
* data.
*
* @return a partition statistics scan for this table
*/
default PartitionStatisticsScan newPartitionStatisticsScan() {
throw new UnsupportedOperationException("Partition statistics scan is not supported");
}
/**
* Return the {@link Schema schema} for this table.
*
* @return this table's schema
*/
Schema schema();
/**
* Return a map of {@link Schema schema} for this table.
*
* @return this table's schema map
*/
Map<Integer, Schema> schemas();
/**
* Return the {@link PartitionSpec partition spec} for this table.
*
* @return this table's partition spec
*/
PartitionSpec spec();
/**
* Return a map of {@link PartitionSpec partition specs} for this table.
*
* @return this table's partition specs map
*/
Map<Integer, PartitionSpec> specs();
/**
* Return the {@link SortOrder sort order} for this table.
*
* @return this table's sort order
*/
SortOrder sortOrder();
/**
* Return a map of sort order IDs to {@link SortOrder sort orders} for this table.
*
* @return this table's sort orders map
*/
Map<Integer, SortOrder> sortOrders();
/**
* Return a map of string properties for this table.
*
* @return this table's properties map
*/
Map<String, String> properties();
/**
* Return the table's base location.
*
* @return this table's location
*/
String location();
/**
* Get the current {@link Snapshot snapshot} for this table, or null if there are no snapshots.
*
* @return the current table Snapshot.
*/
Snapshot currentSnapshot();
/**
* Get the {@link Snapshot snapshot} of this table with the given id, or null if there is no
* matching snapshot.
*
* @return the {@link Snapshot} with the given id.
*/
Snapshot snapshot(long snapshotId);
/**
* Get the {@link Snapshot snapshots} of this table.
*
* @return an Iterable of snapshots of this table.
*/
Iterable<Snapshot> snapshots();
/**
* Get the snapshot history of this table.
*
* @return a list of {@link HistoryEntry history entries}
*/
List<HistoryEntry> history();
/**
* Create a new {@link UpdateSchema} to alter the columns of this table and commit the change.
*
* @return a new {@link UpdateSchema}
*/
UpdateSchema updateSchema();
/**
* Create a new {@link UpdatePartitionSpec} to alter the partition spec of this table and commit
* the change.
*
* @return a new {@link UpdatePartitionSpec}
*/
UpdatePartitionSpec updateSpec();
/**
* Create a new {@link UpdateProperties} to update table properties and commit the changes.
*
* @return a new {@link UpdateProperties}
*/
UpdateProperties updateProperties();
/**
* Create a new {@link ReplaceSortOrder} to set the table sort order and commit the change.
*
* @return a new {@link ReplaceSortOrder}
*/
ReplaceSortOrder replaceSortOrder();
/**
* Create a new {@link UpdateLocation} to update table location and commit the changes.
*
* @return a new {@link UpdateLocation}
*/
UpdateLocation updateLocation();
/**
* Create a new {@link AppendFiles append API} to add files to this table and commit.
*
* @return a new {@link AppendFiles}
*/
AppendFiles newAppend();
/**
* Create a new {@link AppendFiles append API} to add files to this table and commit.
*
* <p>Using this method signals to the underlying implementation that the append should not
* perform extra work in order to commit quickly. Fast appends are not recommended for normal
* writes because the fast commit may cause split planning to slow down over time.
*
* <p>Implementations may not support fast appends, in which case this will return the same
* appender as {@link #newAppend()}.
*
* @return a new {@link AppendFiles}
*/
default AppendFiles newFastAppend() {
return newAppend();
}
/**
* Create a new {@link RewriteFiles rewrite API} to replace files in this table and commit.
*
* @return a new {@link RewriteFiles}
*/
RewriteFiles newRewrite();
/**
* Create a new {@link RewriteManifests rewrite manifests API} to replace manifests for this table
* and commit.
*
* @return a new {@link RewriteManifests}
*/
RewriteManifests rewriteManifests();
/**
* Create a new {@link OverwriteFiles overwrite API} to overwrite files by a filter expression.
*
* @return a new {@link OverwriteFiles}
*/
OverwriteFiles newOverwrite();
/**
* Create a new {@link RowDelta row-level delta API} to remove or replace rows in existing data
* files.
*
* @return a new {@link RowDelta}
*/
RowDelta newRowDelta();
/**
* Not recommended: Create a new {@link ReplacePartitions replace partitions API} to dynamically
* overwrite partitions in the table with new data.
*
* <p>This is provided to implement SQL compatible with Hive table operations but is not
* recommended. Instead, use the {@link OverwriteFiles overwrite API} to explicitly overwrite
* data.
*
* @return a new {@link ReplacePartitions}
*/
ReplacePartitions newReplacePartitions();
/**
* Create a new {@link DeleteFiles delete API} to delete files in this table and commit.
*
* @return a new {@link DeleteFiles}
*/
DeleteFiles newDelete();
/**
* Create a new {@link UpdateStatistics update table statistics API} to add or remove statistics
* files in this table.
*
* @return a new {@link UpdateStatistics}
*/
default UpdateStatistics updateStatistics() {
throw new UnsupportedOperationException(
"Updating statistics is not supported by " + getClass().getName());
}
/**
* Create a new {@link UpdatePartitionStatistics update partition statistics API} to add or remove
* partition statistics files in this table.
*
* @return a new {@link UpdatePartitionStatistics}
*/
default UpdatePartitionStatistics updatePartitionStatistics() {
throw new UnsupportedOperationException(
"Updating partition statistics is not supported by " + getClass().getName());
}
/**
* Create a new {@link ExpireSnapshots expire API} to expire snapshots in this table and commit.
*
* @return a new {@link ExpireSnapshots}
*/
ExpireSnapshots expireSnapshots();
/**
* Create a new {@link ManageSnapshots manage snapshots API} to manage snapshots in this table and
* commit.
*
* @return a new {@link ManageSnapshots}
*/
ManageSnapshots manageSnapshots();
/**
* Create a new {@link Transaction transaction API} to commit multiple table operations at once.
*
* @return a new {@link Transaction}
*/
Transaction newTransaction();
/** Returns a {@link FileIO} to read and write table data and metadata files. */
FileIO io();
/**
* Returns an {@link org.apache.iceberg.encryption.EncryptionManager} to encrypt and decrypt data
* files.
*/
EncryptionManager encryption();
/** Returns a {@link LocationProvider} to provide locations for new data files. */
LocationProvider locationProvider();
/**
* Returns the current statistics files for the table
*
* @return the current statistics files for the table
*/
List<StatisticsFile> statisticsFiles();
/** Returns the current partition statistics files for the table. */
default List<PartitionStatisticsFile> partitionStatisticsFiles() {
return ImmutableList.of();
}
/**
* Returns the current refs for the table
*
* @return the current refs for the table
*/
Map<String, SnapshotRef> refs();
/**
* Returns the UUID of the table
*
* @return the UUID of the table
*/
default UUID uuid() {
throw new UnsupportedOperationException(this.getClass().getName() + " doesn't implement uuid");
}
/**
* Returns the snapshot referenced by the given name or null if no such reference exists.
*
* @return the snapshot which is referenced by the given name or null if no such reference exists.
*/
default Snapshot snapshot(String name) {
SnapshotRef ref = refs().get(name);
if (ref != null) {
return snapshot(ref.snapshotId());
}
return null;
}
}