Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,158 +17,18 @@

package org.apache.fluss.flink.catalog;

import org.apache.flink.table.api.DataTypes;
import org.apache.flink.table.api.Schema;
import org.apache.flink.table.catalog.CatalogTable;
import org.apache.flink.table.catalog.ObjectPath;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;

/** IT case for catalog in Flink 2.2. */
public class Flink22CatalogITCase extends FlinkCatalogITCase {

Copy link

Copilot AI Jan 4, 2026

Choose a reason for hiding this comment

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

This method overrides FlinkCatalogITCase.supportIndex; it is advisable to add an Override annotation.

Suggested change
@Override

Copilot uses AI. Check for mistakes.
@Test
void testGetTableWithIndex() throws Exception {
String tableName = "table_with_pk_only";
tEnv.executeSql(
String.format(
"create table %s ( "
+ " a int, "
+ " b varchar, "
+ " c bigint, "
+ " primary key (a, b) NOT ENFORCED"
+ ") with ( "
+ " 'connector' = 'fluss' "
+ ")",
tableName));
CatalogTable table = (CatalogTable) catalog.getTable(new ObjectPath(DEFAULT_DB, tableName));
Schema expectedSchema =
Schema.newBuilder()
.column("a", DataTypes.INT().notNull())
.column("b", DataTypes.STRING().notNull())
.column("c", DataTypes.BIGINT())
.primaryKey("a", "b")
.index("a", "b")
.build();
assertThat(table.getUnresolvedSchema()).isEqualTo(expectedSchema);

tableName = "table_with_prefix_bucket_key";
tEnv.executeSql(
String.format(
"create table %s ( "
+ " a int, "
+ " b varchar, "
+ " c bigint, "
+ " primary key (a, b) NOT ENFORCED"
+ ") with ( "
+ " 'connector' = 'fluss', "
+ " 'bucket.key' = 'a'"
+ ")",
tableName));

table = (CatalogTable) catalog.getTable(new ObjectPath(DEFAULT_DB, tableName));
expectedSchema =
Schema.newBuilder()
.column("a", DataTypes.INT().notNull())
.column("b", DataTypes.STRING().notNull())
.column("c", DataTypes.BIGINT())
.primaryKey("a", "b")
.index("a", "b")
.index("a")
.build();
assertThat(table.getUnresolvedSchema()).isEqualTo(expectedSchema);

tableName = "table_with_bucket_key_is_not_prefix_pk";
tEnv.executeSql(
String.format(
"create table %s ( "
+ " a int, "
+ " b varchar, "
+ " c bigint, "
+ " primary key (a, b) NOT ENFORCED"
+ ") with ( "
+ " 'connector' = 'fluss', "
+ " 'bucket.key' = 'b'"
+ ")",
tableName));

table = (CatalogTable) catalog.getTable(new ObjectPath(DEFAULT_DB, tableName));
expectedSchema =
Schema.newBuilder()
.column("a", DataTypes.INT().notNull())
.column("b", DataTypes.STRING().notNull())
.column("c", DataTypes.BIGINT())
.primaryKey("a", "b")
.index("a", "b")
.build();
assertThat(table.getUnresolvedSchema()).isEqualTo(expectedSchema);

tableName = "table_with_partition_1";
tEnv.executeSql(
String.format(
"create table %s ( "
+ " a int, "
+ " b varchar, "
+ " c bigint, "
+ " dt varchar, "
+ " primary key (a, b, dt) NOT ENFORCED "
+ ") "
+ " partitioned by (dt) "
+ " with ( "
+ " 'connector' = 'fluss', "
+ " 'bucket.key' = 'a'"
+ ")",
tableName));

table = (CatalogTable) catalog.getTable(new ObjectPath(DEFAULT_DB, tableName));
expectedSchema =
Schema.newBuilder()
.column("a", DataTypes.INT().notNull())
.column("b", DataTypes.STRING().notNull())
.column("c", DataTypes.BIGINT())
.column("dt", DataTypes.STRING().notNull())
.primaryKey("a", "b", "dt")
.index("a", "b", "dt")
.index("a", "dt")
.build();
assertThat(table.getUnresolvedSchema()).isEqualTo(expectedSchema);

tableName = "table_with_partition_2";
tEnv.executeSql(
String.format(
"create table %s ( "
+ " a int, "
+ " b varchar, "
+ " c bigint, "
+ " dt varchar, "
+ " primary key (dt, a, b) NOT ENFORCED "
+ ") "
+ " partitioned by (dt) "
+ " with ( "
+ " 'connector' = 'fluss', "
+ " 'bucket.key' = 'a'"
+ ")",
tableName));

table = (CatalogTable) catalog.getTable(new ObjectPath(DEFAULT_DB, tableName));
expectedSchema =
Schema.newBuilder()
.column("a", DataTypes.INT().notNull())
.column("b", DataTypes.STRING().notNull())
.column("c", DataTypes.BIGINT())
.column("dt", DataTypes.STRING().notNull())
.primaryKey("dt", "a", "b")
.index("dt", "a", "b")
.index("a", "dt")
.build();
assertThat(table.getUnresolvedSchema()).isEqualTo(expectedSchema);
protected boolean supportIndex() {
return true;
}

@Override
protected void addDefaultIndexKey(Schema.Builder schemaBuilder) {
super.addDefaultIndexKey(schemaBuilder);

Schema currentSchema = schemaBuilder.build();
currentSchema.getPrimaryKey().ifPresent(pk -> schemaBuilder.index(pk.getColumnNames()));
}
Expand Down
Loading