use of org.apache.flink.table.connector.sink.DynamicTableSink in project flink by apache.
the class OggJsonFormatFactoryTest method testSeDeSchema.
@Test
public void testSeDeSchema() {
final Map<String, String> options = getAllOptions();
final OggJsonSerializationSchema expectedSer = new OggJsonSerializationSchema((RowType) PHYSICAL_DATA_TYPE.getLogicalType(), TimestampFormat.ISO_8601, JsonFormatOptions.MapNullKeyMode.LITERAL, "null", true);
final DynamicTableSink actualSink = createTableSink(SCHEMA, options);
assert actualSink instanceof TestDynamicTableFactory.DynamicTableSinkMock;
TestDynamicTableFactory.DynamicTableSinkMock sinkMock = (TestDynamicTableFactory.DynamicTableSinkMock) actualSink;
SerializationSchema<RowData> actualSer = sinkMock.valueFormat.createRuntimeEncoder(new SinkRuntimeProviderContext(false), PHYSICAL_DATA_TYPE);
assertEquals(expectedSer, actualSer);
}
use of org.apache.flink.table.connector.sink.DynamicTableSink in project flink by apache.
the class HiveDynamicTableFactoryTest method testJobConfWithCredentials.
@Test
public void testJobConfWithCredentials() throws Exception {
final Text hdfsDelegationTokenKind = new Text("HDFS_DELEGATION_TOKEN");
final Text hdfsDelegationTokenService = new Text("ha-hdfs:hadoop-namespace");
Credentials credentials = new Credentials();
credentials.addToken(hdfsDelegationTokenService, new Token<>(new byte[4], new byte[4], hdfsDelegationTokenKind, hdfsDelegationTokenService));
UserGroupInformation.getCurrentUser().addCredentials(credentials);
// test table source's jobConf with credentials
tableEnv.executeSql(String.format("create table table10 (x int, y string, z int) partitioned by (" + " pt_year int, pt_mon string, pt_day string)"));
DynamicTableSource tableSource1 = getTableSource("table10");
HiveTableSource tableSource = (HiveTableSource) tableSource1;
Token token = tableSource.getJobConf().getCredentials().getToken(hdfsDelegationTokenService);
assertNotNull(token);
assertEquals(hdfsDelegationTokenKind, token.getKind());
assertEquals(hdfsDelegationTokenService, token.getService());
// test table sink's jobConf with credentials
DynamicTableSink tableSink1 = getTableSink("table10");
HiveTableSink tableSink = (HiveTableSink) tableSink1;
token = tableSink.getJobConf().getCredentials().getToken(hdfsDelegationTokenService);
assertNotNull(token);
assertEquals(hdfsDelegationTokenKind, token.getKind());
assertEquals(hdfsDelegationTokenService, token.getService());
}
use of org.apache.flink.table.connector.sink.DynamicTableSink in project flink by apache.
the class OracleTableSinkITCase method testFlushBufferWhenCheckpoint.
@Test
public void testFlushBufferWhenCheckpoint() throws Exception {
Map<String, String> options = new HashMap<>();
options.put("connector", "jdbc");
options.put("url", containerUrl);
options.put("table-name", OUTPUT_TABLE5);
options.put("sink.buffer-flush.interval", "0");
ResolvedSchema schema = ResolvedSchema.of(Column.physical("id", DataTypes.BIGINT().notNull()));
DynamicTableSink tableSink = createTableSink(schema, options);
SinkRuntimeProviderContext context = new SinkRuntimeProviderContext(false);
SinkFunctionProvider sinkProvider = (SinkFunctionProvider) tableSink.getSinkRuntimeProvider(context);
GenericJdbcSinkFunction<RowData> sinkFunction = (GenericJdbcSinkFunction<RowData>) sinkProvider.createSinkFunction();
sinkFunction.setRuntimeContext(new MockStreamingRuntimeContext(true, 1, 0));
sinkFunction.open(new Configuration());
sinkFunction.invoke(GenericRowData.of(1L), SinkContextUtil.forTimestamp(1));
sinkFunction.invoke(GenericRowData.of(2L), SinkContextUtil.forTimestamp(1));
check(new Row[] {}, containerUrl, OUTPUT_TABLE5, new String[] { "id" });
sinkFunction.snapshotState(new StateSnapshotContextSynchronousImpl(1, 1));
check(new Row[] { Row.of(1L), Row.of(2L) }, containerUrl, OUTPUT_TABLE5, new String[] { "id" });
sinkFunction.close();
}
use of org.apache.flink.table.connector.sink.DynamicTableSink in project flink by apache.
the class CsvFormatFactoryTest method createSerializationSchema.
private static SerializationSchema<RowData> createSerializationSchema(Map<String, String> options) {
final DynamicTableSink actualSink = createTableSink(SCHEMA, options);
assert actualSink instanceof TestDynamicTableFactory.DynamicTableSinkMock;
TestDynamicTableFactory.DynamicTableSinkMock sinkMock = (TestDynamicTableFactory.DynamicTableSinkMock) actualSink;
return sinkMock.valueFormat.createRuntimeEncoder(null, PHYSICAL_DATA_TYPE);
}
use of org.apache.flink.table.connector.sink.DynamicTableSink in project flink by apache.
the class BlackHoleSinkFactoryTest method testBlackHole.
@Test
public void testBlackHole() {
Map<String, String> properties = new HashMap<>();
properties.put("connector", "blackhole");
List<String> partitionKeys = Arrays.asList("f0", "f1");
DynamicTableSink sink = createTableSink(SCHEMA, partitionKeys, properties);
assertEquals("BlackHole", sink.asSummaryString());
assertTrue(sink instanceof SupportsPartitioning);
}
Aggregations