com.netease.arctic.table.BasicUnkeyedTable Maven / Gradle / Ivy
The newest version!
/*
* 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 com.netease.arctic.table;
import com.netease.arctic.AmsClient;
import com.netease.arctic.io.ArcticFileIO;
import com.netease.arctic.op.PartitionPropertiesUpdate;
import com.netease.arctic.op.UpdatePartitionProperties;
import com.netease.arctic.trace.AmsTableTracer;
import com.netease.arctic.trace.ArcticAppendFiles;
import com.netease.arctic.trace.ArcticOverwriteFiles;
import com.netease.arctic.trace.ArcticReplacePartitions;
import com.netease.arctic.trace.ArcticRowDelta;
import com.netease.arctic.trace.TableTracer;
import com.netease.arctic.trace.TraceOperations;
import com.netease.arctic.trace.TracedDeleteFiles;
import com.netease.arctic.trace.TracedRewriteFiles;
import com.netease.arctic.trace.TracedSchemaUpdate;
import com.netease.arctic.trace.TracedTransaction;
import com.netease.arctic.trace.TracedUpdateProperties;
import com.netease.arctic.utils.CatalogUtil;
import com.netease.arctic.utils.TablePropertyUtil;
import com.netease.arctic.shade.org.apache.iceberg.AppendFiles;
import com.netease.arctic.shade.org.apache.iceberg.DeleteFiles;
import com.netease.arctic.shade.org.apache.iceberg.ExpireSnapshots;
import com.netease.arctic.shade.org.apache.iceberg.HasTableOperations;
import com.netease.arctic.shade.org.apache.iceberg.HistoryEntry;
import com.netease.arctic.shade.org.apache.iceberg.ManageSnapshots;
import com.netease.arctic.shade.org.apache.iceberg.OverwriteFiles;
import com.netease.arctic.shade.org.apache.iceberg.PartitionSpec;
import com.netease.arctic.shade.org.apache.iceberg.ReplacePartitions;
import com.netease.arctic.shade.org.apache.iceberg.ReplaceSortOrder;
import com.netease.arctic.shade.org.apache.iceberg.RewriteFiles;
import com.netease.arctic.shade.org.apache.iceberg.RewriteManifests;
import com.netease.arctic.shade.org.apache.iceberg.Rollback;
import com.netease.arctic.shade.org.apache.iceberg.RowDelta;
import com.netease.arctic.shade.org.apache.iceberg.Schema;
import com.netease.arctic.shade.org.apache.iceberg.Snapshot;
import com.netease.arctic.shade.org.apache.iceberg.SortOrder;
import com.netease.arctic.shade.org.apache.iceberg.Table;
import com.netease.arctic.shade.org.apache.iceberg.TableOperations;
import com.netease.arctic.shade.org.apache.iceberg.TableScan;
import com.netease.arctic.shade.org.apache.iceberg.Transaction;
import com.netease.arctic.shade.org.apache.iceberg.UpdateLocation;
import com.netease.arctic.shade.org.apache.iceberg.UpdatePartitionSpec;
import com.netease.arctic.shade.org.apache.iceberg.UpdateProperties;
import com.netease.arctic.shade.org.apache.iceberg.UpdateSchema;
import com.netease.arctic.shade.org.apache.iceberg.encryption.EncryptionManager;
import com.netease.arctic.shade.org.apache.iceberg.io.LocationProvider;
import com.netease.arctic.shade.org.apache.iceberg.util.StructLikeMap;
import java.util.List;
import java.util.Map;
/**
* Basic implementation of {@link UnkeyedTable}, wrapping a {@link Table}.
*/
public class BasicUnkeyedTable implements UnkeyedTable, HasTableOperations {
private final Map catalogProperties;
private final TableIdentifier tableIdentifier;
protected final Table icebergTable;
protected final ArcticFileIO arcticFileIO;
private final AmsClient client;
public BasicUnkeyedTable(
TableIdentifier tableIdentifier, Table icebergTable, ArcticFileIO arcticFileIO,
AmsClient client, Map catalogProperties) {
this.tableIdentifier = tableIdentifier;
this.icebergTable = icebergTable;
this.arcticFileIO = arcticFileIO;
this.client = client;
this.catalogProperties = catalogProperties;
}
@Override
public void refresh() {
icebergTable.refresh();
}
@Override
public TableScan newScan() {
return icebergTable.newScan();
}
@Override
public TableIdentifier id() {
return tableIdentifier;
}
@Override
public Schema schema() {
return icebergTable.schema();
}
@Override
public Map schemas() {
return icebergTable.schemas();
}
@Override
public PartitionSpec spec() {
return icebergTable.spec();
}
@Override
public Map specs() {
return icebergTable.specs();
}
@Override
public SortOrder sortOrder() {
return icebergTable.sortOrder();
}
@Override
public Map sortOrders() {
return icebergTable.sortOrders();
}
@Override
public Map properties() {
if (catalogProperties == null) {
return icebergTable.properties();
} else {
return CatalogUtil.mergeCatalogPropertiesToTable(icebergTable.properties(), catalogProperties);
}
}
@Override
public String location() {
return icebergTable.location();
}
@Override
public Snapshot currentSnapshot() {
return icebergTable.currentSnapshot();
}
@Override
public Snapshot snapshot(long snapshotId) {
return icebergTable.snapshot(snapshotId);
}
@Override
public Iterable snapshots() {
return icebergTable.snapshots();
}
@Override
public List history() {
return icebergTable.history();
}
@Override
public UpdateSchema updateSchema() {
if (client != null) {
return new TracedSchemaUpdate(icebergTable.updateSchema(),
new AmsTableTracer(this, TraceOperations.UPDATE_SCHEMA, client, false));
} else {
return icebergTable.updateSchema();
}
}
@Override
public UpdatePartitionSpec updateSpec() {
return icebergTable.updateSpec();
}
@Override
public UpdateProperties updateProperties() {
UpdateProperties updateProperties = icebergTable.updateProperties();
if (client != null) {
AmsTableTracer tracer = new AmsTableTracer(this, TraceOperations.UPDATE_PROPERTIES, client, false);
return new TracedUpdateProperties(updateProperties, tracer);
} else {
return updateProperties;
}
}
@Override
public ReplaceSortOrder replaceSortOrder() {
return icebergTable.replaceSortOrder();
}
@Override
public UpdateLocation updateLocation() {
return icebergTable.updateLocation();
}
@Override
public AppendFiles newAppend() {
return ArcticAppendFiles.buildFor(this, false)
.traceTable(client, this).onTableStore(icebergTable).build();
}
@Override
public AppendFiles newFastAppend() {
return ArcticAppendFiles.buildFor(this, true)
.traceTable(client, this).onTableStore(icebergTable).build();
}
@Override
public RewriteFiles newRewrite() {
RewriteFiles rewriteFiles = icebergTable.newRewrite();
if (client != null) {
TableTracer tracer = new AmsTableTracer(this, TraceOperations.REPLACE, client, true);
return new TracedRewriteFiles(rewriteFiles, tracer);
} else {
return rewriteFiles;
}
}
@Override
public RewriteManifests rewriteManifests() {
return icebergTable.rewriteManifests();
}
@Override
public OverwriteFiles newOverwrite() {
return ArcticOverwriteFiles.buildFor(this)
.traceTable(client, this).onTableStore(icebergTable).build();
}
@Override
public RowDelta newRowDelta() {
return ArcticRowDelta.buildFor(this)
.traceTable(client, this).onTableStore(icebergTable).build();
}
@Override
public ReplacePartitions newReplacePartitions() {
return ArcticReplacePartitions.buildFor(this)
.traceTable(client, this).onTableStore(icebergTable).build();
}
@Override
public DeleteFiles newDelete() {
DeleteFiles deleteFiles = icebergTable.newDelete();
if (client != null) {
TableTracer tracer = new AmsTableTracer(this, TraceOperations.DELETE, client, true);
return new TracedDeleteFiles(deleteFiles, tracer);
} else {
return deleteFiles;
}
}
@Override
public ExpireSnapshots expireSnapshots() {
return icebergTable.expireSnapshots();
}
@Override
public Rollback rollback() {
return icebergTable.rollback();
}
@Override
public ManageSnapshots manageSnapshots() {
return icebergTable.manageSnapshots();
}
@Override
public Transaction newTransaction() {
Transaction transaction = icebergTable.newTransaction();
if (client != null) {
return new TracedTransaction(this, transaction, new AmsTableTracer(this, client, false));
} else {
return transaction;
}
}
@Override
public ArcticFileIO io() {
return arcticFileIO;
}
@Override
public EncryptionManager encryption() {
return icebergTable.encryption();
}
@Override
public LocationProvider locationProvider() {
return icebergTable.locationProvider();
}
@Override
public TableOperations operations() {
if (icebergTable instanceof HasTableOperations) {
return ((HasTableOperations) icebergTable).operations();
}
throw new UnsupportedOperationException();
}
@Override
public StructLikeMap
© 2015 - 2025 Weber Informatics LLC | Privacy Policy