use of org.apache.flink.table.data.GenericRowData in project flink by apache.
the class HBaseSerde method convertToRow.
private RowData convertToRow(Result result, GenericRowData resultRow, GenericRowData[] familyRows) {
for (int i = 0; i < fieldLength; i++) {
if (rowkeyIndex == i) {
assert keyDecoder != null;
Object rowkey = keyDecoder.decode(result.getRow());
resultRow.setField(rowkeyIndex, rowkey);
} else {
int f = (rowkeyIndex != -1 && i > rowkeyIndex) ? i - 1 : i;
// get family key
byte[] familyKey = families[f];
GenericRowData familyRow = familyRows[f];
for (int q = 0; q < this.qualifiers[f].length; q++) {
// get quantifier key
byte[] qualifier = qualifiers[f][q];
// read value
byte[] value = result.getValue(familyKey, qualifier);
familyRow.setField(q, qualifierDecoders[f][q].decode(value));
}
resultRow.setField(i, familyRow);
}
}
return resultRow;
}
use of org.apache.flink.table.data.GenericRowData in project flink by apache.
the class ElasticsearchDynamicSinkBaseITCase method testWritingDocuments.
@Test
public void testWritingDocuments() throws Exception {
ResolvedSchema schema = new ResolvedSchema(Arrays.asList(Column.physical("a", DataTypes.BIGINT().notNull()), Column.physical("b", DataTypes.TIME()), Column.physical("c", DataTypes.STRING().notNull()), Column.physical("d", DataTypes.FLOAT()), Column.physical("e", DataTypes.TINYINT().notNull()), Column.physical("f", DataTypes.DATE()), Column.physical("g", DataTypes.TIMESTAMP().notNull())), Collections.emptyList(), UniqueConstraint.primaryKey("name", Arrays.asList("a", "g")));
GenericRowData rowData = GenericRowData.of(1L, 12345, StringData.fromString("ABCDE"), 12.12f, (byte) 2, 12345, TimestampData.fromLocalDateTime(LocalDateTime.parse("2012-12-12T12:12:12")));
String index = "writing-documents";
ElasticsearchDynamicSinkFactoryBase sinkFactory = getDynamicSinkFactory();
DynamicTableSink.SinkRuntimeProvider runtimeProvider = sinkFactory.createDynamicTableSink(getPrefilledTestContext(index).withSchema(schema).build()).getSinkRuntimeProvider(new ElasticsearchUtil.MockContext());
final SinkV2Provider sinkProvider = (SinkV2Provider) runtimeProvider;
final Sink<RowData> sink = sinkProvider.createSink();
StreamExecutionEnvironment environment = StreamExecutionEnvironment.getExecutionEnvironment();
environment.setParallelism(4);
rowData.setRowKind(RowKind.UPDATE_AFTER);
environment.<RowData>fromElements(rowData).sinkTo(sink);
environment.execute();
RestHighLevelClient client = getClient();
Map<String, Object> response = makeGetRequest(client, index, "1_2012-12-12T12:12:12");
Map<Object, Object> expectedMap = new HashMap<>();
expectedMap.put("a", 1);
expectedMap.put("b", "00:00:12");
expectedMap.put("c", "ABCDE");
expectedMap.put("d", 12.12d);
expectedMap.put("e", 2);
expectedMap.put("f", "2003-10-20");
expectedMap.put("g", "2012-12-12 12:12:12");
Assertions.assertEquals(response, expectedMap);
}
use of org.apache.flink.table.data.GenericRowData in project flink by apache.
the class HBaseRowDataAsyncLookupFunction method fetchResult.
/**
* Execute async fetch result .
*
* @param resultFuture The result or exception is returned.
* @param currentRetry Current number of retries.
* @param rowKey the lookup key.
*/
private void fetchResult(CompletableFuture<Collection<RowData>> resultFuture, int currentRetry, Object rowKey) {
Get get = serde.createGet(rowKey);
CompletableFuture<Result> responseFuture = table.get(get);
responseFuture.whenCompleteAsync((result, throwable) -> {
if (throwable != null) {
if (throwable instanceof TableNotFoundException) {
LOG.error("Table '{}' not found ", hTableName, throwable);
resultFuture.completeExceptionally(new RuntimeException("HBase table '" + hTableName + "' not found.", throwable));
} else {
LOG.error(String.format("HBase asyncLookup error, retry times = %d", currentRetry), throwable);
if (currentRetry >= maxRetryTimes) {
resultFuture.completeExceptionally(throwable);
} else {
try {
Thread.sleep(1000 * currentRetry);
} catch (InterruptedException e1) {
resultFuture.completeExceptionally(e1);
}
fetchResult(resultFuture, currentRetry + 1, rowKey);
}
}
} else {
if (result.isEmpty()) {
resultFuture.complete(Collections.emptyList());
if (cache != null) {
cache.put(rowKey, new GenericRowData(0));
}
} else {
if (cache != null) {
RowData rowData = serde.convertToNewRow(result);
resultFuture.complete(Collections.singletonList(rowData));
cache.put(rowKey, rowData);
} else {
resultFuture.complete(Collections.singletonList(serde.convertToNewRow(result)));
}
}
}
});
}
use of org.apache.flink.table.data.GenericRowData in project flink by apache.
the class PartitionPathUtils method fillPartitionValueForRecord.
/**
* Extract partition value from path and fill to record.
*
* @param fieldNames record field names.
* @param fieldTypes record field types.
* @param selectFields the selected fields.
* @param partitionKeys the partition field names.
* @param path the file path that the partition located.
* @param defaultPartValue default value of partition field.
* @return the filled record.
*/
public static GenericRowData fillPartitionValueForRecord(String[] fieldNames, DataType[] fieldTypes, int[] selectFields, List<String> partitionKeys, Path path, String defaultPartValue) {
GenericRowData record = new GenericRowData(selectFields.length);
LinkedHashMap<String, String> partSpec = PartitionPathUtils.extractPartitionSpecFromPath(path);
for (int i = 0; i < selectFields.length; i++) {
int selectField = selectFields[i];
String name = fieldNames[selectField];
if (partitionKeys.contains(name)) {
String value = partSpec.get(name);
value = defaultPartValue.equals(value) ? null : value;
record.setField(i, PartitionPathUtils.convertStringToInternalValue(value, fieldTypes[selectField]));
}
}
return record;
}
use of org.apache.flink.table.data.GenericRowData in project flink by apache.
the class FirstValueAggFunction method createAccumulator.
// --------------------------------------------------------------------------------------------
// Runtime
// --------------------------------------------------------------------------------------------
@Override
public RowData createAccumulator() {
GenericRowData acc = new GenericRowData(2);
acc.setField(0, null);
acc.setField(1, Long.MAX_VALUE);
return acc;
}
Aggregations