atifiu opened a new pull request, #57857:
URL: https://github.com/apache/doris/pull/57857

   ## Summary
   Fixes #57773 - Temporary table resolution with lower_case_table_names=1
   
   Supersedes #57832 (rebased from branch-4.0 to master per maintainer request)
   
   ## Problem
   When `lower_case_table_names=1`, temporary tables failed in:
   - **Scenario 1:** CREATE TEMPORARY TABLE ... LIKE on AUTO LIST PARTITION 
tables → "Table does not exist"
   - **Scenario 2:** INSERT OVERWRITE TABLE on temporary tables → "Unknown 
table"
   
   ## Root Cause
   Missing display name → internal name mapping in `lowerCaseToTableName`:
   - Temp tables use internal names: `sessionId_#TEMP#_displayName`
   - Map only had: internal(lowercase) → internal
   - Missing: display(lowercase) → internal
   - Result: Lookups by display name failed
   
   ## Solution
   1. **Database.registerTable()**: Add display name → internal name mapping 
for temp tables
   2. **Database.getTableNullable()**: Resolve temp inner names in mode=1
   3. **Util.java**: Case-insensitive temp table utilities
   4. **FeNameFormat.java**: Added `TEMPORARY_TABLE_SIGN_LOWER` constant
   5. **ShowTableStatusCommand.java**: Apply LOWER() for consistent filtering
   
   ## Testing
   ✅ **Regression tests** added in `regression-test/suites/temp_table_p0/`:
   - `test_temp_like.sql/.out`: CREATE TEMP LIKE on AUTO LIST PARTITION table
   - `test_temp_overwrite.sql/.out`: INSERT OVERWRITE on temp table
   - `test_temp_table_case_sensitivity.groovy`: Comprehensive case-sensitivity 
suite (14 test scenarios)
   
   ✅ **Unit tests** (243 lines):
   - `UtilTest.java`: Temp table utility functions across all modes (0, 1, 2)
   - `ShowTableStatusCommandTest.java`: Filtering logic validation
   
   ✅ **Manual validation**: All scenarios pass with correct row counts on FE 
with `lower_case_table_names=1`
   
   ## Files Changed
   **11 files, +605/-24 lines:**
   
   **Source (4 files):**
   - `fe/fe-core/src/main/java/org/apache/doris/catalog/Database.java` (+37/-7)
   - `fe/fe-core/src/main/java/org/apache/doris/common/util/Util.java` (+15/-8)
   - `fe/fe-core/src/main/java/org/apache/doris/common/FeNameFormat.java` 
(+8/-1)
   - 
`fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowTableStatusCommand.java`
 (+28/-8)
   
   **Unit Tests (2 files):**
   - `fe/fe-core/src/test/java/org/apache/doris/common/util/UtilTest.java` 
(+229)
   - 
`fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/ShowTableStatusCommandTest.java`
 (+14)
   
   **Regression Tests (5 files):**
   - `regression-test/suites/temp_table_p0/test_temp_like.sql` (+37)
   - `regression-test/suites/temp_table_p0/test_temp_like.out` (+2)
   - `regression-test/suites/temp_table_p0/test_temp_overwrite.sql` (+21)
   - `regression-test/suites/temp_table_p0/test_temp_overwrite.out` (+3)
   - 
`regression-test/suites/temp_table_p0/test_temp_table_case_sensitivity.groovy` 
(+230)
   
   ## Compatibility
   - **Mode=0** (case-sensitive): No change ✅
   - **Mode=1** (stored-lowercase): Fixed ✅
   - **Mode=2** (case-insensitive): No behavior change ✅
   
   All changes are backward compatible. No BE modifications required.
   
   ## Example - Complete Test Scenarios
   
   ### Scenario 1: CREATE TEMP LIKE on AUTO LIST PARTITION Table
   ```sql
   -- Create source table with AUTO LIST PARTITION
   CREATE TABLE `contacts` (
     `client_code` varchar(100) NOT NULL,
     `id` varchar(100) NULL COMMENT "Campaign ID",
     `me_id` varchar(100) NULL COMMENT "Marketing event ID",
     `universal_person_id` varchar(100) NULL,
     `person_type` varchar(100) NULL
   ) ENGINE=OLAP
   UNIQUE KEY(`client_code`, `id`, `me_id`, `universal_person_id`)
   AUTO PARTITION BY LIST (`client_code`)
   ()
   DISTRIBUTED BY HASH(`client_code`, `id`, `universal_person_id`) BUCKETS 1
   PROPERTIES (
     "replication_num" = "1",
     "enable_unique_key_merge_on_write" = "true"
   );```
   
   INSERT INTO contacts VALUES ('clientA', 'id1', 'me1', 'person1', 'type1');
   INSERT INTO contacts VALUES ('clientB', 'id2', 'me2', 'person2', 'type2');
   
   -- Create temp table LIKE source (with mixed-case name)
   CREATE TEMPORARY TABLE Contacts_Test_GKL LIKE contacts;
   
   -- Before fix: ❌ "Table [contacts_test_gkl] does not exist"
   -- After fix: ✅ Works correctly
   
   INSERT INTO Contacts_Test_GKL VALUES ('clientC', 'id3', 'me3', 'person3', 
'type3');
   SELECT COUNT(*) FROM Contacts_Test_GKL;
   -- Result: 1 ✅
   
   INSERT INTO Contacts_Test_GKL VALUES ('clientD', 'id4', 'me4', 'person4', 
'type4');
   SELECT COUNT(*) FROM Contacts_Test_GKL;
   -- Result: 2 ✅
   ```
   
   ### Scenario 2: INSERT OVERWRITE on Temporary Table
   ```sql
   
   
   -- Create temp table with CTAS
   CREATE TEMPORARY TABLE test123_emp 
   PROPERTIES('replication_num' = '1') 
   AS SELECT 1 as id;
   
   SELECT COUNT(*) FROM test123_emp;
   -- Result: 1 ✅
   
   INSERT INTO test123_emp VALUES (2);
   SELECT COUNT(*) FROM test123_emp;
   -- Result: 2 ✅
   
   -- Before fix: ❌ "Unknown table <internal_temp_name>"
   -- After fix: ✅ Works correctly
   
   INSERT OVERWRITE TABLE test123_emp VALUES (3);
   SELECT COUNT(*) FROM test123_emp;
   -- Result: 1 ✅
   ```
   
   How the Fix Works (Mode=1)
   
   1. User creates: CREATE TEMPORARY TABLE MyTable (id INT)
      → Stored as: sessionId_#TEMP#_MyTable in nameToTable
      
   2. Database.registerTable() adds two mappings:
      → lowerCaseToTableName["sessionid_#temp#_mytable"] = 
"sessionId_#TEMP#_MyTable"
      → lowerCaseToTableName["mytable"] = "sessionId_#TEMP#_MyTable"  ← NEW!
      
   3. User queries: SELECT * FROM mytable
      → tableName lowercased: "mytable"
      → generateTempTableInnerName: "sessionid_#temp#_mytable"
      → Resolve via map: "sessionId_#TEMP#_MyTable"
      → Lookup succeeds ✅
      
   4. User executes: INSERT OVERWRITE TABLE MyTable VALUES (1)
      → Same resolution path
      → Operation succeeds ✅
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to