forked from apache/gravitino
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[apache#1736] feat(postgresql): Support PostgreSQL index.
- Loading branch information
Showing
4 changed files
with
81 additions
and
37 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
67 changes: 67 additions & 0 deletions
67
...va/com/datastrato/gravitino/catalog/postgresql/operation/UTPostgreSqlTableOperations.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,67 @@ | ||
/* | ||
* Copyright 2024 Datastrato Pvt Ltd. | ||
* This software is licensed under the Apache License version 2. | ||
*/ | ||
package com.datastrato.gravitino.catalog.postgresql.operation; | ||
|
||
import com.datastrato.gravitino.rel.indexes.Index; | ||
import com.datastrato.gravitino.rel.indexes.Indexes; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
/** Unit test for {@link PostgreSqlTableOperations}. */ | ||
public class UTPostgreSqlTableOperations { | ||
|
||
@Test | ||
public void testAppendIndexesSql() { | ||
// Test append index sql success. | ||
Index[] indexes = | ||
new Index[] { | ||
Indexes.primary("test_pk", new String[][] {{"col_1"}, {"col_2"}}), | ||
Indexes.unique("u1_key", new String[][] {{"col_2"}, {"col_3"}}), | ||
Indexes.unique("u2_key", new String[][] {{"col_3"}, {"col_4"}}) | ||
}; | ||
StringBuilder successBuilder = new StringBuilder(); | ||
PostgreSqlTableOperations.appendIndexesSql(indexes, successBuilder); | ||
Assertions.assertEquals( | ||
",\n" | ||
+ "CONSTRAINT \"test_pk\" PRIMARY KEY (\"col_1\", \"col_2\"),\n" | ||
+ "CONSTRAINT \"u1_key\" UNIQUE (\"col_2\", \"col_3\"),\n" | ||
+ "CONSTRAINT \"u2_key\" UNIQUE (\"col_3\", \"col_4\")", | ||
successBuilder.toString()); | ||
|
||
// Test append index sql not have name. | ||
indexes = | ||
new Index[] { | ||
Indexes.primary(null, new String[][] {{"col_1"}, {"col_2"}}), | ||
Indexes.unique(null, new String[][] {{"col_2"}, {"col_3"}}), | ||
Indexes.unique(null, new String[][] {{"col_3"}, {"col_4"}}) | ||
}; | ||
successBuilder = new StringBuilder(); | ||
PostgreSqlTableOperations.appendIndexesSql(indexes, successBuilder); | ||
Assertions.assertEquals( | ||
",\n" | ||
+ " PRIMARY KEY (\"col_1\", \"col_2\"),\n" | ||
+ " UNIQUE (\"col_2\", \"col_3\"),\n" | ||
+ " UNIQUE (\"col_3\", \"col_4\")", | ||
successBuilder.toString()); | ||
|
||
// Test append index sql failed. | ||
IllegalArgumentException illegalArgumentException = | ||
Assertions.assertThrows( | ||
IllegalArgumentException.class, | ||
() -> | ||
PostgreSqlTableOperations.appendIndexesSql( | ||
new Index[] { | ||
Indexes.primary("test_pk", new String[][] {{"col_1", "col_2"}}), | ||
Indexes.unique("u1_key", new String[][] {{"col_2", "col_3"}}), | ||
Indexes.unique("u2_key", new String[][] {{"col_3", "col_4"}}) | ||
}, | ||
new StringBuilder())); | ||
Assertions.assertTrue( | ||
StringUtils.contains( | ||
illegalArgumentException.getMessage(), | ||
"Index does not support complex fields in PostgreSQL")); | ||
} | ||
} |
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