-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[590] Add Iceberg HMS Catalog Sync implementation
- Loading branch information
1 parent
d60625c
commit 25bf942
Showing
30 changed files
with
2,637 additions
and
13 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
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
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
33 changes: 33 additions & 0 deletions
33
xtable-core/src/main/java/org/apache/xtable/catalog/CatalogTableBuilder.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,33 @@ | ||
/* | ||
* 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.xtable.catalog; | ||
|
||
import org.apache.xtable.model.InternalTable; | ||
import org.apache.xtable.model.catalog.CatalogTableIdentifier; | ||
|
||
/** | ||
* The interface for creating/updating catalog table object, each catalog can have its own | ||
* implementation that can be plugged in. | ||
*/ | ||
public interface CatalogTableBuilder<REQUEST, TABLE> { | ||
public REQUEST getCreateTableRequest(InternalTable table, CatalogTableIdentifier tableIdentifier); | ||
|
||
public REQUEST getUpdateTableRequest( | ||
InternalTable table, TABLE catalogTable, CatalogTableIdentifier tableIdentifier); | ||
} |
33 changes: 33 additions & 0 deletions
33
xtable-core/src/main/java/org/apache/xtable/catalog/CatalogUtils.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,33 @@ | ||
/* | ||
* 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.xtable.catalog; | ||
|
||
import org.apache.xtable.model.catalog.CatalogTableIdentifier; | ||
import org.apache.xtable.model.catalog.HierarchicalTableIdentifier; | ||
|
||
public class CatalogUtils { | ||
|
||
public static HierarchicalTableIdentifier castToHierarchicalTableIdentifier( | ||
CatalogTableIdentifier tableIdentifier) { | ||
if (tableIdentifier instanceof HierarchicalTableIdentifier) { | ||
return (HierarchicalTableIdentifier) tableIdentifier; | ||
} | ||
throw new IllegalArgumentException("Invalid tableIdentifier implementation"); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
xtable-core/src/main/java/org/apache/xtable/catalog/Constants.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,27 @@ | ||
/* | ||
* 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.xtable.catalog; | ||
|
||
public class Constants { | ||
|
||
public static final String PROP_SPARK_SQL_SOURCES_PROVIDER = "spark.sql.sources.provider"; | ||
public static final String PROP_PATH = "path"; | ||
public static final String PROP_SERIALIZATION_FORMAT = "serialization.format"; | ||
public static final String PROP_EXTERNAL = "EXTERNAL"; | ||
} |
76 changes: 76 additions & 0 deletions
76
xtable-core/src/main/java/org/apache/xtable/catalog/TableFormatUtils.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,76 @@ | ||
/* | ||
* 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.xtable.catalog; | ||
|
||
import static org.apache.iceberg.BaseMetastoreTableOperations.TABLE_TYPE_PROP; | ||
import static org.apache.xtable.catalog.Constants.PROP_SPARK_SQL_SOURCES_PROVIDER; | ||
|
||
import java.util.Map; | ||
|
||
import org.apache.iceberg.TableProperties; | ||
|
||
import com.google.common.base.Strings; | ||
|
||
import org.apache.xtable.exception.NotSupportedException; | ||
import org.apache.xtable.model.storage.TableFormat; | ||
|
||
public class TableFormatUtils { | ||
|
||
public static String getTableDataLocation( | ||
String tableFormat, String tableLocation, Map<String, String> properties) { | ||
switch (tableFormat) { | ||
case TableFormat.ICEBERG: | ||
return getIcebergDataLocation(tableLocation, properties); | ||
case TableFormat.DELTA: | ||
case TableFormat.HUDI: | ||
return tableLocation; | ||
default: | ||
throw new NotSupportedException("Unsupported table format: " + tableFormat); | ||
} | ||
} | ||
|
||
/** Get iceberg table data files location */ | ||
private static String getIcebergDataLocation( | ||
String tableLocation, Map<String, String> properties) { | ||
String dataLocation = properties.get(TableProperties.WRITE_DATA_LOCATION); | ||
if (dataLocation == null) { | ||
dataLocation = properties.get(TableProperties.WRITE_FOLDER_STORAGE_LOCATION); | ||
if (dataLocation == null) { | ||
dataLocation = properties.get(TableProperties.OBJECT_STORE_PATH); | ||
if (dataLocation == null) { | ||
dataLocation = String.format("%s/data", tableLocation); | ||
} | ||
} | ||
} | ||
return dataLocation; | ||
} | ||
|
||
// Get table format name from table properties | ||
public static String getTableFormat(Map<String, String> properties) { | ||
// - In case of ICEBERG, table_type param will give the table format | ||
// - In case of DELTA, table_type or spark.sql.sources.provider param will give the table | ||
// format | ||
// - In case of HUDI, spark.sql.sources.provider param will give the table format | ||
String tableFormat = properties.get(TABLE_TYPE_PROP); | ||
if (Strings.isNullOrEmpty(tableFormat)) { | ||
tableFormat = properties.get(PROP_SPARK_SQL_SOURCES_PROVIDER); | ||
} | ||
return tableFormat; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
xtable-core/src/main/java/org/apache/xtable/exception/CatalogSyncException.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,33 @@ | ||
/* | ||
* 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.xtable.exception; | ||
|
||
import org.apache.xtable.model.exception.ErrorCode; | ||
import org.apache.xtable.model.exception.InternalException; | ||
|
||
public class CatalogSyncException extends InternalException { | ||
|
||
public CatalogSyncException(ErrorCode errorCode, String message, Throwable e) { | ||
super(errorCode, message, e); | ||
} | ||
|
||
public CatalogSyncException(String message, Throwable e) { | ||
super(ErrorCode.CATALOG_SYNC_GENERIC_EXCEPTION, message, e); | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
xtable-core/src/test/java/org/apache/xtable/catalog/TestSchemaExtractorBase.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,78 @@ | ||
/* | ||
* 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.xtable.catalog; | ||
|
||
import java.util.Collections; | ||
import java.util.Map; | ||
|
||
import org.apache.xtable.model.schema.InternalField; | ||
import org.apache.xtable.model.schema.InternalSchema; | ||
import org.apache.xtable.model.schema.InternalType; | ||
|
||
public class TestSchemaExtractorBase { | ||
protected static InternalField getPrimitiveOneField( | ||
String fieldName, String schemaName, InternalType dataType, boolean isNullable, int fieldId) { | ||
return getPrimitiveOneField( | ||
fieldName, schemaName, dataType, isNullable, fieldId, Collections.emptyMap()); | ||
} | ||
|
||
protected static InternalField getPrimitiveOneField( | ||
String fieldName, | ||
String schemaName, | ||
InternalType dataType, | ||
boolean isNullable, | ||
int fieldId, | ||
String parentPath) { | ||
return getPrimitiveOneField( | ||
fieldName, schemaName, dataType, isNullable, fieldId, parentPath, Collections.emptyMap()); | ||
} | ||
|
||
protected static InternalField getPrimitiveOneField( | ||
String fieldName, | ||
String schemaName, | ||
InternalType dataType, | ||
boolean isNullable, | ||
int fieldId, | ||
Map<InternalSchema.MetadataKey, Object> metadata) { | ||
return getPrimitiveOneField( | ||
fieldName, schemaName, dataType, isNullable, fieldId, null, metadata); | ||
} | ||
|
||
protected static InternalField getPrimitiveOneField( | ||
String fieldName, | ||
String schemaName, | ||
InternalType dataType, | ||
boolean isNullable, | ||
int fieldId, | ||
String parentPath, | ||
Map<InternalSchema.MetadataKey, Object> metadata) { | ||
return InternalField.builder() | ||
.name(fieldName) | ||
.parentPath(parentPath) | ||
.schema( | ||
InternalSchema.builder() | ||
.name(schemaName) | ||
.dataType(dataType) | ||
.isNullable(isNullable) | ||
.metadata(metadata) | ||
.build()) | ||
.fieldId(fieldId) | ||
.build(); | ||
} | ||
} |
Oops, something went wrong.