use of com.netflix.metacat.connector.s3.model.Field in project metacat by Netflix.
the class S3ConnectorTableService method update.
@Override
public void update(@Nonnull final ConnectorRequestContext context, @Nonnull final TableInfo tableInfo) {
log.debug("Start: Update table {}", tableInfo.getName());
final QualifiedName tableName = tableInfo.getName();
final Table table = tableDao.getBySourceDatabaseTableName(catalogName, tableName.getDatabaseName(), tableName.getTableName());
if (table == null) {
throw new TableNotFoundException(tableName);
}
// we can update the fields, the uri, or the full serde
final Location newLocation = infoConverter.toLocation(tableInfo);
Location location = table.getLocation();
if (location == null) {
location = new Location();
location.setTable(table);
table.setLocation(location);
}
if (newLocation.getUri() != null) {
location.setUri(newLocation.getUri());
}
final Info newInfo = newLocation.getInfo();
if (newInfo != null) {
final Info info = location.getInfo();
if (info == null) {
location.setInfo(newInfo);
newInfo.setLocation(location);
} else {
if (newInfo.getInputFormat() != null) {
info.setInputFormat(newInfo.getInputFormat());
}
if (newInfo.getOutputFormat() != null) {
info.setOutputFormat(newInfo.getOutputFormat());
}
if (newInfo.getOwner() != null) {
info.setOwner(newInfo.getOwner());
}
if (newInfo.getSerializationLib() != null) {
info.setSerializationLib(newInfo.getSerializationLib());
}
if (newInfo.getParameters() != null && !newInfo.getParameters().isEmpty()) {
info.setParameters(newInfo.getParameters());
}
}
}
final Schema newSchema = newLocation.getSchema();
if (newSchema != null) {
final List<Field> newFields = newSchema.getFields();
if (newFields != null && !newFields.isEmpty()) {
final Schema schema = location.getSchema();
if (schema == null) {
location.setSchema(newSchema);
newSchema.setLocation(location);
} else {
final List<Field> fields = schema.getFields();
if (fields.isEmpty()) {
newFields.forEach(field -> {
field.setSchema(schema);
fields.add(field);
});
} else {
for (int i = 0; i < newFields.size(); i++) {
final Field newField = newFields.get(i);
newField.setPos(i);
newField.setSchema(schema);
if (newField.getType() == null) {
newField.setType(newField.getSourceType());
}
}
schema.setFields(null);
fieldDao.delete(fields);
tableDao.save(table, true);
schema.setFields(newFields);
}
}
}
}
log.debug("End: Update table {}", tableInfo.getName());
}
use of com.netflix.metacat.connector.s3.model.Field in project metacat by Netflix.
the class S3ConnectorInfoConverter method partitionKeys.
/**
* Gets the partition keys for the given table.
* @param table table info
* @return list of keys
*/
public List<String> partitionKeys(final Table table) {
List<String> result = Lists.newArrayList();
if (table.getLocation() != null) {
final Schema schema = table.getLocation().getSchema();
if (schema != null) {
final List<Field> fields = schema.getFields();
result = fields.stream().filter(Field::isPartitionKey).map(Field::getName).collect(Collectors.toList());
}
}
return result;
}
use of com.netflix.metacat.connector.s3.model.Field in project metacat by Netflix.
the class S3ConnectorInfoConverter method toFields.
private List<FieldInfo> toFields(final Table table) {
List<FieldInfo> result = Lists.newArrayList();
final Location location = table.getLocation();
if (location != null) {
final Schema schema = location.getSchema();
if (schema != null) {
result = schema.getFields().stream().sorted(Comparator.comparing(Field::getPos)).map(this::toFieldInfo).collect(Collectors.toList());
}
}
return result;
}
use of com.netflix.metacat.connector.s3.model.Field in project metacat by Netflix.
the class S3ConnectorInfoConverter method toFields.
/**
* Creates list of fields from table info.
* @param tableInfo table info
* @param schema schema
* @return list of fields
*/
public List<Field> toFields(final TableInfo tableInfo, final Schema schema) {
final ImmutableList.Builder<Field> columns = ImmutableList.builder();
int index = 0;
for (FieldInfo fieldInfo : tableInfo.getFields()) {
final Field field = toField(fieldInfo);
field.setPos(index++);
field.setSchema(schema);
columns.add(field);
}
return columns.build();
}
use of com.netflix.metacat.connector.s3.model.Field in project metacat by Netflix.
the class S3ConnectorTableService method update.
@Override
public void update(@Nonnull final ConnectorContext context, @Nonnull final TableInfo tableInfo) {
log.debug("Start: Update table {}", tableInfo.getName());
final QualifiedName tableName = tableInfo.getName();
final Table table = tableDao.getBySourceDatabaseTableName(catalogName, tableName.getDatabaseName(), tableName.getTableName());
if (table == null) {
throw new TableNotFoundException(tableName);
}
//we can update the fields, the uri, or the full serde
final Location newLocation = infoConverter.toLocation(tableInfo);
Location location = table.getLocation();
if (location == null) {
location = new Location();
location.setTable(table);
table.setLocation(location);
}
if (newLocation.getUri() != null) {
location.setUri(newLocation.getUri());
}
final Info newInfo = newLocation.getInfo();
if (newInfo != null) {
final Info info = location.getInfo();
if (info == null) {
location.setInfo(newInfo);
newInfo.setLocation(location);
} else {
if (newInfo.getInputFormat() != null) {
info.setInputFormat(newInfo.getInputFormat());
}
if (newInfo.getOutputFormat() != null) {
info.setOutputFormat(newInfo.getOutputFormat());
}
if (newInfo.getOwner() != null) {
info.setOwner(newInfo.getOwner());
}
if (newInfo.getSerializationLib() != null) {
info.setSerializationLib(newInfo.getSerializationLib());
}
if (newInfo.getParameters() != null && !newInfo.getParameters().isEmpty()) {
info.setParameters(newInfo.getParameters());
}
}
}
final Schema newSchema = newLocation.getSchema();
if (newSchema != null) {
final List<Field> newFields = newSchema.getFields();
if (newFields != null && !newFields.isEmpty()) {
final Schema schema = location.getSchema();
if (schema == null) {
location.setSchema(newSchema);
newSchema.setLocation(location);
} else {
final List<Field> fields = schema.getFields();
if (fields.isEmpty()) {
newFields.forEach(field -> {
field.setSchema(schema);
fields.add(field);
});
} else {
for (int i = 0; i < newFields.size(); i++) {
final Field newField = newFields.get(i);
newField.setPos(i);
newField.setSchema(schema);
if (newField.getType() == null) {
newField.setType(newField.getSourceType());
}
}
schema.setFields(null);
fieldDao.delete(fields);
tableDao.save(table, true);
schema.setFields(newFields);
}
}
}
}
log.debug("End: Update table {}", tableInfo.getName());
}
Aggregations