From 1f2ac2dd61608099ab96b91557fbe8ce8e437af6 Mon Sep 17 00:00:00 2001 From: jtian <86805957+rsyncv@users.noreply.github.com> Date: Fri, 14 Jan 2022 16:23:52 -0800 Subject: [PATCH] Parse table uri to include in serde and add serde tests --- .../polaris/mappers/PolarisTableMapper.java | 3 +++ .../PolarisConnectorTableServiceTest.java | 22 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/metacat-connector-polaris/src/main/java/com/netflix/metacat/connector/polaris/mappers/PolarisTableMapper.java b/metacat-connector-polaris/src/main/java/com/netflix/metacat/connector/polaris/mappers/PolarisTableMapper.java index a33c82c0a..69203fd43 100644 --- a/metacat-connector-polaris/src/main/java/com/netflix/metacat/connector/polaris/mappers/PolarisTableMapper.java +++ b/metacat-connector-polaris/src/main/java/com/netflix/metacat/connector/polaris/mappers/PolarisTableMapper.java @@ -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; /** @@ -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( @@ -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; diff --git a/metacat-connector-polaris/src/test/java/com/netflix/metacat/connector/polaris/PolarisConnectorTableServiceTest.java b/metacat-connector-polaris/src/test/java/com/netflix/metacat/connector/polaris/PolarisConnectorTableServiceTest.java index ca0ab413c..77c6c595b 100644 --- a/metacat-connector-polaris/src/test/java/com/netflix/metacat/connector/polaris/PolarisConnectorTableServiceTest.java +++ b/metacat-connector-polaris/src/test/java/com/netflix/metacat/connector/polaris/PolarisConnectorTableServiceTest.java @@ -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. */