use of org.apache.flink.table.connector.source.TableFunctionProvider 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"));
}
use of org.apache.flink.table.connector.source.TableFunctionProvider 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"));
}
use of org.apache.flink.table.connector.source.TableFunctionProvider in project flink by apache.
the class LookupJoinUtil method getLookupFunction.
/**
* Gets LookupFunction from temporal table according to the given lookup keys.
*/
public static UserDefinedFunction getLookupFunction(RelOptTable temporalTable, Collection<Integer> lookupKeys) {
int[] lookupKeyIndicesInOrder = getOrderedLookupKeys(lookupKeys);
if (temporalTable instanceof TableSourceTable) {
// TODO: support nested lookup keys in the future,
// currently we only support top-level lookup keys
int[][] indices = IntStream.of(lookupKeyIndicesInOrder).mapToObj(i -> new int[] { i }).toArray(int[][]::new);
LookupTableSource tableSource = (LookupTableSource) ((TableSourceTable) temporalTable).tableSource();
LookupRuntimeProviderContext providerContext = new LookupRuntimeProviderContext(indices);
LookupTableSource.LookupRuntimeProvider provider = tableSource.getLookupRuntimeProvider(providerContext);
if (provider instanceof TableFunctionProvider) {
return ((TableFunctionProvider<?>) provider).createTableFunction();
} else if (provider instanceof AsyncTableFunctionProvider) {
return ((AsyncTableFunctionProvider<?>) provider).createAsyncTableFunction();
}
}
if (temporalTable instanceof LegacyTableSourceTable) {
String[] lookupFieldNamesInOrder = IntStream.of(lookupKeyIndicesInOrder).mapToObj(temporalTable.getRowType().getFieldNames()::get).toArray(String[]::new);
LegacyTableSourceTable<?> legacyTableSourceTable = (LegacyTableSourceTable<?>) temporalTable;
LookupableTableSource<?> tableSource = (LookupableTableSource<?>) legacyTableSourceTable.tableSource();
if (tableSource.isAsyncEnabled()) {
return tableSource.getAsyncLookupFunction(lookupFieldNamesInOrder);
} else {
return tableSource.getLookupFunction(lookupFieldNamesInOrder);
}
}
throw new TableException(String.format("table %s is neither TableSourceTable not LegacyTableSourceTable", temporalTable.getQualifiedName()));
}
Aggregations