Java Code Examples for org.apache.flink.table.descriptors.DescriptorProperties#putLong()

The following examples show how to use org.apache.flink.table.descriptors.DescriptorProperties#putLong() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Pravega.java    From flink-connectors with Apache License 2.0 6 votes vote down vote up
/**
 * Populate all the writer configurations based on the values supplied through {@link TableSinkWriterBuilder}
 * @param properties the supplied descriptor properties.
 */
private void populateWriterProperties(DescriptorProperties properties) {
    properties.putBoolean(CONNECTOR_WRITER, true);
    properties.putString(CONNECTOR_WRITER_SCOPE, tableSinkWriterBuilder.resolveStream().getScope());
    properties.putString(CONNECTOR_WRITER_STREAM, tableSinkWriterBuilder.resolveStream().getStreamName());

    if (tableSinkWriterBuilder.writerMode == PravegaWriterMode.ATLEAST_ONCE) {
        properties.putString(CONNECTOR_WRITER_MODE, CONNECTOR_WRITER_MODE_VALUE_ATLEAST_ONCE);

    } else if (tableSinkWriterBuilder.writerMode == PravegaWriterMode.EXACTLY_ONCE) {
        properties.putString(CONNECTOR_WRITER_MODE, CONNECTOR_WRITER_MODE_VALUE_EXACTLY_ONCE);
    }

    properties.putBoolean(CONNECTOR_WRITER_ENABLE_WATERMARK, tableSinkWriterBuilder.enableWatermark);
    properties.putLong(CONNECTOR_WRITER_TXN_LEASE_RENEWAL_INTERVAL, tableSinkWriterBuilder.txnLeaseRenewalPeriod.toMilliseconds());

    if (tableSinkWriterBuilder.routingKeyFieldName != null) {
        properties.putString(CONNECTOR_WRITER_ROUTING_KEY_FILED_NAME, tableSinkWriterBuilder.routingKeyFieldName);
    }
}
 
Example 2
Source File: DataGenTableSourceFactoryTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testLackStartForSequence() {
	try {
		DescriptorProperties descriptor = new DescriptorProperties();
		descriptor.putString(FactoryUtil.CONNECTOR.key(), "datagen");
		descriptor.putString(FIELDS + ".f0." + KIND, SEQUENCE);
		descriptor.putLong(FIELDS + ".f0." + END, 100);

		createSource(
				TableSchema.builder().field("f0", DataTypes.BIGINT()).build(),
				descriptor.asMap());
	} catch (ValidationException e) {
		Throwable cause = e.getCause();
		Assert.assertTrue(cause instanceof ValidationException);
		Assert.assertTrue(cause.getMessage().contains(
				"Could not find required property 'fields.f0.start' for sequence generator."));
		return;
	}
	Assert.fail("Should fail by ValidationException.");
}
 
Example 3
Source File: DataGenTableSourceFactoryTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testLackEndForSequence() {
	try {
		DescriptorProperties descriptor = new DescriptorProperties();
		descriptor.putString(FactoryUtil.CONNECTOR.key(), "datagen");
		descriptor.putString(FIELDS + ".f0." + KIND, SEQUENCE);
		descriptor.putLong(FIELDS + ".f0." + START, 0);

		createSource(
				TableSchema.builder().field("f0", DataTypes.BIGINT()).build(),
				descriptor.asMap());
	} catch (ValidationException e) {
		Throwable cause = e.getCause();
		Assert.assertTrue(cause instanceof ValidationException);
		Assert.assertTrue(cause.getMessage().contains(
				"Could not find required property 'fields.f0.end' for sequence generator."));
		return;
	}
	Assert.fail("Should fail by ValidationException.");
}
 
Example 4
Source File: DataGenTableSourceFactoryTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testSequenceCheckpointRestore() throws Exception {
	DescriptorProperties descriptor = new DescriptorProperties();
	descriptor.putString(FactoryUtil.CONNECTOR.key(), "datagen");
	descriptor.putString(FIELDS + ".f0." + KIND, SEQUENCE);
	descriptor.putLong(FIELDS + ".f0." + START, 0);
	descriptor.putLong(FIELDS + ".f0." + END, 100);

	DynamicTableSource dynamicTableSource = createSource(
			TableSchema.builder().field("f0", DataTypes.BIGINT()).build(),
			descriptor.asMap());

	DataGenTableSource dataGenTableSource = (DataGenTableSource) dynamicTableSource;
	DataGeneratorSource<RowData> source = dataGenTableSource.createSource();

	final int initElement = 0;
	final int maxElement = 100;
	final Set<RowData> expectedOutput = new HashSet<>();
	for (long i = initElement; i <= maxElement; i++) {
		expectedOutput.add(GenericRowData.of(i));
	}
	DataGeneratorSourceTest.innerTestDataGenCheckpointRestore(
			() -> {
				try {
					return InstantiationUtil.clone(source);
				} catch (IOException | ClassNotFoundException e) {
					throw new RuntimeException(e);
				}
			}, expectedOutput);
}
 
Example 5
Source File: Pravega.java    From flink-connectors with Apache License 2.0 4 votes vote down vote up
/**
 * Populate all the reader configurations based on the values supplied through {@link TableSourceReaderBuilder}
 * @param properties the supplied descriptor properties.
 */
private void populateReaderProperties(DescriptorProperties properties) {
    properties.putBoolean(CONNECTOR_READER, true);

    // reader stream information
    AbstractStreamingReaderBuilder.ReaderGroupInfo readerGroupInfo = tableSourceReaderBuilder.buildReaderGroupInfo();

    Map<Stream, StreamCut> startStreamCuts = readerGroupInfo.getReaderGroupConfig().getStartingStreamCuts();
    Map<Stream, StreamCut> endStreamCuts = readerGroupInfo.getReaderGroupConfig().getEndingStreamCuts();
    final List<List<String>> values = new ArrayList<>();
    startStreamCuts.keySet().stream().forEach(stream -> {
        StreamCut startStreamCut = startStreamCuts.get(stream);
        StreamCut endStreamCut = endStreamCuts.get(stream);
        values.add(Arrays.asList(stream.getScope(), stream.getStreamName(), startStreamCut.asText(), endStreamCut.asText()));
    });
    properties.putIndexedFixedProperties(
                                            CONNECTOR_READER_STREAM_INFO,
                                            Arrays.asList(
                                                        CONNECTOR_READER_STREAM_INFO_SCOPE,
                                                        CONNECTOR_READER_STREAM_INFO_STREAM,
                                                        CONNECTOR_READER_STREAM_INFO_START_STREAMCUT,
                                                        CONNECTOR_READER_STREAM_INFO_END_STREAMCUT
                                                    ),
                                            values
                                        );

    // reader group information
    String uid = Optional.ofNullable(tableSourceReaderBuilder.uid).orElseGet(tableSourceReaderBuilder::generateUid);
    properties.putString(CONNECTOR_READER_READER_GROUP_UID, uid);
    properties.putString(CONNECTOR_READER_READER_GROUP_SCOPE, readerGroupInfo.getReaderGroupScope());
    properties.putString(CONNECTOR_READER_READER_GROUP_NAME, readerGroupInfo.getReaderGroupName());
    properties.putLong(CONNECTOR_READER_READER_GROUP_REFRESH_INTERVAL, readerGroupInfo.getReaderGroupConfig().getGroupRefreshTimeMillis());
    properties.putLong(CONNECTOR_READER_READER_GROUP_EVENT_READ_TIMEOUT_INTERVAL, tableSourceReaderBuilder.eventReadTimeout.toMilliseconds());
    properties.putLong(CONNECTOR_READER_READER_GROUP_CHECKPOINT_INITIATE_TIMEOUT_INTERVAL, tableSourceReaderBuilder.checkpointInitiateTimeout.toMilliseconds());

    // user information
    if (tableSourceReaderBuilder.getAssignerWithTimeWindows() != null) {
        try {
            @SuppressWarnings("unchecked")
            AssignerWithTimeWindows<Row> assigner = (AssignerWithTimeWindows<Row>) tableSourceReaderBuilder
                    .getAssignerWithTimeWindows().deserializeValue(getClass().getClassLoader());

            properties.putClass(CONNECTOR_READER_USER_TIMESTAMP_ASSIGNER, assigner.getClass());
        } catch (Exception e) {
            throw new TableException(e.getMessage());
        }
    }
}