Skip to content

Commit 7469e38

Browse files
committed
[fix](lance) Reject blank Lance index names in CREATE and DROP INDEX
### What problem does this PR solve? Issue Number: #66497 Related PR: #67201 Problem Summary: Nereids accepts an empty backquoted identifier, so CREATE INDEX `` and DROP INDEX `` reach Lance validation with an empty index name. validateCreateIndex only bounded names over 64 UTF-8 bytes, and the Directory DROP path returned the typed unsupported error before DropIndexOp.validate() could run its empty-name check, masking malformed SQL as an unsupported operation; if admission later reuses this validator, an empty logical name could reach the durable job and same-name fence. Add a shared Lance index-name validator rejecting null/empty names and names over 64 UTF-8 bytes, invoke it for Directory CREATE and DROP, and add command-level coverage for empty quoted names. The REST path retains its fail-fast unsupported response before database/table metadata resolution. ### Release note None ### Check List (For Author) - Test: Unit Test - LanceIndexMutationValidatorTest - AlterTableCommandLanceIndexTest - CreateIndexParserTest - AlterTableCommandTest - IndexDefinitionTest - Regression suite test_lance_index_ddl (external docker env, runs in CI) - Behavior changed: Yes. Blank Lance index names now fail with "index name cannot be empty" instead of the unsupported-operation error. - Does this need documentation: No
1 parent 3938775 commit 7469e38

5 files changed

Lines changed: 111 additions & 10 deletions

File tree

‎fe/fe-core/src/main/java/org/apache/doris/datasource/lance/LanceIndexMutationValidator.java‎

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,7 @@ public static void validateCreateIndex(LanceExternalCatalog catalog, LanceExtern
7171
if (def.getCols() == null || def.getCols().size() != 1) {
7272
rejectInvalidDefinition("Lance index must be built on exactly one column");
7373
}
74-
if (def.getIndexName().getBytes(StandardCharsets.UTF_8).length > MAX_INDEX_NAME_BYTES) {
75-
rejectInvalidDefinition("index name too long, the index name length at most is 64.");
76-
}
74+
validateIndexName(def.getIndexName());
7775
String columnName = def.getCols().get(0);
7876
Column column = table.getColumn(columnName);
7977
if (column == null) {
@@ -109,12 +107,30 @@ public static void validateCreateIndexCatalog(LanceExternalCatalog catalog, Inde
109107
}
110108

111109
/**
112-
* Validates a top-level DROP INDEX statement targeting a Lance catalog table.
110+
* Validates a top-level DROP INDEX statement targeting a Lance catalog table. The REST
111+
* rejection keeps failing fast; Directory catalogs then get the same index-name bounds as
112+
* the CREATE path.
113113
*/
114-
public static void validateDropIndex(LanceExternalCatalog catalog) throws AnalysisException {
114+
public static void validateDropIndex(LanceExternalCatalog catalog, String indexName)
115+
throws AnalysisException {
115116
if (catalog.isRestCatalogConfigured()) {
116117
rejectUnsupportedOperation("DROP INDEX", "REST catalogs");
117118
}
119+
validateIndexName(indexName);
120+
}
121+
122+
/**
123+
* Shared Lance index-name bounds for the CREATE and DROP paths: the name becomes the durable
124+
* logical identity that an admitted job and its same-name fence key are built on, so
125+
* null/empty names are rejected here instead of being masked as unsupported operations.
126+
*/
127+
private static void validateIndexName(String indexName) throws AnalysisException {
128+
if (indexName == null || indexName.isEmpty()) {
129+
rejectInvalidDefinition("index name cannot be empty");
130+
}
131+
if (indexName.getBytes(StandardCharsets.UTF_8).length > MAX_INDEX_NAME_BYTES) {
132+
rejectInvalidDefinition("index name too long, the index name length at most is 64.");
133+
}
118134
}
119135

120136
private static void validateAnnIndex(Column column, Map<String, String> properties)

‎fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/AlterTableCommand.java‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ private void validate(ConnectContext ctx) throws UserException {
144144
String tableName = tbl.getTbl();
145145
CatalogIf catalog = Env.getCurrentEnv().getCatalogMgr()
146146
.getCatalogOrException(ctlName, catalogName -> new DdlException("Unknown catalog " + catalogName));
147-
validateLanceRestIndexOperations(catalog);
147+
validateLanceIndexOperationsBeforeResolution(catalog);
148148
DatabaseIf dbIf = catalog.getDbOrDdlException(dbName);
149149
TableIf tableIf = dbIf.getTableOrDdlException(tableName);
150150
if (tableIf.isTemporary()) {
@@ -178,7 +178,13 @@ private void validate(ConnectContext ctx) throws UserException {
178178
}
179179
}
180180

181-
private void validateLanceRestIndexOperations(CatalogIf catalog) throws AnalysisException {
181+
/**
182+
* Lance index checks that do not need the resolved table: REST catalogs fail fast for
183+
* top-level CREATE/DROP INDEX before database/table metadata resolution, and DROP INDEX on
184+
* Directory catalogs gets the shared index-name bounds here because the op-level
185+
* DropIndexOp.validate() is never reached on the typed-rejection path below.
186+
*/
187+
private void validateLanceIndexOperationsBeforeResolution(CatalogIf catalog) throws AnalysisException {
182188
if (!(catalog instanceof LanceExternalCatalog)) {
183189
return;
184190
}
@@ -187,7 +193,8 @@ private void validateLanceRestIndexOperations(CatalogIf catalog) throws Analysis
187193
LanceIndexMutationValidator.validateCreateIndexCatalog((LanceExternalCatalog) catalog,
188194
((CreateIndexOp) op).getIndexDef());
189195
} else if (op instanceof DropIndexOp && !((DropIndexOp) op).isAlter()) {
190-
LanceIndexMutationValidator.validateDropIndex((LanceExternalCatalog) catalog);
196+
LanceIndexMutationValidator.validateDropIndex((LanceExternalCatalog) catalog,
197+
((DropIndexOp) op).getIndexName());
191198
}
192199
}
193200
}

‎fe/fe-core/src/test/java/org/apache/doris/datasource/lance/LanceIndexMutationValidatorTest.java‎

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,16 +407,53 @@ public void testRestCatalogRejectedBeforeAnyOtherCheck() {
407407
orReplaceException.getMysqlErrorCode());
408408

409409
AnalysisException dropException = Assertions.assertThrows(AnalysisException.class,
410-
() -> LanceIndexMutationValidator.validateDropIndex(restCatalog()));
410+
() -> LanceIndexMutationValidator.validateDropIndex(restCatalog(), "idx"));
411411
Assertions.assertEquals("DROP INDEX is not supported for Lance REST catalogs",
412412
dropException.getDetailMessage());
413413
Assertions.assertEquals(ErrorCode.ERR_LANCE_INDEX_OPERATION_NOT_SUPPORTED,
414414
dropException.getMysqlErrorCode());
415+
416+
// The REST fail-fast precedes even the index-name bounds on the DROP path.
417+
AnalysisException dropEmptyNameException = Assertions.assertThrows(AnalysisException.class,
418+
() -> LanceIndexMutationValidator.validateDropIndex(restCatalog(), ""));
419+
Assertions.assertEquals("DROP INDEX is not supported for Lance REST catalogs",
420+
dropEmptyNameException.getDetailMessage());
421+
Assertions.assertEquals(ErrorCode.ERR_LANCE_INDEX_OPERATION_NOT_SUPPORTED,
422+
dropEmptyNameException.getMysqlErrorCode());
423+
}
424+
425+
@Test
426+
public void testBlankIndexNameRejectedOnBothPaths() {
427+
// Nereids accepts an empty backquoted identifier (``), so both the CREATE and the DROP
428+
// path must reject the empty name instead of masking it as an unsupported operation.
429+
assertRejected("index name cannot be empty",
430+
indexDef("", Collections.singletonList("v"), "ANN", validAnnProperties()), annTable());
431+
assertRejected("index name cannot be empty",
432+
indexDef(null, Collections.singletonList("v"), "ANN", validAnnProperties()), annTable());
433+
434+
for (String blankName : new String[] {null, ""}) {
435+
AnalysisException exception = Assertions.assertThrows(AnalysisException.class,
436+
() -> LanceIndexMutationValidator.validateDropIndex(filesystemCatalog(), blankName));
437+
Assertions.assertEquals("index name cannot be empty", exception.getDetailMessage());
438+
Assertions.assertEquals(ErrorCode.ERR_LANCE_INDEX_INVALID, exception.getMysqlErrorCode());
439+
}
440+
}
441+
442+
@Test
443+
public void testDropIndexNameLengthBound() {
444+
char[] tooLong = new char[65];
445+
Arrays.fill(tooLong, 'a');
446+
AnalysisException exception = Assertions.assertThrows(AnalysisException.class,
447+
() -> LanceIndexMutationValidator.validateDropIndex(filesystemCatalog(),
448+
new String(tooLong)));
449+
Assertions.assertEquals("index name too long, the index name length at most is 64.",
450+
exception.getDetailMessage());
451+
Assertions.assertEquals(ErrorCode.ERR_LANCE_INDEX_INVALID, exception.getMysqlErrorCode());
415452
}
416453

417454
@Test
418455
public void testDropIndexOnFilesystemCatalogPasses() {
419456
Assertions.assertDoesNotThrow(
420-
() -> LanceIndexMutationValidator.validateDropIndex(filesystemCatalog()));
457+
() -> LanceIndexMutationValidator.validateDropIndex(filesystemCatalog(), "idx"));
421458
}
422459
}

‎fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/AlterTableCommandLanceIndexTest.java‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,12 @@ public void testRestCatalogMessagesFireFirst() throws Exception {
252252
+ " (c) USING BTREE"));
253253
Assertions.assertEquals("DROP INDEX is not supported for Lance REST catalogs",
254254
runAndGetMessage("DROP INDEX idx ON " + CTL + "." + DB + "." + TBL));
255+
// The REST fail-fast precedes even the index-name bounds.
256+
Assertions.assertEquals("CREATE INDEX is not supported for Lance REST catalogs",
257+
runAndGetMessage("CREATE INDEX `` ON " + CTL + "." + DB + "." + TBL
258+
+ " (v) USING ANN " + VALID_ANN_PROPERTIES));
259+
Assertions.assertEquals("DROP INDEX is not supported for Lance REST catalogs",
260+
runAndGetMessage("DROP INDEX `` ON " + CTL + "." + DB + "." + TBL));
255261
Mockito.verify(fixture.catalog, Mockito.never()).getDbOrDdlException(Mockito.anyString());
256262
Mockito.verify(fixture.database, Mockito.never()).getTableOrDdlException(Mockito.anyString());
257263
Mockito.verify(fixture.env, Mockito.never()).getNextId();
@@ -279,6 +285,29 @@ public void testStaticValidationErrorsPrecedeTheTypedRejection() throws Exceptio
279285
}
280286
}
281287

288+
@Test
289+
public void testBlankQuotedIndexNameRejectedOnBothPaths() throws Exception {
290+
try (LanceFixture fixture = new LanceFixture(false, true)) {
291+
// Nereids accepts an empty backquoted identifier, so `CREATE INDEX `` ` and
292+
// `DROP INDEX `` ` reach the command with an empty index name. Both paths must
293+
// surface the name error, not the typed unsupported-operation rejection.
294+
Assertions.assertEquals("index name cannot be empty",
295+
runAndGetMessage("CREATE INDEX `` ON " + CTL + "." + DB + "." + TBL
296+
+ " (v) USING ANN " + VALID_ANN_PROPERTIES));
297+
Assertions.assertEquals("index name cannot be empty",
298+
runAndGetMessage("CREATE OR REPLACE INDEX `` ON " + CTL + "." + DB + "." + TBL
299+
+ " (c) USING BTREE"));
300+
Assertions.assertEquals("index name cannot be empty",
301+
runAndGetMessage("DROP INDEX `` ON " + CTL + "." + DB + "." + TBL));
302+
Assertions.assertEquals("index name cannot be empty",
303+
runAndGetMessage("DROP INDEX IF EXISTS `` ON " + CTL + "." + DB + "." + TBL));
304+
AnalysisException exception = runAndGetCommonAnalysisException(
305+
"DROP INDEX `` ON " + CTL + "." + DB + "." + TBL);
306+
Assertions.assertEquals(ErrorCode.ERR_LANCE_INDEX_INVALID, exception.getMysqlErrorCode());
307+
Mockito.verify(fixture.env, Mockito.never()).getNextId();
308+
}
309+
}
310+
282311
@Test
283312
public void testNonLanceIndexTypesRejectedEndToEnd() throws Exception {
284313
try (LanceFixture fixture = new LanceFixture(false, true)) {

‎regression-test/suites/external_table_p0/lance/test_lance_index_ddl.groovy‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,18 @@ suite("test_lance_index_ddl", "p0,external") {
106106
exception "DROP INDEX is not supported for Lance catalog tables"
107107
}
108108

109+
// An empty backquoted index name is a blank name, not an unsupported operation.
110+
test {
111+
sql """CREATE INDEX `` ON `${filesystemCatalog}`.`doris`.`vs_ivf_pq_f32` (embedding) USING ANN
112+
PROPERTIES("index_type"="IVF_PQ", "num_partitions"="256", "num_sub_vectors"="16")"""
113+
exception "index name cannot be empty"
114+
}
115+
116+
test {
117+
sql """DROP INDEX `` ON `${filesystemCatalog}`.`doris`.`vs_ivf_pq_f32`"""
118+
exception "index name cannot be empty"
119+
}
120+
109121
// ALTER TABLE ADD/DROP INDEX keeps the generic external-table rejection.
110122
test {
111123
sql """ALTER TABLE `${filesystemCatalog}`.`doris`.`vs_ivf_pq_f32` ADD INDEX idx (category) USING INVERTED"""

0 commit comments

Comments
 (0)