use of org.apache.apex.malhar.lib.appdata.schemas.FieldsDescriptor in project apex-malhar by apache.
the class AppDataSnapshotServerMap method convert.
@Override
public GPOMutable convert(Map<String, Object> inputEvent) {
FieldsDescriptor fd = schema.getValuesDescriptor();
GPOMutable values = new GPOMutable(fd);
List<String> fields = fd.getFieldList();
for (int index = 0; index < fields.size(); index++) {
String field = fields.get(index);
values.setFieldGeneric(field, inputEvent.get(getMapField(field)));
}
return values;
}
use of org.apache.apex.malhar.lib.appdata.schemas.FieldsDescriptor in project apex-malhar by apache.
the class SerdeListGPOMutable method serializeObject.
@Override
public synchronized byte[] serializeObject(Object object) {
@SuppressWarnings("unchecked") List<GPOMutable> mutables = (List<GPOMutable>) object;
if (mutables.isEmpty()) {
return GPOUtils.serializeInt(0);
}
FieldsDescriptor fd = mutables.get(0).getFieldDescriptor();
bytes.add(SerdeFieldsDescriptor.INSTANCE.serializeObject(fd));
for (int index = 0; index < mutables.size(); index++) {
bytes.add(GPOUtils.serialize(mutables.get(index), bytes));
}
byte[] byteArray = bytes.toByteArray();
bytes.clear();
bytes.add(GPOUtils.serializeInt(byteArray.length));
bytes.add(byteArray);
byteArray = bytes.toByteArray();
bytes.clear();
return byteArray;
}
use of org.apache.apex.malhar.lib.appdata.schemas.FieldsDescriptor in project apex-malhar by apache.
the class SerdeListGPOMutable method deserializeObject.
@Override
public synchronized Object deserializeObject(byte[] object, MutableInt offset) {
int length = GPOUtils.deserializeInt(object, offset);
int startIndex = offset.intValue();
if (length == 0) {
return new ArrayList<GPOMutable>();
}
FieldsDescriptor fd = (FieldsDescriptor) SerdeFieldsDescriptor.INSTANCE.deserializeObject(object, offset);
List<GPOMutable> mutables = Lists.newArrayList();
while (startIndex + length > offset.intValue()) {
GPOMutable value = GPOUtils.deserialize(fd, object, offset);
mutables.add(value);
}
return mutables;
}
use of org.apache.apex.malhar.lib.appdata.schemas.FieldsDescriptor in project apex-malhar by apache.
the class SerdeFieldsDescriptor method serializeObject.
@Override
public synchronized byte[] serializeObject(Object object) {
FieldsDescriptor fd = (FieldsDescriptor) object;
for (Map.Entry<String, Type> entry : fd.getFieldToType().entrySet()) {
bal.add(GPOUtils.serializeInt(entry.getValue().ordinal()));
bal.add(GPOUtils.serializeString(entry.getKey()));
}
byte[] serializedBytes = bal.toByteArray();
bal.clear();
bal.add(GPOUtils.serializeInt(serializedBytes.length));
bal.add(serializedBytes);
serializedBytes = bal.toByteArray();
bal.clear();
return serializedBytes;
}
use of org.apache.apex.malhar.lib.appdata.schemas.FieldsDescriptor in project apex-malhar by apache.
the class JDBCDimensionalOutputOperator method setParams.
/**
* @param ps
* The {@link java.sql.PreparedStatement} which will do an insert
* into the Mysql database.
* @param gpo
* The {@link GPOMutable} object whose values need to be set in the
* preparted statement.
* @param qCounter
* The current index in the prepared statement
* @param isKey
* TODO use this
* @return The current index in the prepared statement.
* @throws SQLException
*/
private int setParams(PreparedStatement ps, GPOMutable gpo, int qCounter, boolean isKey) throws SQLException {
FieldsDescriptor fd = gpo.getFieldDescriptor();
Map<String, Type> fieldToType = fd.getFieldToType();
List<String> fields = fd.getFieldList();
for (int fieldCounter = 0; fieldCounter < fields.size(); fieldCounter++, qCounter++) {
String fieldName = fields.get(fieldCounter);
if (fieldName.equals(DimensionsDescriptor.DIMENSION_TIME_BUCKET)) {
qCounter--;
continue;
}
Type type = fieldToType.get(fieldName);
LOG.info("Field Name {} {}", fieldName, qCounter);
switch(type) {
case BOOLEAN:
{
ps.setByte(qCounter, (byte) (gpo.getFieldBool(fieldName) ? 1 : 0));
break;
}
case BYTE:
{
ps.setByte(qCounter, gpo.getFieldByte(fieldName));
break;
}
case CHAR:
{
ps.setString(qCounter, Character.toString(gpo.getFieldChar(fieldName)));
break;
}
case STRING:
{
ps.setString(qCounter, gpo.getFieldString(fieldName));
break;
}
case SHORT:
{
ps.setInt(qCounter, gpo.getFieldShort(fieldName));
break;
}
case INTEGER:
{
ps.setInt(qCounter, gpo.getFieldInt(fieldName));
break;
}
case LONG:
{
ps.setLong(qCounter, gpo.getFieldLong(fieldName));
break;
}
case FLOAT:
{
ps.setFloat(qCounter, gpo.getFieldFloat(fieldName));
break;
}
case DOUBLE:
{
ps.setDouble(qCounter, gpo.getFieldDouble(fieldName));
break;
}
default:
{
throw new UnsupportedOperationException("The type: " + type + " is not supported.");
}
}
}
return qCounter;
}
Aggregations