Skip to content

Commit

Permalink
Parse table uri to include in serde and add serde tests
Browse files Browse the repository at this point in the history
  • Loading branch information
insyncoss committed Jan 22, 2022
1 parent 7471bb2 commit 1f2ac2d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class PolarisTableMapper implements

private static final String PARAMETER_SPARK_SQL_PROVIDER = "spark.sql.sources.provider";
private static final String PARAMETER_EXTERNAL = "EXTERNAL";
private static final String PARAMETER_METADATA_PREFIX = "/metadata/";
private final String catalogName;

/**
Expand All @@ -36,6 +37,7 @@ public PolarisTableMapper(final String catalogName) {
*/
@Override
public TableInfo toInfo(final PolarisTableEntity entity) {
final int uriIndex = entity.getMetadataLocation().indexOf(PARAMETER_METADATA_PREFIX);
final TableInfo tableInfo = TableInfo.builder()
.name(QualifiedName.ofTable(catalogName, entity.getDbName(), entity.getTblName()))
.metadata(ImmutableMap.of(
Expand All @@ -45,6 +47,7 @@ public TableInfo toInfo(final PolarisTableEntity entity) {
.serde(StorageInfo.builder().inputFormat("org.apache.hadoop.mapred.FileInputFormat")
.outputFormat("org.apache.hadoop.mapred.FileOutputFormat")
.serializationLib("org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe")
.uri(uriIndex > 0 ? entity.getMetadataLocation().substring(0, uriIndex) : "")
.build())
.build();
return tableInfo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,28 @@ public void testGetTable() {
Assert.assertEquals(fields.get(2).getSourceType(), "int");
}

/**
* Test table serde fields.
*/
@Test
public void testTableSerde() {
final QualifiedName qualifiedName = QualifiedName.ofTable(CATALOG_NAME, DB_NAME, "table1");
final String location = "src/test/resources/metadata/00000-9b5d4c36-130c-4288-9599-7d850c203d11.metadata.json";
final TableInfo tableInfo = TableInfo.builder()
.name(qualifiedName)
.metadata(ImmutableMap.of("table_type", "ICEBERG", "metadata_location", location))
.build();
polarisTableService.create(requestContext, tableInfo);
final TableInfo tableResult = polarisTableService.get(requestContext, qualifiedName);
// check serde info
Assert.assertNotNull(tableResult.getSerde());
Assert.assertEquals(tableResult.getSerde().getUri(), "src/test/resources");
Assert.assertEquals(tableResult.getSerde().getInputFormat(), "org.apache.hadoop.mapred.FileInputFormat");
Assert.assertEquals(tableResult.getSerde().getOutputFormat(), "org.apache.hadoop.mapred.FileOutputFormat");
Assert.assertEquals(tableResult.getSerde().getSerializationLib(),
"org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe");
}

/**
* Test update table reject cases.
*/
Expand Down

0 comments on commit 1f2ac2d

Please sign in to comment.