本文整理了Java中org.apache.flink.types.Row.<init>
方法的一些代码示例,展示了Row.<init>
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Row.<init>
方法的具体详情如下:
包路径:org.apache.flink.types.Row
类名称:Row
方法名:<init>
[英]Create a new Row instance.
[中]创建一个新的行实例。
代码示例来源:origin: apache/flink
@Override
public Row createInstance() {
return new Row(fieldSerializers.length);
}
代码示例来源:origin: apache/flink
/**
* Creates a new Row with projected fields from another row.
* This method does not perform a deep copy.
*
* @param fields fields to be projected
* @return the new projected Row
*/
public static Row project(Row row, int[] fields) {
final Row newRow = new Row(fields.length);
for (int i = 0; i < fields.length; i++) {
newRow.fields[i] = row.fields[fields[i]];
}
return newRow;
}
}
代码示例来源:origin: apache/flink
/**
* Creates a new Row which copied from another row.
* This method does not perform a deep copy.
*
* @param row The row being copied.
* @return The cloned new Row
*/
public static Row copy(Row row) {
final Row newRow = new Row(row.fields.length);
System.arraycopy(row.fields, 0, newRow.fields, 0, row.fields.length);
return newRow;
}
代码示例来源:origin: apache/flink
@Override
public void openInputFormat() throws IOException {
super.openInputFormat();
// create and initialize the row batch
this.rows = new Row[batchSize];
for (int i = 0; i < batchSize; i++) {
rows[i] = new Row(selectedFields.length);
}
}
代码示例来源:origin: apache/flink
@Override
protected Row fillRecord(Row reuse, Object[] parsedValues) {
Row reuseRow;
if (reuse == null) {
reuseRow = new Row(arity);
} else {
reuseRow = reuse;
}
for (int i = 0; i < parsedValues.length; i++) {
reuseRow.setField(i, parsedValues[i]);
}
return reuseRow;
}
代码示例来源:origin: apache/flink
@Override
public Object apply(Object o) {
if (o == null) {
return null;
} else {
Row r = (Row) o;
Row copy = new Row(copyFields.length);
for (int i = 0; i < copyFields.length; i++) {
copy.setField(i, copyFields[i].apply(r.getField(i)));
}
return copy;
}
}
}
代码示例来源:origin: apache/flink
private Row convertAvroRecordToRow(Schema schema, RowTypeInfo typeInfo, IndexedRecord record) {
final List<Schema.Field> fields = schema.getFields();
final TypeInformation<?>[] fieldInfo = typeInfo.getFieldTypes();
final int length = fields.size();
final Row row = new Row(length);
for (int i = 0; i < length; i++) {
final Schema.Field field = fields.get(i);
row.setField(i, convertAvroType(field.schema(), fieldInfo[i], record.get(i)));
}
return row;
}
代码示例来源:origin: apache/flink
@Override
public void configure(Configuration parameters) {
LOG.info("Initializing HBase configuration.");
connectToTable();
if (table != null) {
scan = getScanner();
}
// prepare output rows
this.resultRow = new Row(families.length);
this.familyRows = new Row[families.length];
for (int f = 0; f < families.length; f++) {
this.familyRows[f] = new Row(qualifiers[f].length);
this.resultRow.setField(f, this.familyRows[f]);
}
this.stringCharset = Charset.forName(schema.getStringCharset());
}
代码示例来源:origin: apache/flink
@Override
public Row deserialize(DataInputView source) throws IOException {
int len = fieldSerializers.length;
Row result = new Row(len);
// read null mask
readIntoNullMask(len, source, nullMask);
for (int i = 0; i < len; i++) {
if (nullMask[i]) {
result.setField(i, null);
}
else {
result.setField(i, fieldSerializers[i].deserialize(source));
}
}
return result;
}
代码示例来源: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 Row convertRow(JsonNode node, RowTypeInfo info) {
final String[] names = info.getFieldNames();
final TypeInformation<?>[] types = info.getFieldTypes();
final Row row = new Row(names.length);
for (int i = 0; i < names.length; i++) {
final String name = names[i];
final JsonNode subNode = node.get(name);
if (subNode == null) {
if (failOnMissingField) {
throw new IllegalStateException(
"Could not find field with name '" + name + "'.");
} else {
row.setField(i, null);
}
} else {
row.setField(i, convert(subNode, types[i]));
}
}
return row;
}
代码示例来源:origin: apache/flink
private static Row createRow(Object... values) {
checkNotNull(values);
checkArgument(values.length == numberOfFields);
Row row = new Row(numberOfFields);
for (int i = 0; i < values.length; i++) {
row.setField(i, values[i]);
}
return row;
}
}
代码示例来源:origin: apache/flink
private static Row createRow(Object f0, Object f1, Object f2, Object f3, Object f4) {
Row row = new Row(5);
row.setField(0, f0);
row.setField(1, f1);
row.setField(2, f2);
row.setField(3, f3);
row.setField(4, f4);
return row;
}
代码示例来源:origin: apache/flink
private static Row createRow(Object f0, Object f1, Object f2, Object f3, Object f4) {
Row row = new Row(5);
row.setField(0, f0);
row.setField(1, f1);
row.setField(2, f2);
row.setField(3, f3);
row.setField(4, f4);
return row;
}
代码示例来源:origin: apache/flink
@Test
public void testRowSerializer() {
TypeInformation<Row> typeInfo = new RowTypeInfo(
BasicTypeInfo.INT_TYPE_INFO,
BasicTypeInfo.STRING_TYPE_INFO);
Row row1 = new Row(2);
row1.setField(0, 1);
row1.setField(1, "a");
Row row2 = new Row(2);
row2.setField(0, 2);
row2.setField(1, null);
TypeSerializer<Row> serializer = typeInfo.createSerializer(new ExecutionConfig());
RowSerializerTestInstance instance = new RowSerializerTestInstance(serializer, row1, row2);
instance.testAll();
}
代码示例来源:origin: apache/flink
@Test
public void testRow() {
Row row = new Row(2);
row.setField(0, "string");
row.setField(1, 15);
TypeInformation<Row> rowInfo = TypeExtractor.getForObject(row);
Assert.assertEquals(rowInfo.getClass(), RowTypeInfo.class);
Assert.assertEquals(2, rowInfo.getArity());
Assert.assertEquals(
new RowTypeInfo(
BasicTypeInfo.STRING_TYPE_INFO,
BasicTypeInfo.INT_TYPE_INFO),
rowInfo);
Row nullRow = new Row(2);
TypeInformation<Row> genericRowInfo = TypeExtractor.getForObject(nullRow);
Assert.assertEquals(genericRowInfo, new GenericTypeInfo<>(Row.class));
}
代码示例来源:origin: apache/flink
@Test
public void testRowProject() {
Row row = new Row(5);
row.setField(0, 1);
row.setField(1, "hello");
row.setField(2, null);
row.setField(3, new Tuple2<>(2, "hi"));
row.setField(4, "hello world");
Row projected = Row.project(row, new int[]{0, 2, 4});
Row expected = new Row(3);
expected.setField(0, 1);
expected.setField(1, null);
expected.setField(2, "hello world");
assertEquals(expected, projected);
}
}
代码示例来源:origin: apache/flink
@Test
public void testRowToString() {
Row row = new Row(5);
row.setField(0, 1);
row.setField(1, "hello");
row.setField(2, null);
row.setField(3, new Tuple2<>(2, "hi"));
row.setField(4, "hello world");
assertEquals("1,hello,null,(2,hi),hello world", row.toString());
}
代码示例来源:origin: apache/flink
@Test
public void testRowOf() {
Row row1 = Row.of(1, "hello", null, Tuple2.of(2L, "hi"), true);
Row row2 = new Row(5);
row2.setField(0, 1);
row2.setField(1, "hello");
row2.setField(2, null);
row2.setField(3, new Tuple2<>(2L, "hi"));
row2.setField(4, true);
assertEquals(row1, row2);
}
代码示例来源:origin: apache/flink
@Test
public void testRowCopy() {
Row row = new Row(5);
row.setField(0, 1);
row.setField(1, "hello");
row.setField(2, null);
row.setField(3, new Tuple2<>(2, "hi"));
row.setField(4, "hello world");
Row copy = Row.copy(row);
assertEquals(row, copy);
assertTrue(row != copy);
}
内容来源于网络,如有侵权,请联系作者删除!