use of org.apache.flink.table.sinks.TableSink in project flink by apache.
the class HiveTableFactoryTest method testGenericTable.
@Test
public void testGenericTable() throws Exception {
final TableSchema schema = TableSchema.builder().field("name", DataTypes.STRING()).field("age", DataTypes.INT()).build();
catalog.createDatabase("mydb", new CatalogDatabaseImpl(new HashMap<>(), ""), true);
final Map<String, String> options = Collections.singletonMap(FactoryUtil.CONNECTOR.key(), "COLLECTION");
final CatalogTable table = new CatalogTableImpl(schema, options, "csv table");
catalog.createTable(new ObjectPath("mydb", "mytable"), table, true);
final Optional<TableFactory> tableFactoryOpt = catalog.getTableFactory();
assertTrue(tableFactoryOpt.isPresent());
final HiveTableFactory tableFactory = (HiveTableFactory) tableFactoryOpt.get();
final TableSource tableSource = tableFactory.createTableSource(new TableSourceFactoryContextImpl(ObjectIdentifier.of("mycatalog", "mydb", "mytable"), table, new Configuration(), false));
assertTrue(tableSource instanceof StreamTableSource);
final TableSink tableSink = tableFactory.createTableSink(new TableSinkFactoryContextImpl(ObjectIdentifier.of("mycatalog", "mydb", "mytable"), table, new Configuration(), true, false));
assertTrue(tableSink instanceof StreamTableSink);
}
use of org.apache.flink.table.sinks.TableSink in project flink by apache.
the class TypeMappingUtilsTest method testCheckPhysicalLogicalTypeCompatible.
@Test
public void testCheckPhysicalLogicalTypeCompatible() {
TableSchema tableSchema = TableSchema.builder().field("a", DataTypes.VARCHAR(2)).field("b", DataTypes.DECIMAL(20, 2)).build();
TableSink tableSink = new TestTableSink(tableSchema);
LegacyTypeInformationType legacyDataType = (LegacyTypeInformationType) tableSink.getConsumedDataType().getLogicalType();
TypeInformation legacyTypeInfo = ((TupleTypeInfo) legacyDataType.getTypeInformation()).getTypeAt(1);
DataType physicalType = TypeConversions.fromLegacyInfoToDataType(legacyTypeInfo);
ResolvedSchema physicSchema = DataTypeUtils.expandCompositeTypeToSchema(physicalType);
DataType[] logicalDataTypes = tableSchema.getFieldDataTypes();
List<DataType> physicalDataTypes = physicSchema.getColumnDataTypes();
for (int i = 0; i < logicalDataTypes.length; i++) {
TypeMappingUtils.checkPhysicalLogicalTypeCompatible(physicalDataTypes.get(i).getLogicalType(), logicalDataTypes[i].getLogicalType(), "physicalField", "logicalField", false);
}
}
use of org.apache.flink.table.sinks.TableSink in project flink by apache.
the class CsvTableSinkFactoryTest method testAppendTableSinkFactory.
@Test
public void testAppendTableSinkFactory() {
DescriptorProperties descriptor = createDescriptor(testingSchema);
descriptor.putString("update-mode", "append");
TableSink sink = createTableSink(descriptor);
assertTrue(sink instanceof CsvTableSink);
assertEquals(testingSchema.toRowDataType(), sink.getConsumedDataType());
}
use of org.apache.flink.table.sinks.TableSink in project flink by apache.
the class CsvTableSinkFactoryTest method testBatchTableSinkFactory.
@Test
public void testBatchTableSinkFactory() {
DescriptorProperties descriptor = createDescriptor(testingSchema);
TableSink sink = createTableSink(descriptor);
assertTrue(sink instanceof CsvTableSink);
assertEquals(testingSchema.toRowDataType(), sink.getConsumedDataType());
}
Aggregations