private Value<?> getValueFromNode(JsonNode nodeValue, DataSetDataType type) { switch (type) { case Boolean: return new Value<Boolean>(type, (boolean)nodeValue.asBoolean()); case DateTime: return new Value<Date>(type, new Date(nodeValue.asLong())); case Double: return new Value<Double>(type, nodeValue.asDouble()); case Float: return new Value<Float>(type, (float)nodeValue.asDouble()); case Int16: case UInt8: return new Value<Byte>(type, (byte)nodeValue.asInt()); case UInt16: case Int32: return new Value<Integer>(type, nodeValue.asInt()); case UInt32: case Int64: return new Value<Long>(type, (long)nodeValue.asLong()); case Text: case String: return new Value<String>(type, nodeValue.asText()); case UInt64: return new Value<BigInteger>(type, BigInteger.valueOf(nodeValue.asLong())); case Unknown: default: return null; } } }
/** * Converts a {@link Row} instance to a {@link List} of Objects representing the values. * * @param row a {@link Row} instance. * @return a {@link List} of Objects. */ public static List<Object> toValues(Row row) { List<Object> list = new ArrayList<Object>(row.getValues().size()); for (Value<?> value : row.getValues()) { list.add(value.getValue()); } return list; }
DataSetDataType type = value.getType(); switch (type) { case Int8: protoValueBuilder.setIntValue((Byte) value.getValue()); break; case Int16: case UInt8: protoValueBuilder.setIntValue((Short) value.getValue()); break; case Int32: case UInt16: protoValueBuilder.setIntValue((Integer) value.getValue()); break; case Int64: case UInt32: protoValueBuilder.setLongValue((Long) value.getValue()); break; case UInt64: protoValueBuilder.setLongValue(((BigInteger) value.getValue()).longValue()); break; case Float: protoValueBuilder.setFloatValue((Float) value.getValue()); break; case Double: protoValueBuilder.setDoubleValue((Double) value.getValue()); break; case String: case Text: if (value.getValue() != null) {
switch (type) { case Boolean: return new Value<Boolean>(type, protoValue.getBooleanValue()); case DateTime: return new Value<Date>(type, null); } else { return new Value<Date>(type, new Date(protoValue.getLongValue())); return new Value<Float>(type, protoValue.getFloatValue()); case Double: return new Value<Double>(type, protoValue.getDoubleValue()); case Int8: return new Value<Byte>(type, (byte) protoValue.getIntValue()); case UInt8: case Int16: return new Value<Short>(type, (short) protoValue.getIntValue()); case UInt16: case Int32: return new Value<Integer>(type, protoValue.getIntValue()); case UInt32: case Int64: return new Value<Long>(type, protoValue.getLongValue()); case UInt64: return new Value<BigInteger>(type, BigInteger.valueOf(protoValue.getLongValue())); case String: case Text: if (protoValue.getStringValue().equals("null")) { return new Value<String>(type, null);
public void validate() throws SparkplugException { if (columnNames.size() != numOfColumns) { throw new SparkplugException("Invalid number of columns in data set column names: " + columnNames.size() + " vs expected " + numOfColumns); } if (types.size() != numOfColumns) { throw new SparkplugException("Invalid number of columns in data set types: " + types.size() + " vs expected: " + numOfColumns); } for (int i = 0; i < types.size(); i++) { for (Row row : rows) { List<Value<?>> values = row.getValues(); if (values.size() != numOfColumns) { throw new SparkplugException("Invalid number of columns in data set row: " + values.size() + " vs expected: " + numOfColumns); } types.get(i).checkType(row.getValues().get(i).getValue()); } } } }
.addType(DataSetDataType.Text) .addRow(new RowBuilder() .addValue(new Value<Byte>(DataSetDataType.Int8, (byte)random.nextInt())) .addValue(new Value<Short>(DataSetDataType.Int16, (short)random.nextInt())) .addValue(new Value<Integer>(DataSetDataType.Int32, random.nextInt())) .addValue(new Value<Long>(DataSetDataType.Int64, random.nextLong())) .addValue(new Value<Short>(DataSetDataType.UInt8, (short)random.nextInt())) .addValue(new Value<Integer>(DataSetDataType.UInt16, random.nextInt())) .addValue(new Value<Long>(DataSetDataType.UInt32, random.nextLong())) .addValue(new Value<BigInteger>(DataSetDataType.UInt64, BigInteger.valueOf(random.nextLong()))) .addValue(new Value<Float>(DataSetDataType.Float, random.nextFloat())) .addValue(new Value<Double>(DataSetDataType.Double, random.nextDouble())) .addValue(new Value<Boolean>(DataSetDataType.Boolean, random.nextBoolean())) .addValue(new Value<String>(DataSetDataType.String, newUUID())) .addValue(new Value<Date>(DataSetDataType.DateTime, new Date())) .addValue(new Value<String>(DataSetDataType.Text, newUUID())) .createRow()) .addRow(new RowBuilder() .addValue(new Value<Byte>(DataSetDataType.Int8, (byte)random.nextInt())) .addValue(new Value<Short>(DataSetDataType.Int16, (short)random.nextInt())) .addValue(new Value<Integer>(DataSetDataType.Int32, random.nextInt())) .addValue(new Value<Long>(DataSetDataType.Int64, random.nextLong())) .addValue(new Value<Short>(DataSetDataType.UInt8, (short)random.nextInt())) .addValue(new Value<Integer>(DataSetDataType.UInt16, random.nextInt())) .addValue(new Value<Long>(DataSetDataType.UInt32, random.nextLong())) .addValue(new Value<BigInteger>(DataSetDataType.UInt64, BigInteger.valueOf(random.nextLong()))) .addValue(new Value<Float>(DataSetDataType.Float, random.nextFloat())) .addValue(new Value<Double>(DataSetDataType.Double, random.nextDouble())) .addValue(new Value<Boolean>(DataSetDataType.Boolean, random.nextBoolean()))