@Internal public class HBaseTableSource extends Object implements BatchTableSource<Row>, ProjectableTableSource<Row>, StreamTableSource<Row>, LookupableTableSource<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.setRowKey("rowkey", String.class);
hSrc.addColumn("fam1", "col1", byte[].class);
hSrc.addColumn("fam1", "col2", Integer.class);
hSrc.addColumn("fam2", "col1", String.class);
tableEnv.registerTableSourceInternal("hTable", hSrc);
Table res = tableEnv.sqlQuery(
"SELECT t.fam2.col1, SUM(t.fam1.col2) FROM hTable AS t " +
"WHERE t.rowkey LIKE 'flink%' GROUP BY t.fam2.col1");
Constructor and Description |
---|
HBaseTableSource(Configuration conf,
String tableName)
The HBase configuration and the name of the table to read.
|
HBaseTableSource(Configuration conf,
String tableName,
HBaseTableSchema hbaseSchema,
int[] projectFields) |
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.
|
AsyncTableFunction<Row> |
getAsyncLookupFunction(String[] lookupKeys)
Gets the
AsyncTableFunction which supports async lookup one key at a time. |
DataSet<Row> |
getDataSet(ExecutionEnvironment execEnv)
Returns the data of the table as a
DataSet . |
DataStream<Row> |
getDataStream(StreamExecutionEnvironment execEnv)
Returns the data of the table as a
DataStream . |
HBaseTableSchema |
getHBaseTableSchema() |
TableFunction<Row> |
getLookupFunction(String[] lookupKeys)
Gets the
TableFunction which supports lookup one key at a time. |
TypeInformation<Row> |
getReturnType() |
TableSchema |
getTableSchema()
Returns the schema of the produced table.
|
boolean |
isAsyncEnabled()
Returns true if async lookup is enabled.
|
boolean |
isBounded()
Returns true if this is a bounded source, false if this is an unbounded source.
|
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.
|
void |
setRowKey(String rowKeyName,
Class<?> clazz)
Sets row key information in the table schema.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getProducedDataType
public HBaseTableSource(Configuration conf, String tableName)
conf
- hbase configurationtableName
- the tableNamepublic HBaseTableSource(Configuration conf, String tableName, HBaseTableSchema hbaseSchema, int[] projectFields)
public void addColumn(String family, String qualifier, Class<?> clazz)
family
- the family namequalifier
- the qualifier nameclazz
- the data type of the qualifierpublic void setRowKey(String rowKeyName, Class<?> clazz)
rowKeyName
- the row key field nameclazz
- the data type of the row keypublic void setCharset(String charset)
charset
- Name of the charset to use.public TypeInformation<Row> getReturnType()
getReturnType
in interface TableSource<Row>
public TableSchema getTableSchema()
TableSource
getTableSchema
in interface TableSource<Row>
TableSchema
of the produced table.public DataSet<Row> getDataSet(ExecutionEnvironment execEnv)
BatchTableSource
DataSet
.
NOTE: This method is for internal use only for defining a TableSource
. Do not use
it in Table API programs.
getDataSet
in interface 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 poduced data type (TableSource.getProducedDataType()
) 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 produced data type (TableSource.getProducedDataType()
) 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
.public TableFunction<Row> getLookupFunction(String[] lookupKeys)
LookupableTableSource
TableFunction
which supports lookup one key at a time.getLookupFunction
in interface LookupableTableSource<Row>
lookupKeys
- the chosen field names as lookup keys, it is in the defined orderpublic AsyncTableFunction<Row> getAsyncLookupFunction(String[] lookupKeys)
LookupableTableSource
AsyncTableFunction
which supports async lookup one key at a time.getAsyncLookupFunction
in interface LookupableTableSource<Row>
lookupKeys
- the chosen field names as lookup keys, it is in the defined orderpublic boolean isAsyncEnabled()
LookupableTableSource
The lookup function returned by LookupableTableSource.getAsyncLookupFunction(String[])
will be used if
returns true. Otherwise, the lookup function returned by LookupableTableSource.getLookupFunction(String[])
will be used.
isAsyncEnabled
in interface LookupableTableSource<Row>
public boolean isBounded()
StreamTableSource
isBounded
in interface StreamTableSource<Row>
public DataStream<Row> getDataStream(StreamExecutionEnvironment execEnv)
StreamTableSource
DataStream
.
NOTE: This method is for internal use only for defining a TableSource
. Do not use
it in Table API programs.
getDataStream
in interface StreamTableSource<Row>
@VisibleForTesting public HBaseTableSchema getHBaseTableSchema()
Copyright © 2014–2021 The Apache Software Foundation. All rights reserved.