Skip to content

Commit 3cdb5c5

Browse files
mriggerclaude
andcommitted
Pull up isPrimaryKey() and hasPrimaryKey() into abstract base classes
Add isPrimaryKey() to AbstractTableColumn (default false) and hasPrimaryKey() to AbstractTable, replacing duplicate implementations in MySQL, OceanBase, and TiDB. Add @OverRide to all database-specific isPrimaryKey() methods. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent e35cbb1 commit 3cdb5c5

File tree

12 files changed

+18
-12
lines changed

12 files changed

+18
-12
lines changed

src/sqlancer/cockroachdb/CockroachDBSchema.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ public CockroachDBColumn(String name, CockroachDBCompositeDataType columnType, b
182182
this.isNullable = isNullable;
183183
}
184184

185+
@Override
185186
public boolean isPrimaryKey() {
186187
return isPrimaryKey;
187188
}

src/sqlancer/common/schema/AbstractTable.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ public boolean isView() {
9595
return isView;
9696
}
9797

98+
public boolean hasPrimaryKey() {
99+
return columns.stream().anyMatch(c -> c.isPrimaryKey());
100+
}
101+
98102
public String getFreeColumnName() {
99103
int i = 0;
100104
if (Randomly.getBooleanWithRatherLowProbability()) {

src/sqlancer/common/schema/AbstractTableColumn.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ public AbstractTableColumn(String name, T table, U type) {
1212
this.type = type;
1313
}
1414

15+
public boolean isPrimaryKey() {
16+
return false;
17+
}
18+
1519
public String getName() {
1620
return name;
1721
}

src/sqlancer/databend/DatabendSchema.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ public DatabendColumn(String name, DatabendCompositeDataType columnType, boolean
148148
this.isNullable = isNullable;
149149
}
150150

151+
@Override
151152
public boolean isPrimaryKey() {
152153
return isPrimaryKey;
153154
}

src/sqlancer/duckdb/DuckDBSchema.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ public DuckDBColumn(String name, DuckDBCompositeDataType columnType, boolean isP
132132
this.isNullable = isNullable;
133133
}
134134

135+
@Override
135136
public boolean isPrimaryKey() {
136137
return isPrimaryKey;
137138
}

src/sqlancer/mariadb/MariaDBSchema.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public int getPrecision() {
5151
return precision;
5252
}
5353

54+
@Override
5455
public boolean isPrimaryKey() {
5556
return isPrimaryKey;
5657
}

src/sqlancer/mysql/MySQLSchema.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public int getPrecision() {
7676
return precision;
7777
}
7878

79+
@Override
7980
public boolean isPrimaryKey() {
8081
return isPrimaryKey;
8182
}
@@ -194,10 +195,6 @@ public MySQLEngine getEngine() {
194195
return engine;
195196
}
196197

197-
public boolean hasPrimaryKey() {
198-
return getColumns().stream().anyMatch(c -> c.isPrimaryKey());
199-
}
200-
201198
}
202199

203200
public static final class MySQLIndex extends TableIndex {

src/sqlancer/oceanbase/OceanBaseSchema.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public int getPrecision() {
8181
return precision;
8282
}
8383

84+
@Override
8485
public boolean isPrimaryKey() {
8586
return isPrimaryKey;
8687
}
@@ -195,10 +196,6 @@ public OceanBaseTable(String tableName, List<OceanBaseColumn> columns, List<Ocea
195196
super(tableName, columns, indexes, false);
196197
}
197198

198-
public boolean hasPrimaryKey() {
199-
return getColumns().stream().anyMatch(c -> c.isPrimaryKey());
200-
}
201-
202199
}
203200

204201
public static final class OceanBaseIndex extends TableIndex {

src/sqlancer/presto/PrestoSchema.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,7 @@ public PrestoColumn(String name, PrestoCompositeDataType columnType, boolean isP
453453
this.isNullable = isNullable;
454454
}
455455

456+
@Override
456457
public boolean isPrimaryKey() {
457458
return isPrimaryKey;
458459
}

src/sqlancer/sqlite3/schema/SQLite3Schema.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public SQLite3Column(String rowId, SQLite3DataType columnType, boolean isInteger
7878
this.generated = generated;
7979
}
8080

81+
@Override
8182
public boolean isPrimaryKey() {
8283
return isPrimaryKey;
8384
}

0 commit comments

Comments
 (0)