Search in sources :

Example 1 with HBaseRowDataLookupFunction

use of org.apache.flink.connector.hbase.source.HBaseRowDataLookupFunction in project flink by apache.

the class HBaseDynamicTableSource method getLookupRuntimeProvider.

@Override
public LookupRuntimeProvider getLookupRuntimeProvider(LookupContext context) {
    checkArgument(context.getKeys().length == 1 && context.getKeys()[0].length == 1, "Currently, HBase table can only be lookup by single rowkey.");
    checkArgument(hbaseSchema.getRowKeyName().isPresent(), "HBase schema must have a row key when used in lookup mode.");
    checkArgument(DataType.getFieldNames(hbaseSchema.convertToDataType()).get(context.getKeys()[0][0]).equals(hbaseSchema.getRowKeyName().get()), "Currently, HBase table only supports lookup by rowkey field.");
    if (lookupOptions.getLookupAsync()) {
        return AsyncTableFunctionProvider.of(new HBaseRowDataAsyncLookupFunction(conf, tableName, hbaseSchema, nullStringLiteral, lookupOptions));
    } else {
        return TableFunctionProvider.of(new HBaseRowDataLookupFunction(conf, tableName, hbaseSchema, nullStringLiteral, lookupOptions));
    }
}
Also used : HBaseRowDataLookupFunction(org.apache.flink.connector.hbase.source.HBaseRowDataLookupFunction)

Example 2 with HBaseRowDataLookupFunction

use of org.apache.flink.connector.hbase.source.HBaseRowDataLookupFunction in project flink by apache.

the class HBaseDynamicTableFactoryTest method testTableSourceFactory.

@SuppressWarnings("rawtypes")
@Test
public void testTableSourceFactory() {
    ResolvedSchema schema = ResolvedSchema.of(Column.physical(FAMILY1, ROW(FIELD(COL1, INT()))), Column.physical(FAMILY2, ROW(FIELD(COL1, INT()), FIELD(COL2, BIGINT()))), Column.physical(ROWKEY, BIGINT()), Column.physical(FAMILY3, ROW(FIELD(COL1, DOUBLE()), FIELD(COL2, BOOLEAN()), FIELD(COL3, STRING()))), Column.physical(FAMILY4, ROW(FIELD(COL1, DECIMAL(10, 3)), FIELD(COL2, TIMESTAMP(3)), FIELD(COL3, DATE()), FIELD(COL4, TIME()))));
    DynamicTableSource source = createTableSource(schema, getAllOptions());
    assertTrue(source instanceof HBaseDynamicTableSource);
    HBaseDynamicTableSource hbaseSource = (HBaseDynamicTableSource) source;
    int[][] lookupKey = { { 2 } };
    LookupTableSource.LookupRuntimeProvider lookupProvider = hbaseSource.getLookupRuntimeProvider(new LookupRuntimeProviderContext(lookupKey));
    assertTrue(lookupProvider instanceof TableFunctionProvider);
    TableFunction tableFunction = ((TableFunctionProvider) lookupProvider).createTableFunction();
    assertTrue(tableFunction instanceof HBaseRowDataLookupFunction);
    assertEquals("testHBastTable", ((HBaseRowDataLookupFunction) tableFunction).getHTableName());
    HBaseTableSchema hbaseSchema = hbaseSource.getHBaseTableSchema();
    assertEquals(2, hbaseSchema.getRowKeyIndex());
    assertEquals(Optional.of(Types.LONG), hbaseSchema.getRowKeyTypeInfo());
    assertArrayEquals(new String[] { "f1", "f2", "f3", "f4" }, hbaseSchema.getFamilyNames());
    assertArrayEquals(new String[] { "c1" }, hbaseSchema.getQualifierNames("f1"));
    assertArrayEquals(new String[] { "c1", "c2" }, hbaseSchema.getQualifierNames("f2"));
    assertArrayEquals(new String[] { "c1", "c2", "c3" }, hbaseSchema.getQualifierNames("f3"));
    assertArrayEquals(new String[] { "c1", "c2", "c3", "c4" }, hbaseSchema.getQualifierNames("f4"));
    assertArrayEquals(new DataType[] { INT() }, hbaseSchema.getQualifierDataTypes("f1"));
    assertArrayEquals(new DataType[] { INT(), BIGINT() }, hbaseSchema.getQualifierDataTypes("f2"));
    assertArrayEquals(new DataType[] { DOUBLE(), BOOLEAN(), STRING() }, hbaseSchema.getQualifierDataTypes("f3"));
    assertArrayEquals(new DataType[] { DECIMAL(10, 3), TIMESTAMP(3), DATE(), TIME() }, hbaseSchema.getQualifierDataTypes("f4"));
}
Also used : HBaseDynamicTableSource(org.apache.flink.connector.hbase1.source.HBaseDynamicTableSource) HBaseRowDataLookupFunction(org.apache.flink.connector.hbase.source.HBaseRowDataLookupFunction) LookupRuntimeProviderContext(org.apache.flink.table.runtime.connector.source.LookupRuntimeProviderContext) LookupTableSource(org.apache.flink.table.connector.source.LookupTableSource) HBaseTableSchema(org.apache.flink.connector.hbase.util.HBaseTableSchema) TableFunction(org.apache.flink.table.functions.TableFunction) ResolvedSchema(org.apache.flink.table.catalog.ResolvedSchema) DynamicTableSource(org.apache.flink.table.connector.source.DynamicTableSource) HBaseDynamicTableSource(org.apache.flink.connector.hbase1.source.HBaseDynamicTableSource) TableFunctionProvider(org.apache.flink.table.connector.source.TableFunctionProvider) Test(org.junit.Test)

Example 3 with HBaseRowDataLookupFunction

use of org.apache.flink.connector.hbase.source.HBaseRowDataLookupFunction in project flink by apache.

the class HBaseDynamicTableFactoryTest method testTableSourceFactory.

@SuppressWarnings("rawtypes")
@Test
public void testTableSourceFactory() {
    ResolvedSchema schema = ResolvedSchema.of(Column.physical(FAMILY1, ROW(FIELD(COL1, INT()))), Column.physical(FAMILY2, ROW(FIELD(COL1, INT()), FIELD(COL2, BIGINT()))), Column.physical(ROWKEY, BIGINT()), Column.physical(FAMILY3, ROW(FIELD(COL1, DOUBLE()), FIELD(COL2, BOOLEAN()), FIELD(COL3, STRING()))), Column.physical(FAMILY4, ROW(FIELD(COL1, DECIMAL(10, 3)), FIELD(COL2, TIMESTAMP(3)), FIELD(COL3, DATE()), FIELD(COL4, TIME()))));
    DynamicTableSource source = createTableSource(schema, getAllOptions());
    assertTrue(source instanceof HBaseDynamicTableSource);
    HBaseDynamicTableSource hbaseSource = (HBaseDynamicTableSource) source;
    int[][] lookupKey = { { 2 } };
    LookupTableSource.LookupRuntimeProvider lookupProvider = hbaseSource.getLookupRuntimeProvider(new LookupRuntimeProviderContext(lookupKey));
    assertTrue(lookupProvider instanceof TableFunctionProvider);
    TableFunction tableFunction = ((TableFunctionProvider) lookupProvider).createTableFunction();
    assertTrue(tableFunction instanceof HBaseRowDataLookupFunction);
    assertEquals("testHBastTable", ((HBaseRowDataLookupFunction) tableFunction).getHTableName());
    HBaseTableSchema hbaseSchema = hbaseSource.getHBaseTableSchema();
    assertEquals(2, hbaseSchema.getRowKeyIndex());
    assertEquals(Optional.of(Types.LONG), hbaseSchema.getRowKeyTypeInfo());
    assertArrayEquals(new String[] { "f1", "f2", "f3", "f4" }, hbaseSchema.getFamilyNames());
    assertArrayEquals(new String[] { "c1" }, hbaseSchema.getQualifierNames("f1"));
    assertArrayEquals(new String[] { "c1", "c2" }, hbaseSchema.getQualifierNames("f2"));
    assertArrayEquals(new String[] { "c1", "c2", "c3" }, hbaseSchema.getQualifierNames("f3"));
    assertArrayEquals(new String[] { "c1", "c2", "c3", "c4" }, hbaseSchema.getQualifierNames("f4"));
    assertArrayEquals(new DataType[] { INT() }, hbaseSchema.getQualifierDataTypes("f1"));
    assertArrayEquals(new DataType[] { INT(), BIGINT() }, hbaseSchema.getQualifierDataTypes("f2"));
    assertArrayEquals(new DataType[] { DOUBLE(), BOOLEAN(), STRING() }, hbaseSchema.getQualifierDataTypes("f3"));
    assertArrayEquals(new DataType[] { DECIMAL(10, 3), TIMESTAMP(3), DATE(), TIME() }, hbaseSchema.getQualifierDataTypes("f4"));
}
Also used : HBaseDynamicTableSource(org.apache.flink.connector.hbase2.source.HBaseDynamicTableSource) HBaseRowDataLookupFunction(org.apache.flink.connector.hbase.source.HBaseRowDataLookupFunction) LookupRuntimeProviderContext(org.apache.flink.table.runtime.connector.source.LookupRuntimeProviderContext) LookupTableSource(org.apache.flink.table.connector.source.LookupTableSource) HBaseTableSchema(org.apache.flink.connector.hbase.util.HBaseTableSchema) TableFunction(org.apache.flink.table.functions.TableFunction) AsyncTableFunction(org.apache.flink.table.functions.AsyncTableFunction) ResolvedSchema(org.apache.flink.table.catalog.ResolvedSchema) DynamicTableSource(org.apache.flink.table.connector.source.DynamicTableSource) HBaseDynamicTableSource(org.apache.flink.connector.hbase2.source.HBaseDynamicTableSource) AsyncTableFunctionProvider(org.apache.flink.table.connector.source.AsyncTableFunctionProvider) TableFunctionProvider(org.apache.flink.table.connector.source.TableFunctionProvider) Test(org.junit.Test)

Aggregations

HBaseRowDataLookupFunction (org.apache.flink.connector.hbase.source.HBaseRowDataLookupFunction)3 HBaseTableSchema (org.apache.flink.connector.hbase.util.HBaseTableSchema)2 ResolvedSchema (org.apache.flink.table.catalog.ResolvedSchema)2 DynamicTableSource (org.apache.flink.table.connector.source.DynamicTableSource)2 LookupTableSource (org.apache.flink.table.connector.source.LookupTableSource)2 TableFunctionProvider (org.apache.flink.table.connector.source.TableFunctionProvider)2 TableFunction (org.apache.flink.table.functions.TableFunction)2 LookupRuntimeProviderContext (org.apache.flink.table.runtime.connector.source.LookupRuntimeProviderContext)2 Test (org.junit.Test)2 HBaseDynamicTableSource (org.apache.flink.connector.hbase1.source.HBaseDynamicTableSource)1 HBaseDynamicTableSource (org.apache.flink.connector.hbase2.source.HBaseDynamicTableSource)1 AsyncTableFunctionProvider (org.apache.flink.table.connector.source.AsyncTableFunctionProvider)1 AsyncTableFunction (org.apache.flink.table.functions.AsyncTableFunction)1