本文整理了Java中org.apache.flink.types.Row.getArity
方法的一些代码示例,展示了Row.getArity
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Row.getArity
方法的具体详情如下:
包路径:org.apache.flink.types.Row
类名称:Row
方法名:getArity
[英]Get the number of fields in the Row.
[中]获取行中的字段数。
代码示例来源:origin: apache/flink
public static String[] rowToString(Row row) {
final String[] fields = new String[row.getArity()];
for (int i = 0; i < row.getArity(); i++) {
final Object field = row.getField(i);
if (field == null) {
fields[i] = CliStrings.NULL_COLUMN;
} else {
fields[i] = field.toString();
}
}
return fields;
}
代码示例来源:origin: apache/flink
@Override
protected Object[] extractFields(Row record) {
Object[] fields = new Object[record.getArity()];
for (int i = 0; i < fields.length; i++) {
fields[i] = record.getField(i);
}
return fields;
}
}
代码示例来源:origin: apache/flink
/**
* Stores the next resultSet row in a tuple.
*
* @param row row to be reused.
* @return row containing next {@link Row}
* @throws java.io.IOException
*/
@Override
public Row nextRecord(Row row) throws IOException {
try {
if (!hasNext) {
return null;
}
for (int pos = 0; pos < row.getArity(); pos++) {
row.setField(pos, resultSet.getObject(pos + 1));
}
//update hasNext after we've read the record
hasNext = resultSet.next();
return row;
} catch (SQLException se) {
throw new IOException("Couldn't read data - " + se.getMessage(), se);
} catch (NullPointerException npe) {
throw new IOException("Couldn't access resultSet", npe);
}
}
代码示例来源:origin: apache/flink
@Override
public void serialize(Row record, DataOutputView target) throws IOException {
int len = fieldSerializers.length;
if (record.getArity() != len) {
throw new RuntimeException("Row arity of from does not match serializers.");
}
// write a null mask
writeNullMask(len, record, target);
// serialize non-null fields
for (int i = 0; i < len; i++) {
Object o = record.getField(i);
if (o != null) {
fieldSerializers[i].serialize(o, target);
}
}
}
代码示例来源:origin: apache/flink
@Override
public Row copy(Row from) {
int len = fieldSerializers.length;
if (from.getArity() != len) {
throw new RuntimeException("Row arity of from does not match serializers.");
}
Row result = new Row(len);
for (int i = 0; i < len; i++) {
Object fromField = from.getField(i);
if (fromField != null) {
Object copy = fieldSerializers[i].copy(fromField);
result.setField(i, copy);
}
else {
result.setField(i, null);
}
}
return result;
}
代码示例来源:origin: apache/flink
private ObjectNode convertRow(ObjectNode reuse, RowTypeInfo info, Row row) {
if (reuse == null) {
reuse = mapper.createObjectNode();
}
final String[] fieldNames = info.getFieldNames();
final TypeInformation<?>[] fieldTypes = info.getFieldTypes();
// validate the row
if (row.getArity() != fieldNames.length) {
throw new IllegalStateException(String.format(
"Number of elements in the row '%s' is different from number of field names: %d", row, fieldNames.length));
}
for (int i = 0; i < fieldNames.length; i++) {
final String name = fieldNames[i];
final JsonNode fieldConverted = convert(reuse, reuse.get(name), fieldTypes[i], row.getField(i));
reuse.set(name, fieldConverted);
}
return reuse;
}
代码示例来源:origin: apache/flink
@Override
protected void deepEquals(String message, Row should, Row is) {
int arity = should.getArity();
assertEquals(message, arity, is.getArity());
for (int i = 0; i < arity; i++) {
Object copiedValue = should.getField(i);
Object element = is.getField(i);
assertEquals(message, element, copiedValue);
}
}
代码示例来源:origin: apache/flink
@Override
protected void deepEquals(String message, Row should, Row is) {
int arity = should.getArity();
assertEquals(message, arity, is.getArity());
for (int i = 0; i < arity; i++) {
Object copiedValue = should.getField(i);
Object element = is.getField(i);
assertEquals(message, element, copiedValue);
}
}
代码示例来源:origin: apache/flink
@Override
protected void deepEquals(String message, Row should, Row is) {
int arity = should.getArity();
assertEquals(message, arity, is.getArity());
for (int i = 0; i < arity; i++) {
Object copiedValue = should.getField(i);
Object element = is.getField(i);
assertEquals(message, element, copiedValue);
}
}
}
代码示例来源:origin: apache/flink
public void writeRecord(Row row) throws IOException {
if (typesArray != null && typesArray.length > 0 && typesArray.length != row.getArity()) {
LOG.warn("Column SQL types array doesn't match arity of passed Row! Check the passed array...");
for (int index = 0; index < row.getArity(); index++) {
LOG.warn("Unknown column type for column {}. Best effort approach to set its value: {}.", index + 1, row.getField(index));
upload.setObject(index + 1, row.getField(index));
for (int index = 0; index < row.getArity(); index++) {
代码示例来源:origin: apache/flink
@Override
public Row copy(Row from, Row reuse) {
int len = fieldSerializers.length;
// cannot reuse, do a non-reuse copy
if (reuse == null) {
return copy(from);
}
if (from.getArity() != len || reuse.getArity() != len) {
throw new RuntimeException(
"Row arity of reuse or from is incompatible with this RowSerializer.");
}
for (int i = 0; i < len; i++) {
Object fromField = from.getField(i);
if (fromField != null) {
Object reuseField = reuse.getField(i);
if (reuseField != null) {
Object copy = fieldSerializers[i].copy(fromField, reuseField);
reuse.setField(i, copy);
}
else {
Object copy = fieldSerializers[i].copy(fromField);
reuse.setField(i, copy);
}
}
else {
reuse.setField(i, null);
}
}
return reuse;
}
代码示例来源:origin: apache/flink
int arity = row.getArity();
for (int i = 0; i < arity; i++) {
if (row.getField(i) == null) {
代码示例来源:origin: apache/flink
@Override
public Row deserialize(Row reuse, DataInputView source) throws IOException {
int len = fieldSerializers.length;
if (reuse.getArity() != len) {
throw new RuntimeException("Row arity of from does not match serializers.");
}
// read null mask
readIntoNullMask(len, source, nullMask);
for (int i = 0; i < len; i++) {
if (nullMask[i]) {
reuse.setField(i, null);
}
else {
Object reuseField = reuse.getField(i);
if (reuseField != null) {
reuse.setField(i, fieldSerializers[i].deserialize(reuseField, source));
}
else {
reuse.setField(i, fieldSerializers[i].deserialize(source));
}
}
}
return reuse;
}
代码示例来源:origin: apache/flink
final String[] changeRow = new String[change.f1.getArity() + 1];
final String[] row = rowToString(change.f1);
System.arraycopy(row, 0, changeRow, 1, row.length);
代码示例来源:origin: com.alibaba.blink/flink-java
@Override
protected int getFieldsNum(Row record) {
return record.getArity();
}
}
代码示例来源:origin: com.alibaba.blink/flink-table
@Override
public void start() {
// clear last value for each field
for (int i = 0; i < currentRow.getArity(); ++i) {
currentRow.setField(i, null);
}
}
代码示例来源:origin: com.alibaba.blink/flink-table
@Override
public Row convert(Row current) {
if (reuse == null) {
return Row.copy(current);
} else {
Preconditions.checkArgument(current.getArity() == reuse.getArity());
for (int i = 0; i < current.getArity(); ++i) {
reuse.setField(i, current.getField(i));
}
return reuse;
}
}
代码示例来源:origin: com.alibaba.blink/flink-table
@Override
public OUT convert(Row current) {
Object[] values = new Object[current.getArity()];
for (int i = 0; i < current.getArity(); ++i) {
values[i] = current.getField(i);
}
if (reuse == null) {
return tupleSerializer.createInstance(values);
} else {
return tupleSerializer.createOrReuseInstance(values, reuse);
}
}
代码示例来源:origin: DTStack/flinkx
public static String rowToJson(Row row, String[] colName) {
Preconditions.checkNotNull(colName);
Preconditions.checkArgument(row.getArity() == colName.length);
Map<String,Object> map = new HashMap<>();
for(int i = 0; i < colName.length; ++i) {
String key = colName[i];
Object value = row.getField(i);
map.put(key, value);
}
return gson.toJson(map);
}
}
代码示例来源:origin: com.alibaba.blink/flink-table
@Override
protected Row convert(Row current) {
if (reuse == null) {
return Row.copy(current);
} else {
for (int i = 0; i < current.getArity(); ++i) {
reuse.setField(i, current.getField(i));
}
return reuse;
}
}
}
内容来源于网络,如有侵权,请联系作者删除!