use of com.amazonaws.services.personalize.model.DatasetSchemaSummary in project knime-cloud by knime.
the class AmazonPersonalizeUtils method listAllSchemas.
/**
* @param personalize the amazon personalize client
* @return all schemas
*/
public static List<DatasetSchemaSummary> listAllSchemas(final AmazonPersonalize personalize) {
final ListSchemasRequest request = new ListSchemasRequest().withMaxResults(100);
ListSchemasResult result = personalize.listSchemas(request);
List<DatasetSchemaSummary> list = result.getSchemas();
String nextToken;
while ((nextToken = result.getNextToken()) != null) {
result = personalize.listSchemas(request.withNextToken(nextToken));
list.addAll(result.getSchemas());
}
return list;
}
use of com.amazonaws.services.personalize.model.DatasetSchemaSummary in project knime-cloud by knime.
the class AbstractAmazonPersonalizeDataUploadNodeModel method createSchema.
private String createSchema(final AmazonPersonalize personalizeClient, final DataTableSpec spec) {
final StringBuilder schemaNameBuilder = new StringBuilder(getSchemaNamePrefix());
FieldAssembler<Schema> fieldAssembler = createFieldAssembler(SCHEMA_NAMESPACE);
for (final String colName : spec.getColumnNames()) {
if (!colName.startsWith(PREFIX_METADATA_FIELD)) {
continue;
}
final DataColumnSpec colSpec = spec.getColumnSpec(colName);
final boolean isCategorical;
final Type type;
if (colSpec.getType().isCompatible(StringValue.class)) {
isCategorical = true;
type = Type.STRING;
} else if (colSpec.getType().isCompatible(IntValue.class)) {
isCategorical = false;
type = Type.INT;
} else if (colSpec.getType().isCompatible(LongValue.class)) {
isCategorical = false;
type = Type.LONG;
} else {
isCategorical = false;
type = Type.DOUBLE;
}
schemaNameBuilder.append("-" + type);
// 'categorical' must be set for metadata
fieldAssembler = fieldAssembler.name(colName).prop("categorical", isCategorical).type(Schema.create(type)).noDefault();
}
final String schemaName = schemaNameBuilder.toString();
// check if the same schema has been created before
final List<DatasetSchemaSummary> existingSchemas = AmazonPersonalizeUtils.listAllSchemas(personalizeClient);
final Optional<DatasetSchemaSummary> schemaSummary = existingSchemas.stream().filter(e -> e.getName().equals(schemaName)).findAny();
// if so, use this one again
if (schemaSummary.isPresent()) {
return schemaSummary.get().getSchemaArn();
}
// otherwise create new one
final Schema schema = fieldAssembler.endRecord();
final CreateSchemaRequest createSchemaRequest = new CreateSchemaRequest().withName(schemaName).withSchema(schema.toString());
return personalizeClient.createSchema(createSchemaRequest).getSchemaArn();
}
Aggregations