Search in sources :

Example 11 with FieldInfo

use of com.netflix.metacat.common.server.connectors.model.FieldInfo in project metacat by Netflix.

the class CassandraConnectorTableService method getTableInfo.

private TableInfo getTableInfo(@Nonnull @NonNull final QualifiedName name, @Nonnull @NonNull final TableMetadata tableMetadata) {
    final ImmutableList.Builder<FieldInfo> fieldInfoBuilder = ImmutableList.builder();
    // TODO: Ignores clustering, primary key, index, etc columns. We need to rework TableInfo to support
    for (final ColumnMetadata column : tableMetadata.getColumns()) {
        final String dataType = column.getType().toString();
        fieldInfoBuilder.add(FieldInfo.builder().name(column.getName()).sourceType(dataType).type(this.typeConverter.toMetacatType(dataType)).build());
    }
    return TableInfo.builder().name(QualifiedName.ofTable(name.getCatalogName(), name.getDatabaseName(), tableMetadata.getName())).fields(fieldInfoBuilder.build()).build();
}
Also used : ColumnMetadata(com.datastax.driver.core.ColumnMetadata) ImmutableList(com.google.common.collect.ImmutableList) FieldInfo(com.netflix.metacat.common.server.connectors.model.FieldInfo)

Example 12 with FieldInfo

use of com.netflix.metacat.common.server.connectors.model.FieldInfo in project metacat by Netflix.

the class JdbcConnectorTableService method get.

/**
 * {@inheritDoc}
 */
@Override
public TableInfo get(@Nonnull final ConnectorRequestContext context, @Nonnull final QualifiedName name) {
    log.debug("Beginning to get table metadata for qualified name {} for request {}", name, context);
    try (Connection connection = this.getConnection(name.getDatabaseName())) {
        final ImmutableList.Builder<FieldInfo> fields = ImmutableList.builder();
        try (ResultSet columns = this.getColumns(connection, name)) {
            while (columns.next()) {
                final String type = columns.getString("TYPE_NAME");
                final String size = columns.getString("COLUMN_SIZE");
                final String precision = columns.getString("DECIMAL_DIGITS");
                final String sourceType = this.buildSourceType(type, size, precision);
                final FieldInfo.FieldInfoBuilder fieldInfo = FieldInfo.builder().name(columns.getString("COLUMN_NAME")).sourceType(sourceType).type(this.typeConverter.toMetacatType(sourceType)).comment(columns.getString("REMARKS")).isNullable(columns.getString("IS_NULLABLE").equals("YES")).defaultValue(columns.getString("COLUMN_DEF"));
                if (size != null) {
                    fieldInfo.size(Integer.parseInt(size));
                }
                fields.add(fieldInfo.build());
            }
        }
        final List<FieldInfo> fieldInfos = fields.build();
        // If table does not exist, throw TableNotFoundException.
        if (fieldInfos.isEmpty() && !exists(context, name)) {
            throw new TableNotFoundException(name);
        }
        // Set table details
        final TableInfo result = TableInfo.builder().name(name).fields(fields.build()).build();
        setTableInfoDetails(connection, result);
        log.debug("Finished getting table metadata for qualified name {} for request {}", name, context);
        return result;
    } catch (final SQLException se) {
        throw new ConnectorException(se.getMessage(), se);
    }
}
Also used : TableNotFoundException(com.netflix.metacat.common.server.connectors.exception.TableNotFoundException) SQLException(java.sql.SQLException) ImmutableList(com.google.common.collect.ImmutableList) ConnectorException(com.netflix.metacat.common.server.connectors.exception.ConnectorException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) TableInfo(com.netflix.metacat.common.server.connectors.model.TableInfo) FieldInfo(com.netflix.metacat.common.server.connectors.model.FieldInfo)

Example 13 with FieldInfo

use of com.netflix.metacat.common.server.connectors.model.FieldInfo in project metacat by Netflix.

the class PolarisConnectorTableServiceTest method testGetTable.

/**
 * Test get table using metadata json resource file.
 */
@Test
public void testGetTable() {
    final QualifiedName qualifiedName = QualifiedName.ofTable(CATALOG_NAME, DB_NAME, "table1");
    final String location = "src/test/resources/metadata/00001-abf48887-aa4f-4bcc-9219-1e1721314ee1.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 schema info correctly parsed from iceberg metadata file
    final List<FieldInfo> fields = tableResult.getFields();
    Assert.assertEquals(fields.size(), 3);
    Assert.assertEquals(fields.get(0).getName(), "id");
    Assert.assertEquals(fields.get(0).getComment(), "1st field");
    Assert.assertEquals(fields.get(0).getSourceType(), "long");
    Assert.assertEquals(fields.get(1).getName(), "data");
    Assert.assertEquals(fields.get(1).getComment(), "2nd field");
    Assert.assertEquals(fields.get(1).getSourceType(), "string");
    Assert.assertEquals(fields.get(2).getName(), "dateint");
    Assert.assertEquals(fields.get(2).getComment(), "3rd field");
    Assert.assertEquals(fields.get(2).getSourceType(), "int");
}
Also used : QualifiedName(com.netflix.metacat.common.QualifiedName) TableInfo(com.netflix.metacat.common.server.connectors.model.TableInfo) FieldInfo(com.netflix.metacat.common.server.connectors.model.FieldInfo) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

FieldInfo (com.netflix.metacat.common.server.connectors.model.FieldInfo)13 ImmutableList (com.google.common.collect.ImmutableList)9 QualifiedName (com.netflix.metacat.common.QualifiedName)5 StorageInfo (com.netflix.metacat.common.server.connectors.model.StorageInfo)5 FieldSchema (org.apache.hadoop.hive.metastore.api.FieldSchema)5 StorageDescriptor (org.apache.hadoop.hive.metastore.api.StorageDescriptor)5 TableInfo (com.netflix.metacat.common.server.connectors.model.TableInfo)4 DirectSqlTable (com.netflix.metacat.connector.hive.sql.DirectSqlTable)4 SerDeInfo (org.apache.hadoop.hive.metastore.api.SerDeInfo)4 Lists (com.google.common.collect.Lists)3 AuditInfo (com.netflix.metacat.common.server.connectors.model.AuditInfo)3 ViewInfo (com.netflix.metacat.common.server.connectors.model.ViewInfo)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 Slf4j (lombok.extern.slf4j.Slf4j)3 Table (org.apache.hadoop.hive.metastore.api.Table)3 StructField (org.apache.hadoop.hive.serde2.objectinspector.StructField)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 Preconditions (com.google.common.base.Preconditions)2 Splitter (com.google.common.base.Splitter)2