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();
}
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);
}
}
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");
}
Aggregations