Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.slf4j.LoggerFactory;
import software.amazon.awssdk.services.glue.model.Column;
import software.amazon.awssdk.services.glue.model.DatabaseInput;
import software.amazon.awssdk.services.glue.model.SerDeInfo;
import software.amazon.awssdk.services.glue.model.StorageDescriptor;
import software.amazon.awssdk.services.glue.model.TableInput;

Expand All @@ -55,6 +56,9 @@ private IcebergToGlueConverter() {

private static final Pattern GLUE_DB_PATTERN = Pattern.compile("^[a-z0-9_]{1,252}$");
private static final Pattern GLUE_TABLE_PATTERN = Pattern.compile("^[a-z0-9_]{1,255}$");
public static final String GLUE_TABLE_INPUT_FORMAT = "org.apache.hadoop.mapred.FileInputFormat";
public static final String GLUE_TABLE_OUTPUT_FORMAT = "org.apache.hadoop.mapred.FileOutputFormat";
public static final String GLUE_TABLE_SERDELIB = "org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe";
public static final String ICEBERG_FIELD_USAGE = "iceberg.field.usage";
public static final String ICEBERG_FIELD_TYPE_TYPE_ID = "iceberg.field.type.typeid";
public static final String ICEBERG_FIELD_TYPE_STRING = "iceberg.field.type.string";
Expand Down Expand Up @@ -180,6 +184,9 @@ static void setTableInputInformation(TableInput.Builder tableInputBuilder, Table
.storageDescriptor(StorageDescriptor.builder()
.location(metadata.location())
.columns(toColumns(metadata))
.inputFormat(GLUE_TABLE_INPUT_FORMAT)
.outputFormat(GLUE_TABLE_OUTPUT_FORMAT)
.serdeInfo(SerDeInfo.builder().serializationLibrary(GLUE_TABLE_SERDELIB).build())
.build());
} catch (RuntimeException e) {
LOG.warn("Encountered unexpected exception while converting Iceberg metadata to Glue table information", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.junit.Test;
import software.amazon.awssdk.services.glue.model.Column;
import software.amazon.awssdk.services.glue.model.DatabaseInput;
import software.amazon.awssdk.services.glue.model.SerDeInfo;
import software.amazon.awssdk.services.glue.model.StorageDescriptor;
import software.amazon.awssdk.services.glue.model.TableInput;

Expand Down Expand Up @@ -159,4 +160,60 @@ public void testSetTableInputInformation() {
expectedTableInput.storageDescriptor().columns(),
actualTableInput.storageDescriptor().columns());
}

@Test
public void testSetTableFormatAndSerdeInformation() {
// Actual TableInput
TableInput.Builder actualTableInputBuilder = TableInput.builder();
Schema schema = new Schema(
Types.NestedField.required(0, "col", Types.StringType.get(), "comment_string_col")
);

PartitionSpec partitionSpec = PartitionSpec.builderFor(schema)
.identity("col")
.withSpecId(1000)
.build();

TableMetadata tableMetadata = TableMetadata
.newTableMetadata(schema, partitionSpec, "s3://test", ImmutableMap.of());
IcebergToGlueConverter.setTableInputInformation(actualTableInputBuilder, tableMetadata);
TableInput actualTableInput = actualTableInputBuilder.build();

// Expected TableInput
TableInput expectedTableInput = TableInput.builder().storageDescriptor(
StorageDescriptor.builder()
.location("s3://test")
.columns(ImmutableList.of(
Column.builder()
.name("col")
.type("string")
.comment("comment_string_col")
.parameters(null)
.build()))
.inputFormat("org.apache.hadoop.mapred.FileInputFormat")
.outputFormat("org.apache.hadoop.mapred.FileOutputFormat")
.serdeInfo(
SerDeInfo.builder()
.serializationLibrary("org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe")
.build())
.build())
.build();

// Assertions
Assert.assertEquals(
"Not match the input format.",
expectedTableInput.storageDescriptor().inputFormat(),
actualTableInput.storageDescriptor().inputFormat());

Assert.assertEquals(
"Not match the out format.",
expectedTableInput.storageDescriptor().outputFormat(),
actualTableInput.storageDescriptor().outputFormat());

Assert.assertEquals(
"Not match the serde lib.",
expectedTableInput.storageDescriptor().serdeInfo().serializationLibrary(),
actualTableInput.storageDescriptor().serdeInfo().serializationLibrary());

}
}