Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Added content as per suggestion from discussion thread

...

Background and Motivation


Brief Introduction about to Redshift  

Redshift is a cloud-based data warehousing service provided by Amazon Web Services (AWS). It is designed to handle large-scale data analytics workloads, processing petabytes of structured and semi-structured data with high performance and scalability. Redshift allows businesses to store and analyze vast amounts of data in a cost-effective way, using a columnar storage format and massively parallel processing. It supports SQL queries, making it easy for users to extract insights from their data (detail reference). One of the key benefits of Redshift is its ability to scale elastically, automatically adding or removing compute nodes as needed to handle changes in workload. It also integrates with a wide range of other AWS services, such as S3, Kinesis, and Lambda, enabling users to build sophisticated data processing pipelines. Overall, Amazon Redshift is a powerful tool for businesses looking to store, process, and analyze large volumes of data in the cloud, with high performance, scalability, and ease of use.


Why is Flink connector to Redshift useful?

...

  1. Real-time data analysis: With Flink, businesses can analyze data as it arrives, enabling them to respond quickly to changes and make data-driven decisions in real - time.
  2. Scalability: The Flink Redshift Connector allows businesses to scale their data processing and analysis up or down as needed, depending on changes in workload.
  3. Easy integration: The Flink Redshift Connector will provide easy to integrate integration with existing Flink and Redshift workflows, enabling users to get up and running quickly.
  4. Community support: As an open-source solution, the Flink Redshift Connector benefits from a vibrant community of developers and users who contribute to its development and provide support.

...

Phase 2

  • Integrate with Flink's new Source API (FLIP-27)
  • Integrate with Table API (FLIP-95) for Source. Build upon Flink New DynamicTableSource and DynamicTableSinkFactory Interfaces.

...

For general information on Redshift's transactional guarantees, please refer to the documentation on
managing concurrent write operations and serializable isolation. According to the Redshift documentation, although any of the four transaction isolation levels can be used, Amazon Redshift processes all isolation levels as serializable. Amazon Redshift also supports a default automatic commit behavior behaviour in which each separately - executed SQL command commits individually. As a result, individual commands such as COPY and UNLOAD are atomic and transactional, while explicit BEGIN and END should only be necessary to enforce the atomicity of multiple commands/queries. When reading from or writing to Redshift, this library reads and writes data in S3. Both Flink and Redshift produce partitioned output, which is stored in multiple files in S3. According to the Amazon S3 Data Consistency Model documentation, S3 bucket listing operations are eventually-consistent. Therefore, flink-connector-redshift needs to take special measures to avoid missing or incomplete data due to this source of eventual-consistency.

...

To customize compression encoding for specific columns when creating a table, the connector provides a way to set the
encoding column metadata field. Please refer to the available encodings in the Amazon Redshift documentation.
Redshift allows descriptions to be attached to columns, which can be viewed in most query tools. You can specify a description for individual columns by setting the description column metadata field. This can be done using the COMMENT command.


IV) Source Design

Flink connector redshift will offer 2 modes to read from the source:-

  1. Directly reading from
  2. redshift
  3. Redshift using JDBC driver.
  4. Use UNLOAD command to execute a query and save its result to s3 and read from s3.


In flink-connector-redshift, the concept of a connector source that allows users to configure different modes for data retrieval. This functionality is achieved by utilizing the `read.mode` option available in the source configuration. This flexible configuration empowers users to adapt the connector's behavior behaviour based on their specific requirements.

...

Alternatively, when the selected read mode is unload , the flink-connector-redshift module takes a different approach. In this case, flink-connector-redshift will execute preprocessing and colleting collect the required information from redshift like schema, the path to unload size of the data and other meta information then it dynamically employs the functionalities of the flink-filesystem module, specifically utilizing the S3 connector. By doing so, the flink-connector-redshift is able to read data from the unloaded path in an S3 bucket. This approach leverages the scalability and durability of the S3 storage system, making it an efficient and reliable intermediary for data transfer between Redshift and the Flink framework.

In summary, the flink-connector-redshift module acts as an intelligent mediator that dynamically selects and integrates with the appropriate connectors based on the specified read mode. This flexibility allows users to choose between a direct JDBC-based interaction with Redshift or an optimized data unload mechanism using the S3 connector. By leveraging the capabilities of these connectors, the flink-connector-redshift module effectively achieves the goal of seamless and efficient data transfer between Redshift and the Flink framework, providing users with a comprehensive and adaptable solution for their data processing needs.

  1. Configuration:

    i) Source configurations (mandatory)


    Option

    Value

    Description
    read.modejdbc, unload

    hostname

    <redshifthost>


    database

    <name_of_database>


    table

    <name_of_table>


    temp.s3.path

    s3n://path/to/temp/data

    If read mode is unload  then `temp.s3.path` becomes mandatory
    username<username>
    password<password>




    ii) Source configurations (optional)

    Option

    Value

    Default

    Description

    query
    String


    Code Block
    SELECT * from <Table_Name> limit <record_size>;



    This will help optimizing optimise the data read from the source itself.
    portInteger5439
    record.sizePositive Integer1000


...

V) Sink Design

      Flink connector redshift Redshift will offer 2 modes to write to Redshift:-
      a)

  1. Directly writing to redshift using JDBC driver.

...

  1. Flink stream write to a specified s3 path in the format and schema accepted by

...

  1. Redshift then use COPY command to write data into the redshift table.

    Flink connector redshift will provide users with the ability to configure different modes for the connector sink by utilizing the write.mode option in the source configuration. This configuration flexibility allows users to tailor the

...

  1. behaviour of the connector sink to their specific needs.

...

  1. Internally, the flink-connector-redshift module will intelligently select and integrate with the appropriate connectors based on the chosen write mode. If the user specifies the write mode as "jdbc" in the source configuration, the flink-connector-redshift module will internally

...

  1. leverage the capabilities of the flink-connector-jdbc. This integration will enable seamless interaction with Redshift using the JDBC protocol, ensuring efficient data transfer from Flink to the Redshift database.

...

  1. Similarly, when the write mode is selected as a file-based operation, the flink-connector-redshift module will utilize the flink-connector-filesystem. This connector will facilitate writing data to an S3 bucket, adhering to the specific format and schema requirements outlined by Redshift's COPY command. By utilizing this connector, the flink-connector-redshift module will ensure that data is written in a manner compatible with Redshift's expectations.

...

  1. To provide a streamlined sink solution for Flink and Redshift integration, the flink-connector-redshift module will orchestrate and utilize these two connectors, flink-connector-jdbc and flink-filesystem, behind the scenes. It preprocesses the data and seamlessly wraps these connectors to offer a unified sink interface for transferring data from Flink to Redshift.

In summary, the flink-connector-redshift module offers users the flexibility to configure different modes for the connector sink. By intelligently utilizing the appropriate connectors, such as flink-connector-jdbc for direct JDBC-based interaction and flink-connector-filesystem for file-based operations, the module ensures efficient data transfer to Redshift. Through its preprocessing capabilities and seamless integration, the flink-connector-redshift module acts as a comprehensive sink solution, facilitating the smooth transfer of data from Flink to Redshift.

...

Code Block
val env = StreamExecutionEnvironment.getExecutionEnvironment
val stream = .....

val prop = new Properties()
prop.setProperty("url","
jdbc:redshift://redshifthost:5439/database?user=<username>&password=<password>")
prop.setProperty("database", "test_db")
prop.setProperty("table", "test_sink_table")
prop.setProperty("write.mode", "jdbc")


stream.addSink(new FlinkRedshiftSink(prop))
env.execute()
        • Sample streaming Streaming Table Write:
Code Block
val env = StreamExecutionEnvironment.getExecutionEnvironment
val tEnv = StreamTableEnvironment.create(env)

val prop = new Properties()
prop.setProperty("url","
jdbc:redshift://redshifthost:5439/database?user=<username>&password=<password>")
prop.setProperty("database", "test_db")
prop.setProperty("table", "test_sink_table")
prop.setProperty("write.mode", "jdbc")

tEnv
.connect(new Redshift().properties(props))
.inAppendMode()
.registerTableSource("sink-table")

val sql = "INSERT INTO sink-table ....."
tEnv.sqlUpdate(sql)
env.execute()



NOTE:

Additional Features that the Flink connector for AWS Redshift can provide on top of using JDBC:

1. Integration with AWS Redshift Workload Management (WLM): AWS Redshift allows you to configure WLM to manage query prioritization and resource allocation. The Flink connector for Redshift will be agnostic to the configured WLM and utilise it for scaling in and out for the source/sink. This means that the connector can leverage the WLM capabilities of Redshift to optimize the execution of queries and allocate resources efficiently based on your defined workload priorities.

2. Abstraction of AWS Redshift Quotas and Limits: AWS Redshift imposes certain quotas and limits on various aspects such as the number of clusters, concurrent connections, queries per second, etc. The Flink connector for Redshift will provide an abstraction layer for users, allowing them to work with Redshift without having to worry about these specific limits. The connector will handle the management of connections and queries within the defined quotas and limits, abstracting away the complexity and ensuring compliance with Redshift's restrictions.

                 VI) Authentication to S3 and Redshift

The use of this library involves several connections which must be authenticated/secured, all of which are illustrated in the following diagram:

Reference from the above diagram
→ Redshift Configured Connections:- Configuring a connection for JDBC driver version 2.1 for Amazon Redshi...
→ SSL enable in Redshift:- Configuring authentication and SSL - Amazon Redshift

This library reads and writes data to S3 when transferring data to/from Redshift. As a result, it requires AWS credentials with read and write access to a S3 bucket (specified using the temp.s3.path configuration parameter).


The following describes how each connection can be authenticated:

      1. Flink to Redshift: The Flink connects to Redshift via JDBC using a username and password.
        Redshift does not support the use of IAM roles to authenticate this connection.
        This connection can be secured using SSL; for more details, see the Encryption section below.
      2. Flink to S3: S3 acts as a middleman to store bulk data when reading from or writing to Redshift.
        Flink connects to S3 using both the Hadoop FileSystem interfaces and directly using the Amazon Java SDK's S3 client.

        This connection can be authenticated using either AWS keys or IAM roles.
      3. Default Authentication: Flink-connector-aws provides different mode modes of Authentication redshift connector connectors will use CredentialProvider.
        AWS credentials will automatically be retrieved through the
        DefaultAWSCredentialsProviderChain.
        Users can use IAM instance roles to authenticate to S3 (e.g. on EMR, or EC2).



...

  1. Parallelism in flink-connector-redhsift redshift will be limited by Quotas configured for the job in Redshift Connections Quotas and limits in Amazon Redshift - Amazon Redshift.
  2. Speed and latency in source and sink will be regulated by the latency and data transfer rate of UNLOAD and COPY feature from redshift
  3. Flink connector redshift sink will only support append-only tables. (no changelog mode support)

...

The flink-connector-redshift will be compatible with respect to the Flink source and sink interface.
This is a new connector(feature) no compatibility, deprecation, and migration plan is are expected.

Test Plan

...