Search in sources :

Example 1 with FieldsDescriptor

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;
}
Also used : GPOMutable(org.apache.apex.malhar.lib.appdata.gpo.GPOMutable) FieldsDescriptor(org.apache.apex.malhar.lib.appdata.schemas.FieldsDescriptor)

Example 2 with FieldsDescriptor

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;
}
Also used : FieldsDescriptor(org.apache.apex.malhar.lib.appdata.schemas.FieldsDescriptor) List(java.util.List) ArrayList(java.util.ArrayList)

Example 3 with FieldsDescriptor

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;
}
Also used : ArrayList(java.util.ArrayList) FieldsDescriptor(org.apache.apex.malhar.lib.appdata.schemas.FieldsDescriptor)

Example 4 with FieldsDescriptor

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;
}
Also used : Type(org.apache.apex.malhar.lib.appdata.schemas.Type) FieldsDescriptor(org.apache.apex.malhar.lib.appdata.schemas.FieldsDescriptor) Map(java.util.Map)

Example 5 with FieldsDescriptor

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;
}
Also used : Type(org.apache.apex.malhar.lib.appdata.schemas.Type) FieldsDescriptor(org.apache.apex.malhar.lib.appdata.schemas.FieldsDescriptor)

Aggregations

FieldsDescriptor (org.apache.apex.malhar.lib.appdata.schemas.FieldsDescriptor)24 Type (org.apache.apex.malhar.lib.appdata.schemas.Type)19 Test (org.junit.Test)10 Map (java.util.Map)5 GPOMutable (org.apache.apex.malhar.lib.appdata.gpo.GPOMutable)4 MutableInt (org.apache.commons.lang3.mutable.MutableInt)4 JSONObject (org.codehaus.jettison.json.JSONObject)3 PreparedStatement (java.sql.PreparedStatement)2 SQLException (java.sql.SQLException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 EventKey (org.apache.apex.malhar.lib.dimensions.DimensionsEvent.EventKey)2 Int2ObjectMap (it.unimi.dsi.fastutil.ints.Int2ObjectMap)1 Set (java.util.Set)1 Serde (org.apache.apex.malhar.lib.appdata.gpo.Serde)1 DimensionalConfigurationSchema (org.apache.apex.malhar.lib.appdata.schemas.DimensionalConfigurationSchema)1 Fields (org.apache.apex.malhar.lib.appdata.schemas.Fields)1