Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use the connector to load data into a table with an auto-incrementing primary key? #407

Open
2292384454 opened this issue Dec 30, 2024 · 0 comments

Comments

@2292384454
Copy link

I try to use flink-connector-starrocks 1.2.10_flink-1.15 to load data into a primary key table with an auto-increment id defined, as shown below. However, I don't know how to make the auto-increment id work: If I don't assign a value to this field, I get the error NULL value in auto increment column 'FID'. On the contrary, if I assign any value to this field, it will actually write the value I assigned instead of using an auto-increment value to fill the id.

TableSchema schema = TableSchema.builder()
        .field("id", DataTypes.INT().notNull()) // id is defined as an auto-increment field in the table
        .field("name", DataTypes.STRING())
        .field("score", DataTypes.INT())
        .primaryKey("id")
        .build();

RowDataTransformer transformer = new RowDataTransformer();
SinkFunction<RowData> starRockSink = StarRocksSink.sink(schema, options, transformer);
source.addSink(starRockSink);

// ......

private static class RowDataTransformer implements StarRocksSinkRowBuilder<RowData> {


    @Override
    public void accept(Object[] internalRow, RowData rowData) {
        internalRow[0] = 0;  // if I delete this line,I get the error 'NULL value in auto increment column 'FID',On the contrary, the id will be all 0.I don't know how to get an auto increment id
        internalRow[1] = rowData.name;
        internalRow[2] = rowData.score;
        internalRow[internalRow.length - 1] = StarRocksSinkOP.UPSERT.ordinal();
    }
}  
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant