use of org.apache.flink.table.connector.source.DynamicTableSource 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.DynamicTableSource in project flink by apache.
the class HBaseDynamicTableFactoryTest method testLookupAsync.
@Test
public void testLookupAsync() {
Map<String, String> options = getAllOptions();
options.put("lookup.async", "true");
ResolvedSchema schema = ResolvedSchema.of(Column.physical(ROWKEY, STRING()), Column.physical(FAMILY1, ROW(FIELD(COL1, DOUBLE()), FIELD(COL2, INT()))));
DynamicTableSource source = createTableSource(schema, options);
assertTrue(source instanceof HBaseDynamicTableSource);
HBaseDynamicTableSource hbaseSource = (HBaseDynamicTableSource) source;
int[][] lookupKey = { { 0 } };
LookupTableSource.LookupRuntimeProvider lookupProvider = hbaseSource.getLookupRuntimeProvider(new LookupRuntimeProviderContext(lookupKey));
assertTrue(lookupProvider instanceof AsyncTableFunctionProvider);
AsyncTableFunction asyncTableFunction = ((AsyncTableFunctionProvider) lookupProvider).createAsyncTableFunction();
assertTrue(asyncTableFunction instanceof HBaseRowDataAsyncLookupFunction);
assertEquals("testHBastTable", ((HBaseRowDataAsyncLookupFunction) asyncTableFunction).getHTableName());
}
use of org.apache.flink.table.connector.source.DynamicTableSource in project flink by apache.
the class PushWatermarkIntoTableSourceScanRuleBase method supportsWatermarkPushDown.
protected boolean supportsWatermarkPushDown(FlinkLogicalTableSourceScan scan) {
TableSourceTable tableSourceTable = scan.getTable().unwrap(TableSourceTable.class);
if (tableSourceTable == null) {
return false;
}
final DynamicTableSource tableSource = tableSourceTable.tableSource();
return (tableSource instanceof SupportsWatermarkPushDown) || (tableSource instanceof SupportsSourceWatermark && hasSourceWatermarkDeclaration(tableSourceTable));
}
use of org.apache.flink.table.connector.source.DynamicTableSource in project flink by apache.
the class CatalogSourceTable method toRel.
@Override
public RelNode toRel(ToRelContext toRelContext) {
final RelOptCluster cluster = toRelContext.getCluster();
final List<RelHint> hints = toRelContext.getTableHints();
final FlinkContext context = ShortcutUtils.unwrapContext(cluster);
final FlinkRelBuilder relBuilder = FlinkRelBuilder.of(cluster, relOptSchema);
// finalize catalog table with option hints
final Map<String, String> hintedOptions = FlinkHints.getHintedOptions(hints);
final ContextResolvedTable catalogTable = computeContextResolvedTable(context, hintedOptions);
// create table source
final DynamicTableSource tableSource = createDynamicTableSource(context, catalogTable.getResolvedTable());
// prepare table source and convert to RelNode
return DynamicSourceUtils.convertSourceToRel(!schemaTable.isStreamingMode(), context.getTableConfig().getConfiguration(), relBuilder, schemaTable.getContextResolvedTable(), schemaTable.getStatistic(), hints, tableSource);
}
use of org.apache.flink.table.connector.source.DynamicTableSource in project flink by apache.
the class FileSystemTableFactoryTest method testSourceSink.
@Test
public void testSourceSink() {
DescriptorProperties descriptor = new DescriptorProperties();
descriptor.putString(FactoryUtil.CONNECTOR.key(), "filesystem");
descriptor.putString("path", "/tmp");
descriptor.putString("format", "testcsv");
// test ignore format options
descriptor.putString("testcsv.my_option", "my_value");
DynamicTableSource source = createTableSource(SCHEMA, descriptor.asMap());
assertTrue(source instanceof FileSystemTableSource);
DynamicTableSink sink = createTableSink(SCHEMA, descriptor.asMap());
assertTrue(sink instanceof FileSystemTableSink);
}
Aggregations