-
Notifications
You must be signed in to change notification settings - Fork 288
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ARCTIC-497] fix When adding cloumn to keyed hive table with partitio…
…ns, the scheam sequence of change table and base table is different (#501) * add HiveChangeInternalTable and BaseSchemaUpdate * fix code style
- Loading branch information
1 parent
a175622
commit bb1fa59
Showing
6 changed files
with
193 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
156 changes: 156 additions & 0 deletions
156
hive/src/main/java/com/netease/arctic/hive/op/BaseSchemaUpdate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
/* | ||
* 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.hive.op; | ||
|
||
import com.netease.arctic.table.ArcticTable; | ||
import org.apache.iceberg.PartitionField; | ||
import org.apache.iceberg.Schema; | ||
import org.apache.iceberg.UpdateSchema; | ||
import org.apache.iceberg.types.Type; | ||
import org.apache.iceberg.types.Types; | ||
|
||
import java.util.Collection; | ||
|
||
public class BaseSchemaUpdate implements UpdateSchema { | ||
|
||
private final ArcticTable arcticTable; | ||
private final UpdateSchema updateSchema; | ||
|
||
public BaseSchemaUpdate(ArcticTable arcticTable, UpdateSchema updateSchema) { | ||
this.arcticTable = arcticTable; | ||
this.updateSchema = updateSchema; | ||
} | ||
|
||
@Override | ||
public Schema apply() { | ||
return this.updateSchema.apply(); | ||
} | ||
|
||
@Override | ||
public void commit() { | ||
this.updateSchema.commit(); | ||
} | ||
|
||
@Override | ||
public UpdateSchema allowIncompatibleChanges() { | ||
throw new UnsupportedOperationException("hive table not support allowIncompatibleChanges"); | ||
} | ||
|
||
@Override | ||
public UpdateSchema addColumn(String name, Type type, String doc) { | ||
this.updateSchema.addColumn(name, type, doc); | ||
moveColBeforePar(name); | ||
return this; | ||
} | ||
|
||
@Override | ||
public UpdateSchema addColumn(String parent, String name, Type type, String doc) { | ||
this.updateSchema.addColumn(parent, name, type, doc); | ||
if (parent == null) { | ||
moveColBeforePar(name); | ||
} | ||
return this; | ||
} | ||
|
||
@Override | ||
public UpdateSchema addRequiredColumn(String name, Type type, String doc) { | ||
throw new UnsupportedOperationException("hive table not support addRequiredColumn"); | ||
} | ||
|
||
@Override | ||
public UpdateSchema addRequiredColumn(String parent, String name, Type type, String doc) { | ||
throw new UnsupportedOperationException("hive table not support addRequiredColumn"); | ||
} | ||
|
||
@Override | ||
public UpdateSchema renameColumn(String name, String newName) { | ||
throw new UnsupportedOperationException("not support renameColumn now, there will be error when hive stored as " + | ||
"parquet and we rename the column"); | ||
} | ||
|
||
@Override | ||
public UpdateSchema updateColumn(String name, Type.PrimitiveType newType) { | ||
this.updateSchema.updateColumn(name, newType); | ||
return this; | ||
} | ||
|
||
@Override | ||
public UpdateSchema updateColumnDoc(String name, String newDoc) { | ||
this.updateSchema.updateColumnDoc(name, newDoc); | ||
return this; | ||
} | ||
|
||
@Override | ||
public UpdateSchema makeColumnOptional(String name) { | ||
throw new UnsupportedOperationException("hive table not support makeColumnOptional"); | ||
} | ||
|
||
@Override | ||
public UpdateSchema requireColumn(String name) { | ||
throw new UnsupportedOperationException("hive table not support requireColumn"); | ||
} | ||
|
||
@Override | ||
public UpdateSchema deleteColumn(String name) { | ||
throw new UnsupportedOperationException("hive table not support deleteColumn"); | ||
} | ||
|
||
@Override | ||
public UpdateSchema moveFirst(String name) { | ||
throw new UnsupportedOperationException("hive table not support moveFirst"); | ||
} | ||
|
||
@Override | ||
public UpdateSchema moveBefore(String name, String beforeName) { | ||
throw new UnsupportedOperationException("hive table not support moveBefore"); | ||
} | ||
|
||
@Override | ||
public UpdateSchema moveAfter(String name, String afterName) { | ||
throw new UnsupportedOperationException("hive table not support moveAfter"); | ||
} | ||
|
||
@Override | ||
public UpdateSchema unionByNameWith(Schema newSchema) { | ||
throw new UnsupportedOperationException("hive table not support unionByNameWith"); | ||
} | ||
|
||
@Override | ||
public UpdateSchema setIdentifierFields(Collection<String> names) { | ||
throw new UnsupportedOperationException("hive table not support setIdentifierFields"); | ||
} | ||
|
||
//It is strictly required that all non-partitioned columns precede partitioned columns in the schema. | ||
private void moveColBeforePar(String name) { | ||
if (!arcticTable.spec().isUnpartitioned()) { | ||
int parFieldMinIndex = Integer.MAX_VALUE; | ||
Types.NestedField firstParField = null; | ||
for (PartitionField partitionField : arcticTable.spec().fields()) { | ||
Types.NestedField sourceField = arcticTable.schema().findField(partitionField.sourceId()); | ||
if (arcticTable.schema().columns().indexOf(sourceField) < parFieldMinIndex) { | ||
parFieldMinIndex = arcticTable.schema().columns().indexOf(sourceField); | ||
firstParField = sourceField; | ||
} | ||
} | ||
if (firstParField != null) { | ||
this.updateSchema.moveBefore(name, firstParField.name()); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters