Search in sources :

Example 36 with BatchTableEnvironment

use of org.apache.flink.table.api.java.BatchTableEnvironment in project flink by apache.

the class HBaseConnectorITCase method testTableSourceFullScan.

// ######## HBaseTableSource tests ############
@Test
public void testTableSourceFullScan() throws Exception {
    ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    env.setParallelism(4);
    BatchTableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env, new TableConfig());
    HBaseTableSource hbaseTable = new HBaseTableSource(getConf(), TEST_TABLE);
    hbaseTable.addColumn(FAMILY1, F1COL1, Integer.class);
    hbaseTable.addColumn(FAMILY2, F2COL1, String.class);
    hbaseTable.addColumn(FAMILY2, F2COL2, Long.class);
    hbaseTable.addColumn(FAMILY3, F3COL1, Double.class);
    hbaseTable.addColumn(FAMILY3, F3COL2, Boolean.class);
    hbaseTable.addColumn(FAMILY3, F3COL3, String.class);
    tableEnv.registerTableSource("hTable", hbaseTable);
    Table result = tableEnv.sql("SELECT " + "  h.family1.col1, " + "  h.family2.col1, " + "  h.family2.col2, " + "  h.family3.col1, " + "  h.family3.col2, " + "  h.family3.col3 " + "FROM hTable AS h");
    DataSet<Row> resultSet = tableEnv.toDataSet(result, Row.class);
    List<Row> results = resultSet.collect();
    String expected = "10,Hello-1,100,1.01,false,Welt-1\n" + "20,Hello-2,200,2.02,true,Welt-2\n" + "30,Hello-3,300,3.03,false,Welt-3\n" + "40,null,400,4.04,true,Welt-4\n" + "50,Hello-5,500,5.05,false,Welt-5\n" + "60,Hello-6,600,6.06,true,Welt-6\n" + "70,Hello-7,700,7.07,false,Welt-7\n" + "80,null,800,8.08,true,Welt-8\n";
    TestBaseUtils.compareResultAsText(results, expected);
}
Also used : ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) Table(org.apache.flink.table.api.Table) HTable(org.apache.hadoop.hbase.client.HTable) TableConfig(org.apache.flink.table.api.TableConfig) Row(org.apache.flink.types.Row) BatchTableEnvironment(org.apache.flink.table.api.java.BatchTableEnvironment) Test(org.junit.Test)

Example 37 with BatchTableEnvironment

use of org.apache.flink.table.api.java.BatchTableEnvironment in project flink by apache.

the class HBaseConnectorITCase method testTableSourceProjection.

@Test
public void testTableSourceProjection() throws Exception {
    ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    env.setParallelism(4);
    BatchTableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env, new TableConfig());
    HBaseTableSource hbaseTable = new HBaseTableSource(getConf(), TEST_TABLE);
    hbaseTable.addColumn(FAMILY1, F1COL1, Integer.class);
    hbaseTable.addColumn(FAMILY2, F2COL1, String.class);
    hbaseTable.addColumn(FAMILY2, F2COL2, Long.class);
    hbaseTable.addColumn(FAMILY3, F3COL1, Double.class);
    hbaseTable.addColumn(FAMILY3, F3COL2, Boolean.class);
    hbaseTable.addColumn(FAMILY3, F3COL3, String.class);
    tableEnv.registerTableSource("hTable", hbaseTable);
    Table result = tableEnv.sql("SELECT " + "  h.family1.col1, " + "  h.family3.col1, " + "  h.family3.col2, " + "  h.family3.col3 " + "FROM hTable AS h");
    DataSet<Row> resultSet = tableEnv.toDataSet(result, Row.class);
    List<Row> results = resultSet.collect();
    String expected = "10,1.01,false,Welt-1\n" + "20,2.02,true,Welt-2\n" + "30,3.03,false,Welt-3\n" + "40,4.04,true,Welt-4\n" + "50,5.05,false,Welt-5\n" + "60,6.06,true,Welt-6\n" + "70,7.07,false,Welt-7\n" + "80,8.08,true,Welt-8\n";
    TestBaseUtils.compareResultAsText(results, expected);
}
Also used : ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) Table(org.apache.flink.table.api.Table) HTable(org.apache.hadoop.hbase.client.HTable) TableConfig(org.apache.flink.table.api.TableConfig) Row(org.apache.flink.types.Row) BatchTableEnvironment(org.apache.flink.table.api.java.BatchTableEnvironment) Test(org.junit.Test)

Example 38 with BatchTableEnvironment

use of org.apache.flink.table.api.java.BatchTableEnvironment in project flink by apache.

the class HBaseConnectorITCase method testTableSourceReadAsByteArray.

@Test
public void testTableSourceReadAsByteArray() throws Exception {
    ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    env.setParallelism(4);
    BatchTableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env, new TableConfig());
    // fetch row2 from the table till the end
    HBaseTableSource hbaseTable = new HBaseTableSource(getConf(), TEST_TABLE);
    hbaseTable.addColumn(FAMILY2, F2COL1, byte[].class);
    hbaseTable.addColumn(FAMILY2, F2COL2, byte[].class);
    tableEnv.registerTableSource("hTable", hbaseTable);
    tableEnv.registerFunction("toUTF8", new ToUTF8());
    tableEnv.registerFunction("toLong", new ToLong());
    Table result = tableEnv.sql("SELECT " + "  toUTF8(h.family2.col1), " + "  toLong(h.family2.col2) " + "FROM hTable AS h");
    DataSet<Row> resultSet = tableEnv.toDataSet(result, Row.class);
    List<Row> results = resultSet.collect();
    String expected = "Hello-1,100\n" + "Hello-2,200\n" + "Hello-3,300\n" + "null,400\n" + "Hello-5,500\n" + "Hello-6,600\n" + "Hello-7,700\n" + "null,800\n";
    TestBaseUtils.compareResultAsText(results, expected);
}
Also used : ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) Table(org.apache.flink.table.api.Table) HTable(org.apache.hadoop.hbase.client.HTable) TableConfig(org.apache.flink.table.api.TableConfig) Row(org.apache.flink.types.Row) BatchTableEnvironment(org.apache.flink.table.api.java.BatchTableEnvironment) Test(org.junit.Test)

Aggregations

ExecutionEnvironment (org.apache.flink.api.java.ExecutionEnvironment)38 BatchTableEnvironment (org.apache.flink.table.api.java.BatchTableEnvironment)38 Test (org.junit.Test)36 Table (org.apache.flink.table.api.Table)30 Row (org.apache.flink.types.Row)19 Tuple3 (org.apache.flink.api.java.tuple.Tuple3)12 ArrayList (java.util.ArrayList)6 TableConfig (org.apache.flink.table.api.TableConfig)4 HTable (org.apache.hadoop.hbase.client.HTable)4 Tuple5 (org.apache.flink.api.java.tuple.Tuple5)2 BatchTableSource (org.apache.flink.table.sources.BatchTableSource)2 HashMap (java.util.HashMap)1 Tuple4 (org.apache.flink.api.java.tuple.Tuple4)1 TupleTypeInfo (org.apache.flink.api.java.typeutils.TupleTypeInfo)1 CalciteConfig (org.apache.flink.table.calcite.CalciteConfig)1 CalciteConfigBuilder (org.apache.flink.table.calcite.CalciteConfigBuilder)1