-
Notifications
You must be signed in to change notification settings - Fork 3.8k
add schema change test for variant and inverted index #61746
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,116 @@ | ||||||||||||||||||||||||||||||||||||
| // Licensed to the Apache Software Foundation (ASF) under one | ||||||||||||||||||||||||||||||||||||
| // or more contributor license agreements. See the NOTICE file | ||||||||||||||||||||||||||||||||||||
| // distributed with this work for additional information | ||||||||||||||||||||||||||||||||||||
| // regarding copyright ownership. The ASF licenses this file | ||||||||||||||||||||||||||||||||||||
| // to you under the Apache License, Version 2.0 (the | ||||||||||||||||||||||||||||||||||||
| // "License"); you may not use this file except in compliance | ||||||||||||||||||||||||||||||||||||
| // with the License. You may obtain a copy of the License at | ||||||||||||||||||||||||||||||||||||
| // | ||||||||||||||||||||||||||||||||||||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||||||||||||||||||||||||||||||||||||
| // | ||||||||||||||||||||||||||||||||||||
| // Unless required by applicable law or agreed to in writing, | ||||||||||||||||||||||||||||||||||||
| // software distributed under the License is distributed on an | ||||||||||||||||||||||||||||||||||||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||||||||||||||||||||||||||||||||||||
| // KIND, either express or implied. See the License for the | ||||||||||||||||||||||||||||||||||||
| // specific language governing permissions and limitations | ||||||||||||||||||||||||||||||||||||
| // under the License. | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| suite("test_variant_multi_index_schema_change", "p0") { | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| sql """ set enable_match_without_inverted_index = false """ | ||||||||||||||||||||||||||||||||||||
| sql """ set enable_common_expr_pushdown = true """ | ||||||||||||||||||||||||||||||||||||
| sql """ set inverted_index_skip_threshold = 0 """ | ||||||||||||||||||||||||||||||||||||
| sql """ set default_variant_enable_typed_paths_to_sparse = false """ | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| def createVariantTable = { tableName -> | ||||||||||||||||||||||||||||||||||||
| sql """ DROP TABLE IF EXISTS ${tableName} """ | ||||||||||||||||||||||||||||||||||||
| sql """ | ||||||||||||||||||||||||||||||||||||
| CREATE TABLE ${tableName} ( | ||||||||||||||||||||||||||||||||||||
| `id` bigint NULL, | ||||||||||||||||||||||||||||||||||||
| `tag` string NULL, | ||||||||||||||||||||||||||||||||||||
| `var` variant<properties ("variant_max_subcolumns_count" = "10")> NOT NULL, | ||||||||||||||||||||||||||||||||||||
| INDEX idx_a_d (`var`) USING INVERTED PROPERTIES("parser" = "unicode", "support_phrase" = "true"), | ||||||||||||||||||||||||||||||||||||
| INDEX idx_a_d_2 (`var`) USING INVERTED | ||||||||||||||||||||||||||||||||||||
| ) ENGINE=OLAP | ||||||||||||||||||||||||||||||||||||
| DUPLICATE KEY(`id`) | ||||||||||||||||||||||||||||||||||||
| DISTRIBUTED BY HASH(`id`) BUCKETS 1 | ||||||||||||||||||||||||||||||||||||
| PROPERTIES ( | ||||||||||||||||||||||||||||||||||||
| "replication_allocation" = "tag.location.default: 1", | ||||||||||||||||||||||||||||||||||||
| "disable_auto_compaction" = "true", | ||||||||||||||||||||||||||||||||||||
| "inverted_index_storage_format" = "V2" | ||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| def insertBatch = { tableName -> | ||||||||||||||||||||||||||||||||||||
| sql """ | ||||||||||||||||||||||||||||||||||||
| INSERT INTO ${tableName} VALUES | ||||||||||||||||||||||||||||||||||||
| (1, 'hello', '{"string" : "hello", "array_string" : ["hello"]}'), | ||||||||||||||||||||||||||||||||||||
| (2, 'world', '{"string" : "world", "array_string" : ["world"]}'), | ||||||||||||||||||||||||||||||||||||
| (3, 'hello', '{"string" : "hello", "array_string" : ["hello"]}'), | ||||||||||||||||||||||||||||||||||||
| (4, 'world', '{"string" : "world", "array_string" : ["world"]}'), | ||||||||||||||||||||||||||||||||||||
| (5, 'hello', '{"string" : "hello", "array_string" : ["hello"]}') | ||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| def loadTable = { tableName -> | ||||||||||||||||||||||||||||||||||||
| insertBatch(tableName) | ||||||||||||||||||||||||||||||||||||
| for (int i = 0; i < 10; i++) { | ||||||||||||||||||||||||||||||||||||
| insertBatch(tableName) | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| trigger_and_wait_compaction(tableName, "cumulative") | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| def waitSchemaChange = { tableName -> | ||||||||||||||||||||||||||||||||||||
| waitForSchemaChangeDone { | ||||||||||||||||||||||||||||||||||||
| sql """ SHOW ALTER TABLE COLUMN WHERE TableName='${tableName}' ORDER BY createtime DESC LIMIT 1 """ | ||||||||||||||||||||||||||||||||||||
| time 600 | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| def assertPhraseCount = { tableName -> | ||||||||||||||||||||||||||||||||||||
| assertEquals(33, sql(""" SELECT COUNT() FROM ${tableName} WHERE var['string'] MATCH_PHRASE 'hello' """)[0][0]) | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| def assertNestedIndexFileReady = { tableName -> | ||||||||||||||||||||||||||||||||||||
| def backendIdToBackendIP = [:] | ||||||||||||||||||||||||||||||||||||
| def backendIdToBackendHttpPort = [:] | ||||||||||||||||||||||||||||||||||||
| getBackendIpHttpPort(backendIdToBackendIP, backendIdToBackendHttpPort) | ||||||||||||||||||||||||||||||||||||
| def tablets = sql_return_maparray(""" SHOW TABLETS FROM ${tableName} """) | ||||||||||||||||||||||||||||||||||||
| String tabletId = tablets[0].TabletId | ||||||||||||||||||||||||||||||||||||
| String backendId = tablets[0].BackendId | ||||||||||||||||||||||||||||||||||||
| String ip = backendIdToBackendIP.get(backendId) | ||||||||||||||||||||||||||||||||||||
| String port = backendIdToBackendHttpPort.get(backendId) | ||||||||||||||||||||||||||||||||||||
| check_nested_index_file(ip, port, tabletId, 2, 3, "V2") | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
| check_nested_index_file(ip, port, tabletId, 2, 3, "V2") | |
| // Derive the active rowset count dynamically to avoid hard-coded assumptions | |
| def tabletStatusList = be_show_tablet_status(tableName) | |
| int activeRowsetCount = 0 | |
| for (status in tabletStatusList) { | |
| if (status.TabletId == tabletId) { | |
| // Use the rowset count reported by the backend for this tablet | |
| activeRowsetCount = (status.RowsetCount as int) | |
| break | |
| } | |
| } | |
| assertTrue(activeRowsetCount > 0) | |
| check_nested_index_file(ip, port, tabletId, activeRowsetCount, 3, "V2") |
Copilot
AI
Mar 26, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The expected per-segment indices_count is set to 3, but the table defines two inverted indexes on var and the inserted JSON has two extracted paths (string, array_string). A very similar variant multi-index test asserts indices_count = 4 for this shape (2 indexes × 2 paths). Unless there is a documented reason this schema change produces only 3 indices, this expectation is likely incorrect and will fail. Consider aligning the expected indices_count with the actual number of built indices (e.g., 4) or deriving it from SHOW INDEX/returned JSON instead of hard-coding.
| check_nested_index_file(ip, port, tabletId, 2, 3, "V2") | |
| check_nested_index_file(ip, port, tabletId, 2, 4, "V2") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check_nested_index_file(...)hard-codes index storage format as "V2", but the table DDL does not set"inverted_index_storage_format"in PROPERTIES. This makes the assertion dependent on cluster defaults (and could flip to V3/V1), causing test flakiness. Consider setting"inverted_index_storage_format" = "V2"explicitly in the CREATE TABLE PROPERTIES (or loosening the assertion to accept the actual format returned by the API).