Skip to content

Conversation

@StrikeW
Copy link
Contributor

@StrikeW StrikeW commented Jun 27, 2023

I hereby agree to the terms of the RisingWave Labs, Inc. Contributor License Agreement.

What's changed and what's your intention?

  • Add a optional schema.name field to the WITH clause to allow user to specify schema for pg sink
CREATE SINK s2_postgres
FROM
    lineitem_rw WITH (
        connector = 'jdbc',
        jdbc.url = 'jdbc:postgresql://localhost:5432/postgres?user=postgres&password=xxxx',
        table.name = 't_lineitem',
        schema.name='biz',
        type='upsert'
);

Fix #10418

Checklist

  • I have written necessary rustdoc comments
  • I have added necessary unit tests and integration tests
  • I have added fuzzing tests or opened an issue to track them. (Optional, recommended for new SQL features Sqlsmith: Sql feature generation #7934).
  • My PR contains breaking changes. (If it deprecates some features, please create a tracking issue to remove them in the future).
  • All checks passed in ./risedev check (or alias, ./risedev c)
  • My PR changes performance-critical code. (Please run macro/micro-benchmarks and show the results.)

Documentation

  • My PR contains user-facing changes.
Click here for Documentation

Types of user-facing changes

Please keep the types that apply to your changes, and remove the others.

  • Connector (sources & sinks)
  • SQL commands, functions, and operators

Release note

Add a optional schema.name field to the WITH clause to allow user to specify schema for Postgres sink

@github-actions github-actions bot added the type/fix Type: Bug fix. Only for pull requests. label Jun 27, 2023
@StrikeW StrikeW marked this pull request as ready for review June 27, 2023 04:10
@StrikeW StrikeW marked this pull request as draft June 27, 2023 09:18
@StrikeW StrikeW marked this pull request as ready for review June 27, 2023 09:48
@codecov
Copy link

codecov bot commented Jun 27, 2023

Codecov Report

Merging #10576 (ea1f24c) into main (2100dc2) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##             main   #10576   +/-   ##
=======================================
  Coverage   70.14%   70.14%           
=======================================
  Files        1276     1276           
  Lines      219818   219818           
=======================================
  Hits       154200   154200           
  Misses      65618    65618           
Flag Coverage Δ
rust 70.14% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

see 2 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@StrikeW StrikeW added the user-facing-changes Contains changes that are visible to users label Jun 28, 2023
Copy link
Contributor

@wenym1 wenym1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rest LGTM.

@StrikeW StrikeW enabled auto-merge June 28, 2023 11:51
@wenym1 wenym1 disabled auto-merge June 28, 2023 11:55
@StrikeW StrikeW requested a review from wenym1 June 28, 2023 16:36
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

license-eye has totally checked 3692 files.

Valid Invalid Ignored Fixed
1668 1 2023 0
Click to see the invalid file list
  • java/connector-node/risingwave-sink-jdbc/src/main/java/com/risingwave/connector/jdbc/SchemaTableName.java

@StrikeW StrikeW force-pushed the siyuan/jdbc-sink-fix branch from e5bf443 to 1f1dc0d Compare June 29, 2023 01:57
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

license-eye has totally checked 3695 files.

Valid Invalid Ignored Fixed
1669 2 2024 0
Click to see the invalid file list
  • java/connector-node/risingwave-sink-jdbc/src/main/java/com/risingwave/connector/jdbc/PostgresSchemaTableName.java
  • java/connector-node/risingwave-sink-jdbc/src/main/java/com/risingwave/connector/jdbc/SchemaTableName.java

return tableName;
}

public String getNormalizedTableName() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this method should be inside the JdbcDialect, and has the signature of getNormalizedTableName(SchemaTableName schemaTableName), since how to concatenate the schema name and table name is a database-specific behavior. This class should be simply a POJO that contains that raw input from user.

package com.risingwave.connector.jdbc;

public class PostgresSchemaTableName extends SchemaTableName {
public PostgresSchemaTableName(String schemaName, String tableName) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have a createSchemaTable in JdbcDialect. We can set the default schema name there. This class is unnecessary.

String placeholders = fieldNames.stream().map(f -> "?").collect(Collectors.joining(", "));
return "INSERT INTO "
+ quoteIdentifier(tableName)
+ quoteIdentifier(tableName.getNormalizedTableName())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be "INSERT INTO " + getNormalizedTableName() .... The current code cannot handle databases that quote the schema name and table name separatedly (i.e. `schema_name`.`table_name`).

Copy link
Contributor

@wenym1 wenym1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for the PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type/fix Type: Bug fix. Only for pull requests. user-facing-changes Contains changes that are visible to users 📖✓ Covered or will be covered in the user docs.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JDBC sink(postgres): User cannot specify the schema name of a table

7 participants