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

Fix default collation of tables when creating in JDBC DBs, make them be consistent with others. #336

Merged
merged 3 commits into from
Oct 14, 2021
Merged
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 @@ -78,7 +78,7 @@ public class JdbcDatabaseAdmin implements DistributedStorageAdmin {
ImmutableMap.<DataType, String>builder()
.put(DataType.INT, "INT")
.put(DataType.BIGINT, "BIGINT")
.put(DataType.TEXT, "VARCHAR(8000)")
.put(DataType.TEXT, "VARCHAR(8000) COLLATE Latin1_General_BIN")
Copy link
Collaborator

@brfrn169 brfrn169 Oct 7, 2021

Choose a reason for hiding this comment

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

Can we use utf8 encoding instead of latin1?

Copy link
Contributor Author

@thongdk8 thongdk8 Oct 7, 2021

Choose a reason for hiding this comment

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

I couldn't found the collation in SQL Server that contains both utf8, and bin posfix for binary comparison sort.

Copy link
Contributor Author

@thongdk8 thongdk8 Oct 7, 2021

Choose a reason for hiding this comment

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

Here is the list of all collations with binary sort order in SQL Server I found. https://docs.google.com/spreadsheets/d/1j7-5lM6tRR8O-YJErc4b3iyfk3HogNj_qNlPqFrN7os/edit?usp=sharing

.put(DataType.FLOAT, "FLOAT(24)")
.put(DataType.DOUBLE, "FLOAT")
.put(DataType.BOOLEAN, "BIT")
Expand Down Expand Up @@ -150,6 +150,9 @@ public void createNamespace(String namespace, Map<String, String> options)
if (rdbEngine == RdbEngine.ORACLE) {
execute(connection, "CREATE USER " + fullNamespace + " IDENTIFIED BY \"oracle\"");
execute(connection, "ALTER USER " + fullNamespace + " quota unlimited on USERS");
} else if (rdbEngine == RdbEngine.MYSQL) {
execute(
connection, "CREATE SCHEMA " + fullNamespace + " character set utf8 COLLATE utf8_bin");
} else {
execute(connection, "CREATE SCHEMA " + fullNamespace);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public ResultSet mockResultSet(List<GetColumnsResultSetMocker.Row> rows) throws
public void createNamespace_forMysql_shouldExecuteCreateNamespaceStatement()
throws ExecutionException, SQLException {
createNamespace_forX_shouldExecuteCreateNamespaceStatement(
RdbEngine.MYSQL, "CREATE SCHEMA `my_ns`");
RdbEngine.MYSQL, "CREATE SCHEMA `my_ns` character set utf8 COLLATE utf8_bin");
}

@Test
Expand Down Expand Up @@ -298,7 +298,8 @@ public void createTable_forSqlServer_shouldExecuteCreateTableStatement()
createTable_forX_shouldExecuteCreateTableStatement(
RdbEngine.SQL_SERVER,
Optional.empty(),
"CREATE TABLE [my_ns].[foo_table]([c3] BIT,[c1] VARCHAR(8000),[c4] VARBINARY(8000),[c2] BIGINT,[c5] INT,[c6] FLOAT,[c7] FLOAT(24), PRIMARY KEY ([c3],[c1],[c4]))",
"CREATE TABLE [my_ns].[foo_table]([c3] BIT,[c1] VARCHAR(8000) COLLATE Latin1_General_BIN,"
+ "[c4] VARBINARY(8000),[c2] BIGINT,[c5] INT,[c6] FLOAT,[c7] FLOAT(24), PRIMARY KEY ([c3],[c1],[c4]))",
"CREATE INDEX index_my_ns_foo_table_c4 ON [my_ns].[foo_table] ([c4])",
"CREATE INDEX index_my_ns_foo_table_c1 ON [my_ns].[foo_table] ([c1])",
"CREATE SCHEMA [scalardb]",
Expand Down Expand Up @@ -406,7 +407,7 @@ public void createTable_forMysqlWithTableMetadataSchemaChanged_shouldExecuteCrea
createTable_forX_shouldExecuteCreateTableStatement(
RdbEngine.SQL_SERVER,
Optional.of("changed"),
"CREATE TABLE [my_ns].[foo_table]([c3] BIT,[c1] VARCHAR(8000),[c4] VARBINARY(8000),[c2] BIGINT,[c5] INT,[c6] FLOAT,[c7] FLOAT(24), PRIMARY KEY ([c3],[c1],[c4]))",
"CREATE TABLE [my_ns].[foo_table]([c3] BIT,[c1] VARCHAR(8000) COLLATE Latin1_General_BIN,[c4] VARBINARY(8000),[c2] BIGINT,[c5] INT,[c6] FLOAT,[c7] FLOAT(24), PRIMARY KEY ([c3],[c1],[c4]))",
"CREATE INDEX index_my_ns_foo_table_c4 ON [my_ns].[foo_table] ([c4])",
"CREATE INDEX index_my_ns_foo_table_c1 ON [my_ns].[foo_table] ([c1])",
"CREATE SCHEMA [changed]",
Expand Down