Skip to content

Commit

Permalink
[Enhancement] Implement StarRocksTable.equals() (#309)
Browse files Browse the repository at this point in the history
Signed-off-by: PengFei Li <[email protected]>
  • Loading branch information
banmoy authored Nov 27, 2023
1 parent 2983f58 commit cfe73c0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,17 @@ public Optional<StarRocksTable> getTable(String databaseName, String tableName)
while (resultSet.next()) {
String name = resultSet.getString("COLUMN_NAME");
String type = resultSet.getString("DATA_TYPE");
int position = resultSet.getInt("ORDINAL_POSITION");
Integer size = resultSet.getInt("COLUMN_SIZE");
if (resultSet.wasNull()) {
size = null;
}
// mysql does not have boolean type, and starrocks `information_schema`.`COLUMNS` will return
// a "tinyint" data type for both StarRocks BOOLEAN and TINYINT type, Distinguish them by
// column size, and the size of BOOLEAN is null
if ("tinyint".equalsIgnoreCase(type) && size == null) {
type = "boolean";
}
int position = resultSet.getInt("ORDINAL_POSITION");
Integer scale = resultSet.getInt("DECIMAL_DIGITS");
if (resultSet.wasNull()) {
scale = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;


Expand Down Expand Up @@ -172,10 +173,29 @@ public String toString() {
", numBuckets=" + numBuckets +
", comment='" + comment + '\'' +
", properties=" + properties +
", columnMap=" + columnMap +
'}';
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
StarRocksTable that = (StarRocksTable) o;
return Objects.equals(databaseName, that.databaseName) &&
Objects.equals(tableName, that.tableName) &&
tableType == that.tableType &&
Objects.equals(columns, that.columns) &&
Objects.equals(tableKeys, that.tableKeys) &&
Objects.equals(distributionKeys, that.distributionKeys) &&
Objects.equals(numBuckets, that.numBuckets) &&
Objects.equals(comment, that.comment) &&
Objects.equals(properties, that.properties);
}

/** Build a {@link StarRocksTable}. */
public static class Builder {

Expand Down Expand Up @@ -219,7 +239,7 @@ public Builder setDistributionKeys(List<String> distributionKeys) {
return this;
}

public Builder setNumBuckets(int numBuckets) {
public Builder setNumBuckets(Integer numBuckets) {
this.numBuckets = numBuckets;
return this;
}
Expand Down

0 comments on commit cfe73c0

Please sign in to comment.