@@ -1810,7 +1810,7 @@ def test_tidb_plan_mysql_conversion():
1810
1810
parsed = json .loads (mysql_plan )
1811
1811
assert parsed ['query_block' ]['table' ]['table_name' ] == 'orders'
1812
1812
assert parsed ['query_block' ]['table' ]['access_type' ] == 'range'
1813
- assert parsed ['query_block' ]['table' ]['key' ] == 'idx_date(created_at) '
1813
+ assert parsed ['query_block' ]['table' ]['key' ] == 'idx_date'
1814
1814
1815
1815
# Test TableFullScan conversion
1816
1816
mysql_plan = statement_samples ._convert_tidb_plan_to_mysql_format (json .dumps ([tidb_plans [2 ]]))
@@ -2683,46 +2683,42 @@ def test_parse_tidb_text_plan_with_tree_structure(self):
2683
2683
result_json = statement_samples ._parse_tidb_text_plan (plan_text )
2684
2684
result = json .loads (result_json )
2685
2685
2686
- # Verify it's the root node
2687
- assert result ['id' ] == 'Sort_13'
2688
- assert result ['taskType' ] == 'root'
2689
- assert result ['estRows' ] == '0.40'
2690
-
2691
- # Verify tree structure - Sort_13 has one child (Projection_15)
2692
- assert 'children' in result
2693
- assert len (result ['children' ]) == 1
2694
- projection = result ['children' ][0 ]
2695
- assert projection ['id' ] == 'Projection_15'
2696
-
2697
- # Verify Projection_15 has one child (Selection_16)
2698
- assert 'children' in projection
2699
- assert len (projection ['children' ]) == 1
2700
- selection = projection ['children' ][0 ]
2701
- assert selection ['id' ] == 'Selection_16'
2702
-
2703
- # Verify Selection_16 has one child (HashJoin_17)
2704
- assert 'children' in selection
2705
- assert len (selection ['children' ]) == 1
2706
- hash_join = selection ['children' ][0 ]
2707
- assert hash_join ['id' ] == 'HashJoin_17'
2708
-
2709
- # Verify HashJoin_17 has two children
2710
- assert 'children' in hash_join
2711
- assert len (hash_join ['children' ]) == 2
2712
-
2713
- # First child is IndexLookUp_75
2714
- index_lookup = hash_join ['children' ][0 ]
2715
- assert index_lookup ['id' ] == 'IndexLookUp_75(Build)'
2716
-
2717
- # IndexLookUp_75 has two children
2718
- assert 'children' in index_lookup
2719
- assert len (index_lookup ['children' ]) == 2
2720
- assert index_lookup ['children' ][0 ]['id' ] == 'IndexRangeScan_73(Build)'
2721
- assert index_lookup ['children' ][1 ]['id' ] == 'TableRowIDScan_74(Probe)'
2722
-
2723
- # Second child is IndexHashJoin_27
2724
- index_hash_join = hash_join ['children' ][1 ]
2725
- assert index_hash_join ['id' ] == 'IndexHashJoin_27(Probe)'
2686
+ # Verify it's a flat array
2687
+ assert isinstance (result , list )
2688
+ assert len (result ) > 0
2689
+
2690
+ # Verify the first node is Sort_13
2691
+ assert result [0 ]['id' ] == 'Sort_13'
2692
+ assert result [0 ]['taskType' ] == 'root'
2693
+ assert result [0 ]['estRows' ] == '0.40'
2694
+
2695
+ # Find Projection_15 in the array
2696
+ projection = next ((n for n in result if n ['id' ] == 'Projection_15' ), None )
2697
+ assert projection is not None
2698
+ assert projection ['taskType' ] == 'root'
2699
+
2700
+ # Find Selection_16 in the array
2701
+ selection = next ((n for n in result if n ['id' ] == 'Selection_16' ), None )
2702
+ assert selection is not None
2703
+ assert selection ['taskType' ] == 'root'
2704
+
2705
+ # Find HashJoin_17 in the array
2706
+ hash_join = next ((n for n in result if n ['id' ] == 'HashJoin_17' ), None )
2707
+ assert hash_join is not None
2708
+
2709
+ # Find IndexLookUp_75(Build) in the array
2710
+ index_lookup = next ((n for n in result if n ['id' ] == 'IndexLookUp_75(Build)' ), None )
2711
+ assert index_lookup is not None
2712
+
2713
+ # Find IndexRangeScan_73(Build) and TableRowIDScan_74(Probe) in the array
2714
+ index_range_scan = next ((n for n in result if n ['id' ] == 'IndexRangeScan_73(Build)' ), None )
2715
+ assert index_range_scan is not None
2716
+ table_row_scan = next ((n for n in result if n ['id' ] == 'TableRowIDScan_74(Probe)' ), None )
2717
+ assert table_row_scan is not None
2718
+
2719
+ # Find IndexHashJoin_27(Probe) in the array
2720
+ index_hash_join = next ((n for n in result if n ['id' ] == 'IndexHashJoin_27(Probe)' ), None )
2721
+ assert index_hash_join is not None
2726
2722
2727
2723
def test_parse_tidb_text_plan_empty (self ):
2728
2724
"""Test parsing empty TiDB text plan."""
@@ -2759,10 +2755,12 @@ def test_parse_tidb_text_plan_with_escaped_chars(self):
2759
2755
result_json = statement_samples ._parse_tidb_text_plan (plan_text )
2760
2756
result = json .loads (result_json )
2761
2757
2762
- # Should parse successfully
2763
- assert result ['id' ] == 'Sort_13'
2764
- assert result ['taskType' ] == 'root'
2765
- assert result ['estRows' ] == '0.40'
2758
+ # Should parse successfully as a flat array
2759
+ assert isinstance (result , list )
2760
+ assert len (result ) > 0
2761
+ assert result [0 ]['id' ] == 'Sort_13'
2762
+ assert result [0 ]['taskType' ] == 'root'
2763
+ assert result [0 ]['estRows' ] == '0.40'
2766
2764
2767
2765
def test_parse_tidb_text_plan_with_na_values (self ):
2768
2766
"""Test parsing TiDB text plan with N/A values."""
@@ -2779,12 +2777,17 @@ def test_parse_tidb_text_plan_with_na_values(self):
2779
2777
result_json = statement_samples ._parse_tidb_text_plan (plan_text )
2780
2778
result = json .loads (result_json )
2781
2779
2780
+ # Should be a flat array
2781
+ assert isinstance (result , list )
2782
+ assert len (result ) == 1
2783
+ node = result [0 ]
2784
+
2782
2785
# N/A values should be converted to "0" for numeric fields
2783
- assert result ['estRows' ] == '0'
2784
- assert result ['actRows' ] == '0'
2786
+ assert node ['estRows' ] == '0'
2787
+ assert node ['actRows' ] == '0'
2785
2788
# N/A for memory and disk should be omitted
2786
- assert 'memory' not in result
2787
- assert 'disk' not in result
2789
+ assert 'memory' not in node
2790
+ assert 'disk' not in node
2788
2791
2789
2792
def test_parse_tidb_text_plan_numeric_formatting (self ):
2790
2793
"""Test parsing TiDB text plan preserves numeric formatting."""
@@ -2802,13 +2805,18 @@ def test_parse_tidb_text_plan_numeric_formatting(self):
2802
2805
result_json = statement_samples ._parse_tidb_text_plan (plan_text )
2803
2806
result = json .loads (result_json )
2804
2807
2808
+ # Should be a flat array
2809
+ assert isinstance (result , list )
2810
+ assert len (result ) == 2
2811
+
2805
2812
# Verify numeric formatting is preserved
2806
- assert result ['estRows' ] == '1.00' # Decimal preserved
2807
- assert result ['actRows' ] == '100' # Integer as string
2813
+ sort_node = result [0 ]
2814
+ assert sort_node ['estRows' ] == '1.00' # Decimal preserved
2815
+ assert sort_node ['actRows' ] == '100' # Integer as string
2808
2816
2809
- child = result ['children' ][ 0 ]
2810
- assert child ['estRows' ] == '0.40' # Decimal preserved
2811
- assert child ['actRows' ] == '0' # Integer as string
2817
+ projection_node = result [1 ]
2818
+ assert projection_node ['estRows' ] == '0.40' # Decimal preserved
2819
+ assert projection_node ['actRows' ] == '0' # Integer as string
2812
2820
2813
2821
def test_convert_tidb_to_mysql_format_improved_table_extraction (self ):
2814
2822
"""Test improved table name extraction from various patterns."""
0 commit comments