use of org.apache.flink.table.data.StringData.fromString in project flink by apache.
the class StreamRecordUtils method binaryrow.
/**
* Receives a object array, generates a BinaryRowData based on the array.
*
* @param fields input object array
* @return generated BinaryRowData.
*/
public static BinaryRowData binaryrow(Object... fields) {
BinaryRowData row = new BinaryRowData(fields.length);
BinaryRowWriter writer = new BinaryRowWriter(row);
for (int j = 0; j < fields.length; j++) {
Object value = fields[j];
if (value == null) {
writer.setNullAt(j);
} else if (value instanceof Byte) {
writer.writeByte(j, (Byte) value);
} else if (value instanceof Short) {
writer.writeShort(j, (Short) value);
} else if (value instanceof Integer) {
writer.writeInt(j, (Integer) value);
} else if (value instanceof String) {
writer.writeString(j, StringData.fromString((String) value));
} else if (value instanceof Double) {
writer.writeDouble(j, (Double) value);
} else if (value instanceof Float) {
writer.writeFloat(j, (Float) value);
} else if (value instanceof Long) {
writer.writeLong(j, (Long) value);
} else if (value instanceof Boolean) {
writer.writeBoolean(j, (Boolean) value);
} else if (value instanceof byte[]) {
writer.writeBinary(j, (byte[]) value);
} else if (value instanceof DecimalData) {
DecimalData decimal = (DecimalData) value;
writer.writeDecimal(j, decimal, decimal.precision());
} else if (value instanceof TimestampData) {
TimestampData timestamp = (TimestampData) value;
writer.writeTimestamp(j, timestamp, 3);
} else if (value instanceof Tuple2 && ((Tuple2) value).f0 instanceof TimestampData) {
TimestampData timestamp = (TimestampData) ((Tuple2) value).f0;
writer.writeTimestamp(j, timestamp, (int) ((Tuple2) value).f1);
} else if (value instanceof Tuple2 && ((Tuple2) value).f0 instanceof ArrayData) {
ArrayData array = (ArrayData) ((Tuple2) value).f0;
ArrayDataSerializer serializer = (ArrayDataSerializer) ((Tuple2) value).f1;
writer.writeArray(j, array, serializer);
} else if (value instanceof Tuple2 && ((Tuple2) value).f0 instanceof RowData) {
RowData rowData = ((RowData) ((Tuple2) value).f0);
RowDataSerializer serializer = (RowDataSerializer) ((Tuple2) value).f1;
writer.writeRow(j, rowData, serializer);
} else {
throw new RuntimeException("Not support yet!");
}
}
writer.complete();
return row;
}
Aggregations