Search in sources :

Example 6 with Schema

use of com.netflix.metacat.connector.s3.model.Schema in project metacat by Netflix.

the class S3ConnectorInfoConverter method toLocation.

/**
 * Creates location.
 * @param tableInfo table info
 * @return location
 */
public Location toLocation(final TableInfo tableInfo) {
    final Location location = fromStorageInfo(tableInfo.getSerde());
    final Schema schema = new Schema();
    schema.setLocation(location);
    schema.setFields(toFields(tableInfo, schema));
    location.setSchema(schema);
    return location;
}
Also used : Schema(com.netflix.metacat.connector.s3.model.Schema) Location(com.netflix.metacat.connector.s3.model.Location)

Example 7 with Schema

use of com.netflix.metacat.connector.s3.model.Schema 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();
}
Also used : Field(com.netflix.metacat.connector.s3.model.Field) ImmutableList(com.google.common.collect.ImmutableList) FieldInfo(com.netflix.metacat.common.server.connectors.model.FieldInfo)

Example 8 with Schema

use of com.netflix.metacat.connector.s3.model.Schema 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());
}
Also used : TableNotFoundException(com.netflix.metacat.common.server.connectors.exception.TableNotFoundException) Field(com.netflix.metacat.connector.s3.model.Field) Table(com.netflix.metacat.connector.s3.model.Table) QualifiedName(com.netflix.metacat.common.QualifiedName) Schema(com.netflix.metacat.connector.s3.model.Schema) Info(com.netflix.metacat.connector.s3.model.Info) TableInfo(com.netflix.metacat.common.server.connectors.model.TableInfo) Location(com.netflix.metacat.connector.s3.model.Location)

Example 9 with Schema

use of com.netflix.metacat.connector.s3.model.Schema in project uPMT by coco35700.

the class NewProjectDialogController method initialize.

@Override
public void initialize(URL location, ResourceBundle resources) {
    // TODO Auto-generated method stub
    choixSchema.getItems().add(main.getDefaultSchema());
    for (Project p : main.getProjects()) {
        choixSchema.getItems().add(p.getSchema());
    }
    // change the text to make it pretty
    choixSchema.setConverter(new StringConverter<Schema>() {

        @Override
        public String toString(Schema object) {
            // TODO Auto-generated method stub
            return object.getName();
        }

        @Override
        public Schema fromString(String string) {
            // TODO Auto-generated method stub
            return new Schema(string);
        }
    });
    choixSchema.setValue(main.getDefaultSchema());
}
Also used : Project(model.Project) Schema(model.Schema)

Aggregations

Field (com.netflix.metacat.connector.s3.model.Field)5 Schema (com.netflix.metacat.connector.s3.model.Schema)5 Location (com.netflix.metacat.connector.s3.model.Location)4 Schema (model.Schema)3 QualifiedName (com.netflix.metacat.common.QualifiedName)2 TableNotFoundException (com.netflix.metacat.common.server.connectors.exception.TableNotFoundException)2 FieldInfo (com.netflix.metacat.common.server.connectors.model.FieldInfo)2 TableInfo (com.netflix.metacat.common.server.connectors.model.TableInfo)2 Info (com.netflix.metacat.connector.s3.model.Info)2 Table (com.netflix.metacat.connector.s3.model.Table)2 Project (model.Project)2 ImmutableList (com.google.common.collect.ImmutableList)1 AlertType (javafx.scene.control.Alert.AlertType)1 ButtonType (javafx.scene.control.ButtonType)1 Category (model.Category)1 Folder (model.Folder)1 Property (model.Property)1 Type (model.Type)1