-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[duckdb] Utility to compare table schemas (#1442)
This is used to check whether a pre-existing table on disk has a schema equal to the one we want. Did this by introducing various utility classes, including: - ColumnDefinition - TableDefinition - IndexType - SQLUtils Also refactored unit tests to decouple from DuckDB, so that it's easier to test other engines in the future (e.g., SQLite).
- Loading branch information
Showing
14 changed files
with
687 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
integrations/venice-duckdb/src/main/java/com/linkedin/venice/sql/ColumnDefinition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
package com.linkedin.venice.sql; | ||
|
||
import java.sql.JDBCType; | ||
import java.util.Objects; | ||
import javax.annotation.Nonnull; | ||
import javax.annotation.Nullable; | ||
|
||
|
||
public class ColumnDefinition { | ||
@Nonnull | ||
private final String name; | ||
@Nonnull | ||
private final JDBCType type; | ||
private final boolean nullable; | ||
@Nullable | ||
private final IndexType indexType; | ||
@Nullable | ||
private final String defaultValue; | ||
@Nullable | ||
private final String extra; | ||
private final int jdbcIndex; | ||
|
||
public ColumnDefinition(@Nonnull String name, @Nonnull JDBCType type, int jdbcIndex) { | ||
this(name, type, true, null, jdbcIndex); | ||
} | ||
|
||
public ColumnDefinition( | ||
@Nonnull String name, | ||
@Nonnull JDBCType type, | ||
boolean nullable, | ||
@Nullable IndexType indexType, | ||
int jdbcIndex) { | ||
this(name, type, nullable, indexType, null, null, jdbcIndex); | ||
} | ||
|
||
public ColumnDefinition( | ||
@Nonnull String name, | ||
@Nonnull JDBCType type, | ||
boolean nullable, | ||
@Nullable IndexType indexType, | ||
@Nullable String defaultValue, | ||
@Nullable String extra, | ||
int jdbcIndex) { | ||
this.name = Objects.requireNonNull(name); | ||
this.type = Objects.requireNonNull(type); | ||
this.nullable = nullable; | ||
this.indexType = indexType; | ||
this.defaultValue = defaultValue; | ||
this.extra = extra; | ||
this.jdbcIndex = jdbcIndex; | ||
if (this.jdbcIndex < 1) { | ||
throw new IllegalArgumentException("The jdbcIndex must be at least 1"); | ||
} | ||
} | ||
|
||
@Nonnull | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
@Nonnull | ||
public JDBCType getType() { | ||
return type; | ||
} | ||
|
||
public boolean isNullable() { | ||
return nullable; | ||
} | ||
|
||
@Nullable | ||
public IndexType getIndexType() { | ||
return indexType; | ||
} | ||
|
||
@Nullable | ||
public String getDefaultValue() { | ||
return defaultValue; | ||
} | ||
|
||
@Nullable | ||
public String getExtra() { | ||
return extra; | ||
} | ||
|
||
public int getJdbcIndex() { | ||
return jdbcIndex; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
|
||
ColumnDefinition that = (ColumnDefinition) o; | ||
|
||
return this.nullable == that.nullable && this.jdbcIndex == that.jdbcIndex && this.name.equals(that.name) | ||
&& this.type == that.type && this.indexType == that.indexType && Objects.equals(defaultValue, that.defaultValue) | ||
&& Objects.equals(extra, that.extra); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return this.name.hashCode(); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
integrations/venice-duckdb/src/main/java/com/linkedin/venice/sql/IndexType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.linkedin.venice.sql; | ||
|
||
public enum IndexType { | ||
PRIMARY_KEY, UNIQUE; | ||
} |
Oops, something went wrong.