Java Code Examples for org.apache.flink.addons.hbase.TableInputFormat

The following examples show how to use org.apache.flink.addons.hbase.TableInputFormat. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: flink-learning   Source File: HBaseReadMain.java    License: Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    env.createInput(new TableInputFormat<Tuple2<String, String>>() {

        private Tuple2<String, String> reuse = new Tuple2<String, String>();

        @Override
        protected Scan getScanner() {
            Scan scan = new Scan();
            scan.addColumn(INFO, BAR);
            return scan;
        }

        @Override
        protected String getTableName() {
            return HBASE_TABLE_NAME;
        }

        @Override
        protected Tuple2<String, String> mapResultToTuple(Result result) {
            String key = Bytes.toString(result.getRow());
            String val = Bytes.toString(result.getValue(INFO, BAR));
            reuse.setField(key, 0);
            reuse.setField(val, 1);
            return reuse;
        }
    }).filter(new FilterFunction<Tuple2<String, String>>() {
        @Override
        public boolean filter(Tuple2<String, String> value) throws Exception {
            return value.f1.startsWith("zhisheng");
        }
    }).print();
}
 
Example 2
Source Project: flinkDemo   Source File: FlinkGHBaseByDataSet.java    License: Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

    DataSet<Tuple2<String, String>> hbaseInput =  env.createInput(new TableInputFormat<Tuple2<String, String>>(){
        @Override
        protected Scan getScanner() {
            Scan scan = new Scan();
            scan.setStartRow(Bytes.toBytes("lastSpeed1"));
            scan.setStopRow(Bytes.toBytes("lastSpeed4"));
            return scan;
        }
        @Override
        protected String getTableName() {
            return "dfdq_rhm_aly:f_turbine_event_data";
        }
        @Override
        protected Tuple2<String, String> mapResultToTuple(Result result) {

            Tuple2<String,String> tup = new Tuple2<String,String>();
            tup.setField(Bytes.toString(result.getRow()),0);
            tup.setField(Bytes.toString(result.getValue("f".getBytes(), "slv".getBytes())), 1);
            return tup;
        }
    });

    try {
        hbaseInput.print();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 3
Source Project: flink-learning   Source File: HBaseReadMain.java    License: Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    env.createInput(new TableInputFormat<Tuple2<String, String>>() {

        private Tuple2<String, String> reuse = new Tuple2<String, String>();

        @Override
        protected Scan getScanner() {
            Scan scan = new Scan();
            scan.addColumn(INFO, BAR);
            return scan;
        }

        @Override
        protected String getTableName() {
            return HBASE_TABLE_NAME;
        }

        @Override
        protected Tuple2<String, String> mapResultToTuple(Result result) {
            String key = Bytes.toString(result.getRow());
            String val = Bytes.toString(result.getValue(INFO, BAR));
            reuse.setField(key, 0);
            reuse.setField(val, 1);
            return reuse;
        }
    }).filter(new FilterFunction<Tuple2<String, String>>() {
        @Override
        public boolean filter(Tuple2<String, String> value) throws Exception {
            return value.f1.startsWith("zhisheng");
        }
    }).print();
}