public class HBaseTableSource extends Object implements org.apache.flink.table.sources.BatchTableSource<Row>, ProjectableTableSource<Row>
The table name and required HBase configuration is passed during HBaseTableSource
construction.
Use addColumn(String, String, Class)
to specify the family, qualifier, and type of columns to scan.
The TableSource returns Row
with nested Rows for each column family.
The HBaseTableSource is used as shown in the example below.
HBaseTableSource hSrc = new HBaseTableSource(conf, "hTable");
hSrc.addColumn("fam1", "col1", byte[].class);
hSrc.addColumn("fam1", "col2", Integer.class);
hSrc.addColumn("fam2", "col1", String.class);
tableEnv.registerTableSource("hTable", hSrc);
Table res = tableEnv.sqlQuery("SELECT t.fam2.col1, SUM(t.fam1.col2) FROM hTable AS t GROUP BY t.fam2.col1");
Constructor and Description |
---|
HBaseTableSource(Configuration conf,
String tableName)
The HBase configuration and the name of the table to read.
|
Modifier and Type | Method and Description |
---|---|
void |
addColumn(String family,
String qualifier,
Class<?> clazz)
Adds a column defined by family, qualifier, and type to the table schema.
|
String |
explainSource()
Describes the table source.
|
DataSet<Row> |
getDataSet(ExecutionEnvironment execEnv) |
TypeInformation<Row> |
getReturnType()
Returns the
TypeInformation for the return type of the TableSource . |
TableSchema |
getTableSchema()
Returns the schema of the produced table.
|
HBaseTableSource |
projectFields(int[] fields)
Creates a copy of the
TableSource that projects its output to the given field indexes. |
void |
setCharset(String charset)
Specifies the charset to parse Strings to HBase byte[] keys and String values.
|
public HBaseTableSource(Configuration conf, String tableName)
conf
- hbase configurationtableName
- the tableNamepublic void addColumn(String family, String qualifier, Class<?> clazz)
family
- the family namequalifier
- the qualifier nameclazz
- the data type of the qualifierpublic void setCharset(String charset)
charset
- Name of the charset to use.public TypeInformation<Row> getReturnType()
TableSource
TypeInformation
for the return type of the TableSource
.
The fields of the return type are mapped to the table schema based on their name.getReturnType
in interface TableSource<Row>
DataSet
or DataStream
.public TableSchema getTableSchema()
TableSource
getTableSchema
in interface TableSource<Row>
TableSchema
of the produced table.public DataSet<Row> getDataSet(ExecutionEnvironment execEnv)
getDataSet
in interface org.apache.flink.table.sources.BatchTableSource<Row>
public HBaseTableSource projectFields(int[] fields)
ProjectableTableSource
TableSource
that projects its output to the given field indexes.
The field indexes relate to the physical return type (TableSource.getReturnType()
) and not
to the table schema (TableSource.getTableSchema()
of the TableSource
.
The table schema (TableSource.getTableSchema()
of the TableSource
copy must not be
modified by this method, but only the return type (TableSource.getReturnType()
) and the
produced DataSet
(BatchTableSource#getDataSet(
) or DataStream
(StreamTableSource#getDataStream
).
If the TableSource
implements the DefinedFieldMapping
interface, it might
be necessary to adjust the mapping as well.
IMPORTANT: This method must return a true copy and must not modify the original table source object.
projectFields
in interface ProjectableTableSource<Row>
fields
- The indexes of the fields to return.TableSource
that projects its output.public String explainSource()
TableSource
explainSource
in interface TableSource<Row>
TableSource
.Copyright © 2014–2020 The Apache Software Foundation. All rights reserved.