Skip to content
Open
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
1 change: 1 addition & 0 deletions src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt
Original file line number Diff line number Diff line change
Expand Up @@ -11046,6 +11046,7 @@ List<String> CreateParameter():
| tk=<K_DESC> | tk=<K_TRUE> | tk=<K_FALSE> | tk=<K_PARALLEL> | tk=<K_BINARY> | tk=<K_START> | tk=<K_ORDER>
| tk=<K_TIME_KEY_EXPR> | tk=<K_RAW> | tk=<K_HASH> | tk=<K_FIRST> | tk=<K_LAST> | tk = <K_SIGNED> | tk = <K_UNSIGNED>
| tk=<K_ENGINE> | tk=<K_IDENTITY> | tk=<K_MATERIALIZED> | tk=<K_SAMPLE> | tk=<K_ALWAYS>
| tk=<K_VISIBLE> | tk=<K_INVISIBLE>
| tk="="
)
{ param.add(tk.image); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,10 @@ public void testCreateIndexWithFunctionalKeyParts() throws JSQLParserException {

assertSqlCanBeParsedAndDeparsed(statement);
}

@Test
public void testCreateIndexVisibility() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed("CREATE INDEX idx_a ON t1 (a) INVISIBLE", true);
assertSqlCanBeParsedAndDeparsed("CREATE INDEX idx_a ON t1 (a) VISIBLE", true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1162,4 +1162,48 @@ void testWithCatalog() throws JSQLParserException {
assertEquals("session1", t.getSchemaName());
assertEquals("a", t.getUnquotedName());
}

@Test
void testCreateTableIndexVisibility() throws JSQLParserException {
String sqlStr = "CREATE TABLE `orders` (" +
"`id` bigint NOT NULL AUTO_INCREMENT" +
", `status` varchar (32) NOT NULL" +
", `quote_id` varchar (191) NOT NULL" +
", PRIMARY KEY (`id`)" +
", KEY `idx_status` (`status`) INVISIBLE" +
", UNIQUE KEY `idx_quote_id` (`quote_id`) VISIBLE" +
") ENGINE = InnoDB";
CreateTable createTable = (CreateTable) assertSqlCanBeParsedAndDeparsed(sqlStr, true);

assertEquals(Arrays.asList("INVISIBLE"), createTable.getIndexes().get(1).getIndexSpec());
assertEquals(Arrays.asList("VISIBLE"), createTable.getIndexes().get(2).getIndexSpec());
}

@Test
void testCreateTableColumnVisibility() throws JSQLParserException {
String sqlStr =
"CREATE TABLE t1 (id bigint NOT NULL VISIBLE, secret varchar (10) INVISIBLE)";
CreateTable createTable = (CreateTable) assertSqlCanBeParsedAndDeparsed(sqlStr, true);

assertEquals(Arrays.asList("NOT", "NULL", "VISIBLE"),
createTable.getColumnDefinitions().get(0).getColumnSpecs());
assertEquals(Arrays.asList("INVISIBLE"),
createTable.getColumnDefinitions().get(1).getColumnSpecs());
}

@Test
void testCreateTableIndexVisibilityWithOtherIndexOptions() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed(
"CREATE TABLE t1 (a int, KEY idx_a (a) INVISIBLE COMMENT 'retiring')", true);
assertSqlCanBeParsedAndDeparsed(
"CREATE TABLE t1 (a int, KEY idx_a (a) COMMENT 'retiring' INVISIBLE)", true);
assertSqlCanBeParsedAndDeparsed(
"CREATE TABLE t1 (a int, KEY idx_a (a) USING BTREE INVISIBLE)", true);
}

@Test
void testCreateTableQuotedColumnNamedVisible() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed(
"CREATE TABLE t1 (`visible` int, `invisible` varchar (10))", true);
}
}
Loading