Skip to content

Commit 58113a7

Browse files
authored
[hive] Drop a Hive external table only deletes metadata but not data files. (#2979)
1 parent 8f8091f commit 58113a7

File tree

7 files changed

+24
-31
lines changed

7 files changed

+24
-31
lines changed

docs/layouts/shortcodes/generated/jdbc_catalog_configuration.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<tbody>
2929
<tr>
3030
<td><h5>catalog-key</h5></td>
31-
<td style="word-wrap: break-word;">(none)</td>
31+
<td style="word-wrap: break-word;">"jdbc"</td>
3232
<td>String</td>
3333
<td>Custom jdbc catalog store key.</td>
3434
</tr>

paimon-core/src/main/java/org/apache/paimon/jdbc/JdbcCatalog.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import org.apache.paimon.schema.SchemaManager;
3232
import org.apache.paimon.schema.TableSchema;
3333
import org.apache.paimon.utils.Preconditions;
34-
import org.apache.paimon.utils.StringUtils;
3534

3635
import org.apache.paimon.shade.guava30.com.google.common.collect.ImmutableMap;
3736
import org.apache.paimon.shade.guava30.com.google.common.collect.Lists;
@@ -78,7 +77,7 @@ public class JdbcCatalog extends AbstractCatalog {
7877
protected JdbcCatalog(
7978
FileIO fileIO, String catalogKey, Map<String, String> config, String warehouse) {
8079
super(fileIO);
81-
this.catalogKey = StringUtils.isBlank(catalogKey) ? "jdbc" : catalogKey;
80+
this.catalogKey = catalogKey;
8281
this.options = config;
8382
this.warehouse = warehouse;
8483
Preconditions.checkNotNull(options, "Invalid catalog properties: null");

paimon-core/src/main/java/org/apache/paimon/jdbc/JdbcCatalogOptions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public final class JdbcCatalogOptions {
2727
public static final ConfigOption<String> CATALOG_KEY =
2828
ConfigOptions.key("catalog-key")
2929
.stringType()
30-
.defaultValue(null)
30+
.defaultValue("jdbc")
3131
.withDescription("Custom jdbc catalog store key.");
3232

3333
private JdbcCatalogOptions() {}

paimon-core/src/main/java/org/apache/paimon/operation/AppendOnlyFileStoreRead.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,15 @@ public RecordReader<InternalRow> createReader(DataSplit split) throws IOExceptio
140140

141141
Pair<int[], RowType> partitionPair = null;
142142
if (!dataSchema.partitionKeys().isEmpty()) {
143-
Pair<int[], int[][]> partitionMappping =
143+
Pair<int[], int[][]> partitionMapping =
144144
PartitionUtils.constructPartitionMapping(
145145
dataSchema, dataProjection);
146146
// if partition fields are not selected, we just do nothing
147-
if (partitionMappping != null) {
148-
dataProjection = partitionMappping.getRight();
147+
if (partitionMapping != null) {
148+
dataProjection = partitionMapping.getRight();
149149
partitionPair =
150150
Pair.of(
151-
partitionMappping.getLeft(),
151+
partitionMapping.getLeft(),
152152
dataSchema.projectedLogicalRowType(
153153
dataSchema.partitionKeys()));
154154
}

paimon-core/src/main/java/org/apache/paimon/utils/BulkFormatMapping.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public CastFieldGetter[] getCastMapping() {
6464
return castMapping;
6565
}
6666

67+
@Nullable
6768
public Pair<int[], RowType> getPartitionPair() {
6869
return partitionPair;
6970
}
@@ -166,15 +167,15 @@ public BulkFormatMapping build(
166167

167168
Pair<int[], RowType> partitionPair = null;
168169
if (!dataSchema.partitionKeys().isEmpty()) {
169-
Pair<int[], int[][]> partitionMappping =
170+
Pair<int[], int[][]> partitionMapping =
170171
PartitionUtils.constructPartitionMapping(
171172
dataRecordType, dataSchema.partitionKeys(), dataProjection);
172173
// is partition fields are not selected, we just do nothing.
173-
if (partitionMappping != null) {
174-
dataProjection = partitionMappping.getRight();
174+
if (partitionMapping != null) {
175+
dataProjection = partitionMapping.getRight();
175176
partitionPair =
176177
Pair.of(
177-
partitionMappping.getLeft(),
178+
partitionMapping.getLeft(),
178179
dataSchema.projectedLogicalRowType(dataSchema.partitionKeys()));
179180
}
180181
}

paimon-hive/paimon-hive-catalog/src/main/java/org/apache/paimon/hive/HiveCatalog.java

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@
8787
import static org.apache.paimon.options.CatalogOptions.TABLE_TYPE;
8888
import static org.apache.paimon.options.OptionsUtils.convertToPropertiesPrefixKey;
8989
import static org.apache.paimon.utils.Preconditions.checkArgument;
90-
import static org.apache.paimon.utils.Preconditions.checkState;
9190
import static org.apache.paimon.utils.StringUtils.isNullOrWhitespaceOnly;
9291

9392
/** A catalog implementation for Hive. */
@@ -349,6 +348,17 @@ protected void dropTableImpl(Identifier identifier) {
349348
try {
350349
client.dropTable(
351350
identifier.getDatabaseName(), identifier.getObjectName(), true, false, true);
351+
352+
// When drop a Hive external table, only the hive metadata is deleted and the data files
353+
// are not deleted.
354+
TableType tableType =
355+
OptionsUtils.convertToEnum(
356+
hiveConf.get(TABLE_TYPE.key(), TableType.MANAGED.toString()),
357+
TableType.class);
358+
if (TableType.EXTERNAL.equals(tableType)) {
359+
return;
360+
}
361+
352362
// Deletes table directory to avoid schema in filesystem exists after dropping hive
353363
// table successfully to keep the table consistency between which in filesystem and
354364
// which in Hive metastore.
@@ -468,19 +478,6 @@ public String warehouse() {
468478
return warehouse;
469479
}
470480

471-
private void checkIdentifierUpperCase(Identifier identifier) {
472-
checkState(
473-
identifier.getDatabaseName().equals(identifier.getDatabaseName().toLowerCase()),
474-
String.format(
475-
"Database name[%s] cannot contain upper case in hive catalog",
476-
identifier.getDatabaseName()));
477-
checkState(
478-
identifier.getObjectName().equals(identifier.getObjectName().toLowerCase()),
479-
String.format(
480-
"Table name[%s] cannot contain upper case in hive catalog",
481-
identifier.getObjectName()));
482-
}
483-
484481
private Table newHmsTable(Identifier identifier, Map<String, String> tableParameters) {
485482
long currentTimeMillis = System.currentTimeMillis();
486483
TableType tableType =
@@ -587,10 +584,6 @@ private FieldSchema convertToFieldSchema(DataField dataField) {
587584
dataField.description());
588585
}
589586

590-
private boolean schemaFileExists(Identifier identifier) {
591-
return new SchemaManager(fileIO, getDataTableLocation(identifier)).latest().isPresent();
592-
}
593-
594587
private SchemaManager schemaManager(Identifier identifier) {
595588
return new SchemaManager(fileIO, getDataTableLocation(identifier))
596589
.withLock(lock(identifier));

paimon-hive/paimon-hive-connector-common/src/test/java/org/apache/paimon/hive/HiveCatalogITCaseBase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ public void testCreateExternalTable() throws Exception {
277277
.isTrue();
278278
tEnv.executeSql("DROP TABLE t").await();
279279
Path tablePath = new Path(path, "test_db.db/t");
280-
assertThat(tablePath.getFileSystem().exists(tablePath)).isFalse();
280+
assertThat(tablePath.getFileSystem().exists(tablePath)).isTrue();
281281
}
282282

283283
@Test

0 commit comments

Comments
 (0)