use of com.hortonworks.registries.storage.PrimaryKey in project registry by hortonworks.
the class MLModel method getPrimaryKey.
@JsonIgnore
@Override
public PrimaryKey getPrimaryKey() {
Map<Field, Object> fieldObjectMap = new HashMap<>();
fieldObjectMap.put(new Schema.Field(ID, Type.LONG), this.id);
return new PrimaryKey(fieldObjectMap);
}
use of com.hortonworks.registries.storage.PrimaryKey in project registry by hortonworks.
the class AbstractSelectQuery method buildSqlWithSearchQuery.
protected String buildSqlWithSearchQuery(SearchQuery searchQuery, Schema schema) {
String sql = "SELECT * FROM " + fieldEncloser() + tableName + fieldEncloser();
WhereClause whereClause = searchQuery.getWhereClause();
Map<Schema.Field, Object> fieldsToValues = new HashMap<>();
if (whereClause != null) {
sql += " WHERE ";
StringBuilder clauseString = new StringBuilder();
for (PredicateCombinerPair predicateCombinerPair : whereClause.getPredicateCombinerPairs()) {
WhereClauseCombiner.Operation combinerOperation = predicateCombinerPair.getCombinerOperation();
Predicate predicate = predicateCombinerPair.getPredicate();
clauseString.append(generateClauseString(predicate, fieldsToValues, schema));
if (combinerOperation != null) {
String opStr;
switch(combinerOperation) {
case ENCL_START:
opStr = " ( ";
break;
case ENCL_FINISH:
opStr = " ) ";
break;
default:
opStr = combinerOperation.toString();
}
clauseString.append(opStr);
}
}
sql += clauseString;
}
List<OrderBy> orderByFields = searchQuery.getOrderByFields();
if (orderByFields != null && !orderByFields.isEmpty()) {
sql += " ORDER BY " + join(orderByFields.stream().map(x -> fieldEncloser() + x.getFieldName() + fieldEncloser() + (x.isAsc() ? " ASC " : " DESC ")).collect(Collectors.toList()), ", ");
}
primaryKey = new PrimaryKey(fieldsToValues);
columns = Lists.newArrayList(fieldsToValues.keySet());
return sql;
}
use of com.hortonworks.registries.storage.PrimaryKey in project registry by hortonworks.
the class InMemoryStorageManager method update.
@Override
public void update(Storable storable) {
String namespace = storable.getNameSpace();
PrimaryKey pk = storable.getPrimaryKey();
if (!storageMap.containsKey(namespace)) {
throw new StorageException("Row could not be updated");
}
storageMap.get(namespace).put(pk, storable);
}
Aggregations