use of com.linkedin.databus2.producers.ds.PrimaryKeySchema in project databus by linkedin.
the class ORListener method generateKeyPair.
private List<KeyPair> generateKeyPair(List<Column> cl, Schema schema) throws DatabusException {
Object o = null;
Schema.Type st = null;
// Build PrimaryKeySchema
String pkFieldName = SchemaHelper.getMetaField(schema, "pk");
if (pkFieldName == null) {
throw new DatabusException("No primary key specified in the schema");
}
PrimaryKeySchema pkSchema = new PrimaryKeySchema(pkFieldName);
List<Schema.Field> fields = schema.getFields();
List<KeyPair> kpl = new ArrayList<KeyPair>();
int cnt = 0;
for (Schema.Field field : fields) {
if (pkSchema.isPartOfPrimaryKey(field)) {
o = cl.get(cnt).getValue();
st = field.schema().getType();
KeyPair kp = new KeyPair(o, st);
kpl.add(kp);
}
cnt++;
}
return kpl;
}
use of com.linkedin.databus2.producers.ds.PrimaryKeySchema in project databus by linkedin.
the class ORListener method generateKeyPair.
private List<KeyPair> generateKeyPair(GenericRecord gr, VersionedSchema versionedSchema) throws DatabusException {
Object o = null;
Schema.Type st = null;
List<Field> pkFieldList = versionedSchema.getPkFieldList();
if (pkFieldList.isEmpty()) {
String pkFieldName = SchemaHelper.getMetaField(versionedSchema.getSchema(), "pk");
if (pkFieldName == null) {
throw new DatabusException("No primary key specified in the schema");
}
PrimaryKeySchema pkSchema = new PrimaryKeySchema(pkFieldName);
List<Schema.Field> fields = versionedSchema.getSchema().getFields();
for (int i = 0; i < fields.size(); i++) {
Schema.Field field = fields.get(i);
if (pkSchema.isPartOfPrimaryKey(field)) {
pkFieldList.add(field);
}
}
}
List<KeyPair> kpl = new ArrayList<KeyPair>();
for (Field field : pkFieldList) {
o = gr.get(field.name());
st = field.schema().getType();
KeyPair kp = new KeyPair(o, st);
kpl.add(kp);
}
if (kpl == null || kpl.isEmpty()) {
String pkFieldName = SchemaHelper.getMetaField(versionedSchema.getSchema(), "pk");
StringBuilder sb = new StringBuilder();
for (Schema.Field f : versionedSchema.getSchema().getFields()) {
sb.append(f.name()).append(",");
}
throw new DatabusException("pk is assigned to " + pkFieldName + " but fieldList is " + sb.toString());
}
return kpl;
}
Aggregations